FormHOZMain.cs 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  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. m_Ms.InitMeas(m_MeasureFile);
  196. //注册事件
  197. m_Ms.SendThreadStatus += new ThreadStatusHandler(displayMessage);
  198. //注册事件
  199. m_Ms.SendCutHolesStatus += new CutHolesStatusHandler(displayCutHoleMessage);
  200. //设置控件操作
  201. SetWinControlMeasureState(false);
  202. //自动测量的全过程
  203. m_Ms.DoMeasure();
  204. }
  205. catch (Exception ex)
  206. {
  207. LogManager.AddHardwareLog(ex.ToString(),true);
  208. }
  209. }
  210. public void displayMessage(object sender, ThreadStatusEventArgs e)
  211. {
  212. //主界面显示内容
  213. this.BeginInvoke((Action)delegate
  214. {
  215. this.listmsg.Items.Add(e.HoleName +"_" + e.Time.ToString() + "_"+ e.Message + "_" + e.State );
  216. //显示流程中对应编号的内容
  217. MeasureMsgManage.ShowMsgContent(this, e);
  218. AddLogListInfo(e);
  219. });
  220. }
  221. public void displayCutHoleMessage(object sender, CutHolesStatusEventArgs e)
  222. {
  223. //主界面显示内容
  224. this.BeginInvoke((Action)delegate
  225. {
  226. //修改切孔状态
  227. ChangeCutHoleState(e.HoleName.ToString(), Convert.ToInt32(e.State));
  228. });
  229. }
  230. void UpdateProgress(object sender, ProgressChangedEventArgs e)
  231. {
  232. }
  233. void CompletedWork(object sender, RunWorkerCompletedEventArgs e)
  234. {
  235. ControlFlicker = false;
  236. //设置控件操作
  237. MessageBox.Show("测量已完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  238. SetWinControlMeasureState(true);
  239. pbStop.Visible = false;
  240. pbStart.Visible = true;
  241. //UControl_ParaInfo uControl_ParaInfo=new UControl_ParaInfo()
  242. UControl_ParaInfo uControl_ParaInfo = new UControl_ParaInfo(this);
  243. uControl_ParaInfo.pbMeasure.Value = 100;
  244. uControl_ParaInfo.lblCompletedAmount.Text = "100%";
  245. }
  246. #endregion
  247. #region 窗体加载
  248. private void FormHOZMain_Load(object sender, EventArgs e)
  249. {
  250. //加载控件的点击事件
  251. this.Click += new EventHandler(FormHOZMain_Click);
  252. plFill.Click += new EventHandler(FormHOZMain_Click);
  253. plTop.Click += new EventHandler(FormHOZMain_Click);
  254. plLeft.Click += new EventHandler(FormHOZMain_Click);
  255. plLeftContent.Click += new EventHandler(FormHOZMain_Click);
  256. pbImage.Click += new EventHandler(FormHOZMain_Click);
  257. //加载窗口移动事件
  258. this.MouseDown += new MouseEventHandler(FormHOZMain_MouseDown);
  259. this.plTop.MouseDown += new MouseEventHandler(FormHOZMain_MouseDown);
  260. //新建
  261. NewCreate();
  262. //实例初始化窗体对象
  263. if (uControl_Init == null)
  264. {
  265. uControl_Init = new UControl_Init(this);
  266. uControl_Init.ReloadConfig();
  267. }
  268. }
  269. #endregion
  270. #region 创建切孔列表信息
  271. /// <summary>
  272. /// 创建切孔列表信息
  273. /// </summary>
  274. /// <param name="ListCutHole"></param>
  275. public void CreateCutHoleList(List<CutHole> ListCutHole)
  276. {
  277. //清空左侧Panel中的切孔控件
  278. ClearPanelControls();
  279. for (int i = ListCutHole.Count - 1; i >= 0; i--)
  280. {
  281. UControl_CutHole ucCutHole = new UControl_CutHole(this);
  282. ucCutHole.Dock = DockStyle.Top;
  283. ucCutHole.CutHoleName = ListCutHole[i].HoleName;
  284. //显示切孔参数信息
  285. if (ucCutHole.UControl_ParaInfo == null)
  286. {
  287. ucCutHole.UControl_ParaInfo = new UControl_ParaInfo(this);
  288. }
  289. plPrarInfo.Width = ucCutHole.UControl_ParaInfo.Width;
  290. plPrarInfo.Height = ucCutHole.UControl_ParaInfo.Height;
  291. //设置当前样品的参数信息
  292. string CutHoleName = ListCutHole[i].HoleName;
  293. ucCutHole.UControl_ParaInfo.Name = CutHoleName;
  294. ucCutHole.UControl_ParaInfo.CutHoleName = CutHoleName;
  295. ucCutHole.UControl_ParaInfo.Position = ListCutHole[i].Position;
  296. ucCutHole.UControl_ParaInfo.StartTime = ListCutHole[i].START.ToString();
  297. ucCutHole.UControl_ParaInfo.EndTime = ListCutHole[i].END.ToString();
  298. int state = (int)ListCutHole[i].STATE;
  299. ucCutHole.UControl_ParaInfo.State = state;
  300. ucCutHole.UControl_ParaInfo.IsSwitch = ListCutHole[i].SWITCH;
  301. ucCutHole.UControl_ParaInfo.ShowParaInfo();
  302. this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  303. plPrarInfo.Controls.Add(ucCutHole.UControl_ParaInfo);
  304. plLeftContent.Controls.Add(ucCutHole);
  305. ChangeCutHoleState(CutHoleName, state);
  306. }
  307. plPrarInfo.Visible = false;
  308. }
  309. #endregion
  310. #region 隐藏处理层
  311. //隐藏处理层
  312. private void FormHOZMain_Click(object sender, EventArgs e)
  313. {
  314. if (plPrarInfo.Visible)
  315. {
  316. plPrarInfo.Visible = false;
  317. }
  318. }
  319. #endregion
  320. #region 设置控件在线程过程中的编辑状态
  321. /// <summary>
  322. /// 设置控件在线程过程中的编辑状态
  323. /// </summary>
  324. /// <param name="cState"></param>
  325. public void SetWinControlMeasureState(bool cState)
  326. {
  327. pbNew.Enabled = cState;
  328. pbOpen.Enabled = cState;
  329. pbSave.Enabled = cState;
  330. pbInit.Enabled = cState;
  331. pbImportTemplateFile.Enabled = cState;
  332. //pbLog.Enabled = cState;
  333. pbStart.Enabled = cState;
  334. pbStop.Enabled = !cState;
  335. //设置切孔是否执行
  336. foreach (Control item in plPrarInfo.Controls)
  337. {
  338. if (item is UserControl)
  339. {
  340. UControl_ParaInfo ucParaInfo = (UControl_ParaInfo)item;
  341. ucParaInfo.CkIsSwitch.Enabled = cState;
  342. }
  343. }
  344. }
  345. #endregion
  346. #region 窗体中 线程开始 停止 最大化 最小化 关闭 按钮事件
  347. private void pbMin_MouseEnter(object sender, EventArgs e)
  348. {
  349. this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_2_;
  350. }
  351. private void pbMin_MouseLeave(object sender, EventArgs e)
  352. {
  353. this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_2_;
  354. }
  355. private void pbMax_MouseEnter(object sender, EventArgs e)
  356. {
  357. this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_2_;
  358. }
  359. private void pbMax_MouseLeave(object sender, EventArgs e)
  360. {
  361. this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_2_;
  362. }
  363. private void pbClose_MouseEnter(object sender, EventArgs e)
  364. {
  365. this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  366. }
  367. private void pbClose_MouseLeave(object sender, EventArgs e)
  368. {
  369. this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  370. }
  371. private void pbStart_MouseEnter(object sender, EventArgs e)
  372. {
  373. //this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.StartMove;
  374. }
  375. private void pbStart_MouseLeave(object sender, EventArgs e)
  376. {
  377. //this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.Start_3_;
  378. }
  379. private void pbStop_MouseEnter(object sender, EventArgs e)
  380. {
  381. //this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.StopMove;
  382. }
  383. private void pbStop_MouseLeave(object sender, EventArgs e)
  384. {
  385. //this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.Stop;
  386. }
  387. private void pbClose_Click(object sender, EventArgs e)
  388. {
  389. try
  390. {
  391. if (m_Ms != null)
  392. {
  393. if (m_BackgroundWorker.IsBusy)
  394. {
  395. if (MessageBox.Show("当前测量正在运行,是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  396. {
  397. //线程停止变量
  398. m_Ms.key_stop = true;
  399. IsClose = true;
  400. lblStateMessage.Text = "正在关闭窗体...请等待";
  401. pbClose.Enabled = false;
  402. ControlFlicker = false;
  403. }
  404. return;
  405. }
  406. }
  407. if (MessageBox.Show("是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  408. {
  409. m_MeasureFile.Save();
  410. this.Close();
  411. }
  412. }
  413. catch (Exception ex)
  414. {
  415. LogManager.LogError(ex.Message);
  416. }
  417. }
  418. private void pbMin_Click(object sender, EventArgs e)
  419. {
  420. this.WindowState = FormWindowState.Minimized;
  421. }
  422. private void pbMax_Click(object sender, EventArgs e)
  423. {
  424. if (this.WindowState == FormWindowState.Maximized)
  425. {
  426. this.WindowState = FormWindowState.Normal;
  427. }
  428. else
  429. {
  430. this.WindowState = FormWindowState.Maximized;
  431. }
  432. //窗体据中
  433. this.StartPosition = FormStartPosition.CenterScreen;
  434. }
  435. #endregion
  436. #region 新建、保存、打开、初始化、导入配置、查看日志
  437. private void pbNew_Click(object sender, EventArgs e)
  438. {
  439. NewCreate();
  440. }
  441. private void NewCreate()
  442. {
  443. m_MeasureFile = new MeasureFile();
  444. if (!m_MeasureFile.New())
  445. {
  446. return;
  447. }
  448. else
  449. {
  450. //清空内容容器中的控件
  451. ClearPanelControls();
  452. }
  453. //实例初始化窗体对象
  454. if (uControl_Init == null)
  455. {
  456. uControl_Init = new UControl_Init(this);
  457. uControl_Init.ReloadConfig();
  458. }
  459. m_MeasureFile.MParam = uControl_Init.GetMeasureParam();
  460. }
  461. private void pbSave_Click(object sender, EventArgs e)
  462. {
  463. if (m_MeasureFile == null)
  464. {
  465. MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  466. }
  467. else
  468. {
  469. //保存测量文件
  470. if (m_MeasureFile.SaveAs())
  471. {
  472. //获取测量文件所在路径
  473. string savePath = m_MeasureFile.FilePath;
  474. //数据库名称
  475. string dbFileName = "MeasureFile.db";
  476. //要复制的文件路径
  477. string pLocalFilePath = Application.StartupPath +"\\"+dbFileName;
  478. string pSaveFilePath = savePath + "\\" + dbFileName;//指定存储的路径
  479. if (File.Exists(pLocalFilePath))//必须判断要复制的文件是否存在
  480. {
  481. //三个参数分别是源文件路径,存储路径,若存储路径有相同文件是否替换
  482. File.Copy(pLocalFilePath, pSaveFilePath, true);
  483. }
  484. //将初始化中的参数,配置到测量参数中
  485. m_MeasureFile.MParam = uControl_Init.GetMeasureParamInfo();
  486. //设置已保存状态
  487. IsSave = true;
  488. }
  489. }
  490. }
  491. private void pbOpen_Click(object sender, EventArgs e)
  492. {
  493. try
  494. {
  495. //打开默认路径
  496. OpenFileDialog openFileDialog = new OpenFileDialog();
  497. //设置筛选文件格式
  498. openFileDialog.Filter = "测量文件(*.msf)|*.msf";
  499. if (openFileDialog.ShowDialog() == DialogResult.OK)
  500. {
  501. //读取文件
  502. string measureFileNamePath = openFileDialog.FileName;
  503. m_MeasureFile.FileName = measureFileNamePath;
  504. m_MeasureFile.Open();
  505. List<CutHole> ListCutHole = m_MeasureFile.ListCutHole;
  506. //文件路径
  507. string CutHoleFilePath = m_MeasureFile.CutHoleFilePath;
  508. CreateCutHoleList(ListCutHole);
  509. ////保存测量文件
  510. //m_MeasureFile.Save();
  511. //设置已保存状态
  512. IsSave = true;
  513. }
  514. }
  515. catch (Exception ex)
  516. {
  517. LogManager.LogError(ex.Message);
  518. }
  519. }
  520. private void pbInit_Click(object sender, EventArgs e)
  521. {
  522. if (uControl_Init == null)
  523. {
  524. uControl_Init = new UControl_Init(this);
  525. uControl_Init.ReloadConfig();
  526. }
  527. if (m_FormInit == null)
  528. {
  529. m_FormInit = new FormMove();
  530. }
  531. m_FormInit.StartPosition = FormStartPosition.CenterScreen;
  532. m_FormInit.FormBorderStyle = FormBorderStyle.None;
  533. m_FormInit.Width = uControl_Init.Width + 2;
  534. m_FormInit.Height = uControl_Init.Height + 2;
  535. if (m_FormInit.Controls.Count == 0)
  536. {
  537. uControl_Init.Location = new Point(1,1);
  538. m_FormInit.Controls.Add(uControl_Init);
  539. }
  540. m_FormInit.ShowDialog();
  541. }
  542. private void pictureBox1_Click(object sender, EventArgs e)
  543. {
  544. //if (UControl_ZoomIn == null)
  545. //{
  546. // UControl_ZoomIn = new UControl_ZoomIn(this);
  547. // UControl_ZoomIn.ReloadConfig();
  548. //}
  549. //if (m_FormZoomIn == null)
  550. //{
  551. // m_FormZoomIn = new FormZoomIn();
  552. //}
  553. //m_FormZoomIn.StartPosition = FormStartPosition.CenterScreen;
  554. //m_FormZoomIn.FormBorderStyle = FormBorderStyle.None;
  555. //m_FormZoomIn.Width = UControl_ZoomIn.Width + 4;
  556. //m_FormZoomIn.Height = UControl_ZoomIn.Height + 4;
  557. //if (m_FormZoomIn.Controls.Count == 0)
  558. //{
  559. // UControl_ZoomIn.Location = new Point(2, 2);
  560. // m_FormZoomIn.Controls.Add(UControl_ZoomIn);
  561. //}
  562. //m_FormZoomIn.ShowDialog();
  563. }
  564. private void pbImportTemplateFile_Click(object sender, EventArgs e)
  565. {
  566. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  567. string m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString();
  568. //判断保存的路径是否存在
  569. if (!Directory.Exists(m_TemplateFilePath))
  570. {
  571. ////创建路径
  572. //Directory.CreateDirectory(m_TemplateFilePath);
  573. FolderBrowserDialog dialog = new FolderBrowserDialog();
  574. dialog.Description = "请选择文件路径";
  575. //dialog.RootFolder = Environment.SpecialFolder.Programs;
  576. if (dialog.ShowDialog() == DialogResult.OK)
  577. {
  578. m_TemplateFilePath = dialog.SelectedPath;
  579. config.AppSettings.Settings["TemplateFilePath"].Value = m_TemplateFilePath;
  580. config.Save(ConfigurationSaveMode.Modified);
  581. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  582. }
  583. }
  584. //打开默认路径
  585. OpenFileDialog openFileDialog = new OpenFileDialog();
  586. //设置默认打开路径(绝对路径)
  587. openFileDialog.InitialDirectory = m_TemplateFilePath;
  588. openFileDialog.Filter = "样品参数文件|*.cfg";
  589. if (openFileDialog.ShowDialog() == DialogResult.OK)
  590. {
  591. if (uControl_Init == null)
  592. {
  593. uControl_Init = new UControl_Init(this);
  594. }
  595. //设置选择的模板文件
  596. uControl_Init.ReadConfigPath = openFileDialog.FileName;
  597. //获取文件
  598. uControl_Init.ReadConfigInfo();
  599. }
  600. }
  601. private void pbLog_Click(object sender, EventArgs e)
  602. {
  603. m_FormLog = new Form();
  604. m_FormLog.StartPosition = FormStartPosition.CenterScreen;
  605. if (ucLog == null)
  606. {
  607. ucLog = new UControl_Log();
  608. }
  609. m_FormLog.FormBorderStyle = FormBorderStyle.None;
  610. m_FormLog.Width = ucLog.Width;
  611. m_FormLog.Height = ucLog.Height;
  612. ucLog.Name = "UControl_Log";
  613. //获取日志信息
  614. if (listmsg.Items.Count>0)
  615. {
  616. string[] strLog = new string[listmsg.Items.Count];
  617. for (int i = 0; i < listmsg.Items.Count; i++)
  618. {
  619. //赋值给数组
  620. strLog[i] = listmsg.Items[i].ToString();
  621. }
  622. ucLog.ShowProcessLogInfo(strLog);
  623. }
  624. m_FormLog.Controls.Add(ucLog);
  625. m_FormLog.ShowDialog();
  626. }
  627. //显示日志
  628. private void AddLogListInfo(ThreadStatusEventArgs e)
  629. {
  630. if (m_FormLog != null)
  631. {
  632. foreach (Control item in m_FormLog.Controls)
  633. {
  634. if (item is UserControl)
  635. {
  636. if (item.Name == "UControl_Log")
  637. {
  638. ucLog = (UControl_Log)item;
  639. //获取日志信息
  640. if (listmsg.Items.Count > 0)
  641. {
  642. string[] strLog = new string[listmsg.Items.Count];
  643. for (int i = 0; i < listmsg.Items.Count; i++)
  644. {
  645. //赋值给数组
  646. strLog[i] = listmsg.Items[i].ToString();
  647. }
  648. ucLog.ShowProcessLogInfo(strLog);
  649. }
  650. }
  651. }
  652. }
  653. }
  654. }
  655. #endregion
  656. #region 修改切孔状态
  657. /// <summary>
  658. /// 修改切孔状态
  659. /// </summary>
  660. /// <param name="cutHoleCode"></param>
  661. /// <param name="States"></param>
  662. public void ChangeCutHoleState(string CutHoleName, int States)
  663. {
  664. foreach (Control item in plLeftContent.Controls)
  665. {
  666. if (item is UserControl)
  667. {
  668. UControl_CutHole cutHole = (UControl_CutHole)item;
  669. if (cutHole.CutHoleName == CutHoleName)
  670. {
  671. Button btnCutHole = (Button)cutHole.Controls.Find("btnCutHole", false)[0];
  672. switch (States)
  673. {
  674. //运行中
  675. case (int)ThreadState.InProcess:
  676. //btnCutHole.BackColor = Color.Yellow;
  677. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Yellow_2_;
  678. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  679. ChangeCutHoleMeasureState(CutHoleName, States);
  680. ControlFlicker = true;
  681. break;
  682. //等待
  683. case (int)ThreadState.Waiting:
  684. //btnCutHole.BackColor = Color.Yellow;
  685. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Yellow_2_;
  686. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  687. ChangeCutHoleMeasureState(CutHoleName, States);
  688. break;
  689. //准备
  690. case (int)ThreadState.Ready:
  691. //btnCutHole.BackColor = Color.White;
  692. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Gray_2_;
  693. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  694. ChangeCutHoleMeasureState(CutHoleName, States);
  695. break;
  696. //失败
  697. case (int)ThreadState.Failed:
  698. //btnCutHole.BackColor = Color.Red;
  699. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Red_2_;
  700. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  701. ChangeCutHoleMeasureState(CutHoleName, States);
  702. ControlFlicker = false;
  703. break;
  704. //完成
  705. case (int)ThreadState.Success:
  706. //btnCutHole.BackColor = Color.GreenYellow;
  707. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Green_2_;
  708. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  709. //修改切孔状态
  710. ChangeCutHoleMeasureState(CutHoleName, States);
  711. ControlFlicker = false;
  712. break;
  713. }
  714. break;
  715. }
  716. }
  717. }
  718. }
  719. #endregion
  720. #region 修改切孔状态
  721. public void ChangeCutHoleMeasureState(string CutHoleName, int States)
  722. {
  723. if (plPrarInfo.Controls.Count > 0)
  724. {
  725. foreach (Control item in plPrarInfo.Controls)
  726. {
  727. if (item is UserControl)
  728. {
  729. if (item.Name == CutHoleName)
  730. {
  731. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  732. //获取切孔列表
  733. List<CutHole> aCutHole = m_MeasureFile.ListCutHole;
  734. foreach (CutHole cutHoleItem in aCutHole)
  735. {
  736. if (cutHoleItem.HoleName == CutHoleName)
  737. {
  738. //设置开始时间与结束时间
  739. uControl_ParaInfo.StartTime = cutHoleItem.START.ToString();
  740. uControl_ParaInfo.EndTime = cutHoleItem.END.ToString();
  741. uControl_ParaInfo.ShowTime();
  742. break;
  743. }
  744. }
  745. switch (States)
  746. {
  747. //准备
  748. case (int)ThreadState.Ready:
  749. //修改切孔状态
  750. uControl_ParaInfo.lblShowState.Text = "准备";
  751. break;
  752. //等待
  753. case (int)ThreadState.Waiting:
  754. //修改切孔状态
  755. uControl_ParaInfo.lblShowState.Text = "等待";
  756. break;
  757. //进行中
  758. case (int)ThreadState.InProcess:
  759. //修改切孔状态
  760. uControl_ParaInfo.lblShowState.Text = "进行中";
  761. break;
  762. //完成
  763. case (int)ThreadState.Success:
  764. //修改切孔状态
  765. uControl_ParaInfo.lblShowState.Text = "完成";
  766. break;
  767. //失败
  768. case (int)ThreadState.Failed:
  769. uControl_ParaInfo.lblShowState.Text = "失败";
  770. uControl_ParaInfo.pbMeasure.Value = 100;
  771. uControl_ParaInfo.lblCompletedAmount.Text = "100%";
  772. break;
  773. }
  774. break;
  775. }
  776. }
  777. }
  778. }
  779. }
  780. #endregion
  781. #region 拖动无窗体的控件
  782. [DllImport("user32.dll")]//拖动无窗体的控件
  783. public static extern bool ReleaseCapture();
  784. [DllImport("user32.dll")]
  785. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  786. public const int WM_SYSCOMMAND = 0x0112;
  787. public const int SC_MOVE = 0xF010;
  788. public const int HTCAPTION = 0x0002;
  789. private void FormHOZMain_MouseDown(object sender, MouseEventArgs e)
  790. {
  791. if (this.WindowState == FormWindowState.Normal)
  792. {
  793. //拖动窗体
  794. ReleaseCapture();
  795. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  796. }
  797. }
  798. #endregion
  799. #region 开始、结束线程事件
  800. private void pbStart_Click(object sender, EventArgs e)
  801. {
  802. if (plLeftContent.Controls.Count==0)
  803. {
  804. MessageBox.Show("请添加切孔信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  805. return;
  806. }
  807. if (IsSave)
  808. {
  809. if (m_BackgroundWorker.IsBusy)
  810. {
  811. MessageBox.Show("线程已经运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  812. return;
  813. }
  814. if (MessageBox.Show("是否开始测量!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
  815. {
  816. LogManager.AddHardwareLog("开始", true);
  817. m_BackgroundWorker.RunWorkerAsync(this);
  818. pbStop.Visible = true;
  819. pbStart.Visible = false;
  820. }
  821. }
  822. else
  823. {
  824. MessageBox.Show("请保存当前测量文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  825. return;
  826. }
  827. }
  828. private void pbStop_Click(object sender, EventArgs e)
  829. {
  830. if (m_Ms != null)
  831. {
  832. if (MessageBox.Show("是否停止当前测量?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.Yes)
  833. {
  834. ControlFlicker = false;
  835. //线程停止变量
  836. m_Ms.key_stop = true;
  837. }
  838. }
  839. }
  840. #endregion
  841. #region 清空内容容器中的控件
  842. /// <summary>
  843. /// 清空内容容器中的控件
  844. /// </summary>
  845. private void ClearPanelControls()
  846. {
  847. //清空内容容器中的控件
  848. plLeftContent.Controls.Clear();
  849. plPrarInfo.Controls.Clear();
  850. }
  851. /// <summary>
  852. /// 清空日志控件内容
  853. /// </summary>
  854. private void ClearContrlsContent()
  855. {
  856. try
  857. {
  858. if (ucLog != null)
  859. {
  860. if (ucLog.dgvLog != null)
  861. {
  862. if (ucLog.dgvLog.Rows.Count > 0)
  863. {
  864. ucLog.dgvLog.Rows.Clear();
  865. }
  866. }
  867. }
  868. if (listmsg != null)
  869. {
  870. if (listmsg.Items.Count > 0)
  871. {
  872. listmsg.Items.Clear();
  873. }
  874. }
  875. }
  876. catch (Exception ex)
  877. {
  878. LogManager.LogError(ex.Message);
  879. }
  880. }
  881. #endregion
  882. #region 测试修改切孔中流程状态
  883. private void button1_Click(object sender, EventArgs e)
  884. {
  885. if (plPrarInfo.Controls.Count > 0)
  886. {
  887. string name = textBox1.Text;
  888. string code = textBox2.Text;
  889. bool state = Convert.ToBoolean(comboBox1.Text);
  890. foreach (Control item in plPrarInfo.Controls)
  891. {
  892. if (item is UserControl)
  893. {
  894. if (item.Name == name)
  895. {
  896. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  897. TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
  898. foreach (TimeLineItem tlItem in ParaItem)
  899. {
  900. if (tlItem.Code == code)
  901. {
  902. tlItem.State = Convert.ToInt32(state);
  903. break;
  904. }
  905. }
  906. uControl_ParaInfo.TimeLineInvalidate();
  907. break;
  908. }
  909. }
  910. }
  911. }
  912. }
  913. #endregion
  914. private void FormHOZMain_Resize(object sender, EventArgs e)
  915. {
  916. plMain.Left = 2;
  917. plMain.Top = 2;
  918. plMain.Width = this.Width - 4;
  919. plMain.Height = this.Height - 4;
  920. plFill.Width = plMain.Width - plLeft.Width - 4;
  921. plFill.Height = plMain.Height - plTop.Height - 4;
  922. plFill.Left = plLeft.Width + 4;
  923. plFill.Top = plTop.Height + 4;
  924. if(this.WindowState!= FormWindowState.Maximized)
  925. {
  926. plPrarInfo.Height = 505;
  927. foreach (Control item in plPrarInfo.Controls)
  928. {
  929. if (item is UserControl)
  930. {
  931. if(item.Height>505)
  932. {
  933. item.Height = 505;
  934. }
  935. }
  936. }
  937. }
  938. }
  939. private void FormHOZMain_Paint(object sender, PaintEventArgs e)
  940. {
  941. }
  942. }
  943. }