天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
6.4 KiB

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 打印属性
/// <summary>
/// 打印命令
/// </summary>
[Description("打印命令")]
public enum PrintActionMode
{
/// <summary>
/// 直接打印
/// </summary>
[Description("直接打印")]
AutoPrint,
/// <summary>
/// 选择打印
/// </summary>
[Description("选择打印")]
SelectPrint,
/// <summary>
/// 打印预览
/// </summary>
[Description("打印预览")]
PrintPreview
}
/// <summary>
/// 纸张方向
/// </summary>
public enum PageOrient
{
[Description("自由选择")]
Select,
[Description("纵向")]
Direction,
[Description("横向")]
Inffed
}
#endregion
#region 打印设置信息
/// <summary>
/// 打印设置信息
/// </summary>
public class PrintInfoModel
{
public PrintInfoModel()
{
ContentList = new Dictionary<string, string>();
}
/// <summary>
/// 内容列表
/// </summary>
private Dictionary<string, string> ContentList { get; set; }
/// <summary>
/// 打印任务名称
/// </summary>
public string TaskName { get; set; }
/// <summary>
/// 打印内容
/// </summary>
public string PrintContent { get; set; }
/// <summary>
/// 打印输出
/// </summary>
public string PrintOutput { get; set; }
/// <summary>
/// 打印行为
/// </summary>
public PrintActionMode PrintAction { get; set; }
/// <summary>
/// 打印方向
/// </summary>
public PageOrient PrintOrient { get; set; }
/// <summary>
/// 纸张宽度(0.1毫米)
/// </summary>
public string PageWidth { get; set; }
/// <summary>
/// 纸张高度(0.1毫米)
/// </summary>
public string PageHeight { get; set; }
/// <summary>
/// 打印纸张
/// </summary>
public string PageName { get; set; }
/// <summary>
/// 上边距(毫米)
/// </summary>
public string Top { get; set; }
/// <summary>
/// 左边距(毫米)
/// </summary>
public string Left { get; set; }
/// <summary>
/// 右边距(毫米)
/// </summary>
public string Right { get; set; }
/// <summary>
/// 下边距(毫米)
/// </summary>
public string Bottom { get; set; }
/// <summary>
/// 内容宽度(像素)
/// </summary>
public string ContentWidth { get; set; }
/// <summary>
/// 内容高度(像素)
/// </summary>
public string ContentHeight { get; set; }
/// <summary>
/// 回调函数
/// </summary>
public string CallBackFunction { get; set; }
/// <summary>
///
/// </summary>
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("<div id=\"div{0}\">{1}</div>",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
}