//populate combo boxes so there is a supplierID and product ID to choose from //Populate the Product list with products from the database //Populate the Supplier list with supplier from the database private void FillComboBoxes() { // return list of productID created in GetProductName() List <Product> myProdList = ProductsDB.GetProducts(); // adding product names to the CBName (combo box) var prodLinq = from prod in myProdList select new { prod.ProductId }; foreach (var item in prodLinq) { cboProdID.Items.Add(item.ProductId); } // return list of supplierID names created in GetProductName() List <Supplier> mySupList = SuppliersDB.GetSuppliers(); // adding package names to the CBName (combo box) var supLinq = from sup in mySupList select new { sup.SupplierId }; foreach (var item in supLinq) { cboSupID.Items.Add(item.SupplierId); } }
//Populate the Product list with products from the database private void FillComboProducts() { // return list of product created in GetProductName() List <Product> myProdList = ProductsDB.GetProducts(); // adding product id to the CBName (combo box) var prodLinq = from prod in myProdList select new { prod.ProductId }; foreach (var item in prodLinq) { cboProdList.Items.Add(item.ProductId); } }
// populate drop down with names of prod objects from the Products list private void PopulateProducts() { // return list of packages created in GetProducts() List <Product> productList = ProductsDB.GetProducts(); //if(btnUpdateClicked) //{ // adding product names to the CBName (combo box) var productLinq = from prod in productList select new { prod.ProdName }; foreach (var item in productLinq) { cBName.Items.Add(item.ProdName); } // } // else // { //// adding product names to the CBName (combo box) //var productLinq = from prod in productList // select new // { // prod.ProductId // }; //foreach (var item in productLinq) //{ // cbProdID.Items.Add(item.ProductId); //} cbProdID.DataSource = productList; cbProdID.DisplayMember = "ProdName"; cbProdID.ValueMember = "ProductId"; // } }
// when name combo box (ddl) is used to select an object from the list private void cBPkgName_SelectedIndexChanged(object sender, EventArgs e) { // if the Products button was most recently clicked if (btnProdClicked) { // return list of packages created in GetProducts() List <Product> productList = ProductsDB.GetProducts(); // display information about the selected product if (cBName.SelectedIndex != -1) { var prod = (from selectedprod in productList where selectedprod.ProdName == cBName.Text select selectedprod).First(); txtID.Text = prod.ProductId.ToString(); //Maryam SingleProd = prod; } } // if the Suppliers button was most recently clicked else if (btnSupClicked) { // return list of packages created in GetSuppliers() List <Supplier> supplierList = SuppliersDB.GetSuppliers(); // if a selection is made from the combobox if (cBName.SelectedIndex != -1) { // display information about the selected supplier var sup = (from selectedsup in supplierList where selectedsup.SupName == cBName.Text select selectedsup).First(); txtID.Text = sup.SupplierId.ToString(); //Maryam SingleSup = new Supplier(); SingleSup.SupplierId = Convert.ToInt32(txtID.Text); SingleSup.SupName = cBName.Text; } } // if the Packages button was most recently clicked // or on form load else { // return list of packages created in GetPackages() List <Package> packageList = MainPackageDB.GetPackages(); // if a selection is made from the combo box if (cBName.SelectedIndex != -1) { // display information about the selected package var pkg = (from selectedpkg in packageList where selectedpkg.PkgName == cBName.Text select selectedpkg).First(); txtID.Text = pkg.PackageId.ToString(); dTPStartDate.Value = Convert.ToDateTime(pkg.PkgStartDate); dTPEndDate.Value = Convert.ToDateTime(pkg.PkgEndDate); txtDesc.Text = pkg.PkgDesc; txtBasePrice.Text = pkg.PkgBasePrice.ToString("c"); txtAgencyComm.Text = pkg.PkgAgencyCommission.ToString("c"); //Maryam SinglePkg = pkg; } } }