金质打印通 示例 zt

《金质打印通》03年开始第一版,然后到V2.5源码版,好多年了,从06年之后基本没动。

 

做了一个订单自定义打印,于是做出如下效果来。

 

达到如下效果有两种方式:

1、用模板打印方式,支持XML

2、用程序方式

3、模板+程序方式

 

为了全大家理解打印的组成部分,特用图标作了说明。

现把实现方式,分享给大家!

 

金质打印通单据打印

 

附代码,需要的朋友可以参考。

注意:

如上效果,除了标题头前的那个图标,是在新增事件OnDrawPageSetup实现外,所有功能,在6年前共享的《金质打印通》之AnyReport下,完全一样。

 

  1. //调用金质打印通预览打印  
  2.  private void CallGoldPrinter(bool viewOrPrint)  
  3.  {  
  4.   
  5.      //打印表格,实质,就是打印二维数据  
    1.     string[,] gridText = new string[this.DetailGrids[0].Rows.Count, 8];  
    2.   
    3.    for (int i = 0; i < this.DetailGrids[0].Rows.Count; i++)  
    4.    {  
    5.        if (i < this.DetailGrids[0].Rows.Count - 1)  
    6.        {  
    7.            gridText[i, 0] = (i + 1).ToString();  
    8.        }  
    9.        else  
    10.        {  
    11.            gridText[i, 0] = "合计";                  
    12.        }  
    13.        gridText[i, 1] = this.DetailGrids[0].Rows[i].Cells["品牌"].Text.ToString();  
    14.        gridText[i, 2] = this.DetailGrids[0].Rows[i].Cells["国标型号"].Text.ToString();  
    15.        gridText[i, 3] = this.DetailGrids[0].Rows[i].Cells["数量"].Text.ToString();  
    16.        gridText[i, 4] = this.DetailGrids[0].Rows[i].Cells["含税单价"].Text.ToString();  
    17.        gridText[i, 5] = this.DetailGrids[0].Rows[i].Cells["含税金额"].Text.ToString();  
    18.        gridText[i, 6] = this.DetailGrids[0].Rows[i].Cells["到货周期"].Text.ToString();  
    19.        gridText[i, 7] = this.DetailGrids[0].Rows[i].Cells["小注"].Text.ToString();  
    20.    }  
    21.   
    22.     //清单、单据打印类  
    23.     GoldPrinter.GoldPrinterList gpl = new GoldPrinter.GoldPrinterList();  
    24.     //事件,方便自定义打印  
    25.     gpl.OnDrawPageSetup += new EventHandler<GoldPrinter.DrawPageSetupEventArgs>(gpl_OnDrawPageSetup);  
    26.   
    27.     gpl.PageSetupManager.ShowPrinterArea = false;  //指定画可参考有效区域  
    28.     gpl.PageSetupManager.PageMargins = new System.Drawing.Printing.Margins(50, 50, 50, 50);  //页边距  
    29.   
    30.     gpl.DocumentName = "采购订单打印";  
    31.     gpl.PageBreakSuperCols = true;                          //是否因列超宽分页  
    32.     gpl.DefaultRowHeight = 25;                              //明细行高  
    33.     gpl.PageSize = 10;                                     //每页指定打多少行  
    34.     gpl.AllowPadEmptyLines = true;                         //不够PageSize,刚空行填充  
    35.  
    36.     #region 主子标题...  
    37.   
    38.     gpl.PageSetupManager.PrimaryTitle.Text = "北京元六鸿远电子技术有限公司";  
    39.     gpl.PageSetupManager.PrimaryTitle.Font = new Font("华文行楷", 22, FontStyle.Bold);  
    40.     gpl.PageSetupManager.PrimaryTitle.BorderFormat.BordersEdge = GoldPrinter.Drawing.BorderEdgeFlags.None;  
    41.     //gpl.PageSetupManager.PrimaryTitle.LineCount = 0;   //主标题下划线,默认2条  
    42.   
    43.     gpl.PageSetupManager.SubTitle.Text = "采 购 订 单";  
    44.     gpl.PageSetupManager.SubTitle.Font = new Font("华文中宋", 16, FontStyle.Bold);  
    45.     gpl.PageSetupManager.SubTitle.BorderFormat.BordersEdge = GoldPrinter.Drawing.BorderEdgeFlags.None;  
    46.  
    47.     #endregion 主子标题...  
    48.   
    49.   
    50.     //多层表头  
    51.     gpl.TableTitleRowHeight = 35;  
    52.  
    53.     #region 表格标题(多层表头)...  
    54.     gpl.TableTitleText = new string[1, 8];  
    55.   
    56.     gpl.TableTitleText[0, 0] = "序号";  
    57.     gpl.TableTitleText[0, 1] = "品牌";  
    58.     gpl.TableTitleText[0, 2] = "型号规格";  
    59.     gpl.TableTitleText[0, 3] = "数量(支)";  
    60.     gpl.TableTitleText[0, 4] = "含税单价(元)";  
    61.     gpl.TableTitleText[0, 5] = "含税金额(元)";  
    62.     gpl.TableTitleText[0, 6] = "到货周期";  
    63.     gpl.TableTitleText[0, 7] = "备注";  
    64.  
    65.     #endregion 表格标题(多层表头)...  
    66.   
    67.   
    68.     //表格主体明细  
    69.     gpl.TableText = gridText;  
    70.     gpl.TableFormat.TextFormat.Font = new Font("华文中宋", 11);  
    71.     gpl.TableInfo.ColsAlignment = new GoldPrinter.Drawing.HAlignFlag[] { GoldPrinter.Drawing.HAlignFlag.Right, GoldPrinter.Drawing.HAlignFlag.Left, GoldPrinter.Drawing.HAlignFlag.Left, GoldPrinter.Drawing.HAlignFlag.Right, GoldPrinter.Drawing.HAlignFlag.Right, GoldPrinter.Drawing.HAlignFlag.Right, GoldPrinter.Drawing.HAlignFlag.Left, GoldPrinter.Drawing.HAlignFlag.Left };  
    72.     //gpl.TableInfo.ColsAlignment = GoldPrinter.Drawing.HAlignFlag[]  
    73.     //{GoldPrinter.Drawing.HAlignFlag.Left,GoldPrinter.Drawing.HAlignFlag.Left,GoldPrinter.Drawing.HAlignFlag.Right,GoldPrinter.Drawing.HAlignFlag.Left,GoldPrinter.Drawing.HAlignFlag.Right,GoldPrinter.Drawing.HAlignFlag.Left,GoldPrinter.Drawing.HAlignFlag.Right};  
    74.   
    75.     //装订线  
    76.     gpl.PageSetupManager.Gutter.Text = "元     六     订     单     装     订     线";  
    77.   
    78.     //页眉  
    79.     #region 页眉...  
    80.   
    81.     gpl.PageSetupManager.HeaderMargin = 20;  
    82.     gpl.PageHeader.Align = GoldPrinter.Drawing.HAlignFlag.Right;  
    83.     gpl.PageHeader.LineVisible = false;  
    84.     gpl.PageHeader.Font = new Font("华文中宋", 11);  
    85.     gpl.PageHeader.Text = "文件号:YL-JL-JH-010-2011";  
    86.  
    87.     #endregion 页眉...  
    88.   
    89.     //页脚  
    90.     #region 页脚...  
    91.   
    92.     gpl.PageSetupManager.FooterMargin = 20;  
    93.     gpl.PageFooter.Align = GoldPrinter.Drawing.HAlignFlag.Center;  
    94.     gpl.PageHeader.LineVisible = false;  
    95.     gpl.PageFooter.Font = new Font("华文中宋", 11);  
    96.     gpl.PageFooter.Text = "第[@PageIndex]页/共[@PageCount]页";  
    97.  
    98.     #endregion 页脚...  
    99.   
    100.     GoldPrinter.TablePrinterBase header = new GoldPrinter.TablePrinterBase();  
    101.   
    102.     //表头个数不限,因此,无论是几行几列,是否规则,都可以打印  
    103.     #region 表头...  
    104.   
    105.     gpl.PageSetupManager.SubTitle.Font = new Font("华文中宋", 12);  
    106.   
    107.     header.TableText = new string[5, 4];  
    108.     header.TableFormat.DefaultRowHeight = 30;  
    109.     header.TableFormat.TextFormat.Font = new Font("华文中宋", 12);  
    110.   
    111.   
    112.     header.TableInfo.ColsWidth = new int[] { 100,250,100,250};  
    113.     header.TableFormat.GridLines = GoldPrinter.Drawing.GridLineFlag.None;  
    114.   
    115.     header.TableText[0, 0] = "订货日期:";  
    116.     header.TableText[1, 0] = "供方单位:";  
    117.     header.TableText[2, 0] = "供方联系人:";  
    118.     header.TableText[3, 0] = "供方电话:";  
    119.     header.TableText[4, 0] = "供方传真:";  
    120.   
    121.     header.TableText[0, 1] = "";  
    122.     header.TableText[1, 1] = "";  
    123.     header.TableText[2, 1] = "";  
    124.     header.TableText[3, 1] = "";  
    125.     header.TableText[4, 1] = "";  
    126.   
    127.     header.TableText[0, 2] = "订单号:";  
    128.     header.TableText[1, 2] = "需方单位:";  
    129.     header.TableText[2, 2] = "需方联系人:";  
    130.     header.TableText[3, 2] = "需方电话:";  
    131.     header.TableText[4, 2] = "需方传真:";  
    132.   
    133.     header.TableText[0, 3] = "";  
    134.     header.TableText[1, 3] = "";  
    135.     header.TableText[2, 3] = "";  
    136.     header.TableText[3, 3] = "";  
    137.     header.TableText[3, 3] = "";  
    138.  
    139.     #endregion 表头...  
    140.     gpl.AddTableHeader(header);  
    141.   
    142.     //页底签字  
    143.     GoldPrinter.TablePrinterBase footer = null;  
    144.   
    145.     //表底,个数不限  
    146.     gpl.ColsWidth = new int[] { 40, 70, 230, 70, 95, 95, 70, 40 };  //列宽  
    147.   
    148.     gpl.SpaceTableBodyFooter = 0;   //金额大写与明细表,合为一体  
    149.  
    150.     #region 表底(包括金额合计大写)...  
    151.   
    152.     //金额合计  
    153.     footer = new GoldPrinter.TablePrinterBase();  
    154.     footer.TableFormat.TextFormat.Font = new Font("华文中宋", 12, FontStyle.Bold);  
    155.     footer.TableText = new string[1, 2];  
    156.     footer.TableFormat.DefaultRowHeight = 30;  
    157.   
    158.     footer.TableInfo.ColsWidth = new int[] { 40+70+230+ 70, 95+95+70+40 };  //列宽  
    159.     footer.TableInfo.ColsAlignment = new GoldPrinter.Drawing.HAlignFlag[] { GoldPrinter.Drawing.HAlignFlag.Center, GoldPrinter.Drawing.HAlignFlag.Center };  
    160.   
    161.     footer.TableText[0, 0] = "金额大小";  
    162.   
    163.     if (this.DetailGrids[0].Rows.Count > 2 && this.DetailGrids[0].Rows[(this.DetailGrids[0].Rows.Count - 1)].Cells["含税金额"].Text != "")  
    164.     {  
    165.         footer.TableText[0, 1] = GoldPrinter.ChineseNum.GetUpperMoney(double.Parse(this.DetailGrids[0].Rows[(this.DetailGrids[0].Rows.Count - 1)].Cells["含税金额"].Text.ToString()));  
    166.     }  
    167.     else  
    168.     {  
    169.         footer.TableText[0, 1] = "";  
    170.     }  
    171.       
    172.     gpl.AddTableFooter(footer);  
    173.  
    174.     #region 页底签字...  
    175.     footer = new GoldPrinter.TablePrinterBase();  
    176.     footer.TableFormat.TextFormat.Font = new Font("华文中宋", 12, FontStyle.Bold);  
    177.     footer.TableText = new string[7, 2];  
    178.     footer.TableFormat.DefaultRowHeight = 30;  
    179.     footer.TableFormat.GridLines = GoldPrinter.Drawing.GridLineFlag.None;  
    180.     footer.IsAverageColsWidth = true;  
    181.     footer.TableText[0, 0] = "供方签字:";  
    182.     footer.TableText[1, 0] = "";  
    183.     footer.TableText[2, 0] = "";  
    184.     footer.TableText[3, 0] = "________________________";  
    185.     footer.TableText[4, 0] = "";  
    186.     footer.TableText[5, 0] = "";  
    187.     footer.TableText[6, 0] = "________________________";  
    188.   
    189.     footer.TableText[0, 1] = "需方签字:";  
    190.     footer.TableText[1, 1] = "";  
    191.     footer.TableText[2, 1] = "制单人:________________________";  
    192.     footer.TableText[3, 1] = "";  
    193.     footer.TableText[4, 1] = "审核人:________________________";  
    194.     footer.TableText[5, 1] = "";  
    195.     footer.TableText[6, 1] = "批准人:________________________";  
    196.     gpl.AddTableFooter(footer);  
    197.     #endregion 页底签字...  
    198.   
    199.     //页底 (备注)  
    200.     #region 页底备注...  
    201.     //GoldPrinter.TablePrinterBase = null;                   
    202.     footer = new GoldPrinter.TablePrinterBase();  
    203.     footer.TableFormat.TextFormat.Font = new Font("华文中宋", 12);  
    204.     footer.TableText = new string[10, 1];  
    205.     footer.TableFormat.DefaultRowHeight = 30;  
    206.     footer.TableFormat.GridLines = GoldPrinter.Drawing.GridLineFlag.None;  
    207.     footer.IsAverageColsWidth = true;        //只有一列,用平均宽,就是有效页宽了  
    208.     footer.TableText[0, 0] = "备注:";  
    209.     footer.TableText[1, 0] = "   1 合同签订地点及交货地点:需方所在地。";  
    210.     footer.TableText[2, 0] = "   2 运费负担:供方承担运费。";  
    211.     footer.TableText[3, 0] = "   3 产品包装:原厂包装。";  
    212.     footer.TableText[4, 0] = "   4 质量标准:产品质量必须符合相应品牌标准。";  
    213.     footer.TableText[5, 0] = "   5 付款方式:预付/货到付款。";  
    214.     footer.TableText[6, 0] = "   6 开具发票:以上单价含17%增值税,供方开具正规合法增值税发票。";  
    215.     footer.TableText[7, 0] = "   7 质量保证:如出现质量问题,由供方负责调换或退货,并承担相应的费用。";  
    216.     footer.TableText[8, 0] = "   8 违约责任:双方友好协商解决,协商未果依照中华人民共和国合同法执行。";  
    217.     footer.TableText[9, 0] = "   9 本合同一式两份,自签订之日起生效,传真件有效。";  
    218.     gpl.AddTableFooter(footer);  
    219.     #endregion 页底备注...  
    220.  
    221.     #endregion 表底...  
    222.   
    223.     if (viewOrPrint)  
    224.     {  
    225.         gpl.ShowPreview();  
    226.     }  
    227.     else  
    228.     {  
    229.         gpl.Print();  
    230.     }  
    231. }  
    232.   
    233. void gpl_OnDrawPageSetup(object sender, GoldPrinter.DrawPageSetupEventArgs e)  
    234. {  
    235.     System.Drawing.Image img = null;  
    236.     System.Drawing.Graphics g = e.Graphics;  
    237.   
    238.     img = System.Drawing.Image.FromFile("Images\\UserLogo.bmp");  
    239.   
    240.     g.DrawImage(img,125,50);  

posted on 2013-03-20 18:59  武胜-阿伟  阅读(1581)  评论(3编辑  收藏  举报