瀏覽代碼

供应商条码打印CS程序修改

Hcsy 7 年之前
父節點
當前提交
2690b96283
共有 4 個文件被更改,包括 225 次插入176 次删除
  1. 1 1
      UAS_Web/Browser.cs
  2. 4 2
      UAS_Web/PrinterList.Designer.cs
  3. 15 4
      UAS_Web/tool/DownLoadFile.cs
  4. 205 169
      UAS_Web/tool/RequestHandler.cs

+ 1 - 1
UAS_Web/Browser.cs

@@ -18,7 +18,7 @@ namespace UAS_Web
         {
             InitializeComponent();
             Text = "供应商条码打印";
-            string path = "http://183.238.39.179:8099/ERP/jsps/vendbarcode/login.jsp";
+            string path = "http://192.168.253.80:8090/ERP/jsps/vendbarcode/login.jsp";
             webBrowser = new ChromiumWebBrowser(path)
             {
                 Dock = DockStyle.Fill

+ 4 - 2
UAS_Web/PrinterList.Designer.cs

@@ -58,14 +58,13 @@
             // PRXA
             // 
             this.PRXA.AutoSize = true;
-            this.PRXA.Checked = true;
             this.PRXA.Location = new System.Drawing.Point(29, 84);
             this.PRXA.Name = "PRXA";
             this.PRXA.Size = new System.Drawing.Size(71, 16);
             this.PRXA.TabIndex = 2;
-            this.PRXA.TabStop = true;
             this.PRXA.Text = "指令打印";
             this.PRXA.UseVisualStyleBackColor = true;
+            this.PRXA.Visible = false;
             // 
             // PRPIC
             // 
@@ -76,10 +75,12 @@
             this.PRPIC.TabIndex = 3;
             this.PRPIC.Text = "图片打印";
             this.PRPIC.UseVisualStyleBackColor = true;
+            this.PRPIC.Visible = false;
             // 
             // PRFR
             // 
             this.PRFR.AutoSize = true;
+            this.PRFR.Checked = true;
             this.PRFR.Location = new System.Drawing.Point(226, 84);
             this.PRFR.Name = "PRFR";
             this.PRFR.Size = new System.Drawing.Size(71, 16);
@@ -87,6 +88,7 @@
             this.PRFR.TabStop = true;
             this.PRFR.Text = "程序打印";
             this.PRFR.UseVisualStyleBackColor = true;
+            this.PRFR.Visible = false;
             // 
             // PrinterList
             // 

+ 15 - 4
UAS_Web/tool/DownLoadFile.cs

@@ -1,6 +1,7 @@
 using CefSharp;
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Linq;
 using System.Text;
 
@@ -8,21 +9,31 @@ namespace UAS_Web.tool
 {
     class DownLoadFile : IDownloadHandler
     {
+        public static bool downloading = false;
+
         public void OnBeforeDownload(IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
         {
             if (!callback.IsDisposed)
             {
                 using (callback)
-                {
+                {                   
                     callback.Continue(System.AppDomain.CurrentDomain.BaseDirectory + downloadItem.SuggestedFileName,
-                        showDialog: false);
+                        showDialog: false);          
                 }
-            }
+            }    
         }
 
         public void OnDownloadUpdated(IBrowser browser, DownloadItem downloadItem, IDownloadItemCallback callback)
         {
-           
+            if (downloadItem.IsComplete)
+            {
+                downloading = false;
+            }
+            else {
+                downloading = true;
+            }        
         }
+
+        
     }
 }

+ 205 - 169
UAS_Web/tool/RequestHandler.cs

@@ -13,6 +13,7 @@ using System.Threading;
 using System.Net;
 using System.Text;
 using System.Web;
+using System.Diagnostics;
 
 namespace UAS_Web.tool
 {
@@ -25,7 +26,8 @@ namespace UAS_Web.tool
 
      
 
-        Report Report = new Report();
+        Report BarcodeReport  = new Report();
+        Report BoxReport = new Report();
 
         //图片打印中间变量
         int imagecount = 0;
@@ -153,217 +155,248 @@ namespace UAS_Web.tool
                     PrintType = data["data"].ToString().Replace("\"", "");
                     break;
                 case "vendorZplPrint.action":
-                    DataTable dt = new DataTable();
-                    RadioButton PRFR = (RadioButton)print.Controls["PRFR"];
-                    RadioButton PRPIC = (RadioButton)print.Controls["PRPIC"];
-                    string type;
-                    bitmaps.Clear();
                     try
                     {
                         filter = FilterManager.GetFileter(request.Identifier.ToString()) as MessageFilter;
                         str = System.Text.Encoding.UTF8.GetString(filter.dataAll.ToArray());
                         data = ToDictionary(str);
+                        vendorZplPrint(data);                   
                     }
-                    catch {
-                        return;
-                    }
-                    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"];
-                    try 
+                    catch (Exception ex)
                     {
-                         type = ((String)data["type"]).Replace("\"", "");
-                    }
-                    catch {
-                         type = "no";
+                        MessageBox.Show(ex.Message + "请重新进行打印");
+                        return;
                     }
+                    break;
+                default:
+                    break;
+            }
+        }
 
-                    if (PRFR.Checked)
+            public  void vendorZplPrint(Object data)
+       {
+            DataTable dt = new DataTable();
+            RadioButton PRFR = (RadioButton)print.Controls["PRFR"];
+            RadioButton PRPIC = (RadioButton)print.Controls["PRPIC"];
+            string type;
+            bitmaps.Clear();
+            List<Dictionary<string, object>> parameter = new List<Dictionary<string, object>>();
+            List<Dictionary<string, object>> barcode = new List<Dictionary<string, object>>();
+            try
+            {            
+                parameter = (List<Dictionary<string, object>>)((Dictionary<string, object>)data)["parameter"];
+                barcode = (List<Dictionary<string, object>>)((Dictionary<string, object>)data)["barcode"];
+            }
+            catch {
+                MessageBox.Show("打印数据解析异常,请联系管理员进行处理");
+                return;
+            }
+            try
+            {
+                type = ((String)((Dictionary<string, object>)data)["type"]).Replace("\"", "");
+            }
+            catch
+            {
+                type = "no";
+            }
+
+            if (PRFR.Checked)
+            {
+                Thread.Sleep(1000);
+                int i = 0;
+                while (DownLoadFile.downloading && i < 2)
+                {
+                    Thread.Sleep(1000);
+                    i++;
+                }
+                if (DownLoadFile.downloading)
+                    Console.WriteLine("标签更新有误");
+                try
+                {
+                    if (type == "box")
                     {
-                        Thread.Sleep(800);
-                        try
-                        {
-                            if (type == "box")
-                            {
-                                Report.Load(System.AppDomain.CurrentDomain.BaseDirectory + "GD_box.frx");
-                            }
-                            else
-                            {
-                                Report.Load(System.AppDomain.CurrentDomain.BaseDirectory + LABELNAME+".frx");
-                            }
-                        }
-                        catch
-                        {
-                            MessageBox.Show("未找到可使用的标签文件");
-                            return;
-                        }
+                        BoxReport.Load(System.AppDomain.CurrentDomain.BaseDirectory + LABELNAME + ".frx");
                     }
-                    int la_width = int.Parse(parameter.First()["LA_WIDTH"].ToString());
-                    int la_height = int.Parse(parameter.First()["LA_HEIGHT"].ToString());
+                    else {
+                        BarcodeReport.Load(System.AppDomain.CurrentDomain.BaseDirectory + LABELNAME + ".frx");
+                    }
+                }
+                catch
+                {
+                    MessageBox.Show("未找到可使用的标签文件,请重试");
+                    return;
+                }
+            }
+            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 * 10, la_height * 4);
+            foreach (var item in barcode)
+            {
+                Bitmap bit = new Bitmap(la_width * 10, la_height * 4);
 
 
-                        using (Graphics g = Graphics.FromImage(bit))
+                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 != null)
                         {
-                            //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)
+                            if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "text")
                             {
-                                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")
+                                string itemstr = "";
+                                if (itemc.Value != null)
                                 {
-                                    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 = 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("\\\"", "\"");                                 
-                                        }
+                                        itemstr = itemstr.Remove(0, 2);
                                     }
-                                    if (PRFR.Checked)
+                                    if (itemstr.StartsWith("\""))
                                     {
-                                        DataColumn DC = new DataColumn(itemc.Key, Type.GetType("System.String"));
-                                        if (!dt.Columns.Contains(itemc.Key))
-                                            dt.Columns.Add(DC);
+                                        itemstr = itemstr.Remove(0, 1);
                                     }
-                                    if (PRPIC.Checked)
+                                    while (itemstr.EndsWith("\f") || itemstr.EndsWith("\v") || itemstr.EndsWith("\t") || itemstr.EndsWith("\r") || itemstr.EndsWith("\n"))
                                     {
-                                        PrintHelper.Printstring(itemc.Value != null ? itemstr : " ", int.Parse(Sidc["LP_SIZE"].ToString()), g, int.Parse(Sidc["LP_LEFTRATE"].ToString()), int.Parse(Sidc["LP_TOPRATE"].ToString()));
+                                        itemstr = itemstr.Remove(itemstr.Length - 2);
                                     }
-                                }
-                                else if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "barcode")
-                                {
-                                    if (PRFR.Checked)
+                                    if (itemstr.EndsWith("\""))
                                     {
-                                        DataColumn DC = new DataColumn(itemc.Key, Type.GetType("System.String"));
-                                        if (!dt.Columns.Contains(itemc.Key))
-                                            dt.Columns.Add(DC);
+                                        itemstr = itemstr.Remove(itemstr.Length - 1);
                                     }
-                                    if (PRPIC.Checked)
+                                    if (itemstr.Contains("\\\""))
                                     {
-                                        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);
+                                        itemstr = itemstr.Replace("\\\"", "\"");
                                     }
                                 }
