FormHOZMain.cs 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. using FileManager;
  2. using MeasureData;
  3. using MeasureThread;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Configuration;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Drawing.Drawing2D;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Runtime.InteropServices;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows.Forms;
  17. using static MeasureThread.ThreadStatusEventArgs;
  18. namespace HOZProject
  19. {
  20. public partial class FormHOZMain : Form
  21. {
  22. #region 控制窗体可以调整大小用
  23. const int HTLEFT = 10;
  24. const int HTRIGHT = 11;
  25. const int HTTOP = 12;
  26. const int HTTOPLEFT = 13;
  27. const int HTTOPRIGHT = 14;
  28. const int HTBOTTOM = 15;
  29. const int HTBOTTOMLEFT = 0x10;
  30. const int HTBOTTOMRIGHT = 17;
  31. protected override void WndProc(ref Message m)
  32. {
  33. switch (m.Msg)
  34. {
  35. case 0x0084:
  36. base.WndProc(ref m);
  37. Point vPoint = new Point((int)m.LParam & 0xFFFF,
  38. (int)m.LParam >> 16 & 0xFFFF);
  39. vPoint = PointToClient(vPoint);
  40. if (vPoint.X <= 5)
  41. if (vPoint.Y <= 5)
  42. m.Result = (IntPtr)HTTOPLEFT;
  43. else if (vPoint.Y >= ClientSize.Height - 5)
  44. m.Result = (IntPtr)HTBOTTOMLEFT;
  45. else m.Result = (IntPtr)HTLEFT;
  46. else if (vPoint.X >= ClientSize.Width - 5)
  47. if (vPoint.Y <= 5)
  48. m.Result = (IntPtr)HTTOPRIGHT;
  49. else if (vPoint.Y >= ClientSize.Height - 5)
  50. m.Result = (IntPtr)HTBOTTOMRIGHT;
  51. else m.Result = (IntPtr)HTRIGHT;
  52. else if (vPoint.Y <= 5)
  53. m.Result = (IntPtr)HTTOP;
  54. else if (vPoint.Y >= ClientSize.Height - 5)
  55. m.Result = (IntPtr)HTBOTTOM;
  56. break;
  57. case 0x0201://鼠标左键按下的消息
  58. m.Msg = 0x00A1;//更改消息为非客户区按下鼠标
  59. m.LParam = IntPtr.Zero;//默认值
  60. m.WParam = new IntPtr(2);//鼠标放在标题栏内
  61. base.WndProc(ref m);
  62. break;
  63. default:
  64. base.WndProc(ref m);
  65. break;
  66. }
  67. }
  68. #endregion
  69. #region 成员变量
  70. /// <summary>
  71. /// 控制闪烁
  72. /// </summary>
  73. public static bool ControlFlicker;//控制流程闪烁
  74. public BackgroundWorker m_BackgroundWorker;// 申明后台对象
  75. /// <summary>
  76. /// 测量文件
  77. /// </summary>
  78. public MeasureFile m_MeasureFile;
  79. /// 测量线程
  80. public Measure m_Ms;
  81. /// <summary>
  82. /// 显示日志窗体
  83. /// </summary>
  84. Form m_FormLog = null;
  85. /// <summary>
  86. /// 显示实例化窗体
  87. /// </summary>
  88. FormMove m_FormInit = null;
  89. /// <summary>
  90. /// 是否已保存
  91. /// </summary>
  92. public bool IsSave = false;
  93. /// <summary>
  94. /// 初始化用户控件
  95. /// </summary>
  96. UControl_Init uControl_Init = null;
  97. /// <summary>
  98. /// 日志用户控件
  99. /// </summary>
  100. UControl_Log ucLog = null;
  101. //流程控制
  102. public int m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  103. //是否关闭窗体标识
  104. public bool IsClose = false;
  105. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  106. #endregion
  107. #region 构造函数
  108. public FormHOZMain()
  109. {
  110. InitializeComponent();
  111. //在线程操作过程中,可以设置控件属性
  112. Control.CheckForIllegalCrossThreadCalls = false;
  113. m_BackgroundWorker = new BackgroundWorker(); // 实例化后台对象
  114. m_BackgroundWorker.WorkerReportsProgress = true; // 设置可以通告进度
  115. m_BackgroundWorker.WorkerSupportsCancellation = true; // 设置可以取消
  116. m_BackgroundWorker.DoWork += new DoWorkEventHandler(DoWork);
  117. m_BackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(UpdateProgress);
  118. m_BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedWork);
  119. LogManager.InitManulLog();
  120. }
  121. #endregion
  122. #region 测量线程
  123. void DoWork(object sender, DoWorkEventArgs e)
  124. {
  125. try
  126. {
  127. m_Ms = new Measure(ConfigurationManager.AppSettings["WebServerIP"].ToString(),
  128. ConfigurationManager.AppSettings["WebServerPort"].ToString(),
  129. ConfigurationManager.AppSettings["WebServerUrl"].ToString());
  130. m_MeasureFile.MParam.AutoFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  131. m_MeasureFile.MParam.AutoFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  132. m_MeasureFile.MParam.AutoFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  133. m_MeasureFile.MParam.AutoFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  134. m_MeasureFile.MParam.AutoFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  135. m_MeasureFile.MParam.FIBFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_UP"].ToString());
  136. m_MeasureFile.MParam.FIBFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Down"].ToString());
  137. m_MeasureFile.MParam.FIBFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Step"].ToString());
  138. m_MeasureFile.MParam.FIBFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_Range"].ToString());
  139. m_MeasureFile.MParam.FIBFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["FIB_FStep"].ToString());
  140. m_MeasureFile.MParam.AutoStigX.UP = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_UP"].ToString());
  141. m_MeasureFile.MParam.AutoStigX.Down = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Down"].ToString());
  142. m_MeasureFile.MParam.AutoStigX.Step = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Step"].ToString());
  143. m_MeasureFile.MParam.AutoStigX.Range = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_Range"].ToString());
  144. m_MeasureFile.MParam.AutoStigX.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["StigX_FStep"].ToString());
  145. m_MeasureFile.MParam.AutoStigY.UP = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_UP"].ToString());
  146. m_MeasureFile.MParam.AutoStigY.Down = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Down"].ToString());
  147. m_MeasureFile.MParam.AutoStigY.Step = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Step"].ToString());
  148. m_MeasureFile.MParam.AutoStigY.Range = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_Range"].ToString());
  149. m_MeasureFile.MParam.AutoStigY.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["StigY_FStep"].ToString());
  150. m_MeasureFile.MParam.FIBDo= Convert.ToBoolean(ConfigurationManager.AppSettings["Is_FIBDo"]);
  151. m_MeasureFile.MParam.FIBAutoBC = Convert.ToBoolean(ConfigurationManager.AppSettings["Is_FIBAutoBc"]);
  152. m_MeasureFile.MParam.FIBB = Convert.ToSingle(ConfigurationManager.AppSettings["FIBB"]);
  153. m_MeasureFile.MParam.FIBC = Convert.ToSingle(ConfigurationManager.AppSettings["FIBC"]);
  154. m_MeasureFile.MParam.MagComp = Convert.ToBoolean(ConfigurationManager.AppSettings["MagComp"]);
  155. m_MeasureFile.MParam.MagRange1 = Convert.ToSingle(ConfigurationManager.AppSettings["MagRange1"]);
  156. m_MeasureFile.MParam.MagRange2 = Convert.ToSingle(ConfigurationManager.AppSettings["MagRange2"]);
  157. m_MeasureFile.MParam.MagRange3 = Convert.ToSingle(ConfigurationManager.AppSettings["MagRange3"]);
  158. m_MeasureFile.MParam.MagCompX1 = Convert.ToSingle(ConfigurationManager.AppSettings["MagCompX1"]);
  159. m_MeasureFile.MParam.MagCompX2 = Convert.ToSingle(ConfigurationManager.AppSettings["MagCompX2"]);
  160. m_MeasureFile.MParam.MagCompX3 = Convert.ToSingle(ConfigurationManager.AppSettings["MagCompX3"]);
  161. m_MeasureFile.MParam.MagCompY1 = Convert.ToSingle(ConfigurationManager.AppSettings["MagCompY1"]);
  162. m_MeasureFile.MParam.MagCompY2 = Convert.ToSingle(ConfigurationManager.AppSettings["MagCompY2"]);
  163. m_MeasureFile.MParam.MagCompY3 = Convert.ToSingle(ConfigurationManager.AppSettings["MagCompY3"]);
  164. m_Ms.X_Min = Convert.ToSingle(ConfigurationManager.AppSettings["X_Min"]);
  165. m_Ms.X_Max = Convert.ToSingle(ConfigurationManager.AppSettings["X_Max"]);
  166. m_Ms.Y_Min = Convert.ToSingle(ConfigurationManager.AppSettings["Y_Min"]);
  167. m_Ms.Y_Max = Convert.ToSingle(ConfigurationManager.AppSettings["Y_Max"]);
  168. m_Ms.Z_Min = Convert.ToSingle(ConfigurationManager.AppSettings["Z_Min"]);
  169. m_Ms.Z_Max = Convert.ToSingle(ConfigurationManager.AppSettings["Z_Max"]);
  170. m_Ms.T_Min = Convert.ToSingle(ConfigurationManager.AppSettings["T_Min"]);
  171. m_Ms.T_Max = Convert.ToSingle(ConfigurationManager.AppSettings["T_Max"]);
  172. m_Ms.R_Min = Convert.ToSingle(ConfigurationManager.AppSettings["R_Min"]);
  173. m_Ms.R_Max = Convert.ToSingle(ConfigurationManager.AppSettings["R_Max"]);
  174. m_Ms.M_Min = Convert.ToSingle(ConfigurationManager.AppSettings["M_Min"]);
  175. m_Ms.M_Max = Convert.ToSingle(ConfigurationManager.AppSettings["M_Max"]);
  176. //人工干预
  177. m_Ms.hand_intervene = Convert.ToInt32(ConfigurationManager.AppSettings["Hand_Intervene"]);
  178. //SmartSEM远程路径
  179. m_Ms.RemoteELYPath = ConfigurationManager.AppSettings["RemoteELYPath"];
  180. m_Ms.RemoteMLFPath = ConfigurationManager.AppSettings["RemoteMLFPath"];
  181. //Z轴移动距离
  182. m_MeasureFile.MParam.ZDistance= Convert.ToSingle(ConfigurationManager.AppSettings["ZDistance"]);
  183. //add by sun 2020-12-15 增加不同样品扫描速度参数
  184. m_MeasureFile.MParam.ScanSpeedNormal = Convert.ToString(ConfigurationManager.AppSettings["ScanSpeedNormal_" + m_MeasureFile.MParam.SampleName]);
  185. m_MeasureFile.MParam.ScanSpeedFocus = Convert.ToString(ConfigurationManager.AppSettings["ScanSpeedFocus_" + m_MeasureFile.MParam.SampleName]);
  186. m_MeasureFile.MParam.ScanSpeedHigh = Convert.ToString(ConfigurationManager.AppSettings["ScanSpeedHigh_" + m_MeasureFile.MParam.SampleName]);
  187. LogManager.AddHardwareLog("==============="+ ConfigurationManager.AppSettings["ScanSpeedNormal_3"] + "========="+ m_MeasureFile.MParam.SampleName, true);
  188. //add by sun 2020-12-15 增加不同样品扫描速度参数 end
  189. //add by sun 2020-12-17 增加调试时是否切割开关
  190. m_MeasureFile.MParam.IsCutingForDebug = Convert.ToBoolean(ConfigurationManager.AppSettings["IsCutingForDebug"]);
  191. //add by sun 2020-12-17 增加调试时是否切割开关 end
  192. // add by zjx 2020-12-18 为了测试只做能谱部分
  193. m_MeasureFile.MParam.IsonlyEDSForDebug = Convert.ToBoolean(ConfigurationManager.AppSettings["IsonlyEDSForDebug"]);
  194. // add by zjx 2020-12-18 为了测试只做能谱部分 end
  195. #region 初始化参数的默认值
  196. // add by zjx 2020-12-20 厂商参数
  197. m_MeasureFile.MParam.VendorType0 = Convert.ToString(ConfigurationManager.AppSettings["VendorType0"]);
  198. m_MeasureFile.MParam.VendorType1 = Convert.ToString(ConfigurationManager.AppSettings["VendorType1"]);
  199. m_MeasureFile.MParam.VendorType2 = Convert.ToString(ConfigurationManager.AppSettings["VendorType2"]);
  200. m_MeasureFile.MParam.VendorType3 = Convert.ToString(ConfigurationManager.AppSettings["VendorType3"]);
  201. // add by zjx 2020-12-20 厂商参数 end
  202. // add by zjx 2020-12-21 校正角度
  203. m_MeasureFile.MParam.CorrectionType0 = Convert.ToString(ConfigurationManager.AppSettings["CorrectionType0"]);
  204. m_MeasureFile.MParam.CorrectionType1 = Convert.ToString(ConfigurationManager.AppSettings["CorrectionType1"]);
  205. m_MeasureFile.MParam.CorrectionType2 = Convert.ToString(ConfigurationManager.AppSettings["CorrectionType2"]);
  206. m_MeasureFile.MParam.CorrectionType3 = Convert.ToString(ConfigurationManager.AppSettings["CorrectionType3"]);
  207. // add by zjx 2020-12-21 校正角度 end
  208. // add by zjx 2020-12-21 拉直操作放大倍数
  209. m_MeasureFile.MParam.StraightenTimesType0 = Convert.ToString(ConfigurationManager.AppSettings["StraightenTimesType0"]);
  210. m_MeasureFile.MParam.StraightenTimesType1 = Convert.ToString(ConfigurationManager.AppSettings["StraightenTimesType1"]);
  211. m_MeasureFile.MParam.StraightenTimesType2 = Convert.ToString(ConfigurationManager.AppSettings["StraightenTimesType2"]);
  212. m_MeasureFile.MParam.StraightenTimesType3 = Convert.ToString(ConfigurationManager.AppSettings["StraightenTimesType3"]);
  213. // add by zjx 2020-12-21 拉直操作放大倍数 end
  214. // add by zjx 2020-12-21 定位电压
  215. m_MeasureFile.MParam.PositioningVoltageeType0 = Convert.ToString(ConfigurationManager.AppSettings["PositioningVoltageeType0"]);
  216. m_MeasureFile.MParam.PositioningVoltageeType1 = Convert.ToString(ConfigurationManager.AppSettings["PositioningVoltageeType1"]);
  217. m_MeasureFile.MParam.PositioningVoltageeType2 = Convert.ToString(ConfigurationManager.AppSettings["PositioningVoltageeType2"]);
  218. m_MeasureFile.MParam.PositioningVoltageeType3 = Convert.ToString(ConfigurationManager.AppSettings["PositioningVoltageeType3"]);
  219. // add by zjx 2020-12-21 定位电压 end
  220. // add by zjx 2020-12-21 定位放大倍数
  221. m_MeasureFile.MParam.PositioningTimesType0 = Convert.ToString(ConfigurationManager.AppSettings["PositioningTimesType0"]);
  222. m_MeasureFile.MParam.PositioningTimesType1 = Convert.ToString(ConfigurationManager.AppSettings["PositioningTimesType1"]);
  223. m_MeasureFile.MParam.PositioningTimesType2 = Convert.ToString(ConfigurationManager.AppSettings["PositioningTimesType2"]);
  224. m_MeasureFile.MParam.PositioningTimesType3 = Convert.ToString(ConfigurationManager.AppSettings["PositioningTimesType3"]);
  225. // add by zjx 2020-12-21 定位放大倍数 end
  226. // add by zjx 2020-12-21 拍照电压
  227. m_MeasureFile.MParam.PhotoVoltageeType0 = Convert.ToString(ConfigurationManager.AppSettings["PhotoVoltageeType0"]);
  228. m_MeasureFile.MParam.PhotoVoltageeType1 = Convert.ToString(ConfigurationManager.AppSettings["PhotoVoltageeType1"]);
  229. m_MeasureFile.MParam.PhotoVoltageeType2 = Convert.ToString(ConfigurationManager.AppSettings["PhotoVoltageeType2"]);
  230. m_MeasureFile.MParam.PhotoVoltageeType3 = Convert.ToString(ConfigurationManager.AppSettings["PhotoVoltageeType3"]);
  231. // add by zjx 2020-12-21 拍照电压 end
  232. // add by zjx 2020-12-21 拍照放大倍数
  233. m_MeasureFile.MParam.PhotoTimesType0 = Convert.ToString(ConfigurationManager.AppSettings["PhotoTimesType0"]);
  234. m_MeasureFile.MParam.PhotoTimesType1 = Convert.ToString(ConfigurationManager.AppSettings["PhotoTimesType1"]);
  235. m_MeasureFile.MParam.PhotoTimesType2 = Convert.ToString(ConfigurationManager.AppSettings["PhotoTimesType2"]);
  236. m_MeasureFile.MParam.PhotoTimesType3 = Convert.ToString(ConfigurationManager.AppSettings["PhotoTimesType3"]);
  237. // add by zjx 2020-12-21 拍照放大倍数 end
  238. // add by zjx 2020-12-21 ScanRotate修正参数
  239. m_MeasureFile.MParam.ScanRotateType0 = Convert.ToString(ConfigurationManager.AppSettings["ScanRotateType0"]);
  240. m_MeasureFile.MParam.ScanRotateType1 = Convert.ToString(ConfigurationManager.AppSettings["ScanRotateType1"]);
  241. m_MeasureFile.MParam.ScanRotateType2 = Convert.ToString(ConfigurationManager.AppSettings["ScanRotateType2"]);
  242. m_MeasureFile.MParam.ScanRotateType3 = Convert.ToString(ConfigurationManager.AppSettings["ScanRotateType3"]);
  243. // add by zjx 2020-12-21 ScanRotate修正参数 end
  244. // add by zjx 2020-12-21 Y轴方向PixelSize修正值
  245. m_MeasureFile.MParam.PixelSizeType0 = Convert.ToString(ConfigurationManager.AppSettings["PixelSizeType0"]);
  246. m_MeasureFile.MParam.PixelSizeType1 = Convert.ToString(ConfigurationManager.AppSettings["PixelSizeType1"]);
  247. m_MeasureFile.MParam.PixelSizeType2 = Convert.ToString(ConfigurationManager.AppSettings["PixelSizeType2"]);
  248. m_MeasureFile.MParam.PixelSizeType3 = Convert.ToString(ConfigurationManager.AppSettings["PixelSizeType3"]);
  249. // add by zjx 2020-12-21 Y轴方向PixelSize修正值 end
  250. // add by zjx 2020-12-21 能谱Z轴移动位置
  251. m_MeasureFile.MParam.SEMAxis_ZType0 = Convert.ToString(ConfigurationManager.AppSettings["SEMAxis_ZType0"]);
  252. m_MeasureFile.MParam.SEMAxis_ZType1 = Convert.ToString(ConfigurationManager.AppSettings["SEMAxis_ZType1"]);
  253. m_MeasureFile.MParam.SEMAxis_ZType2 = Convert.ToString(ConfigurationManager.AppSettings["SEMAxis_ZType2"]);
  254. m_MeasureFile.MParam.SEMAxis_ZType3 = Convert.ToString(ConfigurationManager.AppSettings["SEMAxis_ZType3"]);
  255. // add by zjx 2020-12-21 能谱Z轴移动位置 end
  256. // add by zjx 2020-12-21 能谱电压值
  257. m_MeasureFile.MParam.SEMVoltageeType0 = Convert.ToString(ConfigurationManager.AppSettings["SEMVoltageeType0"]);
  258. m_MeasureFile.MParam.SEMVoltageeType1 = Convert.ToString(ConfigurationManager.AppSettings["SEMVoltageeType1"]);
  259. m_MeasureFile.MParam.SEMVoltageeType2 = Convert.ToString(ConfigurationManager.AppSettings["SEMVoltageeType2"]);
  260. m_MeasureFile.MParam.SEMVoltageeType3 = Convert.ToString(ConfigurationManager.AppSettings["SEMVoltageeType3"]);
  261. // add by zjx 2020-12-21 能谱电压值 end
  262. // add by zjx 2020-12-21 能谱电流值
  263. m_MeasureFile.MParam.SEMCurrentType0 = Convert.ToString(ConfigurationManager.AppSettings["SEMCurrentType0"]);
  264. m_MeasureFile.MParam.SEMCurrentType1 = Convert.ToString(ConfigurationManager.AppSettings["SEMCurrentType1"]);
  265. m_MeasureFile.MParam.SEMCurrentType2 = Convert.ToString(ConfigurationManager.AppSettings["SEMCurrentType2"]);
  266. m_MeasureFile.MParam.SEMCurrentType3 = Convert.ToString(ConfigurationManager.AppSettings["SEMCurrentType3"]);
  267. // add by zjx 2020-12-21 能谱电流值 end
  268. #endregion
  269. m_Ms.InitMeas(m_MeasureFile);
  270. //注册事件
  271. m_Ms.SendThreadStatus += new ThreadStatusHandler(displayMessage);
  272. //注册事件
  273. m_Ms.SendCutHolesStatus += new CutHolesStatusHandler(displayCutHoleMessage);
  274. //设置控件操作
  275. SetWinControlMeasureState(false);
  276. //自动测量的全过程
  277. m_Ms.DoMeasure();
  278. }
  279. catch (Exception ex)
  280. {
  281. LogManager.AddHardwareLog(ex.ToString(),true);
  282. }
  283. }
  284. public void displayMessage(object sender, ThreadStatusEventArgs e)
  285. {
  286. //主界面显示内容
  287. this.BeginInvoke((Action)delegate
  288. {
  289. this.listmsg.Items.Add(e.HoleName +"_" + e.Time.ToString() + "_"+ e.Message + "_" + e.State );
  290. //显示流程中对应编号的内容
  291. MeasureMsgManage.ShowMsgContent(this, e);
  292. AddLogListInfo(e);
  293. });
  294. }
  295. public void displayCutHoleMessage(object sender, CutHolesStatusEventArgs e)
  296. {
  297. //主界面显示内容
  298. this.BeginInvoke((Action)delegate
  299. {
  300. //修改切孔状态
  301. ChangeCutHoleState(e.HoleName.ToString(), Convert.ToInt32(e.State));
  302. });
  303. }
  304. void UpdateProgress(object sender, ProgressChangedEventArgs e)
  305. {
  306. }
  307. void CompletedWork(object sender, RunWorkerCompletedEventArgs e)
  308. {
  309. ControlFlicker = false;
  310. //设置控件操作
  311. MessageBox.Show("测量已完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  312. SetWinControlMeasureState(true);
  313. pbStop.Visible = false;
  314. pbStart.Visible = true;
  315. //UControl_ParaInfo uControl_ParaInfo=new UControl_ParaInfo()
  316. UControl_ParaInfo uControl_ParaInfo = new UControl_ParaInfo(this);
  317. uControl_ParaInfo.pbMeasure.Value = 100;
  318. uControl_ParaInfo.lblCompletedAmount.Text = "100%";
  319. }
  320. #endregion
  321. #region 窗体加载
  322. private void FormHOZMain_Load(object sender, EventArgs e)
  323. {
  324. //加载控件的点击事件
  325. this.Click += new EventHandler(FormHOZMain_Click);
  326. plFill.Click += new EventHandler(FormHOZMain_Click);
  327. plTop.Click += new EventHandler(FormHOZMain_Click);
  328. plLeft.Click += new EventHandler(FormHOZMain_Click);
  329. plLeftContent.Click += new EventHandler(FormHOZMain_Click);
  330. pbImage.Click += new EventHandler(FormHOZMain_Click);
  331. //加载窗口移动事件
  332. this.MouseDown += new MouseEventHandler(FormHOZMain_MouseDown);
  333. this.plTop.MouseDown += new MouseEventHandler(FormHOZMain_MouseDown);
  334. //新建
  335. NewCreate();
  336. //实例初始化窗体对象
  337. if (uControl_Init == null)
  338. {
  339. uControl_Init = new UControl_Init(this);
  340. uControl_Init.ReloadConfig();
  341. }
  342. }
  343. #endregion
  344. #region 创建切孔列表信息
  345. /// <summary>
  346. /// 创建切孔列表信息
  347. /// </summary>
  348. /// <param name="ListCutHole"></param>
  349. public void CreateCutHoleList(List<CutHole> ListCutHole)
  350. {
  351. //清空左侧Panel中的切孔控件
  352. ClearPanelControls();
  353. for (int i = ListCutHole.Count - 1; i >= 0; i--)
  354. {
  355. UControl_CutHole ucCutHole = new UControl_CutHole(this);
  356. ucCutHole.Dock = DockStyle.Top;
  357. ucCutHole.CutHoleName = ListCutHole[i].HoleName;
  358. //显示切孔参数信息
  359. if (ucCutHole.UControl_ParaInfo == null)
  360. {
  361. ucCutHole.UControl_ParaInfo = new UControl_ParaInfo(this);
  362. }
  363. plPrarInfo.Width = ucCutHole.UControl_ParaInfo.Width;
  364. plPrarInfo.Height = ucCutHole.UControl_ParaInfo.Height;
  365. //设置当前样品的参数信息
  366. string CutHoleName = ListCutHole[i].HoleName;
  367. ucCutHole.UControl_ParaInfo.Name = CutHoleName;
  368. ucCutHole.UControl_ParaInfo.CutHoleName = CutHoleName;
  369. ucCutHole.UControl_ParaInfo.Position = ListCutHole[i].Position;
  370. ucCutHole.UControl_ParaInfo.StartTime = ListCutHole[i].START.ToString();
  371. ucCutHole.UControl_ParaInfo.EndTime = ListCutHole[i].END.ToString();
  372. int state = (int)ListCutHole[i].STATE;
  373. ucCutHole.UControl_ParaInfo.State = state;
  374. ucCutHole.UControl_ParaInfo.IsSwitch = ListCutHole[i].SWITCH;
  375. ucCutHole.UControl_ParaInfo.ShowParaInfo();
  376. this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  377. plPrarInfo.Controls.Add(ucCutHole.UControl_ParaInfo);
  378. plLeftContent.Controls.Add(ucCutHole);
  379. ChangeCutHoleState(CutHoleName, state);
  380. }
  381. plPrarInfo.Visible = false;
  382. }
  383. #endregion
  384. #region 隐藏处理层
  385. //隐藏处理层
  386. private void FormHOZMain_Click(object sender, EventArgs e)
  387. {
  388. if (plPrarInfo.Visible)
  389. {
  390. plPrarInfo.Visible = false;
  391. }
  392. }
  393. #endregion
  394. #region 设置控件在线程过程中的编辑状态
  395. /// <summary>
  396. /// 设置控件在线程过程中的编辑状态
  397. /// </summary>
  398. /// <param name="cState"></param>
  399. public void SetWinControlMeasureState(bool cState)
  400. {
  401. pbNew.Enabled = cState;
  402. pbOpen.Enabled = cState;
  403. pbSave.Enabled = cState;
  404. pbInit.Enabled = cState;
  405. pbImportTemplateFile.Enabled = cState;
  406. //pbLog.Enabled = cState;
  407. pbStart.Enabled = cState;
  408. pbStop.Enabled = !cState;
  409. //设置切孔是否执行
  410. foreach (Control item in plPrarInfo.Controls)
  411. {
  412. if (item is UserControl)
  413. {
  414. UControl_ParaInfo ucParaInfo = (UControl_ParaInfo)item;
  415. ucParaInfo.CkIsSwitch.Enabled = cState;
  416. }
  417. }
  418. }
  419. #endregion
  420. #region 窗体中 线程开始 停止 最大化 最小化 关闭 按钮事件
  421. private void pbMin_MouseEnter(object sender, EventArgs e)
  422. {
  423. this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_2_;
  424. }
  425. private void pbMin_MouseLeave(object sender, EventArgs e)
  426. {
  427. this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_2_;
  428. }
  429. private void pbMax_MouseEnter(object sender, EventArgs e)
  430. {
  431. this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_2_;
  432. }
  433. private void pbMax_MouseLeave(object sender, EventArgs e)
  434. {
  435. this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_2_;
  436. }
  437. private void pbClose_MouseEnter(object sender, EventArgs e)
  438. {
  439. this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  440. }
  441. private void pbClose_MouseLeave(object sender, EventArgs e)
  442. {
  443. this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  444. }
  445. private void pbStart_MouseEnter(object sender, EventArgs e)
  446. {
  447. //this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.StartMove;
  448. }
  449. private void pbStart_MouseLeave(object sender, EventArgs e)
  450. {
  451. //this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.Start_3_;
  452. }
  453. private void pbStop_MouseEnter(object sender, EventArgs e)
  454. {
  455. //this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.StopMove;
  456. }
  457. private void pbStop_MouseLeave(object sender, EventArgs e)
  458. {
  459. //this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.Stop;
  460. }
  461. private void pbClose_Click(object sender, EventArgs e)
  462. {
  463. try
  464. {
  465. if (m_Ms != null)
  466. {
  467. if (m_BackgroundWorker.IsBusy)
  468. {
  469. if (MessageBox.Show("当前测量正在运行,是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  470. {
  471. //线程停止变量
  472. m_Ms.key_stop = true;
  473. IsClose = true;
  474. lblStateMessage.Text = "正在关闭窗体...请等待";
  475. pbClose.Enabled = false;
  476. ControlFlicker = false;
  477. }
  478. return;
  479. }
  480. }
  481. if (MessageBox.Show("是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  482. {
  483. m_MeasureFile.Save();
  484. this.Close();
  485. }
  486. }
  487. catch (Exception ex)
  488. {
  489. LogManager.LogError(ex.Message);
  490. }
  491. }
  492. private void pbMin_Click(object sender, EventArgs e)
  493. {
  494. this.WindowState = FormWindowState.Minimized;
  495. }
  496. private void pbMax_Click(object sender, EventArgs e)
  497. {
  498. if (this.WindowState == FormWindowState.Maximized)
  499. {
  500. this.WindowState = FormWindowState.Normal;
  501. }
  502. else
  503. {
  504. this.WindowState = FormWindowState.Maximized;
  505. }
  506. //窗体据中
  507. this.StartPosition = FormStartPosition.CenterScreen;
  508. }
  509. #endregion
  510. #region 新建、保存、打开、初始化、导入配置、查看日志
  511. private void pbNew_Click(object sender, EventArgs e)
  512. {
  513. NewCreate();
  514. }
  515. private void NewCreate()
  516. {
  517. m_MeasureFile = new MeasureFile();
  518. if (!m_MeasureFile.New())
  519. {
  520. return;
  521. }
  522. else
  523. {
  524. //清空内容容器中的控件
  525. ClearPanelControls();
  526. }
  527. //实例初始化窗体对象
  528. if (uControl_Init == null)
  529. {
  530. uControl_Init = new UControl_Init(this);
  531. uControl_Init.ReloadConfig();
  532. }
  533. m_MeasureFile.MParam = uControl_Init.GetMeasureParam();
  534. }
  535. private void pbSave_Click(object sender, EventArgs e)
  536. {
  537. if (m_MeasureFile == null)
  538. {
  539. MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  540. }
  541. else
  542. {
  543. //保存测量文件
  544. if (m_MeasureFile.SaveAs())
  545. {
  546. //获取测量文件所在路径
  547. string savePath = m_MeasureFile.FilePath;
  548. //数据库名称
  549. string dbFileName = "MeasureFile.db";
  550. //要复制的文件路径
  551. string pLocalFilePath = Application.StartupPath +"\\"+dbFileName;
  552. string pSaveFilePath = savePath + "\\" + dbFileName;//指定存储的路径
  553. if (File.Exists(pLocalFilePath))//必须判断要复制的文件是否存在
  554. {
  555. //三个参数分别是源文件路径,存储路径,若存储路径有相同文件是否替换
  556. File.Copy(pLocalFilePath, pSaveFilePath, true);
  557. }
  558. //将初始化中的参数,配置到测量参数中
  559. m_MeasureFile.MParam = uControl_Init.GetMeasureParamInfo();
  560. //设置已保存状态
  561. IsSave = true;
  562. }
  563. }
  564. }
  565. private void pbOpen_Click(object sender, EventArgs e)
  566. {
  567. try
  568. {
  569. //打开默认路径
  570. OpenFileDialog openFileDialog = new OpenFileDialog();
  571. //设置筛选文件格式
  572. openFileDialog.Filter = "测量文件(*.msf)|*.msf";
  573. if (openFileDialog.ShowDialog() == DialogResult.OK)
  574. {
  575. //读取文件
  576. string measureFileNamePath = openFileDialog.FileName;
  577. m_MeasureFile.FileName = measureFileNamePath;
  578. m_MeasureFile.Open();
  579. List<CutHole> ListCutHole = m_MeasureFile.ListCutHole;
  580. //文件路径
  581. string CutHoleFilePath = m_MeasureFile.CutHoleFilePath;
  582. CreateCutHoleList(ListCutHole);
  583. ////保存测量文件
  584. //m_MeasureFile.Save();
  585. //设置已保存状态
  586. IsSave = true;
  587. }
  588. }
  589. catch (Exception ex)
  590. {
  591. LogManager.LogError(ex.Message);
  592. }
  593. }
  594. private void pbInit_Click(object sender, EventArgs e)
  595. {
  596. if (uControl_Init == null)
  597. {
  598. uControl_Init = new UControl_Init(this);
  599. uControl_Init.ReloadConfig();
  600. }
  601. if (m_FormInit == null)
  602. {
  603. m_FormInit = new FormMove();
  604. }
  605. m_FormInit.StartPosition = FormStartPosition.CenterScreen;
  606. m_FormInit.FormBorderStyle = FormBorderStyle.None;
  607. m_FormInit.Width = uControl_Init.Width + 2;
  608. m_FormInit.Height = uControl_Init.Height + 2;
  609. if (m_FormInit.Controls.Count == 0)
  610. {
  611. uControl_Init.Location = new Point(1,1);
  612. m_FormInit.Controls.Add(uControl_Init);
  613. }
  614. m_FormInit.ShowDialog();
  615. }
  616. private void pictureBox1_Click(object sender, EventArgs e)
  617. {
  618. //if (UControl_ZoomIn == null)
  619. //{
  620. // UControl_ZoomIn = new UControl_ZoomIn(this);
  621. // UControl_ZoomIn.ReloadConfig();
  622. //}
  623. //if (m_FormZoomIn == null)
  624. //{
  625. // m_FormZoomIn = new FormZoomIn();
  626. //}
  627. //m_FormZoomIn.StartPosition = FormStartPosition.CenterScreen;
  628. //m_FormZoomIn.FormBorderStyle = FormBorderStyle.None;
  629. //m_FormZoomIn.Width = UControl_ZoomIn.Width + 4;
  630. //m_FormZoomIn.Height = UControl_ZoomIn.Height + 4;
  631. //if (m_FormZoomIn.Controls.Count == 0)
  632. //{
  633. // UControl_ZoomIn.Location = new Point(2, 2);
  634. // m_FormZoomIn.Controls.Add(UControl_ZoomIn);
  635. //}
  636. //m_FormZoomIn.ShowDialog();
  637. }
  638. private void pbImportTemplateFile_Click(object sender, EventArgs e)
  639. {
  640. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  641. string m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString();
  642. //判断保存的路径是否存在
  643. if (!Directory.Exists(m_TemplateFilePath))
  644. {
  645. ////创建路径
  646. //Directory.CreateDirectory(m_TemplateFilePath);
  647. FolderBrowserDialog dialog = new FolderBrowserDialog();
  648. dialog.Description = "请选择文件路径";
  649. //dialog.RootFolder = Environment.SpecialFolder.Programs;
  650. if (dialog.ShowDialog() == DialogResult.OK)
  651. {
  652. m_TemplateFilePath = dialog.SelectedPath;
  653. config.AppSettings.Settings["TemplateFilePath"].Value = m_TemplateFilePath;
  654. config.Save(ConfigurationSaveMode.Modified);
  655. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  656. }
  657. }
  658. //打开默认路径
  659. OpenFileDialog openFileDialog = new OpenFileDialog();
  660. //设置默认打开路径(绝对路径)
  661. openFileDialog.InitialDirectory = m_TemplateFilePath;
  662. openFileDialog.Filter = "样品参数文件|*.cfg";
  663. if (openFileDialog.ShowDialog() == DialogResult.OK)
  664. {
  665. if (uControl_Init == null)
  666. {
  667. uControl_Init = new UControl_Init(this);
  668. }
  669. //设置选择的模板文件
  670. uControl_Init.ReadConfigPath = openFileDialog.FileName;
  671. //获取文件
  672. uControl_Init.ReadConfigInfo();
  673. }
  674. }
  675. private void pbLog_Click(object sender, EventArgs e)
  676. {
  677. m_FormLog = new Form();
  678. m_FormLog.StartPosition = FormStartPosition.CenterScreen;
  679. if (ucLog == null)
  680. {
  681. ucLog = new UControl_Log();
  682. }
  683. m_FormLog.FormBorderStyle = FormBorderStyle.None;
  684. m_FormLog.Width = ucLog.Width;
  685. m_FormLog.Height = ucLog.Height;
  686. ucLog.Name = "UControl_Log";
  687. //获取日志信息
  688. if (listmsg.Items.Count>0)
  689. {
  690. string[] strLog = new string[listmsg.Items.Count];
  691. for (int i = 0; i < listmsg.Items.Count; i++)
  692. {
  693. //赋值给数组
  694. strLog[i] = listmsg.Items[i].ToString();
  695. }
  696. ucLog.ShowProcessLogInfo(strLog);
  697. }
  698. m_FormLog.Controls.Add(ucLog);
  699. m_FormLog.ShowDialog();
  700. }
  701. //显示日志
  702. private void AddLogListInfo(ThreadStatusEventArgs e)
  703. {
  704. if (m_FormLog != null)
  705. {
  706. foreach (Control item in m_FormLog.Controls)
  707. {
  708. if (item is UserControl)
  709. {
  710. if (item.Name == "UControl_Log")
  711. {
  712. ucLog = (UControl_Log)item;
  713. //获取日志信息
  714. if (listmsg.Items.Count > 0)
  715. {
  716. string[] strLog = new string[listmsg.Items.Count];
  717. for (int i = 0; i < listmsg.Items.Count; i++)
  718. {
  719. //赋值给数组
  720. strLog[i] = listmsg.Items[i].ToString();
  721. }
  722. ucLog.ShowProcessLogInfo(strLog);
  723. }
  724. }
  725. }
  726. }
  727. }
  728. }
  729. #endregion
  730. #region 修改切孔状态
  731. /// <summary>
  732. /// 修改切孔状态
  733. /// </summary>
  734. /// <param name="cutHoleCode"></param>
  735. /// <param name="States"></param>
  736. public void ChangeCutHoleState(string CutHoleName, int States)
  737. {
  738. foreach (Control item in plLeftContent.Controls)
  739. {
  740. if (item is UserControl)
  741. {
  742. UControl_CutHole cutHole = (UControl_CutHole)item;
  743. if (cutHole.CutHoleName == CutHoleName)
  744. {
  745. Button btnCutHole = (Button)cutHole.Controls.Find("btnCutHole", false)[0];
  746. switch (States)
  747. {
  748. //运行中
  749. case (int)ThreadState.InProcess:
  750. //btnCutHole.BackColor = Color.Yellow;
  751. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Yellow_2_;
  752. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  753. ChangeCutHoleMeasureState(CutHoleName, States);
  754. ControlFlicker = true;
  755. break;
  756. //等待
  757. case (int)ThreadState.Waiting:
  758. //btnCutHole.BackColor = Color.Yellow;
  759. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Yellow_2_;
  760. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  761. ChangeCutHoleMeasureState(CutHoleName, States);
  762. break;
  763. //准备
  764. case (int)ThreadState.Ready:
  765. //btnCutHole.BackColor = Color.White;
  766. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Gray_2_;
  767. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  768. ChangeCutHoleMeasureState(CutHoleName, States);
  769. break;
  770. //失败
  771. case (int)ThreadState.Failed:
  772. //btnCutHole.BackColor = Color.Red;
  773. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Red_2_;
  774. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  775. ChangeCutHoleMeasureState(CutHoleName, States);
  776. ControlFlicker = false;
  777. break;
  778. //完成
  779. case (int)ThreadState.Success:
  780. //btnCutHole.BackColor = Color.GreenYellow;
  781. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Green_2_;
  782. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  783. //修改切孔状态
  784. ChangeCutHoleMeasureState(CutHoleName, States);
  785. ControlFlicker = false;
  786. break;
  787. }
  788. break;
  789. }
  790. }
  791. }
  792. }
  793. #endregion
  794. #region 修改切孔状态
  795. public void ChangeCutHoleMeasureState(string CutHoleName, int States)
  796. {
  797. if (plPrarInfo.Controls.Count > 0)
  798. {
  799. foreach (Control item in plPrarInfo.Controls)
  800. {
  801. if (item is UserControl)
  802. {
  803. if (item.Name == CutHoleName)
  804. {
  805. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  806. //获取切孔列表
  807. List<CutHole> aCutHole = m_MeasureFile.ListCutHole;
  808. foreach (CutHole cutHoleItem in aCutHole)
  809. {
  810. if (cutHoleItem.HoleName == CutHoleName)
  811. {
  812. //设置开始时间与结束时间
  813. uControl_ParaInfo.StartTime = cutHoleItem.START.ToString();
  814. uControl_ParaInfo.EndTime = cutHoleItem.END.ToString();
  815. uControl_ParaInfo.ShowTime();
  816. break;
  817. }
  818. }
  819. switch (States)
  820. {
  821. //准备
  822. case (int)ThreadState.Ready:
  823. //修改切孔状态
  824. uControl_ParaInfo.lblShowState.Text = "准备";
  825. break;
  826. //等待
  827. case (int)ThreadState.Waiting:
  828. //修改切孔状态
  829. uControl_ParaInfo.lblShowState.Text = "等待";
  830. break;
  831. //进行中
  832. case (int)ThreadState.InProcess:
  833. //修改切孔状态
  834. uControl_ParaInfo.lblShowState.Text = "进行中";
  835. break;
  836. //完成
  837. case (int)ThreadState.Success:
  838. //修改切孔状态
  839. uControl_ParaInfo.lblShowState.Text = "完成";
  840. break;
  841. //失败
  842. case (int)ThreadState.Failed:
  843. uControl_ParaInfo.lblShowState.Text = "失败";
  844. uControl_ParaInfo.pbMeasure.Value = 100;
  845. uControl_ParaInfo.lblCompletedAmount.Text = "100%";
  846. break;
  847. }
  848. break;
  849. }
  850. }
  851. }
  852. }
  853. }
  854. #endregion
  855. #region 拖动无窗体的控件
  856. [DllImport("user32.dll")]//拖动无窗体的控件
  857. public static extern bool ReleaseCapture();
  858. [DllImport("user32.dll")]
  859. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  860. public const int WM_SYSCOMMAND = 0x0112;
  861. public const int SC_MOVE = 0xF010;
  862. public const int HTCAPTION = 0x0002;
  863. private void FormHOZMain_MouseDown(object sender, MouseEventArgs e)
  864. {
  865. if (this.WindowState == FormWindowState.Normal)
  866. {
  867. //拖动窗体
  868. ReleaseCapture();
  869. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  870. }
  871. }
  872. #endregion
  873. #region 开始、结束线程事件
  874. private void pbStart_Click(object sender, EventArgs e)
  875. {
  876. if (plLeftContent.Controls.Count==0)
  877. {
  878. MessageBox.Show("请添加切孔信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  879. return;
  880. }
  881. if (IsSave)
  882. {
  883. if (m_BackgroundWorker.IsBusy)
  884. {
  885. MessageBox.Show("线程已经运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  886. return;
  887. }
  888. if (MessageBox.Show("是否开始测量!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  889. {
  890. LogManager.AddHardwareLog("开始", true);
  891. m_BackgroundWorker.RunWorkerAsync(this);
  892. pbStop.Visible = true;
  893. pbStart.Visible = false;
  894. }
  895. }
  896. else
  897. {
  898. MessageBox.Show("请保存当前测量文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  899. return;
  900. }
  901. }
  902. private void pbStop_Click(object sender, EventArgs e)
  903. {
  904. if (m_Ms != null)
  905. {
  906. if (MessageBox.Show("是否停止当前测量?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.Yes)
  907. {
  908. ControlFlicker = false;
  909. //线程停止变量
  910. m_Ms.key_stop = true;
  911. }
  912. }
  913. }
  914. #endregion
  915. #region 清空内容容器中的控件
  916. /// <summary>
  917. /// 清空内容容器中的控件
  918. /// </summary>
  919. private void ClearPanelControls()
  920. {
  921. //清空内容容器中的控件
  922. plLeftContent.Controls.Clear();
  923. plPrarInfo.Controls.Clear();
  924. }
  925. /// <summary>
  926. /// 清空日志控件内容
  927. /// </summary>
  928. private void ClearContrlsContent()
  929. {
  930. try
  931. {
  932. if (ucLog != null)
  933. {
  934. if (ucLog.dgvLog != null)
  935. {
  936. if (ucLog.dgvLog.Rows.Count > 0)
  937. {
  938. ucLog.dgvLog.Rows.Clear();
  939. }
  940. }
  941. }
  942. if (listmsg != null)
  943. {
  944. if (listmsg.Items.Count > 0)
  945. {
  946. listmsg.Items.Clear();
  947. }
  948. }
  949. }
  950. catch (Exception ex)
  951. {
  952. LogManager.LogError(ex.Message);
  953. }
  954. }
  955. #endregion
  956. #region 测试修改切孔中流程状态
  957. private void button1_Click(object sender, EventArgs e)
  958. {
  959. if (plPrarInfo.Controls.Count > 0)
  960. {
  961. string name = textBox1.Text;
  962. string code = textBox2.Text;
  963. bool state = Convert.ToBoolean(comboBox1.Text);
  964. foreach (Control item in plPrarInfo.Controls)
  965. {
  966. if (item is UserControl)
  967. {
  968. if (item.Name == name)
  969. {
  970. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  971. TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
  972. foreach (TimeLineItem tlItem in ParaItem)
  973. {
  974. if (tlItem.Code == code)
  975. {
  976. tlItem.State = Convert.ToInt32(state);
  977. break;
  978. }
  979. }
  980. uControl_ParaInfo.TimeLineInvalidate();
  981. break;
  982. }
  983. }
  984. }
  985. }
  986. }
  987. #endregion
  988. private void FormHOZMain_Resize(object sender, EventArgs e)
  989. {
  990. plMain.Left = 2;
  991. plMain.Top = 2;
  992. plMain.Width = this.Width - 4;
  993. plMain.Height = this.Height - 4;
  994. plFill.Width = plMain.Width - plLeft.Width - 4;
  995. plFill.Height = plMain.Height - plTop.Height - 4;
  996. plFill.Left = plLeft.Width + 4;
  997. plFill.Top = plTop.Height + 4;
  998. if(this.WindowState!= FormWindowState.Maximized)
  999. {
  1000. plPrarInfo.Height = 505;
  1001. foreach (Control item in plPrarInfo.Controls)
  1002. {
  1003. if (item is UserControl)
  1004. {
  1005. if(item.Height>505)
  1006. {
  1007. item.Height = 505;
  1008. }
  1009. }
  1010. }
  1011. }
  1012. }
  1013. private void FormHOZMain_Paint(object sender, PaintEventArgs e)
  1014. {
  1015. }
  1016. }
  1017. }