private void btnDeleteEx_Click(object sender, EventArgs e) { FExportBill fExportBill = new FExportBill(); var IDEx1 = Convert.ToInt32(dgrvEx.CurrentRow.Cells["ID"].Value.ToString()); var list = db.ProductDetails.Where(x => x.IDExBill == IDEx1).ToList(); foreach (var item in list) { FProductDetail dt = new FProductDetail(); dt.Delete(item.ID); } fExportBill.Delete(IDEx1); BindingdgrvEx(); }
private void btnEdit_Click_1(object sender, EventArgs e) { ImportBill entity = new ImportBill(); entity.ID = IDImBill; entity.Bill = txtBillName.Text; entity.IDWareHouse = Convert.ToInt32(cbWH.SelectedValue); entity.Date = dateTimePicker.Value; entity.Quantity = Convert.ToInt32(txtQuantity.Text); entity.TotalPrice = Convert.ToInt32(txtMoney.Text); FImportBill im = new FImportBill(); var result = im.Update(entity); var listolder = (from dt in db.ProductDetails.Where(x => x.IDImBill == IDImBill).ToList() from pr in db.Products.Where(x => x.ID == dt.IDProduct).ToList() from com in db.Companies.Where(x => x.ID == pr.IDCompany).ToList() select new { IDProductDetail = dt.ID, ID = pr.ID, Product1 = pr.Product1, Quantity = dt.Quantity, OrdinaryPrice = pr.OrdinaryPrice } ).ToList(); foreach (var item in lprodt) { var search = listolder.Find(x => x.ID == item.IDProduct); if (search == null) { FProductDetail dt = new FProductDetail(); dt.Insert(item); } else { item.ID = search.IDProductDetail; FProductDetail dt = new FProductDetail(); dt.Update(item); } } if (result == true) { MessageBox.Show("Sửa phiếu nhập thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnDeleteDTWH_Click(object sender, EventArgs e) { FProductDetail fprodt = new FProductDetail(); var IDwh = Convert.ToInt32(dgrvWH.CurrentRow.Cells["ID"].Value.ToString()); var IDpro = Convert.ToInt32(dgrvDetailWH.CurrentRow.Cells["ID"].Value.ToString()); var IDprodt = (from wh in db.WareHouses.Where(x => x.ID == IDwh).ToList() from prodt in db.ProductDetails.Where(z => z.IDProduct == IDpro).ToList() select new { ID = prodt.ID } ).ToList(); foreach (var item in IDprodt) { var a = Convert.ToInt32(item.ID.ToString()); fprodt.Delete(a); } Binding_dgrDetailWH(); }
private void btnAdd_Click(object sender, EventArgs e) { ExportBill entity = new ExportBill(); entity.Bill = txtBillName.Text; entity.IDWareHouse = Convert.ToInt32(cbWH.SelectedValue); entity.Date = dateTimePicker.Value; entity.Quantity = Convert.ToInt32(txtQuantity.Text); entity.TotalPrice = Convert.ToInt32(txtMoney.Text); FExportBill Ex = new FExportBill(); var result = Ex.Insert(entity); foreach (var item in lprodt) { item.IDExBill = entity.ID; FProductDetail dt = new FProductDetail(); dt.Insert(item); } if (result == true) { MessageBox.Show("Thêm phiếu nhập thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } }