@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == 1) {
      if (data.getCharSequenceExtra(SyncDialog.RESULT_FROM_DIALOG)
          .toString()
          .equalsIgnoreCase("ya")) {

        JSONObject outer = new JSONObject();
        JSONArray arrItems = new JSONArray();
        try {
          outer.put("user_id", Contents.getLogInfo().getUserid());
          for (int i = 0; i < m_orders.size(); i++) {
            pemesananDTO penjualan = m_orders.get(i);
            arrItems.put(penjualan.toJSON());
          }
          outer.put("po", arrItems);
        } catch (JSONException e) {
          System.out.println(e);
        }
        dialog =
            ProgressDialog.show(ListPemesanan.this, "", "Mengirim data. Mohon tunggu...", true);

        HttpRequest.instance()
            .request(
                dialog, ListPemesanan.this, Contents.urlServer + "po/syncpo", outer.toString(), 0);
      }
    }
  }
  public int onHttpResponse(int code, String msg) {
    // TODO Auto-generated method stub
    dialog.dismiss();
    JSONObject jsonObject;
    try {
      jsonObject = new JSONObject(msg);
      if (jsonObject.getBoolean("success")) {
        dbi.deleteAll();

        m_adapter.clear();

        JSONArray arrfItem = jsonObject.getJSONArray("po");

        for (int j = 0; j < arrfItem.length(); j++) {
          pemesananDTO _penjualan = new pemesananDTO();
          _penjualan.fromJSON(arrfItem.getString(j));
          long insertedId = dbi.insert(_penjualan);
          dbi.setUploaded(insertedId);
        }

        m_orders = dbi.selectAll();
        for (int w = 0; w < m_orders.size(); w++) {
          m_adapter.add(m_orders.get(w));
        }
        m_adapter.notifyDataSetChanged();
      }
    } catch (JSONException e) {
      // TODO Auto-generated catch block

      showMessage("Format data rusak");
    }

    return 0;
  }
Example #3
0
  public String toJSON() {
    JSONObject outer = new JSONObject();
    JSONArray arrItems = new JSONArray();
    try {
      outer.put(USER_ID, this.getUserId());
      outer.put(KEYWORD, this.getKeyword());
      outer.put(CHANNEL_ID, this.getChannelId());
      outer.put(FRONTLINER_CODE, this.getFrontlinerCode());
      outer.put(CLAIM_PROGRAM, this.getClaimProgram());
      for (int i = 0; i < this.getItems().size(); i++) {
        // JSONObject item = new JSONObject();
        // item.put("item_code",this.getItems().get(i));
        arrItems.put(this.getItems().get(i));
      }
      outer.put(ITEMS, arrItems);

    } catch (JSONException e) {
      System.out.println(e);
    }
    return outer.toString();
  }