private void toolStripButton1_Click_1(object sender, EventArgs e) { //создать новую тему tema_add ta = new tema_add(); DialogResult res = ta.ShowDialog(); if (res == DialogResult.Cancel) { return; } string tm = "", cnt = ""; tm = Normalize(ta.tema.Text.Trim()); cnt = Normalize(ta.cont.Text.Trim()); ta.Dispose(); string q = string.Format( "insert into tema_rabota(name, content, predmet_id, vid_rabota_id) " + " values('{0}','{1}',{2},{3})", tm, cnt, predmet_id, vid_rab_id); main.global_command = new SqlCommand(q, main.global_connection); try { main.global_command.ExecuteNonQuery(); } catch (Exception exx) { MessageBox.Show("Невозможно выполнить операцию вследствие сетевой ошибки. Повторите попытку позднее.", "Ошибка операции", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } fill_temas(); q = "select @@identity"; main.global_command = new SqlCommand(q, main.global_connection); SqlDataReader r = main.global_command.ExecuteReader(); r.Read(); new_tema_id = Convert.ToInt32(r[0]); select_by_id(new_tema_id); }
private void toolStripButton2_Click(object sender, EventArgs e) { //редактирование темы int row = 0; if (table.CurrentCell != null) { row = table.CurrentCell.RowIndex; } else { return; } string tm = ""; string cnt = ""; int id = 0; if (!Filtered) { tm = temas.Rows[row][0].ToString(); cnt = temas.Rows[row][1].ToString(); id = Convert.ToInt32(temas.Rows[row][2]); } else { tm = filteredtema[row][0].ToString(); cnt = filteredtema[row][1].ToString(); id = Convert.ToInt32(filteredtema[row][2]); } tema_add ta = new tema_add(); ta.tema.Text = tm; ta.cont.Text = cnt; DialogResult res = ta.ShowDialog(); if (res == DialogResult.Cancel) { return; } tm = Normalize(ta.tema.Text.Trim()); cnt = Normalize(ta.cont.Text.Trim()); string q = string.Format( "update tema_rabota set name = '{0}', content = '{1}', predmet_id = {2}, vid_rabota_id = {3} " + " where id = {4}", tm, cnt, predmet_id, vid_rab_id, id); main.global_command = new SqlCommand(q, main.global_connection); try { main.global_command.ExecuteNonQuery(); } catch (Exception exx) { MessageBox.Show("Невозможно выполнить операцию вследствие сетевой ошибки. Повторите попытку позднее.", "Ошибка операции", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } fill_temas(); if (Filtered) { toolStripTextBox1_KeyUp(sender, new KeyEventArgs(Keys.Enter)); } //select_by_id(id); ta.Dispose(); }