FormHOZMain.cs 36 KB

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