فهرست منبع

SOP修改提交

callm 2 سال پیش
والد
کامیت
048422e5bb
6فایلهای تغییر یافته به همراه222 افزوده شده و 40 حذف شده
  1. 9 0
      FileWatcher/LogicHandler.cs
  2. 1 1
      FileWatcher/Login.cs
  3. 1 1
      FileWatcher/Program.cs
  4. 96 13
      FileWatcher/SOP.Designer.cs
  5. 114 24
      FileWatcher/SOP.cs
  6. 1 1
      FileWatcher/TcpServer.cs

+ 9 - 0
FileWatcher/LogicHandler.cs

@@ -30,6 +30,15 @@ namespace FileWatcher
                 return false;
         }
 
+        public static void DoCommandLog(string iCaller, string iUserCode, string iMakeCode, string iLineCode, string iSourceCode, string iOperate, string iResult, string iSncode, string iCheckno)
+        {
+            sql.Clear();
+            sql.Append("insert into commandlog(cl_id,cl_caller,cl_man,cl_date,cl_linecode,cl_sourcecode,cl_makecode,cl_operate,");
+            sql.Append("cl_result,cl_sncode,cl_code) values( commandlog_seq.nextval,:cl_caller,:iUserCode,sysdate,:iLineCode ,");
+            sql.Append(":iSourceCode ,:iMakeCode,:iOperate,:iResult,:iSncode,:iCheckno)");
+            dh.ExecuteSql(sql.ToString(), "insert", iCaller, iUserCode, iLineCode, iSourceCode, iMakeCode, iOperate, iResult, iSncode, iCheckno);
+        }
+
         public static void AutoPassLog(string iSN, string iSource, string iMakeCode, string iDate, string iStepCode, string iLineCode, string iFileName, string iIFNG, string iIFAutoSN, int iMiss, string iTestPart, string iNGPart)
         {
             sql.Clear();

+ 1 - 1
FileWatcher/Login.cs

@@ -28,7 +28,7 @@ namespace FileWatcher
                 {
                     BaseUtil.SetCacheData("UserName", UserName.Text);
                     BaseUtil.SetCacheData("Source", Source.Text);
-                    AutoAnalysisXmlByStep xml = new AutoAnalysisXmlByStep(UserName.Text, Source.Text,Master.Text);
+                    SOP xml = new SOP(UserName.Text, Source.Text);
                     Hide();
                     xml.ShowDialog();
                     Close();

+ 1 - 1
FileWatcher/Program.cs

@@ -45,7 +45,7 @@ namespace FileWatcher
                 //Application.EnableVisualStyles();
                 //Application.SetCompatibleTextRenderingDefault(false);
                 if (principal.IsInRole(WindowsBuiltInRole.Administrator))
-                    Application.Run(new SOP());
+                    Application.Run(new SOP("zhangz","123"));
                 else
                 {
                     //创建启动对象

+ 96 - 13
FileWatcher/SOP.Designer.cs

@@ -38,6 +38,12 @@
             this.label2 = new System.Windows.Forms.Label();
             this.OperatResult = new System.Windows.Forms.RichTextBox();
             this.SendSop = new System.Windows.Forms.Button();
+            this.label3 = new System.Windows.Forms.Label();
+            this.label4 = new System.Windows.Forms.Label();
+            this.pr_detail = new System.Windows.Forms.Label();
+            this.pr_spec = new System.Windows.Forms.Label();
+            this.JPG = new System.Windows.Forms.RadioButton();
+            this.PDF = new System.Windows.Forms.RadioButton();
             this.SuspendLayout();
             // 
             // richTextBox1
@@ -56,7 +62,7 @@
             // 
             this.label1.AutoSize = true;
             this.label1.Font = new System.Drawing.Font("微软雅黑", 12F);
-            this.label1.Location = new System.Drawing.Point(41, 255);
+            this.label1.Location = new System.Drawing.Point(19, 430);
             this.label1.Name = "label1";
             this.label1.Size = new System.Drawing.Size(146, 41);
             this.label1.TabIndex = 6;
@@ -64,14 +70,14 @@
             // 
             // FilePath
             // 
-            this.FilePath.Location = new System.Drawing.Point(240, 260);
+            this.FilePath.Location = new System.Drawing.Point(218, 435);
             this.FilePath.Name = "FilePath";
-            this.FilePath.Size = new System.Drawing.Size(300, 35);
+            this.FilePath.Size = new System.Drawing.Size(582, 35);
             this.FilePath.TabIndex = 7;
             // 
             // ChooseFile
             // 
-            this.ChooseFile.Location = new System.Drawing.Point(240, 359);
+            this.ChooseFile.Location = new System.Drawing.Point(218, 593);
             this.ChooseFile.Name = "ChooseFile";
             this.ChooseFile.Size = new System.Drawing.Size(160, 42);
             this.ChooseFile.TabIndex = 8;
@@ -81,7 +87,7 @@
             // 
             // UploadSOP
             // 
-            this.UploadSOP.Location = new System.Drawing.Point(446, 359);
+            this.UploadSOP.Location = new System.Drawing.Point(424, 593);
             this.UploadSOP.Name = "UploadSOP";
             this.UploadSOP.Size = new System.Drawing.Size(160, 42);
             this.UploadSOP.TabIndex = 9;
@@ -91,17 +97,19 @@
             // 
             // pr_code
             // 
-            this.pr_code.Location = new System.Drawing.Point(240, 151);
+            this.pr_code.Location = new System.Drawing.Point(218, 152);
             this.pr_code.Name = "pr_code";
-            this.pr_code.Size = new System.Drawing.Size(300, 35);
+            this.pr_code.Size = new System.Drawing.Size(582, 35);
             this.pr_code.TabIndex = 11;
             this.pr_code.Text = "TEST";
+            this.pr_code.KeyDown += new System.Windows.Forms.KeyEventHandler(this.pr_code_KeyDown);
+            this.pr_code.Leave += new System.EventHandler(this.pr_code_Leave);
             // 
             // label2
             // 
             this.label2.AutoSize = true;
             this.label2.Font = new System.Drawing.Font("微软雅黑", 12F);
-            this.label2.Location = new System.Drawing.Point(41, 146);
+            this.label2.Location = new System.Drawing.Point(19, 147);
             this.label2.Name = "label2";
             this.label2.Size = new System.Drawing.Size(146, 41);
             this.label2.TabIndex = 10;
@@ -109,16 +117,16 @@
             // 
             // OperatResult
             // 
-            this.OperatResult.Location = new System.Drawing.Point(874, 79);
+            this.OperatResult.Location = new System.Drawing.Point(823, 80);
             this.OperatResult.Name = "OperatResult";
-            this.OperatResult.Size = new System.Drawing.Size(628, 758);
+            this.OperatResult.Size = new System.Drawing.Size(591, 758);
             this.OperatResult.TabIndex = 12;
             this.OperatResult.Text = "";
             this.OperatResult.TextChanged += new System.EventHandler(this.OperatResult_TextChanged);
             // 
             // SendSop
             // 
-            this.SendSop.Location = new System.Drawing.Point(662, 359);
+            this.SendSop.Location = new System.Drawing.Point(640, 593);
             this.SendSop.Name = "SendSop";
             this.SendSop.Size = new System.Drawing.Size(160, 42);
             this.SendSop.TabIndex = 13;
@@ -126,11 +134,78 @@
             this.SendSop.UseVisualStyleBackColor = true;
             this.SendSop.Click += new System.EventHandler(this.SendSop_Click);
             // 
+            // label3
+            // 
+            this.label3.AutoSize = true;
+            this.label3.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.label3.Location = new System.Drawing.Point(19, 240);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(146, 41);
+            this.label3.TabIndex = 14;
+            this.label3.Text = "产品名称";
+            // 
+            // label4
+            // 
+            this.label4.AutoSize = true;
+            this.label4.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.label4.Location = new System.Drawing.Point(19, 333);
+            this.label4.Name = "label4";
+            this.label4.Size = new System.Drawing.Size(146, 41);
+            this.label4.TabIndex = 15;
+            this.label4.Text = "产品规格";
+            // 
+            // pr_detail
+            // 
+            this.pr_detail.AutoSize = true;
+            this.pr_detail.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.pr_detail.Location = new System.Drawing.Point(211, 240);
+            this.pr_detail.Name = "pr_detail";
+            this.pr_detail.Size = new System.Drawing.Size(0, 41);
+            this.pr_detail.TabIndex = 16;
+            // 
+            // pr_spec
+            // 
+            this.pr_spec.AutoSize = true;
+            this.pr_spec.Font = new System.Drawing.Font("微软雅黑", 12F);
+            this.pr_spec.Location = new System.Drawing.Point(211, 333);
+            this.pr_spec.Name = "pr_spec";
+            this.pr_spec.Size = new System.Drawing.Size(0, 41);
+            this.pr_spec.TabIndex = 17;
+            // 
+            // JPG
+            // 
+            this.JPG.AutoSize = true;
+            this.JPG.Checked = true;
+            this.JPG.Location = new System.Drawing.Point(251, 516);
+            this.JPG.Name = "JPG";
+            this.JPG.Size = new System.Drawing.Size(89, 28);
+            this.JPG.TabIndex = 18;
+            this.JPG.TabStop = true;
+            this.JPG.Text = "图片";
+            this.JPG.UseVisualStyleBackColor = true;
+            // 
+            // PDF
+            // 
+            this.PDF.AutoSize = true;
+            this.PDF.Location = new System.Drawing.Point(382, 516);
+            this.PDF.Name = "PDF";
+            this.PDF.Size = new System.Drawing.Size(77, 28);
+            this.PDF.TabIndex = 18;
+            this.PDF.TabStop = true;
+            this.PDF.Text = "PDF";
+            this.PDF.UseVisualStyleBackColor = true;
+            // 
             // SOP
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(1585, 934);
+            this.ClientSize = new System.Drawing.Size(1442, 934);
+            this.Controls.Add(this.PDF);
+            this.Controls.Add(this.JPG);
+            this.Controls.Add(this.pr_spec);
+            this.Controls.Add(this.pr_detail);
+            this.Controls.Add(this.label4);
+            this.Controls.Add(this.label3);
             this.Controls.Add(this.SendSop);
             this.Controls.Add(this.OperatResult);
             this.Controls.Add(this.pr_code);
@@ -140,8 +215,10 @@
             this.Controls.Add(this.FilePath);
             this.Controls.Add(this.label1);
             this.Controls.Add(this.richTextBox1);
+            this.MaximizeBox = false;
             this.Name = "SOP";
-            this.Text = "Form3";
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+            this.Text = "SOP管理";
             this.Load += new System.EventHandler(this.Form3_Load);
             this.ResumeLayout(false);
             this.PerformLayout();
@@ -159,5 +236,11 @@
         private System.Windows.Forms.Label label2;
         private System.Windows.Forms.RichTextBox OperatResult;
         private System.Windows.Forms.Button SendSop;
+        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.Label label4;
+        private System.Windows.Forms.Label pr_detail;
+        private System.Windows.Forms.Label pr_spec;
+        private System.Windows.Forms.RadioButton JPG;
+        private System.Windows.Forms.RadioButton PDF;
     }
 }

+ 114 - 24
FileWatcher/SOP.cs

@@ -11,6 +11,7 @@ using System.Text.RegularExpressions;
 using System.Net.Sockets;
 using System.Data;
 using System.Web.Script.Serialization;
+using System.Drawing.Imaging;
 
 namespace FileWatcher
 {
@@ -18,37 +19,60 @@ namespace FileWatcher
     {
         DataHelper dh = new DataHelper();
 
-        public SOP()
+        string usercode;
+        string sourcecode;
+
+        public SOP(string iUserCode, string iSource)
         {
+            usercode = iUserCode;
+            sourcecode = iSource;
             InitializeComponent();
         }
 
         private void Form3_Load(object sender, EventArgs e)
         {
             CheckForIllegalCrossThreadCalls = false;
-            //Dictionary<string, object> dic = new Dictionary<string, object>();
-            //dic.Add("em_name", "管理员");
-            //dic.Add("em_code", "ADMIN");
-            //dic.Add("caller", "ProductSOP");
-            //UploadFilesToRemoteUrl("http://10.1.162.15:8080/mes/MEScommon/uploadFiles.action?_noc=1", @"C:\MES_NEW\mes-client\FileWatcher\bin\Debug\包装产品.jpg", dic);
+            IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
+            string IPAddress = "";
+            for (int i = 0; i < IpEntry.AddressList.Length; i++)
+            {
+                if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork)
+                {
+                    IPAddress = IpEntry.AddressList[i].ToString();
+                }
+            }
         }
 
         void uploadfile()
         {
             Workbook workbook = new Workbook();
-            workbook.LoadFromFile(FilePath.Text, ExcelVersion.Version97to2003);
+            workbook.LoadFromFile(FilePath.Text);
             workbook.ConverterSetting.JPEGQuality = 100;
             workbook.ConverterSetting.XDpi = 600;
             workbook.ConverterSetting.YDpi = 600;
+            List<Worksheet> list = new List<Worksheet>();
             List<string> filename = new List<string>();
-            OperatResult.AppendText("一共Sheet: " + workbook.Worksheets[0].Rows.Length + "\n");
+            OperatResult.AppendText("一共Sheet: " + workbook.Worksheets.Count + "\n");
             try
             {
                 for (int i = 0; i < workbook.Worksheets.Count; i++)
                 {
-                    workbook.Worksheets[i].SaveToImage(workbook.Worksheets[i].Name + ".jpg");
-                    filename.Add(workbook.Worksheets[i].Name + ".jpg");
-                    OperatResult.AppendText("解析图片【" + workbook.Worksheets[i].Name + ".jpg】" + "\n");
+                    Workbook bw = new Workbook();
+                    Worksheet she = bw.CreateEmptySheet();
+                    she.Name = workbook.Worksheets[i].Name;
+                    she.CopyFrom(workbook.Worksheets[i]);
+                    if (JPG.Checked)
+                    {
+                        var myThread = new Thread(() => SaveFileToJPG(she));
+                        myThread.Start();
+                        filename.Add(she.Name + ".jpg");
+                    }
+                    else
+                    {
+                        var myThread = new Thread(() => SaveFileToPDF(she));
+                        myThread.Start();
+                        filename.Add(she.Name + ".pdf");
+                    }
                 }
             }
             catch (Exception ex)
@@ -62,12 +86,39 @@ namespace FileWatcher
             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://10.1.162.15:8080/mes/MEScommon/uploadFiles.action?_noc=1", @"C:\MES_NEW\mes-client\FileWatcher\bin\Debug\" + filename.ToArray()[i], dic);
+                OperatResult.AppendText("上传文件【" + filename.ToArray()[i] + "】\n");
+                string fp_id = UploadFilesToRemoteUrl("http://10.1.81.208:11773/mes/MEScommon/uploadFiles.action?_noc=1", Application.StartupPath + @"\" + pr_code.Text + @"\" + filename.ToArray()[i], dic);
                 dh.ExecuteSql("update ProductSOP set ps_attachsop=ps_attachsop||" + fp_id + "||';' where ps_prodcode='" + pr_code.Text + "'", "update");
             }
         }
 
+        private void SaveFileToPDF(Worksheet sheet)
+        {
+            if (!Directory.Exists(Application.StartupPath + @"\" + pr_code.Text))
+            {
+                Directory.CreateDirectory(Application.StartupPath + @"\" + pr_code.Text);
+            }
+            sheet.SaveToPdf(Application.StartupPath + @"\" + pr_code.Text + @"\" + sheet.Name + ".pdf");
+            OperatResult.AppendText("解析PDF【" + sheet.Name + ".pdf】" + "\n");
+        }
+
+        private void SaveFileToJPG(Worksheet sheet)
+        {
+            try
+            {
+                if (!Directory.Exists(Application.StartupPath + @"\" + pr_code.Text))
+                {
+                    Directory.CreateDirectory(Application.StartupPath + @"\" + pr_code.Text);
+                }
+                sheet.SaveToImage(Application.StartupPath + @"\" + pr_code.Text + @"\" + sheet.Name + ".jpg");
+                OperatResult.AppendText("解析图片【" + sheet.Name + ".jpg】" + "\n");
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.Message);
+            }
+        }
+
         /// <summary>
         /// 请求上传图片到阿里云
         /// </summary>
@@ -75,7 +126,7 @@ namespace FileWatcher
         /// <param name="filepath">本地文件路径</param>
         /// <param name="dic">上传的数据信息</param>
         /// <returns></returns>
-        public static string UploadFilesToRemoteUrl(string url1, string filepath, Dictionary<string, object> dic)
+        public string UploadFilesToRemoteUrl(string url1, string filepath, Dictionary<string, object> dic)
         {
             try
             {
@@ -158,6 +209,7 @@ namespace FileWatcher
             }
             catch (Exception e)
             {
+                LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "上传SOP", "上传失败", pr_code.Text, "");
                 Console.WriteLine(e.Message + e.StackTrace);
             }
             return "";
@@ -175,16 +227,24 @@ namespace FileWatcher
 
         private void UploadSOP_Click(object sender, EventArgs e)
         {
-            //Thread thread = new Thread(uploadfile);
-            //SetLoadingWindow stw = new SetLoadingWindow(thread, "上传文件");
-            //stw.StartPosition = FormStartPosition.CenterScreen;
-            //stw.ShowDialog();
-            uploadfile();
+
+            Thread thread = new Thread(uploadfile);
+            SetLoadingWindow stw = new SetLoadingWindow(thread, "上传文件");
+            stw.StartPosition = FormStartPosition.CenterScreen;
+            stw.ShowDialog();
+            if (JPG.Checked)
+            {
+                LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "上传SOP【图片格式】", "上传成功", pr_code.Text, "");
+            }
+            else
+            {
+                LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "上传SOP【PDF格式】", "上传成功", pr_code.Text, "");
+            }
         }
 
         private void OperatResult_TextChanged(object sender, EventArgs e)
         {
-            OperatResult.SelectionStart = Text.Length;
+            //OperatResult.SelectionStart = Text.Length;
             OperatResult.ScrollToCaret();
         }
 
@@ -194,11 +254,11 @@ namespace FileWatcher
         {
             try
             {
-                tcpserver.Start();
-                Thread.Sleep(5000);
                 DataTable dt = (DataTable)dh.ExecuteSql("select * from productsop where ps_prodcode='" + pr_code.Text + "'", "select");
                 if (dt.Rows.Count > 0)
                 {
+                    tcpserver.Start();
+                    Thread.Sleep(5000);
                     List<Dictionary<string, string>> listr = new List<Dictionary<string, string>>();
                     string PS_ATTACHSOP = dt.Rows[0]["PS_ATTACHSOP"].ToString();
                     PS_ATTACHSOP = PS_ATTACHSOP.Substring(0, PS_ATTACHSOP.Length - 1).Replace(";", ",");
@@ -214,16 +274,17 @@ namespace FileWatcher
                         path = dt.Rows[i]["fp_path"].ToString();
                         path = encryptBASE64(path.Replace("/app/uas/webapps/postattach", pathroot)).Replace("\\s*|\r|\n|\t", "");
                         dic1.Add("path", path);
-                        dic1.Add("filename", dt.Rows[i]["fp_name"].ToString());
+                        dic1.Add("filename", dt.Rows[i]["fp_name"].ToString().Replace(" ", "").Replace("(", "").Replace(")", ""));
                         dic1.Add("ps_prodcode", pr_code.Text);
                         listr.Add(dic1);
                     }
-                    map1.Add("ps_code","");
+                    map1.Add("ps_code", "");
                     map1.Add("url", listr);
                     map.Add("success", true);
                     map.Add("data", map1);
                     tcpserver.Send(jss.Serialize(map));
                     tcpserver.Stop();
+                    LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "广播SOP", "广播成功", pr_code.Text, "");
                 }
                 else
                 {
@@ -232,6 +293,7 @@ namespace FileWatcher
             }
             catch (Exception ex)
             {
+                LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "广播SOP", "广播失败", pr_code.Text, "");
                 Console.WriteLine(ex.Message + ex.StackTrace);
             }
         }
@@ -256,5 +318,33 @@ namespace FileWatcher
             }
             return encode;
         }
+
+        private void pr_code_KeyDown(object sender, KeyEventArgs e)
+        {
+            if (e.KeyCode == Keys.Enter)
+            {
+                LoadPrCode();
+            }
+        }
+
+
+        private void LoadPrCode()
+        {
+            DataTable dt = (DataTable)dh.ExecuteSql("select pr_code,pr_spec,pr_detail from product where pr_code='" + pr_code.Text + "'", "select");
+            if (dt.Rows.Count > 0)
+            {
+                pr_spec.Text = dt.Rows[0]["pr_spec"].ToString();
+                pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
+            }
+            else
+            {
+                MessageBox.Show("产品编号" + pr_code.Text + "不存在");
+            }
+        }
+
+        private void pr_code_Leave(object sender, EventArgs e)
+        {
+            LoadPrCode();
+        }
     }
 }

+ 1 - 1
FileWatcher/TcpServer.cs

@@ -13,7 +13,7 @@ namespace FileWatcher
     public class TcpServer
     {
         //端口号
-        private int SocketServerPort = 8888;
+        private int SocketServerPort = 8800;
         //处理连接请求的线程
         private Thread acceptConnectReqThd;