public ElectricalEquipmentPropertiesViewModel(ElectricalEquipmentComponent controlSystemEquipmentComponent) { mElectricalEquipmentComponent = controlSystemEquipmentComponent; Models = new List<Model>(); LastInspectedCommand = new DelegateCommand<object>(LastInspectedHandler, CanModify); NextInspectionCommand = new DelegateCommand<object>(NextInspectionHandler, CanModify); CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); cmsWebServiceClient.GetManufacturersCompleted += (s, e) => { mManufacturers = e.Result; RaisePropertyChanged("Manufacturers"); RaisePropertyChanged("Manufacturer"); if (mElectricalEquipmentComponent.ManufacturerId.HasValue) { LoadModels(mElectricalEquipmentComponent.ManufacturerId.Value); } else if (Loaded != null) { Loaded(); Loaded = null; } }; cmsWebServiceClient.GetManufacturersAsync((int)CommonUtils.EquipmentTypeCode.ELECT); }
public AddEditElectricalComponentViewModel(ElectricalEquipmentComponent mc, IList<string> existingComponentNames ) { ExistingComponentNames = existingComponentNames; EditingName = mc.Name; mElectricalEquipmentComponent = mc; Initialize(); InEditMode = true; }
public AddEditElectricalComponentViewModel(int electricalEquipmentId, IList<string> existingComponentNames) { ExistingComponentNames = existingComponentNames; Initialize(); mElectricalEquipmentComponent = new ElectricalEquipmentComponent(); mElectricalEquipmentComponent.ElectricalPropertyValues = new List<ElectricalPropertyValue>(); mElectricalEquipmentComponent.ElectricalEquipmentId = electricalEquipmentId; InEditMode = false; }
public ElectricalEquipmentPropertiesControl(ElectricalEquipmentComponent controlSystemComponent) { if (DesignerProperties.IsInDesignTool) { return; } InitializeComponent(); CompositionInitializer.SatisfyImports(this); mElectricalEquipmentComponent = controlSystemComponent; ComponentName = mElectricalEquipmentComponent.Name; mViewModel = new ElectricalEquipmentPropertiesViewModel(mElectricalEquipmentComponent); mViewModel.Loaded += () => { PopulatePropertyValues(controlSystemComponent); DataContext = mViewModel; ManufacturerComboBox.ResetOriginalValue(); ManufacturerComboBox.ControlChanged += ControlChanged; ModelComboBox.ResetOriginalValue(); ModelComboBox.ControlChanged += ControlChanged; }; }
private void InsertData(IList<ElectricalComponentDataAdapter> adapters) { for (int index = 0; index < adapters.Count; index++) { ElectricalComponentDataAdapter adapter = adapters[index]; if (!adapter.IsValid()) { continue; } //check for duplicate Component Name in the Excell IList<string> componentNames = (from x in adapters select x.ComponentName).ToList(); if (DuplicateItemNameFoundInExcell(adapter.ComponentName, componentNames, adapter.RowNumber)) { continue; } //Check for duplicate Component Name in the Database componentNames = (from x in mExistingComponents select x.Name).ToList(); if (DuplicateItemNameFoundInDatabase(adapter.ComponentName, componentNames, adapter.RowNumber)) { continue; } ElectricalEquipmentComponent newComponent = new ElectricalEquipmentComponent(); newComponent.LastModifiedDate = DateTime.Now; newComponent.LastModifiedById = MetaData.UserId; newComponent.Name = adapter.ComponentName; newComponent.Description = adapter.ComponentDescription; if (GetElectricalEquipment(adapter.Tag, newComponent, adapter.RowNumber)) { continue; } if (GetElectricalEquipmentComponentType(adapter.ComponentType, newComponent, adapter.RowNumber)) { continue; } mExistingComponents = Cee.ElectricalEquipmentComponents.ToList();//refresh! ElectricalEquipmentComponent existing = (from x in mExistingComponents where string.Compare(x.Name, adapter.Tag, true, CultureInfo.CurrentCulture) == 0 && x.ElectricalEquipmentComponentTypeId == newComponent.ElectricalEquipmentComponentTypeId select x).FirstOrDefault(); if (existing != null) { //error - should not already exist RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}': '{2}' with a component type of '{3}' already exists in the database. Skipping.", WorkSheetName, adapter.RowNumber, adapter.Tag, newComponent.ElectricalEquipmentComponentType.Name)); continue; } var skipRow = ChangeManufacturerModel(adapter, newComponent); if (skipRow) continue; BuildPropertyValues(newComponent, adapter); Cee.ElectricalEquipmentComponents.Add(newComponent); mSavedResults.Add(newComponent); const decimal incrediment = 0.001m; decimal revision = new decimal(1.000); List<decimal> foo = (from x in Cee.ElectricalEquipmentRevisionHistories where x.ElectricalEquipmentId == newComponent.ElectricalEquipmentId orderby x.Revision descending select x.Revision).ToList(); if (foo.Count > 0) { revision = foo[0] + incrediment; } newComponent.ElectricalEquipment.ElectricalEquipmentRevisionHistories.Add(new ElectricalEquipmentRevisionHistory { Date = DateTime.Now, ElectricalEquipmentId = newComponent.ElectricalEquipmentId, UserId = MetaData.UserId, Description = BuildRevisionHistoryInsertComment(MetaData.RevisionHistoryComment), IsSystemMessage = true, Revision = revision }); } if (mSavedResults.Count == 0) { RaiseMessage(CommonUtils.MessageType.Warning, string.Format("No Equipment Components were added from from worksheet '{0}'.", WorkSheetName)); } else { //|--- S A V E Cee.SaveChanges(); } }
private void EditComponentHandler(object parameter) { if (SelectedComponent != null) { CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); cmsWebServiceClient.GetElectricalEquipmentComponentsCompleted += (s, e) => { ElectricalEquipmentComponent clone = new ElectricalEquipmentComponent(); CommonUtils.CloneObject(clone, SelectedComponent, ""); clone.ElectricalEquipmentComponentType = SelectedComponent.ElectricalEquipmentComponentType;//not done by CloneObject method. IList<string> existingComponentNames = (from x in Components select x.Name).ToList(); AddEditElectricalEquipmentComponentDialog dialog = new AddEditElectricalEquipmentComponentDialog(SelectedComponent, existingComponentNames); dialog.Show(); //Select the component as user might have changed the component type //and this needs to reload the component type properties dialog.Closed += (s1, e1) => { if (dialog.DialogResult.HasValue && dialog.DialogResult.Value) { Utils.OnCollectionChanged(EventAggregator, mElectricalEquipment, PROPERTYNAME, true); } else { SelectedComponent.Name = clone.Name; SelectedComponent.ElectricalEquipmentComponentType = clone.ElectricalEquipmentComponentType; SelectedComponent.Description = clone.Description; } RaisePropertyChanged("Components"); }; }; cmsWebServiceClient.GetElectricalEquipmentComponentsAsync(); } }
private void CreateAndBindDynamicProperties(ElectricalEquipmentComponent electricalEquipmentComponent, List<String> pidDocuments, List<String> specDocuments) { int rowCount = 5; var controlSystemComponentProperies = electricalEquipmentComponent.ElectricalEquipmentComponentType.ElectricalEquipmentComponentTypeProperties.OrderBy(x => x.Ordinal).ToList(); CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint); cmsWebServiceClient.GetAllPropertyListsCompleted += (s, e) => { foreach (var controlSystemComponentProperty in controlSystemComponentProperies.Where(x => x.ElectricalEquipmentProperty.IsVisible)) { Label label = new Label(); Binding labelBinding = new Binding("Name") { Mode = BindingMode.OneTime, Source = controlSystemComponentProperty.ElectricalEquipmentProperty }; label.SetBinding(ContentControl.ContentProperty, labelBinding); label.VerticalAlignment = VerticalAlignment.Center; label.Margin = new Thickness(1); PropertiesGrid.Children.Add(label); Grid.SetRow(label, rowCount); Grid.SetColumn(label, 0); var propertyValue = GetPropertyValue(electricalEquipmentComponent, controlSystemComponentProperty); var element = Utils.BindElement(controlSystemComponentProperty.ElectricalEquipmentProperty, propertyValue, e.Result, ComponentPropertyWrapViewModels, ControlChanged, pidDocuments, specDocuments); PropertiesGrid.Children.Add(element); Grid.SetRow((FrameworkElement)element, rowCount); Grid.SetColumn((FrameworkElement)element, 1); PropertiesGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(element.Height + 2) }); rowCount++; } LastInspectedTextBox.ResetOriginalValue(); LastInspectedTextBox.ControlChanged += ControlChanged; NextInspectionTextBox.ResetOriginalValue(); NextInspectionTextBox.ControlChanged += ControlChanged; }; cmsWebServiceClient.GetAllPropertyListsAsync(); }
private void PopulatePropertyValues(ElectricalEquipmentComponent electricalEquipmentComponent) { var controlSystemComponentProperies = electricalEquipmentComponent.ElectricalEquipmentComponentType.ElectricalEquipmentComponentTypeProperties.OrderBy(x => x.Ordinal).ToList(); if (controlSystemComponentProperies.Any(x => x.ElectricalEquipmentProperty.SystemComboType == CommonUtils.SystemComboBoxType.PandIdDocuments.ToString() || x.ElectricalEquipmentProperty.SystemComboType == CommonUtils.SystemComboBoxType.SpecificationDocuments.ToString())) { Task<List<QuickDocument>> getPidDocumentsTask = null; Task<List<QuickDocument>> getSpecDocumentsTask = null; getPidDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypePidCode); getSpecDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypeFuncspecCode); List<Task> tasks = new List<Task> {getPidDocumentsTask, getSpecDocumentsTask}; Task.Factory.ContinueWhenAll(tasks.ToArray(), x => { CMS.UiFactory.StartNew(() => { CreateAndBindDynamicProperties(electricalEquipmentComponent, getPidDocumentsTask.Result.Select(d => d.Name).ToList(), getSpecDocumentsTask.Result.Select(d => d.Name).ToList()); }); }); } CreateAndBindDynamicProperties(electricalEquipmentComponent, null, null); }
public DbOperationResult SaveElectricalEquipmentComponent(ElectricalEquipmentComponent electricalEquipmentComponent) { DbOperationResult result = new DbOperationResult(); if (electricalEquipmentComponent == null) { result.ServerInformationMessages.Add("Save Completed"); return result; } using (CmsEntities cee = new CmsEntities()) { var match = (from x in cee.ElectricalEquipmentComponents where x.Id == electricalEquipmentComponent.Id select x).FirstOrDefault(); if (match == null) { //So component doesnt exist in the database so lets create it electricalEquipmentComponent.ElectricalEquipment = null; electricalEquipmentComponent.ElectricalEquipmentComponentType = null; cee.ElectricalEquipmentComponents.Add(electricalEquipmentComponent); } else { if (match.LastInspectedDate != electricalEquipmentComponent.LastInspectedDate) { ElectricalEquipmentRevisionHistory rv = new ElectricalEquipmentRevisionHistory(); rv.ElectricalEquipmentId = electricalEquipmentComponent.ElectricalEquipmentId; rv.Date = DateTime.Now; if (electricalEquipmentComponent.LastModifiedById.HasValue) { rv.UserId = electricalEquipmentComponent.LastModifiedById.Value; } rv.Description = string.Format("Last Inspected Date changed from '{0}' to '{1}'.", match.LastInspectedDate, electricalEquipmentComponent.LastInspectedDate); rv.IsSystemMessage = true; AddElectricalRevisionHistoryInternal(rv, cee); } //Compoent exist, change the ID of Equipment match.ElectricalEquipmentId = electricalEquipmentComponent.ElectricalEquipmentId; } cee.SaveChanges(); result.ServerInformationMessages.Add("Save Completed"); return result; } }
private ElectricalPropertyValue GetPropertyValue(ElectricalEquipmentComponent controlSystemComponent, ElectricalEquipmentComponentTypeProperty controlSystemComponentProperty) { var propertyValue = (from x in controlSystemComponent.ElectricalPropertyValues where x.ElectricalEquipmentPropertyId == controlSystemComponentProperty.ElectricalEquipmentPropertyId && x.ElectricalEquipmentComponentId == controlSystemComponent.Id select x).FirstOrDefault(); if (propertyValue == null) { propertyValue = new ElectricalPropertyValue { ElectricalEquipmentComponentId = controlSystemComponent.Id, ElectricalEquipmentPropertyId = controlSystemComponentProperty.ElectricalEquipmentPropertyId, Value = controlSystemComponentProperty.ElectricalEquipmentProperty.DefaultValue }; controlSystemComponent.ElectricalPropertyValues.Add(propertyValue); } return propertyValue; }
private void SaveElectricalEquipmentComponents(IEnumerable<ElectricalEquipmentComponent> electricalComponents, CmsEntities cee, int electricalEquipmentId, int userId) { foreach (var electricalComponent in electricalComponents) { var dbMatch = (from x in cee.ElectricalEquipmentComponents where x.Id == electricalComponent.Id select x).FirstOrDefault(); if (dbMatch != null) { if (dbMatch.LastInspectedDate != electricalComponent.LastInspectedDate) { ElectricalEquipmentRevisionHistory rv = new ElectricalEquipmentRevisionHistory { ElectricalEquipmentId = electricalEquipmentId, Date = DateTime.Now, UserId = userId, Description = string.Format("Component '{0}': Last Inspected Date changed from '{1}' to '{2}'.", electricalComponent.Name, dbMatch.LastInspectedDate, electricalComponent.LastInspectedDate) }; rv.IsSystemMessage = true; AddElectricalRevisionHistoryInternal(rv, cee); } //Update Electrical Componet cee.Entry(dbMatch).CurrentValues.SetValues(electricalComponent); } else { dbMatch = new ElectricalEquipmentComponent { ElectricalEquipmentId = electricalComponent.ElectricalEquipmentId, ElectricalEquipmentComponentTypeId = electricalComponent.ElectricalEquipmentComponentTypeId, Name = electricalComponent.Name, Ordinal = electricalComponent.Ordinal, NextInspectionDate = electricalComponent.NextInspectionDate, LastInspectedById = electricalComponent.LastInspectedById, LastInspectedDate = electricalComponent.LastInspectedDate, LastModifiedById = electricalComponent.LastModifiedById, LastModifiedDate = electricalComponent.LastModifiedDate, Description = electricalComponent.Description, ManufacturerId = electricalComponent.ManufacturerId, ModelId = electricalComponent.ModelId }; //Add new Electrical Component cee.ElectricalEquipmentComponents.Add(dbMatch); } foreach (var electricalComponentPropertyValue in electricalComponent.ElectricalPropertyValues) { var qq = (from x in cee.ElectricalPropertyValues where x.Id == electricalComponentPropertyValue.Id select x).FirstOrDefault(); if (qq != null) { cee.Entry(qq).CurrentValues.SetValues(electricalComponentPropertyValue); } else { cee.ElectricalPropertyValues.Add(electricalComponentPropertyValue); } } } }
public void DeleteElectricalEquipmentComponent(ElectricalEquipmentComponent mec) { using (CmsEntities cee = new CmsEntities()) { var electricalPropertyValues = (from x in cee.ElectricalPropertyValues where x.ElectricalEquipmentComponentId == mec.Id select x).ToList(); foreach (var electricalPropertyValue in electricalPropertyValues) { cee.ElectricalPropertyValues.Remove(electricalPropertyValue); } var q = (from x in cee.ElectricalEquipmentComponents where x.Id == mec.Id select x).FirstOrDefault(); if (q != null) { cee.ElectricalEquipmentComponents.Remove(q); cee.SaveChanges(); } } }
private bool GetElectricalEquipmentComponentType(string typeName, ElectricalEquipmentComponent component, int rowIndex) { ElectricalEquipmentComponentType componentType = (from x in mExistingEquipmentComponentTypes where string.Compare(typeName, x.Name, true, CultureInfo.CurrentCulture) == 0 && !string.IsNullOrEmpty(x.Name) select x).FirstOrDefault(); if (componentType != null) { component.ElectricalEquipmentComponentType = componentType; component.ElectricalEquipmentComponentTypeId = componentType.Id; } else { if (CanCreateProperties) { string code = typeName.Replace(" ", "_").ToUpper(); componentType = new ElectricalEquipmentComponentType { Name = typeName, Code = code, Description = typeName + " (created by importer)", IsActive = true }; mExistingEquipmentComponentTypes.Add(componentType); component.ElectricalEquipmentComponentType = componentType; } else { RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}': Could not find ElectricalEquipmentComponentType '{2}' in database. Skipping this row.", WorkSheetName, rowIndex, typeName)); return true; } } return false; }
private ElectricalEquipmentComponent CloneComponent(ElectricalEquipmentComponent selectedComponent) { ElectricalEquipmentComponent clone = new ElectricalEquipmentComponent(); clone.Id = selectedComponent.Id; clone.ElectricalEquipmentId = selectedComponent.ElectricalEquipmentId; clone.ElectricalEquipmentComponentTypeId = selectedComponent.ElectricalEquipmentComponentTypeId; clone.Name = selectedComponent.Name; clone.Description = selectedComponent.Description; clone.Ordinal = selectedComponent.Ordinal; clone.LastModifiedById = selectedComponent.LastModifiedById; clone.LastModifiedDate = selectedComponent.LastModifiedDate; clone.LastInspectedById = selectedComponent.LastInspectedById; clone.NextInspectionDate = selectedComponent.NextInspectionDate; clone.LastInspectedDate = selectedComponent.LastInspectedDate; clone.ElectricalPropertyValues = new List<ElectricalPropertyValue>(); foreach (var electricalPropertyValue in selectedComponent.ElectricalPropertyValues) { clone.ElectricalPropertyValues.Add(new ElectricalPropertyValue { ElectricalEquipmentPropertyId = electricalPropertyValue.ElectricalEquipmentPropertyId, ElectricalEquipmentComponentId = electricalPropertyValue.ElectricalEquipmentComponentId, Value = electricalPropertyValue.Value }); } return clone; }
private bool GetElectricalEquipment(string tag, ElectricalEquipmentComponent newComponent, int rowIndex) { bool skipRow = false; //Check if the Area exist in the database ElectricalEquipment equipment = (from x in mExistingEquipments where string.Compare(tag, x.Name, true, CultureInfo.CurrentCulture) == 0 && !string.IsNullOrEmpty(x.Name) select x).FirstOrDefault(); if (equipment == null) { //try db equipment = (from x in Cee.ElectricalEquipments where string.Compare(tag, x.Name, true, CultureInfo.CurrentCulture) == 0 && !string.IsNullOrEmpty(x.Name) select x).FirstOrDefault(); } if (equipment != null) { newComponent.ElectricalEquipment = equipment; newComponent.ElectricalEquipmentId = equipment.Id; } else { RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}': Could not find Equipment width Tag '{2}' in database. Skipping this row.", WorkSheetName, rowIndex, tag)); skipRow = true; } return skipRow; }
private bool ChangeManufacturerModel(ElectricalComponentDataAdapter adapter, ElectricalEquipmentComponent newComponent) { //CHANGING Manufacturer if (!string.IsNullOrEmpty(adapter.Manufacturer)) { if (adapter.Manufacturer.ToLower() != "null") { var manufactuer = (from x in mExistingManufacturers where x.Name.ToLower() == adapter.Manufacturer.ToLower() select x).FirstOrDefault(); if (manufactuer == null) { RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("Manufacturer", adapter.Manufacturer, adapter.RowNumber))); return false; } newComponent.Manufacturer = manufactuer; newComponent.ManufacturerId = manufactuer.Id; if (adapter.Model.ToLower() != "null") { //CHANGING Model if (!string.IsNullOrEmpty(adapter.Model)) { var model = (from x in manufactuer.Models where x.Name.ToLower() == adapter.Model.ToLower() select x).FirstOrDefault(); if (model == null) { RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("Model", adapter.Model, adapter.RowNumber))); return false; } newComponent.Model = model; newComponent.ModelId = model.Id; } } else { newComponent.Model = null; newComponent.ModelId = null; } } else { newComponent.Manufacturer = null; newComponent.ManufacturerId = null; newComponent.Model = null; newComponent.ModelId = null; } } return false; }
private ElectricalEquipmentRevisionHistory BuildRevisionHistory(ElectricalEquipmentComponent existing) { const decimal incrediment = 0.001m; decimal revision = new decimal(1.000); List<decimal> foo = (from x in Cee.ElectricalEquipmentRevisionHistories where x.ElectricalEquipmentId == existing.ElectricalEquipmentId orderby x.Revision descending select x.Revision).ToList(); if (foo.Count > 0) { revision = foo[0] + incrediment; } ElectricalEquipmentRevisionHistory rvh = new ElectricalEquipmentRevisionHistory { Date = DateTime.Now, ElectricalEquipmentId = existing.ElectricalEquipmentId, UserId = MetaData.UserId, Description = BuildRevisionHistoryInsertVersionComment(MetaData.RevisionHistoryComment, revision), Revision = revision, IsSystemMessage = true }; return rvh; }
private void BuildPropertyValues(ElectricalEquipmentComponent componentIn, ElectricalComponentDataAdapter adapter) { foreach (KeyValuePair<string, string> pair in adapter.PropertyValues) { //DOES PROPERTY EXIST? ElectricalEquipmentProperty property = (from x in mExistingEquipmentProperties where x.Name.ToLower() == pair.Key.ToLower() select x).FirstOrDefault(); if (property == null) { if (CanCreateProperties) { property = new ElectricalEquipmentProperty { 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 ElectricalEquipmentComponentTypeProperty Exists ElectricalEquipmentComponentTypeProperty equipmentComponentTypeProperty = null; if (mExistingEquipmentComponentTypeProperty.Any()) { equipmentComponentTypeProperty = (from x in mExistingEquipmentComponentTypeProperty where x.ElectricalEquipmentComponentType.Name.ToLower() == componentIn.ElectricalEquipmentComponentType.Name.ToLower() && x.ElectricalEquipmentProperty.Name.ToLower() == property.Name.ToLower() select x).FirstOrDefault(); } if (equipmentComponentTypeProperty == null) { if (CanCreateProperties) { //CREATE JOIN ROW equipmentComponentTypeProperty = new ElectricalEquipmentComponentTypeProperty(); equipmentComponentTypeProperty.ElectricalEquipmentComponentType = componentIn.ElectricalEquipmentComponentType; //note: set the object! equipmentComponentTypeProperty.ElectricalEquipmentProperty = 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.ElectricalEquipmentComponentType.Name, property.Name)); continue; } } property.ElectricalEquipmentComponentTypeProperties.Add(equipmentComponentTypeProperty); //CHECK PROPERTYVALUE EXISTS ElectricalPropertyValue propertyValue = null; if (mExistingPropertyValues.Any()) { propertyValue = (from x in mExistingPropertyValues where x.ElectricalEquipmentComponent.Name.ToLower() == componentIn.Name.ToLower() && x.ElectricalEquipmentProperty.Name.ToLower() == property.Name.ToLower() select x).FirstOrDefault(); } if (propertyValue == null) { propertyValue = new ElectricalPropertyValue(); propertyValue.ElectricalEquipmentComponent = componentIn; propertyValue.ElectricalEquipmentProperty = property; mExistingPropertyValues.Add(propertyValue);//update cache } //set value if (!string.IsNullOrEmpty(pair.Value)) { propertyValue.Value = pair.Value.ChangeNullToEmptyString(); } componentIn.ElectricalPropertyValues.Add(propertyValue); } }
private void MoveComponentHandler(object parameter) { if (SelectedComponent != null) { AddIssueElectricalEquipmentDialog dialog = new AddIssueElectricalEquipmentDialog("Select Destination Tag", true, SelectedComponent.ElectricalEquipmentId); dialog.Show(); //Select the component as user might have changed the component type //and this needs to reload the component type properties dialog.Closed += (s1, e1) => { if (dialog.DialogResult.HasValue && dialog.DialogResult.Value) { if (dialog.SelectedEquipment != null) { //THE MOVE (parent id changed) SelectedComponent.ElectricalEquipmentId = dialog.SelectedEquipment.Id; //need to CLONE due to the line "RaisePropertyChanged("Components");" MovedComponent = CloneComponent(SelectedComponent); MovedComponent.ElectricalEquipment = new ElectricalEquipment { Id = dialog.SelectedEquipment.Id, Name = dialog.SelectedEquipment.Name }; //remove mElectricalEquipment.ElectricalEquipmentComponents.Remove(SelectedComponent); RaiseChangeEvent(); OnCollectionChanged(); mSelectedComponent = null; RaisePropertyChanged("Components"); } } }; } }