public EditAlarmMappingCentumPropertyLevelControl(ControlSystemAlarmMappingCentum controlSystemAlarmMappingCentum, List<ControlSystemAlarmPriority> priorities, List<ControlSystemAlarmColour> colours)
        {
            InitializeComponent();

            var model = new EditAlarmPropertyLevelCentumViewModel(controlSystemAlarmMappingCentum, priorities, colours) { View = this };
            DataContext = model;
            Utils.ResetOriginalValues(this);
        }
        public EditAlarmPropertyLevelCentumViewModel(ControlSystemAlarmMappingCentum controlSystemAlarmMappingCentum, List<ControlSystemAlarmPriority> priorities, List<ControlSystemAlarmColour> colours)
        {
            mControlSystemAlarmMappingCentum = controlSystemAlarmMappingCentum;

            Colours = new List<ControlSystemAlarmColour>();
            Colours.AddRange(colours);
            Priorities = new List<ControlSystemAlarmPriority>();
            Priorities.AddRange(priorities);

            RaisePropertyChanged("SelectedPriority");
            RaisePropertyChanged("SelectedColour");
            RaisePropertyChanged("AlarmLevel"); //readonly

            RaisePropertyChanged("Colours");
            RaisePropertyChanged("Priorities");

            OnDataLoaded();
        }
        private void LoadCentumControls(int propertyId)
        {
            var contentControls = new List<ContentControl>
            {
                View.level5,
                View.level6,
                View.level7,
                View.level8,
                View.level9,
                View.level10,
                View.level11,
                View.level12,
                View.level13,
                View.level14,
                View.level15,
                View.level16
            };

            if (ExistingCentums != null && ExistingCentums.Any())
            {
                for (var i = 5; i < 17; i++)
                {
                    var centumPropertyMapping = (from x in ExistingCentums
                                                 where x.PropertyId == propertyId
                                                       && x.Level == i
                                                 select x).FirstOrDefault();
                    if (centumPropertyMapping == null)
                    {
                        centumPropertyMapping = new ControlSystemAlarmMappingCentum { PropertyId = propertyId, Level = i };
                    }

                    var ctrl = new EditAlarmMappingCentumPropertyLevelControl(centumPropertyMapping, mPriorities, mColours);
                    contentControls[i - 5].Content = ctrl;
                    mCentumViewModels.Add(centumPropertyMapping);
                }
            }
        }
