I am printing result report in medical laboratory system , and i have IF statement with multiple conditions with && and || , then i call crystal report depending on that condition and I am using stored procedure and passing parameters when run the report. IF statement not working and not passing parameters to the report . I am using this code when click print link and in page load :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TXTORDERID.Text = Request.QueryString["order_id"].ToString();
TXTDEPTID.Text = Request.QueryString["DEPT ID"].ToString();
if (Convert.ToInt32(Session["custid"]) > 1 && Convert.ToInt32(TXTDEPTID.Text) == 1 || Convert.ToInt32(TXTDEPTID.Text) == 2 || Convert.ToInt32(TXTDEPTID.Text) == 3 || Convert.ToInt32(TXTDEPTID.Text) == 4 )
{
paramField.Name = "@ORDER_ID";
paramDiscreteValue.Value = TXTORDERID.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
paramField = new ParameterField();
paramDiscreteValue = new ParameterDiscreteValue();
paramField.Name = "@deptid";
paramDiscreteValue1.Value = TXTDEPTID.Text.ToString();
paramField.CurrentValues.Add(paramDiscreteValue1);
paramFields.Add(paramField);
CrystalReportViewer1.ParameterFieldInfo = paramFields;
CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
reportDocument.Load(Server.MapPath("~/RPT/RPT_RESULTS.rpt"));
CrystalReportViewer1.ReportSource = reportDocument;
}
now when i use the IF statement like this code its not passing the parameters direct to the report and ask for report parameters order_id and dept_id
if (Convert.ToInt32(Session["custid"]) > 1 && Convert.ToInt32(TXTDEPTID.Text) == 1 || Convert.ToInt32(TXTDEPTID.Text) == 2 || Convert.ToInt32(TXTDEPTID.Text) == 3 || Convert.ToInt32(TXTDEPTID.Text) == 4 )
and when i use IF statement like this code with () after && its not ask for parameter and run empty report
if (Convert.ToInt32(Session["custid"]) > 1 && (Convert.ToInt32(TXTDEPTID.Text) == 1 || Convert.ToInt32(TXTDEPTID.Text) == 2 || Convert.ToInt32(TXTDEPTID.Text) == 3 || Convert.ToInt32(TXTDEPTID.Text) == 4) )
how to update IF statement to run the report without ask for report parameter value @order_id and @deptid ?
I know its an old post, but if it's of some help to somebody else
Essentially your 2 if statements summarizes as below
if( boolean1 && boolean2 || boolean3 || boolean4 || boolean5)
The expression evaluates boolean1 and boolean2 if true then checks the remaining
if(boolean1 && (boolean2 || boolean3 || boolean4 || boolean5))
The expression evaulates boolean1 && the result of boolean in the paranthesis
You can read about Conditional logical operators
and its short-circuit
behavior
here