瀏覽代碼

自定义标签打印修改

Hcsy 8 年之前
父節點
當前提交
d25a42abf9
共有 2 個文件被更改,包括 61 次插入3 次删除
  1. 30 2
      UAS-MES/FunctionCode/Make/Make_CustomLabelPrint.cs
  2. 31 1
      UAS-MES/PublicMethod/BaseUtil.cs

+ 30 - 2
UAS-MES/FunctionCode/Make/Make_CustomLabelPrint.cs

@@ -70,7 +70,7 @@ namespace UAS_MES.Make
             try
             {
                 lbl = new ApplicationClass();
-                BaseUtil.WriteLbl(lbl);
+                BaseUtil.WriteLbl();
             }
             catch (Exception ex)
             {
@@ -145,7 +145,21 @@ namespace UAS_MES.Make
                     {
                         inputValues = new string[paramsInfo.Rows.Count];
                         sb = new StringBuilder();
-                        doc = lbl.Documents.Open(listA.Rows[PrintLabel.SelectedIndex]["la_url"].ToString());
+                        string filelastwritetime = dh.getFieldDataByCondition("label", "la_lastwritetime", "la_id = '" + listA.Rows[PrintLabel.SelectedIndex]["la_id"].ToString() + "'").ToString();
+                        FileInfo PrintFile = new FileInfo(listA.Rows[PrintLabel.SelectedIndex]["la_url"].ToString());
+                        if (PrintFile == null)
+                        {
+                            MessageBox.Show("打印文件不存在");
+                            return ;
+                        }
+                        if (PrintFile.LastWriteTime.ToString() != filelastwritetime)
+                        {
+                            lbl.Quit();
+                            lbl = new ApplicationClass();
+                            BaseUtil.WriteLbl();
+                            dh.UpdateByCondition("label", "la_lastwritetime = to_date('" + PrintFile.LastWriteTime.ToString() + "', 'yyyy-mm-dd hh24:mi:ss') ", "la_id = '" + listA.Rows[PrintLabel.SelectedIndex]["la_id"].ToString() + "'");
+                        }
+                        doc = lbl.Documents.Open(listA.Rows[PrintLabel.SelectedIndex]["la_url"].ToString(), true);
                     }
                     //将值赋到doc对应的变量
                     for (int i = 0; i < doc.Variables.FormVariables.Count; i++)
@@ -249,6 +263,20 @@ namespace UAS_MES.Make
         {
             if (canPrint)
             {
+                string filelastwritetime = dh.getFieldDataByCondition("label", "la_lastwritetime", "la_id = '" + listA.Rows[PrintLabel.SelectedIndex]["la_id"].ToString() + "'").ToString();
+                FileInfo PrintFile = new FileInfo(listA.Rows[PrintLabel.SelectedIndex]["la_url"].ToString());
+                if (PrintFile == null)
+                {
+                    MessageBox.Show("打印文件不存在");
+                    return;
+                }
+                if (PrintFile.LastWriteTime.ToString() != filelastwritetime)
+                {
+                    lbl.Quit();
+                    lbl = new ApplicationClass();
+                    BaseUtil.WriteLbl(lbl);
+                    dh.UpdateByCondition("label", "la_lastwritetime = to_date('" + PrintFile.LastWriteTime.ToString() + "', 'yyyy-mm-dd hh24:mi:ss') ", "la_id = '" + listA.Rows[PrintLabel.SelectedIndex]["la_id"].ToString() + "'");
+                }
                 doc = lbl.Documents.Open(listA.Rows[PrintLabel.SelectedIndex]["la_url"].ToString());
                 sb = new StringBuilder();
                 //将值赋到doc对应的变量

+ 31 - 1
UAS-MES/PublicMethod/BaseUtil.cs

@@ -1008,7 +1008,10 @@ namespace UAS_MES.PublicMethod
             {
                 try
                 {
-                    ProInf.Add(processes[i].StartTime.ToString(), processes[i].Id);
+                    if (processes[i].ProcessName == "lppa")
+                    {
+                        ProInf.Add(processes[i].StartTime.ToString(), processes[i].Id);
+                    }
                 }
                 catch {
                 }
@@ -1022,6 +1025,33 @@ namespace UAS_MES.PublicMethod
             fs.Close();
         }
 
+        public static void WriteLbl()
+        {
+            Process[] processes = System.Diagnostics.Process.GetProcessesByName("lppa");
+            Dictionary<string, int> ProInf = new Dictionary<string, int>();
+            int PID = 0;
+            for (int i = 0; i < processes.Length; i++)
+            {
+                try
+                {
+                    if (processes[i].ProcessName == "lppa")
+                    {
+                        ProInf.Add(processes[i].StartTime.ToString(), processes[i].Id);
+                    }
+                }
+                catch
+                {
+                }
+            }
+            var temp = ProInf.Keys.Max();
+            String str = SystemInf.ProcessesID + "|" + ProInf[temp];
+            FileStream fs = new FileStream(SystemInf.CacheFolder + "lblprocess.txt", FileMode.Append, FileAccess.Write);
+            StreamWriter sw = new StreamWriter(fs);
+            sw.WriteLine(str, Encoding.UTF8);
+            sw.Close();
+            fs.Close();
+        }
+
         public static Object GetCacheData(string ParamName)
         {
             try