// link selected list box items
        private void btnLinkPS_Click(object sender, EventArgs e)
        {
            int supID = -1;
            int proID = -1;

            foreach (Product pro in products)
            {
                if (selectedProduct == pro.ProdName)
                {
                    proID = pro.ProductId;
                }
            }
            foreach (Supplier sup in suppliers)
            {
                if (selectedSupplier == sup.SupName)
                {
                    supID = sup.SupplierId;
                }
            }
            if (ProductSuppliersDB.LinkProductSuppliers(supID, proID))
            {
                MessageBox.Show("You have linked the product with that supplier");
            }
            else
            {
                MessageBox.Show("product could not be linked to supllier");
            }
        }
        // selected value change in the suppliers combo box
        //By:Nathan Armstrong
        private void cbSuppliers_SelectedIndexChanged(object sender, EventArgs e)
        {
            listProducts();                                                               // refresh the combo box to have all products
            selectedSupplier = cbSuppliers.SelectedItem.ToString();                       // selected value of the combo box
            List <ProductSuppliers> corispondingProducts = new List <ProductSuppliers>(); // empty list that we will put all previously linked product and suppliers
            int selectedSupID;                                                            // the ID we will use to find corisponding relationship

            // go through all suppliers in the List
            foreach (Supplier sup in suppliers)
            {
                if (sup.SupName == selectedSupplier)
                {
                    selectedSupID        = sup.SupplierId;
                    corispondingProducts = ProductSuppliersDB.GetProducts(selectedSupID);
                    foreach (ProductSuppliers prod in corispondingProducts)
                    {
                        cbProducts.Items.Remove(prod.ProdName);
                    }
                }
            }
            if (selectedProduct != null)
            {
                btnLinkPS.Enabled = true;
            }
        }
예제 #3
0
 //Display all Product_Suppliers from list
 private void listProSup()
 {
     cbProSup.Items.Clear();
     ProSups = ProductSuppliersDB.GetProductSuppliers();
     foreach (ProductSuppliers ProSup in ProSups)
     {
         cbProSup.Items.Add(ProSup.ProdName + " - " + ProSup.SupName);
     }
 }