private void button3_Click(object sender, EventArgs e) { competitioons competition = new competitioons(); competition.name = textBox3.Text; competition.start_date = (dateTimePicker1.Value); competition.end_date = (dateTimePicker2.Value); string sqlQuery = ""; SQLiteCommand command = new SQLiteCommand(); int i = 0; sqlQuery = "INSERT INTO competition (name, start_date, end_date)VALUES ('" + competition.name + "','" + competition.start_date.ToString("yyyy-MM-dd") + "','" + competition.end_date.ToString("yyyy-MM-dd") + "');"; command = new SQLiteCommand(sqlQuery, m_dbConn); command.ExecuteNonQuery(); sqlQuery = "SELECT id FROM competition WHERE id=last_insert_rowid();"; command = new SQLiteCommand(sqlQuery, m_dbConn); string id_comp = command.ExecuteScalar().ToString(); foreach (CheckedListBox l1 in tables) { category_halder a = categories[i]; distantion dist = (distantion)a.f.SelectedItem; sqlQuery = "INSERT INTO `smena_info` (title, table_name, id_comp)VALUES ('" + a.a.Text + "','smena" + (i).ToString() + "','" + id_comp + "');"; command = new SQLiteCommand(sqlQuery, m_dbConn); command.ExecuteNonQuery(); sqlQuery = "SELECT id FROM smena_info WHERE id=last_insert_rowid();"; command = new SQLiteCommand(sqlQuery, m_dbConn); string id_smena = command.ExecuteScalar().ToString(); foreach (Object obj in l1.CheckedItems) { table_names archer = (table_names)obj; sqlQuery = "INSERT INTO performance (id_user,id_comp,id_smena) values ('" + archer.id.ToString() + "','" + id_comp + "','" + id_smena + "');"; command = new SQLiteCommand(sqlQuery, m_dbConn); command.ExecuteNonQuery(); sqlQuery = "SELECT id FROM performance WHERE id=last_insert_rowid();"; command = new SQLiteCommand(sqlQuery, m_dbConn); string id_perfomanse = command.ExecuteScalar().ToString(); for (int j = 0; j++ < dist.rounds_col; j++) { sqlQuery = "INSERT INTO `rounds` (id_distantion,id_perf)VALUES ('" + dist.id + "','" + id_perfomanse + "');"; command = new SQLiteCommand(sqlQuery, m_dbConn); command.ExecuteNonQuery(); } } i++; } if (!File.Exists("this_comp.txt")) { File.Create("this_comp.txt").Close();; } sqlQuery = "SELECT id FROM 'competition' order by id desc limit 1"; command = new SQLiteCommand(sqlQuery, m_dbConn); string id = command.ExecuteScalar().ToString(); File.AppendAllText("this_comp.txt", id); }
private void Form1_Load(object sender, EventArgs e) { //checkedComboBox1.Items.Add(12); //checkedComboBox1.Items.Add(18); //checkedComboBox1.Items.Add(30); //checkedComboBox1.Items.Add(40); //checkedComboBox1.Items.Add(50); //checkedComboBox1.Items.Add(60); //checkedComboBox1.Items.Add(70); //checkedComboBox1.Items.Add(90); //checkedComboBox1.Items.Add("M1"); int i5 = 1; foreach (DataGridViewColumn obj in dataGridView3.Columns) { i5++; DataGridViewColumn col = new DataGridViewColumn(); col.Width = obj.Width; col.CellTemplate = new DataGridViewTextBoxCell(); col.HeaderText = obj.HeaderText; col.Name = "col" + i5.ToString(); dataGridView2.Columns.Add(col); } category_halder item = new category_halder(); item.a = textBox2; item.b = comboBox3; item.c = comboBox4; item.f = comboBox1; categories.Add(item); m_sqlCmd = new SQLiteCommand(); dbFileName = "sample.sqlite"; //lbStatusText.Text = "Disconnected"; if (!File.Exists(dbFileName)) { SQLiteConnection.CreateFile(dbFileName); } try { m_dbConn = new SQLiteConnection("Data Source=" + dbFileName + ";Version=3;"); m_dbConn.Open(); } catch (SQLiteException ex) { MessageBox.Show("Error: " + ex.Message); } Form2 example2 = new Form2(); if (!example2.cost) { example2.ShowDialog(); this.Show(); } if (File.Exists("this_comp.txt")) { FileStream file1 = new FileStream("this_comp.txt", FileMode.Open); StreamReader reader = new StreamReader(file1); string id = (reader.ReadToEnd()); reader.Close(); if (id != "") { splitContainer2.Enabled = false; } else { string sqlQuery = "select * from distantions"; SQLiteCommand command = new SQLiteCommand(sqlQuery, m_dbConn); SQLiteDataReader dist = command.ExecuteReader(); while (dist.Read()) { distantion categ = new distantion(); categ.id = dist["id"].ToString(); categ.name = dist["title"].ToString(); categ.rounds_col = Convert.ToInt32(dist["rounds_col"]); comboBox1.ValueMember = "id"; comboBox1.DisplayMember = "name"; comboBox1.Items.Add(categ); } comboBox1.ValueMember = "id"; comboBox1.DisplayMember = "name"; comboBox1.SelectedItem = comboBox3.Items[0]; } } competition_list(); }