从Sqlite中获取一行,将其上传到服务器上,删除它并移动到下一行

时间:2013-12-18 09:07:38

标签: android sqlite

我在sqlite数据库表中有几个条目FeedbackDetails我想从该表中获取每一行,在服务器上更新该行,然后获取该特定的行ID,并使用该Id我必须删除该特定的条目...

我试过下面的代码..

它正在更新并删除第一行被提取...然后不是去下一行而是继续更新被删除的第一行......它进入无限循环......

请告诉我错误的地方......我认为光标有问题...请帮忙

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.upload);
    upload = (Button) findViewById(R.id.upload);
    upload.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.upload:
        if (networkOn(Upload.this)) {
            // Internet Connection is Present
            // make HTTP requests
            Log.d("XXX", "You have internet connection");

            new Uploading().execute();
        } else {
            Log.d("XXX", "You dont have internet connection");
        }
        break;
    }
}

public int deleteEntry(String ID_firstRow) {
    // String id=String.valueOf(ID);
    String where = "ID=?";
    int numberOFEntriesDeleted = db.delete("FeedbackDetails", where,
            new String[] { ID_firstRow });
    // Toast.makeText(context,
    // "Number fo Entry Deleted Successfully : "+numberOFEntriesDeleted,
    // Toast.LENGTH_LONG).show();
    return numberOFEntriesDeleted;
}

public static boolean networkOn(Context context) {

    boolean mobileFlag = false, wifiFlag = false;
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    State mobile = connManager.getNetworkInfo(
            ConnectivityManager.TYPE_MOBILE).getState();

    State wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
            .getState();

    NetworkInfo networkInfo = connManager.getActiveNetworkInfo();
    if (mobile == NetworkInfo.State.CONNECTED
            || mobile == NetworkInfo.State.CONNECTING) {
        mobileFlag = true;
    }
    if (wifi == NetworkInfo.State.CONNECTED
            || wifi == NetworkInfo.State.CONNECTING) {
        wifiFlag = true;
    }

    if (wifiFlag == true || mobileFlag == true) {
        return true;
    }
    if (networkInfo != null && networkInfo.isConnected()) {
        return true;
    }

    return false;
}

