using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows.Documents;
|
|
using System.Windows;
|
|
using System.Data;
|
|
using System.Windows.Media;
|
|
using Utils.Datas;
|
|
|
|
namespace Utils.Printers
|
|
{
|
|
public class BillDataPaginator : DocumentPaginator
|
|
{
|
|
#region 属性及字段
|
|
private DataTable _DataTable;
|
|
private Size _PageSize;
|
|
private int _DetailMaxRows;
|
|
|
|
public override Size PageSize { get { return _PageSize; } set { _PageSize = value; } }
|
|
public override bool IsPageCountValid { get { return true; } }
|
|
public override int PageCount { get { return PageNumUtil.GetTotalPageCount(_DataTable.Rows.Count, _DetailMaxRows); } }
|
|
public override IDocumentPaginatorSource Source { get { return null; } }
|
|
|
|
private DrawPage dp;
|
|
#endregion
|
|
|
|
#region 构造函数相关方法
|
|
//构造函数
|
|
public BillDataPaginator(DataTable dt, Size pagesize, Typeface typeface, PrintInfo printInfo)
|
|
{
|
|
_DataTable = dt;
|
|
_PageSize = pagesize;
|
|
_DetailMaxRows = printInfo.清单每页最大行数;
|
|
|
|
dp = new DrawPage() {
|
|
InforsBeforeHead = printInfo.表前信息,
|
|
FontSize_InforsBeforeHead = printInfo.表前信息字号,
|
|
Title = printInfo.标题 + "№" + printInfo.单号,
|
|
TitleFontSize = printInfo.标题字号,
|
|
TitleMarginLeft = printInfo.标题左边距,
|
|
PageWidth = printInfo.表头页宽,
|
|
FontSize = printInfo.正文字号,
|
|
FontSize_Footer = printInfo.页脚字号,
|
|
MarginLeft = printInfo.正文左边距,
|
|
MarginTop = printInfo.顶边距,
|
|
DetailMaxRows = _DetailMaxRows,
|
|
HeaderCharCount = printInfo.表头标签文字最大个数,
|
|
HeaderColumnsCount = printInfo.表头列数,
|
|
LineDistance = printInfo.行距,
|
|
TypeFace = typeface,
|
|
ShowPageNum = printInfo.是否打印页码,
|
|
ShowPrinter = printInfo.是否打印打印人,
|
|
ShowPrintTime = printInfo.是否打印打印时间,
|
|
Printer = printInfo.打印人,
|
|
AllowSum = printInfo.是否允许合计,
|
|
SumColumnNames = printInfo.合计列的列名,
|
|
InforsBeforeFooter = printInfo.页脚前信息,
|
|
InforsAfterFooter = printInfo.页脚后信息,
|
|
FontSize_InforsBeforeFooter = printInfo.页脚前信息字号,
|
|
FontSize_InforsAfterFooter = printInfo.页脚后信息字号,
|
|
};
|
|
|
|
if (printInfo.表头信息 != null && printInfo.表头信息.Count > 0)
|
|
foreach (var heads in printInfo.表头信息)
|
|
dp.AddHeaders(heads);
|
|
List<string> columnNames = new List<string>();
|
|
foreach (DataColumn column in dt.Columns) {
|
|
columnNames.Add(column.Caption);
|
|
}
|
|
dp.AddColumnNames(columnNames.ToArray());
|
|
foreach (DataRow row in dt.Rows) {
|
|
List<string> datas = new List<string>();
|
|
for (int i = 0; i < dt.Columns.Count; i++) {
|
|
datas.Add(row[i].ToString());
|
|
}
|
|
dp.AddRow(datas.ToArray());
|
|
}
|
|
dp.SetColumnWidths(printInfo.清单每列列宽.ToArray());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取对应页面数据并进行相应的打印设置
|
|
/// </summary>
|
|
public override DocumentPage GetPage(int pageNumber)//pageNumber:从0开始
|
|
{
|
|
return dp.GetPage(pageNumber);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|