ResultGrid.cs 13 KB

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