FormHOZMain.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. using FileManager;
  2. using MeasureData;
  3. using MeasureThread;
  4. using SenseShield;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Configuration;
  9. using System.Data;
  10. using System.Diagnostics;
  11. using System.Drawing;
  12. using System.Drawing.Drawing2D;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Runtime.InteropServices;
  16. using System.Text;
  17. //using SenseShield;
  18. using System.Threading.Tasks;
  19. using System.Windows.Forms;
  20. using static MeasureThread.ThreadStatusEventArgs;
  21. namespace HOZProject
  22. {
  23. public partial class FormHOZMain : Form
  24. {
  25. #region 控制窗体可以调整大小用
  26. const int HTLEFT = 10;
  27. const int HTRIGHT = 11;
  28. const int HTTOP = 12;
  29. const int HTTOPLEFT = 13;
  30. const int HTTOPRIGHT = 14;
  31. const int HTBOTTOM = 15;
  32. const int HTBOTTOMLEFT = 0x10;
  33. const int HTBOTTOMRIGHT = 17;
  34. protected override void WndProc(ref Message m)
  35. {
  36. switch (m.Msg)
  37. {
  38. case 0x0084:
  39. base.WndProc(ref m);
  40. Point vPoint = new Point((int)m.LParam & 0xFFFF,
  41. (int)m.LParam >> 16 & 0xFFFF);
  42. vPoint = PointToClient(vPoint);
  43. if (vPoint.X <= 5)
  44. if (vPoint.Y <= 5)
  45. m.Result = (IntPtr)HTTOPLEFT;
  46. else if (vPoint.Y >= ClientSize.Height - 5)
  47. m.Result = (IntPtr)HTBOTTOMLEFT;
  48. else m.Result = (IntPtr)HTLEFT;
  49. else if (vPoint.X >= ClientSize.Width - 5)
  50. if (vPoint.Y <= 5)
  51. m.Result = (IntPtr)HTTOPRIGHT;
  52. else if (vPoint.Y >= ClientSize.Height - 5)
  53. m.Result = (IntPtr)HTBOTTOMRIGHT;
  54. else m.Result = (IntPtr)HTRIGHT;
  55. else if (vPoint.Y <= 5)
  56. m.Result = (IntPtr)HTTOP;
  57. else if (vPoint.Y >= ClientSize.Height - 5)
  58. m.Result = (IntPtr)HTBOTTOM;
  59. break;
  60. case 0x0201://鼠标左键按下的消息
  61. m.Msg = 0x00A1;//更改消息为非客户区按下鼠标
  62. m.LParam = IntPtr.Zero;//默认值
  63. m.WParam = new IntPtr(2);//鼠标放在标题栏内
  64. base.WndProc(ref m);
  65. break;
  66. default:
  67. base.WndProc(ref m);
  68. break;
  69. }
  70. }
  71. #endregion
  72. #region 成员变量
  73. private NLog.Logger log;
  74. /// <summary>
  75. /// 控制闪烁
  76. /// </summary>
  77. public static bool ControlFlicker;//控制流程闪烁
  78. public BackgroundWorker m_BackgroundWorker;// 申明后台对象
  79. /// <summary>
  80. /// 测量文件
  81. /// </summary>
  82. public MeasureFile m_MeasureFile;
  83. /// 测量线程
  84. public Measure m_Ms;
  85. /// <summary>
  86. /// 显示日志窗体
  87. /// </summary>
  88. Form m_FormLog = null;
  89. /// <summary>
  90. /// 显示实例化窗体
  91. /// </summary>
  92. FormMove m_FormInit = null;
  93. /// <summary>
  94. /// 是否已保存
  95. /// </summary>
  96. public bool IsSave = false;
  97. /// <summary>
  98. /// 初始化用户控件
  99. /// </summary>
  100. UControl_Init uControl_Init = null;
  101. /// <summary>
  102. /// 日志用户控件
  103. /// </summary>
  104. UControl_Log ucLog = null;
  105. //流程控制
  106. public int m_MeasureType = (int)MeasureMsgManage.measureType.FIB;
  107. //是否关闭窗体标识
  108. public bool IsClose = false;
  109. OTSMeasureOutputNlog logwin;
  110. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  111. #endregion
  112. #region 构造函数
  113. public FormHOZMain()
  114. {
  115. InitializeComponent();
  116. //在线程操作过程中,可以设置控件属性
  117. Control.CheckForIllegalCrossThreadCalls = false;
  118. m_BackgroundWorker = new BackgroundWorker(); // 实例化后台对象
  119. m_BackgroundWorker.WorkerReportsProgress = true; // 设置可以通告进度
  120. m_BackgroundWorker.WorkerSupportsCancellation = true; // 设置可以取消
  121. m_BackgroundWorker.DoWork += new DoWorkEventHandler(DoWork);
  122. m_BackgroundWorker.ProgressChanged += new ProgressChangedEventHandler(UpdateProgress);
  123. m_BackgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompletedWork);
  124. uControl_Init = new UControl_Init(this);
  125. }
  126. #endregion
  127. #region 测量线程
  128. void DoWork(object sender, DoWorkEventArgs e)
  129. {
  130. try
  131. {
  132. m_Ms = new Measure(ConfigurationManager.AppSettings["WebServerIP"].ToString(),
  133. ConfigurationManager.AppSettings["WebServerPort"].ToString(),
  134. ConfigurationManager.AppSettings["WebServerUrl"].ToString(),m_MeasureFile);
  135. m_Ms.InitMeasure();
  136. //注册事件
  137. m_Ms.SendThreadStatus += new ThreadStatusHandler(displayMessage);
  138. //注册事件
  139. m_Ms.SendCutHolesStatus += new CutHolesStatusHandler(displayCutHoleMessage);
  140. //自动测量的全过程
  141. m_Ms.DoMeasure();
  142. }
  143. catch (Exception ex)
  144. {
  145. log.Error(ex.ToString(),false);
  146. }
  147. }
  148. public void displayMessage(object sender, ThreadStatusEventArgs e)
  149. {
  150. //主界面显示内容
  151. this.BeginInvoke((Action)delegate
  152. {
  153. this.listmsg.Items.Add(e.HoleName +"_" + e.Time.ToString() + "_"+ e.Message + "_" + e.State );
  154. //显示流程中对应编号的内容
  155. MeasureMsgManage.ShowMsgContent(this, e);
  156. AddLogListInfo(e);
  157. });
  158. }
  159. public void displayCutHoleMessage(object sender, CutHolesStatusEventArgs e)
  160. {
  161. //主界面显示内容
  162. this.BeginInvoke((Action)delegate
  163. {
  164. //修改切孔状态
  165. ChangeCutHoleState(e.HoleName.ToString(), Convert.ToInt32(e.State));
  166. });
  167. }
  168. void UpdateProgress(object sender, ProgressChangedEventArgs e)
  169. {
  170. }
  171. void CompletedWork(object sender, RunWorkerCompletedEventArgs e)
  172. {
  173. ControlFlicker = false;
  174. //设置控件操作
  175. MessageBox.Show("测量已完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  176. SetWinControlMeasureState(true);
  177. pbStop.Visible = false;
  178. pbStart.Visible = true;
  179. //UControl_ParaInfo uControl_ParaInfo=new UControl_ParaInfo()
  180. UControl_ParaInfo uControl_ParaInfo = new UControl_ParaInfo(this);
  181. uControl_ParaInfo.pbMeasure.Value = 100;
  182. uControl_ParaInfo.lblCompletedAmount.Text = "100%";
  183. }
  184. #endregion
  185. #region 窗体加载
  186. private void FormHOZMain_Load(object sender, EventArgs e)
  187. {
  188. try
  189. {
  190. DogDecrypting.decrypting(100);//参数为许可号
  191. //加载控件的点击事件
  192. this.Click += new EventHandler(FormHOZMain_Click);
  193. plFill.Click += new EventHandler(FormHOZMain_Click);
  194. plTop.Click += new EventHandler(FormHOZMain_Click);
  195. plLeft.Click += new EventHandler(FormHOZMain_Click);
  196. plLeftContent.Click += new EventHandler(FormHOZMain_Click);
  197. pbImage.Click += new EventHandler(FormHOZMain_Click);
  198. //加载窗口移动事件
  199. this.MouseDown += new MouseEventHandler(FormHOZMain_MouseDown);
  200. this.plTop.MouseDown += new MouseEventHandler(FormHOZMain_MouseDown);
  201. //新建
  202. m_MeasureFile = new MeasureFile();
  203. m_MeasureFile.MParam.GetMeasureParamFromConfigration() ;//读到参数对象中
  204. uControl_Init.DisplayInitialParam();//显示到界面上
  205. logwin = new OTSMeasureOutputNlog();
  206. logwin.Show();
  207. logwin.Height = this.Height;
  208. logwin.Left = this.Left - logwin.Width;
  209. logwin.Top = this.Top;
  210. NLog.Config.LoggingRule lr = NLog.LogManager.Configuration.LoggingRules.FirstOrDefault(
  211. r => r.Targets.Any(
  212. t => "control" == t.Name
  213. )
  214. );
  215. log = NLog.LogManager.GetCurrentClassLogger();
  216. this.Left = this.Location.X + logwin.Width / 2;
  217. }
  218. catch (Exception ex)
  219. {
  220. MessageBox.Show(ex.Message, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
  221. this.Close();
  222. }
  223. }
  224. #endregion
  225. #region 创建切孔列表信息
  226. /// <summary>
  227. /// 创建切孔列表信息
  228. /// </summary>
  229. /// <param name="ListCutHole"></param>
  230. public void CreateCutHoleList(List<CutHole> ListCutHole)
  231. {
  232. //清空左侧Panel中的切孔控件
  233. ClearPanelControls();
  234. for (int i = ListCutHole.Count - 1; i >= 0; i--)
  235. {
  236. UControl_CutHole ucCutHole = new UControl_CutHole(this);
  237. ucCutHole.Dock = DockStyle.Top;
  238. ucCutHole.CutHoleName = ListCutHole[i].HoleName;
  239. //显示切孔参数信息
  240. if (ucCutHole.UControl_ParaInfo == null)
  241. {
  242. ucCutHole.UControl_ParaInfo = new UControl_ParaInfo(this);
  243. }
  244. plPrarInfo.Width = ucCutHole.UControl_ParaInfo.Width;
  245. plPrarInfo.Height = ucCutHole.UControl_ParaInfo.Height;
  246. //设置当前样品的参数信息
  247. string CutHoleName = ListCutHole[i].HoleName;
  248. ucCutHole.UControl_ParaInfo.Name = CutHoleName;
  249. ucCutHole.UControl_ParaInfo.CutHoleName = CutHoleName;
  250. ucCutHole.UControl_ParaInfo.Position = ListCutHole[i].Position;
  251. ucCutHole.UControl_ParaInfo.StartTime = ListCutHole[i].START.ToString();
  252. ucCutHole.UControl_ParaInfo.EndTime = ListCutHole[i].END.ToString();
  253. int state = (int)ListCutHole[i].STATE;
  254. ucCutHole.UControl_ParaInfo.State = state;
  255. ucCutHole.UControl_ParaInfo.IsSwitch = ListCutHole[i].SWITCH;
  256. ucCutHole.UControl_ParaInfo.ShowParaInfo();
  257. this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  258. plPrarInfo.Controls.Add(ucCutHole.UControl_ParaInfo);
  259. plLeftContent.Controls.Add(ucCutHole);
  260. ChangeCutHoleState(CutHoleName, state);
  261. }
  262. plPrarInfo.Visible = false;
  263. }
  264. #endregion
  265. #region 隐藏处理层
  266. //隐藏处理层
  267. private void FormHOZMain_Click(object sender, EventArgs e)
  268. {
  269. if (plPrarInfo.Visible)
  270. {
  271. plPrarInfo.Visible = false;
  272. }
  273. }
  274. #endregion
  275. #region 设置控件在线程过程中的编辑状态
  276. /// <summary>
  277. /// 设置控件在线程过程中的编辑状态
  278. /// </summary>
  279. /// <param name="cState"></param>
  280. public void SetWinControlMeasureState(bool cState)
  281. {
  282. pbNew.Enabled = cState;
  283. pbOpen.Enabled = cState;
  284. pbSave.Enabled = cState;
  285. // pbInit.Enabled = cState;
  286. pbImportTemplateFile.Enabled = cState;
  287. //pbLog.Enabled = cState;
  288. pbStart.Enabled = cState;
  289. pbStop.Enabled = !cState;
  290. //设置切孔是否执行
  291. foreach (Control item in plPrarInfo.Controls)
  292. {
  293. if (item is UserControl)
  294. {
  295. UControl_ParaInfo ucParaInfo = (UControl_ParaInfo)item;
  296. ucParaInfo.CkIsSwitch.Enabled = cState;
  297. }
  298. }
  299. }
  300. #endregion
  301. #region 窗体中 线程开始 停止 最大化 最小化 关闭 按钮事件
  302. private void pbMin_MouseEnter(object sender, EventArgs e)
  303. {
  304. this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_2_;
  305. }
  306. private void pbMin_MouseLeave(object sender, EventArgs e)
  307. {
  308. this.pbMin.BackgroundImage = global::HOZProject.Properties.Resources.Min_2_;
  309. }
  310. private void pbMax_MouseEnter(object sender, EventArgs e)
  311. {
  312. this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_2_;
  313. }
  314. private void pbMax_MouseLeave(object sender, EventArgs e)
  315. {
  316. this.pbMax.BackgroundImage = global::HOZProject.Properties.Resources.Max_2_;
  317. }
  318. private void pbClose_MouseEnter(object sender, EventArgs e)
  319. {
  320. this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  321. }
  322. private void pbClose_MouseLeave(object sender, EventArgs e)
  323. {
  324. this.pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  325. }
  326. private void pbStart_MouseEnter(object sender, EventArgs e)
  327. {
  328. //this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.StartMove;
  329. }
  330. private void pbStart_MouseLeave(object sender, EventArgs e)
  331. {
  332. //this.pbStart.BackgroundImage = global::HOZProject.Properties.Resources.Start_3_;
  333. }
  334. private void pbStop_MouseEnter(object sender, EventArgs e)
  335. {
  336. //this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.StopMove;
  337. }
  338. private void pbStop_MouseLeave(object sender, EventArgs e)
  339. {
  340. //this.pbStop.BackgroundImage = global::HOZProject.Properties.Resources.Stop;
  341. }
  342. private void pbClose_Click(object sender, EventArgs e)
  343. {
  344. try
  345. {
  346. if (m_Ms != null)
  347. {
  348. if (m_BackgroundWorker.IsBusy)
  349. {
  350. if (MessageBox.Show("当前测量正在运行,是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  351. {
  352. //线程停止变量
  353. m_Ms.key_stop = true;
  354. IsClose = true;
  355. lblStateMessage.Text = "正在关闭窗体...请等待";
  356. pbClose.Enabled = false;
  357. ControlFlicker = false;
  358. }
  359. return;
  360. }
  361. }
  362. if (MessageBox.Show("是否关闭此窗体?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  363. {
  364. //m_MeasureFile.Save();
  365. this.Close();
  366. }
  367. }
  368. catch (Exception ex)
  369. {
  370. log.Error(ex.Message);
  371. }
  372. }
  373. private void pbMin_Click(object sender, EventArgs e)
  374. {
  375. this.WindowState = FormWindowState.Minimized;
  376. }
  377. private void pbMax_Click(object sender, EventArgs e)
  378. {
  379. if (this.WindowState == FormWindowState.Maximized)
  380. {
  381. this.WindowState = FormWindowState.Normal;
  382. }
  383. else
  384. {
  385. this.WindowState = FormWindowState.Maximized;
  386. }
  387. //窗体据中
  388. this.StartPosition = FormStartPosition.CenterScreen;
  389. }
  390. #endregion
  391. #region 新建、保存、打开、初始化、导入配置、查看日志
  392. private void pbNew_Click(object sender, EventArgs e)
  393. {
  394. m_MeasureFile.MParam.GetMeasureParamFromConfigration();
  395. }
  396. private void pbSave_Click(object sender, EventArgs e)
  397. {
  398. Saveclick();
  399. }
  400. public void Saveclick()
  401. {
  402. }
  403. private void pbOpen_Click(object sender, EventArgs e)
  404. {
  405. try
  406. {
  407. //打开默认路径
  408. OpenFileDialog openFileDialog = new OpenFileDialog();
  409. //设置筛选文件格式
  410. openFileDialog.Filter = "测量文件(*.msf)|*.msf";
  411. if (openFileDialog.ShowDialog() == DialogResult.OK)
  412. {
  413. //读取文件
  414. string measureFileNamePath = openFileDialog.FileName;
  415. m_MeasureFile.FileName = measureFileNamePath;
  416. m_MeasureFile.Open();
  417. List<CutHole> ListCutHole = m_MeasureFile.ListCutHole;
  418. //文件路径
  419. string CutHoleFilePath = m_MeasureFile.CutHoleFilePath;
  420. CreateCutHoleList(ListCutHole);
  421. ////保存测量文件
  422. //m_MeasureFile.Save();
  423. //设置已保存状态
  424. IsSave = true;
  425. }
  426. }
  427. catch (Exception ex)
  428. {
  429. log.Error(ex.Message);
  430. }
  431. }
  432. private void pbInit_Click(object sender, EventArgs e)
  433. {
  434. if (uControl_Init == null)
  435. {
  436. uControl_Init = new UControl_Init(this);
  437. //uControl_Init.ReloadConfig();
  438. }
  439. if (m_FormInit == null)
  440. {
  441. m_FormInit = new FormMove();
  442. }
  443. m_FormInit.StartPosition = FormStartPosition.CenterScreen;
  444. m_FormInit.FormBorderStyle = FormBorderStyle.None;
  445. m_FormInit.Width = uControl_Init.Width + 8;
  446. m_FormInit.Height = uControl_Init.Height + 8;
  447. if (m_FormInit.Controls.Count == 0)
  448. {
  449. uControl_Init.Location = new Point(4,4);
  450. m_FormInit.Controls.Add(uControl_Init);
  451. }
  452. m_FormInit.ShowDialog();
  453. //ConfigurationParameter();
  454. m_FormInit.Left = this.Left;
  455. }
  456. private void pictureBox1_Click(object sender, EventArgs e)
  457. {
  458. }
  459. private void pbImportTemplateFile_Click(object sender, EventArgs e)
  460. {
  461. Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  462. string m_TemplateFilePath = config.AppSettings.Settings["TemplateFilePath"].Value.ToString();
  463. //判断保存的路径是否存在
  464. if (!Directory.Exists(m_TemplateFilePath))
  465. {
  466. ////创建路径
  467. //Directory.CreateDirectory(m_TemplateFilePath);
  468. FolderBrowserDialog dialog = new FolderBrowserDialog();
  469. dialog.Description = "请选择文件路径";
  470. //dialog.RootFolder = Environment.SpecialFolder.Programs;
  471. if (dialog.ShowDialog() == DialogResult.OK)
  472. {
  473. m_TemplateFilePath = dialog.SelectedPath;
  474. config.AppSettings.Settings["TemplateFilePath"].Value = m_TemplateFilePath;
  475. config.Save(ConfigurationSaveMode.Modified);
  476. ConfigurationManager.RefreshSection("appSettings");//重新加载新的配置文件
  477. }
  478. }
  479. //打开默认路径
  480. OpenFileDialog openFileDialog = new OpenFileDialog();
  481. //设置默认打开路径(绝对路径)
  482. openFileDialog.InitialDirectory = m_TemplateFilePath;
  483. openFileDialog.Filter = "样品参数文件|*.cfg";
  484. if (openFileDialog.ShowDialog() == DialogResult.OK)
  485. {
  486. if (uControl_Init == null)
  487. {
  488. uControl_Init = new UControl_Init(this);
  489. }
  490. //设置选择的模板文件
  491. uControl_Init.ReadConfigPath = openFileDialog.FileName;
  492. //获取文件
  493. uControl_Init.ReadConfigInfo();
  494. }
  495. }
  496. private void pbLog_Click(object sender, EventArgs e)
  497. {
  498. }
  499. //显示日志
  500. private void AddLogListInfo(ThreadStatusEventArgs e)
  501. {
  502. if (m_FormLog != null)
  503. {
  504. foreach (Control item in m_FormLog.Controls)
  505. {
  506. if (item is UserControl)
  507. {
  508. if (item.Name == "UControl_Log")
  509. {
  510. ucLog = (UControl_Log)item;
  511. //获取日志信息
  512. if (listmsg.Items.Count > 0)
  513. {
  514. string[] strLog = new string[listmsg.Items.Count];
  515. for (int i = 0; i < listmsg.Items.Count; i++)
  516. {
  517. //赋值给数组
  518. strLog[i] = listmsg.Items[i].ToString();
  519. }
  520. ucLog.ShowProcessLogInfo(strLog);
  521. }
  522. }
  523. }
  524. }
  525. }
  526. }
  527. #endregion
  528. #region 修改切孔状态
  529. /// <summary>
  530. /// 修改切孔状态
  531. /// </summary>
  532. /// <param name="cutHoleCode"></param>
  533. /// <param name="States"></param>
  534. public void ChangeCutHoleState(string CutHoleName, int States)
  535. {
  536. foreach (Control item in plLeftContent.Controls)
  537. {
  538. if (item is UserControl)
  539. {
  540. UControl_CutHole cutHole = (UControl_CutHole)item;
  541. if (cutHole.CutHoleName == CutHoleName)
  542. {
  543. Button btnCutHole = (Button)cutHole.Controls.Find("btnCutHole", false)[0];
  544. switch (States)
  545. {
  546. //运行中
  547. case (int)MeasureThread.ThreadState.InProcess:
  548. //btnCutHole.BackColor = Color.Yellow;
  549. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Yellow_2_;
  550. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  551. ChangeCutHoleMeasureState(CutHoleName, States);
  552. ControlFlicker = true;
  553. break;
  554. //等待
  555. case (int)MeasureThread.ThreadState.Waiting:
  556. //btnCutHole.BackColor = Color.Yellow;
  557. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Yellow_2_;
  558. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  559. ChangeCutHoleMeasureState(CutHoleName, States);
  560. break;
  561. //准备
  562. case (int)MeasureThread.ThreadState.Ready:
  563. //btnCutHole.BackColor = Color.White;
  564. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Gray_2_;
  565. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  566. ChangeCutHoleMeasureState(CutHoleName, States);
  567. break;
  568. //失败
  569. case (int)MeasureThread.ThreadState.Failed:
  570. //btnCutHole.BackColor = Color.Red;
  571. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Red_2_;
  572. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  573. ChangeCutHoleMeasureState(CutHoleName, States);
  574. ControlFlicker = false;
  575. break;
  576. //完成
  577. case (int)MeasureThread.ThreadState.Success:
  578. //btnCutHole.BackColor = Color.GreenYellow;
  579. btnCutHole.BackgroundImage = Properties.Resources.CutHole_Green_2_;
  580. btnCutHole.BackgroundImageLayout = ImageLayout.Center;
  581. //修改切孔状态
  582. ChangeCutHoleMeasureState(CutHoleName, States);
  583. ControlFlicker = false;
  584. break;
  585. }
  586. break;
  587. }
  588. }
  589. }
  590. }
  591. #endregion
  592. #region 修改切孔状态
  593. public void ChangeCutHoleMeasureState(string CutHoleName, int States)
  594. {
  595. if (plPrarInfo.Controls.Count > 0)
  596. {
  597. foreach (Control item in plPrarInfo.Controls)
  598. {
  599. if (item is UserControl)
  600. {
  601. if (item.Name == CutHoleName)
  602. {
  603. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  604. //获取切孔列表
  605. List<CutHole> aCutHole = m_MeasureFile.ListCutHole;
  606. foreach (CutHole cutHoleItem in aCutHole)
  607. {
  608. if (cutHoleItem.HoleName == CutHoleName)
  609. {
  610. //设置开始时间与结束时间
  611. uControl_ParaInfo.StartTime = cutHoleItem.START.ToString();
  612. uControl_ParaInfo.EndTime = cutHoleItem.END.ToString();
  613. uControl_ParaInfo.ShowTime();
  614. break;
  615. }
  616. }
  617. switch (States)
  618. {
  619. //准备
  620. case (int)MeasureThread.ThreadState.Ready:
  621. //修改切孔状态
  622. uControl_ParaInfo.lblShowState.Text = "准备";
  623. break;
  624. //等待
  625. case (int)MeasureThread.ThreadState.Waiting:
  626. //修改切孔状态
  627. uControl_ParaInfo.lblShowState.Text = "等待";
  628. break;
  629. //进行中
  630. case (int)MeasureThread.ThreadState.InProcess:
  631. //修改切孔状态
  632. uControl_ParaInfo.lblShowState.Text = "进行中";
  633. break;
  634. //完成
  635. case (int)MeasureThread.ThreadState.Success:
  636. //修改切孔状态
  637. uControl_ParaInfo.lblShowState.Text = "完成";
  638. break;
  639. //失败
  640. case (int)MeasureThread.ThreadState.Failed:
  641. uControl_ParaInfo.lblShowState.Text = "失败";
  642. uControl_ParaInfo.pbMeasure.Value = 100;
  643. uControl_ParaInfo.lblCompletedAmount.Text = "100%";
  644. break;
  645. }
  646. break;
  647. }
  648. }
  649. }
  650. }
  651. }
  652. #endregion
  653. #region 拖动无窗体的控件
  654. [DllImport("user32.dll")]//拖动无窗体的控件
  655. public static extern bool ReleaseCapture();
  656. [DllImport("user32.dll")]
  657. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  658. public const int WM_SYSCOMMAND = 0x0112;
  659. public const int SC_MOVE = 0xF010;
  660. public const int HTCAPTION = 0x0002;
  661. private void FormHOZMain_MouseDown(object sender, MouseEventArgs e)
  662. {
  663. if (this.WindowState == FormWindowState.Normal)
  664. {
  665. //拖动窗体
  666. ReleaseCapture();
  667. SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
  668. }
  669. }
  670. #endregion
  671. #region 开始、结束线程事件
  672. private void pbStart_Click(object sender, EventArgs e)
  673. {
  674. if (plLeftContent.Controls.Count==0)
  675. {
  676. MessageBox.Show("请添加切孔信息!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  677. return;
  678. }
  679. if (IsSave)
  680. {
  681. if (m_BackgroundWorker.IsBusy)
  682. {
  683. MessageBox.Show("线程已经运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  684. return;
  685. }
  686. else
  687. {
  688. log.Info("开始", true);
  689. m_BackgroundWorker.RunWorkerAsync(this);
  690. //设置控件操作
  691. SetWinControlMeasureState(false);
  692. pbStop.Visible = true;
  693. pbStart.Visible = false;
  694. }
  695. }
  696. else
  697. {
  698. MessageBox.Show("请保存当前测量文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  699. return;
  700. }
  701. }
  702. private void pbStop_Click(object sender, EventArgs e)
  703. {
  704. if (m_Ms != null)
  705. {
  706. if (MessageBox.Show("是否停止当前测量?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)== DialogResult.Yes)
  707. {
  708. ControlFlicker = false;
  709. //线程停止变量
  710. m_Ms.key_stop = true;
  711. }
  712. }
  713. }
  714. #endregion
  715. #region 清空内容容器中的控件
  716. /// <summary>
  717. /// 清空内容容器中的控件
  718. /// </summary>
  719. private void ClearPanelControls()
  720. {
  721. //清空内容容器中的控件
  722. plLeftContent.Controls.Clear();
  723. plPrarInfo.Controls.Clear();
  724. }
  725. /// <summary>
  726. /// 清空日志控件内容
  727. /// </summary>
  728. private void ClearContrlsContent()
  729. {
  730. try
  731. {
  732. if (ucLog != null)
  733. {
  734. if (ucLog.dgvLog != null)
  735. {
  736. if (ucLog.dgvLog.Rows.Count > 0)
  737. {
  738. ucLog.dgvLog.Rows.Clear();
  739. }
  740. }
  741. }
  742. if (listmsg != null)
  743. {
  744. if (listmsg.Items.Count > 0)
  745. {
  746. listmsg.Items.Clear();
  747. }
  748. }
  749. }
  750. catch (Exception ex)
  751. {
  752. log.Error(ex.Message);
  753. }
  754. }
  755. #endregion
  756. #region 测试修改切孔中流程状态
  757. private void button1_Click(object sender, EventArgs e)
  758. {
  759. if (plPrarInfo.Controls.Count > 0)
  760. {
  761. string name = textBox1.Text;
  762. string code = textBox2.Text;
  763. bool state = Convert.ToBoolean(comboBox1.Text);
  764. foreach (Control item in plPrarInfo.Controls)
  765. {
  766. if (item is UserControl)
  767. {
  768. if (item.Name == name)
  769. {
  770. UControl_ParaInfo uControl_ParaInfo = (UControl_ParaInfo)item;
  771. TimeLineItem[] ParaItem = uControl_ParaInfo.TlItem;
  772. foreach (TimeLineItem tlItem in ParaItem)
  773. {
  774. if (tlItem.Code == code)
  775. {
  776. tlItem.State = Convert.ToInt32(state);
  777. break;
  778. }
  779. }
  780. uControl_ParaInfo.TimeLineInvalidate();
  781. break;
  782. }
  783. }
  784. }
  785. }
  786. }
  787. #endregion
  788. private void FormHOZMain_Resize(object sender, EventArgs e)
  789. {
  790. plMain.Left = 2;
  791. plMain.Top = 2;
  792. plMain.Width = this.Width - 4;
  793. plMain.Height = this.Height - 4;
  794. plFill.Width = plMain.Width - plLeft.Width - 4;
  795. plFill.Height = plMain.Height - plTop.Height - 4;
  796. plFill.Left = plLeft.Width + 4;
  797. plFill.Top = plTop.Height + 4;
  798. if(this.WindowState!= FormWindowState.Maximized)
  799. {
  800. plPrarInfo.Height = 505;
  801. foreach (Control item in plPrarInfo.Controls)
  802. {
  803. if (item is UserControl)
  804. {
  805. if(item.Height>505)
  806. {
  807. item.Height = 505;
  808. }
  809. }
  810. }
  811. }
  812. }
  813. private void FormHOZMain_Paint(object sender, PaintEventArgs e)
  814. {
  815. }
  816. private void FormHOZMain_FormClosing(object sender, FormClosingEventArgs e)
  817. {
  818. if (m_Ms != null)
  819. {
  820. if (m_Ms.iExtender != null)
  821. {
  822. m_Ms.iExtender.CloseExtender();
  823. }
  824. }
  825. }
  826. private void FormHOZMain_LocationChanged(object sender, EventArgs e)
  827. {
  828. if (logwin != null)
  829. {
  830. logwin.Left = this.Left-logwin.Width;
  831. logwin.Top = this.Top;
  832. }
  833. }
  834. private void pbPause_Click(object sender, EventArgs e)
  835. {
  836. if (File.Exists(m_MeasureFile.m_SavePath))
  837. {
  838. string position = System.Environment.CurrentDirectory;
  839. //Process pro = Process.Start(@"C:\Users\admin\Desktop\Report\Report\ExportReport.exe", @"C:\Users\admin\Downloads\3\3\3.msf");//打开程序B
  840. Process pro = Process.Start(position + "\\Report\\ExportReport.exe", m_MeasureFile.m_SavePath);//打开程序B
  841. pro.WaitForExit();
  842. int Result = pro.ExitCode;//程序B退出回传值
  843. if (Result == 1)//接收到程序B退出代码"1"
  844. {
  845. MessageBox.Show("退出程序B");
  846. }
  847. }
  848. else
  849. {
  850. MessageBox.Show("尚未保存文件");
  851. }
  852. }
  853. }
  854. }