|
@@ -25,6 +25,9 @@ namespace UAS_Web.tool
|
|
|
List<Bitmap> bitmaps = new List<Bitmap>();
|
|
|
Report BarcodeReport = new Report();
|
|
|
|
|
|
+ Dictionary<string, object> itemlast;
|
|
|
+ Dictionary<string, object> itemBox;
|
|
|
+
|
|
|
|
|
|
int imagecount = 0;
|
|
|
int index = 0;
|
|
@@ -39,6 +42,15 @@ namespace UAS_Web.tool
|
|
|
string LABELNAME = "";
|
|
|
string labelview = "";
|
|
|
|
|
|
+ Dictionary<string, object> DataCollection = null;
|
|
|
+
|
|
|
+
|
|
|
+ string AllLabelname = "";
|
|
|
+ string AllBoxname = "";
|
|
|
+
|
|
|
+
|
|
|
+ string PType = "";
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
@@ -87,6 +99,7 @@ namespace UAS_Web.tool
|
|
|
MessageFilter filter;
|
|
|
string str;
|
|
|
Dictionary<string, object> data;
|
|
|
+
|
|
|
switch (request.Url.Substring(request.Url.LastIndexOf("/") + 1))
|
|
|
{
|
|
|
case "zplPrinter":
|
|
@@ -110,9 +123,40 @@ namespace UAS_Web.tool
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ PType = "normal";
|
|
|
|
|
|
print = new PrinterList(browser) { StartPosition = FormStartPosition.CenterScreen,TopMost=true };
|
|
|
|
|
|
+ print.Controls["Confirm"].Click += RequestHandler_Click;
|
|
|
+ print.PrintDoc.PrintPage += PrintPage;
|
|
|
+ print.ShowDialog();
|
|
|
+ break;
|
|
|
+ case "zplPrinterAll":
|
|
|
+ if (request.Method == "POST")
|
|
|
+ {
|
|
|
+ using (var postData = request.PostData)
|
|
|
+ {
|
|
|
+ if (postData != null)
|
|
|
+ {
|
|
|
+ var elements = postData.Elements;
|
|
|
+ var charSet = request.GetCharSet();
|
|
|
+ foreach (var element in elements)
|
|
|
+ {
|
|
|
+ if (element.Type == PostDataElementType.Bytes)
|
|
|
+ {
|
|
|
+ string body = HttpUtility.UrlDecode(element.GetBody(charSet), Encoding.UTF8);
|
|
|
+
|
|
|
+ AllLabelname = body.Substring(body.IndexOf("la_name=") + 8, body.IndexOf("&la_idBox")- (body.IndexOf("la_name=") + 8));
|
|
|
+ AllBoxname = body.Substring(body.LastIndexOf('=') + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PType = "all";
|
|
|
+
|
|
|
+ print = new PrinterList(browser) { StartPosition = FormStartPosition.CenterScreen, TopMost = true };
|
|
|
+
|
|
|
print.Controls["Confirm"].Click += RequestHandler_Click;
|
|
|
print.PrintDoc.PrintPage += PrintPage;
|
|
|
print.ShowDialog();
|
|
@@ -156,14 +200,45 @@ namespace UAS_Web.tool
|
|
|
{
|
|
|
filter = FilterManager.GetFileter(request.Identifier.ToString()) as MessageFilter;
|
|
|
str = System.Text.Encoding.UTF8.GetString(filter.dataAll.ToArray());
|
|
|
- if (str.Contains("不允许打印"))
|
|
|
+ if (str.Contains("不允许打印")||(str.Contains("exceptionInfo")))
|
|
|
return;
|
|
|
data = ToDictionary(str);
|
|
|
- vendorZplPrint(data);
|
|
|
+ if (DataCollection == null)
|
|
|
+ {
|
|
|
+ DataCollection = new Dictionary<string, object>();
|
|
|
+ DataCollection.Add(((string)data["currentPage"]).Replace("\"", ""), data);
|
|
|
+ }
|
|
|
+ if (DataCollection.Count < int.Parse(((string)data["totalPage"]).Replace("\"", "")))
|
|
|
+ {
|
|
|
+ if(!DataCollection.ContainsKey(((string)data["currentPage"]).Replace("\"", "")))
|
|
|
+ DataCollection.Add(((string)data["currentPage"]).Replace("\"", ""), data);
|
|
|
+ }
|
|
|
+ if (DataCollection.Count == int.Parse(((string)data["totalPage"]).Replace("\"", "")))
|
|
|
+ {
|
|
|
+ if (PType == "normal")
|
|
|
+ {
|
|
|
+ for (int i = 0; i < DataCollection.Count; i++)
|
|
|
+ {
|
|
|
+ vendorZplPrint(DataCollection[(i + 1).ToString()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Console.WriteLine("打印ALL");
|
|
|
+ for (int i = 0; i < DataCollection.Count; i++)
|
|
|
+ {
|
|
|
+ vendorZplPrintAll(DataCollection[(i + 1).ToString()]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DataCollection = null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
MessageBox.Show(ex.Message + "请重新进行打印");
|
|
|
+ DataCollection = null;
|
|
|
return;
|
|
|
}
|
|
|
break;
|
|
@@ -172,7 +247,7 @@ namespace UAS_Web.tool
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void vendorZplPrint(Object data)
|
|
|
+ public void vendorZplPrint(Object data)
|
|
|
{
|
|
|
DataTable dt = new DataTable();
|
|
|
RadioButton PRFR = (RadioButton)print.Controls["PRFR"];
|
|
@@ -234,17 +309,8 @@ namespace UAS_Web.tool
|
|
|
foreach (var item in barcode)
|
|
|
{
|
|
|
Bitmap bit = new Bitmap(la_width * 10, la_height * 4);
|
|
|
-
|
|
|
-
|
|
|
using (Graphics g = Graphics.FromImage(bit))
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
foreach (var itemc in item)
|
|
|
{
|
|
|
Dictionary<string, object> Sidc = parameter.Find(p => p["LP_NAME"].ToString().Replace(" ", "").Replace("\"", "").ToUpper() == itemc.Key.ToUpper());
|
|
@@ -349,7 +415,6 @@ namespace UAS_Web.tool
|
|
|
if (itemstr.Contains("\\\""))
|
|
|
{
|
|
|
itemstr = itemstr.Replace("\\\"", "\"");
|
|
|
- Console.WriteLine(itemstr);
|
|
|
}
|
|
|
}
|
|
|
dr[itemc.Key] = itemstr;
|
|
@@ -411,6 +476,270 @@ namespace UAS_Web.tool
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+ string nowboxcode = "";
|
|
|
+ public void vendorZplPrintAll(Object data)
|
|
|
+ {
|
|
|
+
|
|
|
+ DataTable dt = new DataTable();
|
|
|
+
|
|
|
+ DataTable box = new DataTable();
|
|
|
+
|
|
|
+ string type;
|
|
|
+
|
|
|
+ string box_type;
|
|
|
+ bitmaps.Clear();
|
|
|
+ List<Dictionary<string, object>> parameter = new List<Dictionary<string, object>>();
|
|
|
+ List<Dictionary<string, object>> BoxParameter = new List<Dictionary<string, object>>();
|
|
|
+
|
|
|
+ List<Dictionary<string, object>> barcode = new List<Dictionary<string, object>>();
|
|
|
+ List<Dictionary<string, object>> BoxBarcode = new List<Dictionary<string, object>>();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ parameter = (List<Dictionary<string, object>>)((Dictionary<string, object>)data)["parameter"];
|
|
|
+ BoxParameter = (List<Dictionary<string, object>>)((Dictionary<string, object>)data)["BoxParameter"];
|
|
|
+ barcode = (List<Dictionary<string, object>>)((Dictionary<string, object>)data)["barcode"];
|
|
|
+ BoxBarcode = (List<Dictionary<string, object>>)((Dictionary<string, object>)data)["BoxBarcode"];
|
|
|
+ }
|
|
|
+ catch(Exception ex)
|
|
|
+ {
|
|
|
+ MessageBox.Show(ex.Message+"打印数据异常,请联系管理员");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ type = ((String)((Dictionary<string, object>)data)["type"]).Replace("\"", "");
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ type = "no";
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ labelview = ((String)((Dictionary<string, object>)data)["label_type"]).Replace("\"", "");
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ labelview = "";
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ box_type = ((String)((Dictionary<string, object>)data)["BoxLabel_type"]).Replace("\"", "");
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ box_type = "";
|
|
|
+ }
|
|
|
+ Thread.Sleep(1000);
|
|
|
+ int k = 0;
|
|
|
+ while (DownLoadFile.downloading && k < 2)
|
|
|
+ {
|
|
|
+ Thread.Sleep(1000);
|
|
|
+ k++;
|
|
|
+ }
|
|
|
+ if (DownLoadFile.downloading)
|
|
|
+ MessageBox.Show("标签更新有误");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ foreach (var item in parameter)
|
|
|
+ {
|
|
|
+ foreach (var itemc in item)
|
|
|
+ {
|
|
|
+ string itemstr = "";
|
|
|
+ if (itemc.Value != null && itemc.Key.ToString().ToUpper() == "LP_NAME")
|
|
|
+ {
|
|
|
+ itemstr = itemc.Value.ToString();
|
|
|
+ while (itemstr.StartsWith("\f") || itemstr.StartsWith("\v") || itemstr.StartsWith("\t") || itemstr.StartsWith("\r") || itemstr.StartsWith("\n"))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Remove(0, 2);
|
|
|
+ }
|
|
|
+ if (itemstr.StartsWith("\""))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Remove(0, 1);
|
|
|
+ }
|
|
|
+ while (itemstr.EndsWith("\f") || itemstr.EndsWith("\v") || itemstr.EndsWith("\t") || itemstr.EndsWith("\r") || itemstr.EndsWith("\n"))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Remove(itemstr.Length - 2);
|
|
|
+ }
|
|
|
+ if (itemstr.EndsWith("\""))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Remove(itemstr.Length - 1);
|
|
|
+ }
|
|
|
+ if (itemstr.Contains("\\\""))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Replace("\\\"", "\"");
|
|
|
+ }
|
|
|
+
|
|
|
+ DataColumn DC = new DataColumn(itemstr, Type.GetType("System.String"));
|
|
|
+ if (!dt.Columns.Contains(itemc.Key))
|
|
|
+ dt.Columns.Add(DC);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ foreach (var item in BoxParameter)
|
|
|
+ {
|
|
|
+ foreach (var itemc in item)
|
|
|
+ {
|
|
|
+ string itemstr = "";
|
|
|
+ if (itemc.Value != null && itemc.Key.ToString().ToUpper() == "LP_NAME")
|
|
|
+ {
|
|
|
+ itemstr = itemc.Value.ToString();
|
|
|
+ while (itemstr.StartsWith("\f") || itemstr.StartsWith("\v") || itemstr.StartsWith("\t") || itemstr.StartsWith("\r") || itemstr.StartsWith("\n"))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Remove(0, 2);
|
|
|
+ }
|
|
|
+ if (itemstr.StartsWith("\""))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Remove(0, 1);
|
|
|
+ }
|
|
|
+ while (itemstr.EndsWith("\f") || itemstr.EndsWith("\v") || itemstr.EndsWith("\t") || itemstr.EndsWith("\r") || itemstr.EndsWith("\n"))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Remove(itemstr.Length - 2);
|
|
|
+ }
|
|
|
+ if (itemstr.EndsWith("\""))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Remove(itemstr.Length - 1);
|
|
|
+ }
|
|
|
+ if (itemstr.Contains("\\\""))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Replace("\\\"", "\"");
|
|
|
+ }
|
|
|
+
|
|
|
+ DataColumn DC = new DataColumn(itemstr, Type.GetType("System.String"));
|
|
|
+ if (!box.Columns.Contains(itemc.Key))
|
|
|
+ box.Columns.Add(DC);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i < barcode.Count; i++)
|
|
|
+ {
|
|
|
+ Dictionary<string, object> item = barcode[i];
|
|
|
+ if (i == 0 && item["BAN_OUTBOXCODE"].ToString() != nowboxcode && nowboxcode != "")
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ itemBox = BoxBarcode.Find(p => p["BAN_OUTBOXCODE"].ToString().Replace(" ", "").Replace("\"", "") == itemlast["BAN_OUTBOXCODE"].ToString().Replace(" ", "").Replace("\"", ""));
|
|
|
+ FillPrintData(box, itemBox, BoxParameter);
|
|
|
+ PrintLabel(box, box_type, AllBoxname);
|
|
|
+ Console.WriteLine("一箱" + itemlast["BAN_OUTBOXCODE"].ToString());
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ nowboxcode = "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (i > 0 && item["BAN_OUTBOXCODE"].ToString() != barcode[i - 1]["BAN_OUTBOXCODE"].ToString())
|
|
|
+ {
|
|
|
+ PrintLabel(dt,labelview, AllLabelname);
|
|
|
+ itemlast = barcode[i - 1];
|
|
|
+ try
|
|
|
+ {
|
|
|
+ itemBox = BoxBarcode.Find(p => p["BAN_OUTBOXCODE"].ToString().Replace(" ", "").Replace("\"", "") == itemlast["BAN_OUTBOXCODE"].ToString().Replace(" ", "").Replace("\"", ""));
|
|
|
+ FillPrintData(box, itemBox, BoxParameter);
|
|
|
+ PrintLabel(box, box_type, AllBoxname);
|
|
|
+ Console.WriteLine("一箱" + itemlast["BAN_OUTBOXCODE"].ToString());
|
|
|
+ }
|
|
|
+ catch {}
|
|
|
+ }
|
|
|
+ FillPrintData(dt, item, parameter);
|
|
|
+ }
|
|
|
+ PrintLabel(dt, labelview,AllLabelname);
|
|
|
+ itemlast = barcode[barcode.Count-1];
|
|
|
+ if (((String)((Dictionary<string, object>)data)["currentPage"]).Replace("\"", "") == ((String)((Dictionary<string, object>)data)["totalPage"]).Replace("\"", ""))
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ itemBox = BoxBarcode.Find(p => p["BAN_OUTBOXCODE"].ToString().Replace(" ", "").Replace("\"", "") == itemlast["BAN_OUTBOXCODE"].ToString().Replace(" ", "").Replace("\"", ""));
|
|
|
+ FillPrintData(box, itemBox, BoxParameter);
|
|
|
+ PrintLabel(box, box_type, AllBoxname);
|
|
|
+ Console.WriteLine("一箱" + itemBox["BAN_OUTBOXCODE"].ToString());
|
|
|
+ }
|
|
|
+ catch { }
|
|
|
+ nowboxcode = "";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ nowboxcode = itemlast["BAN_OUTBOXCODE"].ToString();
|
|
|
+ }
|
|
|
+ dt.Clear();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void FillPrintData(DataTable dt, Dictionary<string, object> item, List<Dictionary<string, object>> parameter1) {
|
|
|
+
|
|
|
+ DataRow dr = dt.NewRow();
|
|
|
+ foreach (var itemc in item)
|
|
|
+ {
|
|
|
+ Dictionary<string, object> Sidc = parameter1.Find(p => p["LP_NAME"].ToString().Replace(" ", "").Replace("\"", "").ToUpper() == itemc.Key.ToUpper());
|
|
|
+ if (Sidc != null)
|
|
|
+ {
|
|
|
+ if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "text")
|
|
|
+ {
|
|
|
+ string itemstr = "";
|
|
|
+ if (itemc.Value != null)
|
|
|
+ {
|
|
|
+ itemstr = itemc.Value.ToString();
|
|
|
+ while (itemstr.StartsWith("\f") || itemstr.StartsWith("\v") || itemstr.StartsWith("\t") || itemstr.StartsWith("\r") || itemstr.StartsWith("\n"))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Remove(0, 2);
|
|
|
+ }
|
|
|
+ if (itemstr.StartsWith("\""))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Remove(0, 1);
|
|
|
+ }
|
|
|
+ while (itemstr.EndsWith("\f") || itemstr.EndsWith("\v") || itemstr.EndsWith("\t") || itemstr.EndsWith("\r") || itemstr.EndsWith("\n"))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Remove(itemstr.Length - 2);
|
|
|
+ }
|
|
|
+ if (itemstr.EndsWith("\""))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Remove(itemstr.Length - 1);
|
|
|
+ }
|
|
|
+ if (itemstr.Contains("\\\""))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Replace("\\\"", "\"");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dr[itemc.Key] = itemstr;
|
|
|
+ }
|
|
|
+ else if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "barcode")
|
|
|
+ {
|
|
|
+ dr[itemc.Key] = itemc.Value.ToString().Replace("\"", "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dt.Rows.Add(dr);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PrintLabel(DataTable dt,string labelview,string LABELNAME)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ BarcodeReport.Load(System.AppDomain.CurrentDomain.BaseDirectory + LABELNAME + ".frx");
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ MessageBox.Show("未找到可使用的标签文件,请重试");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ BarcodeReport.RegisterData(dt, labelview);
|
|
|
+ BarcodeReport.GetDataSource(labelview).Enabled = true;
|
|
|
+ BarcodeReport.PrintSettings.ShowDialog = false;
|
|
|
+ BarcodeReport.PrintSettings.Printer = PrinterName;
|
|
|
+ BarcodeReport.Print();
|
|
|
+ CleanDataTable(dt);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ MessageBox.Show(ex.Message + "打印出现错误,请检查标签文件选择是否正确");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private void PrintPage(object sender, PrintPageEventArgs e)
|
|
|
{
|
|
@@ -439,13 +768,20 @@ namespace UAS_Web.tool
|
|
|
|
|
|
Graphics gr = print.PrintDoc.PrinterSettings.CreateMeasurementGraphics();
|
|
|
print.browser.FocusedFrame.ExecuteJavaScriptAsync("(function(value,value1){dpi=value,printType=value1})('" + gr.DpiX + "','" + PrintType + "')");
|
|
|
- if (PRXA.Checked)
|
|
|
+ if (PType == "all")
|
|
|
{
|
|
|
- print.browser.FocusedFrame.ExecuteJavaScriptAsync("document.getElementById('confirmZplPrint').click();");
|
|
|
+ print.browser.FocusedFrame.ExecuteJavaScriptAsync("document.getElementById('confirmBarcodeAndBoxPrint').click();");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- print.browser.FocusedFrame.ExecuteJavaScriptAsync("document.getElementById('confirmPicturePrint').click();");
|
|
|
+ if (PRXA.Checked)
|
|
|
+ {
|
|
|
+ print.browser.FocusedFrame.ExecuteJavaScriptAsync("document.getElementById('confirmZplPrint').click();");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ print.browser.FocusedFrame.ExecuteJavaScriptAsync("document.getElementById('confirmPicturePrint').click();");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
print.Close();
|
|
@@ -528,6 +864,13 @@ namespace UAS_Web.tool
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public static void CleanDataTable(DataTable dt)
|
|
|
+ {
|
|
|
+ for (int i = dt.Rows.Count - 1; i >= 0; i--)
|
|
|
+ dt.Rows.Remove(dt.Rows[i]);
|
|
|
+ }
|
|
|
+
|
|
|
public static Dictionary<string, object> ToDictionary(string JsonData)
|
|
|
{
|
|
|
object Data = null;
|