/// <summary> /// Get all decoders information in an instance of <see cref="DataTable"/>. /// </summary> /// <returns>An instance of <see cref="DataTable"/> filled with the requested data.</returns> public List <ControlModule> GetByType(ControlModule.ModuleType type) { string sql = string.Empty; ControlModule item = null; List <ControlModule> items = new List <ControlModule>(); Logger.LogDebug(this, "[CLASS].GetByType({0})", type); try { Connect(); sql = @"SELECT " + ControlModuleManager.SQL_FIELDS_SELECT + @" FROM " + ControlModuleManager.SQL_TABLE + @" WHERE type = @type ORDER BY name Asc"; SetParameter("type", (int)type); using (SQLiteDataReader reader = ExecuteReader(sql)) { while (reader.Read()) { item = ControlModuleManager.ReadEntityRecord(reader); if (item != null) { items.Add(item); } } } return(items); } catch (Exception ex) { Logger.LogError(this, ex); throw; } finally { Disconnect(); } }
/// <summary> /// Gets a control module by its identifier. /// </summary> /// <param name="id">Control module unique identifier (DB).</param> /// <returns>The requested instance of <see cref="ControlModule"/> or <c>null</c> if the module cannot be found.</returns> public ControlModule GetByID(Int64 id) { string sql = string.Empty; Logger.LogDebug(this, "[CLASS].GetByID({0})", id); try { Connect(); sql = @"SELECT " + ControlModuleManager.SQL_FIELDS_SELECT + @" FROM " + ControlModuleManager.SQL_TABLE + @" WHERE id = @id"; SetParameter("id", id); using (SQLiteDataReader reader = ExecuteReader(sql)) { if (reader.Read()) { return(ControlModuleManager.ReadEntityRecord(reader)); } } return(null); } catch (Exception ex) { Logger.LogError(this, ex); throw; } finally { Disconnect(); } }
/// <summary> /// Gets all blocks from a specified switchboard panel. /// </summary> /// <param name="decoderId">The switchboard panel unique identifier (DB).</param> /// <returns>The requested list of <see cref="ElementBase"/>.</returns> public List <ControlModuleConnection> GetByDecoder(int decoderId) { string sql = string.Empty; ControlModule module = null; ControlModuleConnection item = null; List <ControlModuleConnection> items = new List <ControlModuleConnection>(); Logger.LogDebug(this, "[CLASS].GetByDecoder({0})", decoderId); try { Connect(); sql = @"SELECT " + ControlModuleManager.SQL_FIELDS_SELECT + @" FROM " + ControlModuleManager.SQL_TABLE + @" WHERE id = @id"; SetParameter("id", decoderId); using (SQLiteDataReader reader = ExecuteReader(sql)) { if (reader.Read()) { module = ControlModuleManager.ReadEntityRecord(reader); } } if (module == null) { return(items); } sql = @"SELECT " + ControlModuleConnectionManager.SQL_FIELDS_SELECT + @" FROM " + ControlModuleConnectionManager.SQL_TABLE + @" WHERE decoderid = @decoderid ORDER BY name"; SetParameter("decoderid", decoderId); using (SQLiteDataReader reader = ExecuteReader(sql)) { while (reader.Read()) { item = ControlModuleConnectionManager.ReadEntityRecord(reader); if (item != null) { items.Add(item); } } } return(items); } catch (Exception ex) { Logger.LogError(this, ex); throw; } finally { Disconnect(); } }