Browse Source

SOP功能优化

callm 7 months ago
parent
commit
a763237261
6 changed files with 203 additions and 124 deletions
  1. 3 3
      FileWatcher/DataHelper.cs
  2. 147 87
      FileWatcher/Form4.Designer.cs
  3. 0 12
      FileWatcher/Form4.resx
  4. 1 1
      FileWatcher/Program.cs
  5. 14 12
      FileWatcher/SOP.cs
  6. 38 9
      FileWatcher/TcpServer.cs

+ 3 - 3
FileWatcher/DataHelper.cs

@@ -9,9 +9,9 @@ namespace FileWatcher
    public class DataHelper
     {
         //系统默认的的连接字符串
-        private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=HUAG;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=81.71.42.91)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        private string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=113.98.196.181)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
         //用户选择的数据库的连接字符串
-        public static string DBConnectionString= "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=HUAG;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=81.71.42.91)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+        public static string DBConnectionString= "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=MES;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=113.98.196.181)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
         public static OracleConnection connection = null;
         OracleCommand command = null;
         int ReconnectTime = 0;
@@ -508,7 +508,7 @@ namespace FileWatcher
         public object ExecuteSql(string SQL, string Type, params object[] names)
         {
             object result = null;
-            //Console.WriteLine(SQL);
+            Console.WriteLine(SQL);
             command = new OracleCommand(SQL, connection);
             Reconnect(command);
             //用来拼接参数的

+ 147 - 87
FileWatcher/Form4.Designer.cs

@@ -28,136 +28,196 @@
         /// </summary>
         private void InitializeComponent()
         {
-            this.label2 = new System.Windows.Forms.Label();
-            this.label1 = new System.Windows.Forms.Label();
             this.StartWatch = new System.Windows.Forms.Button();
-            this.dataGridView1 = new System.Windows.Forms.DataGridView();
-            this.Column1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
-            this.料号 = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.物料名称 = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.物料规格 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.textBox1 = new System.Windows.Forms.TextBox();
             this.label3 = new System.Windows.Forms.Label();
-            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
+            this.label1 = new System.Windows.Forms.Label();
+            this.textBox2 = new System.Windows.Forms.TextBox();
+            this.label2 = new System.Windows.Forms.Label();
+            this.label4 = new System.Windows.Forms.Label();
+            this.textBox3 = new System.Windows.Forms.TextBox();
+            this.label5 = new System.Windows.Forms.Label();
+            this.textBox4 = new System.Windows.Forms.TextBox();
+            this.label6 = new System.Windows.Forms.Label();
+            this.textBox5 = new System.Windows.Forms.TextBox();
+            this.button1 = new System.Windows.Forms.Button();
+            this.pictureBox1 = new System.Windows.Forms.PictureBox();
+            this.label7 = new System.Windows.Forms.Label();
+            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
             this.SuspendLayout();
             // 
-            // label2
-            // 
-            this.label2.AutoSize = true;
-            this.label2.Location = new System.Drawing.Point(250, 59);
-            this.label2.Name = "label2";
-            this.label2.Size = new System.Drawing.Size(0, 24);
-            this.label2.TabIndex = 2;
-            // 
-            // label1
-            // 
-            this.label1.AutoSize = true;
-            this.label1.Location = new System.Drawing.Point(125, 109);
-            this.label1.Name = "label1";
-            this.label1.Size = new System.Drawing.Size(106, 24);
-            this.label1.TabIndex = 1;
-            this.label1.Text = "单据编号";
-            // 
             // StartWatch
             // 
             this.StartWatch.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.StartWatch.Location = new System.Drawing.Point(290, 686);
+            this.StartWatch.Location = new System.Drawing.Point(344, 206);
             this.StartWatch.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
             this.StartWatch.Name = "StartWatch";
-            this.StartWatch.Size = new System.Drawing.Size(128, 56);
+            this.StartWatch.Size = new System.Drawing.Size(128, 52);
             this.StartWatch.TabIndex = 17;
-            this.StartWatch.Text = "保存";
+            this.StartWatch.Text = "播放";
             this.StartWatch.UseVisualStyleBackColor = true;
             // 
-            // dataGridView1
-            // 
-            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
-            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
-            this.Column1,
-            this.料号,
-            this.物料名称,
-            this.物料规格});
-            this.dataGridView1.Location = new System.Drawing.Point(129, 176);
-            this.dataGridView1.Name = "dataGridView1";
-            this.dataGridView1.RowHeadersWidth = 82;
-            this.dataGridView1.RowTemplate.Height = 37;
-            this.dataGridView1.Size = new System.Drawing.Size(489, 150);
-            this.dataGridView1.TabIndex = 21;
-            // 
-            // Column1
-            // 
-            this.Column1.HeaderText = "勾选";
-            this.Column1.MinimumWidth = 10;
-            this.Column1.Name = "Column1";
-            this.Column1.Width = 200;
-            // 
-            // 料号
-            // 
-            this.料号.HeaderText = "料号";
-            this.料号.MinimumWidth = 10;
-            this.料号.Name = "料号";
-            this.料号.Width = 200;
-            // 
-            // 物料名称
-            // 
-            this.物料名称.HeaderText = "名称";
-            this.物料名称.MinimumWidth = 10;
-            this.物料名称.Name = "物料名称";
-            this.物料名称.Width = 200;
-            // 
-            // 物料规格
-            // 
-            this.物料规格.HeaderText = "规格";
-            this.物料规格.MinimumWidth = 10;
-            this.物料规格.Name = "物料规格";
-            this.物料规格.Width = 200;
-            // 
             // textBox1
             // 
