private void OKBtn_Click(object sender, EventArgs e) { if (target == null) { return; } poison_rod_type_rec pr = null; try { pr = NC.App.DB.PoisonRods.Get(target.rod_type); } catch (InvalidOperationException) // not there, it's new { } if (null != pr) { if (NC.App.DB.PoisonRods.Delete(target)) // removes from DB, and then from in-memory list { target = null; RefreshCombo(); } } }
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { if (e.ColumnIndex == 0) { DataGridViewComboBoxCell cel = (DataGridViewComboBoxCell)this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; if (!cel.Items.Contains(e.FormattedValue)) { for (int i = 0; i < dataGridView1.RowCount; i++) { DataGridViewComboBoxCell temp = (DataGridViewComboBoxCell)dataGridView1.Rows[i].Cells[0]; temp.Items.Add(e.FormattedValue); } list.Add(e.FormattedValue.ToString()); poison_rod_type_rec toAdd = new poison_rod_type_rec(); toAdd.rod_type = e.FormattedValue.ToString(); toAdd.absorption_factor = Double.Parse(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString()); toAdd.modified = true; poison.Add(toAdd); cel.Value = cel.Items.IndexOf(e.FormattedValue); } } else if (e.ColumnIndex > 1)// Numeric column and editable { if (String.IsNullOrEmpty(e.FormattedValue.ToString())) { dataGridView1.Rows[e.RowIndex].ErrorText = "Value must not be empty."; e.Cancel = true; } else { if (e.ColumnIndex != 1) { Regex reg = new Regex("[1-9][0-9]*\\.?[0-9]*([Ee][+-]?[0-9]+)?"); if (!reg.IsMatch(e.FormattedValue.ToString())) { dataGridView1.Rows[e.RowIndex].ErrorText = "Value is not a floating point number."; e.Cancel = true; double res = 0; dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = res.ToString("E3"); dataGridView1.Rows[e.RowIndex].ErrorText = String.Empty; this.dataGridView1.RefreshEdit(); } else { double res = 0; Double.TryParse(e.FormattedValue.ToString(), out res); dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = res.ToString("E3"); this.dataGridView1.RefreshEdit(); } } else { //Num Rods is an int int number = -1; if (!Int32.TryParse(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(), out number)) { MessageBox.Show("WARNING", "You must enter an integer between 0 and 10."); dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "1"; } } } } }
private void PoisonRodTypeComboBox_SelectedIndexChanged(object sender, EventArgs e) { target = NC.App.DB.PoisonRods.Get(((ComboBox)sender).Text); }
private void CurrentPoisonRodTypesComboBox_SelectedIndexChanged(object sender, EventArgs e) { model = new poison_rod_type_rec(NC.App.DB.PoisonRods.Get((string)CurrentPoisonRodTypesComboBox.SelectedItem)); DefaultPoisonAbsorptionTextBox.Text = model.absorption_factor.ToString("F3"); PoisonRodTypeTextBox.Text = model.rod_type; }
public IDDPoisonRodTypeAdd() { InitializeComponent(); model = new poison_rod_type_rec(); RefreshCombo(pick: false); }
private void CurrentPoisonRodTypesComboBox_SelectedIndexChanged(object sender, EventArgs e) { model = new poison_rod_type_rec(NC.App.DB.PoisonRods.Get((string)CurrentPoisonRodTypesComboBox.SelectedItem)); DefaultPoisonAbsorptionTextBox.Text = model.absorption_factor.ToString("F3"); PoisonRodTypeTextBox.Text = model.rod_type; }
public IDDPoisonRodTypeAdd() { InitializeComponent(); model = new poison_rod_type_rec(); RefreshCombo(pick:false); }
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { if (e.ColumnIndex == 0) { DataGridViewComboBoxCell cel = (DataGridViewComboBoxCell)this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; if (!cel.Items.Contains(e.FormattedValue)) { for (int i = 0; i < dataGridView1.RowCount; i++) { DataGridViewComboBoxCell temp = (DataGridViewComboBoxCell)dataGridView1.Rows[i].Cells[0]; temp.Items.Add(e.FormattedValue); } list.Add(e.FormattedValue.ToString()); poison_rod_type_rec toAdd = new poison_rod_type_rec(); toAdd.rod_type = e.FormattedValue.ToString(); toAdd.absorption_factor = Double.Parse(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString()); toAdd.modified = true; poison.Add(toAdd); cel.Value = cel.Items.IndexOf(e.FormattedValue); } } else if (e.ColumnIndex > 1)// Numeric column and editable { if (String.IsNullOrEmpty (e.FormattedValue.ToString())) { dataGridView1.Rows[e.RowIndex].ErrorText = "Value must not be empty."; e.Cancel = true; } else { if (e.ColumnIndex != 1) { Regex reg = new Regex("[1-9][0-9]*\\.?[0-9]*([Ee][+-]?[0-9]+)?"); if (!reg.IsMatch(e.FormattedValue.ToString())) { dataGridView1.Rows[e.RowIndex].ErrorText = "Value is not a floating point number."; e.Cancel = true; double res = 0; dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = res.ToString("E3"); dataGridView1.Rows[e.RowIndex].ErrorText = String.Empty; this.dataGridView1.RefreshEdit(); } else { double res = 0; Double.TryParse(e.FormattedValue.ToString(), out res); dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = res.ToString("E3"); this.dataGridView1.RefreshEdit(); } } else { //Num Rods is an int int number = -1; if (!Int32.TryParse(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(), out number)) { MessageBox.Show("WARNING", "You must enter an integer between 0 and 10."); dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = "1"; } } } } }