public ControlSystemPropertiesViewModel(ControlSystemComponent controlSystemEquipmentComponent)
        {
            mControlSystemComponent = 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 (mControlSystemComponent.ManufacturerId.HasValue)
                        {
                            LoadModels(mControlSystemComponent.ManufacturerId.Value);
                        }
                        else if (Loaded != null)
                        {
                            Loaded();
                            Loaded = null;
                        }
                    };
            cmsWebServiceClient.GetManufacturersAsync((int)CommonUtils.EquipmentTypeCode.CONTR);
        }
        public AddEditControlSystemComponentViewModel(ControlSystemComponent controlSystemComponent, IList<string> existingComponentNames)
        {
            ExistingComponentNames = existingComponentNames;
            EditingName = controlSystemComponent.Name;
            mControlSystemComponent = controlSystemComponent;
            LoadData();
            InEditMode = true;

            mClone = BuildClone(controlSystemComponent);
        }
 public AddEditControlSystemComponentViewModel(int ControlSystemEquipmentId, IList<string> existingComponentNames)
 {
     ExistingComponentNames = existingComponentNames;
     LoadData();
     mControlSystemComponent = new ControlSystemComponent
     {
         ControlSystemPropertyValues = new List<ControlSystemPropertyValue>(),
         ControlSystemId = ControlSystemEquipmentId
     };
     InEditMode = false;
 }
        public ControlSystemAlarmPropertiesControl(ControlSystemComponent controlSystemComponent ,AlarmLists alarmLists )
        {
            InitializeComponent();
            CompositionInitializer.SatisfyImports(this);

            mControlSystemComponent = controlSystemComponent;
            var viewModel = new ControlSystemAlarmPropertiesViewModel(controlSystemComponent, alarmLists) { View = this };
            DataContext = viewModel;

            Loaded += ControlLoaded;
        }
        public ControlSystemAlarmPropertiesViewModel(ControlSystemComponent controlSystemComponent, AlarmLists lists)
        {
            CompositionInitializer.SatisfyImports(this);
            mAlarmLists = lists;

            mControlSystemComponent = controlSystemComponent;
            AlarmPropertyValues = new CmsObservableCollection<ControlSystemAlarmPropertiesWrapViewModel>();

            mLevel = GetControlSystemComponentAlarmLevel();

            LoadData();
        }
        public AddEditControlSystemComponentDialog(ControlSystemComponent controlSystemComponent, IList<string> existingComponetNames)
        {
            // Required to initialize variables
            InitializeComponent();
            Title = "Edit ControlSystem Component";
            AddEditControlSystemComponentViewModel addEditControlSystemComponentViewModel = new AddEditControlSystemComponentViewModel(controlSystemComponent, existingComponetNames);

            addEditControlSystemComponentViewModel.Loaded += () =>
                {
                    addEditControlSystemComponentViewModel.View = this;
                    DataContext = addEditControlSystemComponentViewModel;
                    Utils.ResetOriginalValues(LayoutRoot);
                };
        }
