FormHOZMain.cs 43 KB

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