private void bCreate_Click(object sender, EventArgs e) { try { using (New_train frm = new New_train()) { if (frm.ShowDialog() == DialogResult.OK) { string types; if (Convert.ToString(frm.comboBox1.Text) != "") { types = Convert.ToString(frm.comboBox1.Text); } else { types = Convert.ToString(frm.comboBox1.SelectedItem); } if (db.newTrain(frm.tNumberTrain.Text, types) == null) { MessageBox.Show("Ошибка вставки"); } ; dgTrain.DataSource = db.GetTrains(); } } } catch (Exception) { MessageBox.Show("Ошибка ввода"); } }
private void DgTrain_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { int id = Convert.ToInt32(dgTrain.CurrentRow.Cells["id"].Value); string numberTrain = dgTrain.CurrentRow.Cells["numberTrain"].Value.ToString(); string typeTrain = dgTrain.CurrentRow.Cells["typeTrain"].Value.ToString(); if (e.ColumnIndex == 4) { string message = "Вы действительно хотите удалить поезд " + numberTrain; string caption = "Подтверждение выбора"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { if (db.deleteTrain(id)) { // MessageBox.Show(numberTrain + " удален"); } else { MessageBox.Show("Не удалось удалить"); } } dgTrain.DataSource = db.GetTrains(); } if (e.ColumnIndex == 3) { using (New_train frm = new New_train(numberTrain, typeTrain)) { if (frm.ShowDialog() == DialogResult.OK) { string types; if (Convert.ToString(frm.comboBox1.Text) != "") { types = Convert.ToString(frm.comboBox1.Text); } else { types = Convert.ToString(frm.comboBox1.SelectedItem); } if (!db.UpdateTrain(id, frm.tNumberTrain.Text, types)) { MessageBox.Show("Ошибка изменения"); } ; dgTrain.DataSource = db.GetTrains(); } } } } catch (FormatException) { MessageBox.Show("Ошибка ввода"); } }