UControl_ParaInfo.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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 uCTimeLine = 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. #region 显示开始与结束时间
  60. public void ShowTime()
  61. {
  62. if (StartTime == "0001/1/1 0:00:00")
  63. {
  64. lblShowStartTime.Text = "";
  65. }
  66. else
  67. {
  68. lblShowStartTime.Text = StartTime;
  69. }
  70. if (EndTime == "0001/1/1 0:00:00")
  71. {
  72. lblShowEndTime.Text = "";
  73. }
  74. else
  75. {
  76. lblShowEndTime.Text = EndTime;
  77. }
  78. }
  79. #endregion
  80. #region 当前进度
  81. public void UpdateCurrentMeasureSchedule()
  82. {
  83. if (TlItem != null)
  84. {
  85. //完成状态数量
  86. int finishCount = 0;
  87. //未完成状态数量
  88. int unFinishedCount = 0;
  89. foreach (TimeLineItem item in TlItem)
  90. {
  91. if (item.State>0)
  92. {
  93. finishCount++;
  94. }
  95. switch (FormHOZMainObject.m_MeasureType)
  96. {
  97. case (int)MeasureMsgManage.measureType.Photo:
  98. if (item.Type.ToUpper() == "PT" || item.Type.ToUpper() == "FIB")
  99. {
  100. continue;
  101. }
  102. else
  103. {
  104. unFinishedCount++;
  105. }
  106. break;
  107. case (int)MeasureMsgManage.measureType.FIB:
  108. if (item.Type.ToUpper() == "PT")
  109. {
  110. continue;
  111. }
  112. else
  113. {
  114. unFinishedCount++;
  115. }
  116. break;
  117. case (int)MeasureMsgManage.measureType.PT:
  118. unFinishedCount = TlItem.Length;
  119. break;
  120. }
  121. }
  122. try
  123. {
  124. if (lblShowState.Text == "失败")
  125. {
  126. pbMeasure.Value = 100;
  127. lblCompletedAmount.Text = "100%";
  128. }
  129. else
  130. {
  131. int pbValue = (int)((float)finishCount / (float)unFinishedCount * 100);
  132. pbMeasure.Value = pbValue;
  133. lblCompletedAmount.Text = pbValue + "%";
  134. }
  135. }
  136. //try
  137. //{
  138. // int pbValue = (int)((float)finishCount / (float)unFinishedCount*100);
  139. // pbMeasure.Value = pbValue;
  140. // lblCompletedAmount.Text = pbValue + "%";
  141. //}
  142. catch (Exception)
  143. {
  144. pbMeasure.Value = 0;
  145. }
  146. }
  147. }
  148. #endregion
  149. #region 隐藏属性层
  150. private void btnClose_Click(object sender, EventArgs e)
  151. {
  152. FormHOZMainObject.plPrarInfo.Visible = false;
  153. }
  154. #endregion
  155. #region 重绘时间轴
  156. /// <summary>
  157. /// 重绘时间轴
  158. /// </summary>
  159. public void TimeLineInvalidate()
  160. {
  161. plTimeLine.Invalidate();
  162. uCTimeLine.Invalidate();
  163. //FormHOZMain.ControlFlicker = true;
  164. }
  165. #endregion
  166. #region 显示切孔参数信息
  167. /// <summary>
  168. /// 显示切孔参数信息
  169. /// </summary>
  170. public void ShowParaInfo()
  171. {
  172. int multiple = 1000;
  173. //设置Position参数
  174. lblX.Text = (Position.X * multiple).ToString("f2");
  175. lblY.Text = (Position.Y * multiple).ToString("f2");
  176. lblZ.Text = (Position.Z * multiple).ToString("f2");
  177. lblR.Text = Position.R.ToString();
  178. lblT.Text = Position.T.ToString();
  179. lblM.Text = (Position.M * multiple).ToString();
  180. try
  181. {
  182. DateTime dtst = Convert.ToDateTime(StartTime);
  183. if (dtst.Year != System.DateTime.Now.Year)
  184. {
  185. lblShowStartTime.Text = "";
  186. }
  187. else
  188. {
  189. lblShowStartTime.Text = StartTime;
  190. }
  191. }
  192. catch
  193. {
  194. lblShowStartTime.Text = "";
  195. }
  196. try
  197. {
  198. DateTime dtet = Convert.ToDateTime(EndTime);
  199. if (dtet.Year != System.DateTime.Now.Year)
  200. {
  201. lblShowEndTime.Text = "";
  202. }
  203. else
  204. {
  205. lblShowEndTime.Text = EndTime;
  206. }
  207. }
  208. catch
  209. {
  210. lblShowEndTime.Text = "";
  211. }
  212. //设置切孔状态
  213. switch (State)
  214. {
  215. //准备
  216. case (int)MeasureThread.ThreadState.Ready:
  217. //修改切孔状态
  218. lblShowState.Text = "准备";
  219. break;
  220. //等待
  221. case (int)MeasureThread.ThreadState.Waiting:
  222. //修改切孔状态
  223. lblShowState.Text = "等待";
  224. break;
  225. //进行中
  226. case (int)MeasureThread.ThreadState.InProcess:
  227. //修改切孔状态
  228. lblShowState.Text = "进行中";
  229. break;
  230. //完成
  231. case (int)MeasureThread.ThreadState.Success:
  232. //修改切孔状态
  233. lblShowState.Text = "完成";
  234. break;
  235. //失败
  236. case (int)MeasureThread.ThreadState.Failed:
  237. lblShowState.Text = "失败";
  238. break;
  239. }
  240. lblCutHoleName.Text = CutHoleName;
  241. CkIsSwitch.Checked = IsSwitch;
  242. }
  243. #endregion
  244. #region 绑定流程信息
  245. /// <summary>
  246. /// 绑定流程信息
  247. /// </summary>
  248. /// <param name="flowCode"></param>
  249. private void ShowMeasureFlow()
  250. {
  251. if (TlItem == null)
  252. {
  253. TlItem = GetMeasureFlowStructInfo();
  254. }
  255. if (TlItem != null)
  256. {
  257. ShowUCTimeLine(TlItem);
  258. }
  259. }
  260. public void ShowUCTimeLine(TimeLineItem[] tlItem)
  261. {
  262. if (plTimeLine.Controls.Count == 0)
  263. {
  264. uCTimeLine = new UCTimeLine(tlItem, FormHOZMainObject.m_MeasureType);
  265. uCTimeLine.Dock = DockStyle.Fill;
  266. plTimeLine.Controls.Add(uCTimeLine);
  267. }
  268. }
  269. private TimeLineItem[] GetMeasureFlowStructInfo()
  270. {
  271. string xmlfullname = Application.StartupPath + @"\MeasureXML\MeasureStructXml.xml";
  272. XmlNodeList nodeList = XmlManager.GetXmlMeasureFlowNodeInfo(xmlfullname);
  273. if (nodeList != null)
  274. {
  275. return XmlConvertTimeListItem(nodeList);
  276. }
  277. return null;
  278. }
  279. private TimeLineItem[] XmlConvertTimeListItem(XmlNodeList nodeList)
  280. {
  281. List<TimeLineItem> timeLineList = new List<TimeLineItem>();
  282. for (int i = 0; i < nodeList.Count; i++)
  283. {
  284. if (Convert.ToBoolean(nodeList[i].Attributes["IsShow"].Value))
  285. {
  286. TimeLineItem tlItem = new TimeLineItem();
  287. tlItem.Details = nodeList[i].Attributes["Details"].Value;
  288. tlItem.Code = nodeList[i].Attributes["Code"].Value;
  289. tlItem.State = -1;
  290. tlItem.Title = nodeList[i].Attributes["Title"].Value;
  291. tlItem.IsData = Convert.ToBoolean(nodeList[i].Attributes["IsData"].Value);
  292. tlItem.Type = nodeList[i].Attributes["Type"].Value;
  293. tlItem.IsShow = Convert.ToBoolean(nodeList[i].Attributes["IsShow"].Value);
  294. tlItem.Index = Convert.ToInt32(nodeList[i].Attributes["Index"].Value);
  295. timeLineList.Add(tlItem);
  296. }
  297. }
  298. TimeLineItem[] timeLineItem = new TimeLineItem[timeLineList.Count];
  299. //按照Index进行升序
  300. timeLineItem = timeLineList.OrderBy(i => i.Index).ToArray();
  301. //清空时间轴列表
  302. timeLineList.Clear();
  303. return timeLineItem;
  304. }
  305. #endregion
  306. #region 关闭按钮 鼠标操作事件
  307. private void pbClose_MouseEnter(object sender, EventArgs e)
  308. {
  309. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  310. }
  311. private void pbClose_MouseLeave(object sender, EventArgs e)
  312. {
  313. pbClose.BackgroundImage = global::HOZProject.Properties.Resources.exit_2_;
  314. }
  315. #endregion
  316. #region 设置切孔是否检测
  317. private void CkIsSwitch_CheckedChanged(object sender, EventArgs e)
  318. {
  319. //设置切孔是否检测
  320. List<CutHole> cutHoles = formHOZMain.m_MeasureFile.ListCutHole;
  321. foreach (CutHole item in cutHoles)
  322. {
  323. if (item.HoleName == CutHoleName)
  324. {
  325. item.SWITCH = CkIsSwitch.Checked;
  326. //是否已保存
  327. if (formHOZMain.IsSave)
  328. {
  329. //保存测量文件
  330. formHOZMain.m_MeasureFile.Save();
  331. }
  332. break;
  333. }
  334. }
  335. }
  336. #endregion
  337. private void timerTwinkle_Tick(object sender, EventArgs e)
  338. {
  339. uCTimeLine.Invalidate();
  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. }