on 02-28-2008 9:21 PM
I am about to start work on a adhoc report designer which will allow users to create simple reports from scratch through a browser. This facility has to support cross-tab reports.
Are there any examples of programmatically creating cross-tab reports using the Crystal api?
Thanks
Mark
Hello Mark,
please use this code belwo to add a chart programatically :
This code uses inproc RAS in VS 2005
//********************************************************************
//File Name: CS__Add_Chart_inproc.sln
//Created: March 29, 2008
//Author ID: FLI
//
//Purpose: This C# .NET sample Windows application demonstrates
// how to add a chart in the report header
// using unmanaged RAS.
//
// Note this is available without a dedicated RAS with SP2 for XI R2
//********************************************************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.ReportAppServer.ClientDoc;
namespace CS_Add_Chart_inproc
{
public partial class Form1 : Form
{
ReportDocument boReportDocument;
ISCDReportClientDocument boReportClientDocument;
CrystalDecisions.ReportAppServer.ReportDefModel.ChartObject boChartObject;
CrystalDecisions.ReportAppServer.ReportDefModel.ChartStyle boChartStyle;
CrystalDecisions.ReportAppServer.ReportDefModel.Section boSection;
CrystalDecisions.ReportAppServer.DataDefModel.Fields boFields;
CrystalDecisions.ReportAppServer.DataDefModel.Field boField;
CrystalDecisions.ReportAppServer.DataDefModel.SummaryField boSummaryField;
int boFieldIndex;
public Form1()
{
InitializeComponent();
//Create a new ReportDocument
boReportDocument = new ReportDocument();
// load the RPT file
boReportDocument.Load("..
..
AddChart.rpt");
// set condition for display
boReportDocument.RecordSelectionFormula = "{Customer.Last Year's Sales}>250000";
/*
//Access the ReportClientDocument in the ReportDocument (EROM bridge)
boReportClientDocument = boReportDocument.ReportClientDocument;
boFields = boReportClientDocument.DatabaseController.Database.Tables[0].DataFields;
//Create a chart
boChartObject = new CrystalDecisions.ReportAppServer.ReportDefModel.ChartObject();
//create a bar chart style
boChartStyle = new CrystalDecisions.ReportAppServer.ReportDefModel.ChartStyle();
boChartStyle.Type = CrystalDecisions.ReportAppServer.ReportDefModel.CrChartStyleTypeEnum.crChartStyleTypeBar;
//set the chart style to bar chart
boChartObject.ChartStyle = boChartStyle;
//set the chart type to advanced chart
boChartObject.ChartDefinition.ChartType = CrystalDecisions.ReportAppServer.ReportDefModel.CrChartTypeEnum.crChartTypeDetail;
//set Customer Name field as condition field
//get the Customer Name field
boFieldIndex = boFields.Find("Customer Name",
CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName,
CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);
boField = (CrystalDecisions.ReportAppServer.DataDefModel.Field)boFields[boFieldIndex];
boChartObject.ChartDefinition.ConditionFields.Add(boField);
boField = null;
//set Last Year's Sales as data field
//get {Customer.Last Year's Sales field}
boFieldIndex = boFields.Find("Last Year's Sales",
CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName,
CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);
boField = (CrystalDecisions.ReportAppServer.DataDefModel.Field)boFields[boFieldIndex];
//create a Sum({Customer.Last Year's Sales})
boSummaryField = new CrystalDecisions.ReportAppServer.DataDefModel.SummaryField();
boSummaryField.SummarizedField = boField;
boSummaryField.Operation = CrystalDecisions.ReportAppServer.DataDefModel.CrSummaryOperationEnum.crSummaryOperationSum;
boSummaryField.Type = boField.Type;
//add summary field to report client document
boReportClientDocument.DataDefController.SummaryFieldController.Add(-1, boSummaryField);
boChartObject.ChartDefinition.DataFields.Add(boSummaryField);
//set chart coordinates and dimensions (0, 0), width = 7 inches, height = 5 inches
boChartObject.Left = 0;
boChartObject.Top = 0;
boChartObject.Width = 7 * 1440; // 1 inch = 1440 twips
boChartObject.Height = 5 * 1440;
//get report header section
boSection = boReportClientDocument.ReportDefinition.ReportHeaderArea.Sections[0];
//set chart report area to report header
boChartObject.ChartReportArea = CrystalDecisions.ReportAppServer.ReportDefModel.CrAreaSectionKindEnum.crAreaSectionKindReportHeader;
//add chart in the report header
boReportClientDocument.ReportDefController.ReportObjectController.Add(boChartObject, boSection, -1);
*/
// show in reportviewer
crystalReportViewer1.ReportSource = boReportDocument;
}
private void button1_Click(object sender, EventArgs e)
{
//Access the ReportClientDocument in the ReportDocument (EROM bridge)
boReportClientDocument = boReportDocument.ReportClientDocument;
boFields = boReportClientDocument.DatabaseController.Database.Tables[0].DataFields;
//Create a chart
boChartObject = new CrystalDecisions.ReportAppServer.ReportDefModel.ChartObject();
//create a bar chart style
boChartStyle = new CrystalDecisions.ReportAppServer.ReportDefModel.ChartStyle();
boChartStyle.Type = CrystalDecisions.ReportAppServer.ReportDefModel.CrChartStyleTypeEnum.crChartStyleTypeBar;
//set the chart style to bar chart
boChartObject.ChartStyle = boChartStyle;
//set the chart type to advanced chart
boChartObject.ChartDefinition.ChartType = CrystalDecisions.ReportAppServer.ReportDefModel.CrChartTypeEnum.crChartTypeDetail;
//set Customer Name field as condition field
//get the Customer Name field
boFieldIndex = boFields.Find("Customer Name",
CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName,
CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);
boField = (CrystalDecisions.ReportAppServer.DataDefModel.Field)boFields[boFieldIndex];
boChartObject.ChartDefinition.ConditionFields.Add(boField);
boField = null;
//set Last Year's Sales as data field
//get {Customer.Last Year's Sales field}
boFieldIndex = boFields.Find("Last Year's Sales",
CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameName,
CrystalDecisions.ReportAppServer.DataDefModel.CeLocale.ceLocaleUserDefault);
boField = (CrystalDecisions.ReportAppServer.DataDefModel.Field)boFields[boFieldIndex];
//create a Sum({Customer.Last Year's Sales})
boSummaryField = new CrystalDecisions.ReportAppServer.DataDefModel.SummaryField();
boSummaryField.SummarizedField = boField;
boSummaryField.Operation = CrystalDecisions.ReportAppServer.DataDefModel.CrSummaryOperationEnum.crSummaryOperationSum;
boSummaryField.Type = boField.Type;
//add summary field to report client document
boReportClientDocument.DataDefController.SummaryFieldController.Add(-1, boSummaryField);
boChartObject.ChartDefinition.DataFields.Add(boSummaryField);
//set chart coordinates and dimensions (0, 0), width = 7 inches, height = 5 inches
boChartObject.Left = 0;
boChartObject.Top = 0;
boChartObject.Width = 7 * 1440; // 1 inch = 1440 twips
boChartObject.Height = 5 * 1440;
//get report header section
boSection = boReportClientDocument.ReportDefinition.ReportHeaderArea.Sections[0];
//set chart report area to report header
boChartObject.ChartReportArea = CrystalDecisions.ReportAppServer.ReportDefModel.CrAreaSectionKindEnum.crAreaSectionKindReportHeader;
//add chart in the report header
boReportClientDocument.ReportDefController.ReportObjectController.Add(boChartObject, boSection, -1);
// show in reportviewer
crystalReportViewer1.ReportSource = boReportDocument;
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
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.