mardi 24 novembre 2015

Android Send SQLite table data to XAMPP server

I want to send SQLite table data to PHP Server.Problem is that when i send single row of table it successfully upload in server but when i send bulk row it send last row of table in every while loop. I want to send all my table data send to the Server but this code is not doing this work.I am new in this so please help me.

Class with AsysncTask

     @Override
    public void onClick(View v) {
    switch(v.getId()){
        case R.id.b_sync:
            ArrayList<String> data = hp.getSaveOpInfo(getContext());
            String opid = data.get(0);

            //Create Database Connect Object "dbConnector"
            DatabaseConnector dbConnector = new DatabaseConnector(getActivity());

            if(!dbConnector.isPayTableEmplty()) {
                // open DB for operation
                dbConnector.open();
                // get customer Table columns
                Cursor cr = dbConnector.fetchAllPayment();
              //  cr.moveToNext();
                while(cr.isAfterLast()==false){

                    // get Data from Payment Table
                     getCon = cr.getString(cr.getColumnIndex(dbConnector.CONNO));
                     paid_amt =cr.getString(cr.getColumnIndex(dbConnector.PAIDAMT));
                     discount =cr.getString(cr.getColumnIndex(dbConnector.DISCOUNT));
                     contact =cr.getString(cr.getColumnIndex(dbConnector.CONTACT));
                     lnid =cr.getString(cr.getColumnIndex(dbConnector.LNID));
                     time =cr.getString(cr.getColumnIndex(dbConnector.TIME));


                    // Create param for POST
                    params = new ArrayList<NameValuePair>();
                        params.add(new BasicNameValuePair("tag", "payment"));
                        params.add(new BasicNameValuePair("conNo", getCon));//getData.getString("con")));
                        params.add(new BasicNameValuePair("amount",paid_amt)); //getData.getString("paid_amt")));
                        params.add(new BasicNameValuePair("lineman", lnid));
                        params.add(new BasicNameValuePair("opId", opid));
                        params.add(new BasicNameValuePair("date", time));
                        params.add(new BasicNameValuePair("mobile",""));
                        params.add(new BasicNameValuePair("receipt", "0"));
                        params.add(new BasicNameValuePair("discount", discount));
                        params.add(new BasicNameValuePair("sms_ovr", "0"));

                       // AsyncTask Class
                        new ReadJSONResult().execute(sync_url);

                    Toast.makeText(getContext(), params.toString(), Toast.LENGTH_LONG).show();
                    cr.moveToNext();
                }

            }else{
                Toast.makeText(getContext(), "Empty Data ", Toast.LENGTH_LONG).show();

            }
            dbConnector.close();
            break;
        }
    }

    class ReadJSONResult extends AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... urls) {
            // TODO Auto-generated method stub
            return cn.readJSONFeed(urls[0],params);
        }

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            pb.setVisibility(View.VISIBLE);

        }

        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub
            //   Toast.makeText(getContext(),"RESULT="+ result.toString(),
            //        Toast.LENGTH_LONG).show();
            DatabaseConnector dbConnector = new DatabaseConnector(getActivity());
            try {
                pb.setVisibility(View.GONE);

                //   Toast.makeText(getContext(), result.toString(),
                //  Toast.LENGTH_LONG).show();

                JSONObject jsonObject = new JSONObject(result);

                if ("1".equals(jsonObject.getString("success"))) {

                    Toast.makeText(getContext(),
                            "success =  \n "+jsonObject.toString(),
                            Toast.LENGTH_LONG).show();
                   // dbConnector.deletePayMentTable();
                    pb.setVisibility(View.GONE);
                } else {
                    Toast.makeText(getContext(),
                            "Account Not Found \n Please try again.",
                            Toast.LENGTH_LONG).show();
                    pb.setVisibility(View.GONE);
                }
            } catch (Exception e) {
                Log.d("Ex", e.getLocalizedMessage());
                Toast.makeText(getContext(), "onPost == " + e.toString(),
                        Toast.LENGTH_LONG).show();
                pb.setVisibility(View.GONE);
            }

        }

    }

}

Aucun commentaire:

Enregistrer un commentaire