public AddEditAlarmColourViewModel()
        {
            //NEW
            AlarmColour = new ControlSystemAlarmColour();

            LoadData();

            InitialiseCommandButtons();
        }
        private void LoadData()
        {
            var getPurposeListTask = DatabaseLoader.GetControlSystemAlarmPurposes();
            var getConsequenceListTask = DatabaseLoader.GetControlSystemAlarmConsequences();
            var getResponseListTask = DatabaseLoader.GetControlSystemAlarmResponses();
            var getAlarmColoursTask = DatabaseLoader.GetControlSystemAlarmColours();
            var getAlarmPrioritiesTask = DatabaseLoader.GetControlSystemAlarmPriorities();

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

            Task.Factory.ContinueWhenAll(tasks.ToArray(), xx =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    Consequences = getConsequenceListTask.Result;
                    Responses = getResponseListTask.Result;
                    Purposes = getPurposeListTask.Result;
                    Priorities = getAlarmPrioritiesTask.Result;

                    ControlSystemAlarmPriority noSelectionPriority = new ControlSystemAlarmPriority { Id = -1, Name = " -- " };
                    Priorities.Insert(0, noSelectionPriority);

                    Colours = getAlarmColoursTask.Result;
                    ControlSystemAlarmColour noSelectionColour = new ControlSystemAlarmColour { Id = -1, Name = " -- " };
                    Colours.Insert(0, noSelectionColour);

                    ControlSystemAlarmPurpose noSelectionPurpose = new ControlSystemAlarmPurpose { Id = -1, Name = " -- " };
                    Purposes.Insert(0, noSelectionPurpose);

                    ControlSystemAlarmResponse noSelectionResponse = new ControlSystemAlarmResponse { Id = -1, Name = " -- " };
                    Responses.Insert(0, noSelectionResponse);

                    ControlSystemAlarmConsequence noSelectionConsequence = new ControlSystemAlarmConsequence { Id = -1, Name = " -- " };
                    Consequences.Insert(0, noSelectionConsequence);

                    OnDataLoaded();

                    RaiseAllPropertyChangedEvents();

                });
            });
        }
        public void LoadData(bool isEdit = false)
        {
            var getControlSystemAlarmColoursTask = DatabaseLoader.GetControlSystemAlarmColours();

            var tasks = new List<Task> {getControlSystemAlarmColoursTask};

            Task.Factory.ContinueWhenAll(tasks.ToArray(), x =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    ExistingColours = getControlSystemAlarmColoursTask.Result;

                    if (isEdit)
                    {
                        AlarmColour = (from c in ExistingColours where c.Id == mAlarmColourId select c).FirstOrDefault();
                    }

                    OnDataLoaded();
                });
            });
        }
