Exemplo n.º 1
0
        private void cmbCategoryName_SelectedIndexChanged(object sender, EventArgs e)
        {
            cmbProductName.Text = "";
            cmbProductName.Items.Clear();

            var t = new Task(() => { });

            t.Start();
            t.ContinueWith(task => {
                Connector databaseConnectProduct = new MYSQLDatabaseConnection();
                DatabaseColumn dataSet           = new DatabaseColumn();

                categoryId = databaseConnectProduct.SearchCategoryList(tempCategoryList, cmbCategoryName.SelectedItem.ToString());

                if (databaseConnectProduct.establish() == true)
                {
                    dataSet.company_id  = companyId.company_id;
                    dataSet.category_id = categoryId.category_id;

                    databaseConnectProduct.SetData(dataSet);

                    List <DatabaseColumn> ProductList = databaseConnectProduct.GetProductNameForEachCompanyAndCategory();

                    foreach (DatabaseColumn databseColumn in ProductList)
                    {
                        cmbProductName.Items.Add(databseColumn.product_name);//add category name into combo box
                        tempProductList.Add(new DatabaseColumn()
                        {
                            product_name = databseColumn.product_name,
                            product_id   = databseColumn.product_id,
                        }
                                            );
                    }
                }
                else
                {
                    MessageBox.Show("connection error");
                }
            }, System.Threading.CancellationToken.None, TaskContinuationOptions.None, TaskScheduler.FromCurrentSynchronizationContext());
        }