public void UpdateTrwNomenclature() { if (Nomenclature == null || Order == null) { return; } TrwSaleNomenclature old = _TrwSaleNomenclature; if (old == null || old.Order != Order || old.Nomenclature != Nomenclature) { IObjectSpace os = ObjectSpace.FindObjectSpaceByObject(this); _TrwSaleNomenclature = os.GetObjects <TrwSaleNomenclature>( new OperandProperty("Order") == Order & new OperandProperty("Nomenclature") == Nomenclature, true ).FirstOrDefault(); if (_TrwSaleNomenclature == null) { _TrwSaleNomenclature = os.CreateObject <TrwSaleNomenclature>(); _TrwSaleNomenclature.Order = Order; _TrwSaleNomenclature.Nomenclature = Nomenclature; } OnChanged("TrwSaleNomenclature", old, _TrwSaleNomenclature); } }
public void UpdateTrwNomenclature() { if (Nomenclature == null || Order == null) { return; } TrwSaleNomenclature old = _TrwSaleNomenclature; if (old == null || old.Order != Order || old.Nomenclature != Nomenclature) { IObjectSpace os = ObjectSpace.FindObjectSpaceByObject(this); _TrwSaleNomenclature = os.GetObjects <TrwSaleNomenclature>( new OperandProperty("Order") == Order & new OperandProperty("Nomenclature") == Nomenclature, true).FirstOrDefault(); if (_TrwSaleNomenclature == null) { _TrwSaleNomenclature = os.CreateObject <TrwSaleNomenclature>(); _TrwSaleNomenclature.Order = Order; _TrwSaleNomenclature.Nomenclature = Nomenclature; TrwOrder trw_order = Order.Subject.TrwOrders.FirstOrDefault(x => x.Deal == this.DeliveryUnit.DealVersion.ContractDeal); if (trw_order == null) { Order.Subject.Deals.Add(this.DeliveryUnit.DealVersion.ContractDeal); trw_order = Order.Subject.TrwOrders.FirstOrDefault(x => x.Deal == this.DeliveryUnit.DealVersion.ContractDeal); } if (trw_order != null) { trw_order.TrwSaleNomenclatures.Add(_TrwSaleNomenclature); } } OnChanged("TrwSaleNomenclature", old, _TrwSaleNomenclature); } }
private void UpdateContractDeals() { using (IObjectSpace os = ObjectSpace.CreateNestedObjectSpace()) { crmUserParty cfr = os.GetObjects <crmUserParty>().FirstOrDefault(x => x.Party.Code == "2518"); IList <TrwSaleNomenclature> sale_noms = os.GetObjects <TrwSaleNomenclature>(); IList <crmContractDeal> deals = os.GetObjects <crmContractDeal>(); foreach (crmContractDeal deal in deals) { if (deal.Current != null) { if (deal.Current.Customer != null && deal.Current.Supplier != null) { if (deal.Current.Customer.CfrUserParty != null && deal.Current.Supplier.CfrUserParty == null) { deal.Current.Customer.CfrUserParty = null; deal.Current.Supplier.CfrUserParty = cfr; } else if (deal.Current.Customer.CfrUserParty == null && deal.Current.Supplier.CfrUserParty != null) { deal.Current.Customer.CfrUserParty = cfr; deal.Current.Supplier.CfrUserParty = null; } } } crmDealWithStage deal_ws = deal as crmDealWithStage; if (deal_ws != null) { crmDealWithStageVersion deal_ws_version = deal_ws.Current as crmDealWithStageVersion; if (deal_ws_version == null) { continue; } foreach (crmStage stage in deal_ws_version.StageStructure.Stages) { if (stage.DeliveryUnits == null) { continue; } foreach (crmDeliveryUnit unit in stage.DeliveryUnits) { foreach (crmDeliveryItem item in unit.DeliveryItems) { if (item.Nomenclature == null) { continue; } if (item.Order == null || item.Nomenclature == null) { continue; } TrwSaleNomenclature nom = sale_noms.FirstOrDefault(x => x.Order == item.Order && x.Nomenclature == item.Nomenclature); if (nom == null) { nom = os.CreateObject <TrwSaleNomenclature>(); nom.Order = item.Order; nom.Nomenclature = item.Nomenclature; } nom.TrwCodeSet(nom.Order.Code + ".9" + nom.Nomenclature.Code); foreach (TrwOrder trw_order in deal_ws.TrwOrders) { if (trw_order.Subject == nom.Order.Subject) { trw_order.TrwSaleNomenclatures.Add(nom); } } } } } } } os.CommitChanges(); } }