Example #4
0
        private void InsertUpdateAlarmColours(CmsEntities cee)
        {
            var names = (from x in cee.ControlSystemAlarmColours select x.Name).ToList();

            var cyan = new ControlSystemAlarmColour { Name = "C", Description = "Cyan", ColourRed = 0, ColourGreen = 255, ColourBlue = 255 };
            var grey = new ControlSystemAlarmColour { Name = "GR", Description = "Grey", ColourRed = 128, ColourGreen = 128, ColourBlue = 128 };
            var magenta = new ControlSystemAlarmColour { Name = "M", Description = "Magenta", ColourRed = 255, ColourGreen = 0, ColourBlue = 255 };
            var black = new ControlSystemAlarmColour { Name = "N", Description = "Black", ColourRed = 0, ColourGreen = 0, ColourBlue = 0 };
            var red = new ControlSystemAlarmColour { Name = "R", Description = "Red", ColourRed = 255, ColourGreen = 0, ColourBlue = 0 };
            var white = new ControlSystemAlarmColour { Name = "W", Description = "White", ColourRed = 255, ColourGreen = 255, ColourBlue = 255 };
            var yellow = new ControlSystemAlarmColour { Name = "Y", Description = "Yellow", ColourRed = 255, ColourGreen = 255, ColourBlue = 0 };

            if (!names.Contains(cyan.Name))
            {
                cee.ControlSystemAlarmColours.Add(cyan);
            }
            if (!names.Contains(grey.Name))
            {
                cee.ControlSystemAlarmColours.Add(grey);
            }
            if (!names.Contains(magenta.Name))
            {
                cee.ControlSystemAlarmColours.Add(magenta);
            }
            if (!names.Contains(black.Name))
            {
                cee.ControlSystemAlarmColours.Add(black);
            }
            if (!names.Contains(red.Name))
            {
                cee.ControlSystemAlarmColours.Add(red);
            }
            if (!names.Contains(white.Name))
            {
                cee.ControlSystemAlarmColours.Add(white);
            }
            if (!names.Contains(yellow.Name))
            {
                cee.ControlSystemAlarmColours.Add(yellow);
            }

            cee.SaveChanges();
        }
        private void LoadData()
        {
            //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 getCentumsForLevelTask = DatabaseLoader.GetControlSystemAlarmMappingCentumsForLevel(mLevel);
            var getAlarmPropertyValuesRequiredForComponentTypeTask = DatabaseLoader.GetAlarmPropertyValuesRequiredForComponentType(mControlSystemComponent.ControlSystemComponentTypeId);

            var tasks = new List<Task>
            {
                //getPurposeListTask,
                //getConsequenceListTask,
                //getResponseListTask,
                //getAlarmColoursTask,
                //getAlarmPrioritiesTask,
                getCentumsForLevelTask,
                getAlarmPropertyValuesRequiredForComponentTypeTask
            };

            Task.Factory.ContinueWhenAll(tasks.ToArray(), xx =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    var consequences = mAlarmLists.Consequences;//getConsequenceListTask.Result;
                    var responses = mAlarmLists.Responses;//getResponseListTask.Result;
                    var purposes = mAlarmLists.Purposes;//getPurposeListTask.Result;
                    var priorities = mAlarmLists.Priorities;//getAlarmPrioritiesTask.Result;
                    var colours = mAlarmLists.AlarmColours;//getAlarmColoursTask.Result;
                    var centums = getCentumsForLevelTask.Result;

                    ControlSystemAlarmPriority noSelectionPriority = new ControlSystemAlarmPriority { Id = -1, Name = " -- " };
                    priorities.Insert(0, noSelectionPriority);

                    ControlSystemAlarmColour noSelectionColour = new ControlSystemAlarmColour { Id = -1, Name = " -- " };
                    colours.Insert(0, noSelectionColour);

                    ControlSystemAlarmPurpose noSelectionPurpose = new ControlSystemAlarmPurpose { Id = -1, Name = " -- " };
                    purposes.Insert(0, noSelectionPurpose);

                    ControlSystemAlarmResponse noSelectionResponse = new ControlSystemAlarmResponse { Id = -1, Name = " -- " };
                    responses.Insert(0, noSelectionResponse);

                    ControlSystemAlarmConsequence noSelectionConsequence = new ControlSystemAlarmConsequence { Id = -1, Name = " -- " };
                    consequences.Insert(0, noSelectionConsequence);

                    if (AlarmPropertyValues.Any())
                    {
                        AlarmPropertyValues.Clear();
                    }

                    if (mControlSystemComponent.Id == 0 && !mSaveRequiredShown)
                    {
                        mSaveRequiredShown = true;
                        PopupDialog pop = new PopupDialog(PopupDialogType.Information, "Save the new Component first in order to see the Alarm Details.", "Save Required");
                        pop.Show();
                    }
                    else
                    {
                        if (getAlarmPropertyValuesRequiredForComponentTypeTask.Result != null && getAlarmPropertyValuesRequiredForComponentTypeTask.Result.Any())
                        {
                            foreach (var propertyValue in getAlarmPropertyValuesRequiredForComponentTypeTask.Result)
                            {
                                var match = (from x in mControlSystemComponent.ControlSystemAlarmPropertyValues where x.ControlSystemAlarmPropertyId == propertyValue.ControlSystemAlarmPropertyId select x).FirstOrDefault();

                                if (match == null)
                                {
                                    propertyValue.ControlSystemAlarmProperty = propertyValue.ControlSystemAlarmProperty;
                                    propertyValue.ControlSystemComponent = mControlSystemComponent;
                                    mControlSystemComponent.ControlSystemAlarmPropertyValues.Add(propertyValue);
                                }
                            }
                        }
                    }

                    var orderedByNameList = (from x in mControlSystemComponent.ControlSystemAlarmPropertyValues orderby x.ControlSystemAlarmProperty.Name select x).ToList();

                    orderedByNameList.ForEach(x => AlarmPropertyValues.Add(
                        new ControlSystemAlarmPropertiesWrapViewModel(centums, x, mLevel, priorities, colours, purposes, responses, consequences)));

                    RaisePropertyChanged("AlarmPropertyValues");
                    SelectedAlarmPropertyValue = AlarmPropertyValues.FirstOrDefault();

                });
            });
        }
        public DbOperationResult<ControlSystemAlarmColour> SaveControlSystemAlarmColour(ControlSystemAlarmColour alarmColour)
        {
            var result = new DbOperationResult<ControlSystemAlarmColour>();

            try
            {
                using (var cee = new CmsEntities())
                {
                    var original = (from x in cee.ControlSystemAlarmColours where x.Id == alarmColour.Id select x).FirstOrDefault();

                    if (original == null)
                    {
                        cee.ControlSystemAlarmColours.Add(alarmColour);
                        cee.SaveChanges();
                        result.EntityResult = alarmColour;
                    }
                    else
                    {
                        cee.Entry(original).CurrentValues.SetValues(alarmColour);
                        cee.SaveChanges();
                        result.EntityResult = original;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());
                result.ServerErrorMessages.Add(string.Format("Could not Save ControlSystem Alarm Colour.{0}{1}", Environment.NewLine, ex.Message));
            }
            return result;
        }