Exemplo n.º 1
0
        //изменить
        private void DataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.SelectedCells.Count > 0)
            {
                int  index     = dataGridView1.SelectedCells[0].OwningRow.Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Info mashine = db.Infos.Find(id);

                AddInfoMachine addInfoMachine = new AddInfoMachine();

                addInfoMachine.numericUpDown1.Value = mashine.Port;

                addInfoMachine.textBox1.Text = mashine.Name;



                mashine.Port = (int)addInfoMachine.numericUpDown1.Value;
                mashine.Name = addInfoMachine.textBox1.Text;

                db.SaveChanges();
                dataGridView1.Refresh(); // обновляем
            }
        }
Exemplo n.º 2
0
        //добавить
        private void Button1_Click(object sender, EventArgs e)
        {
            AddInfoMachine addInfoMachine = new AddInfoMachine();
            DialogResult   result         = addInfoMachine.ShowDialog(this);

            if (result == DialogResult.Cancel)
            {
                return;
            }

            Info machine = new Info();

            machine.Name = addInfoMachine.textBox1.Text;
            machine.Port = (int)addInfoMachine.numericUpDown1.Value;

            db.Infos.Add(machine);
            db.SaveChanges();
        }