Exemple #1
0
        private bool ExportToCSV()
        {
            var itens            = ItensSelecionados;
            var progressDialog   = new frmProgressBar();
            var backgroundThread = new Thread(
                () =>
            {
                progressDialog.Maximum = itens.Count();
                progressDialog.UpdateProgress("Exportando \u2026");
                var sw = new StreamWriter(_saveAs, false, Encoding.Default);
                sw.WriteLine(BalanceItem.CSVHeader);

                foreach (var item in itens)
                {
                    progressDialog.UpdateProgress();
                    sw.WriteLine(item.ToCSV);
                }
                sw.Flush();
                sw.Close();

                progressDialog.BeginInvoke(new Action(() => progressDialog.Close()));
            }
                );

            backgroundThread.Start();
            progressDialog.ShowDialog();
            return(true);
        }
Exemple #2
0
        private void toolStripButtonOcorrencias_Click(object sender, EventArgs e)
        {
            var progressDialog   = new frmProgressBar();
            var backgroundThread = new Thread(
                () => {
                progressDialog.UpdateProgress("Verificando ocorrências \u2026");
                progressDialog.Maximum = dgvRegras.RowCount;

                this.Invoke((MethodInvoker) delegate {
                    _pbar.Value   = 0;
                    _pbar.Maximum = dgvRegras.RowCount;
                    _pbar.Visible = true;
                });

                for (var row = 0; row < dgvRegras.RowCount - 1; row++)
                {
                    this.Invoke((MethodInvoker) delegate {
                        _pbar.Value++;
                    });

                    progressDialog.UpdateProgress();
                    var regra = (Regra)dgvRegras.Rows[row].DataBoundItem;
                    regra.Initialize();
                    regra.Ocorrencias =
                        _ctx.Balance.ToList().Count(bal => regra.Matches(bal));
                }
                this.Invoke((MethodInvoker) delegate {
                    _pbar.Visible = false;
                });
                progressDialog.BeginInvoke(new Action(() => progressDialog.Close()));
            }
                );

            backgroundThread.Start();
            progressDialog.ShowDialog();
        }