Browse Source

修改持支BarTender打印

callm 5 years ago
parent
commit
b0ed016127

+ 39 - 23
UAS_MES_MAXMADE/PublicMethod/Print.cs

@@ -6,6 +6,7 @@ using System.IO;
 using UAS_MES_MAXMADE.Entity;
 using System.Text.RegularExpressions;
 using System.Windows.Forms;
+using Seagull.BarTender.Print;
 
 namespace UAS_MES_MAXMADE.PublicMethod
 {
@@ -14,14 +15,12 @@ namespace UAS_MES_MAXMADE.PublicMethod
         static DataHelper dh = SystemInf.dh;
         //CodeSoft打印的驱动和文件
         static Document doc;
-        ////CodeSoft的打印机
-        //string CodeSpft_Printer;
-        static FileInfo info;
 
-        public Print() { }
+        static LabelFormatDocument format;
 
+        public Print() { }
 
-        public static bool CodeSoft(string iCaller, Document doc, string LabelName, string LaID, string PrinterName, string SnCode, int PrintNum, string MakeCode, string ProdCode, string LabelType, string IfRePrint, out string ErrorMessage)
+        public static bool CodeSoft(string iCaller, ref ApplicationClass lbl, string LabelName, string LaID, string PrinterName, string SnCode, int PrintNum, string MakeCode, string ProdCode, string LabelType, string IfRePrint, out string ErrorMessage)
         {
             ErrorMessage = "";
             DataTable dt = new DataTable();
@@ -42,15 +41,33 @@ namespace UAS_MES_MAXMADE.PublicMethod
                     return false;
                 }
             }
+            string filelastwritetime = dh.getFieldDataByCondition("label", "la_lastwritetime", "la_id = '" + LaID + "'").ToString();
+            FileInfo PrintFile = new FileInfo(LabelName);
             //打开模板路径
             //查询模板对应的取值SQL和参数名称
             dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id=lp_laid where la_id='" + LaID + "'", "select");
             StringBuilder sb = new StringBuilder();
-            if (doc == null)
+            if (!PrintFile.Exists)
             {
                 MessageBox.Show("打印文件不存在");
                 return false;
             }
+            string filechangetime = PrintFile.LastWriteTime.ToString();
+            if (filechangetime != filelastwritetime)
+            {
+                lbl.Quit();
+                lbl = new ApplicationClass();
+                BaseUtil.WriteLbl();
+                filechangetime = PrintFile.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
+                string update = "la_lastwritetime = to_date((regexp_substr('" + filechangetime + "','\\d+.+\\d+')),'yyyy-mm-dd hh24:mi:ss')";
+                dh.UpdateByCondition("label", update, "la_id = '" + LaID + "'");
+            }
+            doc = lbl.Documents.Open(LabelName, true);
+            if (doc == null)
+            {
+                MessageBox.Show("标签文件打开失败");
+                return false;
+            }
             //执行全部的SQL
             for (int i = 0; i < dt.Rows.Count; i++)
             {
@@ -87,7 +104,7 @@ namespace UAS_MES_MAXMADE.PublicMethod
                         }
                     }
                 }
-                catch (System.Exception ex)
+                catch (System.Exception)
                 {
                     MessageBox.Show("SQL维护不正确");
                 }
@@ -105,8 +122,7 @@ namespace UAS_MES_MAXMADE.PublicMethod
             return true;
         }
 
