예제 #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            DFormSupplier dFormSupplier = new DFormSupplier();
            DialogResult  dialogResult  = dFormSupplier.ShowDialog();

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

            Supplier supplier = new Supplier
            {
                Name          = dFormSupplier.tbName.Text,
                Address       = dFormSupplier.tbAddress.Text,
                Phone         = dFormSupplier.tbPhone.Text,
                ContactPerson = dFormSupplier.tbContactPerson.Text,
                Description   = dFormSupplier.rtbDescription.Text
            };

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

            SearchObjects(this, EventArgs.Empty);

            MessageBox.Show("Новый объект добавлен.", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
예제 #2
0
        private void btnChange_Click(object sender, EventArgs e)
        {
            if (dgvSuppliers.SelectedRows.Count > 0)
            {
                int  selectedIndex = dgvSuppliers.SelectedRows[0].Index;
                int  id            = 0;
                bool converted     = int.TryParse(dgvSuppliers[0, selectedIndex].Value.ToString(), out id);

                if (!converted)
                {
                    return;
                }

                Supplier supplier = db.Suppliers.Find(id);

                DFormSupplier dFormSupplier = new DFormSupplier();
                dFormSupplier.tbName.Text          = supplier.Name;
                dFormSupplier.tbAddress.Text       = supplier.Address;
                dFormSupplier.tbPhone.Text         = supplier.Phone;
                dFormSupplier.tbContactPerson.Text = supplier.ContactPerson;
                dFormSupplier.rtbDescription.Text  = supplier.Description;

                DialogResult dialogResult = dFormSupplier.ShowDialog(this);

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

                supplier.Name          = dFormSupplier.tbName.Text;
                supplier.Address       = dFormSupplier.tbAddress.Text;
                supplier.Phone         = dFormSupplier.tbPhone.Text;
                supplier.ContactPerson = dFormSupplier.tbContactPerson.Text;
                supplier.Description   = dFormSupplier.rtbDescription.Text;

                db.SaveChanges();
                dgvSuppliers.Refresh();

                LoadDescription(this, EventArgs.Empty);

                MessageBox.Show("Объект обновлен.", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }