Exemplo n.º 1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtZoneName.Text))
            {
                Exception ex = new Exception("Validation Exception : Please provide a new unit name!");
                HandleException(ex);
            }
            else if (string.IsNullOrEmpty(textBox1.Text))
            {
                Exception ex = new Exception("Validation Exception : Please provide a IP Address for the unit!");
                HandleException(ex);
            }
            else
            {
                try
                {
                    lfa.pmgmt.data.DAO.Configuration.Unit DAO = new data.DAO.Configuration.Unit();
                    DAO.ConnectionString = _connectionString;
                    DAO.Insert(zoneId, txtZoneName.Text, DateTime.Now,textBox1.Text);

                    HandleInformationMesssage("Data successfully saved! Please refresh the form data!");

                    this.Close();
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }
Exemplo n.º 2
0
        public bool EntireLoadShed()
        {
            bool hasShedAll = false;

            List<lfa.pmgmt.data.DTO.BusinessRule.Load> loadList = new List<data.DTO.BusinessRule.Load>();

            lfa.pmgmt.data.DAO.BusinessRule.Load loadDAO = new data.DAO.BusinessRule.Load();
            loadDAO.ConnectionString = _connectionString;

            loadList = loadDAO.List();

            if (loadList.Count > 0)
            {
                int current = loadList[0].CurrentLoad;
                int maxLoad = loadList[0].MaximumLoad;

                if (current >= maxLoad)
                {
                    List<lfa.pmgmt.data.DTO.Configuration.Zone> zones = new List<data.DTO.Configuration.Zone>();

                    lfa.pmgmt.data.DAO.Configuration.Zone zoneDAO = new data.DAO.Configuration.Zone();
                    zoneDAO.ConnectionString = _connectionString;
                    zones = zoneDAO.List();

                    foreach (lfa.pmgmt.data.DTO.Configuration.Zone zone in zones)
                    {
                        List<lfa.pmgmt.data.DTO.Configuration.Unit> units = new List<data.DTO.Configuration.Unit>();
                        lfa.pmgmt.data.DAO.Configuration.Unit unitDAO = new data.DAO.Configuration.Unit();
                        unitDAO.ConnectionString = _connectionString;

                        units = unitDAO.List(zone.Id);

                        foreach (lfa.pmgmt.data.DTO.Configuration.Unit unit in units)
                        {
                            List<lfa.pmgmt.data.DTO.Configuration.Device> devices = new List<data.DTO.Configuration.Device>();

                            lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                            deviceDAO.ConnectionString = _connectionString;

                            devices = deviceDAO.List(unit.Id);

                            foreach (lfa.pmgmt.data.DTO.Configuration.Device device in devices)
                            {
                                SwitchDeviceOnOff(2, device.Id, device.Id_Unit);

                                UpdateDeviceStatus(device.Id, 2);
                            }
                        }
                    }

                    hasShedAll = true;
                }
            }

            return hasShedAll;
        }
Exemplo n.º 3
0
        private void BindRuleData()
        {
            dataGridView1.DataSource = null;

            lfa.pmgmt.data.DAO.BusinessRule.Rule ruleDAO = new data.DAO.BusinessRule.Rule();
            ruleDAO.ConnectionString = _connectionString;

            List<lfa.pmgmt.data.DTO.BusinessRule.Rule> rules = new List<data.DTO.BusinessRule.Rule>();
            rules = ruleDAO.List(_ruleId);

            dataGridView1.Rows.Clear();
            dataGridView1.DataSource = null;

            dataGridView1.DataSource = rules;

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                string deviceOnOff = "Off";
                string rule = row.Cells[1].Value.ToString();
                string result = row.Cells[2].Value.ToString();

                string[] ruleArray = rule.Split(".".ToCharArray());
                int unitId = int.Parse(ruleArray[0].ToString());
                string comparer = ruleArray[2].ToString();
                string value = ruleArray[3].ToString();

                string[] resultArray = result.Split(".".ToCharArray());
                int deviceId = int.Parse(resultArray[1].ToString());
                int status = int.Parse(resultArray[2].ToString());

                if(status == 1)
                {
                    deviceOnOff = "On";
                }

                lfa.pmgmt.data.DAO.Configuration.Unit unitDAO = new data.DAO.Configuration.Unit();
                unitDAO.ConnectionString = _connectionString;

                lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                deviceDAO.ConnectionString = _connectionString;

                string unitName = unitDAO.GetName(unitId);
                string deviceName = deviceDAO.GetDeviceName(deviceId);

                row.Cells[1].Value = "If " + unitName + " load is " + comparer + " " + value + " Then";
                row.Cells[2].Value = "Switch " + deviceName + " " + deviceOnOff;
            }

            dataGridView1.Columns[1].Width = 180;
            dataGridView1.Columns[2].Width = 150;
        }
