UControl_ParaInfo.cs 12 KB

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