?? misprinter.cs
字號(hào):
using System;
using System.Drawing;
using System.Drawing.Printing;
namespace GoldPrinter
{
/// <summary>
/// 本程序?yàn)橥ㄓ么蛴〕绦颍瑔螕?jù)、會(huì)計(jì)憑證、發(fā)票清單、報(bào)表、任意復(fù)雜表格、合并表格如工礦企業(yè)合同都可以由系統(tǒng)提供的幾個(gè)默
/// 認(rèn)打印對(duì)象組合打印。
/// DataGrid、DataTable、MSHFlexGrid等二維形式全部可以打印。
/// 部分對(duì)象如PrinterMargins、Sewing、GridLineFlag、GridMergeFlag等提供圖例,以促進(jìn)理解。
/// 后期版本將提供XML描述、SQL數(shù)據(jù)源的打印,并用管理器管理任意多個(gè)網(wǎng)格、文本對(duì)象、圖象等,用戶(hù)可以隨意定義。
///
/// 程序提供:周方勇;Email:flygoldfish@sina.com。
/// 請(qǐng) 關(guān) 注:WebMIS.Net快速開(kāi)發(fā)工具,不寫(xiě)一行程序開(kāi)發(fā)B/S架構(gòu)下MIS、OA、CRM、人事管理、檔案管理等數(shù)據(jù)庫(kù)網(wǎng)頁(yè)系統(tǒng)。簡(jiǎn)單、實(shí)用、穩(wěn)定、可靠。
/// 下 載:
/// 上海奧聯(lián):WWW.AlinkSoft.COM
/// 用友華表:WWW.CellSoft.CC
///★★★★★您可以免費(fèi)使用此程序,但是請(qǐng)您保留此說(shuō)明,以維護(hù)知識(shí)產(chǎn)權(quán)★★★★★
/// </summary>
public class MisPrinter:IDisposable
{
public Color BackColor = Color.White;//背景顏色
//繪圖表面
private Graphics mGraphics;
//打印文檔
private PrintDocument mPrintDocument;
//下一對(duì)象的起點(diǎn)坐標(biāo)及寬
private float X,Y,Width;
//翻頁(yè)用
private int mCurrentPageIndex; //當(dāng)前頁(yè)
private int mCurrentRowIndex; //主數(shù)據(jù)網(wǎng)格的當(dāng)前行
private int mCurrentRowIndexForFooter; //Footer當(dāng)前行
//字段
private int _rowsPerPage; //每頁(yè)行數(shù),小于等于0自適應(yīng),默認(rèn)
private bool _isSewingLine; //是否打印裝訂線(默認(rèn)無(wú))
private bool _isPrinterMargins; //是否打印有效區(qū)域矩陣(默認(rèn)無(wú))
private bool _isSubTotalPerPage; //是否每頁(yè)都要顯示主數(shù)據(jù)網(wǎng)格當(dāng)前頁(yè)小計(jì)(默認(rèn)否)
private string _subTotalCol; //每頁(yè)小計(jì)要指定的列
private Sewing _sewing; //裝訂,對(duì)象的線長(zhǎng)小于0則自動(dòng)設(shè)置
private GridBorderFlag _gridBorder; //網(wǎng)格邊框
#region 字段屬性
/// <summary>
/// 每頁(yè)行數(shù),小于等于0自適應(yīng),默認(rèn)
/// </summary>
public int RowsPerPage
{
get
{
return _rowsPerPage;
}
set
{
int mint = value;
if (mint < 0)
{
mint = -1;
}
_rowsPerPage = mint;
}
}
/// <summary>
/// 是否打印裝訂線,對(duì)象的線長(zhǎng)小于0則自動(dòng)設(shè)置
/// </summary>
public bool IsSewingLine
{
get
{
return _isSewingLine;
}
set
{
_isSewingLine = value;
}
}
/// <summary>
/// 是否打印有效區(qū)域矩陣
/// </summary>
public bool IsPrinterMargins
{
get
{
return _isPrinterMargins;
}
set
{
_isPrinterMargins = value;
}
}
/// <summary>
/// 是否每頁(yè)都要顯示當(dāng)前頁(yè)小計(jì)(默認(rèn)否)
/// </summary>
public bool IsSubTotalPerPage
{
get
{
return _isSubTotalPerPage;
}
set
{
_isSubTotalPerPage = value;
}
}
/// <summary>
/// 用分號(hào)分隔的要每頁(yè)小計(jì)列
/// </summary>
public string SubTotalCol
{
get
{
return _subTotalCol;
}
set
{
_subTotalCol = value;
}
}
/// <summary>
/// 裝訂對(duì)象,對(duì)象的線長(zhǎng)小于0則自動(dòng)設(shè)置
/// </summary>
public Sewing Sewing
{
get
{
return this._sewing;
}
set
{
if (value != null)
{
this._sewing = value;
}
else
{
this._sewing.Margin = 0; //寬度為0則不打印
}
}
}
/// <summary>
/// 網(wǎng)格邊框
/// </summary>
public GridBorderFlag GridBorder
{
get
{
return this._gridBorder;
}
set
{
this._gridBorder = value;
}
}
#endregion
//********************打印對(duì)象********************
private Title _title; //主標(biāo)題
private Caption _caption; //副標(biāo)題
private Top _top; //簡(jiǎn)單的一行三列打印樣式,第一列居左,第三列居右,中間列居中
private Header _header; //正文網(wǎng)格主體之上的幾行幾列的標(biāo)注說(shuō)明
private MultiHeader _multiHeader; //正文網(wǎng)格主體標(biāo)題頭可能需要多層合并表頭說(shuō)明
private Body _body; //*正文網(wǎng)格主體,必須,打印以此為基準(zhǔn)
protected Footer _footer; //正文網(wǎng)格主體之下的幾行幾列的標(biāo)注說(shuō)明
private Bottom _bottom; //簡(jiǎn)單的一行三列打印樣式,第一列居左,第三列居右,中間列居中
#region 打印對(duì)象字段屬性
#region Title、Caption
/// <summary>
/// 獲取或設(shè)置打印主標(biāo)題,可以是文本,也可以是定義更多特性的Title對(duì)象
/// </summary>
public object Title
{
get
{
return this._title;
}
set
{
if (value != null)
{
if (value.GetType().ToString() == "System.String")
{
if (this._title == null)
{
this._title = new Title();
}
this._title.Text = (string)value;
}
else if(value.GetType().ToString() == "GoldPrinter.Title")
{
this._title = (GoldPrinter.Title)value;
}
}
}
}
/// <summary>
/// 獲取或設(shè)置打印副標(biāo)題,可以是文本,也可以是定義更多特性的Caption對(duì)象
/// </summary>
public object Caption
{
get
{
return this._caption;
}
set
{
if (value != null)
{
if (value.GetType().ToString() == "System.String")
{
if (this._caption == null)
{
this._caption = new Caption();
}
this._caption.Text = (string)value;
}
else if(value.GetType().ToString() == "GoldPrinter.Caption")
{
this._caption = (GoldPrinter.Caption)value;
}
}
}
}
#endregion
#region 或取或設(shè)置網(wǎng)格頭、底,可以是以'|'分隔的字符串或或一維數(shù)組或具有更多特性的Top/Bottom對(duì)象
/// <summary>
/// 或取或設(shè)置網(wǎng)格頭,可以是以'|'分隔的字符串或或一維數(shù)組或具有更多特性的Top對(duì)象
/// </summary>
public object Top
{
get
{
return this._top;
}
set
{
if (value != null)
{
if (value.GetType().ToString() == "System.String" || value.GetType().ToString() == "System.String[]")
{
if (this._top == null)
{
this._top = new Top();
}
this._top.DataSource = value;
}
else if(value.GetType().ToString() == "GoldPrinter.Top")
{
this._top = (GoldPrinter.Top)value;
}
}
}
}
/// <summary>
/// 或取或設(shè)置網(wǎng)格底,可以是以'|'分隔的字符串或或一維數(shù)組或具有更多特性的Bottom對(duì)象
/// </summary>
public object Bottom
{
get
{
return this._bottom;
}
set
{
if (value != null)
{
if (value.GetType().ToString() == "System.String" || value.GetType().ToString() == "System.String[]")
{
if (this._bottom == null)
{
this._bottom = new Bottom();
}
this._bottom.DataSource = (string)value;
}
else if(value.GetType().ToString() == "GoldPrinter.Bottom")
{
this._bottom = (GoldPrinter.Bottom)value;
}
}
}
}
#endregion
public object Header
{
get
{
return _header;
}
set
{
this._header = (GoldPrinter.Header)value;
}
}
public object MultiHeader
{
get
{
return _multiHeader;
}
set
{
this._multiHeader = (GoldPrinter.MultiHeader)value;
}
}
public object Body
{
get
{
return _body;
}
set
{
_body = (GoldPrinter.Body)value;
}
}
public object Footer
{
get
{
return this._footer;
}
set
{
this._footer = (GoldPrinter.Footer)value;
}
}
#endregion
//還可以將此程序稍微修改,用一個(gè)集體管理,動(dòng)態(tài)加載打印對(duì)象,形成任意多個(gè)網(wǎng)格的組合體,打印任意復(fù)雜的網(wǎng)格
public MisPrinter()
{
mCurrentPageIndex = 1;
_rowsPerPage = 0;
mCurrentRowIndex = 0;
mCurrentRowIndexForFooter = 0;
_isSewingLine = false;
_isPrinterMargins = false;
_isSubTotalPerPage = false;
_subTotalCol = "";
_sewing = new Sewing(0,SewingDirectionFlag.Left);
mPrintDocument = new PrintDocument();
_body = new Body(); //主要對(duì)象,所以實(shí)例化
_gridBorder = GridBorderFlag.Double;
}
#region IDisposable 成員
public virtual void Dispose()
{
//...
}
#endregion
/// <summary>
/// 頁(yè)面設(shè)置對(duì)話框,如果需要,國(guó)慶期間繼續(xù)開(kāi)放,敬請(qǐng)關(guān)注
/// </summary>
public void PageSetup()
{
PrinterPageSetting printerPageSetting;
printerPageSetting = new PrinterPageSetting(mPrintDocument);
printerPageSetting.PrintPage += new PrintPageDelegate(this.PrintPageEventHandler);
printerPageSetting.ShowPageSetupDialog();
}
/// <summary>
/// 打印,如果需要,國(guó)慶期間繼續(xù)開(kāi)放,敬請(qǐng)關(guān)注
/// </summary>
public void Print()
{
PrinterPageSetting printerPageSetting;
printerPageSetting = new PrinterPageSetting(mPrintDocument);
printerPageSetting.PrintPage += new PrintPageDelegate(this.PrintPageEventHandler);
printerPageSetting.ShowPrintSetupDialog();
}
/// <summary>
/// 打印預(yù)覽,如果需要,國(guó)慶期間繼續(xù)開(kāi)放,敬請(qǐng)關(guān)注
/// </summary>
public void Preview()
{
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -