Преглед изворни кода

条码打印插件增加线程锁,供应商条码打印CS程序增加合并打印功能处理

Hcsy пре 6 година
родитељ
комит
1d5006c6b9

+ 8 - 2
UAS_PRINT/Form2.cs

@@ -79,11 +79,17 @@ namespace UAS_PRINT
                         if (req.Contains("\"" + "chooseprintername" + "\""))
                         {
                             req = req.Remove(req.IndexOf("device"), req.IndexOf("data") - 2);
-                            PrintHandler.vendorZplPrint(req);
+                            lock ("A")
+                            {
+                                PrintHandler.vendorZplPrint(req);
+                            }
                         }
                         else
                         {
-                            PrintHandler.zplprint(req);
+                            lock ("B")
+                            {
+                                PrintHandler.zplprint(req);
+                            }
                         }
                     }
                     else if (requestContext.Request.Url.PathAndQuery == "/default?type=printer")

+ 6 - 0
UAS_PRINT/UAS_PRINT.csproj

@@ -63,6 +63,12 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Form1.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Form1.Designer.cs">
+      <DependentUpon>Form1.cs</DependentUpon>
+    </Compile>
     <Compile Include="Form2.cs">
       <SubType>Form</SubType>
     </Compile>

+ 0 - 25
UAS_PRINT/采购验收条码打印.frx

@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Report ScriptLanguage="CSharp" ReportInfo.Created="10/19/2018 11:43:13" ReportInfo.Modified="10/26/2018 13:54:25" ReportInfo.CreatorVersion="2016.1.0.0">
-  <Styles>
-    <Style Name="格式1" Font="宋体, 8pt"/>
-  </Styles>
-  <Dictionary>
-    <OdbcDataConnection Name="Connection" ConnectionString="rijcmlq4T7ij3QEI356NBqYh9OCyJFC+4ve8MyX68hS9dp4KxtjsXmhMR5qHfWU7SD1aL6rtQ6veEInPXeBljObwgoETiL5P3lLDhCbg0cUCPa9CuOABr92GWnu+Z5vBcfzS8HrJAOBBcDODKQUJus9TGudO8ARvED8UkKj0en0ZcKe4dj09XgVxA1pioytn0IYDL/zOFU04YpURKHW6Tx+lE9WTOW5wZsdr27/idSqAYrKjs7Ad2fI/JfbJJP07iCmtxY1j+x5VbAvBa/yiOreXnYYUg==">
-      <TableDataSource Name="Table1" Alias="BARCODEIO_PRINT_VIEW" DataType="System.Int32" Enabled="true" SelectCommand="SELECT * FROM BARCODEIO_PRINT_VIEW">
-        <Column Name="BI_BARCODE" DataType="System.String"/>
-        <Column Name="BI_PRODCODE" DataType="System.String"/>
-        <Column Name="BI_INQTY" DataType="System.Double"/>
-        <Column Name="PR_ORISPECCODE" DataType="System.String"/>
-      </TableDataSource>
-    </OdbcDataConnection>
-  </Dictionary>
-  <ReportPage Name="Page1" PaperWidth="100" PaperHeight="40" LeftMargin="0" TopMargin="0" RightMargin="0" BottomMargin="0" FirstPageSource="4" OtherPagesSource="4" Guides="28.35,325.55,122.85,217.35,311.85,321.3">
-    <DataBand Name="Data1" Width="378" Height="151.2" FirstRowStartsNewPage="true" Guides="28.35,85.05,103.95,122.85,9.45">
-      <TextObject Name="Text1" Left="29.3" Top="9.45" Width="296.25" Height="18.9" Text="[BARCODEIO_PRINT_VIEW.BI_BARCODE]" HorzAlign="Center" Font="宋体, 9pt"/>
-      <BarcodeObject Name="Barcode1" Left="26.15" Top="37.8" Width="299.4" Height="47.25" AutoSize="false" DataColumn="BARCODEIO_PRINT_VIEW.BI_BARCODE" Text="" ShowText="false" Barcode.CalcCheckSum="false"/>
-      <TextObject Name="Text2" Left="28.35" Top="94.5" Width="94.5" Height="18.9" Text="[BARCODEIO_PRINT_VIEW.BI_PRODCODE]" Font="宋体, 9pt"/>
-      <TextObject Name="Text3" Left="122.85" Top="94.5" Width="94.5" Height="18.9" Text="[BARCODEIO_PRINT_VIEW.PR_ORISPECCODE]" Font="宋体, 9pt"/>
-      <TextObject Name="Text4" Left="217.35" Top="94.5" Width="108.2" Height="18.9" Text="[BARCODEIO_PRINT_VIEW.BI_INQTY]" Format="Number" Format.UseLocale="true" HorzAlign="Right" WordWrap="false" Font="宋体, 9pt" Trimming="EllipsisCharacter"/>
-    </DataBand>
-  </ReportPage>
-</Report>

