public ControlSystemDocumentsView(ControlSystem ControlSystem)
        {
            InitializeComponent();

            mViewModel = new ControlSystemDocumentsViewModel(ControlSystem);
            mViewModel.CollectionChanged += (count) => OnCollectionChanged(count);
            mViewModel.View = this;
            mViewModel.Loaded += ViewModelLoaded;
        }
예제 #2
0
        private List<UpperEquipment> mAllUpperEquipments; //everytime the Selected Area is bound we need to reset the upper equipment list using the area id selected.

        #endregion Fields

        #region Constructors

        public AddControlSystemViewModel()
        {
            CompositionInitializer.SatisfyImports(this);

            ControlSystem = new ControlSystem();
            ControlSystem.IsActive = true;
            UpperEquipments = new List<UpperEquipment>();

            var pidDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypePidCode);
            var specificationDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypeFuncspecCode);
            var controlSystemTypesTask = DatabaseLoader.GetQuickControlSystemTypes();
            var upperEquipmentsTask = DatabaseLoader.GetUpperEquipments();
            var graphicsTask = DatabaseLoader.GetQuickGraphics();

            List<Task> tasks = new List<Task>
            {
                pidDocumentsTask,
                specificationDocumentsTask,
                controlSystemTypesTask,
                upperEquipmentsTask,
                graphicsTask
            };

            Task.Factory.ContinueWhenAll(tasks.ToArray(), x =>
            {
                CMS.UiFactory.StartNew(() =>
               {
                   PandIDDocuments = new List<QuickDocument>(pidDocumentsTask.Result);
                   SpecificationDocuments = new List<QuickDocument>(specificationDocumentsTask.Result);
                   Types = new List<QuickControlSystemType>(controlSystemTypesTask.Result);

                   mAllUpperEquipments = upperEquipmentsTask.Result;
                   mAllUpperEquipments.Insert(0, new UpperEquipment { Name = CMS.Constants.UpperEquipmentNullName });
                   UpperEquipments = new List<UpperEquipment>(mAllUpperEquipments);

                   Graphics = new List<QuickGraphic>(graphicsTask.Result.ToList());

                   Areas = new List<Area>(from a in CMS.Cache.Areas where a.IsActive && a.SiteId == CMS.AppSetting.DefaultSiteId select a).ToList();

                   RaisePropertyChanged("Types");
                   RaisePropertyChanged("PandIDDocuments");
                   RaisePropertyChanged("SpecificationDocuments");
                   RaisePropertyChanged("UpperEquipments");

                   RaisePropertyChanged("Graphics");
                   RaisePropertyChanged("Areas");

                   OnDataSourceLoaded();

               });

            });

            OkButtonCommand = new DelegateCommand<object>(OkButtonHander, CanModify);
            CancelButtonCommand = new DelegateCommand<object>(CancelButtonHander, x => true);
        }
        public ControlSystemTestingPropertiesControl(ControlSystem controlSystem)
        {
            InitializeComponent();

            CompositionInitializer.SatisfyImports(this);
            mControlSystem = controlSystem;

            ComponentName = mControlSystem.Name;

            PopulatePropertyValues(controlSystem);
        }
        public ControlSystemRelatedIssuesViewModel(ControlSystem controlSystem)
        {
            CompositionInitializer.SatisfyImports(this);
            mControlSystem = controlSystem;

            LoadData();

            CreateCommand = new DelegateCommand<object>(AddRelatedIssueHandler, CanCreate);
            LinkCommand = new DelegateCommand<object>(LinkIssueButtonHandler, CanLink);
            ViewCommand = new DelegateCommand<object>(OpenIssueButtonHandler, CanView);
        }
        public ControlSystemRelatedIssuesView(ControlSystem controlSystem)
        {
            if (DesignerProperties.IsInDesignTool)
            {
                return;
            }

            InitializeComponent();

            ControlSystemRelatedIssuesViewModel model = new ControlSystemRelatedIssuesViewModel(controlSystem);
            model.CollectionChanged += (count) => { OnCollectionChanged(count); };
            model.View = this;
            DataContext = model;
        }
        public ControlSystemDocumentsViewModel(ControlSystem ControlSystem)
        {
            CompositionInitializer.SatisfyImports(this);
            mControlSystem = ControlSystem;

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            cmsWebServiceClient.GetControlSystemDocumentsCompleted += cmsWebServiceClient_GetControlSystemDocumentsCompleted;
            cmsWebServiceClient.GetControlSystemDocumentsAsync(ControlSystem.Id);

            AddButton = new DelegateCommand<object>(AddButtonHandler, CanAdd);
            DeleteButton = new DelegateCommand<object>(DeleteButtonHandler, CanDelete);
            OpenDocumentLink = new DelegateCommand<object>(OpenDocumentHandler, CanView);
        }
