@Override public List<CategorieCustomer> getAllCategorieCustomer(Compte c) { // TODO Auto-generated method stub List<CategorieCustomer> res = new ArrayList<>(); ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("username", c.getLogin())); nameValuePairs.add(new BasicNameValuePair("password", c.getPassword())); try { String jsonString = jsonParser.makeHttpRequest(urlcatclt, "POST", nameValuePairs); JSONObject obj = new JSONObject(jsonString); JSONArray lsfree = obj.getJSONArray("lsfree"); JSONArray lscat = obj.getJSONArray("lscategories"); List<Integer> tmp = new ArrayList<>(); for (int i = 0; i < lsfree.length(); i++) { tmp.add(lsfree.getInt(i)); } res.add(new CategorieCustomer(0, "Categorie par defaut", "Categorie par defaut", tmp)); for (int i = 0; i < lscat.length(); i++) { JSONObject jb = lscat.getJSONObject(i); tmp = new ArrayList<>(); for (int j = 0; j < jb.getJSONArray("clts").length(); j++) { tmp.add(jb.getJSONArray("clts").getInt(j)); } res.add( new CategorieCustomer( jb.getInt("id"), jb.getString("label"), jb.getString("description"), tmp)); } Log.e("secto ", " " + res.size()); } catch (Exception e) { // TODO: handle exception Log.e("VendeurDaoMysql error parse secteur getAllCategorieCustomer ", e.getMessage() + " "); res = new ArrayList<>(); MyDebug.WriteLog( this.getClass().getSimpleName(), "getAllCategorieCustomer", nameValuePairs.toString(), e.toString()); } return res; }
@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; }
@Override public List<Client> selectAllLastClient(Compte c, String in) { // TODO Auto-generated method stub ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("username", c.getLogin())); nameValuePairs.add(new BasicNameValuePair("password", c.getPassword())); nameValuePairs.add(new BasicNameValuePair("rowid", in)); String jsonString = jsonParser.makeHttpRequest(urlclt, "POST", nameValuePairs); // Parse les donn�es JSON List<Client> list = new ArrayList<Client>(); Log.e("Json retourne >> ", jsonString); lssociete = new ArrayList<>(); try { JSONArray jArray = new JSONArray(jsonString); // check your log for json response // Log.d("Login attempt", jArray.toString()); for (int i = 0; i < jArray.length(); i++) { JSONObject json = jArray.getJSONObject(i); Client clt = new Client(); // "rowid":"3","name":"karouani","client":"1","zip":"54020","town":null, // "stcomm":"Jamais contact\u00e9","prefix_comm":null,"code_client":"14589" clt.setId(json.getInt("rowid")); clt.setName(json.getString("name")); clt.setZip(json.getString("zip")); clt.setTown(json.getString("town")); clt.setLatitude(Double.parseDouble(json.getString("latitude"))); clt.setLongitude(Double.parseDouble(json.getString("longitude"))); if (!c.getProfile().toLowerCase().equals("technicien")) { clt.setEmail(json.getString("email")); } int nombre_promos = json.getInt("nombre_promotion"); List<Integer> listP = new ArrayList<>(); if (nombre_promos > 0) { for (int j = 0; j < nombre_promos; j++) { int idp = Integer.parseInt(json.getString("id_promos" + j)); listP.add(idp); } } listPromoByClient.put(json.getInt("rowid"), listP); list.add(clt); /** ***************************** Load societe data ********************************* */ Societe s = new Societe( json.getInt("rowid"), json.getString("name"), json.getString("address"), json.getString("town"), json.getString("phone"), json.getString("fax"), json.getString("email"), json.getInt("type"), json.getInt("company"), json.getDouble("latitude"), json.getDouble("longitude")); s.setLogo(json.getString("logo")); if (json.getString("imgin").equals("ok") && !"".equals(json.getString("logo"))) { String imageURL = UrlImage.urlimgclients + json.getString("logo"); // Log.e(">>> img",imageURL+""); Bitmap bitmap = null; try { // Download Image from URL InputStream input = new java.net.URL(imageURL).openStream(); // Decode Bitmap bitmap = BitmapFactory.decodeStream(input); File dir = new File(UrlImage.pathimg + "/client_img"); if (!dir.exists()) dir.mkdirs(); File file = new File(dir, "/" + json.getString("logo")); FileOutputStream fOut = new FileOutputStream(file); // Log.e(">>hotos ",produit.getPhoto()); if (json.getString("logo").split("\\.")[1].equals("jpeg") || json.getString("logo").split("\\.")[1].equals("jpg") || json.getString("logo").split("\\.")[1].equals("jpe")) { bitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut); } else { bitmap.compress(Bitmap.CompressFormat.PNG, 85, fOut); } fOut.flush(); fOut.close(); } catch (Exception e) { e.printStackTrace(); Log.e(">> ", "pic out clt " + e.getMessage()); } } lssociete.add(s); } } catch (Exception e) { Log.e("VendeurDaoMysql log_tag", "Error parsing data selectAllLastClient " + e.toString()); MyDebug.WriteLog( this.getClass().getSimpleName(), "selectAllLastClient", nameValuePairs.toString(), e.toString()); } return list; }