OTSMeasureResultWindow.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. using OTS.WinFormsUI.Docking;
  7. using System.IO;
  8. using System.Collections;
  9. using OTSDataType;
  10. using OTSModelSharp;
  11. namespace OTSMeasureApp
  12. {
  13. public partial class OTSMeasureResultWindow : DockContent
  14. {
  15. #region 全局变量
  16. OTSIncAMeasureAppForm m_MeasureAppForm;
  17. //进度条最大值
  18. int m_MaxValue = 100;
  19. //进度条最小值
  20. int m_MinValue = 0;
  21. //步长
  22. int m_Step = 1;
  23. //文件名称
  24. private string m_fileName = string.Empty;
  25. private bool m_resetText = true;
  26. //国际化
  27. OTSSysMgrTools.Language lan;
  28. Hashtable table;
  29. NLog.Logger log ;
  30. #endregion
  31. public OTSMeasureResultWindow(OTSIncAMeasureAppForm MeasureAppForm)
  32. {
  33. InitializeComponent();
  34. m_MeasureAppForm = MeasureAppForm;
  35. //国际化
  36. lan = new OTSSysMgrTools.Language(this);
  37. table = lan.GetNameTable(this.Name);
  38. }
  39. public string FileName
  40. {
  41. get { return m_fileName; }
  42. set
  43. {
  44. if (value != string.Empty)
  45. {
  46. Stream s = new FileStream(value, FileMode.Open);
  47. FileInfo efInfo = new FileInfo(value);
  48. string fext = efInfo.Extension.ToUpper();
  49. s.Close();
  50. }
  51. m_fileName = value;
  52. this.ToolTipText = value;
  53. }
  54. }
  55. protected override void OnPaint(PaintEventArgs e)
  56. {
  57. base.OnPaint(e);
  58. if (m_resetText)
  59. {
  60. m_resetText = false;
  61. FileName = FileName;
  62. }
  63. }
  64. protected override string GetPersistString()
  65. {
  66. String stName = GetType().ToString() + "," + FileName + "," + Text;
  67. return stName;
  68. }
  69. protected override void OnTextChanged(EventArgs e)
  70. {
  71. base.OnTextChanged(e);
  72. if (FileName == string.Empty)
  73. {
  74. //this.richTextBox1.Text = Text;
  75. return;
  76. }
  77. }
  78. private void OTSMeasureResultWindow_Load(object sender, EventArgs e)
  79. {
  80. this.dg_Info.AutoResizeColumns();
  81. //创建列
  82. this.dg_Info.AutoGenerateColumns = false;
  83. CheckForIllegalCrossThreadCalls = false;
  84. log = NLog.LogManager.GetCurrentClassLogger();
  85. }
  86. private void OTSMeasureResultWindow_SizeChanged(object sender, EventArgs e)
  87. {
  88. //获取屏幕的宽度与高度
  89. int width = this.Width;
  90. int height = this.Height;
  91. }
  92. /// <summary>
  93. /// 设置当前进度信息(当前帧图数量 总数)
  94. /// </summary>
  95. /// <param name="MeasureFieldCount"></param>
  96. /// <param name="CompleteFieldCount"></param>
  97. /// <returns></returns>
  98. public bool SetCurrentProgressInfo(int CompleteFieldCount, int MeasureFieldTotalCount, int ParticleCount)
  99. {
  100. //测量进度
  101. SetProgressInfo(CompleteFieldCount, MeasureFieldTotalCount, ParticleCount);
  102. return false;
  103. }
  104. /// <summary>
  105. /// 初始化 点击主窗体中新建按钮
  106. /// </summary>
  107. /// <returns></returns>
  108. public bool SetInit()
  109. {
  110. lblSampleName.Text = string.Empty;
  111. lblMeasureTime.Text = string.Empty;
  112. lblParticleCount.Text = string.Empty;
  113. lblBeginTime.Text = string.Empty;
  114. lblSingleCount.Text = string.Empty;
  115. lblProgressInfo.Text = "0%";
  116. PBState.Value = 0;
  117. dg_Info.DataSource = null;
  118. return true;
  119. }
  120. ///// <summary>
  121. ///// 设置当前帧图数
  122. ///// </summary>
  123. ///// <param name="fieldIndex"></param>
  124. ///// <returns></returns>
  125. //public bool SetCurrentData(string fieldIndex)
  126. //{
  127. // //获取当前数据
  128. // lblSingleCount.Text = fieldIndex.ToString();
  129. // return false;
  130. //}
  131. #region 显示操作
  132. /// <summary>
  133. /// 测量进度
  134. /// </summary>
  135. /// <param name="currentMeasureCount"></param>
  136. /// <param name="beginTime"></param>
  137. /// <param name="MeasureTime"></param>
  138. public void SetProgressInfo(int currentMeasureCount, int measureAllCount, int ParticleCount)
  139. {
  140. try
  141. {
  142. //设置进度条最大、最小、步长值
  143. PBState.Minimum = m_MinValue;
  144. PBState.Maximum = m_MaxValue;
  145. PBState.Step = m_Step;
  146. int currentProgress = m_MinValue;
  147. int currentMeasureCountAdd = currentMeasureCount;
  148. //设置当前帧图数
  149. lblSingleCount.Text = currentMeasureCount.ToString();
  150. if (currentMeasureCountAdd <= measureAllCount)
  151. {
  152. currentProgress = (currentMeasureCountAdd) * 100 / measureAllCount;
  153. }
  154. //设置当前进度值
  155. if (currentProgress < 100)
  156. {
  157. PBState.Value = currentProgress;
  158. lblProgressInfo.Text = currentProgress + "%";
  159. }
  160. else
  161. {
  162. lblProgressInfo.Text = currentProgress + "%";
  163. PBState.Value = 100;
  164. }
  165. //设置颗粒数量
  166. int pCount = ParticleCount;
  167. lblParticleCount.Text = (pCount).ToString();
  168. }
  169. catch (Exception ex)
  170. {
  171. log.Trace("OTSMeasureResultWindow_SetProgressInfo():" + ex.ToString());
  172. }
  173. }
  174. /// <summary>
  175. /// 设置样品名称
  176. /// </summary>
  177. /// <param name="sampleName"></param>
  178. public void SetSampleName(string sampleName)
  179. {
  180. //设置样品名称
  181. if (sampleName != null)
  182. {
  183. if (sampleName != "")
  184. {
  185. lblSampleName.Text = sampleName;
  186. }
  187. }
  188. }
  189. /// <summary>
  190. /// 设置开始时间
  191. /// </summary>
  192. /// <param name="startTime"></param>
  193. public void SetStartTime(string startTime)
  194. {
  195. if (startTime != null)
  196. {
  197. if (startTime != "")
  198. {
  199. try
  200. {
  201. //设置开始时间
  202. lblBeginTime.Text = startTime;
  203. }
  204. catch (Exception)
  205. {
  206. lblBeginTime.Text = "";
  207. }
  208. }
  209. }
  210. }
  211. /// <summary>
  212. /// 设置结束时间
  213. /// </summary>
  214. /// <param name="endTime"></param>
  215. public void CloseProgressWindow()
  216. {
  217. //this.Dispose();
  218. this.Close();
  219. }
  220. #endregion
  221. private void OTSMeasureResultWindow_FormClosing(object sender, FormClosingEventArgs e)
  222. {
  223. }
  224. #region 设置当前测量用时
  225. /// <summary>
  226. /// 设置当前测量用时
  227. /// </summary>
  228. /// <param name="ts">时间间隔对象</param>
  229. public void SetMeasureTime(TimeSpan ts)
  230. {
  231. //这样就能得到天数、小时、分差
  232. string str1 = string.Empty;
  233. if (ts.Days > 0)
  234. {
  235. string str = table["str1"].ToString();
  236. str1 += ts.Days + str;
  237. }
  238. if (ts.Hours > 0)
  239. {
  240. string str = table["str2"].ToString();
  241. str1 += ts.Hours + str;
  242. }
  243. if (ts.Minutes > 0)
  244. {
  245. string str = table["str3"].ToString();
  246. str1 += ts.Minutes + str;
  247. }
  248. if (ts.Seconds > 0)
  249. {
  250. string str = table["str4"].ToString();
  251. str1 += ts.Seconds + str;
  252. }
  253. //所有时间换去 总计天数、小时、分钟
  254. lblMeasureTime.Text = str1;
  255. }
  256. #endregion
  257. #region 设置当前测量列表
  258. /// <summary>
  259. /// 设置当前测量用时
  260. /// </summary>
  261. /// <param name="ts">时间间隔对象</param>
  262. public void SetMeasureListInfo(IList list)
  263. {
  264. try
  265. {
  266. //颗粒类型数量
  267. int IParticleTypeAmount = 0;
  268. //颗粒总数量
  269. int IParticleAmount = 0;
  270. //颗粒面积总数量
  271. double dAreaAmount = 0;
  272. COTSSample WSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
  273. //list 序列化 DataTable
  274. DataTable dt = ListConvertToDT(list);
  275. if (dt != null)
  276. {
  277. if (dt.Rows.Count > 0)
  278. {
  279. IParticleTypeAmount = dt.Rows.Count;
  280. string stdName = string.Empty;
  281. for (int i = 0; i < dt.Rows.Count; i++)
  282. {
  283. stdName = string.Empty;
  284. int STDID = Convert.ToInt32(dt.Rows[i]["TypeId"].ToString());
  285. IParticleAmount += Convert.ToInt32(dt.Rows[i]["Number"].ToString());
  286. dAreaAmount += Convert.ToDouble(dt.Rows[i]["Area"].ToString());
  287. }
  288. //添加统计行信息
  289. DataRow dr = dt.NewRow();
  290. dr["TypeId"] = "";
  291. dr["STDName"] = "";
  292. string str = table["str6"].ToString();
  293. dr["Number"] = str + IParticleAmount;
  294. str = table["str7"].ToString();
  295. dr["Area"] = str + dAreaAmount;
  296. dt.Rows.Add(dr);
  297. }
  298. dg_Info.DataSource = dt;
  299. }
  300. }
  301. catch (Exception ex)
  302. {
  303. string str = table["str8"].ToString();
  304. log.Trace(str + ex.ToString());
  305. }
  306. }
  307. #endregion
  308. #region List转换为DataTable
  309. /// <summary>
  310. /// 将集合类转换成DataTable
  311. /// </summary>
  312. /// <param name="list">集合</param>
  313. /// <returns></returns>
  314. public static DataTable ListConvertToDT(IList list)
  315. {
  316. DataTable result = new DataTable();
  317. result.Columns.Add("TypeId");
  318. result.Columns.Add("Number");
  319. result.Columns.Add("Area");
  320. result.Columns.Add("STDName");
  321. if (list == null)
  322. {
  323. return null;
  324. }
  325. if (list.Count > 0)
  326. {
  327. for (int i = 0; i < list.Count; i++)
  328. {
  329. CMsrResultItem cMsrResultItemClr = (CMsrResultItem)list[i];
  330. DataRow dr = result.NewRow();
  331. dr[0] = cMsrResultItemClr.GetTypeId();
  332. dr[1] = cMsrResultItemClr.GetNumber();
  333. dr[2] = Math.Round(Convert.ToDouble(cMsrResultItemClr.GetArea()),2);
  334. dr[3] = cMsrResultItemClr.GetName();
  335. result.Rows.Add(dr);
  336. }
  337. }
  338. return result;
  339. }
  340. #endregion
  341. public void GetResultFileInfoBySampleName(string sampleName)
  342. {
  343. //显示样品名称信息
  344. COTSSample sample = m_MeasureAppForm.m_ProjParam.m_ResultData.GetSampleByName(sampleName);
  345. //设置当前样品名称
  346. SetSampleName(sampleName);
  347. //已完成的数量
  348. int CompleteFieldCount = sample.GetMsrStatus().GetCompletedFields();
  349. int MeasureFieldTotalCount = (int)sample.GetMsrStatus().GetCompletedFields();
  350. int ParticleCount = 0;
  351. if (CompleteFieldCount > 0)
  352. {
  353. //设置完成数量 颗粒数量
  354. SetCurrentProgressInfo(CompleteFieldCount, MeasureFieldTotalCount, ParticleCount);
  355. //设置开始、测量时间
  356. string startTime = sample.GetMsrStatus().GetStartTime().ToString();
  357. //开始时间
  358. SetStartTime(startTime);
  359. TimeSpan usedTimeTS = sample.GetMsrStatus().GetUsedTime();
  360. //获取测量时间
  361. SetMeasureTime(usedTimeTS);
  362. //获取结果文件 颗粒列表信息
  363. List<CMsrResultItem> cMsrResultItemClrList = sample.GetMsrResults().GetResultItems();
  364. //设置测量状态数据列表
  365. SetMeasureListInfo(cMsrResultItemClrList);
  366. }
  367. else
  368. {
  369. SetInit();
  370. }
  371. }
  372. private void PBState_SizeChanged(object sender, EventArgs e)
  373. {
  374. //每次在进度条尺寸更变的时候 将进度内容位置设置在进度条位置中心
  375. lblProgressInfo.Location = new Point(PBState.Location.X + (PBState.Width), lblProgressInfo.Location.Y);
  376. }
  377. }
  378. }