Ejemplo n.º 1
0
        /// <summary>
        /// Show suppliers of selected product
        /// </summary>
        /// @author Harry
        private void cmboBoxProducts_SelectedIndexChanged(object sender, EventArgs e)
        {
            // ensure there was a selection
            if (cmboBoxProducts.SelectedIndex > -1)
            {
                cmboBoxSupsOfProd.Text = "";
                try
                {
                    // get product id // NEED TO FIX SELECTED INDEX CAN BE GREATER THAN LENGTH OF SUPPLIERSOFPROD
                    string prodName = (string)cmboBoxProducts.SelectedItem;
                    int    prodId   = -1;
                    foreach (Products p in products)
                    {
                        if (p.ProductName == prodName)
                        {
                            prodId = p.ProductID;
                        }
                    }

                    // get suppliers of product
                    suppliersOfProd = SuppliersDB.FindSuppliersOfProduct(prodId);

                    cmboBoxSupsOfProd.Items.Clear();

                    // add to combo box
                    foreach (Supplier sup in suppliersOfProd)
                    {
                        cmboBoxSupsOfProd.Items.Add(sup.SupName);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while loading suppliers\n" + ex.Message,
                                    ex.GetType().ToString());
                }
            }
        }