protected void btnXoa_Click(object sender, EventArgs e) { if (KTMaSP(DropDownList2.Text) == false) { tbl_ImportDetail im = db.tbl_ImportDetails.SingleOrDefault(c => c.Import_ID == int.Parse(Label7.Text) && c.Product_ID == int.Parse(DropDownList2.Text)); db.tbl_ImportDetails.DeleteOnSubmit(im); var a = from s in db.tbl_ImportDetails where s.Import_ID == int.Parse(Label7.Text) && s.Product_ID == int.Parse(DropDownList2.Text) select new { s.Amount }; foreach (var item in a) { txtSL.Text = item.Amount.ToString(); tbl_Product t = db.tbl_Products.SingleOrDefault(c => c.Product_ID == int.Parse(DropDownList2.Text)); t.Amount = t.Amount - int.Parse(txtSL.Text); } db.SubmitChanges(); load(); rong(); Label6.Text = "Xoá thành công"; tinh(); } else { Label6.Text = "Sản phẩm này không có trong hoá đơn."; } }
public ActionResult AddDetail(int ImportID = 0, int ItemID = 0, int Qty = 0, decimal Price = 0) { var import = db.tbl_Imports.Find(ImportID); tbl_ImportDetail detail = import.tbl_ImportDetail.Where(a => a.ItemID == ItemID).FirstOrDefault(); if (detail != null) { detail.Qty += Qty; db.Entry(detail).State = EntityState.Modified; db.SaveChanges(); } else { detail = new tbl_ImportDetail(); detail.ItemID = ItemID; detail.ImportID = ImportID; detail.Qty = Qty; detail.Price = Price; db.tbl_ImportDetail.Add(detail); db.SaveChanges(); } tbl_Items item = db.tbl_Items.Find(ItemID); item.ItemCount += Qty; db.Entry(item).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Edit", new { id = ImportID })); }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { Label lblMa = (Label)GridView1.Rows[e.RowIndex].FindControl("lbMaSP"); tbl_ImportDetail im = db.tbl_ImportDetails.SingleOrDefault(c => c.Product_ID == int.Parse(lblMa.Text)); db.tbl_ImportDetails.DeleteOnSubmit(im); db.SubmitChanges(); load(); }
protected void btnNhap_Click(object sender, EventArgs e) { if (KTMaSP(DropDownList2.Text) && KTSoluong(txtSL.Text)) { if (KTSoluong(txtSL.Text)) { tbl_ImportDetail im = new tbl_ImportDetail(); im.Import_ID = int.Parse(Label7.Text); im.Product_ID = int.Parse(DropDownList2.Text); im.Price_Import = double.Parse(DropDownList3.Text); im.Amount = int.Parse(txtSL.Text); im.Money = double.Parse(txtThanhtien.Text); db.tbl_ImportDetails.InsertOnSubmit(im); tbl_Product t = db.tbl_Products.SingleOrDefault(c => c.Product_ID == int.Parse(DropDownList2.Text)); t.Amount = t.Amount + int.Parse(txtSL.Text); db.SubmitChanges(); load(); //tbl_Product p = db.tbl_Products.SingleOrDefault(c => c.Product_ID == int.Parse(Label7.Text)); //p.Amount = p.Amount + im.Amount; //+int.Parse(txtSL.Text); // //db.capnhatSL(int.Parse(Label7.Text), int.Parse(DropDownList2.Text)); //db.SubmitChanges(); Label6.Text = "Nhập thành công"; tinh(); //var a = from d in db.tbl_ImportDetails // where d.Product_ID == int.Parse(Label7.Text) // select d.Amount; //tbl_Product p = db.tbl_Products.SingleOrDefault(c => c.Product_ID == int.Parse(Label7.Text)); //p.Amount = p.Amount + int.Parse(txtSL.Text); //db.SubmitChanges(); } else { Label8.Text = "Bạn chưa nhập số lượng."; } } else { Label4.Text = "Sản phẩm này đã tồn tại.Bạn chỉ được sửa Số lượng."; txtThanhtien.Text = ""; var a = from s in db.tbl_ImportDetails where s.Import_ID == int.Parse(Label7.Text) && s.Product_ID == int.Parse(DropDownList2.Text) select new{ s.Amount }; foreach (var item in a) { txtSL.Text = item.Amount.ToString(); Label8.Text = "Số lượng hiện có trong hoá đơn."; } } }
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) { Label lblMa = (Label)GridView1.Rows[e.NewEditIndex].FindControl("lbMaSP"); tbl_ImportDetail im = db.tbl_ImportDetails.SingleOrDefault(c => c.Product_ID == int.Parse(lblMa.Text)); // txtMahoadon.Text = im.Import_ID.ToString(); DropDownList2.Text = im.Product_ID.ToString(); DropDownList3.Text = im.Price_Import.ToString(); txtSL.Text = im.Amount.ToString(); txtThanhtien.Text = im.Money.ToString(); GridView1.EditIndex = e.NewEditIndex; load(); }
public RedirectToRouteResult RemoveDetail(int ImportID, int ItemID) { var import = db.tbl_Imports.Find(ImportID); tbl_ImportDetail detail = import.tbl_ImportDetail.Where(a => a.ItemID == ItemID).FirstOrDefault(); if (detail != null) { db.tbl_ImportDetail.Remove(detail); tbl_Items item = db.tbl_Items.Find(ItemID); item.ItemCount -= detail.Qty.Value; db.Entry(item).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Edit", new { id = ImportID })); }