FormHOZMain.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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.IO;
  11. using System.Linq;
  12. using System.Runtime.InteropServices;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. using static MeasureThread.ThreadStatusEventArgs;
  17. namespace HOZProject
  18. {
  19. public partial class FormHOZMain : Form
  20. {
  21. #region 成员变量
  22. public BackgroundWorker m_BackgroundWorker;// 申明后台对象
  23. /// <summary>
  24. /// 测量文件
  25. /// </summary>
  26. public MeasureFile m_MeasureFile;
  27. /// 测量线程
  28. public Measure m_Ms;
  29. /// <summary>
  30. /// 显示日志窗体
  31. /// </summary>
  32. Form m_FormLog = null;
  33. /// <summary>
  34. /// 显示实例化窗体
  35. /// </summary>
  36. Form m_FormInit = null;
  37. /// <summary>
  38. /// 是否已保存
  39. /// </summary>
  40. public bool IsSave = false;
  41. /// <summary>
  42. /// 初始化用户控件
  43. /// </summary>
  44. UControl_Init uControl_Init = null;
  45. /// <summary>
  46. /// 日志用户控件
  47. /// </summary>
  48. UControl_Log ucLog = null;
  49. //流程控制
  50. public int m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  51. //是否关闭窗体标识
  52. public bool IsClose = false;
  53. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  54. #endregion
  55. #region 构造函数
  56. public FormHOZMain()
  57. {
  58. InitializeComponent();
  59. //在线程操作过程中,可以设置控件属性
  60. Control.CheckForIllegalCrossThreadCalls = false;
  61. m_BackgroundWorker = new BackgroundWorker(); // 实例化后台对象
  62. m_BackgroundWorker.WorkerReportsProgress = true; // 设置可以通告进度
  63. m_BackgroundWorker.WorkerSupportsCancellation = true; // 设置可以取消
  64. m_BackgroundWorker.DoWork += new DoWorkEventHandler(DoWork);
  65. m_BackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(UpdateProgress);
  66. m_BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedWork);
  67. LogManager.InitManulLog();
  68. }
  69. #endregion
  70. #region 测量线程
  71. void DoWork(object sender, DoWorkEventArgs e)
  72. {
  73. m_Ms = new Measure(ConfigurationManager.AppSettings["WebServerIP"].ToString(),
  74. ConfigurationManager.AppSettings["WebServerPort"].ToString(),
  75. ConfigurationManager.AppSettings["WebServerUrl"].ToString());
  76. m_MeasureFile.MParam.AutoFocus.UP = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_UP"].ToString());
  77. m_MeasureFile.MParam.AutoFocus.Down = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Down"].ToString());
  78. m_MeasureFile.MParam.AutoFocus.Step = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Step"].ToString());
  79. m_MeasureFile.MParam.AutoFocus.Range = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_Range"].ToString());
  80. m_MeasureFile.MParam.AutoFocus.fStep = Convert.ToSingle(ConfigurationManager.AppSettings["Focus_FStep"].ToString());
  81. m_Ms.InitMeas(m_MeasureFile);
  82. m_Ms.SendThreadStatus += new ThreadStatusHandler(displayMessage); //注册事件
  83. m_Ms.SendCutHolesStatus += new CutHolesStatusHandler(displayCutHoleMessage); //注册事件
  84. //设置控件操作
  85. SetWinControlMeasureState(false);
  86. //自动测量的全过程
  87. m_Ms.DoMeasure();
  88. }
  89. public void displayMessage(object sender, ThreadStatusEventArgs e)
  90. {
  91. //主界面显示内容
  92. this.BeginInvoke((Action)delegate
  93. {
  94. this.listmsg.Items.Add(e.HoleName +"_" + e.Time.ToString() + "_"+ e.Message + "_" + e.State );
  95. //显示流程中对应编号的内容
  96. MeasureMsgManage.ShowMsgContent(this, e);
  97. AddLogListInfo(e);
  98. });
  99. }
  100. public void displayCutHoleMessage(object sender, CutHolesStatusEventArgs e)
  101. {
  102. //主界面显示内容
  103. this.BeginInvoke((Action)delegate
  104. {
  105. //this.listmsg.Items.Add(e.HoleName.ToString() + e.State);
  106. ChangeCutHoleState(e.HoleName.ToString(), Convert.ToInt32(e.State));
  107. });
  108. }
  109. void UpdateProgress(object sender, ProgressChangedEventArgs e)
  110. {
  111. }
  112. void CompletedWork(object sender, RunWorkerCompletedEventArgs e)
  113. {
  114. //设置控件操作
  115. MessageBox.Show("线程已完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  116. SetWinControlMeasureState(true);
  117. }
  118. #endregion
  119. private void FormHOZMain_Load(object sender, EventArgs e)
  120. {
  121. //加载控件的点击事件
  122. this.Click += new EventHandler(FormHOZMain_Click);
  123. plFill.Click += new EventHandler(FormHOZMain_Click);
  124. plTop.Click += new EventHandler(FormHOZMain_Click);
  125. plLeft.Click += new EventHandler(FormHOZMain_Click);
  126. plLeftContent.Click += new EventHandler(FormHOZMain_Click);
  127. pbImage.Click += new EventHandler(FormHOZMain_Click);
  128. //加载窗口移动事件
  129. this.MouseDown += new MouseEventHandler(FormHOZMain_MouseDown);
  130. //新建
  131. NewCreate();
  132. //实例初始化窗体对象
  133. if (uControl_Init == null)
  134. {
  135. uControl_Init = new UControl_Init(this);
  136. uControl_Init.ReloadConfig();
  137. }
  138. }
  139. #region 创建切孔列表信息
  140. /// <summary>
  141. /// 创建切孔列表信息
  142. /// </summary>
  143. /// <param name="ListCutHole"></param>
  144. public void CreateCutHoleList(List<CutHole> ListCutHole)
  145. {
  146. //清空左侧Panel中的切孔控件
  147. ClearPanelControls();
  148. for (int i = ListCutHole.Count - 1; i >= 0; i--)
  149. {
  150. UControl_CutHole ucCutHole = new UControl_CutHole(this);
  151. ucCutHole.Dock = DockStyle.Top;
  152. ucCutHole.CutHoleName = ListCutHole[i].HoleName;
  153. //显示切孔参数信息
  154. if (ucCutHole.UControl_ParaInfo == null)
  155. {
  156. ucCutHole.UControl_ParaInfo = new UControl_ParaInfo(this);
  157. }
  158. plPrarInfo.Width = ucCutHole.UControl_ParaInfo.Width;
  159. plPrarInfo.Height = ucCutHole.UControl_ParaInfo.Height;
  160. //设置当前样品的参数信息
  161. ucCutHole.UControl_ParaInfo.Name = ListCutHole[i].HoleName;
  162. ucCutHole.UControl_ParaInfo.CutHoleName = ListCutHole[i].HoleName;
  163. ucCutHole.UControl_ParaInfo.Position = ListCutHole[i].Position;
  164. ucCutHole.UControl_ParaInfo.StartTime = ListCutHole[i].START.ToString();
  165. ucCutHole.UControl_ParaInfo.EndTime = ListCutHole[i].END.ToString();
  166. ucCutHole.UControl_ParaInfo.State = ListCutHole[i].STATE.ToString();
  167. ucCutHole.UControl_ParaInfo.IsSwitch = ListCutHole[i].SWITCH;
  168. ucCutHole.UControl_ParaInfo.Dock = DockStyle.Fill;
  169. ucCutHole.UControl_ParaInfo.ShowParaInfo();
  170. plPrarInfo.Controls.Add(ucCutHole.UControl_ParaInfo);
  171. plLeftContent.Controls.Add(ucCutHole);
  172. }
  173. plPrarInfo.Visible = false;
  174. }
  175. #endregion
  176. //隐藏处理层
  177. private void FormHOZMain_Click(object sender, EventArgs e)
  178. {
  179. if (plPrarInfo.Visible)
  180. {
  181. plPrarInfo.Visible = false;
  182. }
  183. }
  184. #region 设置控件在线程过程中的编辑状态
  185. /// <summary>
  186. /// 设置控件在线程过程中的编辑状态
  187. /// </summary>
  188. /// <param name="cState"></param>
  189. public void SetWinControlMeasureState(bool cState)
  190. {
  191. pbNew.Enabled = cState;
  192. pbOpen.Enabled = cState;
  193. pbSave.Enabled = cState;
  194. pbInit.Enabled = cState;
  195. pbImportTemplateFile.Enabled = cState;
  196. //pbLog.Enabled = cState;
  197. pbStop.Enabled = !cState;
  198. }
  199. #endregion
  200. #region 窗体中 线程开始 停止 最大化 最小化 关闭 按钮事件
  201. private void pbMin_MouseEnter(object sender, EventArgs e)
  202. {
  203. this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_Blue;
  204. }
  205. private void pbMin_MouseLeave(object sender, EventArgs e)
  206. {
  207. this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_Gray;
  208. }
  209. private void pbMax_MouseEnter(object sender, EventArgs e)
  210. {
  211. this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_Blue;
  212. }
  213. private void pbMax_MouseLeave(object sender, EventArgs e)
  214. {
  215. this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_Gray;
  216. }
  217. private void pbClose_MouseEnter(object sender, EventArgs e)
  218. {
  219. this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Red;
  220. }
  221. private void pbClose_MouseLeave(object sender, EventArgs e)
  222. {
  223. this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_Gray;
  224. }
  225. private void pbStart_MouseEnter(object sender, EventArgs e)
  226. {
  227. this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.Start_Green;
  228. }
  229. private void pbStart_MouseLeave(object sender, EventArgs e)
  230. {
  231. this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.Start;
  232. }
  233. private void pbStop_MouseEnter(object sender, EventArgs e)
  234. {
  235. this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.Stop_Red;
  236. }
  237. private void pbStop_MouseLeave(object sender, EventArgs e)
  238. {
  239. this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.Stop;
  240. }
  241. private void pbClose_Click(object sender, EventArgs e)
  242. {
  243. if (m_Ms != null)
  244. {
  245. if (!m_Ms.key_stop)
  246. {
  247. if (MessageBox.Show("当前测量正在运行,是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  248. {
  249. //线程停止变量
  250. m_Ms.key_stop = true;
  251. IsClose = true;
  252. lblStateMessage.Text = "正在关闭窗体...请等待";
  253. }
  254. return;
  255. }
  256. }
  257. if (MessageBox.Show("是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  258. {
  259. this.Close();
  260. }
  261. }
  262. private void pbMin_Click(object sender, EventArgs e)
  263. {
  264. this.WindowState = FormWindowState.Minimized;
  265. }
  266. private void pbMax_Click(object sender, EventArgs e)
  267. {
  268. if (this.WindowState == FormWindowState.Maximized)
  269. {
  270. this.WindowState = FormWindowState.Normal;
  271. }
  272. else
  273. {
  274. this.WindowState = FormWindowState.Maximized;
  275. }
  276. //窗体据中
  277. this.StartPosition = FormStartPosition.CenterScreen;
  278. }
  279. #endregion
  280. #region 新建、保存、打开、初始化、导入配置、查看日志
  281. private void pbNew_Click(object sender, EventArgs e)
  282. {
  283. NewCreate();
  284. }
  285. private void NewCreate()
  286. {
  287. m_MeasureFile = new MeasureFile();
  288. if (!m_MeasureFile.New())
  289. {
  290. return;
  291. }
  292. else
  293. {
  294. //清空内容容器中的控件
  295. ClearPanelControls();
  296. }
  297. }
  298. private void pbSave_Click(object sender, EventArgs e)
  299. {
  300. if (m_MeasureFile == null)
  301. {
  302. MessageBox.Show("请新建一个测量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  303. }
  304. else
  305. {
  306. //保存测量文件
  307. if (m_MeasureFile.Save())
  308. {
  309. //获取测量文件所在路径
  310. string savePath = m_MeasureFile.FilePath;
  311. //数据库名称
  312. string dbFileName = "MeasureFile.db";
  313. //要复制的文件路径
  314. string pLocalFilePath = Application.StartupPath +"\\"+dbFileName;
  315. string pSaveFilePath = savePath + "\\" + dbFileName;//指定存储的路径
  316. if (File.Exists(pLocalFilePath))//必须判断要复制的文件是否存在
  317. {
  318. //三个参数分别是源文件路径,存储路径,若存储路径有相同文件是否替换
  319. File.Copy(pLocalFilePath, pSaveFilePath, true);
  320. }
  321. //将初始化中的参数,配置到测量参数中
  322. m_MeasureFile.MParam = uControl_Init.GetMeasureParamInfo();
  323. //设置已保存状态
  324. IsSave = true;
  325. }
  326. }
  327. }
  328. private void pbOpen_Click(object sender, EventArgs e)
  329. {
  330. }
  331. private void pbInit_Click(object sender, EventArgs e)
  332. {
  333. if (uControl_Init == null)
  334. {
  335. uControl_Init = new UControl_Init(this);
  336. uControl_Init.ReloadConfig();
  337. }
  338. if (m_FormInit == null)
  339. {
  340. m_FormInit = new Form();
  341. }
  342. m_FormInit.StartPosition = FormStartPosition.CenterScreen;
  343. m_FormInit.FormBorderStyle = FormBorderStyle.None;
  344. m_FormInit.Width = uControl_Init.Width;
  345. m_FormInit.Height = uControl_Init.Height;
  346. if (m_FormInit.Controls.Count == 0)
  347. {
  348. m_FormInit.Controls.Add(uControl_Init);
  349. }
  350. m_FormInit.ShowDialog();
  351. }
  352. private void pbImportTemplateFile_Click(object sender, EventArgs e)
  353. {
  354. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  355. string m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString();
  356. //判断保存的路径是否存在
  357. if (!Directory.Exists(m_TemplateFilePath))
  358. {
  359. //创建路径
  360. Directory.CreateDirectory(m_TemplateFilePath);
  361. }
  362. //打开默认路径
  363. OpenFileDialog openFileDialog = new OpenFileDialog();
  364. //设置默认打开路径(绝对路径)
  365. openFileDialog.InitialDirectory = m_TemplateFilePath;
  366. openFileDialog.Filter = "样品参数文件|*.cfg";
  367. if (openFileDialog.ShowDialog() == DialogResult.OK)
  368. {
  369. if (uControl_Init == null)
  370. {
  371. uControl_Init = new UControl_Init(this);
  372. }
  373. //设置选择的模板文件
  374. uControl_Init.ReadConfigPath = openFileDialog.FileName;
  375. //获取文件
  376. uControl_Init.ReadConfigInfo();
  377. }
  378. }
  379. private void pbLog_Click(object sender, EventArgs e)
  380. {
  381. m_FormLog = new Form();
  382. m_FormLog.StartPosition = FormStartPosition.CenterScreen;
  383. if (ucLog == null)
  384. {
  385. ucLog = new UControl_Log();
  386. }
  387. m_FormLog.FormBorderStyle = FormBorderStyle.None;
  388. m_FormLog.Width = ucLog.Width;
  389. m_FormLog.Height = ucLog.Height;
  390. ucLog.Name = "UControl_Log";
  391. //获取日志信息
  392. if (listmsg.Items.Count>0)
  393. {
  394. string[] strLog = new string[listmsg.Items.Count];
  395. for (int i = 0; i < listmsg.Items.Count; i++)
  396. {
  397. //赋值给数组
  398. strLog[i] = listmsg.Items[i].ToString();
  399. }
  400. ucLog.ShowProcessLogInfo(strLog);
  401. }
  402. m_FormLog.Controls.Add(ucLog);
  403. m_FormLog.ShowDialog();
  404. }
  405. //显示日志
  406. private void AddLogListInfo(ThreadStatusEventArgs e)
  407. {
  408. if (m_FormLog != null)
  409. {
  410. foreach (Control item in m_FormLog.Controls)
  411. {
  412. if (item is UserControl)
  413. {
  414. if (item.Name == "UControl_Log")
  415. {
  416. ucLog = (UControl_Log)item;
  417. //获取日志信息
  418. if (listmsg.Items.Count > 0)
  419. {
  420. string[] strLog = new string[listmsg.Items.Count];
  421. for (int i = 0; i < listmsg.Items.Count; i++)
  422. {
  423. //赋值给数组
  424. strLog[i] = listmsg.Items[i].ToString();
  425. }
  426. ucLog.ShowProcessLogInfo(strLog);
  427. }
  428. }
  429. }
  430. }
  431. }
  432. }
  433. #endregion
  434. #region 修改切孔状态
  435. /// <summary>
  436. /// 修改切孔状态
  437. /// </summary>
  438. /// <param name="cutHoleCode"></param>
  439. /// <param name="States"></param>
  440. private void ChangeCutHoleState(string CutHoleName, int States)
  441. {
  442. foreach (Control item in plLeftContent.Controls)
  443. {
  444. if (item is UserControl)
  445. {
  446. UControl_CutHole cutHole = (UControl_CutHole)item;
  447. if (cutHole.CutHoleName == CutHoleName)
  448. {
  449. Button btnCutHole = (Button)cutHole.Controls.Find("btnCutHole", false)[0];
  450. switch (States)
  451. {
  452. //运行中
  453. case (int)ThreadState.InProcess:
  454. btnCutHole.BackColor = Color.Yellow;
  455. ChangeCutHoleMeasureState(CutHoleName, States);
  456. break;
  457. //等待
  458. case (int)ThreadState.Waiting:
  459. btnCutHole.BackColor = Color.Yellow;
  460. ChangeCutHoleMeasureState(CutHoleName, States);
  461. break;
  462. //准备
  463. case (int)ThreadState.Ready:
  464. btnCutHole.BackColor = Color.Yellow;
  465. ChangeCutHoleMeasureState(CutHoleName, States);
  466. break;
  467. //失败
  468. case (int)ThreadState.Failed:
  469. btnCutHole.BackColor = Color.Red;
  470. ChangeCutHoleMeasureState(CutHoleName, States);
  471. break;
  472. //完成
  473. case (int)ThreadState.Success:
  474. btnCutHole.BackColor = Color.GreenYellow;
  475. //修改切孔状态
  476. ChangeCutHoleMeasureState(CutHoleName, States);
  477. break;
  478. }
  479. break;
  480. }
  481. }
  482. }
  483. }
  484. #endregion
  485. #region 修改切孔状态
  486. protected void ChangeCutHoleMeasureState(string CutHoleName, int States)
  487. {
  488. if (plPrarInfo.Controls.Count > 0)
  489. {
  490. foreach (Control item in plPrarInfo.Controls)
  491. {
  492. if (item is UserControl)
  493. {
  494. if (item.Name == CutHoleName)
  495. {
  496. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  497. //获取切孔列表
  498. List<CutHole> aCutHole = m_MeasureFile.ListCutHole;
  499. foreach (CutHole cutHoleItem in aCutHole)
  500. {
  501. if (cutHoleItem.HoleName == CutHoleName)
  502. {
  503. //设置开始时间与结束时间
  504. uControl_ParaInfo.StartTime = cutHoleItem.START.ToString();
  505. uControl_ParaInfo.EndTime = cutHoleItem.END.ToString();
  506. uControl_ParaInfo.ShowTime();
  507. break;
  508. }
  509. }
  510. switch (States)
  511. {
  512. //准备
  513. case (int)ThreadState.Ready:
  514. //修改切孔状态
  515. uControl_ParaInfo.lblShowState.Text = "准备";
  516. break;
  517. //等待
  518. case (int)ThreadState.Waiting:
  519. //修改切孔状态
  520. uControl_ParaInfo.lblShowState.Text = "等待";
  521. break;
  522. //进行中
  523. case (int)ThreadState.InProcess:
  524. //修改切孔状态
  525. uControl_ParaInfo.lblShowState.Text = "进行中";
  526. break;
  527. //完成
  528. case (int)ThreadState.Success:
  529. //修改切孔状态
  530. uControl_ParaInfo.lblShowState.Text = "完成";
  531. break;
  532. //失败
  533. case (int)ThreadState.Failed:
  534. uControl_ParaInfo.lblShowState.Text = "失败";
  535. break;
  536. }
  537. break;
  538. }
  539. }
  540. }
  541. }
  542. }
  543. #endregion
  544. #region 拖动无窗体的控件
  545. [DllImport("user32.dll")]//拖动无窗体的控件
  546. public static extern bool ReleaseCapture();
  547. [DllImport("user32.dll")]
  548. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  549. public const int WM_SYSCOMMAND = 0x0112;
  550. public const int SC_MOVE = 0xF010;
  551. public const int HTCAPTION = 0x0002;
  552. private void FormHOZMain_MouseDown(object sender, MouseEventArgs e)
  553. {
  554. if (this.WindowState == FormWindowState.Normal)
  555. {
  556. //拖动窗体
  557. ReleaseCapture();
  558. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  559. }
  560. }
  561. #endregion
  562. #region 开始、结束线程事件
  563. private void pbStart_Click(object sender, EventArgs e)
  564. {
  565. if (m_MeasureFile == null)
  566. {
  567. MessageBox.Show("请新建一个测量文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  568. //listmsg.Items.Clear();
  569. }
  570. else
  571. {
  572. if (IsSave)
  573. {
  574. if (m_BackgroundWorker.IsBusy)
  575. {
  576. MessageBox.Show("线程已经运行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
  577. return;
  578. }
  579. m_BackgroundWorker.RunWorkerAsync(this);
  580. }
  581. else
  582. {
  583. MessageBox.Show("请保存当前测量文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  584. }
  585. }
  586. }
  587. private void pbStop_Click(object sender, EventArgs e)
  588. {
  589. if (m_Ms != null)
  590. {
  591. if (MessageBox.Show("是否停止当前测量?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.Yes)
  592. {
  593. //线程停止变量
  594. m_Ms.key_stop = true;
  595. }
  596. }
  597. }
  598. #endregion
  599. #region 清空内容容器中的控件
  600. /// <summary>
  601. /// 清空内容容器中的控件
  602. /// </summary>
  603. private void ClearPanelControls()
  604. {
  605. //清空内容容器中的控件
  606. plLeftContent.Controls.Clear();
  607. plPrarInfo.Controls.Clear();
  608. }
  609. #endregion
  610. #region 测试修改切孔中流程状态
  611. private void button1_Click(object sender, EventArgs e)
  612. {
  613. if (plPrarInfo.Controls.Count > 0)
  614. {
  615. string name = textBox1.Text;
  616. string code = textBox2.Text;
  617. bool state = Convert.ToBoolean(comboBox1.Text);
  618. foreach (Control item in plPrarInfo.Controls)
  619. {
  620. if (item is UserControl)
  621. {
  622. if (item.Name == name)
  623. {
  624. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  625. TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
  626. foreach (TimeLineItem tlItem in ParaItem)
  627. {
  628. if (tlItem.Code == code)
  629. {
  630. tlItem.State = Convert.ToInt32(state);
  631. break;
  632. }
  633. }
  634. uControl_ParaInfo.TimeLineInvalidate();
  635. break;
  636. }
  637. }
  638. }
  639. }
  640. }
  641. #endregion
  642. }
  643. }