using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using System.ComponentModel; using QMAPP.Common.Web.Models; namespace QMAPP.Common.Web.Models { #region 打印属性 /// /// 打印命令 /// [Description("打印命令")] public enum PrintActionMode { /// /// 直接打印 /// [Description("直接打印")] AutoPrint, /// /// 选择打印 /// [Description("选择打印")] SelectPrint, /// /// 打印预览 /// [Description("打印预览")] PrintPreview } /// /// 纸张方向 /// public enum PageOrient { [Description("自由选择")] Select, [Description("纵向")] Direction, [Description("横向")] Inffed } #endregion #region 打印设置信息 /// /// 打印设置信息 /// public class PrintInfoModel { public PrintInfoModel() { ContentList = new Dictionary(); } /// /// 内容列表 /// private Dictionary ContentList { get; set; } /// /// 打印任务名称 /// public string TaskName { get; set; } /// /// 打印内容 /// public string PrintContent { get; set; } /// /// 打印输出 /// public string PrintOutput { get; set; } /// /// 打印行为 /// public PrintActionMode PrintAction { get; set; } /// /// 打印方向 /// public PageOrient PrintOrient { get; set; } /// /// 纸张宽度(0.1毫米) /// public string PageWidth { get; set; } /// /// 纸张高度(0.1毫米) /// public string PageHeight { get; set; } /// /// 打印纸张 /// public string PageName { get; set; } /// /// 上边距(毫米) /// public string Top { get; set; } /// /// 左边距(毫米) /// public string Left { get; set; } /// /// 右边距(毫米) /// public string Right { get; set; } /// /// 下边距(毫米) /// public string Bottom { get; set; } /// /// 内容宽度(像素) /// public string ContentWidth { get; set; } /// /// 内容高度(像素) /// public string ContentHeight { get; set; } /// /// 回调函数 /// public string CallBackFunction { get; set; } /// /// /// public string FailCallBackFunction { get; set; } #region 添加打印内容 public void AddContent(string content) { ContentList.Add("html" + ContentList.Count+1, content); } #endregion #region 添加分页 public void AddNewPage() { ContentList.Add("newp"+ContentList.Count+1, "newpage"); } #endregion #region 添加条码 public void AddBarCode(int top, int left, int width, int height, string codeType, string code) { ContentList.Add("code" + ContentList.Count + 1, string.Format("LODOP.ADD_PRINT_BARCODE(\"{0}mm\",\"{1}mm\",\"{2}mm\",\"{3}mm\",\"{4}\",\"{5}\");",top,left,width,height,codeType,code)); } public void AddBarCodeNoText(int top, int left, int width, int height, string codeType, string code) { ContentList.Add("code" + ContentList.Count + 1, string.Format("LODOP.ADD_PRINT_BARCODE(\"{0}mm\",\"{1}mm\",\"{2}mm\",\"{3}mm\",\"{4}\",\"{5}\");LODOP.SET_PRINT_STYLEA(0,\"ShowBarText\",0);", top, left, width, height, codeType, code)); } public void AddBarCode(string codeContent) { ContentList.Add("code" + ContentList.Count + 1, codeContent); } #endregion #region 生成打印内容及打印输出 public void BuildPrint() { int contentCount = 0; StringBuilder outputBuilder=new StringBuilder(); StringBuilder contentBuilder = new StringBuilder(); //打印初始化 outputBuilder.AppendLine("LODOP = getLodop(document.getElementById('LODOP'), document.getElementById('LODOP_EM'));"); outputBuilder.AppendLine("LODOP.SET_LICENSES(\"大连启明海通信息技术有限公司\", \"B9171197AF89CE56132E8C860C24FE43\", \"\", \"\");"); outputBuilder.AppendLine("LODOP.PRINT_INIT(\"NLK打印任务\"); "); //打印纸张 outputBuilder.AppendLine(string.Format("LODOP.SET_PRINT_PAGESIZE({0},{1},{2},\"{3}\");",(int)PrintOrient,PageWidth,PageHeight,PageName)); foreach (string key in ContentList.Keys) { contentCount++; if (key.Substring(0, 4) == "html") { contentBuilder.AppendLine(string.Format("
{1}
",contentCount,ContentList[key])); outputBuilder.AppendLine(string.Format("LODOP.ADD_PRINT_HTM(\"{0}mm\",\"{1}mm\",\"RightMargin:{2}mm\",\"BottomMargin:{3}mm\",document.getElementById(\"div{4}\").innerHTML);" ,Top,Left,Right,Bottom,contentCount)); } if (key.Substring(0, 4) == "newp") { outputBuilder.AppendLine("LODOP.NewPage();"); } if (key.Substring(0, 4) == "code") { outputBuilder.AppendLine(ContentList[key]); } } PrintContent = contentBuilder.ToString(); PrintOutput = outputBuilder.ToString(); } #endregion } #endregion }