Beispiel #1
0
        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("Ни один объект не выбран!");
            }
        }