TDray
(Todd Dray)
December 4, 2023, 6:55pm
21
private void EmpGridCheck()
{
DateTime startDate = Convert.ToDateTime(edvCallContextBpmData.dataView[edvCallContextBpmData.Row]["Date01"].ToString());
string startDateString = startDate.ToString("MM-dd-yyyy");
DateTime endDate = Convert.ToDateTime(edvCallContextBpmData.dataView[edvCallContextBpmData.Row]["Date02"].ToString());
string endDateString = endDate.ToString("MM-dd-yyyy");
DynamicQueryAdapter dqadptr = new DynamicQueryAdapter(oTrans);
dqadptr.BOConnect();
QueryExecutionDataSet qeds2;
try
{
qeds2 = dqadptr.GetQueryExecutionParametersByID("tedUntrainedWork3");
}
catch(Exception ex)
{
// exception is not for hide, it is for problem solving
MessageBox.Show(ex.ToString());
}
qeds2.ExecutionParameter[0].ParameterID = "StartDate";
qeds2.ExecutionParameter[0].IsEmpty = false;
qeds2.ExecutionParameter[0].ParameterValue = startDateString;
qeds2.ExecutionParameter[1].ParameterID = "EndDate";
qeds2.ExecutionParameter[1].IsEmpty = false;
qeds2.ExecutionParameter[1].ParameterValue = endDateString;
qeds2.AcceptChanges();
dqadptr.ExecuteByID("tedUntrainedWork3", qeds2);
DataTable results = dqadptr.QueryResults.Tables[0];
if (results != null && results.Rows.Count > 0)
{
grdEmployees.DataSource = results;
grdEmployees.DisplayLayout.Bands[0].Columns["Calculated_Supervisor"].Width = 200;
grdEmployees.DisplayLayout.Bands[0].Columns["Calculated_Employee"].Width = 200;
grdEmployees.DisplayLayout.Bands[0].Columns["OpMaster_OpDesc"].Width = 250;
grdEmployees.DisplayLayout.Bands[0].Columns["UD251_ShortChar01"].Width = 250;
}
}
If I split the parameters out of the try catch I get:
Error: CS0165 - line 92 (250) - Use of unassigned local variable ‘qeds2’
If I put the parameters in the catch, they never get assigned as it breaks out before getting to them.
The only other code in here is:
private void BpmData_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row["FieldName"]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
switch (args.Column.ColumnName)
{
case "Date02":
EmpGridCheck();
break;
}
}
which is working as it runs EmpGridCheck when Date02 is changed (DateO2 is what I am publishing to from the dashboard, and once again, that value will display without error)
Olga
(Olga Klimova)
December 4, 2023, 7:01pm
22
You fire EmpGridCheck twice, when you call server for parameters.
You can see it in the stack.
You need to figure out how to avoid it. Easiest way is to add flag bool isRunning = true/false and check at the beginning of the method.
TDray
(Todd Dray)
December 4, 2023, 7:46pm
23
I originally had an inProcess variable, but it was causing issues as well. Put it back in (changed to isRunning), still had issues.
Broke my EmpGridCheck into two functions (am doing the same thing twice with two different grids and queries) Set the isRunning variable on the first one and set it back to false at end of second one. Surrounded both with try catches and now they work.
Putting the working code here in case anywhere stumbles across this in the future and can glean anything from it. Thank you all for your help. Greatly appreciated!
private void BpmData_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row["FieldName"]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
try{
switch (args.Column.ColumnName)
{
case "Date02":
if (isRunning == false)
{
EmpGridCheck();
EmpGridCheck2();
isRunning = false;
}
break;
}
}catch{isRunning = false;}
}
private void EmpGridCheck()
{
if (isRunning == false)
{
isRunning = true;
DateTime startDate = Convert.ToDateTime(edvCallContextBpmData.dataView[edvCallContextBpmData.Row]["Date01"].ToString());
startDateString = startDate.ToString("MM-dd-yyyy");
DateTime endDate = Convert.ToDateTime(edvCallContextBpmData.dataView[edvCallContextBpmData.Row]["Date02"].ToString());
endDateString = endDate.ToString("MM-dd-yyyy");
DynamicQueryAdapter dqadptr = new DynamicQueryAdapter(oTrans);
dqadptr.BOConnect();
QueryExecutionDataSet qeds2;
try
{
qeds2 = dqadptr.GetQueryExecutionParametersByID("tedUntrainedWork3");
qeds2.ExecutionParameter[0].ParameterID = "StartDate";
qeds2.ExecutionParameter[0].IsEmpty = false;
qeds2.ExecutionParameter[0].ParameterValue = startDateString;
qeds2.ExecutionParameter[1].ParameterID = "EndDate";
qeds2.ExecutionParameter[1].IsEmpty = false;
qeds2.ExecutionParameter[1].ParameterValue = endDateString;
qeds2.AcceptChanges();
dqadptr.ExecuteByID("tedUntrainedWork3", qeds2);
}
catch(Exception ex)
{
// exception is not for hide, it is for problem solving
//MessageBox.Show(ex.ToString());
}
DataTable results = dqadptr.QueryResults.Tables[0];
if (results != null && results.Rows.Count > 0)
{
grdEmployees.DataSource = results;
grdEmployees.DisplayLayout.Bands[0].Columns["Calculated_Supervisor"].Width = 200;
grdEmployees.DisplayLayout.Bands[0].Columns["Calculated_Employee"].Width = 200;
grdEmployees.DisplayLayout.Bands[0].Columns["OpMaster_OpDesc"].Width = 250;
grdEmployees.DisplayLayout.Bands[0].Columns["UD251_ShortChar01"].Width = 250;
}
}
}
private void EmpGridCheck2()
{
DynamicQueryAdapter dqadptr = new DynamicQueryAdapter(oTrans);
dqadptr.BOConnect();
QueryExecutionDataSet qeds;
try{
qeds = dqadptr.GetQueryExecutionParametersByID("tedUntrainedWork4");
qeds.ExecutionParameter[0].ParameterID = "StartDate";
qeds.ExecutionParameter[0].IsEmpty = false;
qeds.ExecutionParameter[0].ParameterValue = startDateString;
qeds.ExecutionParameter[1].ParameterID = "EndDate";
qeds.ExecutionParameter[1].IsEmpty = false;
qeds.ExecutionParameter[1].ParameterValue = endDateString;
qeds.AcceptChanges();
dqadptr.ExecuteByID("tedUntrainedWork4", qeds);
}
catch(Exception ex)
{
// exception is not for hide, it is for problem solving
//MessageBox.Show(ex.ToString());
}
DataTable results2 = dqadptr.QueryResults.Tables[0];
if (results2 != null && results2.Rows.Count > 0)
{
grdEmp2.DataSource = results2;
grdEmp2.DisplayLayout.Bands[0].Columns["Calculated_Supervisor"].Width = 200;
grdEmp2.DisplayLayout.Bands[0].Columns["Calculated_Employee"].Width = 200;
grdEmp2.DisplayLayout.Bands[0].Columns["UD251_ShortChar01"].Width = 250;
}
}
TDray
(Todd Dray)
December 4, 2023, 7:47pm
24
Solution was a combination of the posts above from Olga and Brandon. Marked my code in the post above as the solution as it combines a few posts in here.