Browse Source

Merge branch 'master' of ssh://10.10.101.21/source/mes-client

Hcsy 8 years ago
parent
commit
f122cc6d10

+ 30 - 27
UAS-MES/FunctionCode/Make/Make_UpdateCollectCode.Designer.cs

@@ -54,18 +54,21 @@
             // 
             // collectCodeRules
             // 
+            this.collectCodeRules.AllowUserToAddRows = false;
+            this.collectCodeRules.AllowUserToDeleteRows = false;
             this.collectCodeRules.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
             this.collectCodeRules.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
             this.psr_type,
             this.psr_prefix,
             this.psr_length,
             this.Column1});
-            this.collectCodeRules.Location = new System.Drawing.Point(248, 58);
+            this.collectCodeRules.Enabled = false;
+            this.collectCodeRules.Location = new System.Drawing.Point(279, 70);
             this.collectCodeRules.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.collectCodeRules.Name = "collectCodeRules";
             this.collectCodeRules.RowHeadersVisible = false;
             this.collectCodeRules.RowTemplate.Height = 30;
-            this.collectCodeRules.Size = new System.Drawing.Size(652, 196);
+            this.collectCodeRules.Size = new System.Drawing.Size(734, 235);
             this.collectCodeRules.TabIndex = 6;
             // 
             // psr_type
@@ -100,9 +103,9 @@
             // 
             this.label1.AutoSize = true;
             this.label1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label1.Location = new System.Drawing.Point(244, 22);
+            this.label1.Location = new System.Drawing.Point(274, 26);
             this.label1.Name = "label1";
-            this.label1.Size = new System.Drawing.Size(92, 27);
+            this.label1.Size = new System.Drawing.Size(110, 31);
             this.label1.TabIndex = 7;
             this.label1.Text = "防呆规则";
             // 
@@ -139,11 +142,11 @@
             this.collects.Controls.Add(this.Imei1);
             this.collects.Controls.Add(this.Imei2);
             this.collects.Controls.Add(this.Imei3);
-            this.collects.Location = new System.Drawing.Point(24, 15);
+            this.collects.Location = new System.Drawing.Point(27, 18);
             this.collects.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.collects.Name = "collects";
             this.collects.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
-            this.collects.Size = new System.Drawing.Size(199, 239);
+            this.collects.Size = new System.Drawing.Size(224, 287);
             this.collects.TabIndex = 92;
             this.collects.TabStop = false;
             this.collects.TextColor = System.Drawing.Color.Black;
@@ -152,11 +155,11 @@
             // 
             this.Mac.AutoSize = true;
             this.Mac.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.Mac.Location = new System.Drawing.Point(33, 20);
+            this.Mac.Location = new System.Drawing.Point(37, 23);
             this.Mac.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.Mac.Name = "Mac";
             this.Mac.Power = null;
-            this.Mac.Size = new System.Drawing.Size(133, 31);
+            this.Mac.Size = new System.Drawing.Size(157, 35);
             this.Mac.TabIndex = 5;
             this.Mac.Text = "MAC/WIFI";
             this.Mac.UseVisualStyleBackColor = true;
@@ -166,11 +169,11 @@
             // 
             this.Bt.AutoSize = true;
             this.Bt.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.Bt.Location = new System.Drawing.Point(33, 57);
+            this.Bt.Location = new System.Drawing.Point(37, 67);
             this.Bt.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.Bt.Name = "Bt";
             this.Bt.Power = null;
-            this.Bt.Size = new System.Drawing.Size(58, 31);
+            this.Bt.Size = new System.Drawing.Size(69, 35);
             this.Bt.TabIndex = 4;
             this.Bt.Text = "BT";
             this.Bt.UseVisualStyleBackColor = true;
@@ -180,11 +183,11 @@
             // 
             this.NetCode.AutoSize = true;
             this.NetCode.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.NetCode.Location = new System.Drawing.Point(33, 93);
+            this.NetCode.Location = new System.Drawing.Point(37, 110);
             this.NetCode.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.NetCode.Name = "NetCode";
             this.NetCode.Power = null;