Exemplo n.º 4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtZoneName.Text))
            {
                Exception ex = new Exception("Validation Exception : Please provide a new unit name!");
                HandleException(ex);
            }
            else if (string.IsNullOrEmpty(textBox1.Text))
            {
                Exception ex = new Exception("Validation Exception : Please provide a IP Address for the unit!");
                HandleException(ex);
            }
            else
            {
                try
                {
                    lfa.pmgmt.data.DAO.Configuration.Unit DAO = new data.DAO.Configuration.Unit();
                    DAO.ConnectionString = _connectionString;
                    DAO.Insert(zoneId, txtZoneName.Text, DateTime.Now,textBox1.Text);

                    int insertedId = DAO.GetLastInsertedUnit(zoneId);

                    lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                    deviceDAO.ConnectionString = _connectionString;

                    List<lfa.pmgmt.data.DTO.Configuration.Device> devices = deviceDAO.List(_unitId);

                    foreach (lfa.pmgmt.data.DTO.Configuration.Device device in devices)
                    {
                        deviceDAO.Insert(insertedId, device.Name, DateTime.Now, device.Switch);
                    }

                    HandleInformationMesssage("Data successfully saved! Please refresh the form data!");

                    this.Close();
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }
Exemplo n.º 5
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboItem selectedItem = comboBox1.SelectedItem as ComboItem;
            int       selectedZone = selectedItem.Id;

            List <lfa.pmgmt.data.DTO.Configuration.Unit> units = new List <data.DTO.Configuration.Unit>();

            lfa.pmgmt.data.DAO.Configuration.Unit unitDAO = new data.DAO.Configuration.Unit();
            unitDAO.ConnectionString = _connectionString;

            units = unitDAO.List(selectedZone);

            foreach (lfa.pmgmt.data.DTO.Configuration.Unit unit in units)
            {
                ComboItem item = new ComboItem();
                item.Id   = unit.Id;
                item.Name = unit.Name;

                comboBox2.Items.Add(item);
            }
        }
Exemplo n.º 6
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBox3.Items.Clear();
            comboBox3.Text = string.Empty;

            ComboItem selectedCBItem = comboBox1.SelectedItem as ComboItem;
            int selectedItem = selectedCBItem.Id;

            if (selectedItem > -1)
            {
                lfa.pmgmt.data.DAO.Configuration.Unit units = new data.DAO.Configuration.Unit();
                units.ConnectionString = _connectionString;
                List<lfa.pmgmt.data.DTO.Configuration.Unit> unitList = units.List(selectedItem);

                foreach (lfa.pmgmt.data.DTO.Configuration.Unit unitItem in unitList)
                {
                    ComboItem item = new ComboItem();
                    item.Id = unitItem.Id;
                    item.Name = unitItem.Name;

                    comboBox3.Items.Add(item);
                }
            }
        }
Exemplo n.º 7
0
        private void button3_Click(object sender, EventArgs e)
        {
            switch (_currentModule)
            {
                case "LoadShed":
                    HandleInformationMesssage("Load shedding data can not be deleted! Data is only for control purposes!");
                    break;
                case "Configuration":
                    try
                    {
                        int selectedUnitId = int.Parse(grdChildOne.SelectedRows[0].Cells[0].Value.ToString());

                        lfa.pmgmt.data.DAO.Configuration.Unit unitDAO = new data.DAO.Configuration.Unit();
                        unitDAO.ConnectionString = _connectionString;
                        unitDAO.Delete(selectedUnitId);

                        HandleInformationMesssage("Data successfully deleted! Please refresh the data!");
                    }
                    catch (Exception ex)
                    {
                        HandleException(ex);
                    }
                    break;
                case "Schedule":
                    try
                    {
                        int selectedSchedule = int.Parse(grdMain.SelectedRows[0].Cells[0].Value.ToString());
                        int s_selectedUnitId = int.Parse(grdChildOne.SelectedRows[0].Cells[0].Value.ToString());

                        lfa.pmgmt.data.DAO.Schedule.Unit s_unitDAO = new data.DAO.Schedule.Unit();
                        s_unitDAO.ConnectionString = _connectionString;
                        s_unitDAO.Delete(s_selectedUnitId, selectedSchedule);

                        HandleInformationMesssage("Data successfully deleted! Please refresh the data!");
                    }
                    catch (Exception ex)
                    {
                        HandleException(ex);
                    }
                    break;
            }
        }