예제 #7
0
        public bool GetControlSytemTypeFailed(string typeName, ControlSystem newControlSystem, int rowIndex)
        {
            if (!string.IsNullOrEmpty(typeName))
            {
                ControlSystemType type = (from x in mExistingControlSystemTypes where string.Compare(x.Name, typeName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();
                if (type == null)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format("WorkSheet '{0}' Row '{1}':Could not match '{2}' Control System Type Name Type. Skipping.", WorkSheetName, rowIndex, typeName));
                    return true;
                }

                newControlSystem.ControlSystemTypeId = type.Id;
            }
            return false;
        }
        public ControlSystemComponentsViewModel(ControlSystem controlSystemEquipment)
        {
            CompositionInitializer.SatisfyImports(this);
            ControlSystem = controlSystemEquipment;
            MovedComponents = new List<ControlSystemComponent>();

            AddComponentCommand = new DelegateCommand<object>(AddButtonHandler, CanAdd);
            RemoveComponentCommand = new DelegateCommand<object>(DeleteButtonHandler, CanDelete);
            EditComponentCommand = new DelegateCommand<object>(EditComponentHandler, CanModify);
            SelectComponentCommand = new DelegateCommand<object>(SelectButtonHandler, CanView);
            MoveComponentCommand = new DelegateCommand<object>(MoveComponentHandler, CanModify);

            mDictionary = Utils.BuildDictionaryForCollection(ControlSystem.ControlSystemComponents.Select(x => x.Id).ToList());

            Task<List<ControlSystemAlarmPurpose>> getPurposeListTask = DatabaseLoader.GetControlSystemAlarmPurposes();
            Task<List<ControlSystemAlarmConsequence>> getConsequenceListTask = DatabaseLoader.GetControlSystemAlarmConsequences();
            Task<List<ControlSystemAlarmResponse>> getResponseListTask = DatabaseLoader.GetControlSystemAlarmResponses();
            Task<List<ControlSystemAlarmColour>> getAlarmColoursTask = DatabaseLoader.GetControlSystemAlarmColours();
            Task<List<ControlSystemAlarmPriority>> getAlarmPrioritiesTask = DatabaseLoader.GetControlSystemAlarmPriorities();

            var tasks = new List<Task>
            {
                getPurposeListTask,
                getConsequenceListTask,
                getResponseListTask,
                getAlarmColoursTask,
                getAlarmPrioritiesTask,

            };

            Task.Factory.ContinueWhenAll(tasks.ToArray(), xx =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    mAlarmLists = new AlarmLists
                    {
                        AlarmColours = getAlarmColoursTask.Result,
                        Consequences = getConsequenceListTask.Result,
                        Priorities = getAlarmPrioritiesTask.Result,
                        Purposes = getPurposeListTask.Result,
                        Responses = getResponseListTask.Result
                    };
                });
            });
        }
        public ControlSystemAttachmentsViewModel(ControlSystem controlSystem, ControlSystemAttachmentsControl view)
        {
            CompositionInitializer.SatisfyImports(this);

            View = view;

            AddAttachmentCommand = new DelegateCommand<object>(AddFileHandler, CanAdd);
            RemoveAttachmentCommand = new DelegateCommand<object>(DeleteButtonHandler, CanDelete);
            ExportButton = new DelegateCommand<object>(ExportButtonHandler, x => true);

            mControlSystem = controlSystem;

            Attachments = new ObservableCollection<ControlSystemAttachment>();

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);
            cmsWebServiceClient.GetAttachmentTypesCompleted += cmsWebServiceClient_GetAttachmentTypesCompleted;
            cmsWebServiceClient.GetAttachmentTypesAsync();
        }
        public ControlSystemInterlocksViewModel(ControlSystem controlSystemEquipment)
        {
            CompositionInitializer.SatisfyImports(this);
            mControlSystem = controlSystemEquipment;

            AddInterlockCommand = new DelegateCommand<object>(AddButtonHandler, CanAdd);
            RemoveInterlockCommand = new DelegateCommand<object>(DeleteButtonHandler, CanDelete);
            EditInterlockCommand = new DelegateCommand<object>(EditInterlockHandler, CanModify);
            SelectInterlockCommand = new DelegateCommand<object>(SelectButtonHandler, CanView);
            CopyInterlockCommand = new DelegateCommand<object>(CopyInterlockHandler, CanModify);

            mDictionary = Utils.BuildDictionaryForCollection(mControlSystem.Interlocks.Select(x => x.Id).ToList());

            CmsWebServiceClient cmsWebServiceClient = new CmsWebServiceClient(Utils.WcfBinding, Utils.WcfEndPoint);

            cmsWebServiceClient.GetControlSystemInterlocksCompleted += (sender, args) =>
                {
                    Interlocks = args.Result;
                };

            cmsWebServiceClient.GetControlSystemInterlocksAsync(mControlSystem.Id);
        }
        public ControlSystemAttachmentsControl(ControlSystem controlSystem)
        {
            InitializeComponent();

            mControlSystem = controlSystem;

            CompositionInitializer.SatisfyImports(this);

            mViewModel = new ControlSystemAttachmentsViewModel(controlSystem, this)
            {
                View = this
            };
            mViewModel.UploadComplete += () =>
            {

            };

            mViewModel.Loaded += (s1) =>
            {
                Utils.ResetOriginalValues(AttachedFilesGridView);
                Utils.SetUpChangeEvents(AttachedFilesGridView, EventAggregator, controlSystem);
                DataContext = mViewModel;

                if (ModelLoaded != null)
                {
                    ModelLoaded();
                }
            };

            mViewModel.ErrorOccurred += (message) =>
            {

                List<string> errors = new List<string>();
                errors.Add(message);
                this.ValidationPopup.Show(Utils.BuildValidationResultFromServerErrors("", errors));
            };

            mViewModel.CollectionChanged += (count) => { OnCollectionChanged(count); };
        }