Exemple #4
0
        private void ImportCentumMappings(CmsEntities cee, OldCmsEntities old)
        {
            Logger.Out("ImportPropertiesColoursPriorities - start");
            var sw = new Stopwatch();
            sw.Start();

            var k = 0;

            var prioritiesListNames = (from x in cee.ControlSystemAlarmPriorities select x).ToList();

            var alarmTables = (from x in old.AlarmTables
                .Include("AlarmColour")
                .Include("AlarmPriority")
                .Include("AlarmType")
                               select x).ToList();

            foreach (var alarmTable in alarmTables)
            {
                var priority = (from x in prioritiesListNames where x.Name.Equals(alarmTable.AlarmPriority.Priority, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();

                var matchColour = (from x in cee.ControlSystemAlarmColours
                                   where x.Description.Equals(alarmTable.AlarmColour.Description, StringComparison.CurrentCultureIgnoreCase)
                                   select x).FirstOrDefault();

                if (matchColour == null)
                {
                    Logger.Out(string.Format("Skipping {0}", alarmTable.AlarmColour.Name));
                    Logger.Out(string.Format("InsertAlarmMappingsForPropertiesColoursPriorities: Matching Colour in new CMS not found for {0}", alarmTable.AlarmColour.Name));
                    continue;
                }

                var matchPriority = (from x in prioritiesListNames where x.Name.Equals(alarmTable.AlarmPriority.Priority, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();
                if (matchPriority == null)
                {
                    Logger.Out(string.Format("Skipping {0}", alarmTable.AlarmPriority.Priority));
                    Logger.Out(string.Format("InsertAlarmMappingsForPropertiesColoursPriorities: Matching Priority not found in new CMS for {0}", alarmTable.AlarmPriority.Priority));
                    continue;
                }

                var matchProperty = (from x in cee.ControlSystemAlarmProperties where x.Name.Equals(alarmTable.AlarmType.Name, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();
                if (matchProperty == null)
                {
                    Logger.Out(string.Format("Skipping {0}", alarmTable.AlarmType.Name));
                    Logger.Out(string.Format("InsertAlarmMappingsForPropertiesColoursPriorities: Matching Property not in new CMS found for {0}", alarmTable.AlarmType.Name));
                    continue;
                }

                var checkDup = (from x in cee.ControlSystemAlarmMappingCentums
                                where x.PriorityId == priority.Id
                                      && x.ColourId == matchColour.Id
                                      && x.PropertyId == matchProperty.Id
                                      && x.Level == alarmTable.AlarmLevel
                                select x).FirstOrDefault();

                if (checkDup != null)
                {
                    Logger.Out(string.Format("Early exit due to duplicate found in new CMS Table 'ControlSystemAlarmMappingCentum' for on Alarm Table:  " +
                                             "Type:{0}  Colour:{1}  Priority:{2}  Level:{3}",
                        alarmTable.AlarmType.Name,
                        alarmTable.AlarmColour.Name,
                        alarmTable.AlarmPriority.Priority,
                        alarmTable.AlarmLevel));
                    continue;
                }

                var pcp = new ControlSystemAlarmMappingCentum
                {
                    PropertyId = matchProperty.Id,
                    ColourId = matchColour.Id,
                    PriorityId = matchPriority.Id,
                    Level = alarmTable.AlarmLevel //straight copy.
                };

                cee.ControlSystemAlarmMappingCentums.Add(pcp);
                k++;
                UpdateStatus(string.Format("Mapped - Colour:{0}, Priority:{1}, Level:{2}. ({3} of {4}).", matchColour.Description, matchPriority.Name, alarmTable.AlarmLevel, k, alarmTables.Count));
            }

            Logger.Out("Saving PropertyColourPriorities...");
            cee.SaveChanges();
            sw.Stop();
            Logger.Out(string.Format("Imported {0} out of {1} PropertiesColoursPriorities in {2} min, {3} sec.", k, alarmTables.Count, sw.Elapsed.Minutes, sw.Elapsed.Seconds));
            Logger.Out("");
            Logger.Out("");
        }
        public DbOperationResult<ControlSystemAlarmMappingCentum> SaveControlSystemAlarmMappingCentum(ControlSystemAlarmMappingCentum mappingCentum)
        {
            var result = new DbOperationResult<ControlSystemAlarmMappingCentum>();

            try
            {
                using (var cee = new CmsEntities())
                {
                    //check uniquness
                    var duplicateCheck = (from x in cee.ControlSystemAlarmMappingCentums
                                          where x.ColourId == mappingCentum.ColourId
                                                && x.PropertyId == mappingCentum.PropertyId
                                                && x.PriorityId == mappingCentum.PriorityId
                                                && x.Id != mappingCentum.Id
                                          select x).FirstOrDefault();

                    if (duplicateCheck != null)
                    {
                        throw new DuplicateNameException("This Alarm Property-Priority-Property combination already exists.  Existing Id: " + duplicateCheck.Id);
                    }

                    var original = (from x in cee.ControlSystemAlarmMappingCentums where x.Id == mappingCentum.Id select x).FirstOrDefault();

                    if (original == null)
                    {
                        cee.ControlSystemAlarmMappingCentums.Add(mappingCentum);
                        cee.SaveChanges();
                        result.EntityResult = GetControlSystemAlarmMappingCentumsInternal(mappingCentum.Id, cee);
                    }
                    else
                    {
                        cee.Entry(original).CurrentValues.SetValues(mappingCentum);
                        cee.SaveChanges();
                        result.EntityResult = GetControlSystemAlarmMappingCentumsInternal(original.Id, cee);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());
                result.ServerErrorMessages.Add(string.Format("Could not Save Alarm Property-Colour-Prioritiy record.{0}{1}", Environment.NewLine, ex.Message));
            }
            return result;
        }