Exemplo n.º 8
0
 private void BulkUpdateUnits()
 {
     if (grdChildOne.Rows.Count > 0)
     {
         foreach (DataGridViewRow childOneRow in grdChildOne.Rows)
         {
             lfa.pmgmt.data.DAO.Configuration.Unit unitDOA = new data.DAO.Configuration.Unit();
             unitDOA.ConnectionString = _connectionString;
             unitDOA.Update(int.Parse(childOneRow.Cells[0].Value.ToString()), int.Parse(childOneRow.Cells[1].Value.ToString()),
                                      childOneRow.Cells[2].Value.ToString(), childOneRow.Cells[4].Value.ToString());
             unitDOA.EnableDisable(int.Parse(childOneRow.Cells[0].Value.ToString()),
                                   Convert.ToBoolean(childOneRow.Cells[5].Value.ToString()));
         }
     }
 }
Exemplo n.º 9
0
        private void grdMain_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow selectedRow = null;

            if (_loadComplete)
            {
                switch (_currentModule)
                {
                    case "Configuration":
                        selectedRow = grdMain.SelectedRows[0];
                        _selectedItemDataId = int.Parse(selectedRow.Cells[0].Value.ToString());

                        _loadComplete = false;

                        lfa.pmgmt.data.DAO.Configuration.Unit unitDAO = new data.DAO.Configuration.Unit();
                        unitDAO.ConnectionString = _connectionString;
                        List<lfa.pmgmt.data.DTO.Configuration.Unit> unitList = unitDAO.List(_selectedItemDataId);

                        grdChildOne.DataSource = unitList;

                        grdChildOne.Columns[0].Visible = false;
                        grdChildOne.Columns[1].Visible = false;

                        grdChildTwo.Columns.Clear();
                        grdChildTwo.DataSource = null;

                        button5.Visible = true;

                        _loadComplete = true;
                        break;
                    case "Schedule":

                        if (grdMain.Rows.Count > 0)
                        {
                            try
                            {
                                selectedRow = grdMain.SelectedRows[0];
                            }
                            catch
                            {
                                selectedRow = grdMain.Rows[0];
                            }

                            _selectedItemDataId = int.Parse(selectedRow.Cells[0].Value.ToString());

                            _loadComplete = false;

                            lfa.pmgmt.data.DAO.Schedule.Unit scheduleDAO = new lfa.pmgmt.data.DAO.Schedule.Unit();
                            scheduleDAO.ConnectionString = _connectionString;
                            List<lfa.pmgmt.data.DTO.Schedule.Unit> s_unitList = scheduleDAO.List(_selectedItemDataId);

                            grdChildOne.DataSource = s_unitList;

                            grdChildOne.Columns[0].Visible = false;
                            grdChildOne.Columns[1].Visible = false;
                            grdChildOne.Columns[2].Visible = false;

                            grdChildTwo.Columns.Clear();
                            grdChildTwo.DataSource = null;
                        }

                        _loadComplete = true;
                        break;
                    case "LoadShed":
                        selectedRow = grdMain.SelectedRows[0];
                        _selectedItemDataId = int.Parse(selectedRow.Cells[0].Value.ToString());

                        _loadComplete = false;

                        lfa.pmgmt.data.DAO.Configuration.Unit s_unitDAO = new data.DAO.Configuration.Unit();
                        s_unitDAO.ConnectionString = _connectionString;
                        List<lfa.pmgmt.data.DTO.Configuration.Unit> ls_unitList = s_unitDAO.List(_selectedItemDataId);

                        grdChildOne.DataSource = ls_unitList;

                        grdChildOne.Columns[0].Visible = false;
                        grdChildOne.Columns[1].Visible = false;

                        grdChildTwo.Columns.Clear();
                        grdChildTwo.DataSource = null;

                        _loadComplete = true;
                        break;
                    case "Rules":
                         selectedRow = grdMain.SelectedRows[0];
                        _selectedItemDataId = int.Parse(selectedRow.Cells[0].Value.ToString());

                        _loadComplete = false;

                        btnDelete.Visible = true;
                        button2.Visible = true;

                        _loadComplete = true;
                        break;
                }
            }
        }
