在B/S架构下实现对位打印
现在我们实现打印类的基类
using System;
using System.Drawing;
using System.Drawing.Printing;
namespace WGSys.DataExchange
{
public class PrinterBase
{
protected static readonly Font memFont = new Font("宋体", 9); //普通字体
protected static readonly Font memBarCodeFont=new Font("C39HrP24DhTt",36); //条形码字体
protected PrintPageEventHandler memHandler;
string memDocName = null;
public PrinterBase()
{
memHandler = new PrintPageEventHandler(this.PageHandler);//表示将要处理 PrintDocument 的 PrintPage 事件的方法
}
public string DocName
{
get
{
return memDocName;
}
set
{
memDocName = value;
}
}
public virtual void Print(PrintDocument tempPrnDoc,bool isPreview)
{
tempPrnDoc.PrintPage += memHandler;
if ((memDocName!=null)&&(memDocName.Length>0))
tempPrnDoc.DocumentName = memDocName;//打印文档时要显示的文档名。默认情况下为“文档”
if(isPreview)
{
System.Windows.Forms.PrintPreviewDialog pd = new System.Windows.Forms.PrintPreviewDialog();
pd.Document = tempPrnDoc;
pd.ShowDialog();
}
else
{
tempPrnDoc.Print();
}
}
public virtual void OnPrintPage(PrintPageEventArgs ev)
{
ev.Graphics.DrawString(
"Output",
memFont,
Brushes.Black,
ev.MarginBounds.Left,
ev.MarginBounds.Top,
new StringFormat()
);
//=================
ev.HasMorePages = false;
}
protected void PageHandler(object sender, PrintPageEventArgs ev)
{
OnPrintPage(ev);
}
}
}
/*
* 账单打印数据类
* Create:2005-8-11 Version:WGWATER1.1 Author:maojun
*
* */
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace WGSys.DataExchange
{
/// <summary>
/// Summary description for BillPrintData.
/// </summary>
public class BillPrintData
{
private static XmlSerializer memBillPrnDataSerializer;
static BillPrintData()
{
memBillPrnDataSerializer = new XmlSerializer(typeof(BillPrintData));
}
public string ToXml()
{
StringWriter sw = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(sw);
memBillPrnDataSerializer.Serialize(writer,this);
writer.Close();
sw.Close();
return sw.ToString();
}
public static BillPrintData FromXml(string xml)
{
StringReader r = new StringReader(xml);
XmlTextReader reader = new XmlTextReader(r);
return memBillPrnDataSerializer.Deserialize(reader) as BillPrintData;
}
//抄表员
private string mynotename;
[XmlAttribute]
public string NoteName{
get{return mynotename;}
set{mynotename=value;}
}
//统册号
private string mytcnumber;
[XmlAttribute]
public string TCNumber{
get{return mytcnumber;}
set{mytcnumber=value;}
}
..
..
}
}

浙公网安备 33010602011771号