private void LoadChannels() { using (SQLiteConnection connection = new SQLiteConnection("Data Source = config.db")) { connection.Open(); List <int> periods = new List <int>(); string strainStatement = "SELECT DISTINCT period from DataStoreConfig"; SQLiteCommand command1 = new SQLiteCommand(strainStatement, connection); using (SQLiteDataReader reader1 = command1.ExecuteReader()) { while (reader1.Read()) { int period = reader1.GetInt32(0); periods.Add(period); } } foreach (int period in periods) { List <string> keys = new List <string>(); strainStatement = "select Key from DataStoreConfig where Period =" + period; command1 = new SQLiteCommand(strainStatement, connection); using (SQLiteDataReader reader1 = command1.ExecuteReader()) { while (reader1.Read()) { string key = reader1.GetString(0); keys.Add(key); //string desc = reader1.GetString(2); } } SimpleStore ss = new SimpleStore(keys, period, redis, this.redisDbIndex, dataQueue, textBoxLog); dataStoreCollection.Add(ss); } strainStatement = "select ip,user,password,database,tableName from dbconfig"; SQLiteCommand command2 = new SQLiteCommand(strainStatement, connection); using (SQLiteDataReader reader2 = command2.ExecuteReader()) { while (reader2.Read()) { //string groupId = reader.GetString(0); databaseIp = reader2.GetString(0); databaseUser = reader2.GetString(1); databasePwd = reader2.GetString(2); databaseName = reader2.GetString(3); databaseTable = reader2.GetString(4); } } connection.Close(); } }
private void LoadChannelsSQL() { string connectionString = "Data Source = " + databaseIp + ";Network Library = DBMSSOCN;Initial Catalog = " + databaseName + ";User ID = " + databaseUser + ";Password = "******"SELECT DISTINCT period from DataStoreConfig"; SqlCommand command1 = new SqlCommand(strainStatement, connection); using (SqlDataReader reader1 = command1.ExecuteReader()) { while (reader1.Read()) { int period = reader1.GetInt32(0); periods.Add(period); } } foreach (int period in periods) { List <string> keys = new List <string>(); strainStatement = "select RedisKey,Period,Description from DataStoreConfig where Period =" + period + " order by RedisKey"; command1 = new SqlCommand(strainStatement, connection); using (SqlDataReader reader1 = command1.ExecuteReader()) { while (reader1.Read()) { string key = reader1.GetString(0); int p = reader1.GetInt32(1); Object desc = reader1.GetValue(2); keys.Add(key); string[] viewItem = { key, p.ToString(), desc.ToString() }; ListViewItem listItem = new ListViewItem(viewItem); this.listView1.Items.Add(listItem); } } SimpleStore ss = new SimpleStore(keys, period, redis, this.redisDbIndex, dataQueue, textBoxLog); dataStoreCollection.Add(ss); } connection.Close(); } }