-            this.NetCode.Size = new System.Drawing.Size(74, 31);
+            this.NetCode.Size = new System.Drawing.Size(88, 35);
             this.NetCode.TabIndex = 3;
             this.NetCode.Text = "网标";
             this.NetCode.UseVisualStyleBackColor = true;
@@ -194,11 +197,11 @@
             // 
             this.Imei1.AutoSize = true;
             this.Imei1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.Imei1.Location = new System.Drawing.Point(33, 129);
+            this.Imei1.Location = new System.Drawing.Point(37, 154);
             this.Imei1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.Imei1.Name = "Imei1";
             this.Imei1.Power = null;
-            this.Imei1.Size = new System.Drawing.Size(89, 31);
+            this.Imei1.Size = new System.Drawing.Size(104, 35);
             this.Imei1.TabIndex = 2;
             this.Imei1.Text = "IMEI1";
             this.Imei1.UseVisualStyleBackColor = true;
@@ -208,11 +211,11 @@
             // 
             this.Imei2.AutoSize = true;
             this.Imei2.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.Imei2.Location = new System.Drawing.Point(33, 166);
+            this.Imei2.Location = new System.Drawing.Point(37, 198);
             this.Imei2.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.Imei2.Name = "Imei2";
             this.Imei2.Power = null;
-            this.Imei2.Size = new System.Drawing.Size(89, 31);
+            this.Imei2.Size = new System.Drawing.Size(104, 35);
             this.Imei2.TabIndex = 1;
             this.Imei2.Text = "IMEI2";
             this.Imei2.UseVisualStyleBackColor = true;
@@ -222,11 +225,11 @@
             // 
             this.Imei3.AutoSize = true;
             this.Imei3.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.Imei3.Location = new System.Drawing.Point(33, 202);
+            this.Imei3.Location = new System.Drawing.Point(37, 241);
             this.Imei3.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.Imei3.Name = "Imei3";
             this.Imei3.Power = null;
-            this.Imei3.Size = new System.Drawing.Size(89, 31);
+            this.Imei3.Size = new System.Drawing.Size(104, 35);
             this.Imei3.TabIndex = 0;
             this.Imei3.Text = "IMEI3";
             this.Imei3.UseVisualStyleBackColor = true;
@@ -237,11 +240,11 @@
             this.inputValue.AllPower = null;
             this.inputValue.BackColor = System.Drawing.Color.White;
             this.inputValue.ID = null;
-            this.inputValue.Location = new System.Drawing.Point(147, 477);
+            this.inputValue.Location = new System.Drawing.Point(165, 572);
             this.inputValue.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
             this.inputValue.Name = "inputValue";
             this.inputValue.Power = null;
-            this.inputValue.Size = new System.Drawing.Size(229, 25);
+            this.inputValue.Size = new System.Drawing.Size(257, 28);
             this.inputValue.Str = null;
             this.inputValue.Str1 = null;
             this.inputValue.Str2 = null;
@@ -251,10 +254,10 @@
             // OperateResult
             // 
             this.OperateResult.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.OperateResult.Location = new System.Drawing.Point(24, 272);
-            this.OperateResult.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
+            this.OperateResult.Location = new System.Drawing.Point(27, 326);
+            this.OperateResult.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
             this.OperateResult.Name = "OperateResult";
-            this.OperateResult.Size = new System.Drawing.Size(876, 191);
+            this.OperateResult.Size = new System.Drawing.Size(985, 228);
             this.OperateResult.TabIndex = 88;
             this.OperateResult.Text = "";
             // 
@@ -262,17 +265,17 @@
             // 
             this.label3.AutoSize = true;
             this.label3.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-            this.label3.Location = new System.Drawing.Point(69, 475);
+            this.label3.Location = new System.Drawing.Point(78, 570);
             this.label3.Name = "label3";
-            this.label3.Size = new System.Drawing.Size(72, 27);
+            this.label3.Size = new System.Drawing.Size(86, 31);
             this.label3.TabIndex = 93;
             this.label3.Text = "输入框";
             // 
             // Make_UpdateCollectCode
             // 
-            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
+            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(924, 512);
+            this.ClientSize = new System.Drawing.Size(1040, 614);
             this.Controls.Add(this.label3);
             this.Controls.Add(this.collects);
             this.Controls.Add(this.inputValue);