Пример #7
0
        public bool GetComponentTypeFailed(string name, ControlSystemComponent newComponent, int rowIndex)
        {
            if (!string.IsNullOrEmpty(name))
            {
                ControlSystemComponentType match = (from x in mExistControlSystemComponentTypes where string.Compare(x.Name, name, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();
                if (match == null)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}':Could not match '{2}' Control Component Type in database. Skipping.", WorkSheetName, rowIndex, name));
                    return true;
                }

                newComponent.ControlSystemComponentTypeId = match.Id;
            }
            return false;
        }
        public ControlSystemTuningPropertiesControl(ControlSystemComponent controlSystemComponent)
        {
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }

            InitializeComponent();
            CompositionInitializer.SatisfyImports(this);
            mControlSystemComponent = controlSystemComponent;

            ComponentName = mControlSystemComponent.Name;

            PopulatePropertyValues(controlSystemComponent);
        }
        public ControlSystemPropertiesControl(ControlSystemComponent controlSystemComponent)
        {
            if (DesignerProperties.IsInDesignTool) { return; }

            InitializeComponent();
            CompositionInitializer.SatisfyImports(this);
            mControlSystemComponent = controlSystemComponent;

            ComponentName = mControlSystemComponent.Name;

            mViewModel = new ControlSystemPropertiesViewModel(mControlSystemComponent);
            mViewModel.Loaded += () =>
                                     {
                                         PopulatePropertyValues(controlSystemComponent);
                                         DataContext = mViewModel;

                                         ManufacturerComboBox.ResetOriginalValue();
                                         ManufacturerComboBox.ControlChanged += ControlChanged;

                                         ModelComboBox.ResetOriginalValue();
                                         ModelComboBox.ControlChanged += ControlChanged;
                                     };
        }
        private void PopulatePropertyValues(ControlSystemComponent controlSystemComponent)
        {
            var controlSystemComponentProperies = controlSystemComponent.ControlSystemComponentType.ControlSystemComponentTypeProperties.
                Where(x => x.ControlSystemPropertyId.HasValue).OrderBy(x => x.Ordinal).ToList();

            if (controlSystemComponentProperies.Any(x => x.ControlSystemProperty.SystemComboType == CommonUtils.SystemComboBoxType.PandIdDocuments.ToString() ||
                                                         x.ControlSystemProperty.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(controlSystemComponent, getPidDocumentsTask.Result.Select(d => d.Name).ToList(), getSpecDocumentsTask.Result.Select(d => d.Name).ToList());
                    });
                });

            }
            CreateAndBindDynamicProperties(controlSystemComponent, null, null);
        }
        private void EditComponentHandler(object parameter)
        {
            if (SelectedComponent != null)
            {
                mClone = BuildClone(SelectedComponent);

                IList<string> existingComponentsNames = (from x in Components select x.Name).ToList();
                var dialog = new AddEditControlSystemComponentDialog(SelectedComponent, existingComponentsNames);
                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)
                    {
                        SelectedComponent = dialog.Component;
                        if (SelectedComponent.ControlSystemComponentTypeId != mClone.ControlSystemComponentTypeId)
                        {
                            mComponentTypeChanged = true;
                        }
                        Utils.OnCollectionChanged(EventAggregator, ControlSystem, PROPERTYNAME, true);
                    }
                    else
                    {
                        SelectedComponent.Name = mClone.Name;
                        SelectedComponent.ControlSystemComponentType = mClone.ControlSystemComponentType;
                        SelectedComponent.ControlSystemComponentTypeId = mClone.ControlSystemComponentTypeId;
                        SelectedComponent.Description = mClone.Description;
                    }

                    RaisePropertyChanged("Components");
                    RaisePropertyChanged("SelectedComponent");
                };
            }
        }
        private void CreateAndBindDynamicProperties(ControlSystemComponent controlSystemComponent, List<String> pidDocuments, List<String> specDocuments)
        {
            int rowCount = 5;

            var controlSystemComponentProperies = controlSystemComponent.ControlSystemComponentType.ControlSystemComponentTypeProperties.ToList();

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            cmsWebServiceClient.GetAllPropertyListsCompleted += (s, e) =>
            {
                List<ComponentTypeGroup> addedGroups = new List<ComponentTypeGroup>();

                foreach (var controlSystemComponentProperty in controlSystemComponentProperies.OrderBy(x => x.Ordinal).ThenBy(x => x.GroupOrdinal))
                {
                    //Skip Properties that are not visible
                    if (controlSystemComponentProperty.ControlSystemPropertyId.HasValue && !controlSystemComponentProperty.ControlSystemProperty.IsVisible) continue;

                    //Render Group
                    if (controlSystemComponentProperty.ComponentTypeGroupId.HasValue && !addedGroups.Contains(controlSystemComponentProperty.ComponentTypeGroup))
                    {
                        Label groupLabel = new Label
                        {
                            Content = controlSystemComponentProperty.ComponentTypeGroup.Name,
                            VerticalAlignment = VerticalAlignment.Center,
                            Margin = new Thickness(1),
                            FontWeight = FontWeights.Bold
                        };

                        PropertiesGrid.Children.Add(groupLabel);
                        Grid.SetRow(groupLabel, rowCount);
                        Grid.SetColumn(groupLabel, 0);
                        PropertiesGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(26) });
                        rowCount++;
                        addedGroups.Add(controlSystemComponentProperty.ComponentTypeGroup);

                        //This is a empty Group so don't need to render a Property
                        if (!controlSystemComponentProperty.ControlSystemPropertyId.HasValue) continue;
                    }

                    Label label = new Label();

                    Binding labelBinding = new Binding("Name")
                    {
                        Mode = BindingMode.OneTime,
                        Source = controlSystemComponentProperty.ControlSystemProperty
                    };

                    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(controlSystemComponent, controlSystemComponentProperty);

                    FrameworkElement element = Utils.BindElement(controlSystemComponentProperty.ControlSystemProperty, 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 ControlSystemPropertyValue GetPropertyValue(ControlSystemComponent controlSystemComponent,
            ControlSystemComponentTypeProperty controlSystemComponentProperty)
        {
            var propertyValue = (from x in controlSystemComponent.ControlSystemPropertyValues
                                 where x.ControlSystemPropertyId == controlSystemComponentProperty.ControlSystemPropertyId &&
                                       x.ControlSystemComponentId == controlSystemComponent.Id
                                 select x).FirstOrDefault();

            if (propertyValue == null && controlSystemComponentProperty.ControlSystemPropertyId.HasValue)
            {
                propertyValue = new ControlSystemPropertyValue
                    {
                        ControlSystemComponentId = controlSystemComponent.Id,
                        ControlSystemPropertyId = controlSystemComponentProperty.ControlSystemPropertyId.Value,
                        Value = controlSystemComponentProperty.ControlSystemProperty.DefaultValue
                    };

                controlSystemComponent.ControlSystemPropertyValues.Add(propertyValue);
            }
            return propertyValue;
        }
        private void PopulatePropertyValues(ControlSystemComponent controlSystemComponent)
        {
            int rowCount = 1;
            const int rowHeight = 25;

            //var controlSystemComponentProperies = controlSystemComponent.ControlSystemComponentType.ControlSystemComponentTypeProperties.OrderBy(x => x.Ordinal).ToList();
            var controlSystemComponentTypeTuningProperties =
                controlSystemComponent.ControlSystemComponentType.ControlSystemComponentTypeTuningProperties.OrderBy(x => x.Ordinal).ToList();

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            cmsWebServiceClient.GetAllPropertyListsCompleted += (s, e) =>
            {
                List<ComponentTypeGroup> addedGroups = new List<ComponentTypeGroup>();
                //controlSystemComponentProperies.Where(x => x.ComponentTypeGroupId.HasValue).ToList().ForEach(x => x.Ordinal = x.ComponentTypeGroup.Ordinal);
                controlSystemComponentTypeTuningProperties = controlSystemComponentTypeTuningProperties.
                    OrderBy(x => x.Ordinal).ThenBy(x => x.GroupOrdinal).ToList();

                foreach (var controlSystemComponentTypeTuningProperty in controlSystemComponentTypeTuningProperties.Where(x => x.ControlSystemTuningProperty.IsVisible))
                {
                    if (controlSystemComponentTypeTuningProperty.ComponentTypeGroupId.HasValue && !addedGroups.Contains(controlSystemComponentTypeTuningProperty.ComponentTypeGroup))
                    {
                        Label groupLabel = new Label
                        {
                            Content = controlSystemComponentTypeTuningProperty.ComponentTypeGroup.Name,
                            VerticalAlignment = VerticalAlignment.Center,
                            Margin = new Thickness(1),
                            FontWeight = FontWeights.Bold
                        };

                        PropertiesGrid.Children.Add(groupLabel);
                        Grid.SetRow(groupLabel, rowCount);
                        Grid.SetColumn(groupLabel, 0);
                        PropertiesGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(26) });
                        rowCount++;
                        addedGroups.Add(controlSystemComponentTypeTuningProperty.ComponentTypeGroup);
                    }

                    //Property Label
                    Label label = new Label();

                    Binding labelBinding = new Binding("Name")
                    {
                        Mode = BindingMode.OneTime,
                        Source = controlSystemComponentTypeTuningProperty.ControlSystemTuningProperty
                    };

                    label.SetBinding(ContentControl.ContentProperty, labelBinding);
                    label.VerticalAlignment = VerticalAlignment.Center;
                    label.Margin = new Thickness(1);

                    Silverlight.Controls.ToolTips.ToolTip nameTip = new Silverlight.Controls.ToolTips.ToolTip
                    {
                        Content = controlSystemComponentTypeTuningProperty.ControlSystemTuningProperty.Description
                    };
                    ToolTipService.SetToolTip(label, nameTip);

                    PropertiesGrid.Children.Add(label);
                    Grid.SetRow(label, rowCount);
                    Grid.SetColumn(label, 0);

                    var propertyValue = GetPropertyValue(controlSystemComponent, controlSystemComponentTypeTuningProperty);

                    var tuningPropertyWrapViewModel = new TuningPropertyWrapViewModel(controlSystemComponentTypeTuningProperty.ControlSystemTuningProperty, propertyValue);
                    TuningPropertyWrapViewModels.Add(tuningPropertyWrapViewModel);

                    //Property VALUE
                    var element = BindElementValue(tuningPropertyWrapViewModel, e.Result);
                    PropertiesGrid.Children.Add(element);
                    Grid.SetRow((FrameworkElement) element, rowCount);
                    Grid.SetColumn((FrameworkElement) element, 1);

                    //PCS Value
                    var pcsValueElement = BindElementPcsvalue(tuningPropertyWrapViewModel, "PcsValue");
                    pcsValueElement.IsHitTestVisible = false;
                    //((CmsTextBox)pcsValueElement).Background = new SolidColorBrush(Color.FromArgb(255, 239, 239, 239));

                    PropertiesGrid.Children.Add(pcsValueElement);
                    Grid.SetRow((FrameworkElement) pcsValueElement, rowCount);
                    Grid.SetColumn((FrameworkElement) pcsValueElement, 2);

                    //Trended
                    var trendedElement = BindCheckBoxElement(tuningPropertyWrapViewModel, "Trended");
                    ((FrameworkElement) trendedElement).HorizontalAlignment = HorizontalAlignment.Center;

                    PropertiesGrid.Children.Add(trendedElement);
                    Grid.SetRow((FrameworkElement) trendedElement, rowCount);
                    Grid.SetColumn((FrameworkElement) trendedElement, 3);

                    //Notes
                    var notesElement = BindElementTextBox(tuningPropertyWrapViewModel, "Notes");

                    PropertiesGrid.Children.Add(notesElement);
                    Grid.SetRow((FrameworkElement) notesElement, rowCount);
                    Grid.SetColumn((FrameworkElement) notesElement, 4);

                    //Accept
                    Button acceptButton = new Button {Content = "Accept"};
                    acceptButton.Height = 23;
                    acceptButton.DataContext = tuningPropertyWrapViewModel;
                    acceptButton.Command = tuningPropertyWrapViewModel.AcceptCommand;
                    acceptButton.IsEnabled = controlSystemComponentTypeTuningProperty.ControlSystemTuningProperty.IsEditable;

                    Binding visibilityBinding = new Binding("AcceptButtonVisibility")
                    {
                        Mode = BindingMode.OneWay,
                        Source = tuningPropertyWrapViewModel
                    };
                    acceptButton.SetBinding(VisibilityProperty, visibilityBinding);

                    acceptButton.Width = 60;
                    PropertiesGrid.Children.Add(acceptButton);
                    Grid.SetRow((FrameworkElement) acceptButton, rowCount);
                    Grid.SetColumn((FrameworkElement) acceptButton, 5);

                    //ModfiedUserDate
                    var modfiedUserDate = BindElementLabel(tuningPropertyWrapViewModel, "ModfiedUserDate");
                    PropertiesGrid.Children.Add(modfiedUserDate);
                    Grid.SetRow((FrameworkElement) modfiedUserDate, rowCount);
                    Grid.SetColumn((FrameworkElement) modfiedUserDate, 6);

                    PropertiesGrid.RowDefinitions.Add(new RowDefinition {Height = new GridLength(rowHeight)});

                    rowCount++;
                }
            };
            cmsWebServiceClient.GetAllPropertyListsAsync();
        }
        private void DeleteControlSystemComponent(ControlSystemComponent controlSystemComponent)
        {
            using (var cee = new CmsEntities())
            {
                var controlSystemPropertyValues = (from x in cee.ControlSystemPropertyValues
                                                   where x.ControlSystemComponentId == controlSystemComponent.Id
                                                   select x).ToList();

                foreach (var controlSystemPropertyValue in controlSystemPropertyValues)
                {
                    cee.ControlSystemPropertyValues.Remove(controlSystemPropertyValue);
                }

                var q = (from x in cee.ControlSystemComponents
                         where x.Id == controlSystemComponent.Id
                         select x).FirstOrDefault();
                if (q != null)
                {
                    cee.ControlSystemComponents.Remove(q);
                    cee.SaveChanges();
                }
            }
        }