예제 #12
0
        private void AddUpdateRevisionHistory(ControlSystem equipment)
        {
            ControlSystemRevisionHistory rvh = BuildRevisionHistory(equipment);

            equipment.ControlSystemRevisionHistories.Add(rvh);
        }
예제 #13
0
        private void AddInsertRevisionHistory(ControlSystem newContrlControlSystem)
        {
            var revision = new decimal(1.000);

            Cee.ControlSystems.Add(newContrlControlSystem);
            var rvh = new ControlSystemRevisionHistory
            {
                Date = DateTime.Now,
                UserId = MetaData.UserId,
                Description = BuildRevisionHistoryInsertComment(MetaData.RevisionHistoryComment),
                Revision = revision,
                IsSystemMessage = true
            };
            newContrlControlSystem.ControlSystemRevisionHistories.Add(rvh);
        }
        private void PopulatePropertyValues(ControlSystem controlSystem)
        {
            var rowCount = 1;
            const int rowHeight = 25;

            var typeTestingProperties = controlSystem.ControlSystemType.ControlSystemTypeTestingProperties;

            var getAllPropertyListsTask = DatabaseLoader.GetAllPropertyLists();
            var getPidDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypePidCode);
            var getSpecDocumentsTask = DatabaseLoader.GetQuickDocuments(CommonUtils.DoctypeFuncspecCode);
            var tasks = new List<Task> { getAllPropertyListsTask, getPidDocumentsTask, getSpecDocumentsTask };

            Task.Factory.ContinueWhenAll(tasks.ToArray(), xx =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    var addedGroups = new List<ComponentTypeGroup>();
                    var propertyLists = getAllPropertyListsTask.Result;

                    mPidDocuments = getPidDocumentsTask.Result.Select(d => d.Name).ToList();
                    mSpecDocuments = getSpecDocumentsTask.Result.Select(d => d.Name).ToList();

                    List<ControlSystemTypeTestingProperty> list = typeTestingProperties.OrderBy(x => x.Ordinal).ThenBy(x => x.GroupOrdinal).ToList();

                    foreach (var typeTestingProperty in list)
                    {
                        //Skip Properties that are not visible
                        if (typeTestingProperty.TestPropertyId.HasValue && !typeTestingProperty.ControlSystemTestingProperty.IsVisible) continue;

                        #region Group

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

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

                            //This is a empty Group so don't need to render a Property
                            if (!typeTestingProperty.TestPropertyId.HasValue) continue;
                        }
                        #endregion

                        #region Property Value

                        var propertyValue = GetPropertyValue(controlSystem, typeTestingProperty);

                        var wrapViewModel = new ControlTestingPropertyWrapViewModel(typeTestingProperty.ControlSystemTestingProperty, propertyValue);
                        PropertyWrapViewModels.Add(wrapViewModel);

                        var element = BindElementValue(wrapViewModel, propertyLists, mPidDocuments, mSpecDocuments);
                        PropertiesGrid.Children.Add(element);
                        Grid.SetRow(element, rowCount);
                        Grid.SetColumn(element, (int)GridColumn.Value);

                        #endregion

                        #region Description

                        var descLabel = new Label();
                        var descLabelBinding = new Binding("ShortDescription")
                        {
                            Mode = BindingMode.OneTime,
                            Source = typeTestingProperty.ControlSystemTestingProperty
                        };

                        descLabel.SetBinding(ContentControl.ContentProperty, descLabelBinding);

                        descLabel.Margin = new Thickness(1);

                        PropertiesGrid.Children.Add(descLabel);
                        Grid.SetRow(descLabel, rowCount);
                        Grid.SetColumn(descLabel, (int)GridColumn.Description);

                        var toolTip = new ToolTip { Content = typeTestingProperty.ControlSystemTestingProperty.Description };
                        ToolTipService.SetToolTip(descLabel, toolTip);

                        #endregion

                        #region Notes

                        //NOTES
                        var binding = new Binding("Notes")
                        {
                            Mode = BindingMode.TwoWay,
                            Source = wrapViewModel,
                            UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
                        };

                        var notesTextBox = new CmsTextBox();
                        notesTextBox.SetBinding(TextBox.TextProperty, binding);

                        notesTextBox.Margin = new Thickness(1);

                        var toolTipNotes = new ToolTip { Content = wrapViewModel.Notes };
                        ToolTipService.SetToolTip(notesTextBox, toolTipNotes);

                        notesTextBox.ResetOriginalValue();
                        notesTextBox.ControlChanged += ControlChanged;
                        PropertiesGrid.Children.Add(notesTextBox);
                        Grid.SetRow(notesTextBox, rowCount);
                        Grid.SetColumn(notesTextBox, (int)GridColumn.Notes);

                        #endregion

                        if (wrapViewModel.PropertyType == CommonUtils.PropertyType.LargeText)
                        {
                            descLabel.VerticalAlignment = VerticalAlignment.Top;
                            notesTextBox.VerticalAlignment = VerticalAlignment.Stretch;
                        }
                        else
                        {
                            descLabel.VerticalAlignment = VerticalAlignment.Center;
                            notesTextBox.VerticalAlignment = VerticalAlignment.Center;
                        }

                        PropertiesGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(element.Height + 2) });

                        rowCount++;
                    }
                });
            });
        }
        private void SaveControlSystemAlarms(ControlSystem controlSystem)
        {
            using (var cee = new CmsEntities())
            {

                foreach (var component in controlSystem.ControlSystemComponents)
                {
                    List<int> ctapList = (from x in cee.ControlSystemComponentTypeAlarmProperties
                                          where x.ComponentTypeId == component.ControlSystemComponentTypeId
                                          select x.AlarmPropertyId).ToList();

                    var dbAlarmPropertyValues = (from x in cee.ControlSystemAlarmPropertyValues where x.ControlSystemComponentId == component.Id select x).ToList();

                    foreach (ControlSystemAlarmPropertyValue dbAlarmPropertyValue in dbAlarmPropertyValues)
                    {
                        cee.ControlSystemAlarmPropertyValues.Remove(dbAlarmPropertyValue);
                        cee.SaveChanges();
                    }

                    List<ControlSystemAlarmPropertyValue> newPVs = new List<ControlSystemAlarmPropertyValue>();

                    foreach (var pv in component.ControlSystemAlarmPropertyValues)
                    {
                        bool isInList = ctapList.IndexOf(pv.ControlSystemAlarmPropertyId) != -1;
                        if (!isInList) { continue; }//no business adding this...

                        //needed to new up to ensure decoupled.
                        ControlSystemAlarmPropertyValue insert = new ControlSystemAlarmPropertyValue
                        {
                            ActivationExpr = pv.ActivationExpr,
                            AlarmCalcExpr = pv.AlarmCalcExpr,
                            AlarmCalcExprEnabled = pv.AlarmCalcExprEnabled,
                            ColourId = pv.ColourId,
                            ConsequenceId = pv.ConsequenceId,
                            ControlSystemAlarmPropertyId = pv.ControlSystemAlarmPropertyId,
                            ControlSystemComponentId = component.Id,
                            Enabled = pv.Enabled,
                            Guidance = pv.Guidance,
                            MaskingExpr = pv.MaskingExpr,
                            Notes = pv.Notes,
                            OffDelay = pv.OffDelay,
                            OnDelay = pv.OnDelay,
                            PriorityId = pv.PriorityId,
                            PurposeId = pv.PurposeId,
                            Reportable = pv.Reportable,
                            ReportableSetById = pv.ReportableSetById,
                            ReportableSetDate = pv.ReportableSetDate,
                            ResponseTimeId = pv.ResponseTimeId,
                            ReviewedCompletedById = pv.ReviewedCompletedById,
                            ReviewCompleted = pv.ReviewCompleted,
                            ReviewedCompletedDate = pv.ReviewedCompletedDate,
                            Tested = pv.Tested,
                            TestedDate = pv.TestedDate,
                            TestedUserId = pv.TestedUserId,
                            ModifiedDate = pv.ModifiedDate,
                            ModifiedUserId = pv.ModifiedUserId
                        };

                        cee.ControlSystemAlarmPropertyValues.Add(insert);
                    }
                }
                cee.SaveChanges();
            }
        }
