public void SpareOutgoDelete(int spareOutgoId) { objDataContext = new DriveEntities(); spare_outgo item = objDataContext.spare_outgo.FirstOrDefault(i => i.id == spareOutgoId); // сначала удалить все прикрепленные товары OutOfferingDeleteBySpareOutgoId(spareOutgoId); objDataContext.DeleteObject(item); objDataContext.SaveChanges(); }
public void SaleDelete(int SaleID) { objDataContext = new DriveEntities(); // delete baskets List<Basket> baskets = objDataContext.Baskets.Where(x => x.SaleID == SaleID).ToList(); List<int> spares = new List<int>(); foreach (Basket basket in baskets) { // delete offerings in basket List<OfferingInBasketItem> links = objDataContext.OfferingInBasketItems.Where(x => x.BasketItemID == basket.ID).ToList(); foreach (OfferingInBasketItem link in links) { // delete spare in spare outgo spare_in_spare_outgo siso = objDataContext.spare_in_spare_outgo.FirstOrDefault(x => x.id == link.OfferingOutgoID); if (siso != null) { objDataContext.DeleteObject(siso); } // edit spare in spare income spare_in_spare_income sisi = objDataContext.spare_in_spare_income.FirstOrDefault(x => x.id == link.OfferingIncomeID); if (sisi != null) { sisi.QRest += link.Q; } objDataContext.DeleteObject(link); } spares.Add(basket.SpareID.Value); objDataContext.DeleteObject(basket); } // delete sale Sale s = objDataContext.Sales.FirstOrDefault(x => x.ID == SaleID); if (s == null) return; objDataContext.DeleteObject(s); objDataContext.SaveChanges(); foreach (int SpareID in spares) SpareContainer.Instance.Update(SpareID); }
public void SpareIncomeDelete(int SpareIncomeID) { objDataContext = new DriveEntities(); spare_income item = objDataContext.spare_income.FirstOrDefault(i => i.id == SpareIncomeID); if (item == null) return; // удалить все прикрепленные товары Spare In SpareIncome //InOfferingDeleteBySpareIncomeId(spareIncomeId); spare_in_spare_income sisi = objDataContext.spare_in_spare_income.FirstOrDefault(i => i.spare_income.id == SpareIncomeID); while (sisi != null) { if (sisi.spare == null) sisi.spareReference.Load(); int SpareID = sisi.spare.id; int SpareInSpareIncomeID = sisi.id; // удалить завязанные на данный приход Spare In SpareOutgo //FixOfferingsOutsOnDeletingIncome(item.id); List<spare_in_spare_outgo> sisos = objDataContext.spare_in_spare_outgo.Where(x => x.spare_in_spare_income.id == SpareInSpareIncomeID).ToList(); foreach (spare_in_spare_outgo siso in sisos) { siso.spare_in_spare_income = null; } objDataContext.SaveChanges(); objDataContext.DeleteObject(sisi); objDataContext.SaveChanges(); SpareContainer.Instance.Update(SpareID); sisi = objDataContext.spare_in_spare_income.FirstOrDefault(i => i.spare_income.id == SpareIncomeID); } // удалить SpareIncome objDataContext = new DriveEntities(); item = objDataContext.spare_income.FirstOrDefault(i => i.id == SpareIncomeID); if (item == null) return; objDataContext.DeleteObject(item); objDataContext.SaveChanges(); }
public void RevisionDelete(int id) { objDataContext = new DriveEntities(); revision item = objDataContext.revisions.FirstOrDefault(i => i.id == id); if (item == null) return; // сначала удалить все прикрепленные товары OfferingsDeleteByRevisionId(id); objDataContext.DeleteObject(item); objDataContext.SaveChanges(); }
public void OverpricingDelete(int id) { objDataContext = new DriveEntities(); overpricing item = objDataContext.overpricings.FirstOrDefault(i => i.id == id); if (item == null) return; // откатить if (item.commited.Value) { RecalcIncomesPricesBack(item.id); } // сначала удалить все прикрепленные товары OfferingsDeleteByOverpricingId(id); objDataContext.DeleteObject(item); objDataContext.SaveChanges(); }
public void OutOfferingDelete(int offeringId) { objDataContext = new DriveEntities(); spare_in_spare_outgo offering = objDataContext.spare_in_spare_outgo.FirstOrDefault(i => i.id == offeringId); if (offering == null) return; // delete linked basket item OfferingInBasketItem oibi = objDataContext.OfferingInBasketItems.FirstOrDefault(x => x.OfferingOutgoID == offeringId); if (oibi != null) { int BasketID = oibi.BasketItemID; objDataContext.DeleteObject(oibi); Basket basket = objDataContext.Baskets.FirstOrDefault(x => x.ID == BasketID); if (basket != null) objDataContext.DeleteObject(basket); //objDataContext.SaveChanges(); } if (offering.spare_in_spare_income == null) offering.spare_in_spare_incomeReference.Load(); if (offering.spare_in_spare_income != null) { spare_in_spare_income sin = objDataContext.spare_in_spare_income.FirstOrDefault(s => s.id == offering.spare_in_spare_income.id); offering.spare_outgoReference.Load(); spare_outgo outgo = objDataContext.spare_outgo.FirstOrDefault(i => i.id == offering.spare_outgo.id); if (sin != null && outgo.isGhost != 1) sin.QRest += offering.quantity; } objDataContext.DeleteObject(offering); objDataContext.SaveChanges(); }
public void InvoiceDelete(int id) { objDataContext = new DriveEntities(); invoice item = objDataContext.invoices.FirstOrDefault(i => i.id == id); if (item == null) return; // сначала удалить все прикрепленные товары InvoiceOfferingsDelete(id); objDataContext.DeleteObject(item); objDataContext.SaveChanges(); }
public void InOfferingDelete(int offeringId) { int SpareID = -1; // получаем запись, которую собираемся удалять spare_in_spare_income offering = objDataContext.spare_in_spare_income.FirstOrDefault(i => i.id == offeringId); if (offering != null) { OfferingInBasketItem oibi = objDataContext.OfferingInBasketItems.FirstOrDefault(x => x.OfferingIncomeID == offeringId); if (oibi != null) { objDataContext.DeleteObject(oibi); objDataContext.SaveChanges(); } if (offering.spare == null) offering.spareReference.Load(); SpareID = offering.spare.id; // удаляем связанные с этим приходом переоценки OvOfferingDeleteBySISIID(offeringId); // удаляем связанные с этим поступлением отгрузки OutgoOfferingDeleteBySISIID(offeringId); try { objDataContext = new DriveEntities(); offering = objDataContext.spare_in_spare_income.FirstOrDefault(i => i.id == offeringId); if (offering != null) objDataContext.DeleteObject(offering); } catch (Exception) { } // delete offering in overpricing objDataContext.SaveChanges(); SpareContainer.Instance.Update(SpareID); } }