private void TriggerBgWorkerForQuery(EftExportQuery query) { progressBar1.Visible = true; BackgroundWorker backgroundWorker = new BackgroundWorker { WorkerSupportsCancellation = true, WorkerReportsProgress = true }; backgroundWorker.DoWork += (o, args) => { EftExportQuery report = args.Argument as EftExportQuery; try { args.Result = report?.DoQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }; backgroundWorker.RunWorkerCompleted += (o, args) => { DataTable workerResult = (DataTable)args.Result; //DataView dv = workerResult.DefaultView; //dv.Sort = "individual_identification_number desc"; //DataTable sorted = dv.ToTable(); processLogTextBox.AppendText(@"Compating File Records To DB Table Records..."); var list = workerResult.Rows.OfType <DataRow>() .Select(dr => dr.Field <string>("individual_identification_number")).ToList(); List <int> intList = list.Select(int.Parse).ToList(); //intList.Sort((i1, i2) => i2.CompareTo(i1)); var inFileNotInDb = _idNums.Except(intList).ToList(); var inDbNotInFile = intList.Except(_idNums).ToList(); bindingSource1.DataSource = inFileNotInDb.Select(x => new { Value = x }).ToList(); bindingSource2.DataSource = inDbNotInFile.Select(x => new { Value = x }).ToList(); dataGridView1.DataSource = bindingSource1; dataGridView2.DataSource = bindingSource2; progressBar1.Visible = false; processLogTextBox.AppendText($@"Done!{Environment.NewLine}"); }; backgroundWorker.RunWorkerAsync(query); }
private async void createButton_Click(object sender, EventArgs e) { ResetComps(); EftExportQuery query = new EftExportQuery(Path.GetDirectoryName(Application.ExecutablePath) + @"\Resources\SQL\IEftExport.sql"); string[] eftFileContent; try { HangAndReport(); processLogTextBox.AppendText($@"Reading EFT Export File..."); eftFileContent = await Task.Run(() => File.ReadAllLines( @"\\dmfdwh001pr\X\Deploy\Prod\FTP\Outbound\EFTExport\EFTExport.txt")); processLogTextBox.AppendText($@"Done!{Environment.NewLine}"); } catch (FileNotFoundException fileNotFoundException) { Console.WriteLine($@"Error {DateTimeOffset.Now}: {fileNotFoundException.Message}"); MessageBox.Show(@"File Not Found"); throw; } processLogTextBox.AppendText(@"Validating File Structure..."); StructureValidation(eftFileContent); processLogTextBox.AppendText($@"Done!{Environment.NewLine}"); processLogTextBox.AppendText(@"Splitting File..."); foreach (var row in eftFileContent) { if (row.StartsWith("6")) { int intData; int.TryParse(row.Substring(39, 15), out intData); _idNums.Add(intData); } } processLogTextBox.AppendText($@"Done!{Environment.NewLine}"); processLogTextBox.AppendText(@"Reading (I_EFT_EXPORT) Table..."); TriggerBgWorkerForQuery(query); processLogTextBox.AppendText($@"Done!{Environment.NewLine}"); Release(); }