private void Delbutton_Click(object sender, EventArgs e) { if (MessageBox.Show("Удалить?", "Внимание", MessageBoxButtons.YesNo) == DialogResult.Yes) { //throw new NotImplementedException(); try { connection.Open(); } catch { MessageBox.Show("Нет соединения"); Close(); return; } try { Checkcommand.Parameters["@cod"].Value = dataGridView1.CurrentRow.Cells[table_key.Trim()].Value.ToString(); if (int.Parse(Checkcommand.ExecuteScalar().ToString()) > 0) { MessageBox.Show("Удаление не возможно. Присутствуют записи с данным сотрудником."); connection.Close(); return; } } catch (Exception ex) { MessageBox.Show(ex.Message); Close(); connection.Close(); return; } connection.Close(); try { connection.Open(); } catch { MessageBox.Show("Нет соединения"); Close(); return; } try { Deletecommand.Parameters["@cod"].Value = dataGridView1.CurrentRow.Cells[table_key.Trim()].Value.ToString(); Deletecommand.ExecuteNonQuery(); dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index); } catch (Exception ex) { MessageBox.Show(ex.Message); Close(); connection.Close(); return; } connection.Close(); buttons(); } }
private void Delbutton_Click(object sender, EventArgs e) { if (MessageBox.Show("Удалить?", "Внимание", MessageBoxButtons.YesNo) == DialogResult.Yes) { //throw new NotImplementedException(); try { connection.Open(); } catch { MessageBox.Show("Нет соединения"); Close(); return; } try { Checkcommand.Parameters["@cod"].Value = ((ListItem)listBox1.SelectedItem).Cod.ToString(); if (int.Parse(Checkcommand.ExecuteScalar().ToString()) > 0) { MessageBox.Show("Удаление не возможно. Присутствуют записи с данным жанром."); connection.Close(); return; } } catch (Exception ex) { MessageBox.Show(ex.Message); Close(); connection.Close(); return; } connection.Close(); try { connection.Open(); } catch { MessageBox.Show("Нет соединения"); Close(); return; } try { Deletecommand.Parameters["@cod"].Value = ((ListItem)listBox1.SelectedItem).Cod.ToString(); Deletecommand.ExecuteNonQuery(); listBox1.Items.RemoveAt(listBox1.SelectedIndex); } catch (Exception ex) { MessageBox.Show(ex.Message); Close(); connection.Close(); return; } connection.Close(); buttons(); } }
private void Savebutton_Click(object sender, EventArgs e) { if (textBox1.Text.Trim() == "") { MessageBox.Show("Не введено наименование исполнителя"); return; } try { connection.Open(); } catch { MessageBox.Show("Нет соединения"); Close(); return; } try { if (is_insert || (!is_insert && originalName != textBox1.Text.Trim())) { Checkcommand.Parameters["@naim"].Value = textBox1.Text.Trim(); if (int.Parse(Checkcommand.ExecuteScalar().ToString()) > 0) { MessageBox.Show("Исполнитель с таким наименованием уже присутствует"); connection.Close(); return; } } } catch (Exception ex) { MessageBox.Show(ex.Message); Close(); connection.Close(); return; } connection.Close(); try { connection.Open(); } catch { MessageBox.Show("Нет соединения"); Close(); return; } if (is_insert) { try { Insertcommand.Parameters["@naim"].Value = textBox1.Text.Trim(); Insertcommand.ExecuteNonQuery(); listBox.Items.Add(new ListItem() { Cod = Getidentitycommand.ExecuteScalar(), Value = textBox1.Text.Trim() }); } catch (Exception ex) { MessageBox.Show(ex.Message); Close(); connection.Close(); return; } } else { try { Updatecommand.Parameters["@cod"].Value = listItem.Cod.ToString(); Updatecommand.Parameters["@naim"].Value = textBox1.Text.Trim(); Updatecommand.ExecuteNonQuery(); listBox.Items[listBox.SelectedIndex] = new ListItem() { Cod = listItem.Cod.ToString(), Value = textBox1.Text.Trim() }; } catch (Exception ex) { MessageBox.Show(ex.Message); Close(); connection.Close(); return; } } connection.Close(); Close(); }
private void Savebutton_Click(object sender, EventArgs e) { if (textBox1.Text.Trim() == "") { MessageBox.Show("Не введено наименование записи"); return; } try { connection.Open(); } catch { MessageBox.Show("Нет соединения"); Close(); return; } try { if (is_insert || (origDate != dateTimePicker1.Value || keys[0] != int.Parse(Ispcombo.SelectedValue.ToString()) || keys[1] != int.Parse(Janrcombo.SelectedValue.ToString()) || keys[2] != int.Parse(Sotrcombo.SelectedValue.ToString()) || textBox1.Text.Trim() != origstr)) { Checkcommand.Parameters["@cod_isp"].Value = Ispcombo.SelectedValue.ToString(); Checkcommand.Parameters["@cod_janr"].Value = Janrcombo.SelectedValue.ToString(); Checkcommand.Parameters["@cod_sotr"].Value = Sotrcombo.SelectedValue.ToString(); Checkcommand.Parameters["@data"].Value = dateTimePicker1.Value.ToShortDateString(); Checkcommand.Parameters["@naim_zapis"].Value = textBox1.Text.Trim(); if (int.Parse(Checkcommand.ExecuteScalar().ToString()) > 0) { MessageBox.Show("Такая запись уже присутствует"); connection.Close(); return; } } } catch (Exception ex) { MessageBox.Show(ex.Message); Close(); connection.Close(); return; } connection.Close(); try { connection.Open(); } catch { MessageBox.Show("Нет соединения"); Close(); return; } if (is_insert) { try { Insertcommand.Parameters["@cod_isp"].Value = Ispcombo.SelectedValue.ToString(); Insertcommand.Parameters["@cod_janr"].Value = Janrcombo.SelectedValue.ToString(); Insertcommand.Parameters["@cod_sotr"].Value = Sotrcombo.SelectedValue.ToString(); Insertcommand.Parameters["@data"].Value = dateTimePicker1.Value.ToShortDateString(); Insertcommand.Parameters["@naim_zapis"].Value = textBox1.Text.Trim(); Insertcommand.ExecuteNonQuery(); dataGridView.Rows.Add(Insertcommand.Parameters["@cod"].Value.ToString(), textBox1.Text.Trim(), dateTimePicker1.Value.ToShortDateString(), Ispcombo.SelectedValue.ToString(), Janrcombo.SelectedValue.ToString(), Sotrcombo.SelectedValue.ToString(), ((ListItem)Ispcombo.SelectedItem).Value.ToString(), ((ListItem)Janrcombo.SelectedItem).Value.ToString(), ((ListItem)Sotrcombo.SelectedItem).Value.ToString()); dataGridView.CurrentCell = dataGridView.Rows[dataGridView.Rows.Count - 1].Cells["data"]; } catch (Exception ex) { MessageBox.Show(ex.Message); Close(); connection.Close(); return; } } else { try { Updatecommand.Parameters["@cod_isp"].Value = Ispcombo.SelectedValue.ToString(); Updatecommand.Parameters["@cod_janr"].Value = Janrcombo.SelectedValue.ToString(); Updatecommand.Parameters["@cod_sotr"].Value = Sotrcombo.SelectedValue.ToString(); Updatecommand.Parameters["@cod"].Value = keys[3].ToString().Clone(); Updatecommand.Parameters["@data"].Value = dateTimePicker1.Value.ToShortDateString(); Updatecommand.Parameters["@naim_zapis"].Value = textBox1.Text.Trim(); Updatecommand.ExecuteNonQuery(); dataGridView.CurrentRow.Cells["naim_zapis"].Value = textBox1.Text.Trim(); dataGridView.CurrentRow.Cells["data"].Value = dateTimePicker1.Value.ToShortDateString(); dataGridView.CurrentRow.Cells["cod_isp"].Value = Ispcombo.SelectedValue.ToString(); dataGridView.CurrentRow.Cells["cod_janr"].Value = Janrcombo.SelectedValue.ToString(); dataGridView.CurrentRow.Cells["cod_sotr"].Value = Sotrcombo.SelectedValue.ToString(); dataGridView.CurrentRow.Cells["Isp"].Value = ((ListItem)Ispcombo.SelectedItem).Value.ToString(); dataGridView.CurrentRow.Cells["Janr"].Value = ((ListItem)Janrcombo.SelectedItem).Value.ToString(); dataGridView.CurrentRow.Cells["Sotr"].Value = ((ListItem)Sotrcombo.SelectedItem).Value.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); Close(); connection.Close(); return; } } connection.Close(); Close(); }
private void Savebutton_Click(object sender, EventArgs e) { if (FamBox.Text.Trim() == "") { MessageBox.Show("Не введена фамилия сотрудника"); return; } if (ImBox.Text.Trim() == "") { MessageBox.Show("Не введено имя сотрудника"); return; } try { connection.Open(); } catch { MessageBox.Show("Нет соединения"); Close(); return; } try { if (is_insert || (Famoriginal != FamBox.Text.Trim() || Imoriginal != ImBox.Text.Trim() || Otchoriginal != OtchBox.Text.Trim() || Droriginal != dateTimePicker1.Value || comboBox1.SelectedItem.ToString()[0] != Poloriginal)) { Checkcommand.Parameters["@fam"].Value = FamBox.Text.Trim(); Checkcommand.Parameters["@im"].Value = ImBox.Text.Trim(); Checkcommand.Parameters["@otch"].Value = OtchBox.Text.Trim(); Checkcommand.Parameters["@dr"].Value = dateTimePicker1.Value.ToShortDateString(); Checkcommand.Parameters["@pol"].Value = comboBox1.SelectedItem.ToString()[0]; if (int.Parse(Checkcommand.ExecuteScalar().ToString()) > 0) { MessageBox.Show("Сотрудник с такими данными уже существует"); connection.Close(); return; } } } catch (Exception ex) { MessageBox.Show(ex.Message); Close(); connection.Close(); return; } connection.Close(); try { connection.Open(); } catch { MessageBox.Show("Нет соединения"); Close(); return; } if (is_insert) { try { Insertcommand.Parameters["@fam"].Value = FamBox.Text.Trim(); Insertcommand.Parameters["@im"].Value = ImBox.Text.Trim(); Insertcommand.Parameters["@otch"].Value = OtchBox.Text.Trim(); Insertcommand.Parameters["@dr"].Value = dateTimePicker1.Value.ToShortDateString(); Insertcommand.Parameters["@pol"].Value = comboBox1.SelectedItem.ToString()[0]; Insertcommand.ExecuteNonQuery(); dataGridView.Rows.Add(Getidentitycommand.ExecuteScalar(), FamBox.Text.Trim(), ImBox.Text.Trim(), OtchBox.Text.Trim(), dateTimePicker1.Value, comboBox1.SelectedItem.ToString()[0]); } catch (Exception ex) { MessageBox.Show(ex.Message); Close(); connection.Close(); return; } } else { try { Updatecommand.Parameters["@cod"].Value = dataGridView.CurrentRow.Cells[table_key.Trim()].Value.ToString(); Updatecommand.Parameters["@fam"].Value = FamBox.Text.Trim(); Updatecommand.Parameters["@im"].Value = ImBox.Text.Trim(); Updatecommand.Parameters["@otch"].Value = OtchBox.Text.Trim(); Updatecommand.Parameters["@dr"].Value = dateTimePicker1.Value.ToShortDateString(); Updatecommand.Parameters["@pol"].Value = comboBox1.SelectedItem.ToString()[0]; Updatecommand.ExecuteNonQuery(); dataGridView.CurrentRow.Cells["fam"].Value = FamBox.Text.Trim(); dataGridView.CurrentRow.Cells["im"].Value = ImBox.Text.Trim(); dataGridView.CurrentRow.Cells["otch"].Value = OtchBox.Text.Trim(); dataGridView.CurrentRow.Cells["dr"].Value = dateTimePicker1.Value; dataGridView.CurrentRow.Cells["pol"].Value = comboBox1.SelectedItem.ToString()[0]; } catch (Exception ex) { MessageBox.Show(ex.Message); Close(); connection.Close(); return; } } connection.Close(); Close(); }