彩票走势图

水晶报表教程:发票套打

转帖|使用教程|编辑:我只采一朵|2014-04-02 11:30:01.000|阅读 2329 次

概述:本文教你如何实现水晶报表套打发票。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

经常有人在论坛里面询问水晶报表套打的问题,比如如何精准打印发票,如何配置报表数据源,如何选择最佳套打方案等等。下面我就来分享一下水晶报表如何套打的一些经验,说得不全面的地方还请见谅。

水晶报表套打一般分为两种情况:

  1. 清单类打印,在已经印刷好的纸张上打印 ;
  2. 单据发票类,单据格式固定,如每张打印5行数据,而且这种格式是已经印刷好的,当然机打发票除外。 

我们以第2种情况为例进行说明,因为第2种会了第1种也自然就明白了。在这里我们使用程序代码+报表中设置背景图片的方式来实现。 

1、纸张尺寸类型很难控制客户端的,那就用A4纸,计算设置较大右边距和下边距,以适合你的单据尺寸;

2、页面设置,精确计算左边距与上边距,放好你需打印的组件与不需打印的组件(Top与Left);

3、窗体上,三个控件:CrystalReport控件CrystalReportViewer控件PrintDialog控件,让CrystalReportViewer控件的ShowPrintButton=false,以免客户从它启动打印;

4、在制作报表的时候,把你不需要打印的部分使用图片代替。

如下图:

水晶报表套打 CrystalReport

使用了图片来代替固定数据。如上图中的“仓储企业名称”等标题。

5、报表打印类:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Easipay.Controls.Printer;

using System.Drawing.Printing;

 

namespace Warehouse.Report

{

    public class ReportAllocateBLM : ReportBase, IPrintReport

    {

        // <summary>

        /// 生成报表对象

        /// </summary>

        /// <returns></returns>

        public object Report()

        {

            return new rptAllocateBLMTHD();

        }

     

        /// <summary>

        /// 打印预览, 设置报表数据的方法:

        /// </summary>

        /// <param name="rpt">报表</param>

        /// <param name="reportData">需要打印的数据</param>

        /// <param name="boolBackgroupPic">是否打印背景图片</param>

        public void PrePrint(ref CrystalDecisions.CrystalReports.Engine.ReportDocument rpt, object reportData, bool boolBackgroupPic)

        {

            ProtionOutHeadReport info = GetDataSet(reportData);

 

            AddBarNo(ref rpt);

 

            rpt.SetDataSource(info);

            System.Drawing.Printing.PrintDocument pd = new PrintDocument();

            System.Drawing.Printing.PaperSize paperSize = new System.Drawing.Printing.PaperSize("ProtionInHeadReport", 827, 1200);

        }

        ///<summary>

        ///生成报表所需要的DataSet

        ///</summary>

        ///<param name="reportData">由界面中传过来的数据</param>

        ///<returns></returns>

        private ProtionOutHeadReport GetDataSet(object reportData)

        {

            ProtionOutHeadReport outBillDs = new ProtionOutHeadReport();

            Easipay.WGQ.Entitys.ProtionOutHead head = reportData as Easipay.WGQ.Entitys.ProtionOutHead;

            if (head != null)

            {

                FillDataTable<Easipay.WGQ.Entitys.ProtionOutHead>(GetHeadList(head), outBillDs.ProtionOutHead);

            }

            if (head.ProtionOutODetail != null)

            {

                FillDataTable<Easipay.WGQ.Entitys.ProtionOutODetail>(GetDetailList(head), outBillDs.ProtionOutODetail);

            }

            if (head.ProtionOutMDetail != null)

            {

                FillDataTable<Easipay.WGQ.Entitys.ProtionOutMDetail>(GetMDetailList(head), outBillDs.ProtionOutMDetail);

            }

            return outBillDs;

        }

        /// <summary>

        /// 获取报表头

        /// </summary>

        /// <param name="head">进区凭单表头信息</param>

        /// <returns></returns>

        private List<Easipay.WGQ.Entitys.ProtionOutHead> GetHeadList(Easipay.WGQ.Entitys.ProtionOutHead head)

        {

            List<Easipay.WGQ.Entitys.ProtionOutHead> list = new List<Easipay.WGQ.Entitys.ProtionOutHead>();

            list.Add(head);

            return list;

        }

        /// <summary>

        /// 获取报表体

        /// </summary>

        /// <param name="head">进区凭单带表体的表头信息类</param>

        /// <returns></returns>

