/// <summary> /// item 1 count = 4, goi ham nay voi item 1 count = 2 -> item 1 count =6 /// </summary> public static bool BeanShoppingCart_UpdateItemCount(BeanShoppingCart item) { try { if (File.Exists(DbFilePath)) { db = new SQLiteConnection(DbFilePath); List <BeanShoppingCart> data = BeanShoppingCart_LoadList(); foreach (BeanShoppingCart temp in data) { if (temp.MaMonAn == item.MaMonAn) { temp.SoLuong = temp.SoLuong + item.SoLuong; } } db.DeleteAll <BeanShoppingCart>(); foreach (BeanShoppingCart temp in data) { db.Insert(temp); } return(true); } return(false); } catch (Exception e) { throw; } }
private void Click_DialogOrder(object sender, EventArgs e) { AlertDialog.Builder builder = new AlertDialog.Builder(this); View root = LayoutInflater.Inflate(Resource.Layout.Layout_Food_Detail_AddItem, null); TextView _tvFoodName_Detail = root.FindViewById <TextView>(Resource.Id.AddItem_tvFoodName); TextView _tvPrice_Detail = root.FindViewById <TextView>(Resource.Id.AddItem_tvPrice); TextView _tvCount_Detail = root.FindViewById <TextView>(Resource.Id.AddItem_tvCount); Button _btnDecrease_Detail = root.FindViewById <Button>(Resource.Id.AddItem_btnDecrease); Button _btnIncrease_Detail = root.FindViewById <Button>(Resource.Id.AddItem_btnIncrease); Button _btnAdd_Detail = root.FindViewById <Button>(Resource.Id.AddItem_btnAdd); _tvFoodName_Detail.Text = _beanMonAn.TenMon.ToString(); _tvPrice_Detail.Text = String.Format("{0:#,0}", _beanMonAn.GiaTien).ToString() + " VNĐ"; _btnIncrease_Detail.Click += delegate { int _temp = int.Parse(_tvCount_Detail.Text); _temp = _temp + 1; _tvCount_Detail.Text = _temp.ToString(); _tvPrice_Detail.Text = String.Format("{0:#,0}", _beanMonAn.GiaTien * (_temp * 1.0)).ToString() + " VNĐ"; }; _btnDecrease_Detail.Click += delegate { int _temp = int.Parse(_tvCount_Detail.Text); if (_temp != 1) { _temp = _temp - 1; _tvCount_Detail.Text = _temp.ToString(); _tvPrice_Detail.Text = String.Format("{0:#,0}", _beanMonAn.GiaTien * (_temp * 1.0)).ToString() + " VNĐ"; } }; _btnAdd_Detail.Click += delegate { _dialog.Dismiss(); List <BeanShoppingCart> tempCart = SQLiteDataHandler.BeanShoppingCart_LoadList(); BeanShoppingCart addItem = new BeanShoppingCart(MaMon, int.Parse(_tvCount_Detail.Text)); if (tempCart != null && tempCart.Count > 0) { if (tempCart.Any(x => x.MaMonAn.Equals(MaMon))) // them so luong { SQLiteDataHandler.BeanShoppingCart_UpdateItemCount(addItem); Toast.MakeText(this, "Đã cập nhật số lượng", ToastLength.Long).Show(); } else { SQLiteDataHandler.BeanShoppingCart_AddItem(addItem); Toast.MakeText(this, "Đã thêm vào giỏ hàng", ToastLength.Long).Show(); } } else { SQLiteDataHandler.BeanShoppingCart_AddItem(addItem); Toast.MakeText(this, "Đã thêm vào giỏ hàng", ToastLength.Long).Show(); } }; builder.SetView(root); _dialog = builder.Create(); _dialog.Show(); }
public static bool BeanShoppingCart_AddItem(BeanShoppingCart item) { try { if (File.Exists(DbFilePath)) { db = new SQLiteConnection(DbFilePath); db.Insert(item); return(true); } return(false); } catch (Exception e) { throw; } }
public static bool BeanShoppingCart_UpdateItem(BeanShoppingCart item) { try { if (File.Exists(DbFilePath)) { List <BeanMonAn> data = BeanMonAn_LoadList(); db = new SQLiteConnection(DbFilePath); db.Update(item); return(true); } return(false); } catch (Exception e) { throw; } }
public static bool BeanShoppingCart_DeleteItem(BeanShoppingCart item) { try { if (File.Exists(DbFilePath)) { List <BeanShoppingCart> data = BeanShoppingCart_LoadList(); data.RemoveAll(x => x.MaMonAn == item.MaMonAn); db = new SQLiteConnection(DbFilePath); db.DeleteAll <BeanShoppingCart>(); foreach (BeanShoppingCart temp in data) { db.Insert(temp); } return(true); } return(false); } catch (Exception e) { throw; } }