Axosoft Report Builder(活动报告3)

编程入门 行业动态 更新时间:2024-10-23 14:28:46
Axosoft Report Builder(活动报告3) - 根据字段值的条件结果(Axosoft Report Builder (Active Reports 3) - Conditional Results Depending on Field Value)

我正在尝试使用Axosoft的Report Builder创建自定义报告,尽管我有一个很大的问题需要解决。 该报告将包含计算的总计和从数据库中提取以显示的特定项目的计数。 一个这样的字段(Custom_163)是一个布尔值,其中true将使其成为一种类型的项目(增强),而false将其作为另一种类型(维护)。 我能够计算报告中项目的总数,但我想将其分解为总数的百分比。

问题:一个布尔字段将确定两种类型的项目。 区分它们以收集每个的计数是我在努力的地方。

初始化变量:

private bool _oddRow = true; private string[] _labels = new string[3]; private int _defectsTotal = 0; private int _enhanceTotal = 0; private int _maintenTotal = 0;

细节部分(它为项目创建行的位置):

public void Detail1_Format() { if (rpt.Fields.Contains("Custom_163") && rpt.Fields["Custom_163"].Value != null) { if ((bool)rpt.Fields["Custom_163"].Value == true) { //needs something here to add a count towards this type return enhanceTotal; } else { //needs something here to add a count towards this type return maintenTotal; } _defectsTotal++; _enhanceTotal += enhanceTotal; _maintenTotal += maintenTotal; // To Color Every Other Row if (_oddRow) { rpt.Sections["Detail1"].BackColor = System.Drawing.Color.FromArgb(224, 224, 224); } else { rpt.Sections["Detail1"].BackColor = System.Drawing.Color.White; } _oddRow = !_oddRow; // Converting to String Values if (rpt.Fields["ItemId"].Value == null) return; } }

问题特别在于这些方面:

if((bool)rpt.Fields["Custom_163"].Value == true)

我从类似的条件改变了这一点:

if(rpt.Fields["Custom_163"].Value.ToString() == "True") if(rpt.Fields["Custom_163"].Value == true) if(rpt.Fields["Custom_163"].Value = true) if(rpt.Fields["Custom_163"].Value == 1) if(rpt.Fields["Custom_163"].Value.ToString() == "1") if (Convert.ToBoolean(rpt.Fields["Custom_163"].Value) == true) etc...

但它们似乎没有按预期工作。 我希望它过滤掉该字段为true的项目,以便其余的将执行。

另一件事是从if-else语句返回值(不工作,我尝试使用下面的单独方法也不起作用):

public class findTotals { public findTotals() { } public int resultTotals() { bool item = (bool)rpt.Fields["Custom_163"].Value; if ( item == true) { int enhanceTotal = 1; return; } else { int maintenTotal = 1; return; } } }

(这整个方法需要大量工作TBH)。

最后,这些行必须在第二个if-else之外,或者至少以某种方式返回到原始if,以便打印到报告:

_enhanceTotal += enhanceTotal; _maintenTotal += maintenTotal;

_defectsTotal获取所有项目的总计数,并且工作正常。 这两行虽然应该根据每种类型的上述条件添加一个计数,然后在报告结尾处发布增强的总量和维护项目的总金额。 它不起作用,如果不是转换/转换错误或条件强制数组超出范围,它是一些其他问题。 我也玩过所有这些订单。

可能的解决方案?

如何安全地将bool值转换(如果需要)为int,以便可以使用该数字来添加总数?

如何在if-else中返回值,以便范围与变量匹配? 我需要一种方法吗?

提前谢谢你

I am trying to create a custom report using Axosoft's Report Builder though I have one big issue to tackle. The report will contain calculated totals and counts of the specific items that are pulled in from the database to display. One such field (Custom_163) is a boolean where true will have it be one type of item (Enhancement) while false will have it as another (Maintenance). I am able to get a count of the total amount of items in the report, but I want to break it down as percentages of the total.

Problem: One boolean field will determine two types of items. Differentiating between them to gather a count of each is where I'm struggling.

Initialized Variables:

private bool _oddRow = true; private string[] _labels = new string[3]; private int _defectsTotal = 0; private int _enhanceTotal = 0; private int _maintenTotal = 0;

Detail Section (where it's creating the rows for the items):

public void Detail1_Format() { if (rpt.Fields.Contains("Custom_163") && rpt.Fields["Custom_163"].Value != null) { if ((bool)rpt.Fields["Custom_163"].Value == true) { //needs something here to add a count towards this type return enhanceTotal; } else { //needs something here to add a count towards this type return maintenTotal; } _defectsTotal++; _enhanceTotal += enhanceTotal; _maintenTotal += maintenTotal; // To Color Every Other Row if (_oddRow) { rpt.Sections["Detail1"].BackColor = System.Drawing.Color.FromArgb(224, 224, 224); } else { rpt.Sections["Detail1"].BackColor = System.Drawing.Color.White; } _oddRow = !_oddRow; // Converting to String Values if (rpt.Fields["ItemId"].Value == null) return; } }

The problem is specifically with these lines:

if((bool)rpt.Fields["Custom_163"].Value == true)

I've changed this a ton from similar conditions:

if(rpt.Fields["Custom_163"].Value.ToString() == "True") if(rpt.Fields["Custom_163"].Value == true) if(rpt.Fields["Custom_163"].Value = true) if(rpt.Fields["Custom_163"].Value == 1) if(rpt.Fields["Custom_163"].Value.ToString() == "1") if (Convert.ToBoolean(rpt.Fields["Custom_163"].Value) == true) etc...

But they don't seem to work as intended. I want it to filter out the items where this field is true so the rest will execute.

Another thing is returning the values from the if-else statement (not working and I've tried using a separate method below that doesn't work either):

public class findTotals { public findTotals() { } public int resultTotals() { bool item = (bool)rpt.Fields["Custom_163"].Value; if ( item == true) { int enhanceTotal = 1; return; } else { int maintenTotal = 1; return; } } }

(This whole method needs a ton of work TBH).

Lastly, these lines has to be outside of the second if-else or at least somehow returned to the original if in order to be printed to the report:

_enhanceTotal += enhanceTotal; _maintenTotal += maintenTotal;

The _defectsTotal gets a total count of all the items and that works fine. These two lines though are supposed to add a count based on the above conditions for each type so then the total amount of Enhancements and total amount of Maintenance Items get posted at the end of the report. It doesn't work, if not a casting/conversion error or the conditions force the array(s) out of bounds, it's some other issue. I've played around the order for all these too.

Possible Solutions?

How to safely convert (if needed) the bool values to int so that number can be used to add to a total?

How can I return the values in the if-else so the scope matches up with the variables? Will I need a method?

Thank you in advance.

最满意答案

您应该可以对“True”进行字符串比较。 即

if(string.Compare(rpt.Fields [“Custom_163”]。Value.ToString(),“True”)== 0)

I figured out what the issue was.

So basically...

if (Convert.ToBoolean(rpt.Fields["Custom_163"].Value) == true) { enhanceTotal++; } else { maintenTotal++; } _defectsTotal++;

(This is all within another if-statement and a bunch of code not relevant to issue.) This works fine and actually returns the count, after that another hurdle was figuring out the labels so it can print into it's placeholders correctly. The whole findTotals method wasn't needed. I didn't need any more variables than the three listed above to make it work. A reason I kept on getting errors was because I tried to use one variable as a label to print into different places within the report which isn't allowed apparently. Instead of using one label and sticking it everywhere, I made several that were identical and made sure to give them different names, etc.

So instead of X in three different report sections, X was X, Y, Z (all identical but different identifer) and stuck it where needed. Man, it seems to obvious now, well thanks again.

更多推荐

本文发布于:2023-08-06 21:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1454974.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:报告   Axosoft   Report   Builder

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!