public DataObject.Device Get(int Id) { DataObject.Device dataObjectDevice = null; using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); string query = "Exec [Schedule].[GetActiveDevice] {0}"; using (SqlCommand command = new SqlCommand(string.Format(query, Id), connection)) { SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { dataObjectDevice = new DataObject.Device(); dataObjectDevice.Id = int.Parse(reader.GetValue(0).ToString()); dataObjectDevice.Name = reader.GetValue(1).ToString(); dataObjectDevice.DateAdded = Convert.ToDateTime(reader.GetValue(2).ToString()); } } } } return dataObjectDevice; }
public DataObject.Device Get(int Id) { DataObject.Device dataObjectDevice = null; using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); string query = "Exec [Schedule].[GetActiveDevice] {0}"; using (SqlCommand command = new SqlCommand(string.Format(query, Id), connection)) { SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { dataObjectDevice = new DataObject.Device(); dataObjectDevice.Id = int.Parse(reader.GetValue(0).ToString()); dataObjectDevice.Name = reader.GetValue(1).ToString(); dataObjectDevice.DateAdded = Convert.ToDateTime(reader.GetValue(2).ToString()); } } } } return(dataObjectDevice); }
public List <DataObject.Device> ListById(int Id_Unit, int selectedSchedule) { List <DataObject.Device> deviceList = new List <DataObject.Device>(); using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); string query = "Exec [Schedule].[ListActiveDeviceById] {0}, {1}"; using (SqlCommand command = new SqlCommand(string.Format(query, Id_Unit, selectedSchedule), connection)) { SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { DataObject.Device dataObjectDevice = new DataObject.Device(); dataObjectDevice.Id = int.Parse(reader.GetValue(0).ToString()); dataObjectDevice.Name = reader.GetValue(1).ToString(); dataObjectDevice.DateAdded = Convert.ToDateTime(reader.GetValue(2).ToString()); dataObjectDevice.DeviceOn = Convert.ToBoolean(reader.GetValue(3).ToString()); deviceList.Add(dataObjectDevice); } } } } return(deviceList); }
public List <DataObject.Device> ListWithSwitch(int Id_Unit, int selectedSchedule) { List <DataObject.Device> deviceList = new List <DataObject.Device>(); using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); string query = @"DECLARE @ScheduleUnitId int SELECT @ScheduleUnitId = Id FROM [Schedule].[Unit] WHERE Id_Schedule = {1} and Id_Unit = {0} SELECT device.Id, cfdevice.Name, cfdevice.DateAdded,device.DeviceOn, ID_Device, cfdevice.Switch FROM [Schedule].[Device] device INNER JOIN [Configuration].[Device] cfdevice on cfdevice.Id = device.Id_Device WHERE device.Id_ScheduleUnit =@ScheduleUnitId Order By cfdevice.Switch asc" ; using (SqlCommand command = new SqlCommand(string.Format(query, Id_Unit, selectedSchedule), connection)) { SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { DataObject.Device dataObjectDevice = new DataObject.Device(); dataObjectDevice.Id = int.Parse(reader.GetValue(0).ToString()); dataObjectDevice.Name = reader.GetValue(1).ToString(); dataObjectDevice.Switch = reader.GetValue(5).ToString(); dataObjectDevice.DateAdded = Convert.ToDateTime(reader.GetValue(2).ToString()); dataObjectDevice.DeviceOn = Convert.ToBoolean(reader.GetValue(3).ToString()); dataObjectDevice.DeviceId = int.Parse(reader.GetValue(4).ToString()); dataObjectDevice.Switch = reader.GetValue(5).ToString(); deviceList.Add(dataObjectDevice); } } } } return(deviceList); }
public List<DataObject.Device> ListWithSwitch(int Id_Unit, int selectedSchedule) { List<DataObject.Device> deviceList = new List<DataObject.Device>(); using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); string query = @"DECLARE @ScheduleUnitId int SELECT @ScheduleUnitId = Id FROM [Schedule].[Unit] WHERE Id_Schedule = {1} and Id_Unit = {0} SELECT device.Id, cfdevice.Name, cfdevice.DateAdded,device.DeviceOn, ID_Device, cfdevice.Switch FROM [Schedule].[Device] device INNER JOIN [Configuration].[Device] cfdevice on cfdevice.Id = device.Id_Device WHERE device.Id_ScheduleUnit =@ScheduleUnitId Order By cfdevice.Switch asc"; using (SqlCommand command = new SqlCommand(string.Format(query, Id_Unit, selectedSchedule), connection)) { SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { DataObject.Device dataObjectDevice = new DataObject.Device(); dataObjectDevice.Id = int.Parse(reader.GetValue(0).ToString()); dataObjectDevice.Name = reader.GetValue(1).ToString(); dataObjectDevice.Switch = reader.GetValue(5).ToString(); dataObjectDevice.DateAdded = Convert.ToDateTime(reader.GetValue(2).ToString()); dataObjectDevice.DeviceOn = Convert.ToBoolean(reader.GetValue(3).ToString()); dataObjectDevice.DeviceId = int.Parse(reader.GetValue(4).ToString()); dataObjectDevice.Switch = reader.GetValue(5).ToString(); deviceList.Add(dataObjectDevice); } } } } return deviceList; }
public List<DataObject.Device> ListById(int Id_Unit, int selectedSchedule) { List<DataObject.Device> deviceList = new List<DataObject.Device>(); using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); string query = "Exec [Schedule].[ListActiveDeviceById] {0}, {1}"; using (SqlCommand command = new SqlCommand(string.Format(query, Id_Unit, selectedSchedule), connection)) { SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { DataObject.Device dataObjectDevice = new DataObject.Device(); dataObjectDevice.Id = int.Parse(reader.GetValue(0).ToString()); dataObjectDevice.Name = reader.GetValue(1).ToString(); dataObjectDevice.DateAdded = Convert.ToDateTime(reader.GetValue(2).ToString()); dataObjectDevice.DeviceOn = Convert.ToBoolean(reader.GetValue(3).ToString()); deviceList.Add(dataObjectDevice); } } } } return deviceList; }