예제 #16
0
        private void InsertRevisionHistory(InterlockType interLockType, int interlockNumber, ControlSystem controlSystem)
        {
            var revision = new decimal(1.000);

            string comment = string.Empty;

            if (MetaData.ImportType == CommonUtils.ImportType.CreateInterlocks)
            {
                if (!string.IsNullOrEmpty(MetaData.RevisionHistoryComment))
                {
                    comment = BuildRevisionHistoryInsertComment(string.Format("Added Interlock Type '{0}' Number '{1}' to Control '{2}'. {3}",
                        interLockType.Name, interlockNumber, controlSystem.Name, MetaData.RevisionHistoryComment));
                }
                else
                {
                    comment = BuildRevisionHistoryInsertComment(string.Format("Added Interlock Type '{0}' Number '{1}' to Control '{2}'.",
                        interLockType.Name, interlockNumber, controlSystem.Name));
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(MetaData.RevisionHistoryComment))
                {
                    comment = BuildRevisionHistoryUpdateComment(string.Format("Updated Interlock Type '{0}' Number '{1}' on Control '{2}'. {3}",
                        interLockType.Name, interlockNumber, controlSystem.Name, MetaData.RevisionHistoryComment));
                }
                else
                {
                    comment = BuildRevisionHistoryUpdateComment(string.Format("Updated Interlock Type '{0}'  Number '{1}' on Control '{2}'.",
                        interLockType.Name, interlockNumber, controlSystem.Name));
                }
            }

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

            controlSystem.ControlSystemRevisionHistories.Add(rvh);
        }
        private ControlSystemTestingPropertyValue GetPropertyValue(ControlSystem controlSystem, ControlSystemTypeTestingProperty typeTestingProperty)
        {
            ControlSystemTestingPropertyValue propertyValue = (from x in controlSystem.ControlSystemTestingPropertyValues
                                                               where x.TestPropertyId == typeTestingProperty.TestPropertyId &&
                                                                     x.ContolSystemId == controlSystem.Id
                                                               select x).FirstOrDefault();

            if (propertyValue == null && typeTestingProperty.TestPropertyId.HasValue)
            {
                propertyValue = new ControlSystemTestingPropertyValue
                {
                    ContolSystemId = controlSystem.Id,
                    TestPropertyId = typeTestingProperty.TestPropertyId.Value,
                    Value = typeTestingProperty.ControlSystemTestingProperty.DefaultValue
                };

                controlSystem.ControlSystemTestingPropertyValues.Add(propertyValue);
            }
            return propertyValue;
        }
