Form1.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using System.Text.RegularExpressions;
  10. using System.Windows.Forms;
  11. using System.Windows.Forms.DataVisualization.Charting;
  12. using System.Web.ClientServices;
  13. using UAS_MES.CustomControl.DataGrid_View;
  14. using UAS_MES.DataOperate;
  15. using UAS_MES.PublicForm;
  16. using UAS_MES.PublicMethod;
  17. using System.Net;
  18. using System.IO;
  19. using System.Reflection;
  20. using System.Threading;
  21. using UAS_MES.CustomControl;
  22. namespace UAS_MES
  23. {
  24. public partial class Form1 : Form
  25. {
  26. DataHelper dh;
  27. DataTable dt;
  28. LogStringBuilder sql = new LogStringBuilder();
  29. //经过的步骤
  30. string PastStep = "";
  31. //拆分后的经过的步骤
  32. Dictionary<int, string> Step;
  33. //屏幕高度
  34. int ScreenWidth;
  35. //屏幕宽度
  36. int ScreenHeight;
  37. public Form1()
  38. {
  39. InitializeComponent();
  40. }
  41. [DllImport("kernel32.dll")]
  42. public static extern bool d(int freq, int duration);
  43. private void button3_Click(object sender, EventArgs e)
  44. {
  45. d(800, 600);
  46. }
  47. private void Form1_Load(object sender, EventArgs e)
  48. {
  49. }
  50. private void button3_Click_1(object sender, EventArgs e)
  51. {
  52. // 禁用按钮
  53. //this.button1.Enabled = false;
  54. //// 实例化业务对象
  55. //PublicMethod.LongTimeWork workder = new PublicMethod.LongTimeWork();
  56. //workder.ValueChanged += new PublicMethod.ValueChangedEventHandler(workder_ValueChanged);
  57. //// 使用异步方式调用长时间的方法
  58. //Action handler = new Action(workder.LongTimeMethod);
  59. //handler.BeginInvoke(new AsyncCallback(this.AsyncCallback), handler);
  60. WebClient wc = new WebClient();
  61. wc.DownloadProgressChanged += Wc_DownloadProgressChanged;
  62. wc.DownloadFileAsync(new Uri("http://218.17.158.219:8888/UAS_WinForm.zip"), "UAS_WinForm.zip");
  63. //processBar1.Run();
  64. }
  65. // 结束异步操作
  66. private void AsyncCallback(IAsyncResult ar)
  67. {
  68. // 标准的处理步骤
  69. Action handler = ar.AsyncState as Action;
  70. handler.EndInvoke(ar);
  71. MessageBox.Show("工作完成!");
  72. System.Windows.Forms.MethodInvoker invoker = () =>
  73. {
  74. // 重新启用按钮
  75. this.button3.Enabled = true;
  76. };
  77. if (this.InvokeRequired)
  78. {
  79. this.Invoke(invoker);
  80. }
  81. else
  82. {
  83. invoker();
  84. }
  85. }
  86. private void Wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
  87. {
  88. Action act = () =>
  89. {
  90. this.progressBar1.Value = e.ProgressPercentage;
  91. //this.label1.Text = e.ProgressPercentage + "%";
  92. };
  93. if (e.ProgressPercentage == 100)
  94. {
  95. ZipHelper.UnZip(@"H:\UAS_WinForm\UAS-MES\bin\Debug\icsharpcode-SharpZipLib-4ad264b.zip", @"D:\");
  96. }
  97. this.Invoke(act);
  98. }
  99. //public static void Unzip()
  100. //{
  101. // string _appPath = new DirectoryInfo(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName).Parent.FullName;
  102. // string s7z = _appPath + @"\7-Zip\7z.exe";
  103. // System.Diagnostics.Process pNew = new System.Diagnostics.Process();
  104. // pNew.StartInfo.FileName = s7z;
  105. // pNew.StartInfo.Arguments = string.Format(" x \"{0}\\{1}\" -y -o\"{0}\"", _appPath, zipFileFullName);
  106. // //x "1" -y -o"2" 这段7z命令的意思: x是解压的意思 "{0}"的位置写要解压文件路径"{1}"这个1的位置写要解压的文件名 -y是覆盖的意思 -o是要解压的位置
  107. // pNew.Start();
  108. // //等待完成
  109. // pNew.WaitForExit();
  110. // //删除压缩包
  111. // File.Delete(_appPath + @"\" + zipFileFullName);
  112. //}
  113. private void button4_Click(object sender, EventArgs e)
  114. {
  115. MessageBox.Show(textBoxWithPlaceHolder1.Text);
  116. }
  117. }
  118. //public class ZipHelper
  119. //{
  120. // public static string zipFileFullName = "UAS_WinForm.zip";
  121. // public static void Unzip()
  122. // {
  123. // string _appPath = new DirectoryInfo(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName).Parent.FullName;
  124. // string s7z = _appPath + @"\7z.exe";
  125. // System.Diagnostics.Process pNew = new System.Diagnostics.Process();
  126. // pNew.StartInfo.FileName = s7z;
  127. // pNew.StartInfo.Arguments = string.Format(" x \"{0}\\{1}\" -y -o\"{0}\"", _appPath, zipFileFullName);
  128. // //x "1" -y -o"2" 这段7z命令的意思: x是解压的意思 "{0}"的位置写要解压文件路径"{1}"这个1的位置写要解压的文件名 -y是覆盖的意思 -o是要解压的位置
  129. // pNew.Start();
  130. // //等待完成
  131. // pNew.WaitForExit();
  132. // //删除压缩包
  133. // //File.Delete(_appPath + @"\" + zipFileFullName);
  134. // }
  135. //}
  136. }