private static void RemoveAllIDbInventoryItems(POSAIData.POSAIEntities db) { foreach (POSAIData.InventoryItem eitm in db.InventoryItems) { db.InventoryItems.Remove(eitm); } }
private static void RemoveExistingAdjustment(POSAIData.POSAIEntities db, InventoryQtyAdjustmentRet qbadj) { var xadj = (from i in db.InventoryAdjustments where i.TxnID == qbadj.TxnID select i).FirstOrDefault(); if (xadj == null) { return; } db.InventoryAdjustments.Remove(xadj); }
private static void RemoveExistingDbReceipts(POSAIData.POSAIEntities db, SalesReceiptRet saleReceipt) { POSAIData.SalesReceipt xr = (POSAIData.SalesReceipt)(from er in db.SalesReceipts where er.SalesReceiptNumber == saleReceipt.SalesReceiptNumber select er).FirstOrDefault(); if (xr != null) { db.SalesReceipts.Remove(xr); // db.SaveChanges(); } }
private void SaveToDataBase(TrackableCollection <SalesReceiptRet> trackableCollection) { try { POSAIData.POSAIEntities db = new POSAIData.POSAIEntities(); foreach (SalesReceiptRet saleReceipt in trackableCollection) { POSAIData.SalesReceipt sr = new POSAIData.SalesReceipt(); RemoveExistingDbReceipts(db, saleReceipt); sr.SalesReceiptNumber = saleReceipt.SalesReceiptNumber; sr.TxnDate = saleReceipt.TxnDate; // do details foreach (POSAI_mvvm.QuickBooks.SalesReceiptRetSalesReceiptItemRet saleReceiptDetail in saleReceipt.SalesReceiptItems) { POSAIData.SalesReceiptDetails itm = new POSAIData.SalesReceiptDetails(); itm.ItemListID = saleReceiptDetail.ListID; itm.Tax = saleReceiptDetail.TaxAmount; itm.QtySold = System.Convert.ToDecimal(saleReceiptDetail.Qty); itm.ItemKey = saleReceiptDetail.Desc1 + "|" + saleReceiptDetail.Desc2 + "|" + saleReceiptDetail.Attribute + "|" + saleReceiptDetail.Size; itm.ItemALU = saleReceiptDetail.ALU; itm.ItemDesc1 = saleReceiptDetail.Desc1; itm.ItemDesc2 = saleReceiptDetail.Desc2; sr.SalesReceiptDetails.Add(itm); } db.SalesReceipts.Add(sr); } db.SaveChanges(); MessageBox.Show("Sale Receipt Import Complete"); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } catch (Exception e) { throw e; } }
private void SaveToDataBase(TrackableCollection <InventoryQtyAdjustmentRet> trackableCollection) { try { POSAIData.POSAIEntities db = new POSAIData.POSAIEntities(); foreach (InventoryQtyAdjustmentRet qbadj in trackableCollection) { RemoveExistingAdjustment(db, qbadj); POSAIData.InventoryAdjustment adj = new POSAIData.InventoryAdjustment(); adj.AdjustmentNumber = qbadj.InventoryAdjustmentNumber.ToString(); adj.AdjustmentSource = qbadj.InventoryAdjustmentSource; adj.TxnDate = qbadj.TxnDate; adj.TxnID = qbadj.TxnID; foreach (var qbadjitm in qbadj.InventoryQtyAdjustmentItemRet) { POSAIData.InventoryAdjustmentItem adjitm = new POSAIData.InventoryAdjustmentItem(); adjitm.ItemListID = qbadjitm.ListID; adjitm.NewQuantity = qbadjitm.NewQuantity; adjitm.OldQuantity = qbadjitm.OldQuantity; adjitm.QuantityDifference = qbadjitm.QtyDifference; adj.InventoryAdjustmentItems.Add(adjitm); } db.InventoryAdjustments.Add(adj); } db.SaveChanges(); MessageBox.Show("Inventory Adjustment Import Complete"); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } catch (Exception e) { throw e; } }
private void SaveInventoryToDB(TrackableCollection <ItemInventoryRet> trackableCollection) { POSAIData.POSAIEntities db = new POSAIData.POSAIEntities(); RemoveAllIDbInventoryItems(db); foreach (ItemInventoryRet itm in trackableCollection) { POSAIData.InventoryItem i = new POSAIData.InventoryItem(); i.ALU = itm.ALU; i.Attribute = itm.Attribute; i.DepartmentCode = itm.DepartmentCode; i.ItemDesc1 = itm.Desc1; i.ItemDesc2 = itm.Desc2; i.ItemNumber = System.Convert.ToInt32(itm.ItemNumber); i.ItemType = itm.ItemType; i.ListID = itm.ListID; i.Size = itm.Size; db.InventoryItems.Add(i); } try { db.SaveChanges(); System.Windows.MessageBox.Show("Inventory Items Import Complete"); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } }