cancel
Showing results for 
Search instead for 
Did you mean: 

Adding additional select criteria in code behind

0 Kudos

I'm creating a Crystal Report viewer in an ASP.NET web page and all works fine (except I can't go beyond page 2 but that's another problem). However I now want to add some extra selection criteria to any that may already be present in the report.

I have a class which loads the existing .rpt file and adds the connection info :

    protected ReportDocument LoadCrystalReport(string reportFile)
    {
        if (!string.IsNullOrEmpty(reportFile))
        {
            // Get the required report and load it into the viewer
            ReportDocument crRpt = new ReportDocument();
            crRpt.Load(reportFile);

            // now logon to the files used by the current report
            ConnectionInfo connectionInfo = new ConnectionInfo();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();

            connectionInfo.ServerName = dbServer.Value;
            connectionInfo.DatabaseName = addrBook.Value;
            connectionInfo.UserID = userName.Value;
            SymCrypt sc = new SymCrypt();
            connectionInfo.Password = sc.Decrypt(userPass.Value);

            foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crRpt.Database.Tables)
            {
                crtableLogoninfo = crTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = connectionInfo;
                crTable.ApplyLogOnInfo(crtableLogoninfo);
            }

            return crRpt;
        }

        return null;
    }

And the code to call this class and display the report and extend the selection is:

// load our report
crRpt = LoadCrystalReport(Path.Combine(reportPath.Value, reportName.Value));

crystalReportViewer.ReportSource = crRpt;
crystalReportViewer.PrintMode = CrystalDecisions.Web.PrintMode.Pdf;
string extraSelects = string.Empty;

// This checks for additional select criteria
if (!string.IsNullOrEmpty(extraSelects = SetRecordSelectionForReport()))

{

    // Do we have to add this to existing criteria ??

    if (string.IsNullOrEmpty(crRpt.RecordSelectionFormula))
    {
        crRpt.RecordSelectionFormula = extraSelects;
    }
    else
    {
        crRpt.RecordSelectionFormula = string.Format("{0} and {1}", crRpt.RecordSelectionFormula, extraSelects);
    }
}

However when I assign my joined selection criteria to crRpt.ReportSelectionFormula it immediately clears all existing data and leaves the value empty.

If I check the value of RecordSelectionFormula prior to any assignment it has the value :

" (   (  {Opportunity.Status} = 3  AND  {@0 £ balance remains 24 months}  )   AND   (  {Address.Country} <> \"Channel Islands\"  )   )  ".

I then want to append further criteria:

"(  {Opportunity.Opp_Id}  IN  [ \"060918022732098261889C\", \"060908008692098261889C\" ]  )"

so i concatenate the 2 strings with an "AND" giving  :

" (   (  {Opportunity.Status} = 3  AND  {@0 £ balance remains 24 months}  )   AND   (  {Address.Country} <> \"Channel Islands\"  )   )   AND  (  {Opportunity.Opp_Id}  IN  [ \"060918022732098261889C\", \"060908008692098261889C\" ]  )"

but this clears the existing criteria and doesn't assign my new selection.

Is there something I'm missing with regard to setting a new selection criteria ??

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

OK, I think I've got this resolved. It looks like it might have been down to running a web app under debug. If it runs normally the selection appears to be working however I need to do some more tests to confirm it.

Answers (0)