OTSMeasureResultWindow.cs 13 KB

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