Ejemplo 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 device name!");
                HandleException(ex);
            }
            else
            {
                try
                {
                    lfa.pmgmt.data.DAO.Configuration.Device DAO = new data.DAO.Configuration.Device();
                    DAO.ConnectionString = _connectionString;
                    DAO.Insert(unitId, txtZoneName.Text, DateTime.Now,comboBox1.SelectedItem.ToString());

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

                    this.Close();
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }
Ejemplo n.º 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtZoneName.Text))
            {
                Exception ex = new Exception("Validation Exception : Please provide a new device name!");
                HandleException(ex);
            }
            else
            {
                try
                {
                    lfa.pmgmt.data.DAO.Configuration.Device DAO = new data.DAO.Configuration.Device();
                    DAO.ConnectionString = _connectionString;
                    DAO.Insert(unitId, txtZoneName.Text, DateTime.Now, comboBox1.SelectedItem.ToString());

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

                    this.Close();
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }
Ejemplo n.º 3
0
        private void LoadShedUnit(List <lfa.pmgmt.data.DTO.Schedule.Device> unitDevices, int defaultPort, lfa.pmgmt.data.DTO.Schedule.Unit unit)
        {
            int status = 0;

            foreach (lfa.pmgmt.data.DTO.Schedule.Device unitDevice in unitDevices)
            {
                lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                deviceDAO.ConnectionString = _connectionString;


                string deviceName     = unitDevice.Name;
                int    deviceConfigId = deviceDAO.GetDeviceConfigId(unit.Id_ScheduleUnit, unitDevice.Id);

                string deviceAddress = deviceDAO.GetDeviceAddress(deviceConfigId);
                string deviceSwitch  = deviceDAO.GetDeviceSwitch(deviceConfigId);

                bool switchOn = unitDevice.DeviceOn;

                if (switchOn)
                {
                    status = 1;
                }
                else
                {
                    status = 2;
                }

                SendSwitchState(deviceAddress, defaultPort, deviceSwitch, status);
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
        private void SwitchDeviceOnOff(int status, int deviceId, int unitId)
        {
            lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
            deviceDAO.ConnectionString = _connectionString;

            string ipAddress    = deviceDAO.GetDeviceAddress(deviceId);
            string deviceSwitch = deviceDAO.GetDeviceSwitch(deviceId);

            SendSwitchState(ipAddress, _defaultPort, deviceSwitch, status);
        }
Ejemplo n.º 7
0
        private void btnLoadShed_Click(object sender, EventArgs e)
        {
            string address  = string.Empty;
            string unitName = grdChildOne.SelectedRows[0].Cells[2].Value.ToString();

            BravaCodes.SwitchState[] mySwitchStates = new BravaCodes.SwitchState[8];

            for (int x = 0; x <= 7; x++)
            {
                mySwitchStates[x] = BravaCodes.SwitchState.SwitchOff;
            }

            foreach (DataGridViewRow row in grdChildTwo.Rows)
            {
                int    status        = 0;
                int    id            = int.Parse(row.Cells[0].Value.ToString());
                string selectedvalue = row.Cells[5].Value.ToString();

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

                address = deviceDAO.GetDeviceAddress(id);
                string deviceSwitch = deviceDAO.GetDeviceSwitch(id);

                if (selectedvalue == "On")
                {
                    status = 1;
                }
                else
                {
                    status = 2;
                }

                SetSwitchState(deviceSwitch, status, mySwitchStates);

                UpdateDeviceLoadShedStatus(status, id);
            }

            SendSwitchState(address, unitName, int.Parse(ConfigurationManager.AppSettings["DefaultPort"].ToString()), mySwitchStates);

            DisableAllSchedules();

            string loadShedMsg = "Devices successfully load shedded! ";

            loadShedMsg += "Please note that manual power management disables all schedules. To enable a schedule, please ";
            loadShedMsg += "go to the 'Schedule' management screen and re-enable the schedule.";

            HandleInformationMesssage(loadShedMsg);

            grdChildTwo.DataSource = null;
            grdChildTwo.Columns.Clear();
        }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
0
 private void BulkUpdateDevices()
 {
     if (grdChildTwo.Rows.Count > 0)
     {
         foreach (DataGridViewRow childTwoRow in grdChildTwo.Rows)
         {
             lfa.pmgmt.data.DAO.Configuration.Device deviceDOA = new data.DAO.Configuration.Device();
             deviceDOA.ConnectionString = _connectionString;
             deviceDOA.Update(int.Parse(childTwoRow.Cells[0].Value.ToString()), int.Parse(childTwoRow.Cells[1].Value.ToString()),
                              childTwoRow.Cells[2].Value.ToString());
             deviceDOA.EnableDisable(int.Parse(childTwoRow.Cells[0].Value.ToString()),
                                     Convert.ToBoolean(childTwoRow.Cells[4].Value.ToString()));
         }
     }
 }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        private void button4_Click(object sender, EventArgs e)
        {
            switch (_currentModule)
            {
            case "LoadShed":
                HandleInformationMesssage("Load shedding data can not deleted! Data is only for control purposes!");
                break;

            case "Configuration":
                try
                {
                    int selectedDeviceId = int.Parse(grdChildTwo.SelectedRows[0].Cells[0].Value.ToString());

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

                    HandleInformationMesssage("Data successfully deleted! Please refresh the data!");
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
                break;

            case "Schedule":
                try
                {
                    int s_selectedDeviceId = int.Parse(grdChildTwo.SelectedRows[0].Cells[0].Value.ToString());

                    lfa.pmgmt.data.DAO.Schedule.Device scheduleDAO = new data.DAO.Schedule.Device();
                    scheduleDAO.ConnectionString = _connectionString;
                    scheduleDAO.Delete(s_selectedDeviceId);

                    HandleInformationMesssage("Data successfully deleted! Please refresh the data!");
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
                break;
            }
        }
Ejemplo n.º 13
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);
                }
            }
        }
Ejemplo n.º 14
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);
                }
            }
        }