Exemplo n.º 10
0
        private void grdMain_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow selectedRow = null;

            if (_loadComplete)
            {
                switch (_currentModule)
                {
                case "Configuration":
                    selectedRow         = grdMain.SelectedRows[0];
                    _selectedItemDataId = int.Parse(selectedRow.Cells[0].Value.ToString());

                    _loadComplete = false;

                    lfa.pmgmt.data.DAO.Configuration.Unit unitDAO = new data.DAO.Configuration.Unit();
                    unitDAO.ConnectionString = _connectionString;
                    List <lfa.pmgmt.data.DTO.Configuration.Unit> unitList = unitDAO.List(_selectedItemDataId);

                    grdChildOne.DataSource = unitList;

                    grdChildOne.Columns[0].Visible = false;
                    grdChildOne.Columns[1].Visible = false;

                    grdChildTwo.Columns.Clear();
                    grdChildTwo.DataSource = null;

                    button5.Visible = true;

                    _loadComplete = true;
                    break;

                case "Schedule":

                    if (grdMain.Rows.Count > 0)
                    {
                        try
                        {
                            selectedRow = grdMain.SelectedRows[0];
                        }
                        catch
                        {
                            selectedRow = grdMain.Rows[0];
                        }

                        _selectedItemDataId = int.Parse(selectedRow.Cells[0].Value.ToString());

                        _loadComplete = false;

                        lfa.pmgmt.data.DAO.Schedule.Unit scheduleDAO = new lfa.pmgmt.data.DAO.Schedule.Unit();
                        scheduleDAO.ConnectionString = _connectionString;
                        List <lfa.pmgmt.data.DTO.Schedule.Unit> s_unitList = scheduleDAO.List(_selectedItemDataId);

                        grdChildOne.DataSource = s_unitList;

                        grdChildOne.Columns[0].Visible = false;
                        grdChildOne.Columns[1].Visible = false;
                        grdChildOne.Columns[2].Visible = false;

                        grdChildTwo.Columns.Clear();
                        grdChildTwo.DataSource = null;
                    }

                    _loadComplete = true;
                    break;

                case "LoadShed":
                    selectedRow         = grdMain.SelectedRows[0];
                    _selectedItemDataId = int.Parse(selectedRow.Cells[0].Value.ToString());

                    _loadComplete = false;

                    lfa.pmgmt.data.DAO.Configuration.Unit s_unitDAO = new data.DAO.Configuration.Unit();
                    s_unitDAO.ConnectionString = _connectionString;
                    List <lfa.pmgmt.data.DTO.Configuration.Unit> ls_unitList = s_unitDAO.List(_selectedItemDataId);

                    grdChildOne.DataSource = ls_unitList;

                    grdChildOne.Columns[0].Visible = false;
                    grdChildOne.Columns[1].Visible = false;

                    grdChildTwo.Columns.Clear();
                    grdChildTwo.DataSource = null;

                    _loadComplete = true;
                    break;

                case "Rules":
                    selectedRow         = grdMain.SelectedRows[0];
                    _selectedItemDataId = int.Parse(selectedRow.Cells[0].Value.ToString());

                    _loadComplete = false;

                    btnDelete.Visible = true;
                    button2.Visible   = true;

                    _loadComplete = true;
                    break;
                }
            }
        }
