Exemple #1
0
        private void bSave_Click(object sender, EventArgs e)
        {
            //Create new model.
            var model = new Models.Rule()
            {
                DeviceId = _device.Id,
                Device = _device,

                RuleType = (Models.RuleType) cbRuleType.SelectedItem,
                ValueType = (Models.ValueType) cbValueType.SelectedItem,
                Action = null,
                Alarm = cAlarm.Checked,
                Constraint = tConstraint.Text,
                Name = tName.Text
            };

            //Push to Database.
            var controller = new RuleController();
            _rule = controller.CreateRule(model);

            //Update the global Device object.
            var devController = new DeviceController();
            var index = DeviceController.AllDevices.FindIndex(d => d.Id == _device.Id);
            var allRules = new List<Rule>();
            allRules.AddRange(_device.Rules);
            allRules.Add(_rule);
            _device.Rules = allRules;
            DeviceController.AllDevices[index] = _device;
        }
Exemple #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            var controller = new RuleController();
            var ruleObj = controller.TestMethod_GetLatestRule();

            AddAction aa = new AddAction(ruleObj);
            aa.ShowDialog();
        }
Exemple #3
0
        private void DataBoard_Load(object sender, EventArgs e)
        {
            add_cbCommType.DataSource = Enum.GetValues(typeof (Models.CommunicatorType));
            add_cbValueType.DataSource = Enum.GetValues(typeof (Models.ValueType));
            add_cbDatabaseType.DataSource = Enum.GetValues(typeof (Models.DatabaseType));
            add_cbComPort.DataSource = SerialPort.GetPortNames();
            add_cbRuleCheckValue.DataSource = Enum.GetValues(typeof (Models.ValueType));
            //add_cbRuleType.DataSource = Enum.GetValues(typeof (Models.RuleType));

            //Adds known rules for the device to the list box.
            var controller = new RuleController();
            add_cbRule.Items.Clear();
            foreach (Models.Rule rule in controller.RetrieveRulesForDevice(_device.Id)) add_cbRule.Items.Add(rule);

            //Adds outbound comms to the Action list box.
            var commController = new CommunicatorController();
            add_cbCommunicatorDestination.Items.Clear();
            List<Communicator> allComms = commController.GetAllCommunicators().Where(c => c.Device.Id == _device.Id && c.Inbound == false).ToList();
            add_cbCommunicatorDestination.Items.AddRange(allComms.ToArray());
        }
Exemple #4
0
        private void add_bSaveRule_Click(object sender, EventArgs e)
        {
            var contoller = new RuleController();

            _rule = new Models.Rule()
            {
                Device = _device,
                Action = _action,
                Alarm = add_cAlarm.Checked,
                Constraint = add_tConstraint.Text,
                Name = add_tRuleName.Text,
                DeviceId = _device.Id,
                RuleType = (Models.RuleType)add_cbRuleType.SelectedItem,
                ValueType = (Models.ValueType)add_cbRuleCheckValue.SelectedItem
            };

            contoller.CreateRule(_rule);
            contoller.UpdateRule(_rule);

            this.Close();
        }
Exemple #5
0
        private void modrules_tSave_Click(object sender, EventArgs e)
        {
            _rule.Alarm = modrules_cAlarm.Checked;
            _rule.Name = modrules_Name.Text;
            _rule.Constraint = modrules_tConstraint.Text;
            _rule.RuleType = (Models.RuleType) modrules_cbRuleType.SelectedItem;
            _rule.ValueType = (Models.ValueType) modrules_cbValueType.SelectedItem;
           
            var controller = new RuleController();
            var updated = controller.UpdateRule(_rule);

            if (updated != null)
            {
                _rule = updated;
                DebugOutput.Print($"Rule '{updated}' was updated.");
                return;
            }

            DebugOutput.Print($"Could not updated {updated}!");
        }
Exemple #6
0
        private void modify_bRules_Click(object sender, EventArgs e)
        {
            //Loads the relevant communicators.
            var controller = new RuleController();
            modrules_lbRules.Items.Clear();
            modrules_lbRules.Items.AddRange(
                controller.RetrieveRulesForDevice(_selectedDevice.Id).ToArray());

            if (modrules_lbRules.Items.Count > 0)
            {
                //Select the first element
                modrules_lbRules.SelectedItem = modrules_lbRules.Items[0];



                //Shows the modify tab.
                pTabPanel.SelectedTab = pModifyRules;
            }
            else
            {
                var msg =
                    System.Windows.Forms.MessageBox.Show(
                        "There are no Rules for this Device.", "No Rules Available",
                        MessageBoxButtons.OK, MessageBoxIcon.Hand);

                // -------- Create new rule ----------

                //Create and display the DataBoard form.
                var window = new DataBoard(null, _selectedDevice);
                window.GoToRulePage();
                window.ShowDialog();

                //Get the Comm object created.
                _rule = window.GetRule();
            }
        }
Exemple #7
0
 private void UpdateStartLabels()
 {
     var comm_controller = new CommunicatorController();
     var rule_controller = new RuleController();
     var acti_controller = new ActionController();
     
     try
     {
         //Update labels.
         add_lSource.Text = $"{comm_controller.CountCommunicatorsForDevice(_communicator.Device.Id)} Sources...";
         add_lRules.Text = $"{rule_controller.RetrieveRulesForDevice(_selectedDevice.Id).Count()} Rules...";
     }
     catch
     {
         //Update labels.
         add_lSource.Text = $"0 Sources...";
         add_lRules.Text = $"0 Rules...";
     }
 }
Exemple #8
0
        private void alarm_lbAlarms_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Resetting the form.
            alarm_bRule.Enabled = false;
            alarm_bDevice.Enabled = false;
            alarm_tDateTime.Text = "";
            alarm_rbTrue.Checked = false;
            alarm_rbFalse.Checked = false;
            alarm_tValue.Text = "";
            alarm_tDevice.Text = "";

            try
            {
                var selected = (Alarm) alarm_lbAlarms.SelectedItem;

                alarm_tDateTime.Text = selected.TimeStamp.ToString();
                alarm_rbTrue.Checked = selected.Accepted;
                alarm_rbFalse.Checked = !selected.Accepted;

                //Get Value information.
                if (selected.ValueId > 0)
                {
                    var controller = new ValueController();
                    _value = controller.GetValueById(selected.ValueId);
                    selected.Value = _value;
                    alarm_tValue.Text = selected.Value.StringValue;
                }

                //Get Rule information.
                if (selected.RuleId > 0)
                {
                    var controller = new RuleController();
                    _rule = controller.RetrieveRuleById(selected.RuleId);
                    alarm_bRule.Enabled = true;
                }

                //Get Device information.
                if (selected.DeviceId > 0)
                {
                    var controller = new DeviceController();
                    _selectedDevice = controller.RetrieveDevice(selected.DeviceId);
                    selected.Device = _selectedDevice;
                    alarm_tDevice.Text = _selectedDevice.ToString();
                    alarm_bDevice.Enabled = true;
                }
            }
            catch
            {
                DebugOutput.Print("Attempted to load an alarm and failed...");
            }
        }