Ejemplo n.º 15
0
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboItem selectedItem = comboBox1.SelectedItem as ComboItem;
            int       selectedUnit = selectedItem.Id;

            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(selectedUnit);

            foreach (lfa.pmgmt.data.DTO.Configuration.Device device in devices)
            {
                ComboItem item = new ComboItem();
                item.Id   = device.Id;
                item.Name = device.Name;

                comboBox3.Items.Add(item);
            }
        }
        private void Frm_AddNew_Unit_Load_1(object sender, EventArgs e)
        {
            _connectionString = GetConnectionString();

            lfa.pmgmt.data.DAO.Schedule.Device scheduleDAO = new data.DAO.Schedule.Device();
            scheduleDAO.ConnectionString = _connectionString;
            int s_unitId = scheduleDAO.GetUnitId(unitId);

            lfa.pmgmt.data.DAO.Configuration.Device DAO = new data.DAO.Configuration.Device();
            DAO.ConnectionString = _connectionString;
            List<lfa.pmgmt.data.DTO.Configuration.Device> scheduleList = DAO.List(unitId);

            foreach (lfa.pmgmt.data.DTO.Configuration.Device scheduleItem in scheduleList)
            {
                ComboItem item = new ComboItem();
                item.Id = scheduleItem.Id;
                item.Name = scheduleItem.Name;

                comboBox1.Items.Add(item);
            }

            comboBox2.Items.Add("On");
            comboBox2.Items.Add("Off");
        }
Ejemplo n.º 17
0
        private void Frm_AddNew_Unit_Load_1(object sender, EventArgs e)
        {
            _connectionString = GetConnectionString();

            lfa.pmgmt.data.DAO.Schedule.Device scheduleDAO = new data.DAO.Schedule.Device();
            scheduleDAO.ConnectionString = _connectionString;
            int s_unitId = scheduleDAO.GetUnitId(unitId);

            lfa.pmgmt.data.DAO.Configuration.Device DAO = new data.DAO.Configuration.Device();
            DAO.ConnectionString = _connectionString;
            List <lfa.pmgmt.data.DTO.Configuration.Device> scheduleList = DAO.List(unitId);

            foreach (lfa.pmgmt.data.DTO.Configuration.Device scheduleItem in scheduleList)
            {
                ComboItem item = new ComboItem();
                item.Id   = scheduleItem.Id;
                item.Name = scheduleItem.Name;

                comboBox1.Items.Add(item);
            }

            comboBox2.Items.Add("On");
            comboBox2.Items.Add("Off");
        }
Ejemplo n.º 18
0
 private static void UpdateDeviceLoadShedStatus(int status, int id)
 {
     lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
     deviceDAO.ConnectionString = _connectionString;
     deviceDAO.UpdateLoadShedDeviceStatus(id, status);
 }
Ejemplo n.º 19
0
 private static void UpdateDeviceLoadShedStatus(int status, int id)
 {
     lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
     deviceDAO.ConnectionString = _connectionString;
     deviceDAO.UpdateLoadShedDeviceStatus(id, status);
 }
Ejemplo n.º 20
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;
        }
Ejemplo n.º 21
0
        private void SwitchDeviceOnOff(int status, int deviceId, int unitId)
        {
            lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
            deviceDAO.ConnectionString = _connectionString;

            string ipAddress = deviceDAO.GetDeviceAddress(deviceId);
            string deviceSwitch = deviceDAO.GetDeviceSwitch(deviceId);

            SendSwitchState(ipAddress, _defaultPort, deviceSwitch, status);
        }
Ejemplo n.º 22
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;
        }
Ejemplo n.º 23
0
        private void button4_Click(object sender, EventArgs e)
        {
            switch (_currentModule)
            {
                case "LoadShed":
                    HandleInformationMesssage("Load shedding data can not deleted! Data is only for control purposes!");
                    break;
                case "Configuration":
                    try
                    {
                        int selectedDeviceId = int.Parse(grdChildTwo.SelectedRows[0].Cells[0].Value.ToString());

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

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

                        lfa.pmgmt.data.DAO.Schedule.Device scheduleDAO = new data.DAO.Schedule.Device();
                        scheduleDAO.ConnectionString = _connectionString;
                        scheduleDAO.Delete(s_selectedDeviceId);

                        HandleInformationMesssage("Data successfully deleted! Please refresh the data!");
                    }
                    catch (Exception ex)
                    {
                        HandleException(ex);
                    }
                    break;
            }
        }
Ejemplo n.º 24
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;
        }
Ejemplo n.º 25
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);
            }
        }
Ejemplo n.º 26
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);
            }
        }