Пример #16
0
        private static bool MatchNewComponentFailed(CmsEntities cee, Alarm oldAlarm, out ControlSystemComponent matchedNewCmsComponent)
        {
            matchedNewCmsComponent = (from x in cee.ControlSystemComponents
                                      where x.Name.Equals(oldAlarm.Element.Name, StringComparison.CurrentCultureIgnoreCase)
                                      select x).FirstOrDefault();

            if (matchedNewCmsComponent == null)
            {
                Logger.Out(string.Format("MatchNewComponentFailed on Alarm ID {0}:- could not match Component.Name = Element.Name '{1}'.", oldAlarm.Id, oldAlarm.Element.Name));
                return true;
            }
            return false;
        }
        private ControlSystemComponent BuildClone(ControlSystemComponent controlSystemComponent)
        {
            var clone = new ControlSystemComponent();
            CommonUtils.CloneObject(clone, controlSystemComponent, "");
            clone.ControlSystemComponentTypeId = controlSystemComponent.ControlSystemComponentTypeId;
            clone.ControlSystemComponentType = controlSystemComponent.ControlSystemComponentType;

            foreach (var pv in controlSystemComponent.ControlSystemAlarmPropertyValues)
            {
                var pvClone = new ControlSystemAlarmPropertyValue();
                CommonUtils.CloneObject(pvClone, pv, "");
                clone.ControlSystemAlarmPropertyValues.Add(pvClone);

                var propClone = new ControlSystemAlarmProperty();
                CommonUtils.CloneObject(propClone, pv.ControlSystemAlarmProperty, "");

                propClone.ControlSystemUserInterfacePlatform = pv.ControlSystemAlarmProperty.ControlSystemUserInterfacePlatform;
                propClone.UserInterfacePlatformId = pv.ControlSystemAlarmProperty.UserInterfacePlatformId;

                pvClone.ControlSystemAlarmProperty = propClone;
                pvClone.ControlSystemAlarmPropertyId = propClone.Id;

            }

            return clone;
        }