예제 #18
0
        private bool GetGraphicFailed(string graphicName, ControlSystem controlSystem, int i)
        {
            if (!string.IsNullOrEmpty(graphicName))
            {
                Graphic matched = mExistingGraphics.FirstOrDefault(x => string.Compare(x.Name, graphicName, true, CultureInfo.CurrentCulture) == 0);

                if (matched == null)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, BuildItemNameDoesNotExistInDbMessage("Graphic: " + graphicName, i));
                    return true;
                }

                controlSystem.GraphicId = matched.Id;
            }

            return false;
        }
예제 #19
0
        private List<PropertyNameComponentNamePair> UpdateDynamicProperties(InterlockDataAdapter adapter, ControlSystem matchingControl, Interlock matchingInterlock, int i, out bool failed)
        {
            failed = false;
            var results = new List<PropertyNameComponentNamePair>();

            foreach (DynamicProperty dynamicProperty in adapter.DynamicProperties)
            {
                //MATCH THE PROPERTY
                InterlockProperty matchProperty = (from x in Cee.InterlockProperties where string.Compare(x.Name, dynamicProperty.PropertyName, true, CultureInfo.CurrentCulture) == 0 select x).FirstOrDefault();

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

                //CHECK ASSOCIATEION TO INTERLOCK TYPE
                InterlockTypeProperty matchCompTypeProperty = (from x in Cee.InterlockTypeProperties
                    where x.InterlockPropertyId == matchProperty.Id
                          && x.InterlockTypeId == matchingInterlock.InterlockTypeId
                    select x).FirstOrDefault();

                if (matchCompTypeProperty == null)
                {
                    InterlockType matchingInterlockType = (from x in Cee.InterlockTypes where x.Id == matchingInterlock.InterlockTypeId select x).FirstOrDefault();

                    string message = string.Format("Missing a entry in Database for the Table 'InterlockTypeProperty' Where InterlockPropertyId = '{0}'({1}) And InterlockTypeId = '{2}' ({3}). Row {4}.",
                        matchProperty.Id, matchProperty.Name, matchingInterlockType.Id, matchingInterlockType.Name, i);

                    RaiseMessage(CommonUtils.MessageType.Error, message);
                    failed = true;
                    continue;
                }

                //CHECK IF THE PROP VALUE ALREADY EXISTS
                InterlockPropertyValue propertyValue = (from x in Cee.InterlockPropertyValues where (x.InterlockId == matchingInterlock.Id) && (x.InterlockPropertyId == matchProperty.Id) select x).FirstOrDefault();

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

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

                    if (propertyValue == null)
                    {
                        //create
                        propertyValue = new InterlockPropertyValue
                        {
                            InterlockPropertyId = matchProperty.Id,
                            InterlockId = matchingInterlock.Id,
                            Value = dynamicProperty.PropertyValue,
                            VerifiedUserDate = string.Format("{0} by {1}", DateTime.Now.ToString(@"dd/MM/yyyy hh:mm"), mUser.FirstLastName)
                        };
                        Cee.InterlockPropertyValues.Add(propertyValue);
                    }
                    else
                    {
                        //update
                        propertyValue.Value = dynamicProperty.PropertyValue;
                        propertyValue.VerifiedUserDate = string.Format("{0} by {1}", DateTime.Now.ToString(@"dd/MM/yyyy hh:mm"), mUser.FirstLastName);
                    }
                }

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

                results.Add(pair);
            }

            return results;
        }
예제 #20
0
        private ControlSystemRevisionHistory BuildRevisionHistory(ControlSystem controlSystem)
        {
            const decimal incrediment = 0.001m;
            var revision = new decimal(1.000);

            List<decimal> foo = (from x in Cee.ControlSystemRevisionHistories where x.ControlSystemId == controlSystem.Id orderby x.Revision descending select x.Revision).ToList();

            if (foo.Count > 0)
            {
                revision = foo[0] + incrediment;
            }

            var rvh = new ControlSystemRevisionHistory
            {
                Date = DateTime.Now,
                ControlSystemId = controlSystem.Id,
                UserId = MetaData.UserId,
                Description = BuildRevisionHistoryUpdateComment(MetaData.RevisionHistoryComment),
                Revision = revision,
                IsSystemMessage = true
            };
            return rvh;
        }
