Browse Source

标签上传下载优化

shim 8 years ago
parent
commit
30c9dc8812

+ 4 - 2
UAS-MES/FunctionCode/Make/Make_FuselageLabelPrint.cs

@@ -7,6 +7,7 @@ using UAS_MES.DataOperate;
 using UAS_MES.PublicMethod;
 using UAS_MES.Entity;
 using LabelManager2;
+using System.IO;
 
 namespace UAS_MES.Make
 {
@@ -151,7 +152,7 @@ namespace UAS_MES.Make
         }
         private void pr_code_TextChanged(object sender, EventArgs e)
         {
-            dt = (DataTable)dh.ExecuteSql("select pl_labelname,pl_labelcode from productlabel where pl_prodcode='" + ma_prodcode.Text + "'and PL_LABELTYPE='机身标' order by pl_isdefault desc", "select");
+            dt = (DataTable)dh.ExecuteSql("select pl_labelname,pl_labelcode,to_char(nvl(pl_indate,sysdate),'YYYY-MM-DD HH24:Mi:SS') pl_indate,pl_labelurl from productlabel where pl_prodcode='" + ma_prodcode.Text + "'and PL_LABELTYPE='机身标' order by pl_isdefault desc", "select");
             if (dt.Rows.Count == 0)
             {
                 OperateResult.AppendText(">>该序列号对应的产品未维护机身标标签模板\n", Color.Red);
@@ -162,7 +163,8 @@ namespace UAS_MES.Make
             ftpOperater ftp = new ftpOperater();
             for (int i = 0; i < dt.Rows.Count; i++)
             {
-                ftp.Download(dt.Rows[i]["pl_labelname"].ToString());
+                //ftp.Download(dt.Rows[i]["pl_labelname"].ToString());
+                BaseUtil.GetPrintLabel(dt.Rows[i]["pl_labelname"].ToString(), dt.Rows[i]["pl_labelurl"].ToString(), dt.Rows[i]["pl_indate"].ToString());
             }
         }
 

+ 3 - 3
UAS-MES/FunctionCode/SystemSetting/SystemSetting_LabelMaintain.cs

@@ -342,14 +342,14 @@ namespace UAS_MES.SystemSetting
                     {
                         sql.Clear();
                         sql.Append("update productlabel set pl_labelcode=:pl_labelcode,pl_labeltype=:pl_labeltype,pl_labelname=:pl_labelname,");
-                        sql.Append("pl_prodcode=:pl_prodcode where pl_id='" + pl_id2 + "'");
+                        sql.Append("pl_prodcode=:pl_prodcode,pl_indate=sysdate where pl_id='" + pl_id2 + "'");
                         dh.ExecuteSql(sql.GetString(), "update", la_code.Text, la_type.Text, la_name.Text, pr_code.Text);
                     }
                     else
                     {
                         sql.Clear();
-                        sql.Append("insert into productlabel (pl_id,pl_labelcode,pl_labeltype,pl_labelurl,pl_labelsoft,pl_labelname,pl_prodcode) values( productlabel_seq.nextval, ");
-                        sql.Append("'" + la_code.Text + "','" + la_type.Text + "','" + ftpOperater.FTPAddress + la_name.Text + "','" + SoftWare + "','" + la_name.Text + "','" + pr_code.Text + "')");
+                        sql.Append("insert into productlabel (pl_id,pl_labelcode,pl_labeltype,pl_labelurl,pl_labelsoft,pl_labelname,pl_prodcode,pl_indate) values( productlabel_seq.nextval, ");
+                        sql.Append("'" + la_code.Text + "','" + la_type.Text + "','" + ftpOperater.FTPAddress + la_name.Text + "','" + SoftWare + "','" + la_name.Text + "','" + pr_code.Text + "',sysdate)");
                         dh.ExecuteSql(sql.GetString(), "insert");
                     }
                     pl_id2 = "";

+ 36 - 0
UAS-MES/PublicMethod/BaseUtil.cs

@@ -3,6 +3,7 @@ using System.Collections;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
+using System.IO;
 using System.Reflection;
 using System.Text;
 using System.Text.RegularExpressions;
@@ -453,6 +454,27 @@ namespace UAS_MES.PublicMethod
                 return URL;
         }
 
+        /// <summary>
+        /// 获取标签的路径
+        /// </summary>
+        /// <param name="URL"></param>
+        /// <param name="LabelName"></param>
+        /// <param name="time"></param>
+        /// <returns></returns>
+        public static string GetLabelUrl(string URL, string LabelName, DateTime time)
+        {
+            //如果是传入的数据是从FTP取的文件
+            if (URL.Contains("ftp:"))
+            {
+                ftpOperater ftp = new ftpOperater();
+                return ftp.Download(LabelName, time);
+            }
+            else
+            {
+                return URL;
+            }
+        }
+
         /// <summary>
         /// 往DataTable中添加数据
         /// </summary>
@@ -869,5 +891,19 @@ namespace UAS_MES.PublicMethod
             }
             return ndt;
         }
+        /// <summary>
+        /// 获取打印标签
+        /// </summary>
+        /// <param name="labelName"></param>
+        /// <param name="labelUrl"></param>
+        /// <param name="indate"></param>
+        public static void GetPrintLabel(string labelName,string labelUrl,string indate) {
+            string LabelUrl = labelUrl;
+            string LabelName = labelName;
+            System.DateTime time = Convert.ToDateTime(indate);
+            FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
+            if (time.ToString() != file.LastWriteTime.ToString())
+                BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
+        }
     }
 }

+ 43 - 0
UAS-MES/PublicMethod/ftpOperater.cs

@@ -177,6 +177,49 @@ namespace UAS_MES.PublicMethod
             return fileSize;
         }
 
+        /// <summary>
+        /// 实现ftp下载操作
+        /// </summary>
+        /// <param name="fileName">远程文件名</param>
+        public string Download(string fileName,DateTime time)
+        {
+            FtpWebRequest reqFTP;
+            try
+            {
+                FileStream outputStream = new FileStream(DownLoadTo + @"\" + fileName, FileMode.Create);
+                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(ftpServerIP + "/" + fileName));
+                reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
+                reqFTP.UseBinary = true;
+                reqFTP.Credentials = new NetworkCredential(ftpUser, ftpPwd);
+                reqFTP.UsePassive = true;
+                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+                Stream ftpStream = response.GetResponseStream();
+                long cl = response.ContentLength;
+                int bufferSize = 2048;
+                int readCount;
+                byte[] buffer = new byte[bufferSize];
+
+                readCount = ftpStream.Read(buffer, 0, bufferSize);
+                while (readCount > 0)
+                {
+                    outputStream.Write(buffer, 0, readCount);
+                    readCount = ftpStream.Read(buffer, 0, bufferSize);
+                }
+                ftpStream.Close();
+                outputStream.Close();
+                response.Close();
+                //设置最后修改文件时间为服务器时间
+                FileInfo f = new FileInfo(DownLoadTo + @"\" + fileName);
+                f.LastWriteTime = time;
+                return DownLoadTo + @"\" + fileName;
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message);
+                return "";
+            }
+        }
+
         /// <summary>
         /// 实现ftp下载操作
         /// </summary>