Пример #18
0
        private bool InsertRevisionHistoryFailed(ControlSystemComponent newComponent, ControlSystem controlSystem)
        {
            var revision = new decimal(1.000);

            string comment = string.Empty;

            if (!string.IsNullOrEmpty(MetaData.RevisionHistoryComment))
            {
                if (MetaData.ImportType == CommonUtils.ImportType.CreateControlComponents)
                {
                    if (!string.IsNullOrEmpty(MetaData.RevisionHistoryComment))
                    {
                        comment = BuildRevisionHistoryInsertComment(string.Format("Created Component '{0}' {1}.", newComponent.Name, MetaData.RevisionHistoryComment));
                    }
                    else
                    {
                        comment = BuildRevisionHistoryInsertComment(string.Format("Created Component '{0}'", newComponent.Name));
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(MetaData.RevisionHistoryComment))
                    {
                        comment = BuildRevisionHistoryUpdateComment(string.Format("Updated Component '{0}' {1}.", newComponent.Name, MetaData.RevisionHistoryComment));
                    }
                    else
                    {
                        comment = BuildRevisionHistoryUpdateComment(string.Format("Updated Component '{0}'", newComponent.Name));
                    }
                }
            }

            var rvh = new ControlSystemRevisionHistory
            {
                Date = DateTime.Now,
                UserId = MetaData.UserId,
                Description = comment,
                Revision = revision
            };

            if (controlSystem == null)
            {
                controlSystem = (from x in Cee.ControlSystems where x.Id == newComponent.ControlSystemId select x).FirstOrDefault();
                if (controlSystem == null)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("Could not find existing Control System by Id '{0}'.", newComponent.ControlSystemId));
                    return true;
                }
            }
            rvh.IsSystemMessage = true;
            controlSystem.ControlSystemRevisionHistories.Add(rvh);
            return false;
        }