public class Uploading extends AsyncTask<String, Integer, String> {
    ProgressDialog pd = new ProgressDialog(Upload.this);

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        pd.setTitle("Submitting Your Details");
        pd.setMessage("Please Wait...");
        pd.show();
    }

    @Override
    protected String doInBackground(String... params) {
        // TODO Auto-generated method stub

        dbHelper = new DataBaseHelper(Upload.this, DATABASE_NAME, null,
                DATABASE_VERSION);
        db = dbHelper.getReadableDatabase();
        cursor = db.query("FeedbackDetails", null, null, null, null, null,
                null);
        cursor.moveToFirst();

        while (cursor != null) {
            ID = cursor.getString(cursor.getColumnIndex("ID"));
            PNAME = cursor.getString(cursor.getColumnIndex("PNAME"));
            POUSERID = cursor.getString(cursor.getColumnIndex("POUSERID"));
            PEMAIL = cursor.getString(cursor.getColumnIndex("PEMAIL"));
            PUSERNAME = cursor
                    .getString(cursor.getColumnIndex("PUSERNAME"));
            PLOC = cursor.getString(cursor.getColumnIndex("PLOC"));
            TYPE_OF_PROMOTION = cursor.getString(cursor
                    .getColumnIndex("TYPE_OF_PROMOTION"));
            POUTlET_NAME = cursor.getString(cursor
                    .getColumnIndex("POUTlET_NAME"));
            CUST_TYPE = cursor
                    .getString(cursor.getColumnIndex("CUST_TYPE"));
            CNAME = cursor.getString(cursor.getColumnIndex("CNAME"));
            CEMAIL = cursor.getString(cursor.getColumnIndex("CEMAIL"));
            CMOB = cursor.getString(cursor.getColumnIndex("CMOB"));
            NO_EDGE = cursor.getString(cursor.getColumnIndex("NO_EDGE"));
            NO_MAG = cursor.getString(cursor.getColumnIndex("NO_MAG"));
            CONTACT_BY = cursor.getString(cursor
                    .getColumnIndex("CONTACT_BY"));
            RMKS = cursor.getString(cursor.getColumnIndex("RMKS"));
            RATINGS = cursor.getString(cursor.getColumnIndex("RATINGS"));
            DATE = cursor.getString(cursor.getColumnIndex("DATE"));

            ID_firstRow = ID;
            Log.d("ID_firstRow", ID_firstRow);
            String databaseurl = "http://www.pco.com/submitfeedback.php?location="
                    + PLOC
                    + "&typeofpromotion="
                    + TYPE_OF_PROMOTION
                    + "&outletname="
                    + POUTlET_NAME
                    + "&consumertype="
                    + CUST_TYPE
                    + "&edgebrochure="
                    + NO_EDGE
                    + "&magnatecbrochure="
                    + NO_MAG
                    + "&pcoemail="
                    + PEMAIL
                    + "&pconame="
                    + PNAME
                    + "&username="
                    + PUSERNAME
                    + "&fullname="
                    + CNAME
                    + "&email="
                    + CEMAIL
                    + "&mobile="
                    + CMOB
                    + "&contactby="
                    + CONTACT_BY
                    + "&ratingsystem="
                    + RATINGS
                    + "&remarks="
                    + RMKS
                    + "&datesubmitted=" + DATE;

            Log.d("Query", databaseurl);

            // check for Internet status
            if (networkOn(Upload.this)) {
                // Internet Connection is Present
                // make HTTP requests
                Log.d("XXX", "You have internet connection");
                List<NameValuePair> namevaluepairregis = new ArrayList<NameValuePair>();
                namevaluepairregis.add(new BasicNameValuePair("location",
                        PLOC));
                namevaluepairregis.add(new BasicNameValuePair(
                        "typeofpromotion", TYPE_OF_PROMOTION));
                namevaluepairregis.add(new BasicNameValuePair("outletname",
                        POUTlET_NAME));
                namevaluepairregis.add(new BasicNameValuePair(
                        "consumertype", CUST_TYPE));
                namevaluepairregis.add(new BasicNameValuePair(
                        "edgebrochure", NO_EDGE));
                namevaluepairregis.add(new BasicNameValuePair(
                        "magnatecbrochure", NO_MAG));
                namevaluepairregis.add(new BasicNameValuePair("pcoemail",
                        PEMAIL));
                namevaluepairregis.add(new BasicNameValuePair("pconame",
                        PNAME));
                namevaluepairregis.add(new BasicNameValuePair("username",
                        PUSERNAME));
                namevaluepairregis.add(new BasicNameValuePair("fullname",
                        CNAME));
                namevaluepairregis.add(new BasicNameValuePair("email",
                        CEMAIL));
                namevaluepairregis.add(new BasicNameValuePair("mobile",
                        CMOB));
                namevaluepairregis.add(new BasicNameValuePair("contactby",
                        CONTACT_BY));
                namevaluepairregis.add(new BasicNameValuePair(
                        "ratingsystem", RATINGS));
                namevaluepairregis.add(new BasicNameValuePair("remarks",
                        RMKS));
                namevaluepairregis.add(new BasicNameValuePair(
                        "datesubmitted", DATE));

                order = HttpReader
                        .httpDataReaderRequesternew(
                                "http://www.pco.com/submitfeedback.php?",
                                namevaluepairregis);
                Log.d("XXX", order);
                if (order != null) {
                    boolean val = isInteger(order);
                    if (val) {

                        Log.d("XXX",
                                "Thank You, Yours Details have been Successfully Submitted.");
                        cursor.moveToNext();
                        int deleted = deleteEntry(ID_firstRow);
                        Log.d("DeletedId", ID_firstRow);
                        Log.d("DeletedEntry", String.valueOf(deleted));
                        cursor.moveToFirst();

                    } else {

                        Log.d("XXX",
                                "Sorry,Details have not been Submitted.");
                        finish();

                    }
                }

            } else {
                Log.d("XXX", "You dont have internet connection");

            }

        }

        return order;

    }

    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);

        if (result != null) {
            boolean val = isInteger(result);
            if (val) {
                pd.dismiss();
                Toast.makeText(
                        Upload.this,
                        "Thank You, Yours Details have been Successfully Submitted.",
                        Toast.LENGTH_LONG).show();
            } else {
                pd.dismiss();
                Toast.makeText(Upload.this,
                        "Sorry,Details have not been Submitted.",
                        Toast.LENGTH_LONG).show();
            }
        }
    }

    public boolean isInteger(String s) {
        try {
            Integer.parseInt(s);
        } catch (NumberFormatException e) {
            return false;
        }
        // only got here if we didn't return false
        return true;

    }

}

}

0 个答案:

没有答案