Ejemplo n.º 27
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboItem selectedItem = comboBox1.SelectedItem as ComboItem;
            int       zoneId       = selectedItem.Id;

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

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

            foreach (lfa.pmgmt.data.DTO.Schedule.Unit unit in unitList)
            {
                if (unit.Id_Zone == zoneId)
                {
                    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":
                            checkBox1.Checked = device.DeviceOn;
                            break;

                        case "Switch 2":
                            checkBox2.Checked = device.DeviceOn;
                            break;

                        case "Switch 3":
                            checkBox3.Checked = device.DeviceOn;
                            break;

                        case "Switch 4":
                            checkBox4.Checked = device.DeviceOn;
                            break;

                        case "Switch 5":
                            checkBox5.Checked = device.DeviceOn;
                            break;

                        case "Switch 6":
                            checkBox6.Checked = device.DeviceOn;
                            break;

                        case "Switch 7":
                            checkBox7.Checked = device.DeviceOn;
                            break;

                        case "Switch 8":
                            checkBox8.Checked = device.DeviceOn;
                            break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 28
0
        private void AsyncLoadShedUnit(object parameters)
        {
            try
            {
                ArrayList parms = parameters as ArrayList;

                List <lfa.pmgmt.data.DTO.Schedule.Device> unitDevices = parms[0] as List <lfa.pmgmt.data.DTO.Schedule.Device>;

                int defaultPort = (int)parms[1];

                lfa.pmgmt.data.DTO.Schedule.Unit unit = parms[2] as lfa.pmgmt.data.DTO.Schedule.Unit;

                int status = (int)parms[3];

                if (unit.IsActive)
                {
                    string deviceAddress = string.Empty;

                    SwitchbankUpdate mySwitchbankUpdate = null;

                    BravaCodes.SwitchState[] mySwitchStates = new BravaCodes.SwitchState[8];

                    for (int x = 0; x <= 7; x++)
                    {
                        mySwitchStates[x] = BravaCodes.SwitchState.NoChange;
                    }

                    foreach (lfa.pmgmt.data.DTO.Schedule.Device unitDevice in unitDevices)
                    {
                        lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                        deviceDAO.ConnectionString = _connectionString;

                        string deviceName     = unitDevice.Name;
                        int    deviceConfigId = deviceDAO.GetDeviceConfigId(unit.Id_ScheduleUnit, unitDevice.Id);

                        deviceAddress = deviceDAO.GetDeviceAddress(deviceConfigId);
                        string deviceSwitch = deviceDAO.GetDeviceSwitch(deviceConfigId);

                        //if (status == 0)
                        //{
                        bool switchOn = unitDevice.DeviceOn;

                        if (switchOn)
                        {
                            status = 1;
                        }
                        else
                        {
                            status = 2;
                        }
                        //}

                        SetSwitchState(deviceSwitch, status, mySwitchStates, unitDevice.Id.ToString());
                    }

                    mySwitchbankUpdate = new SwitchbankUpdate(mySwitchStates[0], mySwitchStates[1], mySwitchStates[2],
                                                              mySwitchStates[3], mySwitchStates[4], mySwitchStates[5],
                                                              mySwitchStates[6], mySwitchStates[7]);

                    try
                    {
                        //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send 1", System.Diagnostics.EventLogEntryType.Warning);

                        SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    catch (System.Net.Sockets.SocketException)
                    {
                        System.Threading.Thread.Sleep(200);

                        try
                        {
                            mySwitchbankUpdate = new SwitchbankUpdate(mySwitchStates[0], mySwitchStates[1], mySwitchStates[2],
                                                                      mySwitchStates[3], mySwitchStates[4], mySwitchStates[5],
                                                                      mySwitchStates[6], mySwitchStates[7]);


                            //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send Err 1", System.Diagnostics.EventLogEntryType.Warning);

                            SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                            lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                            currentStatusDAO.ConnectionString = _connectionString;
                            currentStatusDAO.Insert(unit.Name, "OK");
                        }
                        catch (System.Net.Sockets.SocketException soex)
                        {
                            lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log();
                            logDAO.ConnectionString = _connectionString;
                            logDAO.Insert(1, "Unit: " + unit.Name, "TCP/IP Communications Error due to: " + soex.ToString(), DateTime.Now);

                            lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                            currentStatusDAO.ConnectionString = _connectionString;
                            currentStatusDAO.Insert(unit.Name, "ERR");
                        }
                    }
                }
                else
                {
                    try
                    {
                        //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send 2", System.Diagnostics.EventLogEntryType.Warning);

                        SendBatchSwitchState(unit.Address, defaultPort, string.Empty, 2);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    catch (System.Net.Sockets.SocketException)
                    {
                        System.Threading.Thread.Sleep(200);

                        try
                        {
                            //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send Err 2", System.Diagnostics.EventLogEntryType.Warning);

                            SendBatchSwitchState(unit.Address, defaultPort, string.Empty, 2);

                            lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                            currentStatusDAO.ConnectionString = _connectionString;
                            currentStatusDAO.Insert(unit.Name, "OK");
                        }
                        catch (System.Net.Sockets.SocketException ex)
                        {
                            lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log();
                            logDAO.ConnectionString = _connectionString;
                            logDAO.Insert(1, "Unit: " + unit.Name, "TCP/IP Communications Error due to: " + ex.ToString(), DateTime.Now);

                            lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                            currentStatusDAO.ConnectionString = _connectionString;
                            currentStatusDAO.Insert(unit.Name, "ERR");
                        }
                    }
                }
            }
            catch (Exception)
            {
                //File.AppendAllText(@"c:\smartpower\logerr.txt", er.ToString());
            }
        }
Ejemplo n.º 29
0
        private void btnLoadShed_Click(object sender, EventArgs e)
        {
            string address = string.Empty;
            string unitName = grdChildOne.SelectedRows[0].Cells[2].Value.ToString();

            BravaCodes.SwitchState[] mySwitchStates = new BravaCodes.SwitchState[8];

            for (int x = 0; x <= 7; x++) mySwitchStates[x] = BravaCodes.SwitchState.SwitchOff;

            foreach (DataGridViewRow row in grdChildTwo.Rows)
            {
                int status = 0;
                int id = int.Parse(row.Cells[0].Value.ToString());
                string selectedvalue = row.Cells[5].Value.ToString();

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

                address = deviceDAO.GetDeviceAddress(id);
                string deviceSwitch = deviceDAO.GetDeviceSwitch(id);

                if (selectedvalue == "On")
                    status = 1;
                else
                    status = 2;

                SetSwitchState(deviceSwitch, status, mySwitchStates);

                UpdateDeviceLoadShedStatus(status, id);
            }

            SendSwitchState(address, unitName, int.Parse(ConfigurationManager.AppSettings["DefaultPort"].ToString()), mySwitchStates);

            DisableAllSchedules();

            string loadShedMsg = "Devices successfully load shedded! ";
            loadShedMsg += "Please note that manual power management disables all schedules. To enable a schedule, please ";
            loadShedMsg += "go to the 'Schedule' management screen and re-enable the schedule.";

            HandleInformationMesssage(loadShedMsg);

            grdChildTwo.DataSource = null;
            grdChildTwo.Columns.Clear();
        }
Ejemplo n.º 30
0
 private void BulkUpdateDevices()
 {
     if (grdChildTwo.Rows.Count > 0)
     {
         foreach (DataGridViewRow childTwoRow in grdChildTwo.Rows)
         {
             lfa.pmgmt.data.DAO.Configuration.Device deviceDOA = new data.DAO.Configuration.Device();
             deviceDOA.ConnectionString = _connectionString;
             deviceDOA.Update(int.Parse(childTwoRow.Cells[0].Value.ToString()), int.Parse(childTwoRow.Cells[1].Value.ToString()),
                              childTwoRow.Cells[2].Value.ToString());
             deviceDOA.EnableDisable(int.Parse(childTwoRow.Cells[0].Value.ToString()),
                                     Convert.ToBoolean(childTwoRow.Cells[4].Value.ToString()));
         }
     }
 }
Ejemplo n.º 31
0
        private void AsyncLoadShedUnit(object parameters)
        {
            try
            {
                ArrayList parms = parameters as ArrayList;

                List<lfa.pmgmt.data.DTO.Schedule.Device> unitDevices = parms[0] as List<lfa.pmgmt.data.DTO.Schedule.Device>;

                int defaultPort = (int)parms[1];

                lfa.pmgmt.data.DTO.Schedule.Unit unit = parms[2] as lfa.pmgmt.data.DTO.Schedule.Unit;

                int status = (int)parms[3];

                if (unit.IsActive)
                {
                    string deviceAddress = string.Empty;

                    SwitchbankUpdate mySwitchbankUpdate = null;

                    BravaCodes.SwitchState[] mySwitchStates = new BravaCodes.SwitchState[8];

                    for (int x = 0; x <= 7; x++) mySwitchStates[x] = BravaCodes.SwitchState.NoChange;

                    foreach (lfa.pmgmt.data.DTO.Schedule.Device unitDevice in unitDevices)
                    {
                        lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                        deviceDAO.ConnectionString = _connectionString;

                        string deviceName = unitDevice.Name;
                        int deviceConfigId = deviceDAO.GetDeviceConfigId(unit.Id_ScheduleUnit, unitDevice.Id);

                        deviceAddress = deviceDAO.GetDeviceAddress(deviceConfigId);
                        string deviceSwitch = deviceDAO.GetDeviceSwitch(deviceConfigId);

                        //if (status == 0)
                        //{
                        bool switchOn = unitDevice.DeviceOn;

                        if (switchOn)
                        {
                            status = 1;
                        }
                        else
                        {
                            status = 2;
                        }
                        //}

                        SetSwitchState(deviceSwitch, status, mySwitchStates, unitDevice.Id.ToString());
                    }

                    mySwitchbankUpdate = new SwitchbankUpdate(mySwitchStates[0], mySwitchStates[1], mySwitchStates[2],
                                                              mySwitchStates[3], mySwitchStates[4], mySwitchStates[5],
                                                              mySwitchStates[6], mySwitchStates[7]);

                    try
                    {
                        //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send 1", System.Diagnostics.EventLogEntryType.Warning);

                        SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    catch (System.Net.Sockets.SocketException)
                    {
                        System.Threading.Thread.Sleep(200);

                        try
                        {
                            mySwitchbankUpdate = new SwitchbankUpdate(mySwitchStates[0], mySwitchStates[1], mySwitchStates[2],
                                                             mySwitchStates[3], mySwitchStates[4], mySwitchStates[5],
                                                             mySwitchStates[6], mySwitchStates[7]);

                            //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send Err 1", System.Diagnostics.EventLogEntryType.Warning);

                            SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                            lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                            currentStatusDAO.ConnectionString = _connectionString;
                            currentStatusDAO.Insert(unit.Name, "OK");
                        }
                        catch (System.Net.Sockets.SocketException soex)
                        {
                            lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log();
                            logDAO.ConnectionString = _connectionString;
                            logDAO.Insert(1, "Unit: " + unit.Name, "TCP/IP Communications Error due to: " + soex.ToString(), DateTime.Now);

                            lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                            currentStatusDAO.ConnectionString = _connectionString;
                            currentStatusDAO.Insert(unit.Name, "ERR");
                        }
                    }
                }
                else
                {
                    try
                    {
                        //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send 2", System.Diagnostics.EventLogEntryType.Warning);

                        SendBatchSwitchState(unit.Address, defaultPort, string.Empty, 2);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    catch (System.Net.Sockets.SocketException)
                    {
                        System.Threading.Thread.Sleep(200);

                        try
                        {
                            //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send Err 2", System.Diagnostics.EventLogEntryType.Warning);

                            SendBatchSwitchState(unit.Address, defaultPort, string.Empty, 2);

                            lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                            currentStatusDAO.ConnectionString = _connectionString;
                            currentStatusDAO.Insert(unit.Name, "OK");
                        }
                        catch (System.Net.Sockets.SocketException ex)
                        {
                            lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log();
                            logDAO.ConnectionString = _connectionString;
                            logDAO.Insert(1, "Unit: " + unit.Name, "TCP/IP Communications Error due to: " + ex.ToString(), DateTime.Now);

                            lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                            currentStatusDAO.ConnectionString = _connectionString;
                            currentStatusDAO.Insert(unit.Name, "ERR");
                        }
                    }
                }
            }
            catch (Exception)
            {
                //File.AppendAllText(@"c:\smartpower\logerr.txt", er.ToString());
            }
        }
Ejemplo n.º 32
0
        private void grdChildOne_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (_loadComplete)
            {
                switch (_currentModule)
                {
                    case "Configuration":
                        _loadComplete = false;

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

                         lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                        deviceDAO.ConnectionString = _connectionString;
                        List<lfa.pmgmt.data.DTO.Configuration.Device> list = deviceDAO.List(_selectedItemDataId);

                        grdChildTwo.DataSource = list;

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

                        grdChildTwo.Columns[5].ReadOnly = true;

                        _loadComplete = true;
                        break;
                    case "Schedule":
                         _loadComplete = false;

                         DataGridViewRow s_selectedRow = grdChildOne.SelectedRows[0];
                        _selectedItemDataId = int.Parse(s_selectedRow.Cells[0].Value.ToString());

                        int selectedSchedule = int.Parse(grdMain.SelectedRows[0].Cells[0].Value.ToString());

                         lfa.pmgmt.data.DAO.Schedule.Device s_deviceDAO = new data.DAO.Schedule.Device();
                        s_deviceDAO.ConnectionString = _connectionString;
                        List<lfa.pmgmt.data.DTO.Schedule.Device> s_list = s_deviceDAO.ListWithSwitch(_selectedItemDataId,selectedSchedule);

                        grdChildTwo.Columns.Clear();

                        grdChildTwo.DataSource = s_list;

                        grdChildTwo.Columns[0].Visible = false;

                        _loadComplete = true;
                        break;
                    case "LoadShed":
                        _loadComplete = false;

                        DataGridViewRow ls_selectedRow = grdChildOne.SelectedRows[0];
                        _selectedItemDataId = int.Parse(ls_selectedRow.Cells[0].Value.ToString());

                        lfa.pmgmt.data.DAO.Configuration.Device ls_deviceDAO = new data.DAO.Configuration.Device();
                        ls_deviceDAO.ConnectionString = _connectionString;
                        List<lfa.pmgmt.data.DTO.Configuration.LoadShedDevice> ls_list = ls_deviceDAO.ListLoadShed(_selectedItemDataId);

                        grdChildTwo.Columns.Clear();

                        grdChildTwo.DataSource = ls_list;

                        grdChildTwo.Columns[0].Visible = false;
                        grdChildTwo.Columns[2].Visible = false;
                        grdChildTwo.Columns[3].Visible = false;
                        grdChildTwo.Columns[4].Visible = false;

                        ComboBox cmbStatus = new ComboBox();
                        cmbStatus.Items.Add("On");
                        cmbStatus.Items.Add("Off");

                        DataGridViewComboBoxColumn comboBoxColumn = new DataGridViewComboBoxColumn();
                        comboBoxColumn.Items.Add("On");
                        comboBoxColumn.Items.Add("Off");
                        grdChildTwo.Columns.Add(comboBoxColumn);

                        foreach(DataGridViewRow dgvRow in grdChildTwo.Rows)
                        {
                            dgvRow.Cells[5].Value = dgvRow.Cells[4].Value;
                        }

                        btnLoadShed.Visible = true;

                        _loadComplete = true;
                        break;
                }
            }
        }
Ejemplo n.º 33
0
        private void grdChildOne_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (_loadComplete)
            {
                switch (_currentModule)
                {
                case "Configuration":
                    _loadComplete = false;

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

                    lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                    deviceDAO.ConnectionString = _connectionString;
                    List <lfa.pmgmt.data.DTO.Configuration.Device> list = deviceDAO.List(_selectedItemDataId);

                    grdChildTwo.DataSource = list;

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

                    grdChildTwo.Columns[5].ReadOnly = true;

                    _loadComplete = true;
                    break;

                case "Schedule":
                    _loadComplete = false;

                    DataGridViewRow s_selectedRow = grdChildOne.SelectedRows[0];
                    _selectedItemDataId = int.Parse(s_selectedRow.Cells[0].Value.ToString());

                    int selectedSchedule = int.Parse(grdMain.SelectedRows[0].Cells[0].Value.ToString());

                    lfa.pmgmt.data.DAO.Schedule.Device s_deviceDAO = new data.DAO.Schedule.Device();
                    s_deviceDAO.ConnectionString = _connectionString;
                    List <lfa.pmgmt.data.DTO.Schedule.Device> s_list = s_deviceDAO.ListWithSwitch(_selectedItemDataId, selectedSchedule);

                    grdChildTwo.Columns.Clear();

                    grdChildTwo.DataSource = s_list;

                    grdChildTwo.Columns[0].Visible = false;

                    _loadComplete = true;
                    break;

                case "LoadShed":
                    _loadComplete = false;

                    DataGridViewRow ls_selectedRow = grdChildOne.SelectedRows[0];
                    _selectedItemDataId = int.Parse(ls_selectedRow.Cells[0].Value.ToString());

                    lfa.pmgmt.data.DAO.Configuration.Device ls_deviceDAO = new data.DAO.Configuration.Device();
                    ls_deviceDAO.ConnectionString = _connectionString;
                    List <lfa.pmgmt.data.DTO.Configuration.LoadShedDevice> ls_list = ls_deviceDAO.ListLoadShed(_selectedItemDataId);

                    grdChildTwo.Columns.Clear();

                    grdChildTwo.DataSource = ls_list;

                    grdChildTwo.Columns[0].Visible = false;
                    grdChildTwo.Columns[2].Visible = false;
                    grdChildTwo.Columns[3].Visible = false;
                    grdChildTwo.Columns[4].Visible = false;

                    ComboBox cmbStatus = new ComboBox();
                    cmbStatus.Items.Add("On");
                    cmbStatus.Items.Add("Off");

                    DataGridViewComboBoxColumn comboBoxColumn = new DataGridViewComboBoxColumn();
                    comboBoxColumn.Items.Add("On");
                    comboBoxColumn.Items.Add("Off");
                    grdChildTwo.Columns.Add(comboBoxColumn);

                    foreach (DataGridViewRow dgvRow in grdChildTwo.Rows)
                    {
                        dgvRow.Cells[5].Value = dgvRow.Cells[4].Value;
                    }

                    btnLoadShed.Visible = true;

                    _loadComplete = true;
                    break;
                }
            }
        }
Ejemplo n.º 34
0
        private void LoadShedUnit(List <lfa.pmgmt.data.DTO.Schedule.Device> unitDevices, int defaultPort,
                                  lfa.pmgmt.data.DTO.Schedule.Unit unit, int status)
        {
            if (unit.IsActive)
            {
                string deviceAddress = string.Empty;

                SwitchbankUpdate mySwitchbankUpdate = null;

                BravaCodes.SwitchState[] mySwitchStates = new BravaCodes.SwitchState[8];

                for (int x = 0; x <= 7; x++)
                {
                    mySwitchStates[x] = BravaCodes.SwitchState.SwitchOff;
                }

                foreach (lfa.pmgmt.data.DTO.Schedule.Device unitDevice in unitDevices)
                {
                    lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                    deviceDAO.ConnectionString = _connectionString;

                    string deviceName     = unitDevice.Name;
                    int    deviceConfigId = deviceDAO.GetDeviceConfigId(unit.Id_ScheduleUnit, unitDevice.Id);

                    deviceAddress = deviceDAO.GetDeviceAddress(deviceConfigId);
                    string deviceSwitch = deviceDAO.GetDeviceSwitch(deviceConfigId);

                    bool switchOn = unitDevice.DeviceOn;

                    if (switchOn)
                    {
                        status = 1;
                    }
                    else
                    {
                        status = 2;
                    }

                    SetSwitchState(deviceSwitch, status, mySwitchStates, unitDevice.Id.ToString());
                }

                try
                {
                    mySwitchbankUpdate = new SwitchbankUpdate(
                        mySwitchStates[0],
                        mySwitchStates[1],
                        mySwitchStates[2],
                        mySwitchStates[3],
                        mySwitchStates[4],
                        mySwitchStates[5],
                        mySwitchStates[6],
                        mySwitchStates[7]);

                    SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                    lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                    currentStatusDAO.ConnectionString = _connectionString;
                    currentStatusDAO.Insert(unit.Name, "OK");
                }
                catch (System.Net.Sockets.SocketException)
                {
                    System.Threading.Thread.Sleep(200);

                    try
                    {
                        mySwitchbankUpdate = new SwitchbankUpdate(
                            mySwitchStates[0],
                            mySwitchStates[1],
                            mySwitchStates[2],
                            mySwitchStates[3],
                            mySwitchStates[4],
                            mySwitchStates[5],
                            mySwitchStates[6],
                            mySwitchStates[7]);

                        SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    catch (System.Net.Sockets.SocketException ex)
                    {
                        lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log();
                        logDAO.ConnectionString = _connectionString;
                        logDAO.Insert(1, "Unit: " + unit.Name, "TCP/IP Communications Error due to: " + ex.ToString(), DateTime.Now);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "ERR");
                    }
                }
            }
        }
Ejemplo n.º 35
0
        private void LoadShedUnit(List<lfa.pmgmt.data.DTO.Schedule.Device> unitDevices, int defaultPort, lfa.pmgmt.data.DTO.Schedule.Unit unit)
        {
            int status = 0;

            foreach (lfa.pmgmt.data.DTO.Schedule.Device unitDevice in unitDevices)
            {
                lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                deviceDAO.ConnectionString = _connectionString;

                string deviceName = unitDevice.Name;
                int deviceConfigId = deviceDAO.GetDeviceConfigId(unit.Id_ScheduleUnit, unitDevice.Id);

                string deviceAddress = deviceDAO.GetDeviceAddress(deviceConfigId);
                string deviceSwitch = deviceDAO.GetDeviceSwitch(deviceConfigId);

                bool switchOn = unitDevice.DeviceOn;

                if (switchOn)
                {
                    status = 1;
                }
                else
                {
                    status = 2;
                }

                SendSwitchState(deviceAddress, defaultPort, deviceSwitch, status);
            }
        }
Ejemplo n.º 36
0
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboItem selectedItem = comboBox1.SelectedItem as ComboItem;
            int selectedUnit = selectedItem.Id;

            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(selectedUnit);

            foreach (lfa.pmgmt.data.DTO.Configuration.Device device in devices)
            {
                ComboItem item = new ComboItem();
                item.Id = device.Id;
                item.Name = device.Name;

                comboBox3.Items.Add(item);
            }
        }
Ejemplo n.º 37
0
        private void AsyncLoadShedUnit(object parameters)
        {
            ArrayList parms = parameters as ArrayList;

            List<lfa.pmgmt.data.DTO.Schedule.Device> unitDevices = parms[0] as List<lfa.pmgmt.data.DTO.Schedule.Device>;

            int defaultPort = (int)parms[1];

            lfa.pmgmt.data.DTO.Schedule.Unit unit = parms[2] as lfa.pmgmt.data.DTO.Schedule.Unit;

            int status = (int)parms[3];

            if (unit.IsActive)
            {
                string deviceAddress = string.Empty;

                SwitchbankUpdate mySwitchbankUpdate = null;

                BravaCodes.SwitchState[] mySwitchStates = new BravaCodes.SwitchState[8];

                for (int x = 0; x <= 7; x++) mySwitchStates[x] = BravaCodes.SwitchState.SwitchOff;

                foreach (lfa.pmgmt.data.DTO.Schedule.Device unitDevice in unitDevices)
                {
                    lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                    deviceDAO.ConnectionString = _connectionString;

                    string deviceName = unitDevice.Name;
                    int deviceConfigId = deviceDAO.GetDeviceConfigId(unit.Id_ScheduleUnit, unitDevice.Id);

                    deviceAddress = deviceDAO.GetDeviceAddress(deviceConfigId);
                    string deviceSwitch = deviceDAO.GetDeviceSwitch(deviceConfigId);

                    bool switchOn = unitDevice.DeviceOn;

                    if (switchOn)
                    {
                       status = 1;
                    }
                    else
                    {
                       status = 2;
                    }

                    SetSwitchState(deviceSwitch, status, mySwitchStates, unitDevice.Id.ToString());
                }

                mySwitchbankUpdate = new SwitchbankUpdate(mySwitchStates[0], mySwitchStates[1], mySwitchStates[2],
                                                          mySwitchStates[3], mySwitchStates[4], mySwitchStates[5],
                                                          mySwitchStates[6], mySwitchStates[7]);

                try
                {
                    SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                    lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                    currentStatusDAO.ConnectionString = _connectionString;
                    currentStatusDAO.Insert(unit.Name, "OK");
                }
                catch(System.Net.Sockets.SocketException)
                {
                    System.Threading.Thread.Sleep(500);

                    try
                    {
                        mySwitchbankUpdate = new SwitchbankUpdate(mySwitchStates[0], mySwitchStates[1], mySwitchStates[2],
                                                         mySwitchStates[3], mySwitchStates[4], mySwitchStates[5],
                                                         mySwitchStates[6], mySwitchStates[7]);

                        SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    catch (System.Net.Sockets.SocketException soex)
                    {
                        lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log();
                        logDAO.ConnectionString = _connectionString;
                        logDAO.Insert(1, "Unit: " + unit.Name, "TCP/IP Communications Error due to: " + soex.ToString(), DateTime.Now);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "ERR");
                    }
                }
            }
        }
Ejemplo n.º 38
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboItem selectedItem = comboBox1.SelectedItem as ComboItem;
            int zoneId = selectedItem.Id;

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

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

            foreach (lfa.pmgmt.data.DTO.Schedule.Unit unit in unitList)
            {
                if (unit.Id_Zone == zoneId)
                {
                    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":
                                checkBox1.Checked = device.DeviceOn;
                                break;
                            case "Switch 2":
                                checkBox2.Checked = device.DeviceOn;
                                break;
                            case "Switch 3":
                                checkBox3.Checked = device.DeviceOn;
                                break;
                            case "Switch 4":
                                checkBox4.Checked = device.DeviceOn;
                                break;
                            case "Switch 5":
                                checkBox5.Checked = device.DeviceOn;
                                break;
                            case "Switch 6":
                                checkBox6.Checked = device.DeviceOn;
                                break;
                            case "Switch 7":
                                checkBox7.Checked = device.DeviceOn;
                                break;
                            case "Switch 8":
                                checkBox8.Checked = device.DeviceOn;
                                break;
                        }
                    }
                }
            }
        }
