private void btnDelete_Click(object sender, EventArgs e) { if (_loadComplete) { switch (_currentModule) { case "Rules": if (grdMain.SelectedRows.Count == 0) { Exception ex = new Exception("Please selected a ruleset to delete!"); HandleException(ex); } else { DeleteRuleset(); } break; case "LoadShed": HandleInformationMesssage("Load shedding data can not be deleted! Data is only for control purposes!"); break; case "Configuration": try { int selectedZoneId = int.Parse(grdMain.SelectedRows[0].Cells[0].Value.ToString()); lfa.pmgmt.data.DAO.Configuration.Zone zoneDAO = new data.DAO.Configuration.Zone(); zoneDAO.ConnectionString = _connectionString; zoneDAO.Delete(selectedZoneId); HandleInformationMesssage("Data successfully deleted! Please refresh the data!"); } catch (Exception ex) { HandleException(ex); } break; case "Schedule": try { int selectedScheduleId = int.Parse(grdMain.SelectedRows[0].Cells[0].Value.ToString()); lfa.pmgmt.data.DAO.Schedule.Schedule scheduleDAO = new data.DAO.Schedule.Schedule(); scheduleDAO.ConnectionString = _connectionString; scheduleDAO.Delete(selectedScheduleId); HandleInformationMesssage("Data successfully deleted! Please refresh the data!"); } catch (Exception ex) { HandleException(ex); } break; } } }
private void BindRuleData() { lfa.pmgmt.data.DAO.Schedule.Schedule schedulDAO = new data.DAO.Schedule.Schedule(); schedulDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Priority> priorityList = schedulDAO.ListPriority(); dataGridView1.DataSource = priorityList; }
private void BindRuleData() { lfa.pmgmt.data.DAO.Schedule.Schedule schedulDAO = new data.DAO.Schedule.Schedule(); schedulDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Priority> priorityList = schedulDAO.ListPriority(); dataGridView1.DataSource = priorityList; }
public List <lfa.pmgmt.data.DTO.Schedule.Schedule> ListSchedules() { lfa.pmgmt.data.DAO.Schedule.Schedule scheduleDAO = new data.DAO.Schedule.Schedule(); scheduleDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Schedule> scheduleList = scheduleDAO.List(); return(scheduleList); }
private void BindScheduleData() { lfa.pmgmt.data.DAO.Schedule.Schedule scheduleDAO = new data.DAO.Schedule.Schedule(); scheduleDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Schedule> list = scheduleDAO.List(); btnGrdMainHeader.Text = "Schedules"; grdMain.DataSource = list; btnGrdChildOneHeader.Text = "Units"; btnGrdChildTwoHeader.Text = "Devices"; }
private void BulkUpdateScheduleSchedule() { foreach (DataGridViewRow scheduleRow in grdMain.Rows) { lfa.pmgmt.data.DAO.Schedule.Schedule scheduleDAO = new data.DAO.Schedule.Schedule(); scheduleDAO.ConnectionString = _connectionString; scheduleDAO.Update(int.Parse(scheduleRow.Cells[0].Value.ToString()), scheduleRow.Cells[1].Value.ToString(), scheduleRow.Cells[2].Value.ToString(), scheduleRow.Cells[3].Value.ToString(), int.Parse(scheduleRow.Cells[4].Value.ToString())); scheduleDAO.EnableDisable(int.Parse(scheduleRow.Cells[0].Value.ToString()), Convert.ToBoolean(scheduleRow.Cells[6].Value.ToString())); } }
private void BindSchedules() { lfa.pmgmt.data.DAO.Schedule.Schedule scheduleDAO = new data.DAO.Schedule.Schedule(); scheduleDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Schedule> schedules = scheduleDAO.List(); foreach (lfa.pmgmt.data.DTO.Schedule.Schedule schedule in schedules) { ComboItem item = new ComboItem(); item.Id = schedule.Id; item.Name = schedule.Name; comboBox1.Items.Add(item); } }
private void BindSchedules() { lfa.pmgmt.data.DAO.Schedule.Schedule scheduleDAO = new data.DAO.Schedule.Schedule(); scheduleDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Schedule> schedules = scheduleDAO.List(); foreach (lfa.pmgmt.data.DTO.Schedule.Schedule schedule in schedules) { ComboItem item = new ComboItem(); item.Id = schedule.Id; item.Name = schedule.Name; comboBox1.Items.Add(item); } }
private void btnOK_Click(object sender, EventArgs e) { try { ComboItem schedule = comboBox1.SelectedItem as ComboItem; string priority = comboBox4.SelectedItem.ToString(); lfa.pmgmt.data.DAO.Schedule.Schedule dao = new data.DAO.Schedule.Schedule(); dao.ConnectionString = _connectionString; dao.InsertPriority(schedule.Id, priority); BindRuleData(); } catch (Exception ex) { HandleException(ex); } }
private void btnDelete_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { DataGridViewRow selectedRow = dataGridView1.SelectedRows[0]; int selectedItemId = int.Parse(selectedRow.Cells[0].Value.ToString()); lfa.pmgmt.data.DAO.Schedule.Schedule ruleDAO = new data.DAO.Schedule.Schedule(); ruleDAO.ConnectionString = _connectionString; ruleDAO.DeletePriority(selectedItemId); HandleInformationMesssage("Priority successfully deleted!"); BindRuleData(); } else { Exception ex = new Exception("No priority selected to delete!"); HandleException(ex); } }
private void btnOK_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtZoneName.Text)) { Exception ex = new Exception("Validation Exception : Please provide a new name!"); HandleException(ex); } else if(string.IsNullOrEmpty(textBox1.Text)) { Exception ex = new Exception("Validation Exception : Please provide a valid start time!"); HandleException(ex); } else if (string.IsNullOrEmpty(textBox2.Text)) { Exception ex = new Exception("Validation Exception : Please provide a valid end time!"); HandleException(ex); } else if(string.IsNullOrEmpty(textBox3.Text)) { Exception ex = new Exception("Validation Exception : Please provide an interval value!"); HandleException(ex); } else { try { lfa.pmgmt.data.DAO.Schedule.Schedule DAO = new data.DAO.Schedule.Schedule(); DAO.ConnectionString = _connectionString; DAO.Insert(txtZoneName.Text,textBox1.Text,textBox2.Text,int.Parse(textBox3.Text), DateTime.Now); HandleInformationMesssage("Data successfully saved! Please refresh the form data!"); this.Close(); } catch (Exception ex) { HandleException(ex); } } }
private void btnOK_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtZoneName.Text)) { Exception ex = new Exception("Validation Exception : Please provide a new name!"); HandleException(ex); } else if (string.IsNullOrEmpty(textBox1.Text)) { Exception ex = new Exception("Validation Exception : Please provide a valid start time!"); HandleException(ex); } else if (string.IsNullOrEmpty(textBox2.Text)) { Exception ex = new Exception("Validation Exception : Please provide a valid end time!"); HandleException(ex); } else if (string.IsNullOrEmpty(textBox3.Text)) { Exception ex = new Exception("Validation Exception : Please provide an interval value!"); HandleException(ex); } else { try { lfa.pmgmt.data.DAO.Schedule.Schedule DAO = new data.DAO.Schedule.Schedule(); DAO.ConnectionString = _connectionString; DAO.Insert(txtZoneName.Text, textBox1.Text, textBox2.Text, int.Parse(textBox3.Text), DateTime.Now); HandleInformationMesssage("Data successfully saved! Please refresh the form data!"); this.Close(); } catch (Exception ex) { HandleException(ex); } } }
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); } }
public void ExecuteSchedule(List<lfa.pmgmt.data.DTO.Schedule.Schedule> scheduleList, List<int> ruleEnabledUnits, int defaultPort) { _executed = new List<string>(); _defaultUnits = new Dictionary<string, List<lfa.pmgmt.data.DTO.Schedule.Unit>>(); foreach (lfa.pmgmt.data.DTO.Schedule.Schedule schedule in scheduleList) { if (schedule.IsActive) { string scheduleStartTime = schedule.StartTime; string scheduleEndTime = schedule.EndTime; DateTime currentTime = DateTime.Now; DateTime scheduleStart = Convert.ToDateTime(scheduleStartTime); DateTime scheduleEnd = Convert.ToDateTime(scheduleEndTime); if (currentTime <= scheduleEnd) { if (currentTime >= scheduleStart) { lfa.pmgmt.data.DAO.Schedule.Schedule DAO = new data.DAO.Schedule.Schedule(); DAO.ConnectionString = _connectionString; string priorityValue = DAO.GetPriority(schedule.Id); if (string.IsNullOrEmpty(priorityValue)) { priorityValue = "None"; } if (string.IsNullOrEmpty(priorityValue)) { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); GetScheduleUnitDetailsForId(scheduleUnits, schedule.Id, ruleEnabledUnits, defaultPort); } else { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); if (ExecutePriority(_connectionString, priorityValue)) { GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); _executed.Add("true"); } #region OBSOLETE //if (ExecutePriority(_connectionString)) //{ // lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); // unitDAO.ConnectionString = _connectionString; // List<lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); // if (priorityValue.ToLower().Equals("low")) // { // GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); // } // if (priorityValue.ToLower().Equals("medium")) // { // GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); // lfa.pmgmt.data.DAO.Schedule.Schedule dao = new data.DAO.Schedule.Schedule(); // dao.ConnectionString = _connectionString; // int zoneid = dao.GetLinkedZone(schedule.Id); // List<int> scheduleIds = dao.ListPrioritySchedules(zoneid, "Low"); // foreach (int id in scheduleIds) // { // List<lfa.pmgmt.data.DTO.Schedule.Unit> i_scheduleUnits = unitDAO.List(id); // GetScheduleUnitDetails(i_scheduleUnits, id, defaultPort); // } // } // if (priorityValue.ToLower().Equals("high")) // { // GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); // lfa.pmgmt.data.DAO.Schedule.Schedule dao = new data.DAO.Schedule.Schedule(); // dao.ConnectionString = _connectionString; // int zoneid = dao.GetLinkedZone(schedule.Id); // List<int> scheduleIds = dao.ListPrioritySchedules(zoneid, "Medium"); // foreach (int id in scheduleIds) // { // List<lfa.pmgmt.data.DTO.Schedule.Unit> i_scheduleUnits = unitDAO.List(id); // GetScheduleUnitDetails(i_scheduleUnits, id, defaultPort); // } // List<int> lowscheduleIds = dao.ListPrioritySchedules(zoneid, "Low"); // foreach (int id in lowscheduleIds) // { // List<lfa.pmgmt.data.DTO.Schedule.Unit> i_scheduleUnits = unitDAO.List(id); // GetScheduleUnitDetails(i_scheduleUnits,id, defaultPort); // } // } //} #endregion } } } if (scheduleEndTime == "00:00" && scheduleStartTime == "00:00") { lfa.pmgmt.data.DAO.Schedule.Schedule DAO = new data.DAO.Schedule.Schedule(); DAO.ConnectionString = _connectionString; string priorityValue = DAO.GetPriority(schedule.Id); if (string.IsNullOrEmpty(priorityValue)) { priorityValue = "None"; } if (string.IsNullOrEmpty(priorityValue)) { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); GetScheduleUnitDetailsForId(scheduleUnits, schedule.Id, ruleEnabledUnits, defaultPort); } else { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); _defaultUnits.Add(schedule.Id.ToString(),scheduleUnits); //if (ExecutePriority(_connectionString, priorityValue)) //{ //GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); //} } } } } if (_defaultUnits.Count > 0) { if (_executed.Count <= 0) { foreach (string id in _defaultUnits.Keys) { List<lfa.pmgmt.data.DTO.Schedule.Unit> units = _defaultUnits[id]; GetScheduleUnitDetails(units, int.Parse(id), defaultPort); } } } _defaultUnits.Clear(); _executed.Clear(); }
public void Execute(int defaultPort) { _switchStates = new Dictionary <string, string>(); _executed = new List <string>(); int ruleCount = 0; lfa.pmgmt.data.DAO.Schedule.Schedule scheduleDAO = new data.DAO.Schedule.Schedule(); scheduleDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Schedule> scheduleList = scheduleDAO.List(); foreach (lfa.pmgmt.data.DTO.Schedule.Schedule schedule in scheduleList) { if (schedule.IsActive) { string scheduleStartTime = schedule.StartTime; string scheduleEndTime = schedule.EndTime; DateTime currentTime = DateTime.Now; DateTime scheduleStart = Convert.ToDateTime(scheduleStartTime); DateTime scheduleEnd = Convert.ToDateTime(scheduleEndTime); if (scheduleStart > scheduleEnd) { scheduleEnd = scheduleEnd.AddDays(1); } if (currentTime <= scheduleEnd) { if (currentTime >= scheduleStart) { lfa.pmgmt.data.DAO.Schedule.Schedule DAO = new data.DAO.Schedule.Schedule(); DAO.ConnectionString = _connectionString; string priorityValue = DAO.GetPriority(schedule.Id); if (string.IsNullOrEmpty(priorityValue)) { int status = 0; lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort, status); } else { int status = 0; lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); if (ExecutePriority(_connectionString, priorityValue, out status, out ruleCount)) { GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort, status); _executed.Add("true"); } } } } } } }
public void ExecuteSchedule(List <lfa.pmgmt.data.DTO.Schedule.Schedule> scheduleList, List <int> ruleEnabledUnits, int defaultPort) { _executed = new List <string>(); _defaultUnits = new Dictionary <string, List <lfa.pmgmt.data.DTO.Schedule.Unit> >(); int status = 0; int ruleCount = 0; foreach (lfa.pmgmt.data.DTO.Schedule.Schedule schedule in scheduleList) { if (schedule.IsActive) { string scheduleStartTime = schedule.StartTime; string scheduleEndTime = schedule.EndTime; DateTime currentTime = DateTime.Now; DateTime scheduleStart = Convert.ToDateTime(scheduleStartTime); DateTime scheduleEnd = Convert.ToDateTime(scheduleEndTime); if (scheduleStart > scheduleEnd) { scheduleEnd = scheduleEnd.AddDays(1); } if (currentTime.TimeOfDay <= scheduleEnd.TimeOfDay) { if (currentTime.TimeOfDay >= scheduleStart.TimeOfDay) { lfa.pmgmt.data.DAO.Schedule.Schedule DAO = new data.DAO.Schedule.Schedule(); DAO.ConnectionString = _connectionString; string priorityValue = DAO.GetPriority(schedule.Id); if (string.IsNullOrEmpty(priorityValue)) { priorityValue = "None"; } if (string.IsNullOrEmpty(priorityValue)) { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); GetScheduleUnitDetailsForId(scheduleUnits, schedule.Id, ruleEnabledUnits, defaultPort, status); } else { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); if (ExecutePriority(_connectionString, priorityValue, out status, out ruleCount)) { GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort, status); _executed.Add("true"); } else { if (ruleCount <= 0) { status = 0; GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort, status); } _executed.Add("true"); } } } } if (scheduleEndTime == "00:00" && scheduleStartTime == "00:00") { lfa.pmgmt.data.DAO.Schedule.Schedule DAO = new data.DAO.Schedule.Schedule(); DAO.ConnectionString = _connectionString; string priorityValue = DAO.GetPriority(schedule.Id); if (string.IsNullOrEmpty(priorityValue)) { priorityValue = "None"; } if (string.IsNullOrEmpty(priorityValue)) { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); GetScheduleUnitDetailsForId(scheduleUnits, schedule.Id, ruleEnabledUnits, defaultPort, 0); } else { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); _defaultUnits.Add(schedule.Id.ToString(), scheduleUnits); } } } } if (_defaultUnits.Count > 0) { if (_executed.Count <= 0) { foreach (string id in _defaultUnits.Keys) { List <lfa.pmgmt.data.DTO.Schedule.Unit> units = _defaultUnits[id]; GetScheduleUnitDetails(units, int.Parse(id), defaultPort, 0); } } } _defaultUnits.Clear(); _executed.Clear(); }
public void Execute(int defaultPort) { _executed = new List<string>(); lfa.pmgmt.data.DAO.Schedule.Schedule scheduleDAO = new data.DAO.Schedule.Schedule(); scheduleDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Schedule> scheduleList = scheduleDAO.List(); foreach (lfa.pmgmt.data.DTO.Schedule.Schedule schedule in scheduleList) { if (schedule.IsActive) { string scheduleStartTime = schedule.StartTime; string scheduleEndTime = schedule.EndTime; DateTime currentTime = DateTime.Now; DateTime scheduleStart = Convert.ToDateTime(scheduleStartTime); DateTime scheduleEnd = Convert.ToDateTime(scheduleEndTime); if (currentTime <= scheduleEnd) { if (currentTime >= scheduleStart) { lfa.pmgmt.data.DAO.Schedule.Schedule DAO = new data.DAO.Schedule.Schedule(); DAO.ConnectionString = _connectionString; string priorityValue = DAO.GetPriority(schedule.Id); if (string.IsNullOrEmpty(priorityValue)) { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); } else { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); if (ExecutePriority(_connectionString, priorityValue)) { GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); _executed.Add("true"); } #region OBSOLETE //if (priorityValue.ToLower().Equals("low")) //{ // ExecutePriority(connectionString,priority) // { // GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); // } //} //if (priorityValue.ToLower().Equals("medium")) //{ // GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); // lfa.pmgmt.data.DAO.Schedule.Schedule dao = new data.DAO.Schedule.Schedule(); // dao.ConnectionString = _connectionString; // int zoneid = dao.GetLinkedZone(schedule.Id); // List<int> scheduleIds = dao.ListPrioritySchedules(zoneid, "Low"); // foreach (int id in scheduleIds) // { // List<lfa.pmgmt.data.DTO.Schedule.Unit> i_scheduleUnits = unitDAO.List(id); // GetScheduleUnitDetails(i_scheduleUnits, id, defaultPort); // } //} //if (priorityValue.ToLower().Equals("high")) //{ // GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); // lfa.pmgmt.data.DAO.Schedule.Schedule dao = new data.DAO.Schedule.Schedule(); // dao.ConnectionString = _connectionString; // int zoneid = dao.GetLinkedZone(schedule.Id); // List<int> scheduleIds = dao.ListPrioritySchedules(zoneid, "Medium"); // foreach (int id in scheduleIds) // { // List<lfa.pmgmt.data.DTO.Schedule.Unit> i_scheduleUnits = unitDAO.List(id); // GetScheduleUnitDetails(i_scheduleUnits, id, defaultPort); // } // List<int> lowscheduleIds = dao.ListPrioritySchedules(zoneid, "Low"); // foreach (int id in lowscheduleIds) // { // List<lfa.pmgmt.data.DTO.Schedule.Unit> i_scheduleUnits = unitDAO.List(id); // GetScheduleUnitDetails(i_scheduleUnits, id, defaultPort); // } //} #endregion } } } } } }
private void BindScheduleData() { lfa.pmgmt.data.DAO.Schedule.Schedule scheduleDAO = new data.DAO.Schedule.Schedule(); scheduleDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Schedule> list = scheduleDAO.List(); btnGrdMainHeader.Text = "Schedules"; grdMain.DataSource = list; btnGrdChildOneHeader.Text = "Units"; btnGrdChildTwoHeader.Text = "Devices"; }
public void ExecuteSchedule(List<lfa.pmgmt.data.DTO.Schedule.Schedule> scheduleList, List<int> ruleEnabledUnits, int defaultPort) { List<string> _executed = new List<string>(); Dictionary<string, List<lfa.pmgmt.data.DTO.Schedule.Unit>> _defaultUnits = new Dictionary<string, List<lfa.pmgmt.data.DTO.Schedule.Unit>>(); int status = 0; int ruleCount = 0; foreach (lfa.pmgmt.data.DTO.Schedule.Schedule schedule in scheduleList) { if (schedule.IsActive) { string scheduleStartTime = schedule.StartTime; string scheduleEndTime = schedule.EndTime; DateTime currentTime = DateTime.Now; DateTime scheduleStart = Convert.ToDateTime(scheduleStartTime); DateTime scheduleEnd = Convert.ToDateTime(scheduleEndTime); if (scheduleStart > scheduleEnd) { scheduleEnd = scheduleEnd.AddDays(1); } if (currentTime.TimeOfDay <= scheduleEnd.TimeOfDay) { if (currentTime.TimeOfDay >= scheduleStart.TimeOfDay) { lfa.pmgmt.data.DAO.Schedule.Schedule DAO = new data.DAO.Schedule.Schedule(); DAO.ConnectionString = _connectionString; string priorityValue = DAO.GetPriority(schedule.Id); if (string.IsNullOrEmpty(priorityValue)) { priorityValue = "None"; } if (string.IsNullOrEmpty(priorityValue)) { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); GetScheduleUnitDetailsForId(scheduleUnits, schedule.Id, ruleEnabledUnits, defaultPort, status); } else { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); if (ExecutePriority(_connectionString, priorityValue, out status,out ruleCount)) { //File.AppendAllText(@"c:\smartpower\log.txt", priorityValue + " " + System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\r\n"); GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort, status); _executed.Add("true"); } else { if (ruleCount <= 0) { status = 0; GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort, status); } _executed.Add("true"); } } } } if (scheduleEndTime == "00:00" && scheduleStartTime == "00:00") { lfa.pmgmt.data.DAO.Schedule.Schedule DAO = new data.DAO.Schedule.Schedule(); DAO.ConnectionString = _connectionString; string priorityValue = DAO.GetPriority(schedule.Id); if (string.IsNullOrEmpty(priorityValue)) { priorityValue = "None"; } if (string.IsNullOrEmpty(priorityValue)) { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); GetScheduleUnitDetailsForId(scheduleUnits, schedule.Id, ruleEnabledUnits, defaultPort,0); } else { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); _defaultUnits.Add(schedule.Id.ToString(), scheduleUnits); } } } } if (_defaultUnits.Count > 0) { if (_executed.Count <= 0) { foreach (string id in _defaultUnits.Keys) { List<lfa.pmgmt.data.DTO.Schedule.Unit> units = _defaultUnits[id]; GetScheduleUnitDetails(units, int.Parse(id), defaultPort,0); } } } _defaultUnits.Clear(); _executed.Clear(); }
public List<lfa.pmgmt.data.DTO.Schedule.Schedule> ListSchedules() { lfa.pmgmt.data.DAO.Schedule.Schedule scheduleDAO = new data.DAO.Schedule.Schedule(); scheduleDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Schedule> scheduleList = scheduleDAO.List(); return scheduleList; }
public void Execute(int defaultPort) { try { Dictionary<string, string> _switchStates = new Dictionary<string, string>(); List<string> _executed = new List<string>(); int ruleCount = 0; lfa.pmgmt.data.DAO.Schedule.Schedule scheduleDAO = new data.DAO.Schedule.Schedule(); scheduleDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Schedule> scheduleList = scheduleDAO.List(); foreach (lfa.pmgmt.data.DTO.Schedule.Schedule schedule in scheduleList) { if (schedule.IsActive) { string scheduleStartTime = schedule.StartTime; string scheduleEndTime = schedule.EndTime; DateTime currentTime = DateTime.Now; DateTime scheduleStart = Convert.ToDateTime(scheduleStartTime); DateTime scheduleEnd = Convert.ToDateTime(scheduleEndTime); if (scheduleStart > scheduleEnd) { scheduleEnd = scheduleEnd.AddDays(1); } if (currentTime <= scheduleEnd) { if (currentTime >= scheduleStart) { lfa.pmgmt.data.DAO.Schedule.Schedule DAO = new data.DAO.Schedule.Schedule(); DAO.ConnectionString = _connectionString; string priorityValue = DAO.GetPriority(schedule.Id); if (string.IsNullOrEmpty(priorityValue)) { int status = 0; lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort, status); } else { int status = 0; lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List<lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); if (ExecutePriority(_connectionString, priorityValue, out status, out ruleCount)) { GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort, status); _executed.Add("true"); } } } } } } } catch (Exception) { //File.AppendAllText(@"c:\smartpower\logerr2.txt", ex.ToString()); } }
public void ExecuteSchedule(List <lfa.pmgmt.data.DTO.Schedule.Schedule> scheduleList, List <int> ruleEnabledUnits, int defaultPort) { _executed = new List <string>(); _defaultUnits = new Dictionary <string, List <lfa.pmgmt.data.DTO.Schedule.Unit> >(); foreach (lfa.pmgmt.data.DTO.Schedule.Schedule schedule in scheduleList) { if (schedule.IsActive) { string scheduleStartTime = schedule.StartTime; string scheduleEndTime = schedule.EndTime; DateTime currentTime = DateTime.Now; DateTime scheduleStart = Convert.ToDateTime(scheduleStartTime); DateTime scheduleEnd = Convert.ToDateTime(scheduleEndTime); if (currentTime <= scheduleEnd) { if (currentTime >= scheduleStart) { lfa.pmgmt.data.DAO.Schedule.Schedule DAO = new data.DAO.Schedule.Schedule(); DAO.ConnectionString = _connectionString; string priorityValue = DAO.GetPriority(schedule.Id); if (string.IsNullOrEmpty(priorityValue)) { priorityValue = "None"; } if (string.IsNullOrEmpty(priorityValue)) { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); GetScheduleUnitDetailsForId(scheduleUnits, schedule.Id, ruleEnabledUnits, defaultPort); } else { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); if (ExecutePriority(_connectionString, priorityValue)) { GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); _executed.Add("true"); } #region OBSOLETE //if (ExecutePriority(_connectionString)) //{ // lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); // unitDAO.ConnectionString = _connectionString; // List<lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); // if (priorityValue.ToLower().Equals("low")) // { // GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); // } // if (priorityValue.ToLower().Equals("medium")) // { // GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); // lfa.pmgmt.data.DAO.Schedule.Schedule dao = new data.DAO.Schedule.Schedule(); // dao.ConnectionString = _connectionString; // int zoneid = dao.GetLinkedZone(schedule.Id); // List<int> scheduleIds = dao.ListPrioritySchedules(zoneid, "Low"); // foreach (int id in scheduleIds) // { // List<lfa.pmgmt.data.DTO.Schedule.Unit> i_scheduleUnits = unitDAO.List(id); // GetScheduleUnitDetails(i_scheduleUnits, id, defaultPort); // } // } // if (priorityValue.ToLower().Equals("high")) // { // GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); // lfa.pmgmt.data.DAO.Schedule.Schedule dao = new data.DAO.Schedule.Schedule(); // dao.ConnectionString = _connectionString; // int zoneid = dao.GetLinkedZone(schedule.Id); // List<int> scheduleIds = dao.ListPrioritySchedules(zoneid, "Medium"); // foreach (int id in scheduleIds) // { // List<lfa.pmgmt.data.DTO.Schedule.Unit> i_scheduleUnits = unitDAO.List(id); // GetScheduleUnitDetails(i_scheduleUnits, id, defaultPort); // } // List<int> lowscheduleIds = dao.ListPrioritySchedules(zoneid, "Low"); // foreach (int id in lowscheduleIds) // { // List<lfa.pmgmt.data.DTO.Schedule.Unit> i_scheduleUnits = unitDAO.List(id); // GetScheduleUnitDetails(i_scheduleUnits,id, defaultPort); // } // } //} #endregion } } } if (scheduleEndTime == "00:00" && scheduleStartTime == "00:00") { lfa.pmgmt.data.DAO.Schedule.Schedule DAO = new data.DAO.Schedule.Schedule(); DAO.ConnectionString = _connectionString; string priorityValue = DAO.GetPriority(schedule.Id); if (string.IsNullOrEmpty(priorityValue)) { priorityValue = "None"; } if (string.IsNullOrEmpty(priorityValue)) { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); GetScheduleUnitDetailsForId(scheduleUnits, schedule.Id, ruleEnabledUnits, defaultPort); } else { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); _defaultUnits.Add(schedule.Id.ToString(), scheduleUnits); //if (ExecutePriority(_connectionString, priorityValue)) //{ //GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); //} } } } } if (_defaultUnits.Count > 0) { if (_executed.Count <= 0) { foreach (string id in _defaultUnits.Keys) { List <lfa.pmgmt.data.DTO.Schedule.Unit> units = _defaultUnits[id]; GetScheduleUnitDetails(units, int.Parse(id), defaultPort); } } } _defaultUnits.Clear(); _executed.Clear(); }
public void Execute(int defaultPort) { _executed = new List <string>(); lfa.pmgmt.data.DAO.Schedule.Schedule scheduleDAO = new data.DAO.Schedule.Schedule(); scheduleDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Schedule> scheduleList = scheduleDAO.List(); foreach (lfa.pmgmt.data.DTO.Schedule.Schedule schedule in scheduleList) { if (schedule.IsActive) { string scheduleStartTime = schedule.StartTime; string scheduleEndTime = schedule.EndTime; DateTime currentTime = DateTime.Now; DateTime scheduleStart = Convert.ToDateTime(scheduleStartTime); DateTime scheduleEnd = Convert.ToDateTime(scheduleEndTime); if (currentTime <= scheduleEnd) { if (currentTime >= scheduleStart) { lfa.pmgmt.data.DAO.Schedule.Schedule DAO = new data.DAO.Schedule.Schedule(); DAO.ConnectionString = _connectionString; string priorityValue = DAO.GetPriority(schedule.Id); if (string.IsNullOrEmpty(priorityValue)) { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); } else { lfa.pmgmt.data.DAO.Schedule.Unit unitDAO = new data.DAO.Schedule.Unit(); unitDAO.ConnectionString = _connectionString; List <lfa.pmgmt.data.DTO.Schedule.Unit> scheduleUnits = unitDAO.List(schedule.Id); if (ExecutePriority(_connectionString, priorityValue)) { GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); _executed.Add("true"); } #region OBSOLETE //if (priorityValue.ToLower().Equals("low")) //{ // ExecutePriority(connectionString,priority) // { // GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); // } //} //if (priorityValue.ToLower().Equals("medium")) //{ // GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); // lfa.pmgmt.data.DAO.Schedule.Schedule dao = new data.DAO.Schedule.Schedule(); // dao.ConnectionString = _connectionString; // int zoneid = dao.GetLinkedZone(schedule.Id); // List<int> scheduleIds = dao.ListPrioritySchedules(zoneid, "Low"); // foreach (int id in scheduleIds) // { // List<lfa.pmgmt.data.DTO.Schedule.Unit> i_scheduleUnits = unitDAO.List(id); // GetScheduleUnitDetails(i_scheduleUnits, id, defaultPort); // } //} //if (priorityValue.ToLower().Equals("high")) //{ // GetScheduleUnitDetails(scheduleUnits, schedule.Id, defaultPort); // lfa.pmgmt.data.DAO.Schedule.Schedule dao = new data.DAO.Schedule.Schedule(); // dao.ConnectionString = _connectionString; // int zoneid = dao.GetLinkedZone(schedule.Id); // List<int> scheduleIds = dao.ListPrioritySchedules(zoneid, "Medium"); // foreach (int id in scheduleIds) // { // List<lfa.pmgmt.data.DTO.Schedule.Unit> i_scheduleUnits = unitDAO.List(id); // GetScheduleUnitDetails(i_scheduleUnits, id, defaultPort); // } // List<int> lowscheduleIds = dao.ListPrioritySchedules(zoneid, "Low"); // foreach (int id in lowscheduleIds) // { // List<lfa.pmgmt.data.DTO.Schedule.Unit> i_scheduleUnits = unitDAO.List(id); // GetScheduleUnitDetails(i_scheduleUnits, id, defaultPort); // } //} #endregion } } } } } }
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); } }