on 01-30-2016 8:11 AM
In VB6 I have the following code
Set Report = Appl.OpenReport(App.Path & "\reports\rptStock.rpt")
Report.FormulaFields.GetItemByName("Group" & i & "Field").Text = "{vieArtikel.ArticleId}"
Report.GroupNameFields(i).GroupNameConditionFormula = "{vieArtikel.ArticleName}"
In .NET I don't know how to convert the last line with the GroupNameConditionFormula property.
ReportDocument reportDocument = new ReportDocument();
string filePath = "";
filePath = Path.Combine(Application.StartupPath, "Reports", "rptStock.rpt");
reportDocument.Load(filePath);
reportDocument.DataDefinition.FormulaFields["Group" + i + "Field"].Text = "{vieArtikel.ArticleId}";
???
Hi Alef,
SP 16 was just released, you can get the update from here:
You will need to use RAS to get/set those formulae now:
Add these assemblies:
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportAppServer;
using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.ReportDefModel;
using CrystalDecisions.ReportAppServer.CommonControls;
using CrystalDecisions.ReportAppServer.CommLayer;
using CrystalDecisions.ReportAppServer.CommonObjectModel;
using CrystalDecisions.ReportAppServer.ObjectFactory;
using CrystalDecisions.ReportAppServer.Prompting;
using CrystalDecisions.ReportAppServer.DataSetConversion;
using CrystalDecisions.ReportAppServer.DataDefModel;
using CrystalDecisions.ReportSource;
Define the Report objects:
CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;
Load the report and then set to ReportClientDocument:
rptClientDoc = rpt.ReportClientDocument;
Output goes to a text box....
#region Conditional
{
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";
btnReportObjects.Text += textBox1;
btnReportObjects.AppendText(" 'End' \n");
textBox1 = "";
}
}
catch (Exception ex)
{
btnReportObjects.Text += "\nException: " + ex.ToString();
}
//if (reportObject.Name == "Text18")
//{
// // 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 = @"if {Customer.Country} = 'Canada' then Color (150,230,150) else Color (10,19,200)"; //@"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
// // Sage question and solution
// string newFormulaText = Formula.Text; // "'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";
//}
}
//for (int fIndex = 0; fIndex < reportObject.Format.ConditionFormulas.Count; ++fIndex)
//{
// var ObjectFormula = reportObject.Format.ConditionFormulas[(CrystalDecisions.ReportAppServer.ReportDefModel.CrObjectFormatConditionFormulaTypeEnum)fIndex];
// try
// {
// if (ObjectFormula.Text != null)
// {
// textBox1 = "\nObject: " + reportObject.Name + "\n";
// if (((dynamic)reportObject).Text.ToString() != null) // throws error if .Text does not exist
// {
// textBox1 += "Object text: " + ((dynamic)reportObject).Text.ToString() + "\n";
// }
// textBox1 += "Object Formula: " + ObjectFormula.Text.ToString() + "\n";
// btnReportObjects.Text += textBox1;
// btnReportObjects.AppendText("\n");
// ++flcnt;
// btnCount.Text = flcnt.ToString();
// //if (reportObject.Name == "Text7")
// //{
// // // 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 = @"if CurrentFieldValue > 10 then Color (150,230,150) else Color (10,19,200)"; //@"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
// // // Sage question and solution
// // 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)fIndex].Text = newFormulaText;
// // rptClientDoc.ReportDefController.ReportSectionController.SetProperty(reportSection, CrReportSectionPropertyEnum.crReportSectionPropertyFormat, newFormat);
// // }
// // else
// // btnReportObjects.Text += "There are errors in the formula: " + FormulaMessage.ToString() + "\n";
// //}
// }
// }
// catch (Exception ex)
// {
// //btnReportObjects.Text += "\nException: " + ex.ToString();
// textBox1 += "Object Formula: " + ObjectFormula.Text.ToString() + "\n";
// btnReportObjects.Text += textBox1;
// btnReportObjects.AppendText("\n");
// ++flcnt;
// btnCount.Text = flcnt.ToString();
// }
//}
}
}
#endregion Conditional
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Don,
Thanks. I wasn't aware of RAS.
The code you are sending seems part of a bigger sample application. Can you provide a link to the sample code?
I've studied RAS and for the ones who are interested you need the following code to replace the old VB6 function GroupNameConditionFormula:
private void GroupNameConditionFormula(ReportDocument reportDocument, string groupName, string formula) | |
{ | |
CrystalDecisions.ReportAppServer.DataDefModel.Group oldGroup; | |
CrystalDecisions.ReportAppServer.DataDefModel.Group newgroup; |
CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc = (CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument)reportDocument.ReportClientDocument; | ||
int i = 0; | ||
foreach (CrystalDecisions.ReportAppServer.DataDefModel.Group resultField in rptClientDoc.DataDefController.DataDefinition.Groups) | ||
{ | ||
if (resultField.ConditionField.Name == groupName) | ||
{ | ||
oldGroup = rptClientDoc.DataDefController.DataDefinition.Groups[i]; | ||
newgroup = oldGroup.Clone(true); |
CrystalDecisions.ReportAppServer.DataDefModel.GroupOptionsConditionFormulas gpOptsContionFormulas; | |
gpOptsContionFormulas = newgroup.Options.ConditionFormulas; | |
gpOptsContionFormulas[CrystalDecisions.ReportAppServer.DataDefModel.CrGroupOptionsConditionFormulaTypeEnum.crGroupName].Text = formula; | |
rptClientDoc.DataDefController.GroupController.Modify(oldGroup, newgroup); | |
return; | |
} | |
i++; | |
} | |
} |
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.