/** 读取我的菜单数据 */ public ArrayList<HashMap<String, Object>> setElecartListView(Context context) { electrocartgoodslists.clear(); // 读取ele_cart缓存 DBHelper dbhelper = new DBHelper(context); Cursor c = dbhelper.query(DBHelper.ELE_CART_TM_NAME); c.moveToFirst(); while (!c.isAfterLast()) { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("goodsid", c.getString(c.getColumnIndex("goodsid"))); map.put("goodsname", c.getString(c.getColumnIndex("goodsname"))); map.put("memberprice", c.getString(c.getColumnIndex("memberprice"))); map.put("needquantity", c.getString(c.getColumnIndex("needquantity"))); int ineed = Integer.parseInt(map.get("needquantity").toString()); if (ineed >= 1) { electrocartgoodslists.add(map); } c.moveToNext(); } dbhelper.close(); return electrocartgoodslists; }
/** 将商品加入我的菜单 */ public void setGoodsToElecartSQLite( String goodsid, String goodsname, String memberprice, String pictureurl, String needquantity, Context context) { DBHelper dbhelper = new DBHelper(context); ContentValues values = new ContentValues(); values.put("goodsid", goodsid); values.put("goodsname", goodsname); values.put("memberprice", memberprice); values.put("pictureurl", pictureurl); values.put("needquantity", needquantity); Cursor c = dbhelper.queryByParamgoodsid(DBHelper.ELE_CART_TM_NAME, goodsid); int querycount = c.getCount(); if (querycount > 0) { dbhelper.updateByElecartNeedquantity(DBHelper.ELE_CART_TM_NAME, goodsid, "plus"); } else { dbhelper.insert(DBHelper.ELE_CART_TM_NAME, values); } dbhelper.close(); }