private void openFileDialog4_FileOk(object sender, CancelEventArgs e) { if (listBox3.Items.Count == listBox1.Items.Count) { return; } SQLiteConnection cn = new SQLiteConnection(@"Data Source=" + Var.pp + @"\post.db;Version=3;"); SQLiteCommand cmd = new SQLiteCommand(cn); cn.Open(); if (!TableExists("EQH", cn)) { cmd.CommandText = "begin"; cmd.ExecuteNonQuery(); cmd.CommandText = @"create table EQH ([id] integer NOT NULL PRIMARY KEY, [txt_deltaT] double null, [txt_file_name] Text null, [txt_lines_to_skip] int null, [txt_points_per_line] int null, [txt_prefix] int null, [txt_text] Text null, [rdb_values] int null, [order_id] int null)"; cmd.ExecuteNonQuery(); cmd.CommandText = "end"; cmd.ExecuteNonQuery(); } if (!TableExists("EQV", cn)) { cmd.CommandText = "begin"; cmd.ExecuteNonQuery(); cmd.CommandText = @"create table EQV ([id] integer NOT NULL PRIMARY KEY, [txt_deltaT] double null, [txt_file_name] Text null, [txt_lines_to_skip] int null, [txt_points_per_line] int null, [txt_prefix] int null, [txt_text] Text null, [rdb_values] int null, [order_id] int null)"; cmd.ExecuteNonQuery(); cmd.CommandText = "end"; cmd.ExecuteNonQuery(); } if (listBox3.Items.Count == 0) { cmd.CommandText = "begin"; cmd.ExecuteNonQuery(); cmd.CommandText = "DELETE FROM EQV;"; // always create EQH and cmd.ExecuteNonQuery(); cmd.CommandText = "end"; cmd.ExecuteNonQuery(); } for (int i = 0; i < openFileDialog4.SafeFileNames.Length && listBox3.Items.Count < listBox1.Items.Count; i++) { WaveFile wav = new WaveFile(openFileDialog4.FileNames[i]); cmd.CommandText = "begin"; cmd.ExecuteNonQuery(); listBox3.Items.Add(wav); cmd.CommandText = "insert into EQV (txt_file_name,txt_deltaT,txt_lines_to_skip,txt_points_per_line,txt_prefix,rdb_values,txt_text,order_id) values('" + wav.File_Name + "'," + wav.deltaT + "," + wav.Header_Lines + "," + wav.Points_Per_Line + " ," + wav.Prefix_Per_Line + "," + (wav.isTimeAndValues ? 1 : 0) + ",'" + wav.Text + "'," + listBox1.Items.Count + ")"; cmd.ExecuteNonQuery(); cmd.CommandText = "end"; cmd.ExecuteNonQuery(); } while (listBox3.Items.Count < listBox1.Items.Count) { MessageBox.Show("Please add more veritical components files"); OpenFileDialog ofg = new OpenFileDialog(); if (ofg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { for (int i = 0; i < ofg.FileNames.Length && listBox3.Items.Count < listBox1.Items.Count; i++) { WaveFile wav = new WaveFile(ofg.FileNames[i]); cmd.CommandText = "begin"; cmd.ExecuteNonQuery(); listBox3.Items.Add(wav); cmd.CommandText = "insert into EQV (txt_file_name,txt_deltaT,txt_lines_to_skip,txt_points_per_line,txt_prefix,rdb_values,txt_text,order_id) values('" + wav.File_Name + "'," + wav.deltaT + "," + wav.Header_Lines + "," + wav.Points_Per_Line + " ," + wav.Prefix_Per_Line + "," + (wav.isTimeAndValues ? 1 : 0) + ",'" + wav.Text + "'," + listBox1.Items.Count + ")"; cmd.ExecuteNonQuery(); cmd.CommandText = "end"; cmd.ExecuteNonQuery(); } } } cn.Close(); //WHFILE_t = System.IO.File.ReadAllText(openFileDialog3.FileName); }
public void populateEarhQuicksFile() { listBox1.Items.Clear(); listBox3.Items.Clear(); SQLiteConnection cn = new SQLiteConnection(@"Data Source=" + Var.pp + @"\post.db;Version=3;"); SQLiteCommand cmd = new SQLiteCommand(cn); cn.Open(); if (!TableExists("EQH", cn)) { cn.Close(); return; } if (!TableExists("EQV", cn)) { cn.Close(); return; } string sql1 = "SELECT * FROM EQH order by order_id;"; string sql2 = "SELECT * FROM EQV order by order_id;"; // cmd.CommandText = "insert into EQH (txt_file_name,txt_deltaT,txt_lines_to_skip,txt_points_per_line,txt_prefix,rdb_values,txt_text) values('" + wav.File_Name + "'," + wav.deltaT + "," + wav.Header_Lines + "," + wav.Points_Per_Line + " ," + wav.Prefix_Per_Line + "," + (wav.isTimeAndValues ? 1 : 0) + ",'" + wav.Text + "')"; cmd.CommandText = "begin"; cmd.ExecuteNonQuery(); cmd.CommandText = sql1; SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { WaveFile wave = new WaveFile(); wave.File_Name = reader.GetString(reader.GetOrdinal("txt_file_name")); wave.deltaT = reader.GetDouble(reader.GetOrdinal("txt_deltaT")); wave.Header_Lines = reader.GetInt32(reader.GetOrdinal("txt_lines_to_skip")); wave.isTimeAndValues = reader.GetInt32(reader.GetOrdinal("rdb_values")) != 1; wave.Points_Per_Line = reader.GetInt32(reader.GetOrdinal("txt_points_per_line")); wave.Prefix_Per_Line = reader.GetInt32(reader.GetOrdinal("txt_prefix")); wave.Text = reader.GetString(reader.GetOrdinal("txt_text")); listBox1.Items.Add(wave); } reader.Close(); cmd.CommandText = "end"; cmd.ExecuteNonQuery(); // reader.Close(); cn.Close(); cn = new SQLiteConnection(@"Data Source=" + Var.pp + @"\post.db;Version=3;"); cmd = new SQLiteCommand(cn); cn.Open(); cmd.CommandText = "begin"; cmd.ExecuteNonQuery(); cmd.CommandText = sql2; reader = cmd.ExecuteReader(); while (reader.Read()) { WaveFile wave = new WaveFile(); wave.File_Name = reader.GetString(reader.GetOrdinal("txt_file_name")); wave.deltaT = reader.GetDouble(reader.GetOrdinal("txt_deltaT")); wave.Header_Lines = reader.GetInt32(reader.GetOrdinal("txt_lines_to_skip")); wave.isTimeAndValues = !reader.GetBoolean(reader.GetOrdinal("rdb_values")); wave.Points_Per_Line = reader.GetInt32(reader.GetOrdinal("txt_points_per_line")); wave.Prefix_Per_Line = reader.GetInt32(reader.GetOrdinal("txt_prefix")); wave.Text = reader.GetString(reader.GetOrdinal("txt_text")); listBox3.Items.Add(wave); } reader.Close(); cmd.CommandText = "end"; cmd.ExecuteNonQuery(); // reader.Close(); cn.Close(); }
private void openFileDialog3_FileOk(object sender, CancelEventArgs e) { SQLiteConnection cn = new SQLiteConnection(@"Data Source=" + Var.pp + @"\post.db;Version=3;"); SQLiteCommand cmd = new SQLiteCommand(cn); cn.Open(); if (!TableExists("EQH", cn)) { cmd.CommandText = "begin"; cmd.ExecuteNonQuery(); cmd.CommandText = @"create table EQH ([id] integer NOT NULL PRIMARY KEY, [txt_deltaT] double null, [txt_file_name] Text null, [txt_lines_to_skip] int null, [txt_points_per_line] int null, [txt_prefix] int null, [txt_text] Text null, [rdb_values] int null, [order_id] int null)"; cmd.ExecuteNonQuery(); cmd.CommandText = "end"; cmd.ExecuteNonQuery(); } if (!TableExists("EQV", cn)) { cmd.CommandText = "begin"; cmd.ExecuteNonQuery(); cmd.CommandText = @"create table EQV ([id] integer NOT NULL PRIMARY KEY, [txt_deltaT] double null, [txt_file_name] Text null, [txt_lines_to_skip] int null, [txt_points_per_line] int null, [txt_prefix] int null, [txt_text] Text null, [rdb_values] int null, [order_id] int null)"; cmd.ExecuteNonQuery(); cmd.CommandText = "end"; cmd.ExecuteNonQuery(); } if (listBox1.Items.Count == 0) { cmd.CommandText = "begin"; cmd.ExecuteNonQuery(); cmd.CommandText = "DELETE FROM EQH;"; // always create EQH and cmd.ExecuteNonQuery(); cmd.CommandText = "end"; cmd.ExecuteNonQuery(); } for (int i = 0; i < openFileDialog3.SafeFileNames.Length; i++) { WaveFile wav = new WaveFile(openFileDialog3.FileNames[i]); cmd.CommandText = "begin"; cmd.ExecuteNonQuery(); listBox1.Items.Add(wav); cmd.CommandText = "insert into EQH (txt_file_name,txt_deltaT,txt_lines_to_skip,txt_points_per_line,txt_prefix,rdb_values,txt_text,order_id) values('" + wav.File_Name + "'," + wav.deltaT + "," + wav.Header_Lines + "," + wav.Points_Per_Line + " ," + wav.Prefix_Per_Line + "," + (wav.isTimeAndValues ? 1 : 0) + ",'" + wav.Text + "'," + listBox1.Items.Count + ")"; cmd.ExecuteNonQuery(); cmd.CommandText = "end"; cmd.ExecuteNonQuery(); //if (checkboxYN1.Checked == false) //{ // listBox3.Items.Add("None"); //} } cn.Close(); if (checkboxYN1.Checked) { // openFileDialog4.ShowDialog(); } //WHFILE_t = System.IO.File.ReadAllText(openFileDialog3.FileName); }