예제 #21
0
 private static bool MatchControlSystemFailed(CmsEntities cee, ControlModule cm, ControlSystemType controlSystemType, out ControlSystem controlSystem)
 {
     controlSystem = (from x in cee.ControlSystems where x.Name.Equals(cm.Tag, StringComparison.CurrentCultureIgnoreCase) && x.ControlSystemTypeId == controlSystemType.Id select x).FirstOrDefault();
     if (controlSystem == null)
     {
         Logger.Out(string.Format("Warning: Control {0} - No matchng ControlSystem found in CMS using '{0}'.", cm.Tag));
         return true;
     }
     return false;
 }
        private void SaveControlSystemtDocuments(ControlSystem controlSystem, CmsEntities cee)
        {
            //Delete originals
            var originals = (from x in cee.DocumentEquipments
                             where x.EquipmentId == controlSystem.Id
                                   && x.EquipmentTypeId == (int)CommonUtils.EquipmentTypeCode.CONTR
                             select x).ToList();
            originals.ForEach(x => cee.DocumentEquipments.Remove(x));

            if (controlSystem.ControlSystemDocuments != null)
            {
                foreach (var document in controlSystem.ControlSystemDocuments)
                {
                    var newObject = new DocumentEquipment
                    {
                        EquipmentId = controlSystem.Id,
                        DocumentId = document.DocumentId,
                        EquipmentTypeId = (int)CommonUtils.EquipmentTypeCode.CONTR
                    };

                    cee.DocumentEquipments.Add(newObject);
                }
            }
        }
예제 #23
0
        private bool BuildPropertyValueFailed(ControlSystem controlSystem, ControlSystemTestingProperty testingProperty, TestResult testResult, CmsEntities cee, ControlModule cm, out ControlSystemTestingPropertyValue pv)
        {
            pv = new ControlSystemTestingPropertyValue
            {
                ContolSystemId = controlSystem.Id,
                TestPropertyId = testingProperty.Id,
            };

            if (testResult.Notes != null && !string.IsNullOrEmpty(testResult.Notes.Trim()))
            {
                pv.Notes = testResult.Notes; //sets the new Notes property.
            }

            //Numerical
            if (testingProperty.Type.Equals(TestingType.Numerical.ToString(), StringComparison.CurrentCultureIgnoreCase))
            {
                pv.Value = GetNumbers(testResult.Entry); //sets the Numerical checkbox value.
            }

            //VerifiedCheckBox
            else if (testingProperty.Type.Equals(TestingType.VerifiedCheckBox.ToString(), StringComparison.CurrentCultureIgnoreCase))
            {
                pv.Value = testResult.Tested.ToString(); //sets the verified checkbox value.

                if (testResult.TestedDate.HasValue && testResult.TestedUserId.HasValue)
                {
                    var user = (from x in cee.Users where x.Id == testResult.TestedUserId.Value select x).FirstOrDefault();
                    if (user == null)
                    {
                        Logger.Out(string.Format("Warning: Control {0} - No matchng User found in CMS using USer.Idn = '{1}'.", cm.Tag, testResult.TestedUserId.Value));
                        return true;
                    }

                    pv.VerifiedUserDate = string.Format("{0} by {1} {2}", testResult.TestedDate.Value.ToString(DATE_FORMAT), user.FirstName, user.LastName);
                }
            }

            return false;
        }
