public void changesupplier(int itemcode,int purchaseid,string comname,string userid ) { var n = from a in ctx.purchase_item from b in ctx.purchases where (a.itemId == itemcode) && (b.purchaserId == purchaseid) &&(a.purchaseId==b.purchaserId) select a; purchase_item pt=n.SingleOrDefault(); int x = pt.itemId; ctx.purchase_item.Remove(pt); var l = from a in ctx.suppliers where a.compName == comname select a.supplierId; int ls = l.FirstOrDefault(); purchase po = new purchase(); po.supplierId = ls; po.purchaseDate = DateTime.Today.Date; po.expectedDeliveryDate = DateTime.Today.Date.AddDays(14); po.status = "waiting"; po.userId = userid; ctx.purchases.Add(po); var xo = from a in ctx.items where a.itemId == x select a; item xx = xo.SingleOrDefault(); purchase_item npt = new purchase_item(); npt.purchaseId = po.purchaserId; npt.itemId = xx.itemId; npt.requestQty = xx.reorderQty; npt.supplierid = ls; ctx.purchase_item.Add(npt); ctx.SaveChanges(); }
public List<Purchaseitem111> showpurchaseitems(purchase p) { int x1 = p.purchaserId; var n = from a in ctx.items from b in ctx.purchase_item from z in ctx.purchases from c in ctx.item_supplier from y in ctx.suppliers where a.itemId == b.itemId && b.purchaseId == z.purchaserId && a.itemId == c.itemId && c.supplierId == y.supplierId && z.purchaserId == p.purchaserId && b.supplierid == y.supplierId select new Purchaseitem111 { Itemcode = a.itemId, Description = a.description, Quantity = b.requestQty, price = c.price.Value, Amount = c.price.Value * b.requestQty }; return n.ToList(); }
// public void formorder(User u) { var n = from a in ctx.items where (a.balance < a.reorderlevel) && (a.status == "stockout") from c in ctx.item_supplier where a.itemId == c.itemId from b in ctx.suppliers where b.supplierId == c.supplierId && (c.priority == 1) select b; var d = from a in ctx.items where (a.balance < a.reorderlevel) && (a.status == "stockout") from c in ctx.item_supplier where a.itemId == c.itemId from b in ctx.suppliers where b.supplierId == c.supplierId && (c.priority == 1) select c; List<supplier> s = n.ToList(); List<item_supplier> ls = d.ToList(); foreach (supplier x in s) { purchase po = new purchase(); po.supplierId = x.supplierId; po.purchaseDate = DateTime.Today.Date; po.userId = u.UserId; po.expectedDeliveryDate = DateTime.Today.Date.AddDays(14); po.status = "waiting"; ctx.purchases.Add(po); ctx.SaveChanges(); foreach (item_supplier i in ls) { if (i.supplierId == x.supplierId) { var y = from a in ctx.items where a.itemId == i.itemId select a; item item = y.SingleOrDefault(); item.status = "ordering"; purchase_item pitem = new purchase_item(); pitem.purchaseId = po.purchaserId; pitem.itemId = i.itemId.Value; pitem.requestQty = item.reorderlevel; pitem.supplierid = po.supplierId; ctx.purchase_item.Add(pitem); ctx.SaveChanges(); } } } }
public purchase newpurchase(int supplierid,string userid) { purchase po = new purchase(); po.supplierId = supplierid; po.purchaseDate = DateTime.Today.Date; po.expectedDeliveryDate = DateTime.Today.Date.AddDays(14); po.status = "waiting"; po.userId = userid; ctx.purchases.Add(po); ctx.SaveChanges(); return po; }
public List<Purchaseitem111> showpurchaseitems(purchase p) { return f.showpurchaseitems(p); }