Browse Source

供应商条码打印以及打印插件修改:标签类型由json数据获取

Hcsy 7 years ago
parent
commit
1c1f73f7c4
2 changed files with 59 additions and 25 deletions
  1. 29 14
      UAS_PRINT/PrintHandler.cs
  2. 30 11
      UAS_Web/tool/RequestHandler.cs

+ 29 - 14
UAS_PRINT/PrintHandler.cs

@@ -14,15 +14,10 @@ namespace UAS_PRINT
     class PrintHandler
     {
 
-        //图片打印中间变量
-        static int imagecount = 0;
-        static int index = 0;
-
         //打印图片集合
         static List<Bitmap> bitmaps = new List<Bitmap>();
-
-        static DataTable dt = new DataTable("VENDORBARCODE_VIEW");
-
+        static DataTable dt = new DataTable();
+     
         public static void zplprint(string str, string PrinterName)
         {
             Dictionary<string, object> data = PrintHelper.ToDictionary(str);
@@ -79,6 +74,9 @@ namespace UAS_PRINT
         {
             Report Report = new Report();
             string chooseprintername;
+            string label_type = "";
+            string label_name = "";
+
             Dictionary<string, object> data = PrintHelper.ToDictionary(str);
             List<Dictionary<string, object>> parameter = new List<Dictionary<string, object>>();
             List<Dictionary<string, object>> barcode = new List<Dictionary<string, object>>();
@@ -98,11 +96,30 @@ namespace UAS_PRINT
             }
             catch
             {
-                chooseprintername = "no";
+                MessageBox.Show("未传输打印机名称至打印程序,请联系管理员进行处理", "提示");
+                return;
+            }
+            try
+            {
+                label_type = ((string)data["label_type"]).Replace("\"", "");
+            }
+            catch
+            {
+                MessageBox.Show("未获取到标签类型,请联系管理员进行处理", "提示");
+                return;
+            }
+            try
+            {
+                label_name = ((string)data["label_name"]).Replace("\"", "");
+            }
+            catch
+            {
+                MessageBox.Show("未获取到标签名称,请联系管理员进行处理", "提示");
+                return;
             }
             try
             {
-                Report.Load(System.AppDomain.CurrentDomain.BaseDirectory + "库存条码打印.frx");
+                Report.Load(System.AppDomain.CurrentDomain.BaseDirectory + label_name+".frx");
             }
             catch
             {
@@ -155,8 +172,7 @@ namespace UAS_PRINT
                             if (!dt.Columns.Contains(itemc.Key))
                                 dt.Columns.Add(DC);
                         }
-                    }
-                
+                    }               
             }
             foreach (var item in barcode)
             {
@@ -203,9 +219,8 @@ namespace UAS_PRINT
             }
             try
             {
-               
-                Report.RegisterData(dt, "BARCODE_PRINT_VIEW");
-                Report.GetDataSource("BARCODE_PRINT_VIEW").Enabled = true;
+                Report.RegisterData(dt, label_type);
+                Report.GetDataSource(label_type).Enabled = true;
                 Report.PrintSettings.ShowDialog = false;
                 Report.PrintSettings.Printer = chooseprintername;
                 Report.Print();

+ 30 - 11
UAS_Web/tool/RequestHandler.cs

@@ -41,6 +41,7 @@ namespace UAS_Web.tool
 
 
         string LABELNAME = "";
+        string labelview = "";
 
 
         /// <summary>
@@ -199,6 +200,14 @@ namespace UAS_Web.tool
             {
                 type = "no";
             }
+            try
+            {
+                labelview = ((String)((Dictionary<string, object>)data)["label_type"]).Replace("\"", "");
+            }
+            catch
+            {
+                labelview = "";
+            }
 
             if (PRFR.Checked)
             {
@@ -374,22 +383,32 @@ namespace UAS_Web.tool
             {
                 try
                 {
-                    if (type == "box")
+                    if (labelview == "")
                     {
-                        BoxReport.RegisterData(dt, "VENDORBARCODE_BOX_VIEW");
-                        BoxReport.GetDataSource("VENDORBARCODE_BOX_VIEW").Enabled = true;
-                        BoxReport.PrintSettings.ShowDialog = false;
-                        BoxReport.PrintSettings.Printer = PrinterName;
-                        BoxReport.Print();
+                        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();
+                        }
                     }
-                    else
-                    {
-                        BarcodeReport.RegisterData(dt, "VENDORBARCODE_VIEW");
-                        BarcodeReport.GetDataSource("VENDORBARCODE_VIEW").Enabled = true;
+                    else {
+                        BarcodeReport.RegisterData(dt, labelview);
+                        BarcodeReport.GetDataSource(labelview).Enabled = true;
                         BarcodeReport.PrintSettings.ShowDialog = false;
                         BarcodeReport.PrintSettings.Printer = PrinterName;
                         BarcodeReport.Print();
-                    }      
+                    }    
                 }
                 catch(Exception ex)
                 {