/// <summary> /// Retorna uma lista contendo todos os dispositivos cadastrados /// </summary> public static List <Device> GetAllDevices(string connectionString) { List <Device> devices = new List <Device>(); Device temp; using (var conn = new MySqlConnection(connectionString)) { using (var cmd = conn.CreateCommand()) { try { conn.Open(); cmd.CommandText = "SELECT * FROM devices"; using (MySqlDataReader dataReader = cmd.ExecuteReader()) { while (dataReader.Read()) { temp = Maper.MapDevice(dataReader); devices.Add(temp); } } return(devices); } catch (Exception e) { throw e; } } } }
/// <summary> /// Retorna um dispositivo que corresponde o UID informado /// </summary> public static Device GetDeviceByUid(string connectionString, string uid) { Device device; using (var conn = new MySqlConnection(connectionString)) { using (var cmd = conn.CreateCommand()) { try { conn.Open(); cmd.CommandText = "SELECT * FROM devices WHERE device_id = '" + uid + "'"; using (MySqlDataReader dataReader = cmd.ExecuteReader()) { dataReader.Read(); device = Maper.MapDevice(dataReader); } return(device); } catch (MySqlException e) { throw e; } } } }