OTSMeasureResultWindow.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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. OTSCommon.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 OTSCommon.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. #region 显示操作
  121. /// <summary>
  122. /// 测量进度
  123. /// </summary>
  124. /// <param name="currentMeasureCount"></param>
  125. /// <param name="beginTime"></param>
  126. /// <param name="MeasureTime"></param>
  127. public void SetProgressInfo(int currentMeasureCount, int measureAllCount, int ParticleCount)
  128. {
  129. try
  130. {
  131. //设置进度条最大、最小、步长值
  132. PBState.Minimum = m_MinValue;
  133. PBState.Maximum = m_MaxValue;
  134. PBState.Step = m_Step;
  135. int currentProgress = m_MinValue;
  136. int currentMeasureCountAdd = currentMeasureCount;
  137. //设置当前帧图数
  138. lblSingleCount.Text = currentMeasureCount.ToString();
  139. if (currentMeasureCountAdd <= measureAllCount)
  140. {
  141. currentProgress = (currentMeasureCountAdd) * 100 / measureAllCount;
  142. }
  143. //设置当前进度值
  144. if (currentProgress < 100)
  145. {
  146. PBState.Value = currentProgress;
  147. lblProgressInfo.Text = currentProgress + "%";
  148. }
  149. else
  150. {
  151. lblProgressInfo.Text = currentProgress + "%";
  152. PBState.Value = 100;
  153. }
  154. //设置颗粒数量
  155. int pCount = ParticleCount;
  156. lblParticleCount.Text = (pCount).ToString();
  157. }
  158. catch (Exception ex)
  159. {
  160. log.Trace( ex.ToString());
  161. }
  162. }
  163. /// <summary>
  164. /// 设置样品名称
  165. /// </summary>
  166. /// <param name="sampleName"></param>
  167. public void SetSampleName(string sampleName)
  168. {
  169. //设置样品名称
  170. if (sampleName != null)
  171. {
  172. if (sampleName != "")
  173. {
  174. lblSampleName.Text = sampleName;
  175. }
  176. }
  177. }
  178. /// <summary>
  179. /// 设置开始时间
  180. /// </summary>
  181. /// <param name="startTime"></param>
  182. public void SetStartTime(string startTime)
  183. {
  184. if (startTime != null)
  185. {
  186. if (startTime != "")
  187. {
  188. try
  189. {
  190. //设置开始时间
  191. lblBeginTime.Text = startTime;
  192. }
  193. catch (Exception)
  194. {
  195. lblBeginTime.Text = "";
  196. }
  197. }
  198. }
  199. }
  200. /// <summary>
  201. /// 设置结束时间
  202. /// </summary>
  203. /// <param name="endTime"></param>
  204. public void CloseProgressWindow()
  205. {
  206. //this.Dispose();
  207. this.Close();
  208. }
  209. #endregion
  210. private void OTSMeasureResultWindow_FormClosing(object sender, FormClosingEventArgs e)
  211. {
  212. }
  213. #region 设置当前测量用时
  214. /// <summary>
  215. /// 设置当前测量用时
  216. /// </summary>
  217. /// <param name="ts">时间间隔对象</param>
  218. public void SetMeasureTime(TimeSpan ts)
  219. {
  220. //这样就能得到天数、小时、分差
  221. string str1 = string.Empty;
  222. if (ts.Days > 0)
  223. {
  224. string str = table["str1"].ToString();
  225. str1 += ts.Days + str;
  226. }
  227. if (ts.Hours > 0)
  228. {
  229. string str = table["str2"].ToString();
  230. str1 += ts.Hours + str;
  231. }
  232. if (ts.Minutes > 0)
  233. {
  234. string str = table["str3"].ToString();
  235. str1 += ts.Minutes + str;
  236. }
  237. if (ts.Seconds > 0)
  238. {
  239. string str = table["str4"].ToString();
  240. str1 += ts.Seconds + str;
  241. }
  242. //所有时间换去 总计天数、小时、分钟
  243. lblMeasureTime.Text = str1;
  244. }
  245. #endregion
  246. #region 设置当前测量列表
  247. /// <summary>
  248. /// 设置当前测量用时
  249. /// </summary>
  250. /// <param name="ts">时间间隔对象</param>
  251. public void SetMeasureListInfo(IList list)
  252. {
  253. try
  254. {
  255. //颗粒类型数量
  256. int IParticleTypeAmount = 0;
  257. //颗粒总数量
  258. int IParticleAmount = 0;
  259. //颗粒面积总数量
  260. double dAreaAmount = 0;
  261. COTSSample WSample = m_MeasureAppForm.m_ProjParam.GetWorkSample();
  262. //list 序列化 DataTable
  263. DataTable dt = ListConvertToDT(list);
  264. if (dt != null)
  265. {
  266. if (dt.Rows.Count > 0)
  267. {
  268. IParticleTypeAmount = dt.Rows.Count;
  269. string stdName = string.Empty;
  270. for (int i = 0; i < dt.Rows.Count; i++)
  271. {
  272. stdName = string.Empty;
  273. int STDID = Convert.ToInt32(dt.Rows[i]["TypeId"].ToString());
  274. IParticleAmount += Convert.ToInt32(dt.Rows[i]["Number"].ToString());
  275. dAreaAmount += Convert.ToDouble(dt.Rows[i]["Area"].ToString());
  276. }
  277. //添加统计行信息
  278. DataRow dr = dt.NewRow();
  279. dr["TypeId"] = "";
  280. dr["STDName"] = "";
  281. string str = table["str6"].ToString();
  282. dr["Number"] = str + IParticleAmount;
  283. str = table["str7"].ToString();
  284. dr["Area"] = str + dAreaAmount;
  285. dt.Rows.Add(dr);
  286. }
  287. dg_Info.DataSource = dt;
  288. }
  289. }
  290. catch (Exception ex)
  291. {
  292. string str = table["str8"].ToString();
  293. log.Trace(str + ex.ToString());
  294. }
  295. }
  296. #endregion
  297. #region List转换为DataTable
  298. /// <summary>
  299. /// 将集合类转换成DataTable
  300. /// </summary>
  301. /// <param name="list">集合</param>
  302. /// <returns></returns>
  303. public static DataTable ListConvertToDT(IList list)
  304. {
  305. DataTable result = new DataTable();
  306. result.Columns.Add("TypeId");
  307. result.Columns.Add("Number");
  308. result.Columns.Add("Area");
  309. result.Columns.Add("STDName");
  310. if (list == null)
  311. {
  312. return null;
  313. }
  314. if (list.Count > 0)
  315. {
  316. for (int i = 0; i < list.Count; i++)
  317. {
  318. CMsrResultItem cMsrResultItemClr = (CMsrResultItem)list[i];
  319. DataRow dr = result.NewRow();
  320. dr[0] = cMsrResultItemClr.GetTypeId();
  321. dr[1] = cMsrResultItemClr.GetNumber();
  322. dr[2] = Math.Round(Convert.ToDouble(cMsrResultItemClr.GetArea()),2);
  323. dr[3] = cMsrResultItemClr.GetName();
  324. result.Rows.Add(dr);
  325. }
  326. }
  327. return result;
  328. }
  329. #endregion
  330. public void GetResultFileInfoBySampleName(string sampleName)
  331. {
  332. //显示样品名称信息
  333. COTSSample sample = m_MeasureAppForm.m_ProjParam.GetResultData().GetSampleByName(sampleName);
  334. //设置当前样品名称
  335. SetSampleName(sampleName);
  336. //已完成的数量
  337. int CompleteFieldCount = sample.GetMsrStatus().GetCompletedFields();
  338. int MeasureFieldTotalCount = (int)sample.GetMsrStatus().GetCompletedFields();
  339. int ParticleCount = 0;
  340. if (CompleteFieldCount > 0)
  341. {
  342. //设置完成数量 颗粒数量
  343. SetCurrentProgressInfo(CompleteFieldCount, MeasureFieldTotalCount, ParticleCount);
  344. //设置开始、测量时间
  345. string startTime = sample.GetMsrStatus().GetStartTime().ToString();
  346. //开始时间
  347. SetStartTime(startTime);
  348. TimeSpan usedTimeTS = sample.GetMsrStatus().GetUsedTime();
  349. //获取测量时间
  350. SetMeasureTime(usedTimeTS);
  351. //获取结果文件 颗粒列表信息
  352. List<CMsrResultItem> cMsrResultItemClrList = sample.GetMsrResults().GetResultItems();
  353. //设置测量状态数据列表
  354. SetMeasureListInfo(cMsrResultItemClrList);
  355. }
  356. else
  357. {
  358. SetInit();
  359. }
  360. }
  361. private void PBState_SizeChanged(object sender, EventArgs e)
  362. {
  363. //每次在进度条尺寸更变的时候 将进度内容位置设置在进度条位置中心
  364. lblProgressInfo.Location = new Point(PBState.Location.X + (PBState.Width), lblProgressInfo.Location.Y);
  365. }
  366. }
  367. }