发票管理及打印系统的部分代码

时间:2024-04-17 11:05:23

这里是发票管理及打印系统的部分代码,不才,献丑了,有需要的可以参考一下 

 代码

        PrinterSettings printerSets = new PrinterSettings();
        PageSettings pageSets 
= new PageSettings();

       
private void printdoc_PrintPage(object sender, PrintPageEventArgs e)
        {
            XmlDocument _xdoc 
= new XmlDocument();
            _xdoc.LoadXml(
this.printFaPiaoXml);

            PrintDrawString(e, 
065, _xdoc.SelectSingleNode("/row/开票日期").InnerText.Trim());
            PrintDrawString(e, 
0275, fapiaoSets.行业);

            PrintDrawString(e, 
20"付款方:" + _xdoc.SelectSingleNode("/row/付款方").InnerText.Trim()); //河南新互联通信服务咨询有限公司
            PrintDrawString(e, 2370"付款方纳税人识别号:" + _xdoc.SelectSingleNode("/row/付款方税号").InnerText.Trim());
            PrintDrawString(e, 
30"收款方:" + fapiaoSets.收款方);
            PrintDrawString(e, 
3370"收款方纳税人识别号:" + fapiaoSets.收款方税号);

            PrintDrawString(e, 
40"项目明细");
            PrintDrawString(e, 
50"项目");
            PrintDrawString(e, 
5260"金额");
            PrintDrawString(e, 
5400"备注");
            
int i = 6;
            
foreach (XmlNode node in _xdoc.SelectNodes("/row/项目明细/项目"))
            {
                PrintDrawString(e, i, 
0, node.InnerText.Trim());
                PrintDrawString(e, i, 
260, node.Attributes["金额"].Value.Trim());
                PrintDrawString(e, i, 
400, node.Attributes["备注"].Value.Trim());
                i
++;
            }

            PrintDrawString(e, 
130"合计人民币(大写):" + MoneyConvertChinese.MoneyToChinese(_xdoc.SelectSingleNode("/row/金额合计").InnerText.Trim()));
            PrintDrawString(e, 
13380"合计人民币(小写):CNY" + _xdoc.SelectSingleNode("/row/金额合计").InnerText.Trim());
            
//PrintDrawString(e, 13, 600, "付款方式:" + "现金");

            PrintDrawString(e, 
150"开票人:" + fapiaoSets.开票人);
            PrintDrawString(e, 
15150"审核人:" + fapiaoSets.审核人);

            PrintDrawString(e, 
160"主管税务机关:" + fapiaoSets.主管税务机关);
        }
        
/// <summary>
        
/// 处理打印文字
        
/// </summary>
        
/// <param name="e">PrintPageEventArgs</param>
        
/// <param name="lineIndex">行号</param>
        
/// <param name="PointX">X轴偏移量</param>
        
/// <param name="drawString">文字</param>
        private void PrintDrawString(PrintPageEventArgs e, int lineIndex, int PointX, string drawString)
        {
            
//Y轴预设偏移量
            int defaultY = 110;
            
//X轴预设偏移量
            int defaultX = 60;
            
//行距
            int defaultLineHeight = 22;

            e.Graphics.DrawString(drawString, 
new Font("KaiTi_GB2312"10), Brushes.Black, new PointF(defaultX + PointX, defaultY + (lineIndex * defaultLineHeight)));
        }
 
       
/// <summary>
        
/// 打印前事件,设定打印参数
        
/// </summary>
        
/// <param name="sender"></param>
        
/// <param name="e"></param>
        private void printdoc_BeginPrint(object sender, PrintEventArgs e)
        {
            
this.pageSets.PrinterSettings.PrinterName = getPrinterName();
            
this.pageSets.PaperSize = this.fapiaoSize;
            
this.pageSets.Landscape = false;

            
this.printerSets.DefaultPageSettings.PaperSize = this.pageSets.PaperSize;
            
this.printerSets.PrinterName = getPrinterName();

            
this.printdoc.DocumentName = "机打发票";
            
this.printdoc.DefaultPageSettings = this.pageSets;
            
this.printdoc.PrinterSettings = this.printerSets;
        }