问题
I'm a Noobie to Stimulsoft. I have Stimulsoft Version 2015.3 running for our apps in Visual Studio 2013.
Example videos found on YouTube are all old, and I have not found any to show how to create a variable using their built-in conditional logic.
There is a dictionary where variables are created:
Currently, if I try to compile, I have 10 errors as shown here:
I'll focus on the first one: decInvoiceCost
.
The error says ";" expected, and gives this little preview:
The code for it, entered using their editor, is:
{if (blnUseMarketCost) { VwInvoice.MarketCost } else { VwInvoice.AverageCost } }
where blnUseMarketCost
is a Boolean, and the two (2) decimal values MarketCost
and AverageCost
come from the database view.
Back in the error, if I click "Go to Code":
...I am taken to the source code which is rendered by their designer:
public virtual decimal decInvoiceCost
{
get
{
// CheckerInfo: Value decInvoiceCost
return {if (blnUseMarketCost) { VwInvoiceDetail.MarketCostInInvPricingUnit } else { VwInvoiceDetail.AverageCostInInvPricingUnit } }m;
}
}
I think that "m" on the end is causing some issues, but I don't really know.
Does anyone have a few current examples showing how to use basic logic in these variable fields?
UPDATE
The C# code of the report is generated by the designer. I can use it to see what the designer is trying to do, but I do not understand all of the nuances.
namespace Reports
{
public class Report : Stimulsoft.Report.StiReport
{
public Report() {
this.InitializeComponent();
}
#region StiReport Designer generated code - do not modify
//
// {snip}
//
public virtual decimal decMarkup
{
get
{
// CheckerInfo: Value decMarkup
return ((decInvoiceCost==0) ? 0 : (decInvoiceProfit / decInvoiceCost))m;
}
}
//
// {snip}
//
#endregion StiReport Designer generated code - do not modify
}
}
回答1:
The code for the decInvoiceCost
get implementation is invalid. You should use either of these implementations instead:
public virtual decimal decInvoiceCost
{
get
{
// CheckerInfo: Value decInvoiceCost
if (blnUseMarketCost)
return VwInvoiceDetail.MarketCostInInvPricingUnit;
else
return VwInvoiceDetail.AverageCostInInvPricingUnit;
}
}
this will return either one of the two values based on an if statement.
or
public virtual decimal decInvoiceCost
{
get
{
// CheckerInfo: Value decInvoiceCost
return blnUseMarketCost
? VwInvoiceDetail.MarketCostInInvPricingUnit
: VwInvoiceDetail.AverageCostInInvPricingUnit;
}
}
which uses the ternary operator <boolExpr> ? <valueifTrue> : <valueIfFalse>;
回答2:
You should use an expression there that returns a value. The if statement is not an expression. Try to use the conditional operator (?:).
回答3:
The updated version helps a lot. It seems Stimulsoft expects a constant number in form of a literal there (e.g. 5.0 or 7.4 ...). It then tries to mark it as a decimal for the compiler (more info here Letter after a number, what is it called?).
This means that it does NOT expect a calculation, decision or code. I have never used the software so I can only guess how to solve that issue. This is why I struggled whether I should submit this as an answer. My first guess would be to change the Init by:
or the second Type
Dropdown to something else than value
. Something like code
, calculation
or similar would be what I am looking for.
The other properties seem to handle code/calculation just fine so try to look what those are using.
回答4:
Eureka!
I found the answer!
In the Stimulsoft variable editor, there is an option called Init by: that is prefilled to Value.
I changed Init by: to Expression, and the report does now pull data:
The Code View does not appear to be any different:
public virtual decimal decMarkup
{
get
{
// CheckerInfo: Value decMarkup
return ((decInvoiceCost==0) ? 0 : (decInvoiceProfit / decInvoiceCost))m;
}
}
The Stimulsoft Reports Documentation on Conditional Expressions makes no mention of this.
There are not many questions on here about Stimulsoft, and even fewer of them have answers. So, I hope someone else gets use out of this.
来源:https://stackoverflow.com/questions/35328033/creating-readonly-variables-in-stimulsoft