-            this.textBox1.Location = new System.Drawing.Point(254, 498);
+            this.textBox1.Location = new System.Drawing.Point(1006, 340);
             this.textBox1.Name = "textBox1";
-            this.textBox1.Size = new System.Drawing.Size(334, 35);
+            this.textBox1.Size = new System.Drawing.Size(125, 35);
             this.textBox1.TabIndex = 22;
             // 
             // label3
             // 
             this.label3.AutoSize = true;
-            this.label3.Location = new System.Drawing.Point(130, 501);
+            this.label3.Location = new System.Drawing.Point(882, 343);
             this.label3.Name = "label3";
-            this.label3.Size = new System.Drawing.Size(82, 24);
+            this.label3.Size = new System.Drawing.Size(106, 24);
             this.label3.TabIndex = 23;
-            this.label3.Text = "机台号";
+            this.label3.Text = "自动监听";
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Location = new System.Drawing.Point(882, 209);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(58, 24);
+            this.label1.TabIndex = 25;
+            this.label1.Text = "岗位";
+            // 
+            // textBox2
+            // 
+            this.textBox2.Location = new System.Drawing.Point(1006, 206);
+            this.textBox2.Name = "textBox2";
+            this.textBox2.Size = new System.Drawing.Size(125, 35);
+            this.textBox2.TabIndex = 24;
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Location = new System.Drawing.Point(882, 400);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(82, 24);
+            this.label2.TabIndex = 26;
+            this.label2.Text = "中控IP";
+            // 
+            // label4
+            // 
+            this.label4.AutoSize = true;
+            this.label4.Location = new System.Drawing.Point(882, 143);
+            this.label4.Name = "label4";
+            this.label4.Size = new System.Drawing.Size(58, 24);
+            this.label4.TabIndex = 28;
+            this.label4.Text = "线别";
+            // 
+            // textBox3
+            // 
+            this.textBox3.Location = new System.Drawing.Point(1006, 140);
+            this.textBox3.Name = "textBox3";
+            this.textBox3.Size = new System.Drawing.Size(125, 35);
+            this.textBox3.TabIndex = 27;
+            // 
+            // label5
+            // 
+            this.label5.AutoSize = true;
+            this.label5.Location = new System.Drawing.Point(882, 274);
+            this.label5.Name = "label5";
+            this.label5.Size = new System.Drawing.Size(58, 24);
+            this.label5.TabIndex = 30;
+            this.label5.Text = "人员";
+            // 
+            // textBox4
+            // 
+            this.textBox4.Location = new System.Drawing.Point(1006, 271);
+            this.textBox4.Name = "textBox4";
+            this.textBox4.Size = new System.Drawing.Size(125, 35);
+            this.textBox4.TabIndex = 29;
+            // 
+            // label6
+            // 
+            this.label6.AutoSize = true;
+            this.label6.Location = new System.Drawing.Point(61, 154);
+            this.label6.Name = "label6";
+            this.label6.Size = new System.Drawing.Size(94, 24);
+            this.label6.TabIndex = 32;
+            this.label6.Text = "选择SOP";
+            // 
+            // textBox5
+            // 
+            this.textBox5.Location = new System.Drawing.Point(185, 151);
+            this.textBox5.Name = "textBox5";
+            this.textBox5.Size = new System.Drawing.Size(378, 35);
+            this.textBox5.TabIndex = 31;
+            // 
+            // button1
+            // 
+            this.button1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.button1.Location = new System.Drawing.Point(185, 202);
+            this.button1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.button1.Name = "button1";
+            this.button1.Size = new System.Drawing.Size(128, 52);
+            this.button1.TabIndex = 33;
+            this.button1.Text = "搜索";
+            this.button1.UseVisualStyleBackColor = true;
+            // 
+            // pictureBox1
+            // 
+            this.pictureBox1.Location = new System.Drawing.Point(185, 317);
+            this.pictureBox1.Name = "pictureBox1";
+            this.pictureBox1.Size = new System.Drawing.Size(600, 379);
+            this.pictureBox1.TabIndex = 34;
+            this.pictureBox1.TabStop = false;
+            // 
+            // label7
+            // 
+            this.label7.AutoSize = true;
+            this.label7.Location = new System.Drawing.Point(181, 279);
+            this.label7.Name = "label7";
+            this.label7.Size = new System.Drawing.Size(106, 24);
+            this.label7.TabIndex = 35;
+            this.label7.Text = "图片表格";
             // 
             // Form4
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(1419, 820);
+            this.Controls.Add(this.label7);
+            this.Controls.Add(this.pictureBox1);
+            this.Controls.Add(this.button1);
+            this.Controls.Add(this.label6);
+            this.Controls.Add(this.textBox5);
+            this.Controls.Add(this.label5);
+            this.Controls.Add(this.textBox4);
+            this.Controls.Add(this.label4);
+            this.Controls.Add(this.textBox3);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.label1);
+            this.Controls.Add(this.textBox2);
             this.Controls.Add(this.label3);
             this.Controls.Add(this.textBox1);
