cancel
Showing results for 
Search instead for 
Did you mean: 

Get Parameters properties so I can dynamically build a parameters entry screen

Former Member
0 Kudos

Hi

I want to dynamically build an ASP.NET page to allow the user to select values for parameters on a report.

I could keep details of all the parameters in a DB table so I would then know what controls and values to program for on the parameters entry page.

But I would prefer to be able to interrogate the parameters of the selected report direct form the report object itself.

Can you tell me how I can get the details and all properties of parameters on a report pls. If indeed it is possible to do that.

I would need details like name, type, permissible values, single/multiple/range of values etc.

Thanks

Mark

View Entire Topic
0 Kudos

Hi Mark,

Something like this:

private void getParameterFields(CrystalDecisions.CrystalReports.Engine.ReportDocument rpt)

{

    string textBox1 = String.Empty;

    string textBox2 = String.Empty;

    string MyObjectType = ReportObjectComboBox1.SelectedItem.ToString();

    btnReportObjects.Text = "";

    if (rptClientDoc.DataDefController.DataDefinition.ParameterFields.Count > 0) //there are parameters

    {

        btnCount.Text = rptClientDoc.DataDefController.DataDefinition.ParameterFields.Count.ToString();

        foreach (CrystalDecisions.ReportAppServer.DataDefModel.ParameterField paramfield in rptClientDoc.DataDefController.DataDefinition.ParameterFields)

        {

            switch (paramfield.ValueRangeKind)

            {

                case CrParameterValueRangeKindEnum.crParameterValueRangeKindDiscrete:

                    {

                        getDiscreteValues(paramfield);

                        break;

                    }

                case CrParameterValueRangeKindEnum.crParameterValueRangeKindDiscreteAndRange:

                    {

                        getRangeAndDiscreteValues(paramfield);

                        break;

                    }

                case CrParameterValueRangeKindEnum.crParameterValueRangeKindRange:

                    {

                        getRangeValues(paramfield);

                        break;

                    }

            }

        }

    }

}

public Boolean isParameterDynamic(CrystalDecisions.CrystalReports.Engine.ReportDocument rpt, int iCnt, bool YorN)

{

    if (rpt.DataDefinition.ParameterFields[iCnt].Attributes != null && rpt.DataDefinition.ParameterFields[iCnt].Attributes.ContainsKey("IsDCP"))

    {

        Hashtable objAttributes = rpt.DataDefinition.ParameterFields[iCnt].Attributes;

        YorN = (Boolean)objAttributes["IsDCP"];

        return YorN;

    }

    return YorN;

}

private void getDiscreteValues(CrystalDecisions.ReportAppServer.DataDefModel.ISCRParameterField paramfield)

{

    string textBox1 = String.Empty;

    string name = paramfield.Name;

    int currValCount = paramfield.InitialValues.Count;

    int defValCount = paramfield.DefaultValues.Count;

    bool YorN = false;

    if (defValCount > 0)  //this parameter has default values

    {

        foreach (ParameterFieldDiscreteValue discreteDefaultVal in paramfield.DefaultValues)

        {

            btnReportObjects.AppendText(paramfield.Name.ToString());

            textBox1 = ": " + discreteDefaultVal.Value.ToString();

            btnReportObjects.Text += textBox1;

            btnReportObjects.AppendText("\n");

            if (currValCount > 0)

            {

                foreach (ParameterFieldDiscreteValue CurrentInitialVal in paramfield.InitialValues)

                { // Always only going to be 1

                    textBox1 = "Default Value: " + CurrentInitialVal.Value.ToString();

                    btnReportObjects.Text += textBox1;

                    btnReportObjects.AppendText("\n");

                }

            }

            if (discreteDefaultVal.Description != null)

            {

                textBox1 = "Description: " + discreteDefaultVal.Description.ToString();

            }

            else

                textBox1 = "Description:";

            btnReportObjects.Text += textBox1;

            btnReportObjects.AppendText("\n");

        }

    }

    else

    {

        isParameterDynamic(rpt, 0, YorN);

        btnReportObjects.AppendText(paramfield.Name.ToString());

        if (YorN)

        {

            btnReportObjects.AppendText(": No Initial Value \n");

        }

        else

        {

            string myPrefix = paramfield.Description;

            btnReportObjects.AppendText(": Dynamic Cascading Parameter ( LOV )\nBased on field: " + paramfield.FormulaForm + "\n"); // paramfield.Description.Remove(0, 6) + "\n");

        }

    }

}

private void getRangeValues(CrystalDecisions.ReportAppServer.DataDefModel.ParameterField paramfield)

{

    string textBox1 = String.Empty;

    string name = paramfield.Name;

    int currValCount = paramfield.CurrentValues.Count;

    int defValCount = paramfield.DefaultValues.Count;

    int z = 0;

    try

    {

        foreach (ParameterFieldDiscreteValue discreteDefaultVal in paramfield.DefaultValues)

        {

            btnReportObjects.AppendText(paramfield.Name.ToString());

            textBox1 = ": " + discreteDefaultVal.Value.ToString();

            btnReportObjects.Text += textBox1;

            btnReportObjects.AppendText("\n");

            if (z == 0)

            {

                foreach (ParameterFieldDiscreteValue CurrentInitialVal in paramfield.InitialValues)

                { // Always only going to be 1

                    textBox1 = "Default Value: " + CurrentInitialVal.Value.ToString();

                    btnReportObjects.Text += textBox1;

                    btnReportObjects.AppendText("\n");

                }

                z = 1;

            }

            if (discreteDefaultVal.Description != null)

            {

                textBox1 = "Description: " + discreteDefaultVal.Description.ToString();

            }

            else

                textBox1 = "Description:";

            btnReportObjects.Text += textBox1;

            btnReportObjects.AppendText("\n");

            //MessageBox.Show(discreteDefaultVal.Value.ToString());

        }

    }

    catch

    { }

}

private void getRangeAndDiscreteValues(CrystalDecisions.ReportAppServer.DataDefModel.ParameterField paramfield)

{

    string name = paramfield.Name;

    int currValCount = paramfield.CurrentValues.Count;

    int defValCount = paramfield.DefaultValues.Count;

    if (defValCount > 0)  //this parameter has default values

    {

        foreach (ParameterFieldRangeValue discreteDefaultVal in paramfield.DefaultValues)

        {

            MessageBox.Show(discreteDefaultVal.BeginValue.ToString());

        }

    }

}

Permissible values is up to you to handle...

Don

Former Member
0 Kudos

Hi Don

Thanks for the very thorough answer. I am programming in VB.NET and have tried to 'decipher' your CS example but am struggling a bit. Is there any chance of a VB example pls?

Many thanks

Mark

saurabh_pathak
Active Contributor
0 Kudos

Mark,

There are many websites which convert C# code to Vb.net. Google  search might help here.

Thanks,

Saurabh