private void btnXoa_Click(object sender, EventArgs e) { Sell_icreamEntities db = new Sell_icreamEntities(); try { Bill_Item bit = db.Bill_Item.Single(st => st.id == ID2); DialogResult dr = MessageBox.Show("Bạn có chắc chắn Xóa?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { try { db.Bill_Item.Remove(bit); db.SaveChanges(); MessageBox.Show("Xóa thành công!"); this.LoadItem(ID); } catch (Exception) { MessageBox.Show("Xóa không thành công! "); } } else { return; } } catch (Exception) { MessageBox.Show("Vui lòng chọn lại món cần xóa!"); } }
private void btnOk_Click(object sender, EventArgs e) { //Add new item if (flag == 1) { Sell_icreamEntities db = new Sell_icreamEntities(); menu Menu = (menu)cboName.SelectedItem; string stmp = cboName.Text; try { Bill_Item tmp = db.Bill_Item.Single(st => st.C_Bill_id == ID && st.Item_id == Menu.id); int dem = int.Parse(tmp.Quality) + (int)SL.Value; tmp.Quality = dem.ToString(); db.Entry(tmp).State = EntityState.Modified; db.SaveChanges(); db.SaveChanges(); LoadItem(ID); } catch (Exception) { Bill_Item item = new Bill_Item(); item.C_Bill_id = ID; item.Item_id = Menu.id; item.Quality = SL.Value.ToString(); item.Price = Menu.Price; db.Bill_Item.Add(item); db.SaveChanges(); } LoadItem(ID); flag = 0; btnThemSP.Enabled = true; btnXoa.Enabled = true; btnSua.Enabled = true; } //Edit 1 Item in Bill if (flag == 2) { Sell_icreamEntities db = new Sell_icreamEntities(); try { Bill_Item bit = db.Bill_Item.Single(st => st.id == ID2); bit.Quality = SL.Value.ToString(); DialogResult dr = MessageBox.Show("Bạn có chắc chắn chỉnh sửa?", "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { try { db.Entry(bit).State = EntityState.Modified; db.SaveChanges(); MessageBox.Show("Cập nhật thành công!"); this.LoadItem(ID); } catch (Exception) { MessageBox.Show("Chỉnh sửa không thành công! "); } flag = 0; btnThemSP.Enabled = true; btnXoa.Enabled = true; btnSua.Enabled = true; btnHuy.Hide(); } else { return; } } catch (Exception) { MessageBox.Show("Vui lòng chọn lại món cần chỉnh sửa "); } } }