private void btnOK_Click(object sender, EventArgs e) { int status = 2; if (string.IsNullOrEmpty(textBox1.Text)) { Exception ex = new Exception("Validation Exception : Please provide a load value!"); HandleException(ex); } else { ComboItem zone = comboBox1.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 = zone.Id + ".1." + comparer + "." + textBox1.Text; string result = zone.Id + ".1." + status.ToString(); lfa.pmgmt.data.DAO.BusinessRule.Rule ruleDAO = new data.DAO.BusinessRule.Rule(); ruleDAO.ConnectionString = _connectionString; ruleDAO.Insert(_ruleId, condition, result); int ruleId = ruleDAO.GetLastInsertedRuleId(); //if (!comboBox2.SelectedItem.ToString().ToLower().Equals("none")) //{ lfa.pmgmt.data.DAO.BusinessRule.RuleSet rulesetDAO = new data.DAO.BusinessRule.RuleSet(); rulesetDAO.ConnectionString = _connectionString; rulesetDAO.InsertPriority(_ruleId, ruleId, comboBox2.SelectedItem.ToString()); //} 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 = sresult.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.Zone zoneDAO = new data.DAO.Configuration.Zone(); zoneDAO.ConnectionString = _connectionString; lfa.pmgmt.data.DTO.Configuration.Zone zoneItem = zoneDAO.Get(unitId); string zoneName = zoneItem.Name; row.Cells[1].Value = "If " + zoneName + " load is " + scomparer + " " + value + " Then"; row.Cells[2].Value = "Switch " + sdeviceOnOff; } dataGridView1.Columns[1].Width = 180; dataGridView1.Columns[2].Width = 150; } }
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; }
private void btnOK_Click(object sender, EventArgs e) { int status = 2; if (string.IsNullOrEmpty(textBox1.Text)) { Exception ex = new Exception("Validation Exception : Please provide a load value!"); HandleException(ex); } else { ComboItem zone = comboBox1.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 = zone.Id + ".1." + comparer + "." + textBox1.Text; string result = zone.Id + ".1." + status.ToString(); lfa.pmgmt.data.DAO.BusinessRule.Rule ruleDAO = new data.DAO.BusinessRule.Rule(); ruleDAO.ConnectionString = _connectionString; ruleDAO.Insert(_ruleId, condition, result); int ruleId = ruleDAO.GetLastInsertedRuleId(); //if (!comboBox2.SelectedItem.ToString().ToLower().Equals("none")) //{ lfa.pmgmt.data.DAO.BusinessRule.RuleSet rulesetDAO = new data.DAO.BusinessRule.RuleSet(); rulesetDAO.ConnectionString = _connectionString; rulesetDAO.InsertPriority(_ruleId, ruleId, comboBox2.SelectedItem.ToString()); //} 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 = sresult.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.Zone zoneDAO = new data.DAO.Configuration.Zone(); zoneDAO.ConnectionString = _connectionString; lfa.pmgmt.data.DTO.Configuration.Zone zoneItem = zoneDAO.Get(unitId); string zoneName = zoneItem.Name; row.Cells[1].Value = "If " + zoneName + " load is " + scomparer + " " + value + " Then"; row.Cells[2].Value = "Switch " + sdeviceOnOff; } dataGridView1.Columns[1].Width = 180; dataGridView1.Columns[2].Width = 150; } }
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; }