+ 5 - 0
UAS-MES/FunctionCode/Make/Make_UpdateCollectCode.cs

@@ -73,6 +73,11 @@ namespace UAS_MES.Make
                 OperateResult.AppendText(">>" + inputValue.Text + "\n", Color.Black);
                 if (step == 0)
                 {
+                    //避免第一步出错的时候添加不需要的数据
+                    if (list.Count!=0)
+                    {
+                        list.Clear();
+                    }
                     //判断是否有已勾选的项次
                     foreach (Control ctl in collects.Controls)
                     {

+ 26 - 12
UAS_AutoUpdate/CheckUpdateWindow.Designer.cs

@@ -28,31 +28,45 @@
         /// </summary>
         private void InitializeComponent()
         {
-            this.progressBar1 = new System.Windows.Forms.ProgressBar();
+            this._progressbar = new System.Windows.Forms.ProgressBar();
+            this._processrate = new System.Windows.Forms.Label();
             this.SuspendLayout();
             // 
-            // progressBar1
+            // _progressbar
             // 
-            this.progressBar1.Location = new System.Drawing.Point(51, 56);
-            this.progressBar1.Name = "progressBar1";
-            this.progressBar1.Size = new System.Drawing.Size(253, 23);
-            this.progressBar1.TabIndex = 0;
+            this._progressbar.Location = new System.Drawing.Point(44, 56);
+            this._progressbar.Name = "_progressbar";
+            this._progressbar.Size = new System.Drawing.Size(253, 23);
+            this._progressbar.TabIndex = 0;
             // 
-            // Form1
+            // _processrate
+            // 
+            this._processrate.AutoSize = true;
+            this._processrate.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this._processrate.Location = new System.Drawing.Point(307, 57);
+            this._processrate.Name = "_processrate";
+            this._processrate.Size = new System.Drawing.Size(0, 21);
+            this._processrate.TabIndex = 1;
+            // 
+            // CheckUpdateWindow
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(355, 142);
-            this.Controls.Add(this.progressBar1);
-            this.Name = "Form1";
-            this.Text = "Form1";
+            this.ClientSize = new System.Drawing.Size(373, 142);
+            this.Controls.Add(this._processrate);
+            this.Controls.Add(this._progressbar);
+            this.Name = "CheckUpdateWindow";
+            this.Text = "检测升级";
+            this.Load += new System.EventHandler(this.CheckUpdateWindow_Load);
             this.ResumeLayout(false);
+            this.PerformLayout();
 
         }
 
         #endregion
 
-        private System.Windows.Forms.ProgressBar progressBar1;
+        private System.Windows.Forms.ProgressBar _progressbar;
+        private System.Windows.Forms.Label _processrate;
     }
 }
 

+ 82 - 8
UAS_AutoUpdate/CheckUpdateWindow.cs

@@ -1,10 +1,7 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
+using ICSharpCode.SharpZipLib.Zip;
+using System;
+using System.IO;
+using System.Net;
 using System.Windows.Forms;
 
 namespace UAS_AutoUpdate
@@ -15,5 +12,82 @@ namespace UAS_AutoUpdate
         {
             InitializeComponent();
         }
