private void tabControl1_Update() { int i = tabControl1.SelectedIndex; DataGridView dgrv = null; main_form = this.Owner as MainApp; if (main_form != null) { string my_select; switch (i) { case 0: my_select = "SELECT * FROM resources"; dgrv = dataGridView_resources; break; case 1: my_select = "SELECT * FROM results"; dgrv = dataGridView_results; break; case 2: my_select = "SELECT * FROM tests"; dgrv = dataGridView_tests; break; default: return; } using (main_form.mysqlAdapter = new MySqlDataAdapter(my_select, main_form.conn)) using (DataTable dtbl = new DataTable()) { main_form.mysqlAdapter.Fill(dtbl); dgrv.DataSource = dtbl; } } }
private async void result_delete_record_button_Click(object sender, EventArgs e) { // TBD не работает, дает 0 //int row = dataGridView_resources.SelectedCells[0].RowIndex; //номер строки, где отмечен cell main_form = this.Owner as MainApp; if (id_results_textbox.Text != "") { string delete_result_command = "DELETE FROM results WHERE id = @id;"; using (MySqlCommand mysqlcommand = new MySqlCommand(delete_result_command, main_form.conn)) { mysqlcommand.Parameters.AddWithValue("id", id_results_textbox.Text); await mysqlcommand.ExecuteNonQueryAsync(); } } dataGridView_results.Update(); dataGridView_results.Refresh(); tabControl1_Update(); //TBD пометить строчку, рядом с той, которую удалили //dataGridView_results.CurrentCell = dataGridView_results.Rows[row - 1].Cells[0]; }
private async void tests_update_record_button_Click(object sender, EventArgs e) { main_form = this.Owner as MainApp; if (id_tests_textbox.Text != "") { string update_command = "UPDATE tests SET description=@description, test_name=@test_name,test_script=@test_script WHERE id = @id;"; string test_name = name_tests_textbox.Text; string test_script = script_tests_textbox.Text; string description = description_tests_textbox.Text; using (MySqlCommand mysqlcommand = new MySqlCommand(update_command, main_form.conn)) { mysqlcommand.Parameters.AddWithValue("id", id_tests_textbox.Text); mysqlcommand.Parameters.AddWithValue("description", description); mysqlcommand.Parameters.AddWithValue("test_name", test_name); mysqlcommand.Parameters.AddWithValue("test_script", test_script); await mysqlcommand.ExecuteNonQueryAsync(); } } dataGridView_tests.Update(); dataGridView_tests.Refresh(); tabControl1_Update(); }