Exemplo n.º 11
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            int status = 2;

            ComboItem zone   = comboBox1.SelectedItem as ComboItem;
            ComboItem unit   = comboBox2.SelectedItem as ComboItem;
            ComboItem device = comboBox3.SelectedItem as ComboItem;

            string comparer    = comboBox4.SelectedItem.ToString();
            string deviceOnOff = comboBox5.SelectedItem.ToString();

            switch (comparer)
            {
            case "Smaller Then Equal":
                comparer = "<";
                break;

            case "Bigger Then Equal":
                comparer = ">=";
                break;

            case "Smaller Then":
                comparer = "<";
                break;

            case "Bigger Then":
                comparer = ">";
                break;

            case "Equal":
                comparer = "==";
                break;
            }

            if (deviceOnOff == "Switch On")
            {
                status = 1;
            }

            string condition = unit.Id + "." + device.Id + "." + comparer + "." + textBox1.Text;

            string result = unit.Id + "." + device.Id + "." + status.ToString();

            lfa.pmgmt.data.DAO.BusinessRule.Rule ruleDAO = new data.DAO.BusinessRule.Rule();
            ruleDAO.ConnectionString = _connectionString;
            ruleDAO.Insert(_ruleId, condition, result);

            List <lfa.pmgmt.data.DTO.BusinessRule.Rule> rules = new List <data.DTO.BusinessRule.Rule>();

            rules = ruleDAO.List(_ruleId);

            dataGridView1.DataSource = null;

            dataGridView1.DataSource = rules;

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                string sdeviceOnOff = "Off";
                string rule         = row.Cells[1].Value.ToString();
                string sresult      = row.Cells[2].Value.ToString();

                string[] ruleArray = rule.Split(".".ToCharArray());
                int      unitId    = int.Parse(ruleArray[0].ToString());
                string   scomparer = ruleArray[2].ToString();
                string   value     = ruleArray[3].ToString();

                string[] resultArray = result.Split(".".ToCharArray());
                int      deviceId    = int.Parse(resultArray[1].ToString());
                int      sstatus     = int.Parse(resultArray[2].ToString());

                if (sstatus == 1)
                {
                    sdeviceOnOff = "On";
                }

                lfa.pmgmt.data.DAO.Configuration.Unit unitDAO = new data.DAO.Configuration.Unit();
                unitDAO.ConnectionString = _connectionString;

                lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                deviceDAO.ConnectionString = _connectionString;

                string unitName   = unitDAO.GetName(unitId);
                string deviceName = deviceDAO.GetDeviceName(deviceId);

                row.Cells[1].Value = "If " + unitName + " load is " + scomparer + " " + value + "Then";
                row.Cells[2].Value = "Switch " + deviceName + " " + sdeviceOnOff;
            }

            dataGridView1.Columns[1].Width = 180;
            dataGridView1.Columns[2].Width = 150;
        }
