private List <SellProductDto> InnerUpdateProductOnhand(ProductDbContext context, IEnumerable <BuyProductDto> buyItems) { List <SellProductDto> result = new List <SellProductDto>(); foreach (BuyProductDto item in buyItems) { ProductEntity entity = new ProductEntity() { ID = item.ProductId, Onhand = item.BuyNumber }; OQL q = OQL.From(entity) .UpdateSelf('-', entity.Onhand) .Where(cmp => cmp.EqualValue(entity.ID) & cmp.Comparer(entity.Onhand, ">=", item.BuyNumber)) .END; int count = context.ProductQuery.ExecuteOql(q); SellProductDto sell = new SellProductDto(); sell.BuyNumber = item.BuyNumber; sell.ProductId = item.ProductId; //修改库存成功,才能得到发货地 if (count > 0) { sell.StoreHouse = this.GetStoreHouse(item.ProductId); } result.Add(sell); } base.CurrentContext.Session.Set <ProductDbContext>("DbContext", context); Console.WriteLine("----------1,-Session ID:{0}----------", base.CurrentContext.Session.SessionID); return(result); }
public string SellProduct(SellProductDto sellInformation, DateTime dateCreate) { try { using (var dbContext = new XeNangEntities()) { var productInStock = (dbContext.Khoes.First(p => p.ID == sellInformation.ID_Product)); if (productInStock.SoLuong < sellInformation.Quantities) { return(Constant.MESSAGE_ERROR); } dbContext.BanHangs.Add(new BanHang() { ID_Product = sellInformation.ID_Product, NgayBan = dateCreate, SoLuong = sellInformation.Quantities, ID = (from s in dbContext.BanHangs select s.ID).Count() + 1 }); productInStock.NgayUpdated = dateCreate; productInStock.SoLuong -= sellInformation.Quantities; dbContext.SaveChanges(); return(Constant.MESSAGE_SUCCESS); } } // CATCH EXEPTION FOR DEBUG PURPOSE catch (DbEntityValidationException ex) { foreach (var e in ex.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", e.Entry.Entity.GetType().Name, e.Entry.State); foreach (var ve in e.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } return(Constant.MESSAGE_ERROR); } catch (DbUpdateException ex) { return(Constant.MESSAGE_ERROR); } }
private void btn_Them_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(cbb_LoaiSanPham.Text.ToString())) { MessageBox.Show("Vui lòng chọn loại sản phẩm!!", "Thông báo!!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (string.IsNullOrEmpty(tb_TenSanPham.Text.ToString())) { MessageBox.Show("Vui lòng chọn tên sản phẩm!!", "Thông báo!!", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_TenSanPham.Focus(); } else if (string.IsNullOrEmpty(tb_SoLuong.Text.ToString())) { MessageBox.Show("Vui lòng chọn số lượng sản phẩm!!", "Thông báo!!", MessageBoxButtons.OK, MessageBoxIcon.Information); tb_SoLuong.Focus(); } else { NgayBan = DateTime.Parse(dtp_NgayBan.Text.ToString()); ID = Helper.GetIDFromName(tb_TenSanPham.Text); SellProductDto sell = new SellProductDto(); ProductRepo pro = new ProductRepo(); sell.ID_Product = ID; sell.ProductName = tb_TenSanPham.Text.ToString(); sell.Quantities = Int32.Parse(tb_SoLuong.Text.ToString()); sell.Category = Loai; sell.DateOfSale = NgayBan; DialogResult dlg = MessageBox.Show("Xác nhận thông tin sản phẩm đã chính xác!!", "Thông báo!!", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); if (dlg.Equals(DialogResult.OK)) { ProductService sv = new ProductService(); sv.SellProduct(sell, NgayBan); MessageBox.Show("Đã thêm sản phẩm!!", "Thông báo!!", MessageBoxButtons.OK, MessageBoxIcon.Information); fillData(); HelperUI.ResetAllControls(groupBox1); } } } catch { } }
public string SellProduct(SellProductDto sellInformation, DateTime dateCreate) { return(_repository.SellProduct(sellInformation, dateCreate)); }