简体   繁体   English

Winform到Crystal Report的值更改

[英]Winform to Crystal Report value changes

Why does a value from a certain Winform change when passing to a report? 为什么某个Winform中的值传递给报表时会发生变化?

for example from a form I have a string 1311-0015 but when I pass it to a Formula Field it becomes 1,296.00 例如,从表单中我有一个字符串1311-0015,但是当我将其传递给“公式字段”时,它变成1,296.00

http://i.imgur.com/oeIwrAU.jpg http://i.imgur.com/oeIwrAU.jpg

Passing it to a TextObject doesn't change the value it's still 1311-0015 but I can't use TextObjects in formulas in Crystal Report. 将其传递给TextObject不会更改其值,仍然是1311-0015,但是我无法在Crystal Report的公式中使用TextObjects。

Would like to know why this is happening and how to remedy the problem. 想知道为什么会这样以及如何解决该问题。

this is the code from the winForm: 这是winForm中的代码:

report.DataDefinition.FormulaFields["SOS"].Text = transactionId; report.DataDefinition.FormulaFields [“ SOS”]。Text = transactionId; ((TextObject)report.Section2.ReportObjects["Text3"]).Text = transactionId; ((TextObject)report.Section2.ReportObjects [“ Text3”])。Text = transactionId;

the value I was passing to the crystal report: 我传递给水晶报表的价值:

public string transactionId = "1311-0015"; 公共字符串transactionId =“ 1311-0015”;

You said you are passing the value to a formula field. 您说要将该值传递给公式字段。 If there is nothing in the formula, and you pass 1311 - 15 to the formula, it will evaluate it. 如果公式中没有任何内容,并且您将1311-15传递给公式,它将对其求值。 Instead of a formula field, use a text box or modify the string so it doesn't come out like an equation. 代替公式字段,使用文本框或修改字符串,以使它不会像方程式那样出现。 For your transactionID value try something like: 为您的transactionID值尝试类似:

""1311" & "-" & "0015""

You may need to have two separate public string transactionId variables. 您可能需要具有两个单独的公共字符串transactionId变量。

You can pass this string as parameter. 您可以将此字符串作为参数传递。 First, create a parameter field in you Crystal Reports editor. 首先,在Crystal Reports编辑器中创建一个参数字段。 (Right button, New...) (右键,新建...)

参数栏位

Code something like this: 代码如下:

string transactionID = "1311-0015";

yourRpt.SetDatasource(youDataSource);
yourRpt.Parameters.SetParameterValue("transactionID", transactionID);

Now, you just need to drag and drop the parameter field into the report. 现在,您只需要将参数字段拖放到报告中即可。

You should create a parameter and use its value inside the formula. 您应该创建一个参数,并在公式中使用它的值。 In order to avoid showing parameters dialog box make sure that the parameter value is set (you should do this in your code) and set: yourReport.EnableParameterPrompting = false; 为了避免显示参数对话框,请确保已设置参数值(应在代码中执行此操作)并设置:yourReport.EnableParameterPrompting = false;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM