ResultGrid.cs 13 KB

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