Exemplo n.º 1
0
  @Override
  protected void onStart() {
    PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wakelock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "no sleep");
    wakelock.acquire();

    if (CheckOutNet.isNetworkConnected(getApplicationContext())) {
      if (firstexecution == 0) {
        dialog =
            ProgressDialog.show(
                TechnicienActivity.this,
                getResources().getString(R.string.map_data),
                getResources().getString(R.string.msg_wait),
                true);
        new ConnexionTask().execute();
      }
    } else {
      if (firstexecution == 0) {
        dialog =
            ProgressDialog.show(
                TechnicienActivity.this,
                getResources().getString(R.string.map_data),
                getResources().getString(R.string.msg_wait),
                true);
        new OfflineTask().execute();
      }
    }

    super.onStart();
  }
Exemplo n.º 2
0
  @Override
  protected void onResume() {
    // TODO Auto-generated method stub
    if (clients.size() > 0 && listclt.size() > 0) {
      myoffline = new Offlineimpl(getApplicationContext());
      List<Prospection> pros = new ArrayList<>();
      pros = myoffline.LoadProspection("");
      if (!CheckOutNet.isNetworkConnected(getApplicationContext())) {
        if (pros.size() > 0) {
          for (int i = 0; i < pros.size(); i++) {
            if (pros.get(i).getClient() == 1) {
              if (!listclt.contains(pros.get(i).getName())) {
                Client c =
                    new Client(
                        pros.get(i).getIdpros(),
                        pros.get(i).getName(),
                        pros.get(i).getZip(),
                        pros.get(i).getTown(),
                        pros.get(i).getEmail(),
                        pros.get(i).getPhone(),
                        pros.get(i).getAddress());
                clients.add(c);
                listclt.add(pros.get(i).getName());
                addItemsOnSpinner(clientspinner, 1);
              }
            }
          }
        }
      }
    }

    super.onResume();
  }
Exemplo n.º 3
0
    @Override
    protected String doInBackground(Void... params) {

      try {
        myoffine = new Offlineimpl(getApplicationContext());
        if (CheckOutNet.isNetworkConnected(getApplicationContext())) {
          if (!myoffine.checkFolderexsiste()) {
            showmessageOffline();
          } else {
            myoffine.sendOutIntervention(compte);
          }
        }

      } catch (Exception e) {
        // TODO: handle exception
        Log.e("erreu synchro", e.getMessage() + " << ");
      }

      Log.e("start ", "start cnx service");

      return null;
    }
