void Worker_FillDataGridComplete(object sender, RunWorkerCompletedEventArgs e) {
_parent.AuthenticationReset();
Cursor = Cursors.Default;
_frmProgress.Close();
if (e.Error == null) {
if ((e.Result is ZTreeParam) && (e.Result != null)) {
ZTreeParam tp = (ZTreeParam)e.Result;
DataTable table = new DataTable(tp.DataSet1.DataSetName);
foreach (DataTable dsTable in tp.DataSet1.Tables) {
try {
table.Merge(dsTable);
} catch (Exception err) {
Global.LogError("Reporter - Worker_FillDataGridComplete", err);
}
}
DataGridView_Clear();
DataGridView1.DataSource = table.DefaultView;
if (DataGridView1.CurrentRow != null) {
DataGridView1.CurrentRow.Selected = false;
}
UpdateStatusBar(string.Format("{0} records found", DataGridView1.Rows.Count));
if (tp.ColumnName.IndexOf("System_ID") == -1) {
if ((0 < DataGridView1.Rows.Count) &&
(((tp.ColumnName == _EMPLOYEE) || (tp.ColumnName == "Operator"))
|| ((tp.ColumnName == _SERIALNUM) || (tp.ColumnName == "Coils"))
|| (_clearTree == true))) {
List<string> StringList = new List<string>(DataGridView1.Rows.Count);
for (int i = 0; i < DataGridView1.Rows.Count; i++) {
DataGridViewRow row = DataGridView1.Rows[i];
string value = string.Empty;
if ((tp.ColumnName == _EMPLOYEE) || (tp.ColumnName == "Operator")) {
value = row.Cells[tp.Column].Value.ToString().Trim();
if (Action == MainAction.Reports) {
if (-1 < value.IndexOf("Summary")) {
foreach (DataGridViewCell cell in row.Cells) {
cell.Style.BackColor = Color.Yellow;
cell.Style.SelectionBackColor = Color.Gold;
}
}
if (_ReportOpt[_nFilter1Key] == _LEAKSITES) { // nothing to do, I don't think.
} else if (_ReportOpt[_nFilter1Key] == _INSPECTIONS) {
value = string.Empty;
}
}
} else if ((tp.ColumnName == _SERIALNUM) || (tp.ColumnName == "Coils")) {
value = row.Cells[tp.Column].Value.ToString().Trim();
if ((Action == MainAction.Reports) && (_ReportOpt[_nFilter1Key] == _WORKORDER)) {
if (0 < value.IndexOf("Total")) {
foreach (DataGridViewCell cell in row.Cells) {
cell.Style.BackColor = Color.Yellow;
cell.Style.SelectionBackColor = Color.Gold;
}
} else {
if (AcpCoil.CheckFormat(value) == string.Empty) {
Color bgColor = (i % 2 == 0) ? Color.PaleGreen : Color.Lime;
for (int j = 4; (j < 11) && (j < row.Cells.Count); j++) {
string txt = row.Cells[j].Value.ToString();
if ((Global.IsNumeric(txt) == true) && (0 < Global.ToInt32(txt))) {
row.Cells[j].Style.BackColor = bgColor;
row.Cells[j].Style.SelectionBackColor = Color.Silver;
}
}
} else {
value = string.Empty;
}
}
}
} else {
Console.WriteLine(tp.ColumnName);
}
if (((value != string.Empty) && (StringList.Contains(value) == false)) ||
//((Action == MainAction.Reports) && (m_ReportOpt[m_nFilter1Key] == m_LEAKSITES)) ||
(value == "Leak Site Summary")
) {
StringList.Add(value);
}
}
if ((0 < StringList.Count) && (_clearTree == true)) {
BackgroundWorker worker = new BackgroundWorker();
worker.WorkerReportsProgress = true;
worker.WorkerSupportsCancellation = true;
worker.ProgressChanged += new ProgressChangedEventHandler(Worker_ProgressChanged);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(Worker_FillTreeComplete);
if ((Action == MainAction.Reports) && (_ReportOpt[_nFilter1Key] == _LEAKSITES)) {
List<DataRow> Rows = new List<DataRow>(StringList.Count);
foreach (string emp in StringList) {
bool ok = true;
string[] split1 = emp.Split(new char[] { '(' });
string[] split2 = split1[0].Substring(0, split1[0].Length).Trim().Split(_blankspace);
string sql = string.Empty;
if (split2.Length == 2) {
sql = string.Format("(FIRSTNAME Like '{0}%') AND (LASTNAME Like '%{1}')", split2[0], split2[1]);
} else if (split2.Length == 3) {
sql = string.Format("((FIRSTNAME Like '{0}%') OR (FIRSTNAME Like '{1}%')) " +
"AND ((LASTNAME Like '%{1}') OR (LASTNAME Like '%{2}'))", split2[0], split2[1], split2[2]);
} else {
ok = false;
}
if (ok == true) {
DataRow[] dr = Global.CpAppDataSet.Tables[_EMPLOYEEINFO].Select(sql);
DataRow tmp = null;
for (int i = 0; i < dr.Length; i++) {
if (tmp == null) {
tmp = dr[i];
} else {
if ((int)tmp["COUNT"] < (int)dr[i]["COUNT"]) {
tmp = dr[i];
}
}
}
if (tmp != null) Rows.Add(tmp);
}
}
if (0 < Rows.Count) {
worker.DoWork += new DoWorkEventHandler(Worker_FillTreeWithEmployees);
worker.RunWorkerAsync(Rows.ToArray());
}
} else {
worker.DoWork += new DoWorkEventHandler(Worker_FillTreeWithCoils);
worker.RunWorkerAsync(StringList.ToArray());
}
if (worker.IsBusy == true) {
Cursor = Cursors.WaitCursor;
}
} else {
_clearTree = true; // subsequent searches will want to clear this tree information
}
} else {
MessageBox.Show("No records found.", "Search Complete", MessageBoxButtons.OK, MessageBoxIcon.Information, 0);
}
}
if (_cols2hide != null) {
foreach (string col in _cols2hide) {
if (DataGridView1.Columns.Contains(col) == true) {
DataGridView1.Columns[col].Visible = false;
}
}
}
DataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
_footer = string.Format("{0} - {1} View\r\nCreated {2}", Title, tp.ColumnName, DateTime.Now);
} else if (e.Result is string) {
MessageBox.Show(e.Result.ToString());
UpdateStatusBar(string.Format("Collect Data Error: {0}", e.Result.ToString()));
}
} else if (e.Error != null) {
UpdateStatusBar(string.Format("Collect Data Error: {0}", e.Error.Message));
_frmProgress.Close();
} else if (e.Cancelled == true) {
UpdateStatusBar("Data Collection was cancelled.");
_frmProgress.Close();
}
}