使用CrystalActiveXReportViewer 进行预览的
Pull模式,数据源为CRAXDRT.Report没有问题 public void Print_Pull()
{
SAPbouiCOM.Form oFormPrint = null ;
SAPbouiCOM.Item oItem = null;
SAPbouiCOM.ActiveX ax = null; Application app = null;
Report report = null;
CrystalActiveXReportViewer CAXView = null; string rptFile = @"D:\CReport_Pull.rpt";
try
{
report = new Report();
app = new Application();
oFormPrint = Globals.SBO_Application.Forms.Add("FrmReport", SAPbouiCOM.BoFormTypes.ft_Sizable, 100100);
// set the form properties
oFormPrint.Title = "Print Preview Form";
oFormPrint.Left = 300;
oFormPrint.Top = 50;
oFormPrint.ClientHeight = 600;
oFormPrint.ClientWidth = 800; oItem = oFormPrint.Items.Add("atx", SAPbouiCOM.BoFormItemTypes.it_ACTIVE_X);
oItem.Top = 0;
oItem.Left = 0;
oItem.Width = oFormPrint.Width;
oItem.Height = oFormPrint.Height;
oItem.Visible = true;
ax = (SAPbouiCOM.ActiveX)oItem.Specific; ax.ClassID = "CrystalReports115.ActiveXReportViewer.1"; //CrystalReports11.ActiveXReportViewer.1 CAXView = (CrystalActiveXReportViewer)ax.Object; }
catch (Exception ex)
{
oFormPrint.Close();
Console.WriteLine(ex.Message);
} //add crystall report
try
{
report = app.OpenReport(rptFile, 1); foreach (CRAXDRT.DatabaseTable dob_Table in report.Database.Tables)
{
dob_Table.SetLogOnInfo("127.0.0.1", "GY2007", "sa", "qwer");
} //Print Preview
CAXView.ReportSource = report ; CAXView.DisplayGroupTree = false; CAXView.ViewReport(); oFormPrint.Visible = true; Globals.showStatsMsg("打印完成!", 1); }
catch (Exception ex)
{
oFormPrint.Close();
Console.WriteLine(ex.Message);
} }
但是Push模式,好像都是绑定的ReportDocument的,设置数据源时出现错误了
// Push模式:由查询语句生成数据,填充数据源
// CrystalDecisions.CrystalReports.Engine.ReportDocument
public void showForm1()
{
SAPbouiCOM.Form oFormPrint = null;
SAPbouiCOM.Item oItem = null;
SAPbouiCOM.ActiveX ax = null; ReportDocument oRptDoc = null;
Report report = null;
CrystalActiveXReportViewer CAXView = null; string rptFile = @"D:\CReport_Pull.rpt"; try
{ oRptDoc = new ReportDocument();
report = new Report(); oFormPrint = Globals.SBO_Application.Forms.Add("FrmReport", SAPbouiCOM.BoFormTypes.ft_Sizable, 100100);
// set the form properties
oFormPrint.Title = "Print Preview Form";
oFormPrint.Left = 300;
oFormPrint.Top = 50;
oFormPrint.ClientHeight = 600;
oFormPrint.ClientWidth = 800; oItem = oFormPrint.Items.Add("atx", SAPbouiCOM.BoFormItemTypes.it_ACTIVE_X);
oItem.Top = 0;
oItem.Left = 0;
oItem.Width = oFormPrint.Width;
oItem.Height = oFormPrint.Height;
oItem.Visible = true;
ax = (SAPbouiCOM.ActiveX)oItem.Specific; ax.ClassID = "CrystalReports115.ActiveXReportViewer.1"; //CrystalReports11.ActiveXReportViewer.1 CAXView = (CrystalActiveXReportViewer)ax.Object;
}
catch (Exception ex)
{
oFormPrint.Close();
Console.WriteLine(ex.Message);
} try
{
oRptDoc.Load(rptFile); if (ConnDB())
{
oCommand.CommandText = @"SELECT U_ITEMSN, U_CHECKID, U_CAUSE FROM [@CHECKUP]"; SqlDataAdapter sda = new SqlDataAdapter(oCommand); DataSet dataSet = new DataSet(); sda.Fill(dataSet, "CHECKUP"); oRptDoc.SetDataSource(dataSet.Tables[0]); //report.p
} //Print Preview
CAXView.ReportSource = oRptDoc; //在这里出错! CAXView.DisplayGroupTree = false; CAXView.ViewReport(); oFormPrint.Visible = true; Globals.showStatsMsg("打印完成!", 1); }
catch (Exception ex)
{
oFormPrint.Close();
Console.WriteLine(ex.Message);
} }
请问:Report与ReportDocument有什么区别呢,能不能做转换呀? 如何设置CrystalActiveXReportViewer的数据源呀? 谢谢
Pull模式,数据源为CRAXDRT.Report没有问题 public void Print_Pull()
{
SAPbouiCOM.Form oFormPrint = null ;
SAPbouiCOM.Item oItem = null;
SAPbouiCOM.ActiveX ax = null; Application app = null;
Report report = null;
CrystalActiveXReportViewer CAXView = null; string rptFile = @"D:\CReport_Pull.rpt";
try
{
report = new Report();
app = new Application();
oFormPrint = Globals.SBO_Application.Forms.Add("FrmReport", SAPbouiCOM.BoFormTypes.ft_Sizable, 100100);
// set the form properties
oFormPrint.Title = "Print Preview Form";
oFormPrint.Left = 300;
oFormPrint.Top = 50;
oFormPrint.ClientHeight = 600;
oFormPrint.ClientWidth = 800; oItem = oFormPrint.Items.Add("atx", SAPbouiCOM.BoFormItemTypes.it_ACTIVE_X);
oItem.Top = 0;
oItem.Left = 0;
oItem.Width = oFormPrint.Width;
oItem.Height = oFormPrint.Height;
oItem.Visible = true;
ax = (SAPbouiCOM.ActiveX)oItem.Specific; ax.ClassID = "CrystalReports115.ActiveXReportViewer.1"; //CrystalReports11.ActiveXReportViewer.1 CAXView = (CrystalActiveXReportViewer)ax.Object; }
catch (Exception ex)
{
oFormPrint.Close();
Console.WriteLine(ex.Message);
} //add crystall report
try
{
report = app.OpenReport(rptFile, 1); foreach (CRAXDRT.DatabaseTable dob_Table in report.Database.Tables)
{
dob_Table.SetLogOnInfo("127.0.0.1", "GY2007", "sa", "qwer");
} //Print Preview
CAXView.ReportSource = report ; CAXView.DisplayGroupTree = false; CAXView.ViewReport(); oFormPrint.Visible = true; Globals.showStatsMsg("打印完成!", 1); }
catch (Exception ex)
{
oFormPrint.Close();
Console.WriteLine(ex.Message);
} }
但是Push模式,好像都是绑定的ReportDocument的,设置数据源时出现错误了
// Push模式:由查询语句生成数据,填充数据源
// CrystalDecisions.CrystalReports.Engine.ReportDocument
public void showForm1()
{
SAPbouiCOM.Form oFormPrint = null;
SAPbouiCOM.Item oItem = null;
SAPbouiCOM.ActiveX ax = null; ReportDocument oRptDoc = null;
Report report = null;
CrystalActiveXReportViewer CAXView = null; string rptFile = @"D:\CReport_Pull.rpt"; try
{ oRptDoc = new ReportDocument();
report = new Report(); oFormPrint = Globals.SBO_Application.Forms.Add("FrmReport", SAPbouiCOM.BoFormTypes.ft_Sizable, 100100);
// set the form properties
oFormPrint.Title = "Print Preview Form";
oFormPrint.Left = 300;
oFormPrint.Top = 50;
oFormPrint.ClientHeight = 600;
oFormPrint.ClientWidth = 800; oItem = oFormPrint.Items.Add("atx", SAPbouiCOM.BoFormItemTypes.it_ACTIVE_X);
oItem.Top = 0;
oItem.Left = 0;
oItem.Width = oFormPrint.Width;
oItem.Height = oFormPrint.Height;
oItem.Visible = true;
ax = (SAPbouiCOM.ActiveX)oItem.Specific; ax.ClassID = "CrystalReports115.ActiveXReportViewer.1"; //CrystalReports11.ActiveXReportViewer.1 CAXView = (CrystalActiveXReportViewer)ax.Object;
}
catch (Exception ex)
{
oFormPrint.Close();
Console.WriteLine(ex.Message);
} try
{
oRptDoc.Load(rptFile); if (ConnDB())
{
oCommand.CommandText = @"SELECT U_ITEMSN, U_CHECKID, U_CAUSE FROM [@CHECKUP]"; SqlDataAdapter sda = new SqlDataAdapter(oCommand); DataSet dataSet = new DataSet(); sda.Fill(dataSet, "CHECKUP"); oRptDoc.SetDataSource(dataSet.Tables[0]); //report.p
} //Print Preview
CAXView.ReportSource = oRptDoc; //在这里出错! CAXView.DisplayGroupTree = false; CAXView.ViewReport(); oFormPrint.Visible = true; Globals.showStatsMsg("打印完成!", 1); }
catch (Exception ex)
{
oFormPrint.Close();
Console.WriteLine(ex.Message);
} }
请问:Report与ReportDocument有什么区别呢,能不能做转换呀? 如何设置CrystalActiveXReportViewer的数据源呀? 谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货