UControl_ParaInfo.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using MeasureData;
  11. using FileManager;
  12. using System.Xml;
  13. namespace HOZProject
  14. {
  15. public partial class UControl_ParaInfo : UserControl
  16. {
  17. #region 成员变量
  18. /// <summary>
  19. /// 开始时间
  20. /// </summary>
  21. private string startTime;
  22. /// <summary>
  23. /// 结束时间
  24. /// </summary>
  25. private string endTime;
  26. /// <summary>
  27. /// 状态
  28. /// </summary>
  29. private int state;
  30. /// <summary>
  31. /// 位置
  32. /// </summary>
  33. private SemPosition position;
  34. private bool isSwitch;
  35. private string cutHoleName;
  36. private FormHOZMain formHOZMain;
  37. private TimeLineItem[] tlItem = null;
  38. private UCTimeLine uctrlTimeLine = null;
  39. public FormHOZMain FormHOZMainObject { get => formHOZMain; set => formHOZMain = value; }
  40. public string StartTime { get => startTime; set => startTime = value; }
  41. public string EndTime { get => endTime; set => endTime = value; }
  42. public int State { get => state; set => state = value; }
  43. public SemPosition Position { get => position; set => position = value; }
  44. public string CutHoleName { get => cutHoleName; set => cutHoleName = value; }
  45. public bool IsSwitch { get => isSwitch; set => isSwitch = value; }
  46. public TimeLineItem[] TlItem { get => tlItem; set => tlItem = value; }
  47. #endregion
  48. public UControl_ParaInfo(FormHOZMain formHOZ)
  49. {
  50. InitializeComponent();
  51. FormHOZMainObject = formHOZ;
  52. //显示测量流程
  53. ShowMeasureFlow();
  54. //设置Style支持透明背景色
  55. this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  56. //this.BackColor = Color.FromArgb(0, 255, 255, 255);
  57. //this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(192)), ((System.Byte)(192)));
  58. }
  59. public UCTimeLine GetUctrTimeLine()
  60. {
  61. return uctrlTimeLine;
  62. }
  63. #region 显示开始与结束时间
  64. public void ShowTime()
  65. {
  66. if (StartTime == "0001/1/1 0:00:00")
  67. {
  68. lblShowStartTime.Text = "";
  69. }
  70. else
  71. {
  72. lblShowStartTime.Text = StartTime;
  73. }
  74. if (EndTime == "0001/1/1 0:00:00")
  75. {
  76. lblShowEndTime.Text = "";
  77. }
  78. else
  79. {
  80. lblShowEndTime.Text = EndTime;
  81. }
  82. }
  83. #endregion
  84. #region 当前进度
  85. public void UpdateCurrentMeasureSchedule()
  86. {
  87. if (TlItem != null)
  88. {
  89. //完成状态数量
  90. int finishCount = 0;
  91. //未完成状态数量
  92. int unFinishedCount = 0;
  93. foreach (TimeLineItem item in TlItem)
  94. {
  95. if (item.State>0)
  96. {
  97. finishCount++;
  98. }
  99. switch (FormHOZMainObject.m_MeasureType)
  100. {
  101. case (int)MeasureMsgManage.measureType.Photo:
  102. if (item.Type.ToUpper() == "PT" || item.Type.ToUpper() == "FIB")
  103. {
  104. continue;
  105. }
  106. else
  107. {
  108. unFinishedCount++;
  109. }
  110. break;
  111. case (int)MeasureMsgManage.measureType.FIB:
  112. if (item.Type.ToUpper() == "PT")
  113. {
  114. continue;
  115. }
  116. else
  117. {
  118. unFinishedCount++;
  119. }
  120. break;
  121. case (int)MeasureMsgManage.measureType.PT:
  122. unFinishedCount = TlItem.Length;
  123. break;
  124. }
  125. }
  126. try
  127. {
  128. if (lblShowState.Text == "失败")
  129. {
  130. pbMeasure.Value = 100;
  131. lblCompletedAmount.Text = "100%";
  132. }
  133. else
  134. {
  135. int pbValue = (int)((float)finishCount / (float)unFinishedCount * 100);
  136. pbMeasure.Value = pbValue;
  137. lblCompletedAmount.Text = pbValue + "%";
  138. }
  139. }
  140. catch (Exception)
  141. {
  142. pbMeasure.Value = 0;
  143. }
  144. }
  145. }
  146. #endregion
  147. #region 隐藏属性层
  148. private void btnClose_Click(object sender, EventArgs e)
  149. {
  150. FormHOZMainObject.plPrarInfo.Visible = false;
  151. }
  152. #endregion
  153. #region 重绘时间轴
  154. /// <summary>
  155. /// 重绘时间轴
  156. /// </summary>
  157. public void TimeLineInvalidate()
  158. {
  159. plTimeLine.Invalidate();
  160. uctrlTimeLine.Invalidate();
  161. }
  162. #endregion
  163. #region 显示切孔参数信息
  164. /// <summary>
  165. /// 显示切孔参数信息
  166. /// </summary>
  167. public void ShowParaInfo()
  168. {
  169. int multiple = 1000;
  170. //设置Position参数
  171. lblX.Text = (Position.X * multiple).ToString("f2");
  172. lblY.Text = (Position.Y * multiple).ToString("f2");
  173. lblZ.Text = (Position.Z * multiple).ToString("f2");
  174. lblR.Text = Position.R.ToString();
  175. lblT.Text = Position.T.ToString();
  176. lblM.Text = (Position.M * multiple).ToString();
  177. try
  178. {
  179. DateTime dtst = Convert.ToDateTime(StartTime);
  180. if (dtst.Year != System.DateTime.Now.Year)
  181. {
  182. lblShowStartTime.Text = "";
  183. }
  184. else
  185. {
  186. lblShowStartTime.Text = StartTime;
  187. }
  188. }
  189. catch
  190. {
  191. lblShowStartTime.Text = "";
  192. }
  193. try
  194. {
  195. DateTime dtet = Convert.ToDateTime(EndTime);
  196. if (dtet.Year != System.DateTime.Now.Year)
  197. {
  198. lblShowEndTime.Text = "";
  199. }
  200. else
  201. {
  202. lblShowEndTime.Text = EndTime;
  203. }
  204. }
  205. catch
  206. {
  207. lblShowEndTime.Text = "";
  208. }
  209. //设置切孔状态
  210. switch (State)
  211. {
  212. //准备
  213. case (int)MeasureThread.ThreadState.Ready:
  214. //修改切孔状态
  215. lblShowState.Text = "准备";
  216. break;
  217. //等待
  218. case (int)MeasureThread.ThreadState.Waiting:
  219. //修改切孔状态
  220. lblShowState.Text = "等待";
  221. break;
  222. //进行中
  223. case (int)MeasureThread.ThreadState.InProcess:
  224. //修改切孔状态
  225. lblShowState.Text = "进行中";
  226. break;
  227. //完成
  228. case (int)MeasureThread.ThreadState.Success:
  229. //修改切孔状态
  230. lblShowState.Text = "完成";
  231. break;
  232. //失败
  233. case (int)MeasureThread.ThreadState.Failed:
  234. lblShowState.Text = "失败";
  235. break;
  236. }
  237. lblCutHoleName.Text = CutHoleName;
  238. CkIsSwitch.Checked = IsSwitch;
  239. }
  240. #endregion
  241. #region 绑定流程信息
  242. /// <summary>
  243. /// 绑定流程信息
  244. /// </summary>
  245. /// <param name="flowCode"></param>
  246. private void ShowMeasureFlow()
  247. {
  248. if (TlItem == null)
  249. {
  250. TlItem = GetMeasureFlowStructInfo();
  251. }
  252. if (TlItem != null)
  253. {
  254. ShowUCTimeLine(TlItem);
  255. }
  256. }
  257. public void ShowUCTimeLine(TimeLineItem[] tlItem)
  258. {
  259. if (plTimeLine.Controls.Count == 0)
  260. {
  261. uctrlTimeLine = new UCTimeLine(tlItem, FormHOZMainObject.m_MeasureType);
  262. uctrlTimeLine.Dock = DockStyle.Fill;
  263. plTimeLine.Controls.Add(uctrlTimeLine);
  264. }
  265. }
  266. private TimeLineItem[] GetMeasureFlowStructInfo()
  267. {
  268. string xmlfullname = Application.StartupPath + @"\MeasureXML\MeasureStructXml.xml";
  269. XmlNodeList nodeList = XmlManager.GetXmlMeasureFlowNodeInfo(xmlfullname);
  270. if (nodeList != null)
  271. {
  272. return XmlConvertTimeListItem(nodeList);
  273. }
  274. return null;
  275. }
  276. private TimeLineItem[] XmlConvertTimeListItem(XmlNodeList nodeList)
  277. {
  278. List<TimeLineItem> timeLineList = new List<TimeLineItem>();
  279. for (int i = 0; i < nodeList.Count; i++)
  280. {
  281. if (Convert.ToBoolean(nodeList[i].Attributes["IsShow"].Value))
  282. {
  283. TimeLineItem tlItem = new TimeLineItem();
  284. tlItem.Details = nodeList[i].Attributes["Details"].Value;
  285. tlItem.Code = nodeList[i].Attributes["Code"].Value;
  286. tlItem.State = -1;
  287. tlItem.Title = nodeList[i].Attributes["Title"].Value;
  288. tlItem.IsData = Convert.ToBoolean(nodeList[i].Attributes["IsData"].Value);
  289. tlItem.Type = nodeList[i].Attributes["Type"].Value;
  290. tlItem.IsShow = Convert.ToBoolean(nodeList[i].Attributes["IsShow"].Value);
  291. tlItem.Index = Convert.ToInt32(nodeList[i].Attributes["Index"].Value);
  292. timeLineList.Add(tlItem);
  293. }
  294. }
  295. TimeLineItem[] timeLineItem = new TimeLineItem[timeLineList.Count];
  296. //按照Index进行升序
  297. timeLineItem = timeLineList.OrderBy(i => i.Index).ToArray();
  298. //清空时间轴列表
  299. timeLineList.Clear();
  300. return timeLineItem;
  301. }
  302. #endregion
  303. #region 关闭按钮 鼠标操作事件
  304. private void pbClose_MouseEnter(object sender, EventArgs e)
  305. {
  306. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  307. }
  308. private void pbClose_MouseLeave(object sender, EventArgs e)
  309. {
  310. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  311. }
  312. #endregion
  313. #region 设置切孔是否检测
  314. private void CkIsSwitch_CheckedChanged(object sender, EventArgs e)
  315. {
  316. //设置切孔是否检测
  317. List<CutHole> cutHoles = formHOZMain.m_MeasureFile.ListCutHole;
  318. foreach (CutHole item in cutHoles)
  319. {
  320. if (item.HoleName == CutHoleName)
  321. {
  322. item.SWITCH = CkIsSwitch.Checked;
  323. //是否已保存
  324. if (formHOZMain.IsSave)
  325. {
  326. //保存测量文件
  327. formHOZMain.m_MeasureFile.Save();
  328. }
  329. break;
  330. }
  331. }
  332. }
  333. #endregion
  334. private void timerTwinkle_Tick(object sender, EventArgs e)
  335. {
  336. if (FormHOZMain.ControlFlicker)
  337. {
  338. uctrlTimeLine.Invalidate();
  339. }
  340. }
  341. private void panel3_MouseMove(object sender, MouseEventArgs e)
  342. {
  343. if (formHOZMain.WindowState== FormWindowState.Maximized)
  344. {
  345. if (e.Button == MouseButtons.Left)
  346. {
  347. //plMeasureFlow.Height = Control.MousePosition.Y - plMeasureFlow.Location.Y -80;
  348. //this.Height = Control.MousePosition.Y - plMeasureFlow.Location.Y+78 ;
  349. //formHOZMain.plPrarInfo.Height = this.Height;
  350. int h = plMeasureFlow.Height + e.Y + panel1.Height + panel2.Height;
  351. if (h < 300 || h > formHOZMain.pbImage.Height)
  352. {
  353. return;
  354. }
  355. plMeasureFlow.Height = plMeasureFlow.Height + e.Y;
  356. this.Height = plMeasureFlow.Height + panel1.Height + panel2.Height;
  357. formHOZMain.plPrarInfo.Height = this.Height;
  358. }
  359. }
  360. else
  361. {
  362. if (e.Button == MouseButtons.Left)
  363. {
  364. //this.Height = 588;
  365. //plMeasureFlow.Height = Control.MousePosition.Y - plMeasureFlow.Location.Y - 210;
  366. //formHOZMain.plPrarInfo.Height = Control.MousePosition.Y - plMeasureFlow.Location.Y-53;
  367. int h = plMeasureFlow.Height + e.Y + panel1.Height + panel2.Height;
  368. if (h < 300 || h > formHOZMain.pbImage.Height)
  369. {
  370. return;
  371. }
  372. plMeasureFlow.Height = plMeasureFlow.Height + e.Y;
  373. this.Height = plMeasureFlow.Height + panel1.Height + panel2.Height;
  374. formHOZMain.plPrarInfo.Height = this.Height;
  375. }
  376. }
  377. }
  378. private void panel3_Paint(object sender, PaintEventArgs e)
  379. {
  380. }
  381. private void UControl_ParaInfo_Resize(object sender, EventArgs e)
  382. {
  383. this.plMeasureFlow.Top = panel1.Height + panel2.Height;
  384. this.plMeasureFlow.Height = this.Height - this.plMeasureFlow.Top;
  385. }
  386. }
  387. }