예제 #24
0
        private static void SetOrdinalAndGroupOnControlTypeTestingProperty(ARTEntities art, CmsEntities cee, TestResult testResult, ControlModule cm, ControlSystem controlSystem)
        {
            //get the number for this testresult to use on the ControlSystemTypeTestingProperty.Number
            var tp = (from x in cee.ControlSystemTestingProperties where x.Description.Equals(testResult.Test.Description, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();
            if (tp == null)
            {
                //log error
                Logger.Out(string.Format("Control {0} - Trying to set ordinal. No matchng ControlSystemTestingProperty found in CMS using Description = '{1}'.", cm.Tag, testResult.Test.Description));
                return;
            }

            var controlSystemTypeTestingProperty = (from x in cee.ControlSystemTypeTestingProperties
                                                    where x.ControlSystemTypeId == controlSystem.ControlSystemTypeId
                                                          && x.TestPropertyId == tp.Id
                                                    select x).FirstOrDefault();

            if (controlSystemTypeTestingProperty == null)
            {
                Logger.Out(string.Format("Control {0} - Trying to set ordinal. No matchng ControlSystemTypeTestingProperty found in CMS using ControlSystemTypeId = '{1}' and TestPropertyId = {2}.", cm.Tag, controlSystem.ControlSystemTypeId, tp.Id));
                return;
            }

            //matchGroup
            if (testResult.Test == null)
            {
                Logger.Out(string.Format("Control {0} - Trying to set Group Id. No Tests exist on TestResult.Test. ", cm.Tag));
                return;
            }

            if (controlSystemTypeTestingProperty.Ordinal == 0)
            {
                //not been set before.
                controlSystemTypeTestingProperty.GroupOrdinal = testResult.Number;
            }

            Stage stage = (from x in art.Stages where x.Id == testResult.Test.StageId select x).FirstOrDefault();

            if (stage != null)
            {
                if (controlSystemTypeTestingProperty.Ordinal == 0)
                {
                    //not been set before.
                    if (stage.Description.Equals("Stage 2", StringComparison.CurrentCultureIgnoreCase))
                    {
                        controlSystemTypeTestingProperty.Ordinal = 1;
                    }
                    else if (stage.Description.Equals("Stage 3", StringComparison.CurrentCultureIgnoreCase))
                    {
                        controlSystemTypeTestingProperty.Ordinal = 2;
                    }
                    else if (stage.Description.Equals("Stage 4", StringComparison.CurrentCultureIgnoreCase))
                    {
                        controlSystemTypeTestingProperty.Ordinal = 3;
                    }
                }

                //check if we have cee.Group.
                ComponentTypeGroup typeGroup = (from x in cee.ComponentTypeGroups
                                                where x.Name.Equals(stage.Description, StringComparison.InvariantCultureIgnoreCase)
                                                    && x.ComponentPropertyType.Equals(CommonUtils.EquipmentPropertyType.SystemTestingProperty.ToString(), StringComparison.InvariantCultureIgnoreCase)
                                                select x).FirstOrDefault();

                if (typeGroup == null)
                {
                    //CREATE GROUP
                    typeGroup = new ComponentTypeGroup
                    {
                        Name = stage.Description,
                        ComponentPropertyType = CommonUtils.EquipmentPropertyType.SystemTestingProperty.ToString()
                    };

                    cee.ComponentTypeGroups.Add(typeGroup);
                    cee.SaveChanges();
                    Logger.Out(string.Format("Control {0} - Created new CMS ComponentTypeGroup '{1}'. ", cm.Tag, typeGroup.Name));

                }

                controlSystemTypeTestingProperty.ComponentTypeGroupId = typeGroup.Id;
            }
        }
예제 #25
0
        private bool GetEquipmentModuleOrUnitFailed(string upperEquipmentName, ControlSystem controlSystem, int i)
        {
            if (!string.IsNullOrEmpty(upperEquipmentName))
            {
                EquipmentModule matchedModule = mExistingEquipmentModules.FirstOrDefault(x => string.Compare(x.Name, upperEquipmentName, true, CultureInfo.CurrentCulture) == 0);

                if (matchedModule == null)
                {
                    Unit matchedUnit =(from x in Cee.Units where x.Name.Equals(upperEquipmentName, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();

                    if (matchedUnit == null)
                    {
                        RaiseMessage(CommonUtils.MessageType.Error, BuildItemNameDoesNotExistInDbMessage("EquipmentModule: " + upperEquipmentName, i));
                        return true;
                    }

                    controlSystem.EquipmentModuleId = null;
                    controlSystem.UnitId = matchedUnit.Id;
                }
                else
                {
                    controlSystem.EquipmentModuleId = matchedModule.Id;
                    controlSystem.UnitId = null;
                }
            }
            else
            {
                controlSystem.EquipmentModuleId = null;
            }

            return false;
        }
        private void DeleteIssueIssueRelatedOverrides(ControlSystem controlSystem, Interlock interlock, CmsEntities cee, int userId)
        {
            const string Date24HTimestamp = "dd/MM/yyyy HH:mm";

            var issueRelatedOverrides = (from x in cee.IssueRelatedOverrides.Include("Issue") where x.InterlockId == interlock.Id select x).ToList();

            var user = (from x in cee.Users where x.Id == userId select x).FirstOrDefault();

            foreach (var relatedOverride in issueRelatedOverrides)
            {
                var appliedByUser = (from x in cee.Users where x.Id == relatedOverride.AppliedById select x).FirstOrDefault();
                var responseText = string.Format("Related Override {0}-{1}-{2} deleted from Control Module {3} by {4} on {5}. Override Applied on {6} by {7}. Override Removed on {8} by {4}", interlock.InterlockType.Name, interlock.Number, interlock.Cause, controlSystem.Name, user.FirstLastName, DateTime.Now.ToString(Date24HTimestamp), relatedOverride.AppliedDate, appliedByUser.FirstLastName, DateTime.Now.ToString(Date24HTimestamp));

                var issueResponse = new IssueResponse
                {
                    IssueId = relatedOverride.IssueId,
                    PriorityId = relatedOverride.Issue.IssuePriorityId,
                    UserId = user.Id,
                    StatusId = relatedOverride.Issue.IssueStatusId,
                    AssignedToId = relatedOverride.Issue.CurrentlyAssignedToId,
                    Date = DateTime.Now,
                    ResponseText = responseText
                };

                cee.IssueRelatedOverrides.Remove(relatedOverride);
                cee.IssueResponses.Add(issueResponse);
            }
        }
예제 #27
0
        private void InsertData(IList<ControlDataAdapter> importData)
        {
            if (importData.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, NoDataFoundForWorkSheetMessage());
                return;
            }

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

                IList<string> names = (from x in importData select x.ControlSystemName).ToList();
                if (DuplicateItemNameFoundInExcell(adapter.ControlSystemName, names, i + 1)) { continue; }

                ControlSystem controlSystem = (from x in Cee.ControlSystems where x.Name.Equals(adapter.ControlSystemName, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();

                if (controlSystem != null)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildDuplicateNameExistsInDbMessage(adapter.ControlSystemName, i + 1)));
                    continue;
                }

                controlSystem = new ControlSystem{IsActive = true};

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

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

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

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

                //AreaNumber
                if (string.IsNullOrEmpty(adapter.AreaNumber))
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildPropertyEmpty("AreaNumber", i + 1)));
                    continue;
                }
                int areaId;
                if (GetAreaFailed(adapter.AreaNumber, i + 1, out areaId, false)) { continue; }
                if (areaId <= 0)
                {
                    continue;
                }
                controlSystem.AreaId = areaId;

                //ControlSytemType
                if (GetControlSytemTypeFailed(adapter.ControlSytemTypeName, controlSystem, i + 1)) { continue; }

                //EquipmentModule - or Unit
                if (GetEquipmentModuleOrUnitFailed(adapter.UpperEquipmentName, controlSystem, i + 1)) { continue; }

                //Graphic
                if (GetGraphicFailed(adapter.GraphicName, controlSystem, i + 1)) { continue; }

                //Specification
                if (!string.IsNullOrEmpty(adapter.SpecificationName))
                {
                    int docId;
                    if (GetSpecDocumentFailed(adapter.SpecificationName, out docId, i + 1))
                    {
                        continue;
                    }
                    controlSystem.SpecificationDocumentId = docId;

                }

                //PandID
                if (!string.IsNullOrEmpty(adapter.PIDName))
                {
                    int docId;
                    if (GetPIDDocumentFailed(adapter.PIDName, out docId, i + 1))
                    {
                        continue;
                    }
                    controlSystem.PandIDDocumentId = docId;
                }

                //Name
                if (adapter.ControlSystemName.Trim().Length > 50)
                {
                    RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildPropertyTooLong("Name ", 50, i + 1)));
                    continue;
                }
                controlSystem.Name = adapter.ControlSystemName.Trim();

                //Description
                if (!string.IsNullOrEmpty(adapter.Description))
                {
                    if (adapter.Description == NULLTEXT)
                    {
                        controlSystem.Description = string.Empty;
                    }
                    else
                    {
                        if (adapter.Description.Trim().Length > 250)
                        {
                            RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildPropertyTooLong("Description ", 250, i + 1)));
                            continue;
                        }
                        controlSystem.Description = adapter.Description.Trim();
                    }
                }

                //NOTES
                if (!string.IsNullOrEmpty(adapter.Notes))
                {
                    if (adapter.Notes == NULLTEXT)
                    {
                        controlSystem.Notes = string.Empty;
                    }
                    else
                    {
                        if (adapter.Notes.Trim().Length > 250)
                        {
                            RaiseMessage(CommonUtils.MessageType.Error, string.Format(BuildPropertyTooLong("Notes ", 250, i + 1)));
                            continue;
                        }
                        controlSystem.Notes = adapter.Notes.Trim();
                    }
                }

                //IsActive
                controlSystem.Classified = (adapter.Classified.ToLower().Trim() == "true");

                AddInsertRevisionHistory(controlSystem);

                mSavedResults.Add(controlSystem);
            }

            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 (ControlSystem system in mSavedResults)
                {
                    RaiseMessage(CommonUtils.MessageType.Added, string.Format("Processed Control System '{0}'.", system.Name));
                }
            }
        }