Ejemplo n.º 39
0
        private void LoadShedUnit(List<lfa.pmgmt.data.DTO.Schedule.Device> unitDevices, int defaultPort, 
                                 lfa.pmgmt.data.DTO.Schedule.Unit unit, int status)
        {
            if (unit.IsActive)
            {
                string deviceAddress = string.Empty;

                SwitchbankUpdate mySwitchbankUpdate = null;

                BravaCodes.SwitchState[] mySwitchStates = new BravaCodes.SwitchState[8];

                for (int x = 0; x <= 7; x++) mySwitchStates[x] = BravaCodes.SwitchState.NoChange;

                foreach (lfa.pmgmt.data.DTO.Schedule.Device unitDevice in unitDevices)
                {
                    lfa.pmgmt.data.DAO.Configuration.Device deviceDAO = new data.DAO.Configuration.Device();
                    deviceDAO.ConnectionString = _connectionString;

                    string deviceName = unitDevice.Name;
                    int deviceConfigId = deviceDAO.GetDeviceConfigId(unit.Id_ScheduleUnit, unitDevice.Id);

                    deviceAddress = deviceDAO.GetDeviceAddress(deviceConfigId);
                    string deviceSwitch = deviceDAO.GetDeviceSwitch(deviceConfigId);

                    if (status == 0)
                    {
                        bool switchOn = unitDevice.DeviceOn;

                        if (switchOn)
                        {
                            status = 1;
                        }
                        else
                        {
                            status = 2;
                        }
                    }

                    SetSwitchState(deviceSwitch, status, mySwitchStates,unitDevice.Id.ToString());
                }

                try
                {
                    mySwitchbankUpdate = new SwitchbankUpdate(
                       mySwitchStates[0],
                       mySwitchStates[1],
                       mySwitchStates[2],
                       mySwitchStates[3],
                       mySwitchStates[4],
                       mySwitchStates[5],
                       mySwitchStates[6],
                       mySwitchStates[7]);

                    //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send 3", System.Diagnostics.EventLogEntryType.Warning);

                    SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                    lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                    currentStatusDAO.ConnectionString = _connectionString;
                    currentStatusDAO.Insert(unit.Name, "OK");
                }
                catch(System.Net.Sockets.SocketException)
                {
                    System.Threading.Thread.Sleep(200);

                    try
                    {
                       mySwitchbankUpdate = new SwitchbankUpdate(
                       mySwitchStates[0],
                       mySwitchStates[1],
                       mySwitchStates[2],
                       mySwitchStates[3],
                       mySwitchStates[4],
                       mySwitchStates[5],
                       mySwitchStates[6],
                       mySwitchStates[7]);

                       //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send Err 3", System.Diagnostics.EventLogEntryType.Warning);

                       SendSwitchState(deviceAddress, defaultPort, mySwitchbankUpdate);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    catch (System.Net.Sockets.SocketException ex)
                    {
                        lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log();
                        logDAO.ConnectionString = _connectionString;
                        logDAO.Insert(1, "Unit: " + unit.Name, "TCP/IP Communications Error due to: " + ex.ToString(), DateTime.Now);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "ERR");
                    }
                }
            }
            else
            {
                try
                {

                    //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send 4", System.Diagnostics.EventLogEntryType.Warning);

                    SendBatchSwitchState(unit.Address, defaultPort, string.Empty, 2);

                    lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                    currentStatusDAO.ConnectionString = _connectionString;
                    currentStatusDAO.Insert(unit.Name, "OK");
                }
                catch(System.Net.Sockets.SocketException)
                {
                    System.Threading.Thread.Sleep(200);

                    try
                    {
                        //System.Diagnostics.EventLog.WriteEntry("BUGGER", "Send Err 4", System.Diagnostics.EventLogEntryType.Warning);

                        SendBatchSwitchState(unit.Address, defaultPort, string.Empty, 2);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "OK");
                    }
                    catch (System.Net.Sockets.SocketException ex)
                    {
                        lfa.pmgmt.data.DAO.Logging.Log logDAO = new data.DAO.Logging.Log();
                        logDAO.ConnectionString = _connectionString;
                        logDAO.Insert(1, "Unit: " + unit.Name, "TCP/IP Communications Error due to: " + ex.ToString(), DateTime.Now);

                        lfa.pmgmt.data.DAO.Logging.CurrentStatus currentStatusDAO = new data.DAO.Logging.CurrentStatus();
                        currentStatusDAO.ConnectionString = _connectionString;
                        currentStatusDAO.Insert(unit.Name, "ERR");
                    }
                }
            }
        }