Exemplo n.º 12
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                ComboItem selectedItem = comboBox1.SelectedItem as ComboItem;
                int       zoneId       = selectedItem.Id;

                bool status = false;

                lfa.pmgmt.data.DAO.Configuration.Unit unitDAO = new data.DAO.Configuration.Unit();
                unitDAO.ConnectionString = _connectionString;

                List <lfa.pmgmt.data.DTO.Configuration.Unit> units = unitDAO.List(zoneId);

                foreach (lfa.pmgmt.data.DTO.Configuration.Unit unit in units)
                {
                    lfa.pmgmt.data.DAO.Schedule.Unit sunitDAO = new data.DAO.Schedule.Unit();
                    sunitDAO.ConnectionString = _connectionString;
                    sunitDAO.Insert(unit.Id, _scheduleId);

                    lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                    deviceDAO.ConnectionString = _connectionString;

                    List <lfa.pmgmt.data.DTO.Configuration.Device> devices = deviceDAO.List(unit.Id);

                    foreach (lfa.pmgmt.data.DTO.Configuration.Device device in devices)
                    {
                        lfa.pmgmt.data.DAO.Schedule.Device sdeviceDAO = new data.DAO.Schedule.Device();
                        sdeviceDAO.ConnectionString = _connectionString;
                        sdeviceDAO.Insert(device.Id, unit.Id, status, _scheduleId);
                    }

                    lfa.pmgmt.data.DAO.Schedule.Schedule dao = new data.DAO.Schedule.Schedule();
                    dao.ConnectionString = _connectionString;
                    dao.LinkZone(_scheduleId, zoneId);
                }

                bool switch1On = checkBox1.Checked;
                bool switch2On = checkBox2.Checked;
                bool switch3On = checkBox3.Checked;
                bool switch4On = checkBox4.Checked;
                bool switch5On = checkBox5.Checked;
                bool switch6On = checkBox6.Checked;
                bool switch7On = checkBox7.Checked;
                bool switch8On = checkBox8.Checked;

                lfa.pmgmt.data.DAO.Schedule.Unit unitDAO2 = new data.DAO.Schedule.Unit();
                unitDAO2.ConnectionString = _connectionString;
                List <lfa.pmgmt.data.DTO.Schedule.Unit> unitList = unitDAO2.ListWithZone(_scheduleId);

                foreach (lfa.pmgmt.data.DTO.Schedule.Unit unit in unitList)
                {
                    if (unit.Id_Zone == zoneId)
                    {
                        lfa.pmgmt.data.DAO.Schedule.Device deviceDAO = new data.DAO.Schedule.Device();
                        deviceDAO.ConnectionString = _connectionString;

                        List <lfa.pmgmt.data.DTO.Schedule.Device> deviceList = deviceDAO.ListWithDeviceId(unit.Id, _scheduleId);

                        foreach (lfa.pmgmt.data.DTO.Schedule.Device device in deviceList)
                        {
                            lfa.pmgmt.data.DAO.Configuration.Device configDeviceDAO = new data.DAO.Configuration.Device();
                            configDeviceDAO.ConnectionString = _connectionString;
                            lfa.pmgmt.data.DTO.Configuration.Device configDevice = configDeviceDAO.Get(device.DeviceId);

                            switch (configDevice.Switch)
                            {
                            case "Switch 1":
                                deviceDAO.Update(device.Id, 0, 0, switch1On);
                                break;

                            case "Switch 2":
                                deviceDAO.Update(device.Id, 0, 0, switch2On);
                                break;

                            case "Switch 3":
                                deviceDAO.Update(device.Id, 0, 0, switch3On);
                                break;

                            case "Switch 4":
                                deviceDAO.Update(device.Id, 0, 0, switch4On);
                                break;

                            case "Switch 5":
                                deviceDAO.Update(device.Id, 0, 0, switch5On);
                                break;

                            case "Switch 6":
                                deviceDAO.Update(device.Id, 0, 0, switch6On);
                                break;

                            case "Switch 7":
                                deviceDAO.Update(device.Id, 0, 0, switch7On);
                                break;

                            case "Switch 8":
                                deviceDAO.Update(device.Id, 0, 0, switch8On);
                                break;
                            }
                        }
                    }
                }

                HandleInformationMesssage("Data successfully saved! Please refresh the form data!");

                this.Close();
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
Exemplo n.º 13
0
        public bool EntireLoadShed(int zoneId, int status)
        {
            bool hasShedAll = false;

            List<lfa.pmgmt.data.DTO.BusinessRule.Load> loadList = new List<data.DTO.BusinessRule.Load>();

            lfa.pmgmt.data.DAO.BusinessRule.Load loadDAO = new data.DAO.BusinessRule.Load();
            loadDAO.ConnectionString = _connectionString;

            loadList = loadDAO.List();

            if (loadList.Count > 0)
            {
                 List<lfa.pmgmt.data.DTO.Configuration.Zone> zones = new List<data.DTO.Configuration.Zone>();

                 lfa.pmgmt.data.DAO.Configuration.Zone zoneDAO = new data.DAO.Configuration.Zone();
                 zoneDAO.ConnectionString = _connectionString;
                 lfa.pmgmt.data.DTO.Configuration.Zone zone = zoneDAO.Get(zoneId);

                 List<lfa.pmgmt.data.DTO.Configuration.Unit> units = new List<data.DTO.Configuration.Unit>();
                 lfa.pmgmt.data.DAO.Configuration.Unit unitDAO = new data.DAO.Configuration.Unit();
                 unitDAO.ConnectionString = _connectionString;

                 units = unitDAO.List(zone.Id);

                 foreach (lfa.pmgmt.data.DTO.Configuration.Unit unit in units)
                 {
                     List<lfa.pmgmt.data.DTO.Configuration.Device> devices = new List<data.DTO.Configuration.Device>();

                     lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                     deviceDAO.ConnectionString = _connectionString;

                     devices = deviceDAO.List(unit.Id);

                     foreach (lfa.pmgmt.data.DTO.Configuration.Device device in devices)
                     {
                       SwitchDeviceOnOff(status, device.Id, device.Id_Unit);

                       UpdateDeviceStatus(device.Id, status);
                     }
                  }

                 hasShedAll = true;
            }

            return hasShedAll;
        }
