on 2015 Mar 13 10:52 PM
Hi ido,
It should work. I use this to get the collection so the add is commented out but should work for you:
{
btnReportObjects.Text = "";
flcnt = 0;
foreach (CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject reportObject in rptClientDoc.ReportDefController.ReportObjectController.GetAllReportObjects())
{
var reportSection = rptClientDoc.ReportDefController.ReportDefinition.FindSectionByName(reportObject.SectionName);
for (int index = 0;
index < reportSection.Format.ConditionFormulas.Count;
++index)
{
var formula = reportSection.Format.ConditionFormulas[(CrystalDecisions.ReportAppServer.ReportDefModel.CrSectionAreaFormatConditionFormulaTypeEnum)index];
var NewFormula = reportSection.Format.ConditionFormulas[(CrystalDecisions.ReportAppServer.ReportDefModel.CrSectionAreaFormatConditionFormulaTypeEnum)index];
try
{
if (formula.Text != null)
{
textBox1 = "Condition Formula: " + formula.Text.ToString() + "\n";
textBox1 += "Section " + reportSection.Name + "\n";
}
}
catch (Exception ex)
{
btnReportObjects.Text += "\nException: " + ex.ToString();
}
btnReportObjects.Text += textBox1;
btnReportObjects.AppendText("\n");
++flcnt;
btnCount.Text = flcnt.ToString();
//// check the formula by adding it to the report to verify the syntax
//CrystalDecisions.ReportAppServer.ObjectFactory.ObjectFactory objFactory = new CrystalDecisions.ReportAppServer.ObjectFactory.ObjectFactory();
//CrystalDecisions.ReportAppServer.DataDefModel.FormulaField Formula = (CrystalDecisions.ReportAppServer.DataDefModel.FormulaField)objFactory.CreateObject("CrystalReports.FormulaField");
//Formula.Type = CrystalDecisions.ReportAppServer.DataDefModel.CrFieldValueTypeEnum.crFieldValueTypeStringField;
//Formula.Syntax = CrystalDecisions.ReportAppServer.DataDefModel.CrFormulaSyntaxEnum.crFormulaSyntaxCrystal;
//Formula.Text = @"whilereadingrecords; ""A"""; // "hello Ludek = 1"; // resultField.Text; // "n=3"; {Customer.Customer Credit ID} + 1 @"whilereadingrecords; ""A"""
//Formula.Name = "TestDon"; // "TestDon"; // resultField.Name; //"testformula";
//String FormulaMessage = rptClientDoc.DataDefController.FormulaFieldController.Check(Formula);
//if (FormulaMessage == null)
//{
// //then add the conditional formula if it's OK
// string newFormulaText = "'It Worked' = 'It Worked'";
// // Clone a Section Format and use ReportSectionController.SetPropety to modify the ConditionFormulas
// CrystalDecisions.ReportAppServer.ReportDefModel.SectionFormat newFormat = reportSection.Format.Clone(true);
// newFormat.ConditionFormulas[(CrystalDecisions.ReportAppServer.ReportDefModel.CrSectionAreaFormatConditionFormulaTypeEnum)index].Text = newFormulaText;
// rptClientDoc.ReportDefController.ReportSectionController.SetProperty(reportSection, CrReportSectionPropertyEnum.crReportSectionPropertyFormat, newFormat);
//}
//else
// btnReportObjects.Text += "There are errors in the formula: " + FormulaMessage.ToString() + "\n";
}
}
}
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, Don!
Note that checking the condition expression doesn't seem to work for background color expressions (which are Numeric). After setting the formula type to numeric using:
oFormulaField.Type = CrystalDecisions.ReportAppServer.DataDefModel.CrFieldValueTypeEnum.crFieldValueTypeNumberField
The act of assigning the formula Text reverts the Type to StringField if the expression is a String. It doesn't matter if the assignment of TEXT happens before or after attempting to set the formula data type.
Hi Ido,
Isn't that what it is supposed to do?
When I modify the background color the formula Wizard adds this:
// This conditional formatting formula must return one of the following Color Constants:
//
// Color (red, green, blue)
// crBlack
// crMaroon
// crGreen
// crOlive
// crNavy
// crPurple
// crTeal
// crSilver
// crRed
// crLime
// crYellow
// crBlue
// crFuchsia
// crAqua
// crWhite
// crNoColor
//
if {Orders.Order ID} = 1430 then cryellow else crred
Can you paste your code in and I'll try it also, there are so many different object and other parts I can't guess which one you are using try them all. And a report with just the one object you are attempting to change.
You can send it directly to me if you want.
Thanks
Don
Hi Don,
The key objective is to detect BAD expressions in format condition formulas.
Problem 1: There is no .Check() method for such Formulas. Only for REGULAR formulas.
Solution 1: create a dummy regular formula with that same expression and .Check() it.
Problem 2: If the expression we check is bad due to it being a String rather than Number or Boolean, it will not be detected as bad because the act of assigning the bad expression to the dummy formula changes its data type.
Solution 2: ask DEV to not change the data type (if already assigned) of a formula when assigning an expression to it.
To replicate: 1. create a formula in code 2. Set its data type to numeric 3. set its expression to a string ("""Some Text"""). Note that the formula data type somehow just changed to String. And a .Check doesn't detect a problem.
One more thought: a much better solution would be if DEV added a .Check() method for Format Condition Formulas, so we don't have to jump through hoops to check them.
User | Count |
---|---|
66 | |
10 | |
10 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.