OTSMeasureResultWindow.cs 13 KB

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