public void alertPromos() {
    List<Promotion> l =
        chargerMyPromo(
            client.getId(),
            produit.getId()); // vendeurManager.getPromotions(client.getId(), produit.getId());
    // for (int i = 0; i < l.size(); i++) {
    Promotion p = l.get(0);

    AlertDialog.Builder alert = new AlertDialog.Builder(CatalogeActivity.this);
    alert.setTitle(getResources().getString(R.string.promo_alert));
    alert.setMessage(
        String.format(
            getResources().getString(R.string.promo_msg)
                + " car vous avez "
                + p.getQuantite()
                + " Produit Gratuit",
            panier.get(produit.getRef())));
    alert.setNegativeButton(
        "Ok",
        new DialogInterface.OnClickListener() {

          @Override
          public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
            return;
          }
        });
    alert.create().show();
  }
Example #2
0
  @Override
  public List<Produit> selectAllProduct(Compte c) {
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

    nameValuePairs.add(new BasicNameValuePair("username", c.getLogin()));
    nameValuePairs.add(new BasicNameValuePair("password", c.getPassword()));

    String jsonString = jsonParser.makeHttpRequest(urlprd, "POST", nameValuePairs);
    // Parse les donn�es JSON

    List<Produit> list = new ArrayList<Produit>();

    ArrayList<HashMap<String, String>> mapsss = new ArrayList<>();

    listPromoByProduits = new HashMap<>();

    Log.e("Json retourne >> ", jsonString);
    try {

      JSONArray jArray = new JSONArray(jsonString);
      // check your log for json response
      // Log.d("Dictionnaire", jArray.);

      // [{"id":"1","ref":"c00001","desig":"Produit1","stock":"100","pu":"100,00"},
      for (int i = 0; i < jArray.length(); i++) {
        if (i == 0) {
          JSONArray dico = jArray.getJSONArray(i);
          for (int j = 0; j < dico.length(); j++) {
            JSONObject jsone = dico.getJSONObject(j);
            HashMap<String, String> dic = new HashMap<>();
            dic.put(jsone.getString("code"), jsone.getString("libelle"));
            mapsss.add(dic);
          }
        } else {
          JSONObject json = jArray.getJSONObject(i);
          Produit produit = new Produit();
          // Log.e(">>> Produit trouver Successful!", json.toString());

          /*
          String pu = json.getString("pu");
          String[] parts = pu.split(".");

          String mni = parts[1].substring(0, 1);

          String part = parts[1]+"."+ mni;
          for (int j = 0; j < parts.length; j++) {
          	part += Integer.parseInt(parts[j]);
          }
           */

          produit.setId(json.getInt("id"));
          produit.setDesig(json.getString("desig"));
          produit.setPrixUnitaire(json.getString("pu"));
          produit.setQteDispo(json.getInt("stock"));
          produit.setRef(json.getString("ref"));
          produit.setPrixttc(json.getDouble("price_ttc"));
          produit.setFk_tva(json.getString("fk_tva"));
          produit.setTva_tx(json.getString("tva_tx"));
          list.add(produit);

          int nombre_promos = json.getInt("nombre_promotion");
          HashMap<Integer, Promotion> map = new HashMap<>();

          if (nombre_promos > 0) {
            for (int j = 0; j < nombre_promos; j++) {

              Promotion p =
                  new Promotion(
                      json.getInt("id_promos" + j),
                      Integer.parseInt(json.getString("type_promos" + j)),
                      Integer.parseInt(json.getString("promos" + j)),
                      Integer.parseInt(json.getString("qte_promos" + j)));
              map.put(p.getId(), p);
            }
          } else {
            Promotion p = new Promotion(0, -1, 0, 0);
            map.put(p.getId(), p);
          }
          listPromoByProduits.put(json.getInt("id"), map);
        }
      }
    } catch (Exception e) {
      Log.e("VendeurDaoMysql log_tag", "Error parsing data selectAllProduct " + e.toString());
      MyDebug.WriteLog(
          this.getClass().getSimpleName(),
          "selectAllProduct",
          nameValuePairs.toString(),
          e.toString());
    }

    dicot.setDico(mapsss);
    // Log.i("Dictionnaire >> ",dicot.toString());

    return list;
  }