예제 #28
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;
        }
        private void SaveControlSystemRelatedIssues(ControlSystem controlSystem, CmsEntities cee)
        {
            //Delete original
            var originals =
                (from x in cee.IssueRelatedControlSystems where x.ControlSystemId == controlSystem.Id select x).ToList();
            originals.ForEach(x => cee.IssueRelatedControlSystems.Remove(x));

            foreach (var relatedControlSystem in controlSystem.IssueRelatedControlSystems)
            {
                var newObject = new IssueRelatedControlSystem
                {
                    ControlSystemId = controlSystem.Id,
                    IssueId = relatedControlSystem.IssueId,
                    Notes = relatedControlSystem.Notes,
                    TestedById = relatedControlSystem.TestedById,
                    TestedDate = relatedControlSystem.TestedDate,
                    ImplementedById = relatedControlSystem.ImplementedById,
                    ImplementedDate = relatedControlSystem.ImplementedDate
                };

                cee.IssueRelatedControlSystems.Add(newObject);
            }
        }
        private void SaveControlSystemTestingProperties(ControlSystem controlSystem)
        {
            using (var cee = new CmsEntities())
            {
                foreach (var propertyValue in controlSystem.ControlSystemTestingPropertyValues)
                {
                    var qq = (from x in cee.ControlSystemTestingPropertyValues
                              where x.Id == propertyValue.Id
                              select x).FirstOrDefault();

                    if (qq != null)
                    {
                        cee.Entry(qq).CurrentValues.SetValues(propertyValue);
                    }
                    else
                    {
                        cee.ControlSystemTestingPropertyValues.Add(propertyValue);
                    }

                    cee.SaveChanges();
                }
            }
        }