Пример #19
0
        private void InsertData(IList<ControlComponentDataAdapter> importData)
        {
            if (importData.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, NoDataFoundForWorkSheetMessage());
                return;
            }

            User matchUser = (from x in Cee.Users where x.Id == MetaData.UserId select x).FirstOrDefault();

            if (matchUser == null)
            {
                RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("UserId", MetaData.UserId.ToString(CultureInfo.CurrentCulture))));
                return;
            }

            for (int i = 0; i < importData.Count; i++)
            {
                ControlComponentDataAdapter adapter = importData[i];

                ControlSystemComponent newComponent = new ControlSystemComponent();
                Cee.ControlSystemComponents.Add(newComponent);

                //CONTROL ID - must already exist
                ControlSystem control = (from x in Cee.ControlSystems where x.Name.Equals(adapter.ControlSystemName, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();

                if (control == null)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("ControlSystem", adapter.ControlSystemName, i + 1)));
                    continue;
                }
                newComponent.ControlSystemId = control.Id;

                // NAME - Name must be Unique across all comps
                IList<string> names = (from x in importData select x.ControlSystemName).ToList();
                if (DuplicateItemNameFoundInExcell(adapter.ComponentName, names, i + 1))
                {
                    continue;  //Component Names Must be unique in excel sheet
                }
                if (string.IsNullOrEmpty(adapter.ControlSystemName))
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildPropertyEmpty("ControlSystemName", i + 1)));
                    continue;
                }
                ControlSystemComponent comp = mExistingControlSystemComponents.FirstOrDefault(x => string.Compare(x.Name, adapter.ComponentName, true, CultureInfo.CurrentCulture) == 0);
                if (comp != null)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildDuplicateNameExistsInDbMessage(adapter.ComponentName, i + 1)));
                    continue;
                }
                if (adapter.ComponentName.Length > 200)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildPropertyTooLong("ComponentName", 200, i + 1)));
                    continue;
                }
                newComponent.Name = adapter.ComponentName;

                //Component Type
                if (string.IsNullOrEmpty(adapter.ComponentTypeName))
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildPropertyEmpty("ComponentTypeName", i + 1)));
                    continue;
                }
                if (GetComponentTypeFailed(adapter.ComponentTypeName, newComponent, i + 1))
                {
                    continue;
                }

                //Ordinal
                if (string.IsNullOrEmpty(adapter.Ordinal))
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildPropertyEmpty("Ordinal", i + 1)));
                    continue;
                }

                int outOrdinal;
                if (!int.TryParse(adapter.Ordinal, out outOrdinal))
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("Could not parse '{0}' to a number at row {1}.", adapter.Ordinal, i + 1));
                    continue;
                }
                newComponent.Ordinal = outOrdinal;

                //Description
                if (adapter.Description.Trim().Length > 4000)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildPropertyTooLong("Description", 4000, i + 1)));
                    continue;
                }
                newComponent.Description = adapter.Description;

                //ManufacturerId
                int? manufactId;
                if (GetManufacturerFailed(adapter.ManufactuerName, i + 1, out manufactId))
                {
                    continue;
                }
                if (manufactId.HasValue)
                {
                    newComponent.ManufacturerId = manufactId.Value;
                }

                //ModelId
                int? modelId;
                if (GetModelFailed(adapter.ModelName, i + 1, out modelId))
                {
                    continue;
                }
                if (modelId.HasValue)
                {
                    newComponent.ModelId = modelId.Value;
                }

                newComponent.LastModifiedDate = DateTime.Now;
                newComponent.LastModifiedById = MetaData.UserId;

                if (InsertRevisionHistoryFailed(newComponent, control))
                {
                    continue;
                }

                mSavedResults.Add(newComponent);
            }

            if (mSavedResults.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, string.Format("No Control Modules were added from from worksheet {0}.", WorkSheetName));
            }
            else
            {
                //SAVE
                Cee.SaveChanges();

                foreach (ControlSystemComponent component in mSavedResults)
                {
                    RaiseMessage(CommonUtils.MessageType.Added, string.Format("Processed Control Component '{0}'.", component.Name));
                }
            }
        }
        public DbOperationResult SaveControlSystemComponents(List<ControlSystemComponent> controlSystemComponents)
        {
            var result = new DbOperationResult();

            using (var cee = new CmsEntities())
            {
                try
                {
                    foreach (var controlSystemComponent in controlSystemComponents)
                    {
                        var q = (from x in cee.ControlSystemComponents
                                 where x.Id == controlSystemComponent.Id
                                 select x).FirstOrDefault();

                        if (q != null)
                        {
                            //Update ControlSystem Componet
                            q.ControlSystemId = controlSystemComponent.ControlSystemId;
                            q.ControlSystemComponentTypeId = controlSystemComponent.ControlSystemComponentTypeId;
                            q.Name = controlSystemComponent.Name;
                            q.Ordinal = controlSystemComponent.Ordinal;
                            q.NextInspectionDate = controlSystemComponent.NextInspectionDate;
                            q.LastInspectedById = controlSystemComponent.LastInspectedById;
                            q.LastInspectedDate = controlSystemComponent.LastInspectedDate;
                            q.LastModifiedById = controlSystemComponent.LastModifiedById;
                            q.LastModifiedDate = controlSystemComponent.LastModifiedDate;
                            q.Description = controlSystemComponent.Description;
                            q.ManufacturerId = controlSystemComponent.ManufacturerId;
                            q.ModelId = controlSystemComponent.ModelId;
                        }
                        else
                        {
                            q = new ControlSystemComponent();
                            q.ControlSystemId = controlSystemComponent.ControlSystemId;
                            q.ControlSystemComponentTypeId = controlSystemComponent.ControlSystemComponentTypeId;
                            q.Name = controlSystemComponent.Name;
                            q.Ordinal = controlSystemComponent.Ordinal;
                            q.NextInspectionDate = controlSystemComponent.NextInspectionDate;
                            q.LastInspectedById = controlSystemComponent.LastInspectedById;
                            q.LastInspectedDate = controlSystemComponent.LastInspectedDate;
                            q.LastModifiedById = controlSystemComponent.LastModifiedById;
                            q.LastModifiedDate = controlSystemComponent.LastModifiedDate;
                            q.Description = controlSystemComponent.Description;
                            q.ManufacturerId = controlSystemComponent.ManufacturerId;
                            q.ModelId = controlSystemComponent.ModelId;

                            //Add new ControlSystem Component
                            cee.ControlSystemComponents.Add(q);
                        }

                        foreach (var controlSystemComponentPropertyValue in controlSystemComponent.ControlSystemPropertyValues)
                        {
                            var qq = (from x in cee.ControlSystemPropertyValues
                                      where x.Id == controlSystemComponentPropertyValue.Id
                                      select x).FirstOrDefault();

                            if (qq != null)
                            {
                                cee.Entry(qq).CurrentValues.SetValues(controlSystemComponentPropertyValue);
                            }
                            else
                            {
                                cee.ControlSystemPropertyValues.Add(controlSystemComponentPropertyValue);
                            }
                        }
                        cee.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    result.ServerErrorMessages.Add(String.Format("Error moving components: {0}", ex.Message));
                }
            }
            return result;
        }
Пример #21
0
        private void AddDynamicProperties(TuningPropertiesDataAdapter adapter, ControlSystemComponent matchingComponent, int i)
        {
            foreach (DynamicProperty dynamicProperty in adapter.DynamicProperties)
            {
                ControlSystemTuningProperty matchProperty = (from x in Cee.ControlSystemTuningProperties where string.Compare(x.Name, dynamicProperty.PropertyName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();

                if (matchProperty == null)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("ControlSystemTuningProperty", dynamicProperty.PropertyName, i + 1)));
                    continue;
                }

                ControlSystemComponentTypeTuningProperty matchCompTypeProperty = (from x in Cee.ControlSystemComponentTypeTuningProperties
                                                                                  where x.ControlSystemTuningPropertyId == matchProperty.Id
                                                                                  && x.ControlSystemComponentTypeId == matchingComponent.ControlSystemComponentTypeId
                                                                                  select x).FirstOrDefault();

                if (matchCompTypeProperty == null)
                {
                    var controlSystemPropertyName = (from x in Cee.ControlSystemTuningProperties where x.Id == matchProperty.Id select x.Name).FirstOrDefault();
                    var controlSystemTypeName = (from x in Cee.ControlSystemComponentTypes where x.Id == matchingComponent.ControlSystemComponentTypeId select x.Name).FirstOrDefault();

                    string message = string.Format("Missing a entry in Database for the Table 'ControlSystemComponentTypeTuningProperty' Where ControlSystemComponentTyped = '{0}'({1}) And ControlSystemTuningPropertyId = '{2}' ({3}). Row {4}.", matchingComponent.ControlSystemComponentTypeId, controlSystemTypeName, matchProperty.Id, controlSystemPropertyName, i);
                    RaiseMessage(CommonUtils.MessageType.Error, message);
                    continue;
                }

                //check for duplicates properties on this component (not allowed).
                var duplicateCount = (from x in  Cee.ControlSystemTuningPropertyValues
                                      where x.ControlSystemComponentId == matchingComponent.ControlSystemComponentTypeId
                                         && x.ControlSystemTuningPropertyId == matchProperty.Id
                                      select x.Id).Count();

                if (duplicateCount > 0)
                {
                    var propertyName = matchProperty.Name;
                    var componentName = matchingComponent.Name;

                    string message = string.Format("An entry already exists in Database for the Table 'ControlSystemComponentTypeTuningProperty' Where ControlSystemComponentId = '{0}'({1}) And ControlSystemTuningPropertyId = '{2}' ({3}). Row {4}.", matchingComponent.ControlSystemComponentTypeId, componentName, matchProperty.Id, propertyName, i);
                    RaiseMessage(CommonUtils.MessageType.Error, message);
                    continue;
                }

                if (PropertyValueToPropertyTypeMismatched(matchProperty.PropertyListId, matchProperty.Type, dynamicProperty, i + 1)) { continue; }

                ControlSystemTuningPropertyValue propertyValue = new ControlSystemTuningPropertyValue
                {
                    ControlSystemTuningPropertyId = matchProperty.Id,
                    ControlSystemComponentId = matchingComponent.Id,
                    Value = dynamicProperty.PropertyValue,
                    VerifiedUserDate = string.Format("{0} by {1}", DateTime.Now.ToString(@"dd/MM/yyyy hh:mm"), mUser.FirstLastName)
                };

                matchingComponent.ControlSystemTuningPropertyValues.Add(propertyValue);

                PropertyNameComponentNamePair pair = new PropertyNameComponentNamePair
                {
                    ComponentName = matchingComponent.Name,
                    PropertyName = matchProperty.Name,
                    Value = dynamicProperty.PropertyValue
                };

                mSavedResults.Add(pair);
            }
        }
