private void btnUpdate_Click(object sender, EventArgs e) { int index = getSelectedRow(gvPhonesList); if (index != -1) { int id = 0; bool converted = Int32.TryParse(gvPhonesList[0, index].Value.ToString(), out id); if (converted == false) { return; } Phone ph = dal.GetPhone(id); if (ph != null) { AddPhoneForm f = new AddPhoneForm(allManufacturers); f.numericUpDown1.Value = ph.Cost; f.comboBoxManuf.SelectedValue = ph.ManufacturerId; f.textBox1.Text = ph.Name; DialogResult result = f.ShowDialog(this); if (result == DialogResult.Cancel) { return; } ph.Cost = f.numericUpDown1.Value; ph.Name = f.textBox1.Text; ph.ManufacturerId = (int)f.comboBoxManuf.SelectedValue; dal.Save(); gvPhonesList.Refresh(); //MessageBox.Show("Объект обновлен"); } } else { MessageBox.Show("Ни один объект не выбран!"); } }
private void btnNewPhone_Click(object sender, EventArgs e) { AddPhoneForm f = new AddPhoneForm(allManufacturers); DialogResult result = f.ShowDialog(this); if (result == DialogResult.Cancel) { return; } Phone phone = new Phone(); phone.ManufacturerId = (int)f.comboBoxManuf.SelectedValue; phone.Name = f.textBox1.Text; phone.Cost = f.numericUpDown1.Value; dal.CreatePhone(phone); this.gvPhonesList.Refresh(); //MessageBox.Show("Новый объект добавлен"); }