FormHOZMain.cs 29 KB

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