FormHOZMain.cs 30 KB

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