コード例 #1
0
        // populate drop down with names of sup objects from the Suppliers list
        private void PopulateProdSuppliers()
        {
            // return list of suppliers created in GetProdSuppliers()
            List <ProdSupplier> prodSupplierList = ProdSuppliersDB.GetProdSuppliers();

            // adding product supplier names to the CBName (combo box)
            var prodSupplierLinq = from prodSup in prodSupplierList
                                   select new
            {
                prodSup.ProductSupplierId
            };

            foreach (var item in prodSupplierLinq)
            {
                cBID.Items.Add(item.ProductSupplierId);
            }
        }
コード例 #2
0
        // when name combo box (ddl) is used to select an object from the list
        private void cBID_SelectedIndexChanged(object sender, EventArgs e)
        {
            // return list of packages created in GetProdSuppliers()
            //List<ProdSupplier> prodSupplierList = ProdSuppliersDB.GetProdSuppliers();

            //// if a selection is made from the combo box
            //if (cBID.SelectedIndex != -1)
            //{
            //    // display information about the selected product supplier
            //    var prodSup = from selectedprodSup in prodSupplierList where
            //                    selectedprodSup.ProductSupplierId == Convert.ToInt32(cBID.Text)
            //                    select new
            //                    {
            //                        selectedprodSup.ProductId,
            //                        selectedprodSup.ProdName,
            //                        selectedprodSup.SupplierId,
            //                        selectedprodSup.SupName

            //                    };

            //    //return list of packages created in GetSuppliers()

            if (btnProdSupClicked && cBID.SelectedIndex != -1)
            {
                int temp = Convert.ToInt32(cBID.Text);
                if (temp != Convert.ToInt32(null))
                {
                    ProdSupplier prodSupplier = ProdSuppliersDB.GetProdSuppliersOBJECT(temp);

                    cbProdID.Text = prodSupplier.ProdName.ToString();
                    cbSupID.Text  = prodSupplier.SupName.ToString();


                    //cbProdID.Text = prodSup.ProdName.ToString();
                    //cbSupID.Text = prodSup.SupName.ToString();

                    //Maryam
                    //SingleProdSup = prodSup;
                    SingleProdSup = prodSupplier;
                    //}
                }
            }
        }
コード例 #3
0
        private void PutProdSupplierData(ProdSupplier newProductSupplier)
        {
            try
            {
                selectedProduct        = Convert.ToInt32(cboProdID.SelectedItem);
                prodSupplier.ProductId = selectedProduct;

                selectedSupplier        = Convert.ToInt32(cboSupID.SelectedItem);
                prodSupplier.SupplierId = selectedSupplier;

                ProdSuppliersDB.AddNewProdSupplier(prodSupplier);
                this.DialogResult = DialogResult.OK;
                MessageBox.Show("Product Supplier has been saved");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
コード例 #4
0
//when user selects a product in the product list, populate suppliers list
        private void cboProdList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboProdList.SelectedIndex < 00000000)
            {
                selectedProduct   = null;
                product.ProductId = selectedProduct;
            }
            else
            {
                newProdSup           = new ProdSupplier();
                newProdSup.ProductId = Convert.ToInt32(cboProdList.Text);


                // return list of suppliers based on product ID from GetProdSuppliersBasedOnProductId


                cboSupplierList.DataSource    = ProdSuppliersDB.GetProdSuppliersBasedOnProductId(newProdSup);
                cboSupplierList.DisplayMember = "SupplierId";
                cboSupplierList.ValueMember   = "ProductSupplierId";
            }
        }
コード例 #5
0
        //Saving the Data in database
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool updated = false;

            //if Supplier button is clicked
            if (btnSupClicked)
            {
                //Validating Supplier Table
                if (Validator1.IsProvidedCombo(cBName, "Supplier Name"))
                {
                    Supplier newSup = new Supplier();
                    newSup.SupName = cBName.Text;  //for new supplier name

                    updated = SuppliersDB.UpdateSupplier(newSup, SingleSup);
                    if (updated)
                    {
                        MessageBox.Show("Supplier Updated");
                    }
                    else
                    {
                        MessageBox.Show("Supplier not Updated. Please try again.");
                    }
                }
            }
            //If Products button is clicked
            if (btnProdClicked)
            {
                //Validating Product Table
                if (Validator1.IsProvidedCombo(cBName, "Product Name"))
                {
                    Product NewProd = new Product();
                    NewProd.ProdName = cBName.Text; //for new Product name

                    updated = ProductsDB.UpdateProducts(NewProd, SingleProd);
                    if (updated)
                    {
                        MessageBox.Show("Products Updated");
                    }
                    else
                    {
                        MessageBox.Show("Products not Updated. Please try again");
                    }
                }
            }
            if (btnProdSupClicked)// this does not work yet
            {
                //Validating Product-Supplier table
                if (Validator1.IsProvidedCombo(cbProdID, "Product Id") &&
                    Validator1.IsProvidedCombo(cbSupID, "Supplier Id"))
                {
                    ProdSupplier newProdSupplier = new ProdSupplier();
                    newProdSupplier.ProductId  = Convert.ToInt32(cbProdID.SelectedValue);
                    newProdSupplier.SupplierId = Convert.ToInt32(cbSupID.SelectedValue);

                    updated = ProdSuppliersDB.UpdateProdSupplier(newProdSupplier, SingleProdSup);
                    if (updated)
                    {
                        MessageBox.Show("Product_Supplier is Updated");
                    }
                    else
                    {
                        MessageBox.Show("Product_Supplier is not Updated. Please try again");
                    }
                }
            }
            if (btnPackClicked)  // Otherwise just load Packages
            {
                //Validating data for Packages
                if (Validator1.IsProvidedCombo(cBName, "Package Name") &&
                    Validator1.IsProvided(txtDesc, "Describtion") &&
                    Validator1.IsProvided(txtBasePrice, "Base Price") &&
                    Validator1.IsProvided(txtAgencyComm, "Agency Commission"))
                {
                    Package NewPackage = new Package();
                    NewPackage.PkgName = cBName.Text;

                    //Start Date cannnot be greater then End Date
                    if (dTPStartDate.Value.Date >= dTPEndDate.Value.Date)
                    {
                        MessageBox.Show("Package start date cannot be later than end date");
                    }

                    //Agency commission cannot be greater then base price
                    else if (Convert.ToDecimal(txtBasePrice.Text.Replace("$", "")) < (Convert.ToDecimal(txtAgencyComm.Text.Replace("$", ""))))
                    {
                        MessageBox.Show("Agency Comission cannot be more than Package Base price!");
                    }
                    else
                    {
                        NewPackage.PkgStartDate        = dTPStartDate.Value.ToString("yyyy-MM-dd");
                        NewPackage.PkgEndDate          = dTPEndDate.Value.ToString("yyyy-MM-dd");
                        NewPackage.PkgDesc             = txtDesc.Text;
                        NewPackage.PkgBasePrice        = Convert.ToDecimal(txtBasePrice.Text.Replace("$", ""));
                        NewPackage.PkgAgencyCommission = Convert.ToDecimal(txtAgencyComm.Text.Replace("$", ""));

                        updated = PackageDB.UpdatePackage(NewPackage, SinglePkg);
                    }

                    if (updated)
                    {
                        MessageBox.Show("Package is Updated");
                    }
                    else
                    {
                        MessageBox.Show("Package is not Updated, Please try again.");
                    }
                }
            }
        }