private void btnConfirm_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show(this, "Are you sure about that?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { chiTietHDB.MaHDB = lbID.Text; chiTietHDB.MaSanPham = lbIDProduct.Text; chiTietHDB.SoLuong = Convert.ToInt32(numericUpDown1.Value); chiTietHDB.KhuyenMai = Convert.ToDouble(txtDiscount.Text); chiTietHDB.ThanhTien = Convert.ToDouble(lb2UnitPrice.Text) * Convert.ToInt32(numericUpDown1.Value); hoaDonBan.MaHDB = lbID.Text; hoaDonBan.MaNhanVien = txtIDSaler.Text; hoaDonBan.MaKhachHang = txtIdCustomer.Text; hoaDonBan.NgayBan = DateTime.Now; hoaDonBan.TongTien = Convert.ToDouble(lbTotalPrice.Text); phoneManagementDBEntities.ChiTietHDBs.Add(chiTietHDB); phoneManagementDBEntities.SaveChanges(); phoneManagementDBEntities.HoaDonBans.Add(hoaDonBan); phoneManagementDBEntities.SaveChanges(); SanPham sanPham = phoneManagementDBEntities.SanPhams.Find(lbIDProduct.Text); sanPham.SoLuong -= Convert.ToInt32(numericUpDown1.Value); phoneManagementDBEntities.SaveChanges(); MessageBox.Show(this, "Buy success", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); showProduct(); } panel3.Enabled = false; panel5.Enabled = false; }
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 (IDHoaDonNhap != null && IDChiTietHDN != null) { DialogResult dialogResult = MessageBox.Show(this, "Are you sure ?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialogResult == DialogResult.Yes) { ChiTietHDN dltChiTietHDN = dbAddNew.ChiTietHDNs.Where(p => p.MaHDN == (txtIdImport.Text).ToString()).SingleOrDefault(); HoaDonNhap dltHoaDonNhap = dbAddNew.HoaDonNhaps.Where(p => p.MaHDN == (txtIdImport.Text).ToString()).SingleOrDefault(); dbAddNew.ChiTietHDNs.Remove(dltChiTietHDN); dbAddNew.HoaDonNhaps.Remove(dltHoaDonNhap); dbAddNew.SaveChanges(); renewPanel(); } } else { MessageBox.Show(this, "Please select row to delele", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }