ResultGrid.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. using OTSIncAReportApp;
  2. using OTSIncAReportApp.DataOperation.DataAccess;
  3. using OTSIncAReportApp.DataOperation.Model;
  4. using OTSIncAReportApp.OTSSampleReportInfo;
  5. using OTSIncAReportApp.SysMgrTools;
  6. using System;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Windows.Forms;
  11. namespace OTSIncAReportGrids
  12. {
  13. public partial class ResultGrid : UserControl
  14. {
  15. #region 变量定义
  16. //测量结果
  17. frmReportApp m_frmReportApp = null;
  18. //国际化
  19. Language lan;
  20. public Hashtable table;
  21. frmReportConditionChoose m_condition;
  22. #endregion
  23. #region 窗体加载及构造函数
  24. public ResultGrid(frmReportApp frmReportApp)
  25. {
  26. m_frmReportApp = frmReportApp;
  27. m_condition = frmReportApp.m_conditionChoose;
  28. InitializeComponent();
  29. //国际化
  30. lan = new Language(this);
  31. table = lan.GetNameTable(this.Name);
  32. }
  33. private void ResultGrid_Load(object sender, EventArgs e)
  34. {
  35. BindGrid();
  36. SetDataGridViewStyleIncLib();
  37. }
  38. #endregion
  39. #region 绑定数据
  40. private void BindGrid()
  41. {
  42. string str1 = table["str1"].ToString();
  43. string str8 = table["str8"].ToString();
  44. Gview_gz.Rows.Clear();
  45. Gview_gz.Columns.Clear();
  46. //创建列
  47. Gview_gz.Columns.Add(str1, str1);
  48. Gview_gz.Columns.Add(str8, str8);
  49. //自适应列宽
  50. if (this.Width > 0)
  51. {
  52. //再对不同的列宽度进行设置
  53. Gview_gz.Columns[0].Width = this.Width / 2;
  54. Gview_gz.Columns[1].Width = this.Width / 2;
  55. }
  56. //先设置一下头的高度,否则会太矮不好看
  57. Gview_gz.ColumnHeadersVisible = false;
  58. Gview_gz.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
  59. Gview_gz.ColumnHeadersHeight = 30;
  60. //int idx = m_frmReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_frmReportApp.SourceGridData.ConditionItemList, OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  61. //string sou = m_frmReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString();
  62. string sou = m_condition.m_CurrentConditions[OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE].itemDisplayVal.ToString();
  63. //string sou= m_frmReportApp.m_conditionChoose.m_SourceGridData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  64. if (sou.Contains("+"))
  65. {
  66. for (int i = 0; i < sou.Split('+').Length; i++)
  67. {
  68. OTSIncAReportApp.DataOperation.Model.ResultFile resultFile = m_frmReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.FileName == sou.Split('+')[i]);
  69. if (resultFile != null)
  70. {
  71. addGrid(resultFile);
  72. }
  73. }
  74. }
  75. else
  76. {
  77. for (int i=0;i< m_frmReportApp.m_rstDataMgr.ResultFilesList.Count;i++)
  78. {
  79. if(sou== m_frmReportApp.m_rstDataMgr.ResultFilesList[i].FileName.ToString())
  80. addGrid(m_frmReportApp.m_rstDataMgr.ResultFilesList[i]);
  81. }
  82. //int item= (int)m_frmReportApp.m_conditionChoose.m_SourceGridData.GetPropItemDisplayValueByPropItem(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  83. //m_frmReportApp.m_rstDataMgr.SetWorkingResult(item);
  84. //addGrid(m_frmReportApp.m_rstDataMgr.ResultFilesList[m_frmReportApp.m_rstDataMgr.GetWorkingResult()]);
  85. }
  86. }
  87. /// <summary>
  88. /// 获取测量结果概况信息数据
  89. /// </summary>
  90. /// <returns></returns>
  91. public Dictionary<string, string> GetData_ResultGrid(ResultFile resultFile)
  92. {
  93. ResultFile resfile = resultFile;
  94. Dictionary<string, string> keyValues = new Dictionary<string, string>() { };
  95. keyValues.Add(table["col1"].ToString(), resfile.FileName);
  96. string path = resfile.FilePath;
  97. FieldData fielddata = new FieldData(path);
  98. DataTable dt = fielddata.GetGeneralInfo();
  99. DateTime star = new DateTime();
  100. DateTime end = new DateTime();
  101. System.Globalization.DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
  102. dtFormat.ShortDatePattern = "dd/MM/yyyy hh:mm:ss";
  103. if (dt.Rows.Count > 0)
  104. {
  105. for (int i = 0; i < dt.Rows.Count; i++)
  106. {
  107. if (dt.Rows[i]["name"].ToString() == "TimeStart")
  108. {
  109. star = Convert.ToDateTime(dt.Rows[i]["value"], dtFormat);
  110. }
  111. if (dt.Rows[i]["name"].ToString() == "TimeEnd")
  112. {
  113. end = Convert.ToDateTime(dt.Rows[i]["value"], dtFormat);
  114. }
  115. }
  116. }
  117. TimeSpan timeSpan = end - star;
  118. int filedCount = fielddata.GetFiledCount();
  119. Dictionary<string, object> sampleMembers = ((Dictionary<string, object>)((Dictionary<string, object>)resfile.ResultInfo["Sample"])["Members"]);
  120. Dictionary<string, object> semDataMsr = (Dictionary<string, object>)sampleMembers["SEMDataMsr"];
  121. double scanFieldSize = Convert.ToDouble(semDataMsr["ScanFieldSize"]);
  122. Dictionary<string, object> imageScanParam = (Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)sampleMembers["MsrParams"])["Members"])["ImageScanParam"];
  123. string ImageResolution = imageScanParam["ImageResolution"].ToString();
  124. double wide = Convert.ToDouble(ImageResolution.Split('_')[1]);
  125. double high = Convert.ToDouble(ImageResolution.Split('_')[2]);
  126. double pixelSize = scanFieldSize / wide;
  127. double filedsArea = Math.Round(high * wide * pixelSize* pixelSize* filedCount, 2);
  128. int particleArea = fielddata.GetparticleArea();
  129. double ratio = particleArea / filedsArea;
  130. //报告参数文件
  131. string xmlpath = Application.StartupPath + m_frmReportApp.m_OTSReportMgrParamFile;
  132. DataSet ds = XMLoperate.GetXmlData(xmlpath, "XMLData");
  133. DataTable dt1 = ds.Tables["Member"];
  134. string sizestr = "1000";
  135. for (int i = 0; i < dt1.Rows.Count; i++)
  136. {
  137. if (dt1.Rows[i]["RegName"].ToString() == "Scale")
  138. {
  139. sizestr = dt1.Rows[i]["strValue"].ToString();
  140. break;
  141. }
  142. }
  143. keyValues.Add(table["col2"].ToString(), star.ToString("yyyy-MM-dd HH:mm:ss"));
  144. keyValues.Add(table["col3"].ToString(), end.ToString("yyyy-MM-dd HH:mm:ss"));
  145. keyValues.Add(table["col4"].ToString(), Math.Round(timeSpan.TotalMinutes, 2).ToString() + "mins");
  146. keyValues.Add(table["col5"].ToString(), filedCount.ToString());
  147. keyValues.Add(table["col6"].ToString(), ((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)resfile.ResultInfo["Sample"])["Members"])["MsrParams"])["STDName"].ToString());
  148. keyValues.Add(table["col7"].ToString(), fielddata.GetparticleCount().ToString());
  149. keyValues.Add(table["col8"].ToString(), filedsArea.ToString());
  150. keyValues.Add(table["col9"].ToString(), particleArea.ToString());
  151. keyValues.Add(table["col10"].ToString(), ratio.ToString());
  152. keyValues.Add(table["col11"].ToString(), sizestr);
  153. return keyValues;
  154. }
  155. public Dictionary<string, string> GetData_ResultGrid_Report()
  156. {
  157. ResultFile resfile = m_frmReportApp.m_rstDataMgr.ResultFilesList[m_frmReportApp.m_rstDataMgr.getSelectedIndex()];
  158. Dictionary<string, string> keyValues = new Dictionary<string, string>() { };
  159. keyValues.Add(table["col1"].ToString(), resfile.FileName);
  160. string path = resfile.FilePath;
  161. FieldData fielddata = new FieldData(path);
  162. DataTable dt = fielddata.GetGeneralInfo();
  163. DateTime star = new DateTime();
  164. DateTime end = new DateTime();
  165. System.Globalization.DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
  166. dtFormat.ShortDatePattern = "dd/MM/yyyy hh:mm:ss";
  167. if (dt.Rows.Count > 0)
  168. {
  169. for (int i = 0; i < dt.Rows.Count; i++)
  170. {
  171. if (dt.Rows[i]["name"].ToString() == "TimeStart")
  172. {
  173. star = Convert.ToDateTime(dt.Rows[i]["value"], dtFormat);
  174. }
  175. if (dt.Rows[i]["name"].ToString() == "TimeEnd")
  176. {
  177. end = Convert.ToDateTime(dt.Rows[i]["value"], dtFormat);
  178. }
  179. }
  180. }
  181. TimeSpan timeSpan = end - star;
  182. int filedCount = fielddata.GetFiledCount();
  183. Dictionary<string, object> sampleMembers = ((Dictionary<string, object>)((Dictionary<string, object>)resfile.ResultInfo["Sample"])["Members"]);
  184. Dictionary<string, object> semDataMsr = (Dictionary<string, object>)sampleMembers["SEMDataMsr"];
  185. double scanFieldSize = Convert.ToDouble(semDataMsr["ScanFieldSize"]);
  186. Dictionary<string, object> imageScanParam = (Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)sampleMembers["MsrParams"])["Members"])["ImageScanParam"];
  187. string ImageResolution = imageScanParam["ImageResolution"].ToString();
  188. double wide = Convert.ToDouble(ImageResolution.Split('_')[1]);
  189. double high = Convert.ToDouble(ImageResolution.Split('_')[2]);
  190. double pixelSize = scanFieldSize / wide;
  191. double filedsArea = Math.Round(high * wide * pixelSize * pixelSize * filedCount, 2);
  192. int particleArea = fielddata.GetparticleArea();
  193. double ratio = particleArea / filedsArea;
  194. //报告参数文件
  195. string xmlpath = Application.StartupPath + m_frmReportApp.m_OTSReportMgrParamFile;
  196. DataSet ds = XMLoperate.GetXmlData(xmlpath, "XMLData");
  197. DataTable dt1 = ds.Tables["Member"];
  198. string sizestr = "1000";
  199. for (int i = 0; i < dt1.Rows.Count; i++)
  200. {
  201. if (dt1.Rows[i]["RegName"].ToString() == "Scale")
  202. {
  203. sizestr = dt1.Rows[i]["strValue"].ToString();
  204. break;
  205. }
  206. }
  207. keyValues.Add(table["col2"].ToString(), star.ToString("yyyy-MM-dd HH:mm:ss"));
  208. keyValues.Add(table["col3"].ToString(), end.ToString("yyyy-MM-dd HH:mm:ss"));
  209. keyValues.Add(table["col4"].ToString(), Math.Round(timeSpan.TotalMinutes, 2).ToString() + "mins");
  210. keyValues.Add(table["col5"].ToString(), filedCount.ToString());
  211. keyValues.Add(table["col6"].ToString(), ((Dictionary<string, object>)((Dictionary<string, object>)((Dictionary<string, object>)resfile.ResultInfo["Sample"])["Members"])["MsrParams"])["STDName"].ToString());
  212. keyValues.Add(table["col7"].ToString(), fielddata.GetparticleCount().ToString());
  213. keyValues.Add(table["col8"].ToString(), filedsArea.ToString());
  214. keyValues.Add(table["col9"].ToString(), particleArea.ToString());
  215. keyValues.Add(table["col10"].ToString(), ratio.ToString());
  216. keyValues.Add(table["col11"].ToString(), sizestr);
  217. return keyValues;
  218. }
  219. /// <summary>
  220. /// 绑定GridView显示
  221. /// </summary>
  222. /// <param name="resultFile"></param>
  223. private void addGrid(OTSIncAReportApp.DataOperation.Model.ResultFile resultFile)
  224. {
  225. Dictionary<string, string> keyValues = GetData_ResultGrid(resultFile);
  226. Dictionary<string, string>.Enumerator en = keyValues.GetEnumerator();
  227. for (int irow = 0; irow < keyValues.Count; irow++)
  228. {
  229. if (en.MoveNext())
  230. {
  231. //add row
  232. int add_rowindex = 0;
  233. add_rowindex = Gview_gz.Rows.Add();
  234. if (irow == 0)
  235. {
  236. //set title style
  237. Gview_gz.Rows[add_rowindex].Cells[0].Style.BackColor = System.Drawing.Color.PowderBlue;
  238. Gview_gz.Rows[add_rowindex].Cells[1].Style.BackColor = System.Drawing.Color.PowderBlue;
  239. }
  240. else
  241. {
  242. //set row style
  243. Gview_gz.Rows[add_rowindex].Cells[0].Style.BackColor = System.Drawing.Color.LightCyan;
  244. }
  245. //set value
  246. Gview_gz.Rows[add_rowindex].Cells[0].Value = en.Current.Key;
  247. Gview_gz.Rows[add_rowindex].Cells[1].Value = en.Current.Value;
  248. }
  249. }
  250. //将左侧第一列,全部设置成System.Drawing.Color.PowderBlue; 当标题头不错
  251. for (int i = 0; i < Gview_gz.Rows.Count; i++)
  252. {
  253. Gview_gz.Rows[i].Cells[0].Style.Font = new System.Drawing.Font("黑体", 10, System.Drawing.FontStyle.Bold);
  254. Gview_gz.Rows[i].Cells[1].Style.Font = new System.Drawing.Font("黑体", 10, System.Drawing.FontStyle.Bold);
  255. }
  256. }
  257. #endregion
  258. #region 设置Grid样式
  259. /// <summary>
  260. /// 设置夹杂物列表DataGridView样式
  261. /// </summary>
  262. private void SetDataGridViewStyleIncLib()
  263. {
  264. //用户不能调整标题的高度
  265. Gview_gz.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  266. //用户不能调整 行高
  267. Gview_gz.AllowUserToResizeRows = false;
  268. //再次重覆禁用拖动表头高度,居然有效果了
  269. Gview_gz.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  270. //设置grid可以复制
  271. Gview_gz.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
  272. //设置每列的宽度
  273. // dgV_IncALib.Columns[1].Width = 40;
  274. Gview_gz.Columns[0].Width = 300;
  275. //设置序号列不排序
  276. Gview_gz.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  277. //设置序号列不可以设置宽度
  278. Gview_gz.Columns[0].Resizable = DataGridViewTriState.False;
  279. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  280. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
  281. dataGridViewCellStyle1.BackColor = System.Drawing.Color.LightCyan;
  282. Gview_gz.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
  283. Gview_gz.BackgroundColor = System.Drawing.Color.White;
  284. Gview_gz.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
  285. Gview_gz.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
  286. dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;//211, 223, 240
  287. dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(211)))), ((int)(((byte)(223)))), ((int)(((byte)(240)))));
  288. dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  289. dataGridViewCellStyle2.ForeColor = System.Drawing.Color.Navy;
  290. dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
  291. dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
  292. Gview_gz.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
  293. Gview_gz.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  294. Gview_gz.EnableHeadersVisualStyles = false;
  295. Gview_gz.GridColor = System.Drawing.SystemColors.GradientInactiveCaption;
  296. Gview_gz.ReadOnly = true;
  297. Gview_gz.RowHeadersVisible = false; //建议改为true;为了以后显示序号。
  298. Gview_gz.RowTemplate.Height = 23;
  299. Gview_gz.RowTemplate.ReadOnly = true;
  300. //居中
  301. Gview_gz.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
  302. }
  303. #endregion
  304. #region 得到向word中插入Table所需要使用的,该模块结合后的对象数组
  305. /// <summary>
  306. /// 获取到该模块输出后形成的DataTable,和GridView
  307. /// </summary>
  308. /// <param name="out_dt"></param>
  309. /// <param name="out_dg"></param>
  310. public void GetDataTableAndGridView(out DataTable out_dt, out DataGridView out_dg)
  311. {
  312. out_dt = null;
  313. out_dg = this.Gview_gz;
  314. }
  315. #endregion
  316. #region 相关事件
  317. /// <summary>
  318. /// 复制选择区域
  319. /// </summary>
  320. public void CopySelected()
  321. {
  322. //复制选择区域
  323. object oo = Gview_gz.GetClipboardContent();
  324. Clipboard.SetDataObject(Gview_gz.GetClipboardContent());
  325. }
  326. /// <summary>
  327. /// 复制所有
  328. /// </summary>
  329. public void CopyAll()
  330. {
  331. Gview_gz.SelectAll();
  332. Clipboard.SetDataObject(Gview_gz.GetClipboardContent());
  333. }
  334. //复制整个表
  335. private void ToolStripMenuItem1_Click(object sender, EventArgs e)
  336. {
  337. CopyAll();
  338. }
  339. //复制选择区域
  340. private void ToolStripMenuItem2_Click(object sender, EventArgs e)
  341. {
  342. CopySelected();
  343. }
  344. //恢复初始状态
  345. private void ToolStripMenuItem3_Click(object sender, EventArgs e)
  346. {
  347. }
  348. #endregion
  349. }
  350. }