Browse Source

添加图片水印

callm 1 year ago
parent
commit
80c83d2e8e
1 changed files with 33 additions and 17 deletions
  1. 33 17
      FileWatcher/SOP.cs

+ 33 - 17
FileWatcher/SOP.cs

@@ -5,13 +5,12 @@ using System.Windows.Forms;
 using Spire.Xls;
 using System.Net;
 using System.Collections.Generic;
-using System.Web.SessionState;
 using System.Threading;
-using System.Text.RegularExpressions;
 using System.Net.Sockets;
 using System.Data;
 using System.Web.Script.Serialization;
-using System.Drawing.Imaging;
+using NPOI.HSSF.UserModel;
+using NPOI.SS.UserModel;
 
 namespace FileWatcher
 {
@@ -65,6 +64,7 @@ namespace FileWatcher
             workbook.ConverterSetting.YDpi = 600;
             List<Worksheet> list = new List<Worksheet>();
             List<string> filename = new List<string>();
+            dh.ExecuteSql("update ProductSOP set ps_attachsop='' where ps_prodcode='" + pr_code.Text + "'", "update");
             OperatResult.AppendText("一共Sheet: " + workbook.Worksheets.Count + "\n");
             try
             {
@@ -92,20 +92,6 @@ namespace FileWatcher
             {
                 Console.WriteLine(ex.Message);
             }
-            Dictionary<string, object> dic = new Dictionary<string, object>();
-            dic.Add("em_name", "管理员");
-            dic.Add("em_code", "ADMIN");
-            dic.Add("caller", "ProductSOP");
-            dh.ExecuteSql("update ProductSOP set ps_attachsop='' where ps_prodcode='" + pr_code.Text + "'", "update");
-            for (int i = 0; i < filename.ToArray().Length; i++)
-            {
-                OperatResult.AppendText("上传文件【" + filename.ToArray()[i] + "】\n");
-                string fp_id = UploadFilesToRemoteUrl("http://192.168.101.253:11773/mes/MEScommon/uploadFiles.action?_noc=1", Application.StartupPath + @"\" + pr_code.Text + @"\" + filename.ToArray()[i], dic);
-                if (fp_id != "")
-                {
-                    dh.ExecuteSql("update ProductSOP set ps_attachsop=ps_attachsop||" + fp_id + "||';' where ps_prodcode='" + pr_code.Text + "'", "update");
-                }
-            }
         }
 
         private void SaveFileToPDF(Worksheet sheet)
@@ -116,6 +102,16 @@ namespace FileWatcher
             }
             sheet.SaveToPdf(Application.StartupPath + @"\" + pr_code.Text + @"\" + sheet.Name + ".pdf");
             OperatResult.AppendText("解析PDF【" + sheet.Name + ".pdf】" + "\n");
+            Dictionary<string, object> dic = new Dictionary<string, object>();
+            dic.Add("em_name", "管理员");
+            dic.Add("em_code", "ADMIN");
+            dic.Add("caller", "ProductSOP");
+            OperatResult.AppendText("上传文件【" + sheet.Name + ".pdf" + "】\n");
+            string fp_id = UploadFilesToRemoteUrl("http://192.168.101.253:8099/mes/MEScommon/uploadFiles.action?_noc=1", Application.StartupPath + @"\" + pr_code.Text + @"\" + sheet.Name + ".pdf", dic);
+            if (fp_id != "")
+            {
+                dh.ExecuteSql("update ProductSOP set ps_attachsop=ps_attachsop||" + fp_id + "||';' where ps_prodcode='" + pr_code.Text + "'", "update");
+            }
         }
 
         private void SaveFileToJPG(Worksheet sheet)
@@ -126,8 +122,28 @@ namespace FileWatcher
                 {
                     Directory.CreateDirectory(Application.StartupPath + @"\" + pr_code.Text);
                 }
+                ExcelPicture picture = sheet.Pictures.Add(@"图片\电子受控章.png");
+                picture.Width = 113;
+                picture.Height = 38;
+                picture.LeftColumn = 20;
+                picture.TopRowOffset = 20;
+                ExcelPicture picture1 = sheet.Pictures.Add(@"图片\签名.png");
+                picture1.Width = 100;
+                picture1.Height = 38;
+                picture1.LeftColumn = 15;
+                picture1.TopRowOffset = 600;
                 sheet.SaveToImage(Application.StartupPath + @"\" + pr_code.Text + @"\" + sheet.Name + ".jpg");
                 OperatResult.AppendText("解析图片【" + sheet.Name + ".jpg】" + "\n");
+                Dictionary<string, object> dic = new Dictionary<string, object>();
+                dic.Add("em_name", "管理员");
+                dic.Add("em_code", "ADMIN");
+                dic.Add("caller", "ProductSOP");
+                OperatResult.AppendText("上传文件【" + sheet.Name + ".jpg" + "】\n");
+                string fp_id = UploadFilesToRemoteUrl("http://192.168.101.253:8099/mes/MEScommon/uploadFiles.action?_noc=1", Application.StartupPath + @"\" + pr_code.Text + @"\" + sheet.Name + ".jpg", dic);
+                if (fp_id != "")
+                {
+                    dh.ExecuteSql("update ProductSOP set ps_attachsop=ps_attachsop||" + fp_id + "||';' where ps_prodcode='" + pr_code.Text + "'", "update");
+                }
             }
             catch (Exception ex)
             {