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); } }
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); } }