+                                if (PRFR.Checked)
+                                {
+                                    DataColumn DC = new DataColumn(itemc.Key, Type.GetType("System.String"));
+                                    if (!dt.Columns.Contains(itemc.Key))
+                                        dt.Columns.Add(DC);
+                                }
+                                if (PRPIC.Checked)
+                                {
+                                    PrintHelper.Printstring(itemc.Value != null ? itemstr : " ", int.Parse(Sidc["LP_SIZE"].ToString()), g, int.Parse(Sidc["LP_LEFTRATE"].ToString()), int.Parse(Sidc["LP_TOPRATE"].ToString()));
+                                }
                             }
-                        }
-                        bitmaps.Add(bit);
-                    }
-                    if (PRFR.Checked)
-                    {
-                        foreach (var item in barcode)
-                        {
-                            DataRow dr = dt.NewRow();
-                            //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)
+                            else if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "barcode")
                             {
-                                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")
+                                if (PRFR.Checked)
                                 {
-                                    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("\\\"", "\"");
-                                            Console.WriteLine(itemstr);
-                                        }
-                                    }
-                                    dr[itemc.Key] = itemstr;
+                                    DataColumn DC = new DataColumn(itemc.Key, Type.GetType("System.String"));
+                                    if (!dt.Columns.Contains(itemc.Key))
+                                        dt.Columns.Add(DC);
                                 }
