private void fDatHang_ChinhSua_Activated(object sender, EventArgs e) { int size = cboBoxSize.SelectedIndex; int amount = (int)numericAmount.Value; if (size != 0) { product = DAOTrangChu.Instance.getProductByID(fDatHang.mProductID + size); } DAOChiTietHoaDon.Instance.InsertNewDetailBill(fDatHang.mBillID, fDatHang.mProductID, amount, txtbNote.Text); for (int i = 0; i < amount; i++) { DetailBill detailBill = new DetailBill(); detailBill.IDBill = fDatHang.mBillID; detailBill.IDProduct = product.ID - size; detailBill.Name = product.TenMon; detailBill.Price = product.Gia.ToString() + "đ"; detailBill.Amount = amount; detailBill.BtnEdit.Click += editDetailBill; detailBill.BtnEdit.Tag = detailBill; detailBill.BtnDelete.Click += deleteDetailBill; detailBill.BtnDelete.Tag = detailBill; fDatHang.flpHoaDon.Controls.Add(detailBill); } this.Close(); }
private void deleteDetailBill(object sender, EventArgs e) { DetailBill detailBill = (sender as Button).Tag as DetailBill; fDatHang.mTongTien -= detailBill.Price; fDatHang.flpHoaDon.Controls.Remove(detailBill); DAOChiTietHoaDon.Instance.DeleteDetailBillByID(detailBill.ID); }
private void editDetailBill(object sender, EventArgs e) { DetailBill detailBill = (sender as Button).Tag as DetailBill; fDatHang.mProductID = detailBill.IDProduct; fDatHang_ChinhSua f = new fDatHang_ChinhSua(); f.ShowDialog(); }
private void fThanhToan_Load(object sender, EventArgs e) { btnThanhToan.Enabled = false; fLPHoaDon.Controls.Clear(); foreach (DetailBill item in fDatHang.flpHoaDon.Controls) { DetailBill detailBill = new DetailBill(item); detailBill.BtnDelete.Enabled = false; detailBill.BtnEdit.Enabled = false; fLPHoaDon.Controls.Add(detailBill); } txtbIDHoaDon.Text = fDatHang.mBillID.ToString(); txtbTongTien.Text = fDatHang.mTongTien.ToString(); }
private void deleteDetailBill(object sender, EventArgs e) { DetailBill detailBill = (sender as Button).Tag as DetailBill; fDatHang.flpHoaDon.Controls.Remove(detailBill); if (detailBill.Amount == 1) { DAOChiTietHoaDon.Instance.DeleteDetailBillByID(detailBill.IDBill, detailBill.IDProduct); } else { DAOChiTietHoaDon.Instance.UpdateDetailBillAmountByID(detailBill.IDBill, detailBill.IDProduct, detailBill.Amount - 1); } }
public DetailBill(DetailBill detailBill) { InitializeComponent(); ID = detailBill.ID; IDBill = detailBill.IDBill; IDProduct = detailBill.IDProduct; Name = detailBill.Name; Price = detailBill.Price; SizeValue = detailBill.SizeValue; btnEdit.Tag = detailBill; btnDelete.Tag = detailBill; BtnEdit = btnEdit; BtnDelete = btnDelete; }
private void btnAdd_Click(object sender, EventArgs e) { int size = cboBoxSize.SelectedIndex; int amount = (int)numericAmount.Value; if (size != 0) { product = DAOTrangChu.Instance.getProductByID(fDatHang.mProductID + size); } if (!update) { for (int i = 0; i < amount; i++) { DTOChiTietHoaDon cthd = DAOChiTietHoaDon.Instance.InsertNewDetailBill(fDatHang.mBillID, fDatHang.mProductID + size, cboBoxToppingSugar.Text, cboBoxToppingIce.Text, cboBoxSmell.Text, cboBoxTopping.Text, txtbNote.Text); DetailBill detailBill = new DetailBill(); detailBill.ID = cthd.ID; detailBill.IDBill = cthd.IDHoaDon; detailBill.IDProduct = fDatHang.mProductID; detailBill.Name = product.TenMon; detailBill.Price = product.Gia; detailBill.SizeValue = cboBoxSize.Text; detailBill.BtnEdit.Click += editDetailBill; detailBill.BtnEdit.Tag = detailBill; detailBill.BtnDelete.Click += deleteDetailBill; detailBill.BtnDelete.Tag = detailBill; fDatHang.flpHoaDon.Controls.Add(detailBill); fDatHang.mTongTien += product.Gia; } } else { fDatHang.mTongTien -= detailBillUpdate.Price; detailBillUpdate.Price = product.Gia; fDatHang.mTongTien += detailBillUpdate.Price; detailBillUpdate.SizeValue = cboBoxSize.Text; int index = fDatHang.flpHoaDon.Controls.GetChildIndex(detailBillUpdate); fDatHang.flpHoaDon.Controls.Add(detailBillUpdate); fDatHang.flpHoaDon.Controls.SetChildIndex(detailBillUpdate, index); DAOChiTietHoaDon.Instance.UpdateDetailBillInfoByID(detailBillUpdate.ID, detailBillUpdate.IDProduct + size, cboBoxToppingSugar.Text, cboBoxToppingIce.Text, cboBoxSmell.Text, cboBoxTopping.Text, txtbNote.Text); } this.Close(); }