Exemplo n.º 14
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboItem selectedItem = comboBox1.SelectedItem as ComboItem;
            int selectedZone = selectedItem.Id;

            List<lfa.pmgmt.data.DTO.Configuration.Unit> units = new List<data.DTO.Configuration.Unit>();
            lfa.pmgmt.data.DAO.Configuration.Unit unitDAO = new data.DAO.Configuration.Unit();
            unitDAO.ConnectionString = _connectionString;

            units = unitDAO.List(selectedZone);

            foreach (lfa.pmgmt.data.DTO.Configuration.Unit unit in units)
            {
                ComboItem item = new ComboItem();
                item.Id = unit.Id;
                item.Name = unit.Name;

                comboBox2.Items.Add(item);
            }
        }
Exemplo n.º 15
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            int status = 2;

            ComboItem zone = comboBox1.SelectedItem as ComboItem;
            ComboItem unit = comboBox2.SelectedItem as ComboItem;
            ComboItem device = comboBox3.SelectedItem as ComboItem;

            string comparer = comboBox4.SelectedItem.ToString();
            string deviceOnOff = comboBox5.SelectedItem.ToString();

            switch (comparer)
            {
                case "Smaller Then Equal":
                    comparer = "<";
                    break;
                case "Bigger Then Equal":
                    comparer = ">=";
                    break;
                case "Smaller Then":
                    comparer = "<";
                    break;
                case "Bigger Then":
                    comparer = ">";
                    break;
                case "Equal":
                    comparer = "==";
                    break;
            }

            if(deviceOnOff == "Switch On")
            {
                status = 1;
            }

            string condition = unit.Id + "." + device.Id + "." + comparer + "." + textBox1.Text;

            string result = unit.Id + "." + device.Id + "." + status.ToString();

            lfa.pmgmt.data.DAO.BusinessRule.Rule ruleDAO = new data.DAO.BusinessRule.Rule();
            ruleDAO.ConnectionString = _connectionString;
            ruleDAO.Insert(_ruleId,condition,result);

            List<lfa.pmgmt.data.DTO.BusinessRule.Rule> rules = new List<data.DTO.BusinessRule.Rule>();
            rules = ruleDAO.List(_ruleId);

            dataGridView1.DataSource = null;

            dataGridView1.DataSource = rules;

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                string sdeviceOnOff = "Off";
                string rule = row.Cells[1].Value.ToString();
                string sresult = row.Cells[2].Value.ToString();

                string[] ruleArray = rule.Split(".".ToCharArray());
                int unitId = int.Parse(ruleArray[0].ToString());
                string scomparer = ruleArray[2].ToString();
                string value = ruleArray[3].ToString();

                string[] resultArray = result.Split(".".ToCharArray());
                int deviceId = int.Parse(resultArray[1].ToString());
                int sstatus = int.Parse(resultArray[2].ToString());

                if (sstatus == 1)
                {
                    sdeviceOnOff = "On";
                }

                lfa.pmgmt.data.DAO.Configuration.Unit unitDAO = new data.DAO.Configuration.Unit();
                unitDAO.ConnectionString = _connectionString;

                lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                deviceDAO.ConnectionString = _connectionString;

                string unitName = unitDAO.GetName(unitId);
                string deviceName = deviceDAO.GetDeviceName(deviceId);

                row.Cells[1].Value = "If " + unitName + " load is " + scomparer + " " + value + "Then";
                row.Cells[2].Value = "Switch " + deviceName + " " + sdeviceOnOff;
            }

            dataGridView1.Columns[1].Width = 180;
            dataGridView1.Columns[2].Width = 150;
        }