-            this.Controls.Add(this.dataGridView1);
             this.Controls.Add(this.StartWatch);
-            this.Controls.Add(this.label2);
-            this.Controls.Add(this.label1);
             this.Name = "Form4";
             this.Text = "Form4";
             this.Load += new System.EventHandler(this.Form4_Load);
-            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
 
         }
 
         #endregion
-        private System.Windows.Forms.Label label2;
-        private System.Windows.Forms.Label label1;
         private System.Windows.Forms.Button StartWatch;
-        private System.Windows.Forms.DataGridView dataGridView1;
-        private System.Windows.Forms.DataGridViewCheckBoxColumn Column1;
-        private System.Windows.Forms.DataGridViewTextBoxColumn 料号;
-        private System.Windows.Forms.DataGridViewTextBoxColumn 物料名称;
-        private System.Windows.Forms.DataGridViewTextBoxColumn 物料规格;
         private System.Windows.Forms.TextBox textBox1;
         private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.TextBox textBox2;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.Label label4;
+        private System.Windows.Forms.TextBox textBox3;
+        private System.Windows.Forms.Label label5;
+        private System.Windows.Forms.TextBox textBox4;
+        private System.Windows.Forms.Label label6;
+        private System.Windows.Forms.TextBox textBox5;
+        private System.Windows.Forms.Button button1;
+        private System.Windows.Forms.PictureBox pictureBox1;
+        private System.Windows.Forms.Label label7;
     }
 }

