/// <summary> /// Gets all blocks from a specified switchboard panel. /// </summary> /// <returns>The requested list of <see cref="BlockBase"/>.</returns> public List <SensorModule> GetAll() { string sql = string.Empty; SensorModule item = null; List <SensorModule> items = new List <SensorModule>(); Logger.LogDebug(this, "[CLASS].GetAll()"); try { Connect(); sql = @"SELECT " + SensorModuleManager.SQL_FIELDS_SELECT + @" FROM " + SensorModuleManager.SQL_TABLE + @" ORDER BY name Asc"; using (SQLiteDataReader reader = ExecuteReader(sql)) { while (reader.Read()) { item = SensorModuleManager.ReadEntityRecord(reader); if (item != null) { items.Add(item); } } } return(items); } catch (Exception ex) { Logger.LogError(this, ex); throw; } finally { Disconnect(); } }
/// <summary> /// Gets a module by its unique identifier. /// </summary> /// <param name="itemId">Module unique identifier (DB).</param> /// <returns>The requested instance of <see cref="SensorModule"/> or <c>null</c> if the module cannot be found.</returns> public SensorModule GetByID(Int64 itemId) { string sql = string.Empty; Logger.LogDebug(this, "[CLASS].GetByID({0})", itemId); try { Connect(); sql = @"SELECT " + SensorModuleManager.SQL_FIELDS_SELECT + @" FROM " + SensorModuleManager.SQL_TABLE + @" WHERE id = @id"; SetParameter("id", itemId); using (SQLiteDataReader reader = ExecuteReader(sql)) { if (reader.Read()) { return(SensorModuleManager.ReadEntityRecord(reader)); } } return(null); } catch (Exception ex) { Logger.LogError(this, ex); throw; } finally { Disconnect(); } }