Exemplo n.º 16
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                ComboItem selectedItem = comboBox1.SelectedItem as ComboItem;
                int zoneId = selectedItem.Id;

                bool status = false;

                lfa.pmgmt.data.DAO.Configuration.Unit unitDAO = new data.DAO.Configuration.Unit();
                unitDAO.ConnectionString = _connectionString;

                List<lfa.pmgmt.data.DTO.Configuration.Unit> units = unitDAO.List(zoneId);

                foreach (lfa.pmgmt.data.DTO.Configuration.Unit unit in units)
                {
                    lfa.pmgmt.data.DAO.Schedule.Unit sunitDAO = new data.DAO.Schedule.Unit();
                    sunitDAO.ConnectionString = _connectionString;
                    sunitDAO.Insert(unit.Id, _scheduleId);

                    lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                    deviceDAO.ConnectionString = _connectionString;

                    List<lfa.pmgmt.data.DTO.Configuration.Device> devices = deviceDAO.List(unit.Id);

                    foreach (lfa.pmgmt.data.DTO.Configuration.Device device in devices)
                    {
                        lfa.pmgmt.data.DAO.Schedule.Device sdeviceDAO = new data.DAO.Schedule.Device();
                        sdeviceDAO.ConnectionString = _connectionString;
                        sdeviceDAO.Insert(device.Id, unit.Id, status, _scheduleId);
                    }

                    lfa.pmgmt.data.DAO.Schedule.Schedule dao = new data.DAO.Schedule.Schedule();
                    dao.ConnectionString = _connectionString;
                    dao.LinkZone(_scheduleId, zoneId);
                }

                bool switch1On = checkBox1.Checked;
                bool switch2On = checkBox2.Checked;
                bool switch3On = checkBox3.Checked;
                bool switch4On = checkBox4.Checked;
                bool switch5On = checkBox5.Checked;
                bool switch6On = checkBox6.Checked;
                bool switch7On = checkBox7.Checked;
                bool switch8On = checkBox8.Checked;

                lfa.pmgmt.data.DAO.Schedule.Unit unitDAO2 = new data.DAO.Schedule.Unit();
                unitDAO2.ConnectionString = _connectionString;
                List<lfa.pmgmt.data.DTO.Schedule.Unit> unitList = unitDAO2.ListWithZone(_scheduleId);

                foreach (lfa.pmgmt.data.DTO.Schedule.Unit unit in unitList)
                {
                    if (unit.Id_Zone == zoneId)
                    {
                        lfa.pmgmt.data.DAO.Schedule.Device deviceDAO = new data.DAO.Schedule.Device();
                        deviceDAO.ConnectionString = _connectionString;

                        List<lfa.pmgmt.data.DTO.Schedule.Device> deviceList = deviceDAO.ListWithDeviceId(unit.Id, _scheduleId);

                        foreach (lfa.pmgmt.data.DTO.Schedule.Device device in deviceList)
                        {
                            lfa.pmgmt.data.DAO.Configuration.Device configDeviceDAO = new data.DAO.Configuration.Device();
                            configDeviceDAO.ConnectionString = _connectionString;
                            lfa.pmgmt.data.DTO.Configuration.Device configDevice = configDeviceDAO.Get(device.DeviceId);

                            switch (configDevice.Switch)
                            {
                                case "Switch 1":
                                    deviceDAO.Update(device.Id, 0, 0, switch1On);
                                    break;
                                case "Switch 2":
                                    deviceDAO.Update(device.Id, 0, 0, switch2On);
                                    break;
                                case "Switch 3":
                                    deviceDAO.Update(device.Id, 0, 0, switch3On);
                                    break;
                                case "Switch 4":
                                    deviceDAO.Update(device.Id, 0, 0, switch4On);
                                    break;
                                case "Switch 5":
                                    deviceDAO.Update(device.Id, 0, 0, switch5On);
                                    break;
                                case "Switch 6":
                                    deviceDAO.Update(device.Id, 0, 0, switch6On);
                                    break;
                                case "Switch 7":
                                    deviceDAO.Update(device.Id, 0, 0, switch7On);
                                    break;
                                case "Switch 8":
                                    deviceDAO.Update(device.Id, 0, 0, switch8On);
                                    break;
                            }
                        }
                    }
                }

                HandleInformationMesssage("Data successfully saved! Please refresh the form data!");

                this.Close();
            }
            catch (Exception ex)
            {
               HandleException(ex);
            }
        }