/// <summary>
        /// Add a product to the package
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="supplierId"></param>
        private void AddProductToPackage(int productId, int supplierId)
        {
            try
            {
                //get the productsupplier from db
                ProductSupplier productSupplier = ProductSupplierDB.GetProductSupplier(productId, supplierId);

                //create the PPS to be added to db
                PackageProductSupplier newPackagePS = new PackageProductSupplier()
                {
                    ProductSupplierId = productSupplier.ProductSupplierID,
                    PackageId         = PackageSelected.PackageId
                };

                if (!PackageValidator.IsPackageProductSupplierExisting(newPackagePS))
                {
                    //add packageproductsupplier to db
                    PackageProductSupplierDB.Add(newPackagePS);
                    GetBindedPackageProducts(PackageSelected.PackageId);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Unable to add product", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
        ProductSupplier GetProductSupplier()
        {
            int productID  = 0;
            int supplierID = 0;

            productID  = Convert.ToInt32(cboProduct.SelectedValue);
            supplierID = Convert.ToInt32(cboSuppliers.SelectedValue);

            return(ProductSupplierDB.GetProductSupplier(productID, supplierID));
        }
Пример #3
0
        /// <summary>
        /// Jorge: Lists product supplier information when prodsup id is selected from combobox
        /// </summary>
        private void prodSupplierIdComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedId = Convert.ToInt32(prodSupplierIdComboBox.SelectedValue);

            try
            {
                currentProdSup = ProductSupplierDB.GetProductSupplier(selectedId);
                DisplayCurrentProdSupData();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error while retrieving product supplier with selected ID: " + ex.Message,
                                ex.GetType().ToString());
            }
        }
        /// <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());
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Add a product to the package
        /// </summary>
        /// <param name="productId"></param>
        /// <param name="supplierId"></param>
        private void AddProductToPackage(int productId, int supplierId)
        {
            //get the productsupplier from db
            ProductSupplier productSupplier = ProductSupplierDB.GetProductSupplier(productId, supplierId);

            //create the PPS to be added to db
            PackageProductSupplier newPackagePS = new PackageProductSupplier()
            {
                ProductSupplierId = productSupplier.ProductSupplierID,
                PackageId         = PackageSelected.PackageId
            };

            if (!PackageValidator.IsPackageProductSupplierExisting(newPackagePS))
            {
                //add packageproductsupplier to db
                PackageProductSupplierDB.Add(newPackagePS);

                GetBindedPackageProducts(PackageSelected.PackageId);
            }
        }