之前做的报表打印,现在发现不能用了, 提示对象为空,不清除是哪里问题,调用代码如下,帮我看一看,
private void tsbPrint_Click(object sender, EventArgs e)
{
string strID = "ABC";
int[] i={1,2};
DataTable dt = operMM.GetDataSetPartPrint(strID).Tables[0];
C1Report rt = new C1Report();
//c1RibbonPreview1.Document = rt= CreateReport(dt);
rt = CreateReport(dt);
PrinterSettings pSet = new PrinterSettings();
pSet.DefaultPageSettings.Landscape = true;//横向打印
//rt.Layout.Orientation = OrientationEnum.Landscape;//横向打印
//pSet.DefaultPageSettings.Landscape = false;//纵向打印
//rt.Layout.Orientation = OrientationEnum.Portrait;//纵向打印
// rt.RenderToFile("d:\\GoodsTitle.pdf", FileFormatEnum.PDF);//打印到pdf
//rt.PrintDialog(pSet, i, true); //出现打印窗体
//rt.Print(pSet); //直接打印
c1PrintPreviewDialog1.Document=rt;
c1PrintPreviewDialog1.ShowDialog();
// C1.Win.C1Preview.C1PrintPreviewDialog pd = new C1.Win.C1Preview.C1PrintPreviewDialog();
// pd.PrintPreviewControl.ToolBars.File.PrintLayout.Visible = true;
// pd.PrintPreviewControl.ToolBars.File.PrintLayout.Enabled = true;
//......
// pd.Document = _c1r;
// pd.ShowDialog();
}
internal virtual C1Report CreateReport(object t)
{
try
{
C1Report _c1r = new C1Report();
//加载报表
//string[] files = Directory.GetFiles(@"..\..\ReportsC1", "*.xml");
//Application.StartupPath
string[] files = Directory.GetFiles(Application.StartupPath+@"\ReportsC1", "*.xml");
string _file = files[0];
_c1r.Load(_file, "Goods");
//给明细数据赋值
_c1r.DataSource.Recordset = t;
//报表是否分页(网格线)
// if (_ps.IsPaged == 1)
// _c1r.RecordsPerPage = _ps.PageSize;
//页面设置
Layout _layout = _c1r.Layout;
_layout.PaperSize = (System.Drawing.Printing.PaperKind)0;
//自定义纸张时,纸张的大小
//if (_layout.PaperSize == System.Drawing.Printing.PaperKind.Custom)
//{
// _layout.CustomWidth = 12237;
// _layout.CustomHeight = 6969;
//}
_layout.Orientation = (OrientationEnum)1;
//页边距
_layout.MarginTop = 0;
_layout.MarginBottom = 0;
_layout.MarginLeft = 0;
_layout.MarginRight = 0;
return _c1r;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return null;
}
}
另外,新建一个新项目新窗体,拖放一个C1PrintPreviewControl和C1PrintPreviewDialog都出现类似的错误,不知道是什么原因,是产品安装有问题还是没有授权呀
|