Beispiel #1
0
        static void ExportSqlite2Csv(AcquisitionConfig config)
        {
            string       fileName     = config.id + "-" + config.type + ".csv";
            string       sqlStatement = "select Stamp,Value from " + config.table + " where SensorId='" + config.id + "' and Type='" + config.type + "' order by Stamp asc";
            StreamWriter sw           = new StreamWriter(fileName, true); //true表示如果a.txt文件已存在,则以追加的方式写入

            SQLiteConnection conn = null;

            int i = 0;

            try
            {
                conn = new SQLiteConnection(config.connectionString);
                conn.Open();
                SQLiteCommand    command = new SQLiteCommand(sqlStatement, conn);
                SQLiteDataReader reader  = command.ExecuteReader();

                while (reader.Read())
                {
                    string stamp = reader.GetString(0);
                    string value = reader.GetFloat(1).ToString();

                    string record = stamp + "," + value;
                    sw.WriteLine(record);
                }
                conn.Close();
                sw.Close();
            }
            catch (Exception ex)
            {
                sw.Close();
                conn.Close();
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #2
0
        static void ExportSqlServer2Csv(AcquisitionConfig config)
        {
            string fileName = config.id + "-" + config.type + ".csv";
            //string connectionString = "Data Source = " + textBoxIP.Text + ";Network Library = DBMSSOCN;Initial Catalog = " + textBoxDatabase.Text + ";User ID = " + textBoxUser.Text + ";Password = "******"Data Source = 192.168.100.153;Network Library = DBMSSOCN;Initial Catalog = BridgeMonitoring;User ID = bridge_user;Password = 123456";
            string       sqlStatement = "select Stamp,Value from " + config.table + " where SensorId='" + config.id + "' and Type='" + config.type + "' order by Stamp asc";
            StreamWriter sw           = new StreamWriter(fileName, true); //true表示如果a.txt文件已存在,则以追加的方式写入

            using (SqlConnection connection = new SqlConnection(config.connectionString))
            {
                connection.Open();

                SqlCommand command = new SqlCommand(sqlStatement, connection);
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string stamp  = reader.GetDateTime(0).ToString();
                        string value  = reader.GetDouble(1).ToString();
                        string record = stamp + "," + value;
                        sw.WriteLine(record);
                    }
                    reader.Close();
                }
                connection.Close();
            }
        }
Beispiel #3
0
        static void Initialize(List <AcquisitionConfig> list, string configName)
        {
            StreamReader sr = new StreamReader(configName, Encoding.UTF8);
            string       line;
            string       connectionString = "";
            int          i = 0;

            char[] chs = { ',' };
            while ((line = sr.ReadLine()) != null)
            {
                if (i == 0)
                {
                    connectionString = line;
                    i++;
                }
                else
                {
                    string[]          items  = line.Split(chs);
                    AcquisitionConfig config = new AcquisitionConfig(items[0], items[1], items[2], connectionString);
                    list.Add(config);
                }
            }
            sr.Close();
        }