Пример #22
0
        private void UpdateDynamicProperties(TuningPropertiesDataAdapter adapter, ControlSystemComponent matchingComponent, int i)
        {
            foreach (DynamicProperty dynamicProperty in adapter.DynamicProperties.Where(x => !string.IsNullOrEmpty(x.PropertyValue)))
            {
                ControlSystemTuningProperty matchProperty = (from x in Cee.ControlSystemTuningProperties where string.Compare(x.Name, dynamicProperty.PropertyName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();

                if (matchProperty == null)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildItemNotFoundInDatabaseMessage("ControlSystemTuningProperty", dynamicProperty.PropertyName, i + 1)));
                    continue;
                }

                //is this property assocaited with the comp type?
                ControlSystemComponentTypeTuningProperty matchCompTypeProperty = (from x in Cee.ControlSystemComponentTypeTuningProperties
                                                                                  where x.ControlSystemTuningPropertyId == matchProperty.Id
                                                                                  && x.ControlSystemComponentTypeId == matchingComponent.ControlSystemComponentTypeId
                                                                                  select x).FirstOrDefault();

                if (matchCompTypeProperty == null)
                {
                    string controlSystemTuningPropertyName = (from x in Cee.ControlSystemTuningProperties where x.Id == matchProperty.Id select x.Name).FirstOrDefault();
                    var controlSystemTypeName = (from x in Cee.ControlSystemComponentTypes where x.Id == matchingComponent.ControlSystemComponentTypeId select x.Name).FirstOrDefault();
                    string message = string.Format("Missing a entry in Database for the Table 'ControlSystemComponentTypeTuningProperty' Where ControlSystemComponentTyped = '{0}'({1}) And ControlSystemTuningPropertyId = '{2}' ({3}). Row {4}.", matchingComponent.ControlSystemComponentTypeId, controlSystemTypeName, matchProperty.Id, controlSystemTuningPropertyName, i);
                    RaiseMessage(CommonUtils.MessageType.Error, message);
                    continue;
                }

                ControlSystemTuningPropertyValue matchSystemPropertyValue = (from x in Cee.ControlSystemTuningPropertyValues
                                                                             where (x.ControlSystemTuningPropertyId == matchProperty.Id) && (x.ControlSystemComponentId == matchingComponent.Id)
                                                                             select x).FirstOrDefault();

                if (dynamicProperty.PropertyValue.ToLower().Trim() == NULLTEXT)
                {
                    if (matchSystemPropertyValue == null)
                    {
                        //do nothing
                        continue;
                    }

                    //delete
                    Cee.ControlSystemTuningPropertyValues.Remove(matchSystemPropertyValue);
                }
                else
                {
                    if (PropertyValueToPropertyTypeMismatched(matchProperty.PropertyListId, matchProperty.Type, dynamicProperty, i + 1)) { continue; }

                    if (matchSystemPropertyValue == null)
                    {
                        //create
                        matchSystemPropertyValue = new ControlSystemTuningPropertyValue
                        {
                            ControlSystemTuningPropertyId = matchProperty.Id,
                            ControlSystemComponentId = matchingComponent.Id,
                            Value = dynamicProperty.PropertyValue,
                            VerifiedUserDate = string.Format("{0} by {1}", DateTime.Now.ToString(@"dd/MM/yyyy hh:mm"), mUser.FirstLastName)
                        };
                        Cee.ControlSystemTuningPropertyValues.Add(matchSystemPropertyValue);
                    }
                    else
                    {
                        //update
                        matchSystemPropertyValue.Value = dynamicProperty.PropertyValue;
                        matchSystemPropertyValue.VerifiedUserDate = string.Format("{0} by {1}", DateTime.Now.ToString(@"dd/MM/yyyy hh:mm"), mUser.FirstLastName);
                    }
                }

                PropertyNameComponentNamePair pair = new PropertyNameComponentNamePair
                {
                    ComponentName = matchingComponent.Name,
                    PropertyName = matchProperty.Name,
                    Value = dynamicProperty.PropertyValue
                };

                mSavedResults.Add(pair);
            }
        }