private void btnSave_Click(object sender, EventArgs e) { if (state == 1) { chiTietHDB.MaHDB = txtIdExport.Text; chiTietHDB.MaSanPham = txtIdProduct.Text; chiTietHDB.SoLuong = Convert.ToInt32(txtQuantity.Text); chiTietHDB.KhuyenMai = Convert.ToDouble(txtIdPromo.Text); chiTietHDB.ThanhTien = Convert.ToDouble(lbAllPrice.Text); hoaDonBan.MaHDB = txtIdExport.Text; hoaDonBan.MaKhachHang = txtIdCustomer.Text; hoaDonBan.MaNhanVien = txtIdSaler.Text; hoaDonBan.NgayBan = DateTime.Now; hoaDonBan.TongTien = Convert.ToDouble(lbTotalPrice.Text); dbBills.ChiTietHDBs.Add(chiTietHDB); dbBills.SaveChanges(); dbBills.HoaDonBans.Add(hoaDonBan); dbBills.SaveChanges(); renewPanel(); } if (state == 2) { ChiTietHDB editChiTietHDB = dbBills.ChiTietHDBs.Find(IDChiTietHDB); HoaDonBan editHoaDonBan = dbBills.HoaDonBans.Find(IDHoaDonBan); editChiTietHDB.MaHDB = editChiTietHDB.MaHDB; editChiTietHDB.MaSanPham = txtIdProduct.Text; editChiTietHDB.SoLuong = Convert.ToInt32(txtQuantity.Text); editChiTietHDB.KhuyenMai = Convert.ToDouble(txtIdPromo.Text); editChiTietHDB.ThanhTien = Convert.ToDouble(lbAllPrice.Text); editHoaDonBan.MaHDB = editHoaDonBan.MaHDB; editHoaDonBan.MaKhachHang = txtIdCustomer.Text; editHoaDonBan.MaNhanVien = txtIdSaler.Text; editHoaDonBan.NgayBan = DateTime.Now; editHoaDonBan.TongTien = Convert.ToDouble(lbTotalPrice.Text); dbBills.SaveChanges(); renewPanel(); } }
private void btnDelete_Click(object sender, EventArgs e) { if (IDHoaDonBan != null && IDChiTietHDB != null) { DialogResult dialogResult = MessageBox.Show(this, "Are you sure ?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { ChiTietHDB dltChiTietHDB = dbBills.ChiTietHDBs.Where(p => p.MaHDB == (txtIdExport.Text).ToString()).SingleOrDefault(); HoaDonBan dltHoaDonBan = dbBills.HoaDonBans.Where(p => p.MaHDB == (txtIdExport.Text).ToString()).SingleOrDefault(); dbBills.ChiTietHDBs.Remove(dltChiTietHDB); dbBills.HoaDonBans.Remove(dltHoaDonBan); dbBills.SaveChanges(); renewPanel(); } } else { MessageBox.Show(this, "Please select row to delele", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }