Пример #1
0
        //-------------------MODIFY productsSupplier --------------------------------------------------
        private void btnModify_Click_1(object sender, EventArgs e)
        {
            //create second form
            frmAddModifyProdSupp secondForm = new frmAddModifyProdSupp();

            secondForm.isAdd = false;

            secondForm.productsSupplier = context.ProductsSuppliers.Find(selected_ProductsSupplierID);

            DialogResult result = secondForm.ShowDialog();//accept returns ok

            if (result == DialogResult.OK)
            {
                selectedProductsSupplier = secondForm.productsSupplier;
                try
                {
                    context.SaveChanges();
                    DisplayLVProductsSuppliers();
                }
                //catch (DbUpdateConcurrencyException ex)
                //{
                //    HandleConcurrencyError(ex);
                //}
                catch (DbUpdateException ex)
                {
                    HandleDataError(ex);
                }
                catch (Exception ex)
                {
                    HandleGeneralError(ex);
                }
            }

            ManageControls(false);
        }
Пример #2
0
        //-------------------ADD productsSupplier--------------------------------------------------
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //create second form
            frmAddModifyProdSupp addModifySupplier = new frmAddModifyProdSupp();

            addModifySupplier.isAdd            = true;
            addModifySupplier.productsSupplier = null;

            DialogResult result = addModifySupplier.ShowDialog();//accept returns ok

            //if dialogresult is ok, save productsSupplier, and display items in list view
            if (result == DialogResult.OK)
            {
                selectedProductsSupplier    = addModifySupplier.productsSupplier;
                selectedProductsSupplierIds = addModifySupplier.selectedProductsSupplierIds;

                try
                {
                    var newProductsSupplier = context.ProductsSuppliers.Add(selectedProductsSupplier);

                    context.SaveChanges();

                    DisplayLVProductsSuppliers();
                }
                //catch (DbUpdateConcurrencyException ex)
                //{
                //    HandleConcurrencyError(ex);
                //}
                catch (DbUpdateException ex)
                {
                    HandleDataError(ex);
                }
                catch (Exception ex)
                {
                    HandleGeneralError(ex);
                }
            }
        }