private void UpdateInventory(string[] szHeaders, string[] szRow, TimelyDepotContext db, ITEM item, int nPos, ref string szError) { //Asume // 0 = ItemId // 1 = PROD_CD // 2 = UnitperCase // 3 = CaseWeight // 4 = UnitWeight // 5 = CaseDimensionL // 6 = CaseDimensionW // 7 = CaseDimensionH string szItemId = ""; szError = ""; try { szItemId = szRow[0]; item = db.ITEMs.Where(itm => itm.ItemID == szItemId).FirstOrDefault<ITEM>(); if (item != null) { item.UnitPerCase = szRow[2]; item.CaseWeight = szRow[3]; item.UnitWeight = szRow[4]; item.CaseDimensionL = szRow[5]; item.CaseDimensionW = szRow[6]; item.CaseDimensionH = szRow[7]; db.Entry(item).State = EntityState.Modified; db.SaveChanges(); } } catch (Exception err) { szError = string.Format("Row {0}: {1} {2}", nPos, err.Message, err.StackTrace); } }
// // GET: /PurchaseOrder/ReceivePurchaseOrder public ActionResult ReceivePurchaseOrder(int id) { double dPO_Dr = 0; DateTime dDate = DateTime.Now; TimelyDepotContext db01 = new TimelyDepotContext(); SUB_ITEM subitem = null; IQueryable<PurchasOrderDetail> qrypodetails = null; PurchaseOrders purchaseorders = db.PurchaseOrders.Find(id); if (string.IsNullOrEmpty(purchaseorders.ReceiveStatus)) { //Upate inventory qrypodetails = db.PurchasOrderDetails.Where(podt => podt.PurchaseOrderId == id); if (qrypodetails.Count() > 0) { foreach (var item in qrypodetails) { if (!string.IsNullOrEmpty(item.ItemID)) { subitem = db01.SUB_ITEM.Where(sbit => sbit.ItemID == item.ItemID && sbit.Sub_ItemID == item.Sub_ItemID).FirstOrDefault<SUB_ITEM>(); if (subitem != null) { dPO_Dr = Convert.ToDouble(item.Quantity); subitem.OpenPO_Db = subitem.OpenPO_Db + dPO_Dr; db01.Entry(subitem).State = EntityState.Modified; } } } db01.SaveChanges(); } purchaseorders.ReceiveStatus = string.Format("Received on {0}", dDate.ToString("MMM/dd/yyyy")); db.Entry(purchaseorders).State = EntityState.Modified; db.SaveChanges(); } return RedirectToAction("Index"); }