Exemplo n.º 4
0
    @Override
    protected String doInBackground(Void... params) {

      // Log.i("Produit ",vendeurManager.selectAllProduct(compte).toString());
      myoffline = new Offlineimpl(getApplicationContext());
      sv = new StockVirtual(CatalogeActivity.this);

      // getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
      /*
      if(CheckOutNet.isNetworkConnected(getApplicationContext())){
      	if(myoffline.checkAvailableofflinestorage() > 0){
      		for (int i = 0; i < myoffline.LoadCmdList("").size(); i++) {
      			Log.e("send cmd ",myoffline.SendCommande(myoffline.LoadCmdList("").get(i), compte)+ "" );
      		}
      	}
      }
      */

      myoffline = new Offlineimpl(getApplicationContext());
      if (CheckOutNet.isNetworkConnected(getApplicationContext())) {
        myoffline.SendOutData(compte);
      }

      lscats = categorie.LoadCategories(compte);

      products = vendeurManager.selectAllProduct(compte);

      for (int i = 0; i < products.size(); i++) {
        for (int j = 0; j < sv.getAllProduits(-1).size(); j++) {
          // Log.e(products.get(i).getId()+"",sv.getAllProduits().get(j).getRef());
          if (Integer.parseInt(sv.getAllProduits(-1).get(j).getRef()) == products.get(i).getId()) {
            Log.e("qte1 " + products.get(i).getId(), products.get(i).getQteDispo() + "");
            products
                .get(i)
                .setQteDispo(
                    products.get(i).getQteDispo() - sv.getAllProduits(-1).get(j).getQteDispo());
            Log.e("qte2 " + products.get(i).getId(), products.get(i).getQteDispo() + "");
          }
        }
        // Log.d("Produit "+i,p.toString());
      }
      nprod = products.size();

      for (int j = 0; j < lscats.size(); j++) {
        for (int i = 0; i < lscats.get(j).getProducts().size(); i++) {
          for (int k = 0; k < products.size(); k++) {
            if (lscats.get(j).getProducts().get(i).getId() == products.get(k).getId()) {
              lscats.get(j).getProducts().get(i).setQteDispo(products.get(k).getQteDispo());
            }
          }
        }
      }

      if (lscats.size() > 0) {
        myoffline.shynchronizeCategoriesList(lscats);
      }

      dico = vendeurManager.getDictionnaire();

      clients = vendeurManager.selectAllClient(compte);
      nclt = clients.size();

      listclt = new ArrayList<>();
      for (int i = 0; i < clients.size(); i++) {
        listclt.add(clients.get(i).getName());
      }

      /** ********************* offline *************************************** */
      Log.e("begin offline from network", ">>start load");

      // myoffline.CleanService();

      if (!myoffline.checkFolderexsiste()) {
        showmessageOffline();
      } else {
        if (products.size() > 0) {
          myoffline.CleanProduits();
          myoffline.CleanPromotionProduit();
          sysnbr += myoffline.shynchronizeProduits(products);
          sysnbr += myoffline.shynchronizePromotion(vendeurManager.getPromotionProduits());
        }

        if (dico.getDico().size() > 0) {
          myoffline.CleanDico();
          sysnbr += myoffline.shynchronizeDico(dico);
        }

        if (clients.size() > 0) {
          myoffline.CleanClients();
          myoffline.CleanPromotionClient();
          sysnbr += myoffline.shynchronizeClients(clients);
          sysnbr += myoffline.shynchronizePromotionClient(vendeurManager.getPromotionClients());
        }
      }

      Log.e("start ", "start cnx task");

      lscat = new ArrayList<>();
      listcat = new ArrayList<>();
      lscat = vendeurManager.getAllCategorieCustomer(compte);
      if (lscat.size() > 0) {
        myoffline.CleanCategorieClients();
        for (int i = 0; i < lscat.size(); i++) {
          myoffline.shnchronizeCategorieClients(lscat.get(i), compte);
        }
      }
      //	Log.e(">cat ",lscat.toString());
      for (int i = 0; i < lscat.size(); i++) {
        listcat.add(lscat.get(i).getLibelle() + "");
      }
      Log.e("lscatclient", listcat.toString());

      return "success";
    }
  @Override
  public void onClick(View v) {
    // TODO Auto-generated method stub

    if (v.getId() == R.id.addnew) {
      btn2.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              adapter = getSimple(lsmove.size());
              adapter.notifyDataSetChanged();
              myview.setAdapter(adapter);
              dialog.dismiss();
            }
          });

      // Button addprd = (Button) dialog.findViewById(R.id.ajouterproduitdialog);
      Log.e("spinner ", proSpinner + " >>");

      addItemsOnSpinner(proSpinner, 1);

      ////////////// **********************************Traitement
      // PoPup************************************************////////////////////

      qty.addTextChangedListener(
          new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
              String qteString = getResources().getString(R.string.field_qte);

              if (!qteString.equals(qty.getText().toString())
                  && !"".equals(qty.getText().toString())
                  && produit != null) {
                String prix = "";

                prix = qty.getText().toString();

                Log.e("qty", prix + "  ");

                Log.e(">>> sum", check_availableQnt(produit) + "");

                if (produit.getQteDispo()
                    >= (check_availableQnt(produit) + Integer.parseInt(prix))) {
                  btn1.setEnabled(true);
                } else {
                  alert();
                }
              }
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

            @Override
            public void afterTextChanged(Editable s) {
              String qteString = getResources().getString(R.string.field_qte);
            }
          });

      btn1.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              Log.e("me ", qty.getText().toString() + " **");
              if (produit != null) {
                if (produit.getId() != 0 && !qty.getText().toString().equals("")) {
                  int is = -1;

                  if (lsmove.size() > 0) {
                    for (int i = 0; i < lsmove.size(); i++) {
                      if (lsmove.get(i).getId() == produit.getId()) {
                        lsmove
                            .get(i)
                            .setQtedemander(
                                lsmove.get(i).getQtedemander()
                                    + Integer.parseInt(qty.getText().toString()));
                        is = 0;
                        break;
                      }
                    }

                    if (is == -1) {
                      produit.setQtedemander(Integer.parseInt(qty.getText().toString()));
                      lsmove.add(produit);
                    }
                  } else {
                    produit.setQtedemander(Integer.parseInt(qty.getText().toString()));
                    lsmove.add(produit);
                  }
                } else {
                  alert_produit(getResources().getString(R.string.mvm11));
                }
              } else {
                alert_produit(getResources().getString(R.string.mvm1));
              }

              produit = null;
              qty.setText("");
              proSpinner.setText("");
              qty.setEnabled(false);

              adapter = getSimple(lsmove.size());
              adapter.notifyDataSetChanged();
              myview.setAdapter(adapter);
              dialog.dismiss();
            }
          });

      proSpinner.setOnItemClickListener(
          new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View arg1, int position, long arg3) {
              String selected = (String) parent.getItemAtPosition(position);
              produit = new Produit();
              proSpinner.showDropDown();
              final InputMethodManager imm =
                  (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
              imm.hideSoftInputFromInputMethod(parent.getWindowToken(), 0);
              proSpinner.setFilters(
                  new InputFilter[] {new InputFilter.LengthFilter(selected.length())});

              Log.e("Selected Produit Spinner ", selected);

              for (int i = 0; i < lsprod.size(); i++) {
                if (selected.equals(lsprod.get(i).getDesig())) {
                  produit = new Produit();
                  produit = lsprod.get(i);

                  /*
                  if(panier.size() > 0){
                  	if(panier.containsKey(products.get(i).getRef())){
                  		produit.setQteDispo(panier.get(products.get(i).getRef()));
                  	}
                  }
                  */

                  Log.e("Text selectionner ", produit.toString());

                  qty.setEnabled(true);

                  Log.e("Text cicin ", "hellos");
                  // selectionner.setEnabled(true);

                  break;
                }
              }
            }
          });

      dialog.show();
    }

    if (v.getId() == R.id.savedata) {

      if (CheckOutNet.isNetworkConnected(getApplicationContext())) {
        if (lsmove != null && mystock != null) {
          if (lsmove.size() > 0) {

            AlertDialog.Builder alert = new AlertDialog.Builder(ViewstockActivity.this);
            alert.setTitle(getResources().getString(R.string.cmdtofc8));
            alert.setMessage(getResources().getString(R.string.btn_mvmstckgo));
            alert.setNegativeButton(
                android.R.string.no,
                new DialogInterface.OnClickListener() {

                  public void onClick(DialogInterface d, int arg1) {
                    // VendeurActivity.super.onBackPressed();
                    d.dismiss();
                  }
                });
            alert.setPositiveButton(
                android.R.string.yes,
                new DialogInterface.OnClickListener() {

                  public void onClick(DialogInterface d, int arg1) {
                    // VendeurActivity.super.onBackPressed();

                    dialog =
                        ProgressDialog.show(
                            ViewstockActivity.this,
                            getResources().getString(R.string.map_data),
                            getResources().getString(R.string.msg_wait),
                            true);

                    new MouvementTask().execute();

                    d.dismiss();
                  }
                });
            alert.create();
            alert.show();
          } else {
            alert_panier();
          }
        } else {
          alert_panier();
        }
      } else {
        alert_network();
      }
    }
  }