|
|
@@ -2,8 +2,11 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Drawing;
|
|
|
+using System.Drawing.Drawing2D;
|
|
|
+using System.Linq;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using System.Windows.Forms;
|
|
|
+using System.Drawing.Printing;
|
|
|
|
|
|
namespace UAS_Web.tool
|
|
|
{
|
|
|
@@ -11,6 +14,13 @@ namespace UAS_Web.tool
|
|
|
{
|
|
|
public event Action<byte[]> NotifyMsg;
|
|
|
|
|
|
+ //打印图片集合
|
|
|
+ List<Bitmap> bitmaps = new List<Bitmap>();
|
|
|
+
|
|
|
+ //图片打印中间变量
|
|
|
+ int imagecount = 0;
|
|
|
+ int index = 0;
|
|
|
+
|
|
|
string PrinterName = "";
|
|
|
|
|
|
string PrintType = "";
|
|
|
@@ -39,6 +49,9 @@ namespace UAS_Web.tool
|
|
|
case "getPrintType.action":
|
|
|
filter = FilterManager.CreateFilter(request.Identifier.ToString()) as MessageFilter;
|
|
|
return filter;
|
|
|
+ case "vendorZplPrint.action":
|
|
|
+ filter = FilterManager.CreateFilter(request.Identifier.ToString()) as MessageFilter;
|
|
|
+ return filter;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
@@ -94,6 +107,7 @@ namespace UAS_Web.tool
|
|
|
//string PrintCode = data["exceptionInfo"].ToString();
|
|
|
//MessageBox.Show(PrintCode);
|
|
|
}
|
|
|
+
|
|
|
break;
|
|
|
case "getPrintType.action":
|
|
|
filter = FilterManager.GetFileter(request.Identifier.ToString()) as MessageFilter;
|
|
|
@@ -101,20 +115,95 @@ namespace UAS_Web.tool
|
|
|
data = ToDictionary(str);
|
|
|
PrintType = data["data"].ToString().Replace("\"", "");
|
|
|
break;
|
|
|
+ case "vendorZplPrint.action":
|
|
|
+ filter = FilterManager.GetFileter(request.Identifier.ToString()) as MessageFilter;
|
|
|
+ str = System.Text.Encoding.UTF8.GetString(filter.dataAll.ToArray());
|
|
|
+ data = ToDictionary(str);
|
|
|
+ List<Dictionary<string, object>> parameter = new List<Dictionary<string, object>>();
|
|
|
+ List<Dictionary<string, object>> barcode = new List<Dictionary<string, object>>();
|
|
|
+ parameter = (List<Dictionary<string, object>>)data["parameter"];
|
|
|
+ barcode = (List<Dictionary<string, object>>)data["barcode"];
|
|
|
+ int la_width = int.Parse(parameter.First()["LA_WIDTH"].ToString());
|
|
|
+ int la_height = int.Parse(parameter.First()["LA_HEIGHT"].ToString());
|
|
|
+
|
|
|
+ foreach (var item in barcode)
|
|
|
+ {
|
|
|
+ Bitmap bit = new Bitmap(la_width * 4, la_height * 4);
|
|
|
+
|
|
|
+
|
|
|
+ using (Graphics g = Graphics.FromImage(bit))
|
|
|
+ {
|
|
|
+ g.CompositingQuality = CompositingQuality.HighQuality;
|
|
|
+ g.SmoothingMode = SmoothingMode.HighQuality;
|
|
|
+ g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
|
+ ////定义一枝画笔
|
|
|
+ //Pen pen = new Pen(Color.Black);
|
|
|
+ ////用这个画笔在左上角画一个矩形
|
|
|
+ //g.DrawRectangle(pen, new Rectangle(10, 10, 50, 20));
|
|
|
+ foreach (var itemc in item)
|
|
|
+ {
|
|
|
+ Dictionary<string, object> Sidc = parameter.Find(p => p["LP_NAME"].ToString().Replace(" ", "").Replace("\"", "").ToUpper() == itemc.Key.ToUpper());
|
|
|
+ if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "text")
|
|
|
+ {
|
|
|
+ PrintHelper.Printstring(itemc.Value!=null?itemc.Value.ToString().Replace("\"", ""):" ", int.Parse(Sidc["LP_SIZE"].ToString()), g, int.Parse(Sidc["LP_LEFTRATE"].ToString()), int.Parse(Sidc["LP_TOPRATE"].ToString()));
|
|
|
+ }
|
|
|
+ else if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "barcode")
|
|
|
+ {
|
|
|
+ PrintHelper.DrawBarcode(itemc.Value != null ? itemc.Value.ToString().Replace("\"", "") : " ", ref bit, double.Parse(Sidc["LP_LEFTRATE"].ToString()), double.Parse(Sidc["LP_TOPRATE"].ToString()), double.Parse(Sidc["LP_WIDTH"].ToString()), double.Parse(Sidc["LP_HEIGHT"].ToString()) - 2);
|
|
|
+ PrintHelper.Printstring(itemc.Value != null ? itemc.Value.ToString().Replace("\"", "") : " ", int.Parse(Sidc["LP_SIZE"].ToString()), g, int.Parse(Sidc["LP_LEFTRATE"].ToString()), int.Parse(Sidc["LP_TOPRATE"].ToString()) + double.Parse(Sidc["LP_HEIGHT"].ToString()) - 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bitmaps.Add(bit);
|
|
|
+ }
|
|
|
+ imagecount = bitmaps.Count;
|
|
|
+ ////设置打印机名称
|
|
|
+ print.PrintDoc.PrintPage += PrintPage;
|
|
|
+ print.PrintDoc.Print();
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void PrintPage(object sender, PrintPageEventArgs e)
|
|
|
+ {
|
|
|
+ Image i = bitmaps[index];
|
|
|
+ Graphics g = e.Graphics;
|
|
|
+ g.CompositingQuality = CompositingQuality.HighQuality;
|
|
|
+ g.SmoothingMode = SmoothingMode.HighQuality;
|
|
|
+ g.InterpolationMode = InterpolationMode.NearestNeighbor;
|
|
|
+ g.PixelOffsetMode = PixelOffsetMode.Half;
|
|
|
+ g.DrawImage(i, 0, -5, i.Width, i.Height);
|
|
|
+ if (index < imagecount - 1)
|
|
|
+ {
|
|
|
+ e.HasMorePages = true;
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ index = 0;
|
|
|
+ e.HasMorePages = false;
|
|
|
+ bitmaps.Clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void RequestHandler_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
//设置打印机名称
|
|
|
print.PrintDoc.PrinterSettings.PrinterName = print.Controls["Printer"].Text;
|
|
|
PrinterName = print.Controls["Printer"].Text;
|
|
|
+ RadioButton PRXA = (RadioButton)print.Controls["PRXA"];
|
|
|
+ RadioButton PRPIC = (RadioButton)print.Controls["PRPIC"];
|
|
|
//获取矩阵图的分辨率
|
|
|
Graphics gr = print.PrintDoc.PrinterSettings.CreateMeasurementGraphics();
|
|
|
print.browser.FocusedFrame.ExecuteJavaScriptAsync("(function(value,value1){dpi=value,printType=value1})('" + gr.DpiX + "','" + PrintType + "')");
|
|
|
+ if (PRPIC.Checked) {
|
|
|
+ print.browser.FocusedFrame.ExecuteJavaScriptAsync("document.getElementById('confirmPicturePrint').click();");
|
|
|
+ }
|
|
|
+ else
|
|
|
print.browser.FocusedFrame.ExecuteJavaScriptAsync("document.getElementById('confirmZplPrint').click();");
|
|
|
+
|
|
|
print.Close();
|
|
|
}
|
|
|
|