OTSMeasureResultWindow.cs 14 KB

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