//获取当前用户所有历史订单数据
public ArrayList<Order> getOrdersbyTableIndex(String username){
//map表key是订单编号
ArrayList<Order> orders = new ArrayList<Order>();
HashMap<String, ArrayList<Dish>> ordersmap = new HashMap<String, ArrayList<Dish>>();
ArrayList<Dish> dishes = new ArrayList<Dish>();
if(TextUtils.isEmpty(username)){
return orders;
}
SQLiteDatabase db = this.getWritableDatabase();
Cursor cur = db.rawQuery("SELECT * FROM "+TABLE_ORDER, null);
if (cur != null) {
if (cur.moveToFirst()) {
do {
int numColumn = cur.getColumnIndex(DISH_USERNAME);
String o_tableindex = cur.getString(numColumn);
if(username.equals(o_tableindex)){
int COLID = cur.getColumnIndex(ORDER_ID);
String d_id = cur.getString(COLID);
if(ordersmap.containsKey(d_id)){
dishes = ordersmap.get(d_id);
}else{
dishes = new ArrayList<Dish>();
ordersmap.put(d_id, dishes);
}
int NUMPASS = cur.getColumnIndex(DISH_NAME);
String d_name = cur.getString(NUMPASS);
int COLPRICE = cur.getColumnIndex(DISH_PRICE);
int d_price = Integer.parseInt(cur.getString(COLPRICE).toString());
int COLPIC = cur.getColumnIndex(DISH_PIC);
int d_pic = Integer.parseInt(cur.getString(COLPIC).toString());
int COLNUM = cur.getColumnIndex(DISH_NUM);
int d_num = Integer.parseInt(cur.getString(COLNUM).toString());
int COLSHOP = cur.getColumnIndex(DISH_SHOP);
String c_shop = cur.getString(COLSHOP);
Dish dish = new Dish(d_name,d_price,d_pic,d_num, c_shop);
dishes.add(dish);
}
}while( cur.moveToNext());
}
}
db.close();
for(String key: ordersmap.keySet()){
Order order = new Order(key, ordersmap.get(key));
orders.add(order);
}
System.out.print("获取订单数量:" + orders.size());
return orders;
}
alionSSS
cuni
相关分类