Пример #1
0
        /// <summary>
        /// Retrieves monitorModules for specific monitor
        /// and populates NumericUpDown controls with assigned limits
        /// </summary>
        private void GetMonitorModules()
        {
            monitorModules = MonitorModule.GetAllFromMonitor(MonitorForm.MonitorId);

            int index = 0;

            foreach (MonitorModule monitorModule in monitorModules)
            {
                modules.ElementAt(index).Text             = monitorModules.ElementAt(index).Module.Name;
                moduleIcon.ElementAt(index).ImageLocation = @"../../Resources/" + monitorModules.ElementAt(index).Module.Icon;
                limitMin.ElementAt(index).Value           = Convert.ToDecimal(monitorModules.ElementAt(index).AssignedMin);
                limitMax.ElementAt(index).Value           = Convert.ToDecimal(monitorModules.ElementAt(index).AssignedMax);
                ++index;
            }
        }
Пример #2
0
        /// <summary>
        /// Retrieves monitorModules from database and sets min and max limit controls values
        /// </summary>
        public void GetMonitorModules()
        {
            monitorModules = MonitorModule.GetAllFromMonitor(MonitorId);

            int index = 0;

            foreach (MonitorModule monitorModule in monitorModules)
            {
                moduleName.ElementAt(index).Text           = monitorModules.ElementAt(index).Module.Name;
                modulesIcon.ElementAt(index).ImageLocation = @"../../Resources/" + monitorModules.ElementAt(index).Module.Icon;
                limitMin.ElementAt(index).Text             = Convert.ToString(monitorModules.ElementAt(index).AssignedMin);
                limitMax.ElementAt(index).Text             = Convert.ToString(monitorModules.ElementAt(index).AssignedMax);

                ++index;
            }
        }
Пример #3
0
        /// <summary>
        /// Automatically select modules in checkedListBox if already attached to monitor
        /// </summary>
        private void SelectExistingModules()
        {
            List <MonitorModule> monitorModules = MonitorModule.GetAllFromMonitor(MonitorForm.MonitorId);

            for (int i = 0; i < checkedListBox_Modules.Items.Count; ++i)
            {
                DataRowView module   = checkedListBox_Modules.Items[i] as DataRowView;
                int         moduleId = Int32.Parse(module["ModuleID"].ToString());

                foreach (MonitorModule monitorModule in monitorModules)
                {
                    if (moduleId == monitorModule.Module.Id)
                    {
                        checkedListBox_Modules.SetItemChecked(i, true);
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Store selected modules in table "monitorModule"
        /// </summary>
        private void SaveSelectedModules()
        {
            List <int> monitorModulesToSkip = new List <int>();

            // retrieve list of monitorModules for current monitor
            List <MonitorModule> monitorModules = MonitorModule.GetAllFromMonitor(MonitorForm.MonitorId);

            //List to store all monitorModules that need to be saved
            List <MonitorModule> modulesToSave = new List <MonitorModule>();

            //List to store all monitorModules that need to be deleted
            List <MonitorModule> modulesToDelete = new List <MonitorModule>();

            // loop over every checkbox
            for (int i = 0; i < checkedListBox_Modules.Items.Count; ++i)
            {
                DataRowView moduleCheckBox = checkedListBox_Modules.Items[i] as DataRowView;
                int         moduleID       = Int32.Parse(moduleCheckBox["ModuleID"].ToString());

                // if module is checked
                if (checkedListBox_Modules.GetItemCheckState(i) == CheckState.Checked)
                {
                    // and it is not found in the monitorModule table
                    if (!monitorModules.Exists(x => x.Module.Id == moduleID))
                    {
                        // then we will need to save it
                        //create monitor and module objects
                        Monitor monitor = new Monitor(MonitorForm.MonitorId);
                        Module  module  = new Module(moduleID);

                        MonitorModule monitorModule = new MonitorModule(monitor, module);
                        monitorModule.AssignedMin = module.DefaultMin;
                        monitorModule.AssignedMax = module.DefaultMax;

                        modulesToSave.Add(monitorModule);
                    }
                }
                else
                {
                    // if the module is unchecked
                    if (checkedListBox_Modules.GetItemCheckState(i) == CheckState.Unchecked)
                    {
                        // we need to check if it was previously checked and saved
                        int indexOfMonitorModuleToDelete = monitorModules.FindIndex(x => x.Module.Id == moduleID);

                        // monitorModule is saved in monitorModule table
                        if (indexOfMonitorModuleToDelete != -1)
                        {
                            // In which case it will need to be deleted
                            modulesToDelete.Add(monitorModules.ElementAt(indexOfMonitorModuleToDelete));
                        }
                    }
                }
            }

            foreach (MonitorModule monitorModuleToSave in modulesToSave)
            {
                monitorModuleToSave.Save();
            }

            foreach (MonitorModule monitorModuleToDelete in modulesToDelete)
            {
                monitorModuleToDelete.Delete();
                StopAlarmForUnpluggedModule(monitorModuleToDelete);
            }
        }