+ 0 - 12
FileWatcher/Form4.resx

@@ -117,16 +117,4 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
-  <metadata name="Column1.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
-  <metadata name="料号.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
-  <metadata name="物料名称.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
-  <metadata name="物料规格.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
 </root>

+ 1 - 1
FileWatcher/Program.cs

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

+ 14 - 12
FileWatcher/SOP.cs

@@ -33,7 +33,7 @@ namespace FileWatcher
         private void Form3_Load(object sender, EventArgs e)
         {
             CheckForIllegalCrossThreadCalls = false;
-            tcpserver.Start();
+         
         }
 
         void uploadfile()
@@ -83,7 +83,7 @@ namespace FileWatcher
             try
             {
                 DataHelper dh = new DataHelper();
-                OperatResult.AppendText("解析图片【" + sheet.Name + ".jpg】添加水印" + "\n");
+                //OperatResult.AppendText("解析图片【" + sheet.Name + ".jpg】添加水印" + "\n");
                 if (!Directory.Exists(Application.StartupPath + @"\" + pr_code.Text))
                 {
                     Directory.CreateDirectory(Application.StartupPath + @"\" + pr_code.Text);
@@ -101,12 +101,12 @@ namespace FileWatcher
                 //}
                 //Console.WriteLine("width:"+width);
                 //Console.WriteLine("height:"+height);
-                sheet.Pictures.Add(0, 18, @"图片\电子受控章.png");
-                sheet.Pictures.Add(0, 15, @"图片\签名.png");
-                sheet.PageSetup.LeftMargin = 0;
-                sheet.PageSetup.RightMargin = 0;
-                sheet.PageSetup.BottomMargin = 0;
-                sheet.PageSetup.TopMargin = 0;
+                //sheet.Pictures.Add(0, 18, @"图片\电子受控章.png");
+                //sheet.Pictures.Add(0, 15, @"图片\签名.png");
+                //sheet.PageSetup.LeftMargin = 0;
+                //sheet.PageSetup.RightMargin = 0;
+                //sheet.PageSetup.BottomMargin = 0;
+                //sheet.PageSetup.TopMargin = 0;
                 ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
                 imgOptions.ImageFormat = ImageFormat.Png;
                 imgOptions.OnePagePerSheet = true;
@@ -263,12 +263,14 @@ namespace FileWatcher
             OperatResult.ScrollToCaret();
         }
 
-        TcpServer tcpserver = new TcpServer();
+       
 
         private void SendSop_Click(object sender, EventArgs e)
         {
             try
             {
+                TcpServer tcpserver = new TcpServer();
+                tcpserver.Start();
                 IPHostEntry IpEntry = Dns.GetHostEntry(Dns.GetHostName());
                 string IPAddress = "";
                 for (int i = 0; i < IpEntry.AddressList.Length; i++)
@@ -278,10 +280,10 @@ namespace FileWatcher
                         IPAddress = IpEntry.AddressList[i].ToString();
                     }
                 }
-                dh.ExecuteSql("update SOPSOURCE set SS_BRDIP='" + IPAddress + "'", "update");
+                //dh.ExecuteSql("update SOPSOURCE set SS_BRDIP='" + IPAddress + "'", "update");
                 if (SendDGV.Rows.Count > 0)
                 {
-                    Thread.Sleep(8000);
+                    Thread.Sleep(5000);
                     List<Dictionary<string, string>> listr = new List<Dictionary<string, string>>();
                     JavaScriptSerializer jss = new JavaScriptSerializer();
                     Dictionary<string, object> map1 = new Dictionary<string, object>();
@@ -308,7 +310,7 @@ namespace FileWatcher
                     map.Add("data", map1);
                     tcpserver.Send(jss.Serialize(map));
                     //Thread.Sleep(2000);
-                    //tcpserver.Stop();
+                    tcpserver.Stop();
                     LogicHandler.DoCommandLog("SOP", usercode, "", "", sourcecode, "广播SOP", "广播成功", pr_code.Text, "");
                     MessageBox.Show("产品编号" + pr_code.Text + "广播成功");
                 }

+ 38 - 9
FileWatcher/TcpServer.cs

@@ -6,6 +6,7 @@ using System.Net;
 using System.Net.Sockets;
 using System.Text;
 using System.Threading;
+using System.Windows.Forms;
 
 namespace FileWatcher
 {
@@ -23,6 +24,9 @@ namespace FileWatcher
 
         bool Watching;
 
+        RichTextBox OperatResult;
+        DataGridView dgv;
+
         public bool Start()
         {
             try
@@ -42,7 +46,15 @@ namespace FileWatcher
                 acceptConnectReqThd = new Thread(AcceptConnectReqHandler);
                 acceptConnectReqThd.IsBackground = true;
                 acceptConnectReqThd.Start(socketWatch);  //把socket对象当做参数传递给到线程里面的方法
-
+                foreach (Form openForm in Application.OpenForms)
+                {
+                    if (openForm is SOP)
+                    {
+                        form = openForm;
+                    }
+                }
+                OperatResult = (RichTextBox)form.Controls["OperatResult"];
+                dgv = (DataGridView)form.Controls["SendDGV"];
                 return true;
             }
             catch (Exception)
@@ -76,7 +88,7 @@ namespace FileWatcher
                 Console.WriteLine("服务端处理连接事件异常:" + e.ToString());
             }
         }
-
+        Form form = null;
         private void ReciveMsgReqHandler(object _socket)
         {
             Socket clientSocket = (Socket)_socket;
@@ -92,21 +104,31 @@ namespace FileWatcher
                     byte[] buffer = new byte[1024];  //数据缓冲区。
                     //实际接收到的有效字节数
                     //Receive也是个卡线程的方法
-                    Console.WriteLine("等待接受客户端的数据:");
+                    //Console.WriteLine("等待接受客户端的数据:");
+                    //OperatResult.AppendText("等待接受客户端的数据,"+ clientSocket+ "\n");
+                    Console.WriteLine("等待接受客户端的数:");
                     int dataLength = clientSocket.Receive(buffer);
                     Console.WriteLine("接受到客户端的数据,字节数:" + dataLength);
+                    //OperatResult.AppendText("接受到客户端的数据,字节数:" + dataLength);
                     //如果客户端关闭,发送的数据就为空,就跳出循环
                     if (dataLength == 0)
                     {
                         break;
                     }
-
                     //假设收到的是个字符串(先这么假定),转成字符串处理
-                    string strMsg = Encoding.UTF8.GetString(buffer, 1, dataLength - 1);
+                    string strMsg = Encoding.UTF8.GetString(buffer, 0, dataLength);
                     Console.WriteLine("接受到客户端的消息:" + strMsg);
+                    for (int i = 0; i < dgv.Rows.Count; i++)
+                    {
+                        if (dgv.Rows[i].Cells["fp_name"].Value.ToString().Replace(".jpg", "") == strMsg.Replace("成功", ""))
+                        {
+                            dgv.Rows[i].Cells["issend"].Value = "发送成功";
+                        }
+                    }
+                    OperatResult.AppendText("接受到客户端的消息:" + strMsg);
                 }
                 //中止当前线程
-                Thread.CurrentThread.Abort();
+                //Thread.CurrentThread.Abort();
             }
             catch (Exception e)
             {
@@ -126,10 +148,17 @@ namespace FileWatcher
 
         public void Send(string Command)
         {
-            Console.WriteLine(  Command);
-            foreach (Socket item in socket)
+            try
+            {
+                Console.WriteLine(Command);
+                foreach (Socket item in socket)
+                {
+                    item.Send(Encoding.Default.GetBytes(Command));
+                }
+            }
+            catch (Exception ex)
             {
-                item.Send(Encoding.Default.GetBytes(Command));
+                Console.WriteLine(ex.Message);
             }
         }