FormHOZMain.cs 43 KB

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