-                                else if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "barcode")
+                                if (PRPIC.Checked)
                                 {
-                                    dr[itemc.Key] = itemc.Value.ToString().Replace("\"", "");
+                                    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);
                                 }
                             }
-                            dt.Rows.Add(dr);
-                        }
-                    }
-                    if (PRPIC.Checked)
-                    {
-                        if (bitmaps.Count > 0)
-                        {
-                            imagecount = bitmaps.Count;
-                            ////设置打印机名称
-                           
-                            print.PrintDoc.Print();
                         }
                     }
-                    if(PRFR.Checked)
+                }
+                bitmaps.Add(bit);
+            }
+            if (PRFR.Checked)
+            {
+                foreach (var item in barcode)
+                {
+                    DataRow dr = dt.NewRow();
+                    //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)
                     {
-                        try
+                        Dictionary<string, object> Sidc = parameter.Find(p => p["LP_NAME"].ToString().Replace(" ", "").Replace("\"", "").ToUpper() == itemc.Key.ToUpper());
+                        if (Sidc != null)
                         {
-                            if (type == "box")
+                            if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "text")
                             {
-                                Report.RegisterData(dt, "VENDORBARCODE_BOX_VIEW");
-                                Report.GetDataSource("VENDORBARCODE_BOX_VIEW").Enabled = true;
+                                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("\\\"", "\"");
+                                        Console.WriteLine(itemstr);
+                                    }
+                                }
+                                dr[itemc.Key] = itemstr;
                             }
-                            else {
-                                Report.RegisterData(dt, "VENDORBARCODE_VIEW");
-                                Report.GetDataSource("VENDORBARCODE_VIEW").Enabled = true;
+                            else if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "barcode")
+                            {
+                                dr[itemc.Key] = itemc.Value.ToString().Replace("\"", "");
                             }
-                          
-                            Report.PrintSettings.ShowDialog = false;
-                            Report.PrintSettings.Printer = PrinterName;
-                            Report.Print();
-                        }
-                        catch {
-                            MessageBox.Show("程序打印出现错误,请检查标签文件格式");
                         }
-                        dt.Clear();
                     }
-                    break;
-                default:
-                    break;
+                    dt.Rows.Add(dr);
+                }
+            }
+            if (PRPIC.Checked)
+            {
+                if (bitmaps.Count > 0)
+                {
+                    imagecount = bitmaps.Count;
+                    print.PrintDoc.Print();
+                }
+            }
+            if (PRFR.Checked)
+            {
+                try
+                {
+                    if (type == "box")
+                    {
+                        BoxReport.RegisterData(dt, "VENDORBARCODE_BOX_VIEW");
+                        BoxReport.GetDataSource("VENDORBARCODE_BOX_VIEW").Enabled = true;
+                        BoxReport.PrintSettings.ShowDialog = false;
+                        BoxReport.PrintSettings.Printer = PrinterName;
+                        BoxReport.Print();
+                    }
+                    else
+                    {
+                        BarcodeReport.RegisterData(dt, "VENDORBARCODE_VIEW");
+                        BarcodeReport.GetDataSource("VENDORBARCODE_VIEW").Enabled = true;
+                        BarcodeReport.PrintSettings.ShowDialog = false;
+                        BarcodeReport.PrintSettings.Printer = PrinterName;
+                        BarcodeReport.Print();
+                    }      
+                }
+                catch(Exception ex)
+                {
+                    MessageBox.Show(ex.Message+"打印出现错误,请检查标签文件选择是否正确");
+                }
+                dt.Clear();
+         
             }
         }
 
@@ -394,11 +427,14 @@ 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 (PRXA.Checked)
+            {
                 print.browser.FocusedFrame.ExecuteJavaScriptAsync("document.getElementById('confirmZplPrint').click();");
             }
             else
+            {
                 print.browser.FocusedFrame.ExecuteJavaScriptAsync("document.getElementById('confirmPicturePrint').click();");
+            }
 
             print.Close();
         }