private void PurchaseOrderUpdateMethod(new_aprove_price _proxyentity, List <new_port> _portList, OrganizationServiceContext orgContext, IOrganizationService service) { List <new_purchase_order> _orderListForUpdate = (from i in orgContext.CreateQuery <new_purchase_order>() where i.new_cropid.Id == _proxyentity.new_cropid.Id && (i.new_status == new OptionSetValue(100000000) || i.new_status == new OptionSetValue(100000001)) select i).ToList(); if (_orderListForUpdate != null) { foreach (var item in _orderListForUpdate) { new_purchase_order_change _newChangeOrder = new new_purchase_order_change(); _newChangeOrder.new_cropid = item.new_cropid; _newChangeOrder.new_purchase_price = item.new_purchase_price; _newChangeOrder.new_purchase_order = new EntityReference() { Id = item.Id, LogicalName = item.LogicalName }; service.Create(_newChangeOrder); new_purchase_order _updateOrder = new new_purchase_order(); _updateOrder.Id = item.Id; if (item.new_portid == null) { continue; } if (_portList.Where(x => x.Id == item.new_portid.Id).FirstOrDefault().new_name == "Одеса") { _updateOrder.new_purchase_price = _proxyentity.new_recom_purchase_price_odessa; } else if (_portList.Where(x => x.Id == item.new_portid.Id).FirstOrDefault().new_name == "Миколаїв") { _updateOrder.new_purchase_price = _proxyentity.new_recom_purchase_price_nikolaev; } service.Update(_updateOrder); } } }
private void PurchaseOrderUpdateMethod(new_aprove_price _proxyentity, List<new_port> _portList, OrganizationServiceContext orgContext, IOrganizationService service) { List<new_purchase_order> _orderListForUpdate = (from i in orgContext.CreateQuery<new_purchase_order>() where i.new_cropid.Id == _proxyentity.new_cropid.Id && (i.new_status == new OptionSetValue(100000000) || i.new_status == new OptionSetValue(100000001)) select i).ToList(); if ( _orderListForUpdate != null ) { foreach ( var item in _orderListForUpdate ) { new_purchase_order_change _newChangeOrder = new new_purchase_order_change(); _newChangeOrder.new_cropid = item.new_cropid; _newChangeOrder.new_purchase_price = item.new_purchase_price; _newChangeOrder.new_purchase_order = new EntityReference() { Id = item.Id, LogicalName = item.LogicalName }; service.Create(_newChangeOrder); new_purchase_order _updateOrder = new new_purchase_order(); _updateOrder.Id = item.Id; if ( item.new_portid == null ) continue; if ( _portList.Where(x => x.Id == item.new_portid.Id).FirstOrDefault().new_name == "Одеса" ) { _updateOrder.new_purchase_price = _proxyentity.new_recom_purchase_price_odessa; } else if ( _portList.Where(x => x.Id == item.new_portid.Id).FirstOrDefault().new_name == "Миколаїв" ) { _updateOrder.new_purchase_price = _proxyentity.new_recom_purchase_price_nikolaev; } service.Update(_updateOrder); } } }
private void CreateMethod(IPluginExecutionContext context, IOrganizationService service) { try { bool _havePlan = false; Entity _correntEntity; using (var orgContext = new OrganizationServiceContext(service)) { _correntEntity = (Entity)context.InputParameters["Target"]; new_purchase_order _proxyentity = _correntEntity.ToEntity <new_purchase_order>(); if (_proxyentity.new_cropid == null || _proxyentity.new_volume == null || _proxyentity.new_volume.Value == 0 || _proxyentity.new_approve_purchase_order != false || _proxyentity.new_yearid == null) { return; } _havePlan = _proxyentity.new_line_planningid == null ? false : true; EntityReference _planingToUpdate = FindPlaning(orgContext, _proxyentity.new_cropid, _proxyentity.new_yearid); if (_planingToUpdate != null) { double?_sumOfVolume = (from i in orgContext.CreateQuery <new_purchase_order>() where i.new_cropid.Id == _proxyentity.new_cropid.Id && i.new_yearid.Id == _proxyentity.new_yearid.Id && i.new_status != new OptionSetValue(100000002) && i.new_approve_purchase_order == true select i.new_volume).ToList().Sum(); new_line_purchase_planning _UpdatePlan = new new_line_purchase_planning() { Id = _planingToUpdate.Id, new_total_volume_tn = _sumOfVolume }; List <new_port> _portList = (from port in orgContext.CreateQuery <new_port>() where port.new_name == "Одеса" || port.new_name == "Миколаїв" select port).ToList(); foreach (var item in _portList) { double?_sumOfVolumeFromPort = (from i in orgContext.CreateQuery <new_purchase_order>() where i.new_cropid.Id == _proxyentity.new_cropid.Id && i.new_yearid.Id == _proxyentity.new_yearid.Id && i.new_status != new OptionSetValue(100000002) && i.new_portid.Id == item.Id && i.new_approve_purchase_order == true select i.new_volume).ToList().Sum(); if (item.new_name == "Одеса") { _UpdatePlan.new_volume_Odesa = _sumOfVolumeFromPort; } else if (item.new_name == "Миколаїв") { _UpdatePlan.new_volume_Mykolaiv = _sumOfVolumeFromPort; } } service.Update(_UpdatePlan); _proxyentity.new_line_planningid = new EntityReference() { Id = _UpdatePlan.Id, LogicalName = new_line_purchase_planning.EntityLogicalName }; } else { double?_sumOfVolume = (from i in orgContext.CreateQuery <new_purchase_order>() where i.new_cropid.Id == _proxyentity.new_cropid.Id && i.new_status != new OptionSetValue(100000002) select i.new_volume).ToList().Sum(); new_line_purchase_planning _createPlan = new new_line_purchase_planning() { new_total_volume_tn = _sumOfVolume, new_cropid = _proxyentity.new_cropid, new_planningid = _proxyentity.new_yearid }; List <new_port> _portList = (from port in orgContext.CreateQuery <new_port>() where port.new_name == "Одеса" || port.new_name == "Миколаїв" select port).ToList(); foreach (var item in _portList) { double?_sumOfVolumeFromPort = (from i in orgContext.CreateQuery <new_purchase_order>() where i.new_cropid.Id == _proxyentity.new_cropid.Id && i.new_yearid.Id == _proxyentity.new_yearid.Id && i.new_status != new OptionSetValue(100000002) && i.new_portid.Id == item.Id && i.new_approve_purchase_order == true select i.new_volume).ToList().Sum(); if (item.new_name == "Одеса") { _createPlan.new_volume_Odesa = _sumOfVolumeFromPort; } else if (item.new_name == "Миколаїв") { _createPlan.new_volume_Mykolaiv = _sumOfVolumeFromPort; } } Guid _newRecordId = service.Create(_createPlan); _proxyentity.new_line_planningid = new EntityReference() { Id = _newRecordId, LogicalName = new_line_purchase_planning.EntityLogicalName }; } } } catch (Exception ex) { throw new InvalidPluginExecutionException(ex.Message); } }
private void DeleteMethod(IPluginExecutionContext context, IOrganizationService service) { bool _havePlan = false; Entity _correntEntity; using (var orgContext = new OrganizationServiceContext(service)) { _correntEntity = (Entity)context.PreEntityImages["Pre"]; new_purchase_order _proxyentity = _correntEntity.ToEntity <new_purchase_order>(); if (_proxyentity.new_cropid == null || _proxyentity.new_volume == null || _proxyentity.new_volume.Value == 0 || _proxyentity.new_approve_purchase_order == false || _proxyentity.new_yearid == null) { return; } _havePlan = _proxyentity.new_line_planningid == null ? false : true; EntityReference _planingToUpdate = FindPlaning(orgContext, _proxyentity.new_cropid, _proxyentity.new_yearid); if (_planingToUpdate != null) { double?_sumOfVolume = (from i in orgContext.CreateQuery <new_purchase_order>() where i.new_cropid.Id == _proxyentity.new_cropid.Id && i.new_yearid.Id == _proxyentity.new_yearid.Id && i.new_status != new OptionSetValue(100000002) && i.new_approve_purchase_order == true select i.new_volume).ToList().Sum(); _sumOfVolume = _sumOfVolume - _proxyentity.new_volume; new_line_purchase_planning _UpdatePlan = new new_line_purchase_planning() { Id = _planingToUpdate.Id, new_total_volume_tn = _sumOfVolume }; List <new_port> _portList = (from port in orgContext.CreateQuery <new_port>() where port.new_name == "Одеса" || port.new_name == "Миколаїв" select port).ToList(); foreach (var item in _portList) { double?_sumOfVolumeFromPort = (from i in orgContext.CreateQuery <new_purchase_order>() where i.new_cropid.Id == _proxyentity.new_cropid.Id && i.new_yearid.Id == _proxyentity.new_yearid.Id && i.new_status != new OptionSetValue(100000002) && i.new_portid.Id == item.Id && i.new_approve_purchase_order == true select i.new_volume).ToList().Sum(); if (item.new_name == "Одеса") { _UpdatePlan.new_volume_Odesa = _sumOfVolumeFromPort; } else if (item.new_name == "Миколаїв") { _UpdatePlan.new_volume_Mykolaiv = _sumOfVolumeFromPort; } } service.Update(_UpdatePlan); } } }
private void UpdateMethod(IPluginExecutionContext context, IOrganizationService service) { //Проверяем статус на анульовано и удаляем количество с общего плана if (WillChangeStatus(context, service)) { return; } bool _havePlan = false; Entity _correntEntity; using (var orgContext = new OrganizationServiceContext(service)) { _correntEntity = (Entity)context.PostEntityImages["Post"]; new_purchase_order _proxyentity = _correntEntity.ToEntity <new_purchase_order>(); if (_proxyentity.new_cropid == null || _proxyentity.new_volume == null || _proxyentity.new_volume.Value == 0 || _proxyentity.new_approve_purchase_order == false || _proxyentity.new_yearid == null) { return; } _havePlan = _proxyentity.new_line_planningid == null ? false : true; EntityReference _planingToUpdate = FindPlaning(orgContext, _proxyentity.new_cropid, _proxyentity.new_yearid); if (_planingToUpdate != null) { double?_sumOfVolume = (from i in orgContext.CreateQuery <new_purchase_order>() where i.new_cropid.Id == _proxyentity.new_cropid.Id && i.new_yearid.Id == _proxyentity.new_yearid.Id && i.new_status != new OptionSetValue(100000002) && i.new_approve_purchase_order == true select i.new_volume).ToList().Sum(); new_line_purchase_planning _UpdatePlan = new new_line_purchase_planning() { Id = _planingToUpdate.Id, new_total_volume_tn = _sumOfVolume }; List <new_port> _portList = (from port in orgContext.CreateQuery <new_port>() where port.new_name == "Одеса" || port.new_name == "Миколаїв" select port).ToList(); foreach (var item in _portList) { double?_sumOfVolumeFromPort = (from i in orgContext.CreateQuery <new_purchase_order>() where i.new_cropid.Id == _proxyentity.new_cropid.Id && i.new_yearid.Id == _proxyentity.new_yearid.Id && i.new_status != new OptionSetValue(100000002) && i.new_portid.Id == item.Id && i.new_approve_purchase_order == true select i.new_volume).ToList().Sum(); if (item.new_name == "Одеса") { _UpdatePlan.new_volume_Odesa = _sumOfVolumeFromPort; } else if (item.new_name == "Миколаїв") { _UpdatePlan.new_volume_Mykolaiv = _sumOfVolumeFromPort; } } service.Update(_UpdatePlan); } else { double?_sumOfVolume = (from i in orgContext.CreateQuery <new_purchase_order>() where i.new_cropid.Id == _proxyentity.new_cropid.Id && i.new_status != new OptionSetValue(100000002) select i.new_volume).ToList().Sum(); new_line_purchase_planning _createPlan = new new_line_purchase_planning() { new_total_volume_tn = _sumOfVolume, new_cropid = _proxyentity.new_cropid, new_planningid = _proxyentity.new_yearid }; List <new_port> _portList = (from port in orgContext.CreateQuery <new_port>() where port.new_name == "Одеса" || port.new_name == "Миколаїв" select port).ToList(); foreach (var item in _portList) { double?_sumOfVolumeFromPort = (from i in orgContext.CreateQuery <new_purchase_order>() where i.new_cropid.Id == _proxyentity.new_cropid.Id && i.new_yearid.Id == _proxyentity.new_yearid.Id && i.new_status != new OptionSetValue(100000002) && i.new_portid.Id == item.Id && i.new_approve_purchase_order == true select i.new_volume).ToList().Sum(); if (item.new_name == "Одеса") { _createPlan.new_volume_Odesa = _sumOfVolumeFromPort; } else if (item.new_name == "Миколаїв") { _createPlan.new_volume_Mykolaiv = _sumOfVolumeFromPort; } } Guid _newRecordId = service.Create(_createPlan); _proxyentity.new_line_planningid = new EntityReference() { Id = _newRecordId, LogicalName = new_line_purchase_planning.EntityLogicalName }; } } }