private void ModifyProduct()
        {
            var addModifyProductForm = new frmAddModifyProduct()
            { // object initializer
                AddProduct = false,
                Product    = selectedProduct
            };
            DialogResult result = addModifyProductForm.ShowDialog(); // display modal

            if (result == DialogResult.OK)                           // user clicked Accept on the second form
            {
                try
                {
                    selectedProduct = addModifyProductForm.Product; // new data
                    context.SaveChanges();
                    DisplayProducts();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    HandleConcurrencyError(ex);
                }
                catch (DbUpdateException ex)
                {
                    HandleDatabaseError(ex);
                }
                catch (Exception ex)
                {
                    HandleGeneralError(ex);
                }
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var addModifyProductForm = new frmAddModifyProduct()
            {
                AddProduct = true
            };
            DialogResult result = addModifyProductForm.ShowDialog();

            if (result == DialogResult.OK)// user clicked on Accept on the second form
            {
                try
                {
                    selectedProduct = addModifyProductForm.Product; // record product from the second
                                                                    // form as the current product
                    context.Products.Add(selectedProduct);
                    context.SaveChanges();
                    DisplayProducts();
                }
                catch (DbUpdateException ex)
                {
                    HandleDatabaseError(ex);
                }
                catch (Exception ex)
                {
                    HandleGeneralError(ex);
                }
            }
        }
        private void btnModify_Click(object sender, EventArgs e)
        {
            frmAddModifyProduct modifyProductForm = new frmAddModifyProduct();

            modifyProductForm.addProduct = false;
            modifyProductForm.product    = product;
            DialogResult result = modifyProductForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                product = modifyProductForm.product;
                this.DisplayProduct();
            }
            else if (result == DialogResult.Retry)
            {
                this.GetProduct(product.Code);
                if (product != null)
                {
                    this.DisplayProduct();
                }
                else
                {
                    this.ClearControls();
                }
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAddModifyProduct addProductForm = new frmAddModifyProduct();

            addProductForm.addProduct = true;
            DialogResult result = addProductForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                product      = addProductForm.product;
                txtCode.Text = product.Code;
                this.DisplayProduct();
            }
        }
예제 #5
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            frmAddModifyProduct addProductForm = new frmAddModifyProduct();

            addProductForm.addProduct = true;

            DialogResult result = addProductForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                product = addProductForm.product;

                ProductCodeTextBox.Text = product.ProductCode.ToString();
                DisplayProduct();
            }
        }