-
-        public static bool CodeSoft(string iCaller, ref ApplicationClass lbl, string LabelName, string LaID, string PrinterName, string SnCode, int PrintNum, string MakeCode, string ProdCode, string LabelType, string IfRePrint, out string ErrorMessage)
+        public static bool BarTender(string iCaller, ref Engine lbl, string LabelName, string LaID, string PrinterName, string SnCode, int PrintNum, string MakeCode, string ProdCode, string LabelType, string IfRePrint, out string ErrorMessage)
         {
             ErrorMessage = "";
             DataTable dt = new DataTable();
@@ -141,15 +157,15 @@ namespace UAS_MES_MAXMADE.PublicMethod
             string filechangetime = PrintFile.LastWriteTime.ToString();
             if (filechangetime != filelastwritetime)
             {
-                lbl.Quit();
-                lbl = new ApplicationClass();
+                lbl.Stop();
+                lbl = new Engine();
                 BaseUtil.WriteLbl();
                 filechangetime = PrintFile.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
                 string update = "la_lastwritetime = to_date((regexp_substr('" + filechangetime + "','\\d+.+\\d+')),'yyyy-mm-dd hh24:mi:ss')";
                 dh.UpdateByCondition("label", update, "la_id = '" + LaID + "'");
             }
-            doc = lbl.Documents.Open(LabelName, true);
-            if (doc == null)
+            format = lbl.Documents.Open(LabelName);
+            if (format == null)
             {
                 MessageBox.Show("标签文件打开失败");
                 return false;
@@ -175,34 +191,34 @@ namespace UAS_MES_MAXMADE.PublicMethod
                         int LoopTime = Param.Rows.Count > 100 ? 100 : Param.Rows.Count;
                         for (int j = 0; j < LoopTime; j++)
                         {
-                            for (int k = 0; k < doc.Variables.FormVariables.Count; k++)
+                            for (int k = 0; k < format.SubStrings.Count; k++)
                             {
-                                if (j == 0 & doc.Variables.FormVariables.Item(k + 1).Name.ToUpper() == dt.Rows[i]["lp_name"].ToString().ToUpper())
+                                if (j == 0 & format.SubStrings[k].Name.ToUpper() == dt.Rows[i]["lp_name"].ToString().ToUpper())
                                 {
-                                    doc.Variables.FormVariables.Item(k + 1).Value = Param.Rows[0][0].ToString();
+                                    format.SubStrings[k].Value = Param.Rows[0][0].ToString();
                                 }
                                 //使用SN开头的参数赋值SN1,SN2,SN3等参数
-                                if (doc.Variables.FormVariables.Item(k + 1).Name.ToUpper() == dt.Rows[i]["lp_name"].ToString().ToUpper() + (j + 1))
+                                if (format.SubStrings[k].Name.ToUpper() == dt.Rows[i]["lp_name"].ToString().ToUpper() + (j + 1))
                                 {
-                                    doc.Variables.FormVariables.Item(k + 1).Value = Param.Rows[j][0].ToString();
+                                    format.SubStrings[k].Value = Param.Rows[j][0].ToString();
                                 }
                             }
                         }
                     }
                 }
-                catch (System.Exception ex)
+                catch (System.Exception)
                 {
                     MessageBox.Show("SQL维护不正确");
                 }
             }
             LogManager.DoLog(sb.ToString());
             //保存本次赋值进行打印
-            doc.Printer.SwitchTo(PrinterName);
-            doc.PrintDocument(PrintNum);
+            format.PrintSetup.PrinterName = PrinterName;
+            format.Print();
             LogicHandler.DoCommandLog(iCaller, User.UserCode, "", User.UserLineCode, User.UserSourceCode, "打印", "成功打印", SnCode, "");
-            for (int k = 0; k < doc.Variables.FormVariables.Count; k++)
+            for (int k = 0; k < format.SubStrings.Count; k++)
             {
-                doc.Variables.FormVariables.Item(k + 1).Value = null;
+                format.SubStrings[k].Value = null;
             }
             LogicHandler.doLabelPrintLog(SnCode, LabelType, MakeCode, ProdCode, User.UserSourceCode, User.CurrentStepCode, IfRePrint, User.UserCode);
             return true;

BIN
UAS_MES_MAXMADE/Tool/Seagull.BarTender.Print.dll


+ 4 - 0
UAS_MES_MAXMADE/UAS_MES_MAXMADE.csproj

@@ -138,6 +138,10 @@
       <SpecificVersion>False</SpecificVersion>
       <HintPath>Tool\Oracle.ManagedDataAccess.dll</HintPath>
     </Reference>
+    <Reference Include="Seagull.BarTender.Print, Version=10.1.4.1, Culture=neutral, PublicKeyToken=109ff779a1b4cbc7, processorArchitecture=x86">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>Tool\Seagull.BarTender.Print.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Configuration" />
     <Reference Include="System.Core" />