+ 9 - 6
UAS_Web/Browser.cs

@@ -10,6 +10,7 @@ using System.Net;
 using System.Text;
 using System.IO;
 using System.Web;
+using System.Threading;
 
 namespace UAS_Web
 {
@@ -24,7 +25,7 @@ namespace UAS_Web
             InitializeComponent();
             Text = "供应商条码打印";
  
-            string path = "http://192.168.253.80:8090/ERP/jsps/vendbarcode/login.jsp";
+            string path = "http://183.238.39.179:8099/ERP/jsps/vendbarcode/login.jsp";
             webBrowser = new ChromiumWebBrowser(path)
             {
                 Dock = DockStyle.Fill
@@ -46,14 +47,16 @@ namespace UAS_Web
 
         void FrameLoadEnd(object sender, FrameLoadEndEventArgs e)
         {
+          Thread.Sleep(500);
+          var cookiemanager = CefSharp.Cef.GetGlobalCookieManager();
+          CookieVisitor visitor = new CookieVisitor();
+          visitor.SendCookie += visitor_SendCookie;
+          cookiemanager.VisitAllCookies(visitor);
             if (e.Url.Contains("vendbarcode/login.jsp") || e.Url.Contains("relogin.action"))
             {
-                e.Browser.FocusedFrame.EvaluateScriptAsync("document.getElementById('username').value = '"+BaseUtil.GetCacheData("username") +"';document.getElementById('password').value = '"+ BaseUtil.GetCacheData("password") + "';document.getElementById('master').innerHTML = '"+ BaseUtil.GetCacheData("master_fun") + "';document.getElementById('master1').value = '"+ BaseUtil.GetCacheData("master_name") + "';", new TimeSpan(600000));
+                e.Browser.FocusedFrame.EvaluateScriptAsync("document.getElementById('username').value = '" + BaseUtil.GetCacheData("username") + "';document.getElementById('password').value = '" + BaseUtil.GetCacheData("password") + "';document.getElementById('master').innerHTML = '" + BaseUtil.GetCacheData("master_fun") + "';document.getElementById('master1').value = '" + BaseUtil.GetCacheData("master_name") + "';", new TimeSpan(600000));
+                return;
             }
-                var cookiemanager = CefSharp.Cef.GetGlobalCookieManager();
-                CookieVisitor visitor = new CookieVisitor();
-                visitor.SendCookie += visitor_SendCookie;
-                cookiemanager.VisitAllCookies(visitor);
         }
         
         private void visitor_SendCookie(CefSharp.Cookie obj)

+ 69 - 0
UAS_Web/Properties/app.manifest

@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="utf-8"?>
+<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
+  <assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
+  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
+    <security>
+      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
+        <!-- UAC 清单选项
+             如果想要更改 Windows 用户帐户控制级别,请使用
+             以下节点之一替换 requestedExecutionLevel 节点。n
+        <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
+        <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
+        <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />
+
+            指定 requestedExecutionLevel 元素将禁用文件和注册表虚拟化。
+            如果你的应用程序需要此虚拟化来实现向后兼容性,则删除此
+            元素。
+        -->
+        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
+      </requestedPrivileges>
+      <applicationRequestMinimum>
+        <defaultAssemblyRequest permissionSetReference="Custom" />
+        <PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" SameSite="site" Unrestricted="true" />
+      </applicationRequestMinimum>
+    </security>
+  </trustInfo>
+  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
+    <application>
+      <!-- 设计此应用程序与其一起工作且已针对此应用程序进行测试的
+           Windows 版本的列表。取消评论适当的元素,Windows 将
+           自动选择最兼容的环境。 -->
+      <!-- Windows Vista -->
+      <!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
+      <!-- Windows 7 -->
+      <!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
+      <!-- Windows 8 -->
+      <!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
+      <!-- Windows 8.1 -->
+      <!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
+      <!-- Windows 10 -->
+      <!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
+    </application>
+  </compatibility>
+  <!-- 指示该应用程序可以感知 DPI 且 Windows 在 DPI 较高时将不会对其进行
+       自动缩放。Windows Presentation Foundation (WPF)应用程序自动感知 DPI,无需
+       选择加入。选择加入此设置的 Windows 窗体应用程序(目标设定为 .NET Framework 4.6 )还应
+       在其 app.config 中将 "EnableWindowsFormsHighDpiAutoResizing" 设置设置为 "true"。-->
+  <!--
+  <application xmlns="urn:schemas-microsoft-com:asm.v3">
+    <windowsSettings>
+      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
+    </windowsSettings>
+  </application>
+  -->
+  <!-- 启用 Windows 公共控件和对话框的主题(Windows XP 和更高版本) -->
+  <!--
+  <dependency>
+    <dependentAssembly>
+      <assemblyIdentity
+          type="win32"
+          name="Microsoft.Windows.Common-Controls"
+          version="6.0.0.0"
+          processorArchitecture="*"
+          publicKeyToken="6595b64144ccf1df"
+          language="*"
+        />
+    </dependentAssembly>
+  </dependency>
+  -->
+</assembly>

+ 0 - 4
UAS_Web/UAS_Web.csproj

@@ -105,10 +105,6 @@
     <Reference Include="System.Drawing" />
     <Reference Include="System.Windows.Forms" />
     <Reference Include="System.Xml" />
-    <Reference Include="Zen.Barcode.Core, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b5ae55aa76d2d9de, processorArchitecture=MSIL">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>tool\Zen.Barcode.Core.dll</HintPath>
-    </Reference>
     <Reference Include="zxing, Version=0.16.2.0, Culture=neutral, PublicKeyToken=4e88037ac681fe60, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
       <HintPath>tool\zxing.dll</HintPath>

+ 0 - 2
UAS_Web/packages.config

@@ -4,6 +4,4 @@
   <package id="cef.redist.x86" version="3.2623.1401" targetFramework="net40" />
   <package id="CefSharp.Common" version="49.0.1" targetFramework="net40" />
   <package id="CefSharp.WinForms" version="49.0.1" targetFramework="net40" />
-  <package id="Newtonsoft.Json" version="11.0.2" targetFramework="net40" />
-  <package id="Zen.Barcode.Rendering.Framework" version="3.1.10729.1" targetFramework="net40" />
 </packages>

+ 1 - 6
UAS_Web/tool/PrintHelper.cs

@@ -1,15 +1,10 @@
 using System;
-using System.Collections.Generic;
 using System.Drawing;
 using System.Drawing.Drawing2D;
 using System.Drawing.Text;
 using System.IO;
-using System.Linq;
 using System.Runtime.InteropServices;
-using System.Text;
-using Zen.Barcode;
-using ZXing;
-using ZXing.QrCode;
+
 
 namespace UAS_Web.tool
 {

+ 359 - 16
UAS_Web/tool/RequestHandler.cs

@@ -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 = "";
+
 
         /// <summary>
         /// 拦截指定请求
@@ -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);
+                                        //LABELNAME = body.Substring(body.LastIndexOf('=') + 1);
+                                        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;
+                        }
+                         //vendorZplPrint(data);
+                        //vendorZplPrintAll(data);
                     }
                     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))
                 {
-                    //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());
@@ -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
+            DataTable dt = new DataTable();
+            //箱号标签结构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>> parameter2 = 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("标签更新有误");
+           
+
+            //barcode条码datable格式
+            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);
+                    }
+                }
+            }
+
+            //box箱号datatable格式
+            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();
+        }
+
+        //给datable添加行(添加打印具体数据)
+        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;