如何在水晶报表中以编程方式编辑标签?

发布于 2024-10-01 19:20:48 字数 123 浏览 2 评论 0原文

我有一个 Crystal Reports 报表,我想通过 C# 以编程方式编辑标签。我可以操作数据源,但无法编辑标签。

我正在设计一份账单报告,因此我需要显示公司详细信息、日期时间和一些我无法从数据源获取的其他信息。

I have a Crystal Reports report and I want to edit a label programmatically from c#. I can manipulate data source but cannot edit a label.

I'm designing a bill report so I need to display company details, date time and some other information which I can't get from my data source.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

青芜 2024-10-08 19:20:49

查看 CR 对象模型。您可以通过编程控制的内容存在限制,但这应该会有所帮助。

Take a look at the CR Object Model. There are limits to what you can control programatically but this should help.

倾`听者〃 2024-10-08 19:20:48

您需要将此给定的 Label 设为 FomulaField,然后可以通过 FormulaFieldDefinitions 集合访问该 Label,然后您将使用 您感兴趣的 FormulaFieldDefinition 类对象。

此外,此类公司信息等应始终直接放在报告本身上,即编辑后的RPT文件上。尤其是在谈论公司徽标时,您需要这样做。

You will need to make this given Label a FomulaField which will then be accessible through the FormulaFieldDefinitions collection, and you will work with the FormulaFieldDefinition class object that is of interest for you.

Besides, such company information and the like should always be placed directly on the report itself, that is, the edited RPT file. You want to do this particularly when speaking about the company's logo.

时光瘦了 2024-10-08 19:20:48

通常对于账单,公司名称及其详细信息(如地址等)显示在账单顶部。在这种情况下,我使用的是报告标题。在这种情况下,您可以非常轻松地传递要显示的文本。在运行时传递某些内容的另一种方法是使用报告参数。您可以将参数绑定到字段或公式。参数也很容易传递。

有一次,我使用以下代码动态地从报表中获取参数并将其绑定到网格视图:

    private void GetParameters()
    {
        //DataTable dt = new DataTable("Params");
        string dataTableName  = "Params";
        //add a tablestyle to the grid so there will be custom columnstyles available
        // after the datasource has been set....
        DataGridTableStyle ts = new System.Windows.Forms.DataGridTableStyle();
        ts.MappingName = dataTableName;
        dtgParams.TableStyles.Add(ts);

        // DataGridTextBoxColumn
        DataGridTextBoxColumn cParamName = new DataGridTextBoxColumn();
        cParamName.MappingName = "Parameter";
        cParamName.HeaderText = "Parameter";
        cParamName.ReadOnly=true;

        // Add the column style to the column style collection
        ts.GridColumnStyles.Add( cParamName );

        // DataGridTextBoxColumn
        DataGridTextBoxColumn cType = new DataGridTextBoxColumn();
        cType.MappingName = "Data_Type";
        cType.HeaderText = "Data Type";
        cType.ReadOnly=true;

        // Add the column style to the column style collection
        ts.GridColumnStyles.Add( cType );

        // DataGridTextBoxColumn
        DataGridTextBoxColumn cValue = new DataGridTextBoxColumn();
        cValue.MappingName = "Value";
        cValue.HeaderText = "Value";
        cValue.ReadOnly=false;

        // Add the column style to the column style collection
        ts.GridColumnStyles.Add( cValue );

        DataRow dr;
        dt.Columns.Add(new DataColumn("Parameter",typeof(string)));
        dt.Columns.Add(new DataColumn("Data_Type",typeof(string)));
        dt.Columns.Add(new DataColumn("Value",typeof(string)));

        // For all the Parameters defined in the report
        for(int i=0;i<ReportDoc.DataDefinition.ParameterFields.Count;  i++)
        {
            dr = dt.NewRow();
            dr[0] = ReportDoc.DataDefinition.ParameterFields[i].ParameterFieldName;
            dr[1] = ReportDoc.DataDefinition.ParameterFields[i].ParameterValueKind;
            dr[2] = ReportDoc.DataDefinition.ParameterFields[i].DefaultValues[0];
            dt.Rows.Add(dr);
        }
        DataView source = new DataView(dt);
        dtgParams.DataSource = source;
    }

并使用以下代码段来设置参数:

    private void SetParamValue  (string paramName, string paramValue)
    {
        ParameterFieldDefinition PFD = null;
        ParameterValues PValues = null;
        ParameterDiscreteValue Parm = null;
        PValues = new ParameterValues();
        PFD = ReportDoc.DataDefinition.ParameterFields[paramName];
        Parm = new ParameterDiscreteValue();
        Parm.Value = paramValue;
        PValues.Add(Parm);
        PFD.ApplyCurrentValues(PValues);
    }

Normally for a bill, where the company name and details of it (like address etc) are shown at the top of the bill. In such a case, what I use is the report header. In that case, you can pass on the text to be shown very easily. The other way of passing on something at runtime will be using report parameter. You can bind the parameter to a field or to a formula. Parameters are also very easy to pass on.

In one occasion, I have used the following code to get the parameters from a report dynamically and bind it to a gridview:

    private void GetParameters()
    {
        //DataTable dt = new DataTable("Params");
        string dataTableName  = "Params";
        //add a tablestyle to the grid so there will be custom columnstyles available
        // after the datasource has been set....
        DataGridTableStyle ts = new System.Windows.Forms.DataGridTableStyle();
        ts.MappingName = dataTableName;
        dtgParams.TableStyles.Add(ts);

        // DataGridTextBoxColumn
        DataGridTextBoxColumn cParamName = new DataGridTextBoxColumn();
        cParamName.MappingName = "Parameter";
        cParamName.HeaderText = "Parameter";
        cParamName.ReadOnly=true;

        // Add the column style to the column style collection
        ts.GridColumnStyles.Add( cParamName );

        // DataGridTextBoxColumn
        DataGridTextBoxColumn cType = new DataGridTextBoxColumn();
        cType.MappingName = "Data_Type";
        cType.HeaderText = "Data Type";
        cType.ReadOnly=true;

        // Add the column style to the column style collection
        ts.GridColumnStyles.Add( cType );

        // DataGridTextBoxColumn
        DataGridTextBoxColumn cValue = new DataGridTextBoxColumn();
        cValue.MappingName = "Value";
        cValue.HeaderText = "Value";
        cValue.ReadOnly=false;

        // Add the column style to the column style collection
        ts.GridColumnStyles.Add( cValue );

        DataRow dr;
        dt.Columns.Add(new DataColumn("Parameter",typeof(string)));
        dt.Columns.Add(new DataColumn("Data_Type",typeof(string)));
        dt.Columns.Add(new DataColumn("Value",typeof(string)));

        // For all the Parameters defined in the report
        for(int i=0;i<ReportDoc.DataDefinition.ParameterFields.Count;  i++)
        {
            dr = dt.NewRow();
            dr[0] = ReportDoc.DataDefinition.ParameterFields[i].ParameterFieldName;
            dr[1] = ReportDoc.DataDefinition.ParameterFields[i].ParameterValueKind;
            dr[2] = ReportDoc.DataDefinition.ParameterFields[i].DefaultValues[0];
            dt.Rows.Add(dr);
        }
        DataView source = new DataView(dt);
        dtgParams.DataSource = source;
    }

And used the following code segment to set parameters:

    private void SetParamValue  (string paramName, string paramValue)
    {
        ParameterFieldDefinition PFD = null;
        ParameterValues PValues = null;
        ParameterDiscreteValue Parm = null;
        PValues = new ParameterValues();
        PFD = ReportDoc.DataDefinition.ParameterFields[paramName];
        Parm = new ParameterDiscreteValue();
        Parm.Value = paramValue;
        PValues.Add(Parm);
        PFD.ApplyCurrentValues(PValues);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文