public MobilePlantComponentTypeProperty AddMobilePlantComponentTypeProperty(MobilePlantComponentTypeProperty mecp) { using (CmsEntities cee = new CmsEntities()) { //Check if this component property already exist MobilePlantComponentTypeProperty temp = (from x in cee.MobilePlantComponentTypeProperties where x.MobilePlantPropertyId == mecp.MobilePlantPropertyId && x.MobilePlantComponentTypeId == mecp.MobilePlantComponentTypeId select x).FirstOrDefault(); if (temp == null) { //Add new Component Type temp = new MobilePlantComponentTypeProperty(); temp.MobilePlantPropertyId = mecp.MobilePlantPropertyId; temp.MobilePlantComponentTypeId = mecp.MobilePlantComponentTypeId; temp.Ordinal = mecp.Ordinal; cee.MobilePlantComponentTypeProperties.Add(temp); cee.SaveChanges(); } else { temp.Ordinal = mecp.Ordinal; cee.SaveChanges(); } return temp; } }
private void BuildPropertyValues(MobilePlantComponent componentIn, MobilePlantComponentDataAdapter adapter) { foreach (var pair in adapter.PropertyValues) { //DOES PROPERTY EXIST? MobilePlantProperty property = (from x in mExistingEquipmentProperties where x.Name.ToLower() == pair.Key.ToLower() select x).FirstOrDefault(); if (property == null) { if (CanCreateProperties) { property = new MobilePlantProperty { Name = pair.Key, DefaultValue = pair.Value, Description = " (created by importer)." }; mExistingEquipmentProperties.Add(property); //update cache } else { //ERROR! RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1} Tag {2} Component Name {3}' : The property does not exist.", WorkSheetName, adapter.RowNumber, adapter.Tag, adapter.ComponentName)); continue; } } //CHECK MobilePlantComponentTypeProperty Exists MobilePlantComponentTypeProperty equipmentComponentTypeProperty = null; if (mExistingEquipmentComponentTypeProperty.Any()) { equipmentComponentTypeProperty = (from x in mExistingEquipmentComponentTypeProperty where x.MobilePlantComponentType.Name.ToLower() == componentIn.MobilePlantComponentType.Name.ToLower() && x.MobilePlantProperty.Name.ToLower() == property.Name.ToLower() select x).FirstOrDefault(); } if (equipmentComponentTypeProperty == null) { if (CanCreateProperties) { //CREATE JOIN ROW equipmentComponentTypeProperty = new MobilePlantComponentTypeProperty(); equipmentComponentTypeProperty.MobilePlantComponentType = componentIn.MobilePlantComponentType; //note: set the object! equipmentComponentTypeProperty.MobilePlantProperty = property; //not set the object! mExistingEquipmentComponentTypeProperty.Add(equipmentComponentTypeProperty); //update cache } else { //ERROR! RaiseMessage(CommonUtils.MessageType.Warning, string.Format("WorkSheet '{0}' Row '{1} Tag {2} Component Type {3}' : The property {4} does not belong to the Component Type.", WorkSheetName, adapter.RowNumber, adapter.Tag, componentIn.MobilePlantComponentType.Name, property.Name)); continue; } } property.MobilePlantComponentTypeProperties.Add(equipmentComponentTypeProperty); //CHECK PROPERTYVALUE EXISTS MobilePlantPropertyValue propertyValue = null; if (mExistingPropertyValues.Any()) { propertyValue = (from x in mExistingPropertyValues where x.MobilePlantComponent.Name.ToLower() == componentIn.Name.ToLower() && x.MobilePlantProperty.Name.ToLower() == property.Name.ToLower() select x).FirstOrDefault(); } if (propertyValue == null) { propertyValue = new MobilePlantPropertyValue(); propertyValue.MobilePlantComponent = componentIn; propertyValue.MobilePlantProperty = property; mExistingPropertyValues.Add(propertyValue); //update cache } //set value if (!string.IsNullOrEmpty(pair.Value)) { propertyValue.Value = pair.Value.ChangeNullToEmptyString(); } componentIn.MobilePlantPropertyValues.Add(propertyValue); } }
private void EditMobilePlantComponentTypeProperty(NodeView nodeView) { AddEditExistingMobilePlantComponentPropertyDialog dialog = new AddEditExistingMobilePlantComponentPropertyDialog(nodeView.Id); dialog.Closed += (s1, e1) => { if (dialog.DialogResult.HasValue && dialog.DialogResult.Value) { CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); EventHandler<AddUpdateMobilePlantComponentTypePropertyCompletedEventArgs> addCompleted = null; addCompleted = (s2, eventArgs) => { MobilePlantComponentTypeProperty pcpt = eventArgs.Result; if (pcpt != null) { nodeView.Name = dialog.MobilePlantComponentTypeProperty.MobilePlantProperty.Name; nodeView.Description = dialog.MobilePlantComponentTypeProperty.MobilePlantProperty.Description; nodeView.SortField = dialog.MobilePlantComponentTypeProperty.Ordinal.ToString(); } cmsWebServiceClient.AddUpdateMobilePlantComponentTypePropertyCompleted -= addCompleted; }; cmsWebServiceClient.AddUpdateMobilePlantComponentTypePropertyCompleted += addCompleted; MobilePlantComponentTypeProperty MobilePlantComponentTypeProperty = new MobilePlantComponentTypeProperty { MobilePlantComponentTypeId = dialog.MobilePlantComponentTypeProperty.MobilePlantComponentTypeId, MobilePlantPropertyId = dialog.MobilePlantComponentTypeProperty.MobilePlantPropertyId, Ordinal = dialog.MobilePlantComponentTypeProperty.Ordinal }; cmsWebServiceClient.AddUpdateMobilePlantComponentTypePropertyAsync(MobilePlantComponentTypeProperty); } nodeView.Parent.Sort(); }; dialog.Show(); }
private void AddExistingMobilePlantComponentProperty(NodeView nodeView) { int electricalEquipmentComponentTypeId = nodeView.Id; CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); cmsWebServiceClient.GetMobilePlantComponentTypeCompleted += (s, e) => { AddEditExistingMobilePlantComponentPropertyDialog dialog = new AddEditExistingMobilePlantComponentPropertyDialog(e.Result); dialog.Show(); dialog.Closed += (s1, e1) => { if (dialog.DialogResult.HasValue && dialog.DialogResult.Value) { EventHandler<AddMobilePlantComponentTypePropertyCompletedEventArgs> addCompleted = null; addCompleted = (s2, eventArgs) => { MobilePlantComponentTypeProperty pcpt = eventArgs.Result; if (pcpt != null) { NodeView child = new NodeView(nodeView) { Id = pcpt.Id, Name = dialog.MobilePlantComponentTypeProperty.MobilePlantProperty.Name, Description = dialog.MobilePlantComponentTypeProperty.MobilePlantProperty.Description, Icon = "/CmsEquipmentDatabase;component/Images/Configuration.png", Type = NodeType.MobilePlantComponentTypeProperty, HasChildren = false, SortField = dialog.MobilePlantComponentTypeProperty.Ordinal.ToString() }; if (nodeView.ChildrenLoaded) { nodeView.Children.Add(child); nodeView.Sort(); } } cmsWebServiceClient.AddMobilePlantComponentTypePropertyCompleted -= addCompleted; }; cmsWebServiceClient.AddMobilePlantComponentTypePropertyCompleted += addCompleted; MobilePlantComponentTypeProperty electricalEquipmentComponentTypeProperty = new MobilePlantComponentTypeProperty { MobilePlantComponentTypeId = electricalEquipmentComponentTypeId, MobilePlantPropertyId = dialog.MobilePlantComponentTypeProperty.MobilePlantPropertyId, Ordinal = dialog.MobilePlantComponentTypeProperty.Ordinal }; cmsWebServiceClient.AddMobilePlantComponentTypePropertyAsync(electricalEquipmentComponentTypeProperty); } }; }; cmsWebServiceClient.GetMobilePlantComponentTypeAsync(electricalEquipmentComponentTypeId); }