コード例 #1
0
ファイル: SupplierForm.cs プロジェクト: WatherMG/Storehouse
        //добавление товара
        private void button1_Click(object sender, EventArgs e)
        {
            SupplierAddForm supplierAddForm = new SupplierAddForm();

            DialogResult result = supplierAddForm.ShowDialog(this);

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

            Supplier supplier = new Supplier();

            supplier.name      = supplierAddForm.textBox1.Text;
            supplier.country   = supplierAddForm.textBox2.Text;
            supplier.state     = supplierAddForm.textBox3.Text;
            supplier.city      = supplierAddForm.textBox4.Text;
            supplier.telephone = supplierAddForm.textBox7.Text;

            db.Suppliers.Add(supplier);
            db.SaveChanges();
            RefreshGrid(dataGridView1);

            MessageBox.Show("Новый поставщик добавлен");
        }
コード例 #2
0
ファイル: SupplierForm.cs プロジェクト: WatherMG/Storehouse
        //редактирвоание товара
        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                int  index     = dataGridView1.SelectedRows[0].Index;
                int  id        = 0;
                bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id);
                if (converted == false)
                {
                    return;
                }

                Supplier        supplier = db.Suppliers.Find(id);
                SupplierAddForm suForm   = new SupplierAddForm();
                suForm.textBox1.Text = supplier.name;
                suForm.textBox2.Text = supplier.country;
                suForm.textBox3.Text = supplier.state;
                suForm.textBox4.Text = supplier.city;
                suForm.textBox7.Text = supplier.telephone;


                DialogResult result = suForm.ShowDialog(this);

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

                supplier.name      = suForm.textBox1.Text;
                supplier.country   = suForm.textBox2.Text;
                supplier.state     = suForm.textBox3.Text;
                supplier.city      = suForm.textBox4.Text;
                supplier.telephone = suForm.textBox7.Text;

                db.Entry(supplier).State = EntityState.Modified;
                db.SaveChanges();
                RefreshGrid(dataGridView1);

                MessageBox.Show("Поставщик обновлен");
            }
        }