//save new product-supplier into database
        private void btnProdSupplierSave_Click(object sender, EventArgs e)
        {
            if (cboProductSupplierAdd.SelectedValue != null)
            {
                ProductSupplier ps = new ProductSupplier
                {
                    ProductId  = currentProduct.ProductId,
                    SupplierId = Convert.ToInt32(cboProductSupplierAdd.SelectedValue)
                };

                int addedProdSupplierId = ProductSupplierDB.AddProductSupplier(ps);

                if (addedProdSupplierId != 0)
                {
                    //refresh suppliers part of form
                    SetUpFrmControls();
                    LoadProductSuppliers(currentProduct.ProductId);
                }
                else
                {
                    MessageBox.Show("A problem occured adding this item to the database.  Please try again.");
                }
            }
            else
            {
                MessageBox.Show("Please select a supplier from the drop-down list to add.", "Data entry error");
            }
        }
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (checkDuplicate(cmbSupplier.Text, cmbProd.Text))
     {
         MessageBox.Show("This Product Supplier Already Exists");
         cmbSupplier.Focus();
     }
     else
     {
         ProductSupplierDB.AddProductSupplier((Product)cmbProd.SelectedItem, (Supplier)cmbSupplier.SelectedItem);
         refreshDataSource();
         dgvProdSup.Focus();
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Operations for click event on Add Supplier button.
        /// </summary>
        /// @author Chi
        private void btnAddSupplier_Click(object sender, EventArgs e)
        {
            Supplier curSupplier;                                              // Currently select supplier
            int      currentSupID;                                             // Currently select supplier's ID
            int      currentProductID     = Convert.ToInt32(txtPSProdID.Text); // Current product's ProductID
            int      currentSupplierIndex = lstboxSuppliers.SelectedIndex;     // Current index of supplier selected in list box

            if (currentSupplierIndex >= 0)                                     // If user have selected an item from list box
            {
                // Set current supplier's ID to supplier selected in list box.
                curSupplier  = filteredSuppliers[currentSupplierIndex];
                currentSupID = curSupplier.SupplierId;

                // Verify if supplier is already added to product's suppliers list.
                int result = ProductSupplierDB.GetId(currentProductID, currentSupID);

                if (result < 0) // If supplier is not in product's supplier list.
                {
                    try
                    {
                        // Add supplier to current product, reset/reload view for current product
                        // and notify user that supplier was added successfully.
                        ProductSupplierDB.AddProductSupplier(currentProductID, currentSupID);
                        loadProductSupplierData(currentProductID - 1);
                        MessageBox.Show("Supplier Added", "Success");
                    }
                    catch (Exception ex)
                    {
                        // Notify user of optimistic concurrency error or DB error.
                        MessageBox.Show("Unable to Add Supplier.\nThe Product Supplier was either removed or updated.\n\n" +
                                        ex.Message, "Unexpected Database Error");
                    }
                }
                else
                {
                    MessageBox.Show("That supplier is already added to the product", "Failed");
                }
            }
            else
            {
                MessageBox.Show("Please choose a supplier.", "No supplier selected");
            }
        }
        /// <summary>
        /// Jorge: Save new prod sup data based on add or modify
        /// </summary>
        private void ProdSupplierSaveButton_Click(object sender, EventArgs e)
        {
            if (addProductSupplier)
            {
                this.PutProdSupplierData();
                try
                {
                    productSupplier.ProductSupplierId = ProductSupplierDB.AddProductSupplier(productSupplier);
                    this.DialogResult = DialogResult.OK;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.GetType().ToString());
                }
            }
            else // this is Modify
            {
                productSupplier.ProductId         = currentProdSup.ProductId;
                productSupplier.SupplierId        = currentProdSup.SupplierId;
                productSupplier.ProductSupplierId = currentProdSup.ProductSupplierId;
                this.PutProdSupplierData();

                try                                                                                // try to update
                {
                    if (!ProductSupplierDB.UpdateProductSupplier(currentProdSup, productSupplier)) // failed
                    {
                        MessageBox.Show("Another user has updated or deleted current product supplier", "Concurrency Error");
                        this.DialogResult = DialogResult.Retry;
                    }
                    else
                    {
                        currentProdSup = ProductSupplierDB.GetProductSupplier(productSupplier.ProductSupplierId);
                        Console.WriteLine(currentProdSup.ProdName);
                        this.DialogResult = DialogResult.OK;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while updating: " + ex.Message, ex.GetType().ToString());
                }
            }
        }