+
+        private void CheckUpdateWindow_Load(object sender, EventArgs e)
+        {
+            //使用WebClient从指定位置下载文件,然后进行解压缩覆盖
+            MessageBox.Show(Application.StartupPath);
+            WebClient wc = new WebClient();
+            wc.DownloadProgressChanged += Wc_DownloadProgressChanged;
+            wc.DownloadFileAsync(new Uri("http://218.17.158.219:8888/Debug.zip"), "Debug.zip");
+        }
+
+        private void Wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
+        {
+            Action act = () =>
+            {
+                _progressbar.Value = e.ProgressPercentage;
+                _processrate.Text = e.ProgressPercentage + "%";
+            };
+            if (IsHandleCreated)
+                this.Invoke(act);
+            if (e.ProgressPercentage == 100)
+            {
+                ZipHelper.UnZip(Application.StartupPath + @"\Debug.zip", @"F:\TEST");
+            }
+            //Close();
+        }
+    }
+
+    public class ZipHelper
+    {
+        /// <summary>
+        /// 用于解压缩Zip文件
+        /// </summary>
+        /// <param name="ZipFilePath"></param>
+        /// <param name="UnZipPath"></param>
+        public static void UnZip(string ZipFilePath, string UnZipPath)
+        {
+            if (!File.Exists(ZipFilePath))
+            {
+                throw new FileNotFoundException(string.Format("未能找到文件 '{0}' ", ZipFilePath));
+            }
+
+            if (!Directory.Exists(UnZipPath))
+            {
+                Directory.CreateDirectory(UnZipPath);
+            }
+
+            using (var s = new ZipInputStream(File.OpenRead(ZipFilePath)))
+            {
+                ZipEntry theEntry;
+                while ((theEntry = s.GetNextEntry()) != null)
+                {
+                    if (theEntry.IsDirectory)
+                    {
+                        continue;
+                    }
+                    string directorName = Path.Combine(UnZipPath, Path.GetDirectoryName(theEntry.Name));
+                    string fileName = Path.Combine(directorName, Path.GetFileName(theEntry.Name));
+                    if (!Directory.Exists(directorName))
+                    {
+                        Directory.CreateDirectory(directorName);
+                    }
+                    if (!string.IsNullOrEmpty(fileName))
+                    {
+                        using (FileStream streamWriter = File.Create(fileName))
+                        {
+                            int size = 4096;
+                            byte[] data = new byte[size];
+                            while (size > 0)
+                            {
+                                streamWriter.Write(data, 0, size);
+                                size = s.Read(data, 0, data.Length);
+                            }
+                        }
+                    }
+                }
+            }
+        }
     }
-}
+}

+ 48 - 3
UAS_AutoUpdate/Program.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Security.Principal;
 using System.Windows.Forms;
 
 namespace UAS_AutoUpdate
@@ -13,9 +14,53 @@ namespace UAS_AutoUpdate
         [STAThread]
         static void Main()
         {
-            Application.EnableVisualStyles();
-            Application.SetCompatibleTextRenderingDefault(false);
-            Application.Run(new CheckUpdateWindow());
+            try
+            {
+                WindowsIdentity identity = WindowsIdentity.GetCurrent();
+                WindowsPrincipal principal = new WindowsPrincipal(identity);
+                //设置应用程序处理异常方式:ThreadException处理
+                Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
+                //处理UI线程异常
+                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
+                //处理非UI线程异常
+                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
+                #region 应用程序的主入口点
+                Application.EnableVisualStyles();
+                Application.SetCompatibleTextRenderingDefault(false);
+                string sysdisc = Environment.GetEnvironmentVariable("windir").Substring(0, 1);
+                //创建标签缓存的文件夹
+
+                if (principal.IsInRole(WindowsBuiltInRole.Administrator))
+                    Application.Run(new CheckUpdateWindow());
+                else
+                {
+                    //创建启动对象
+                    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
+                    // 设置运行文件
+                    startInfo.FileName = Application.ExecutablePath;
+                    //设置启动动作,确保以管理员身份运行
+                    startInfo.Verb = "runas";
+                    //如果不是管理员,则启动UAC
+                    System.Diagnostics.Process.Start(startInfo);
+                }
+                #endregion
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
+            }
+        }
+
+        //处理线程的异常
+        static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
+        {
+            MessageBox.Show(e.Exception.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
+        }
+
+        //未处理的异常统一通过这里返回
+        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
+        {
+            MessageBox.Show(e.ExceptionObject.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop);
         }
     }
 }

+ 5 - 0
UAS_AutoUpdate/UAS_AutoUpdate.csproj

@@ -49,7 +49,12 @@
   <PropertyGroup>
     <ApplicationIcon>Resources\update.ico</ApplicationIcon>
   </PropertyGroup>
+  <PropertyGroup />
+  <PropertyGroup />
   <ItemGroup>
+    <Reference Include="ICSharpCode.SharpZipLib">
+      <HintPath>tool\ICSharpCode.SharpZipLib.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xml.Linq" />

BIN
UAS_AutoUpdate/tool/ICSharpCode.SharpZipLib.dll