Exemplo n.º 1
0
        // grab function to take invoices
        public static void grab(DataTable invoiceT, string dest)
        {
            // initialize and sets backgroundworker
            backgroundWorker2 = new BackgroundWorker();
            backgroundWorker2.WorkerSupportsCancellation = true;
            backgroundWorker2.WorkerReportsProgress      = true;
            List <object> args = new List <object>();

            backgroundWorker2.DoWork             += new DoWorkEventHandler(backgroundWorker1_DoWork);
            backgroundWorker2.ProgressChanged    += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
            backgroundWorker2.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
            args.Add(invoiceT);
            args.Add(dest);
            // run the background worker
            backgroundWorker2.RunWorkerAsync(args);
            loadbar = new loadInput();
            loadbar.Activate();
            while (backgroundWorker2.IsBusy)
            {
                DialogResult result = loadbar.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.Cancel)
                {
                    backgroundWorker2.CancelAsync();
                }
                System.Threading.Thread.Sleep(50);
            }
            // end the background worker
            backgroundWorker2.Dispose();
        }
        // queries visible table
        private void queryCurrentTable()
        {
            // initialization of variables and backgroundworker
            int selected = tabs.SelectedIndex;

            backgroundWorker1 = new BackgroundWorker();
            backgroundWorker1.WorkerSupportsCancellation = true;
            List <object> args = new List <object>();

            args.Add(con);
            args.Add(commands[selected]);
            args.Add(selected);
            backgroundWorker1.DoWork             += new DoWorkEventHandler(backgroundWorker1_DoWork);
            backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
            // run the background worker
            backgroundWorker1.RunWorkerAsync(args);
            // start the loading bar
            loadbar = new loadInput();
            loadbar.Activate();
            while (backgroundWorker1.IsBusy)
            {
                DialogResult result = loadbar.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.Cancel)
                {
                    backgroundWorker1.CancelAsync();
                }
                System.Threading.Thread.Sleep(50);
            }
            backgroundWorker1.Dispose();
            // attaching tables to datagrid
            try {
                switch (selected)
                {
                case 0:
                    queryResult.ItemsSource = tables[selected].DefaultView;
                    break;

                case 1:
                    invoiceGrid.ItemsSource = tables[selected].DefaultView;
                    break;

                case 2:
                    coaGrid.ItemsSource = tables[selected].DefaultView;
                    break;

                case 3:
                    missingGrid.ItemsSource = tables[selected].DefaultView;
                    break;

                case 4:
                    testGrid.ItemsSource = tables[selected].DefaultView;
                    break;

                case 5:
                    if ((bool)Filter.IsChecked)
                    {
                        tables[selected].DefaultView.RowFilter = "T_BAD_DEBT = 'T'";
                    }
                    customersGrid.ItemsSource = tables[selected].DefaultView;
                    break;
                }
                searched = true;
            } catch (Exception e) {
            }
        }