        private List<Easipay.WGQ.Entitys.ProtionOutODetail> GetDetailList(Easipay.WGQ.Entitys.ProtionOutHead head)

        {

            List<Easipay.WGQ.Entitys.ProtionOutODetail> list = new List<Easipay.WGQ.Entitys.ProtionOutODetail>();

            foreach (Easipay.WGQ.Entitys.ProtionOutODetail item in head.ProtionOutODetail)

            {

                list.Add(item);

            }

 

            return list;

        }

        /// <summary>

        /// 获取报表体

        /// </summary>

        /// <param name="head">进区凭单带表体的表头信息类</param>

        /// <returns></returns>

        private List<Easipay.WGQ.Entitys.ProtionOutMDetail> GetMDetailList(Easipay.WGQ.Entitys.ProtionOutHead head)

        {

            string pid = string.Empty;

            List<Easipay.WGQ.Entitys.ProtionOutMDetail> list = new List<Easipay.WGQ.Entitys.ProtionOutMDetail>();

            foreach (Easipay.WGQ.Entitys.ProtionOutMDetail item in head.ProtionOutMDetail)

            {                

                pid = item.pid;

             if (pid=="2")

             {

                 list.Add(item);

             }

                

            }

//每页要打印八条记录,如果不足8条,则补空行

            while (list.Count < 8)

            {

 

                Easipay.WGQ.Entitys.ProtionOutMDetail detail = new Easipay.WGQ.Entitys.ProtionOutMDetail();

                detail.pid = pid;

                System.Threading.Thread.Sleep(1);

          

                detail.id = (DateTime.UtcNow.Ticks % 100000000000).ToString();               

                list.Add(detail);

            }

            return list;

        }

        string m_PrintTypeBarName;

        /// <summary>

        /// 报表打印类型

        /// </summary>

        public string PrintTypeBarName

        {

            get

            {

                if (string.IsNullOrEmpty(m_PrintTypeBarName))

                {

                    return "分拨货物提货单";

                }

                return m_PrintTypeBarName;

                

            }

            set

            {

                m_PrintTypeBarName = value;

            }

        }

    /// <summary>

        /// 按需要隐藏报表上的某些控件,这里隐藏的都是图片控件,其他的可以自行添加:

        /// </summary>

 

        public void HidePicture(ref CrystalDecisions.CrystalReports.Engine.ReportDocument rpt)

        {

            try

            {

                foreach (CrystalDecisions.CrystalReports.Engine.Section section in rpt.ReportDefinition.Sections)

                {

                    foreach (CrystalDecisions.CrystalReports.Engine.ReportObject rptObject in section.ReportObjects)

                    {

                        if (rptObject is CrystalDecisions.CrystalReports.Engine.PictureObject)

                        {

                            //图片背景

                            (rptObject as CrystalDecisions.CrystalReports.Engine.PictureObject).ObjectFormat.EnableSuppress = true;

                        }

                    }

                }

 

            }

            catch

            {

            }

        }

 

    }

}

6、打印方法:

/// <summary>

/// 打印报表

/// </summary>

/// <param name="strPrintName">打印机名称</param>

/// <param name="shInt">打印份数</param>

/// <returns>true成功,false失败</returns>

private bool blnPrint(string strPrintName,string shInt)

{

bool blnPrintScuss=false;

int intCopies=0;

try

{

intCopies=int.Parse(shInt);

}

catch

{

intCopies=1;

}

try

{

                if (ipr == null)

                {                  

                    MessageBox.Show("打印报表出错");

                    blnPrintScuss = false;

                    return blnPrintScuss;

                }

// m_BillNewRpt.PrintOptions.PaperSize=CrystalDecisions.Shared.PaperSize.PaperA4;

                ipr.HidePicture(ref m_BillNewRpt);

m_BillNewRpt.PrintOptions.PrinterName = strPrintName;

m_BillNewRpt.PrintToPrinter(intCopies,false,1,m_intMaxPage);

blnPrintScuss=true;

}

catch (Exception ex)

{

blnPrintScuss=false;

MessageBox.Show("打印报表出错:"+ex.Message);

}

return blnPrintScuss;

}

7、套打,只打印数据的效果。如下图:

水晶报表套打 CrystalReport

8、非套打,全部打印的效果。如下图:

水晶报表套打 CrystalReport

转自://www.cnblogs.com/chillsrc/p/3577290.html


标签:水晶报表

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@capbkgr.cn

文章转载自:慧都控件

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP