ElementCompositionAvgGrid.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. using OTSIncAReportApp.SysMgrTools;
  2. using OTSIncAReportGraph.Class;
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Windows.Forms;
  9. namespace OTSIncAReportGrids
  10. {
  11. /// <summary>
  12. /// 颗粒平均元素成分含量表 平均元素含量表
  13. /// </summary>
  14. public partial class ElementCompositionAvgGrid : UserControl
  15. {
  16. #region 设置变量
  17. //设置模拟数据表
  18. public DataTable m_dt = new DataTable();
  19. //多个数据源,每个数据源拥有的列数,这里保存下来,供分组使用
  20. public List<int> m_list_oneresult_columncount;
  21. //国际化
  22. Language lan;
  23. Hashtable table;
  24. //测量结果
  25. OTSIncAReportApp.DataOperation.Model.ResultFile result = null;
  26. OTSIncAReportApp.DataOperation.DataAccess.ParticleData particledata;
  27. OTSIncAReportApp.frmReportApp m_ReportApp;
  28. #endregion
  29. #region 自定义方法
  30. /// <summary>
  31. /// 绑定datagridview数据
  32. /// </summary>
  33. public void BindDataGridView()
  34. {
  35. List<string> colid = new List<string>() { "rowid", "pname", "area", "con" };
  36. List<string> colname = new List<string>() { table["str1"].ToString(), table["str4"].ToString(), table["str3"].ToString(), table["str6"].ToString() };
  37. //创建Grid的列
  38. for (int i = 0; i < colid.Count; i++)
  39. {
  40. Gview_gz.Columns.Add(colid[i], colname[i]);
  41. }
  42. DataTable dte = particledata.GetAllElement();
  43. foreach (DataRow item in dte.Rows)
  44. {
  45. DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
  46. iconColumn.Name = item["name"].ToString();
  47. iconColumn.HeaderText = item["name"].ToString();
  48. Gview_gz.Columns.Add(iconColumn);
  49. }
  50. List<int> FLID = new List<int>() { 0, 1, 2, 4, 6, 7, 8, 9 };
  51. List<string> NameList = new List<string>() { table["partcletype0"].ToString(), table["partcletype1"].ToString(), table["partcletype2"].ToString(), table["partcletype4"].ToString(), table["partcletype6"].ToString(), table["partcletype7"].ToString(), table["partcletype8"].ToString(), table["partcletype9"].ToString() };
  52. int idx = m_ReportApp.m_DataMgrFun.GetSampleIndexByPropItemName(m_ReportApp.SourceGridData.SampleDataList, OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  53. int sel = m_ReportApp.SourceGridData.SampleDataList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.SampleDataList[idx].itemVal.ToString());
  54. string filedAndParticl = "";
  55. if (sel == 1)
  56. {
  57. List<OTSIncAReportApp.DataOperation.Model.Particle> selectParticles = m_ReportApp.SelectedParticles;
  58. foreach (var item in selectParticles)
  59. {
  60. filedAndParticl = filedAndParticl + "," + (item.FieldId.ToString() + "-" + item.ParticleId.ToString());
  61. }
  62. if (filedAndParticl != "")
  63. {
  64. filedAndParticl = filedAndParticl + ",";
  65. }
  66. }
  67. DataTable dt = particledata.GetAreaByAllIncA(filedAndParticl);
  68. for (int i = 0; i < dt.Rows.Count; i++)
  69. {
  70. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) < 100)
  71. {
  72. continue;
  73. }
  74. double total = Convert.ToDouble(dt.Rows[i]["ar"]);
  75. //double small = Convert.ToDouble(dt.Rows[i]["small"]);
  76. int add_rowindex = Gview_gz.Rows.Add();
  77. Gview_gz.Rows[add_rowindex].Cells[0].Value = add_rowindex + 1;
  78. Gview_gz.Rows[add_rowindex].Cells[1].Value = dt.Rows[i]["TypeName"];
  79. Gview_gz.Rows[add_rowindex].Cells[1].Style.BackColor = Color.Azure;
  80. Gview_gz.Rows[add_rowindex].Cells[2].Value = Math.Round(total, 2);
  81. Gview_gz.Rows[add_rowindex].Cells[2].Style.BackColor = Color.Azure;
  82. //Gview_gz.Rows[add_rowindex].Cells[3].Value = Math.Round(small, 2);
  83. //Gview_gz.Rows[add_rowindex].Cells[3].Style.BackColor = Color.Azure;
  84. Gview_gz.Rows[add_rowindex].Cells[3].Value = dt.Rows[i]["con"];
  85. Gview_gz.Rows[add_rowindex].Cells[3].Style.BackColor = Color.Azure;
  86. DataTable dtp = particledata.GetAreaByIncA(dt.Rows[i]["TypeId"].ToString(), filedAndParticl);
  87. for (int j = 4; j < Gview_gz.Columns.Count; j++)
  88. {
  89. int col = 0;
  90. foreach (DataRow dr in dtp.Rows)
  91. {
  92. if (Gview_gz.Columns[j].Name == dr["name"].ToString())
  93. {
  94. double ar = Convert.ToDouble(dr["pc"]);
  95. double p = Math.Round(ar / total, 2);
  96. Gview_gz.Rows[add_rowindex].Cells[j].Value = DrawFuncation.GetProcessBitmap((float)p, Color.Azure);
  97. Gview_gz.Rows[add_rowindex].Cells[j].Tag = p;
  98. break;
  99. }
  100. col++;
  101. }
  102. if (col == dtp.Rows.Count)
  103. {
  104. Gview_gz.Rows[add_rowindex].Cells[j].Value = DrawFuncation.GetProcessBitmap(0, Color.Azure);
  105. Gview_gz.Rows[add_rowindex].Cells[j].Tag = 0;
  106. }
  107. }
  108. }
  109. for (int i = 0; i < dt.Rows.Count; i++)
  110. {
  111. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) > 100)
  112. {
  113. continue;
  114. }
  115. int add_rowindex = Gview_gz.Rows.Add();
  116. Gview_gz.Rows[add_rowindex].Cells[0].Value = add_rowindex + 1;
  117. int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[i]["TypeId"]));
  118. if (index == -1)
  119. {
  120. index = 7;
  121. }
  122. string name = NameList[index];
  123. double total = Convert.ToDouble(dt.Rows[i]["ar"]);
  124. //double small = Convert.ToDouble(dt.Rows[i]["small"]);
  125. Gview_gz.Rows[add_rowindex].Cells[1].Value = name;
  126. Gview_gz.Rows[add_rowindex].Cells[1].Style.BackColor = Color.Azure;
  127. Gview_gz.Rows[add_rowindex].Cells[2].Value = Math.Round(total, 2);
  128. Gview_gz.Rows[add_rowindex].Cells[2].Style.BackColor = Color.Azure;
  129. //Gview_gz.Rows[add_rowindex].Cells[3].Value = Math.Round(small, 2);
  130. Gview_gz.Rows[add_rowindex].Cells[3].Style.BackColor = Color.Azure;
  131. Gview_gz.Rows[add_rowindex].Cells[4].Value = dt.Rows[i]["con"];
  132. Gview_gz.Rows[add_rowindex].Cells[4].Style.BackColor = Color.Azure;
  133. DataTable dtp = particledata.GetAreaByIncA(dt.Rows[i]["TypeId"].ToString(), filedAndParticl);
  134. for (int j = 4; j < Gview_gz.Columns.Count; j++)
  135. {
  136. int col = 0;
  137. foreach (DataRow dr in dtp.Rows)
  138. {
  139. if (Gview_gz.Columns[j].Name == dr["name"].ToString())
  140. {
  141. double ar = Convert.ToDouble(dr["pc"]);
  142. double p = Math.Round(ar / total, 2);
  143. Gview_gz.Rows[add_rowindex].Cells[j].Value = DrawFuncation.GetProcessBitmap((float)p, Color.Azure);
  144. Gview_gz.Rows[add_rowindex].Cells[j].Tag = p;
  145. break;
  146. }
  147. col++;
  148. }
  149. if (col == dtp.Rows.Count)
  150. {
  151. Gview_gz.Rows[add_rowindex].Cells[j].Value = DrawFuncation.GetProcessBitmap(0, Color.Azure);
  152. Gview_gz.Rows[add_rowindex].Cells[j].Tag = 0;
  153. }
  154. }
  155. }
  156. }
  157. /// <summary>
  158. /// 设置DataGridView样式
  159. /// </summary>
  160. private void SetDataGridViewStyle()
  161. {
  162. //用户不能调整标题的高度
  163. //Gview_gz.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  164. //用户不能调整 行高
  165. Gview_gz.AllowUserToResizeRows = false;
  166. //改变行的高度;
  167. //Gview_gz.RowTemplate.Height = 20;
  168. //点击选择整行
  169. Gview_gz.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  170. //居中显示
  171. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  172. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  173. Gview_gz.DefaultCellStyle = dataGridViewCellStyle1;
  174. Gview_gz.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  175. //再次重覆禁用拖动表头高度,居然有效果了
  176. //Gview_gz.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  177. //设置grid可以复制
  178. Gview_gz.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
  179. //设置每列的宽度
  180. Gview_gz.Columns[0].Width = 40;//第一列序号的宽度设置一下吧,要不太丑
  181. Gview_gz.Columns[1].Width = 200;
  182. //设置序号列不排序
  183. Gview_gz.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  184. //设置序号列不可以设置宽度
  185. Gview_gz.Columns[0].Resizable = DataGridViewTriState.False;
  186. //设置所有行的高度
  187. for (int i = 0; i < Gview_gz.Rows.Count; i++)
  188. {
  189. Gview_gz.Rows[i].Height = 30;
  190. }
  191. }
  192. #endregion
  193. #region 初始化构造函数
  194. /// <summary>
  195. /// 元素平均含量表,构造函数
  196. /// </summary>
  197. /// <param name="in_sec">传入,委托类对象</param>
  198. /// <param name="in_Cotsreportprojfilemgrclr">传入,项目管理类对象</param>
  199. public ElementCompositionAvgGrid(OTSIncAReportApp.frmReportApp ReportApp)
  200. {
  201. m_ReportApp = ReportApp;
  202. result = m_ReportApp.resultFilesList[m_ReportApp.WorkingResult];
  203. InitializeComponent();
  204. lan = new Language(this);
  205. table = lan.GetNameTable(this.Name);
  206. }
  207. private void ElementContentGrid_Load(object sender, EventArgs e)
  208. {
  209. particledata = new OTSIncAReportApp.DataOperation.DataAccess.ParticleData(result.FilePath);
  210. //创建datatable的列数据,及分栏,及相关行数据
  211. BindDataGridView();
  212. //设置grid风格
  213. SetDataGridViewStyle();
  214. }
  215. #endregion
  216. #region 相关事件
  217. private void ToolStripMenuItem1_Click(object sender, EventArgs e)
  218. {
  219. //复制整个表
  220. CopyAll();
  221. }
  222. private void ToolStripMenuItem2_Click(object sender, EventArgs e)
  223. {
  224. //复制选择区域
  225. CopySelected();
  226. }
  227. /// <summary>
  228. /// 复制选择区域
  229. /// </summary>
  230. public void CopySelected()
  231. {
  232. //复制选择区域
  233. object oo = Gview_gz.GetClipboardContent();
  234. Clipboard.SetDataObject(Gview_gz.GetClipboardContent());
  235. }
  236. /// <summary>
  237. /// 复制所有
  238. /// </summary>
  239. public void CopyAll()
  240. {
  241. Gview_gz.SelectAll();
  242. Clipboard.SetDataObject(Gview_gz.GetClipboardContent());
  243. }
  244. private void ToolStripMenuItem3_Click(object sender, EventArgs e)
  245. {
  246. //恢复至初始状态
  247. Gview_gz.Rows.Clear();
  248. Gview_gz.Columns.Clear();
  249. BindDataGridView();
  250. SetDataGridViewStyle();
  251. }
  252. private void Gview_gz_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
  253. {
  254. //排序中
  255. if (this.Gview_gz.Rows[e.RowIndex1].Tag != null && this.Gview_gz.Rows[e.RowIndex1].Tag.ToString() == "统计行")
  256. {
  257. //ROW1>ROW2
  258. e.SortResult = 1;
  259. if (this.Gview_gz.SortOrder == SortOrder.Descending)
  260. e.SortResult = -1;
  261. e.Handled = true;
  262. return;
  263. }
  264. if (this.Gview_gz.Rows[e.RowIndex2].Tag != null && this.Gview_gz.Rows[e.RowIndex2].Tag.ToString() == "统计行")
  265. {
  266. //ROW1<ROW2
  267. e.SortResult = -1;
  268. if (this.Gview_gz.SortOrder == SortOrder.Descending)
  269. e.SortResult = 1;
  270. e.Handled = true;
  271. return;
  272. }
  273. }
  274. private void Gview_gz_Sorted(object sender, EventArgs e)
  275. {
  276. //排序完成,重新设置序号
  277. for (int i = 0; i < Gview_gz.Rows.Count; i++)
  278. {
  279. if (Gview_gz.Rows[i].Tag != null && this.Gview_gz.Rows[i].Tag.ToString() == "统计行")
  280. { }
  281. else
  282. {
  283. Gview_gz.Rows[i].Cells[0].Value = i.ToString();
  284. }
  285. }
  286. }
  287. #endregion
  288. #region 获取向导出模块提供的DataTable和GridView对象
  289. /// <summary>
  290. /// 获取到该模块输出后形成的DataTable,和GridView
  291. /// </summary>
  292. /// <param name="out_dt"></param>
  293. /// <param name="out_dg"></param>
  294. public void GetDataTableAndGridView(out DataTable out_dt, out DataGridView out_dg)
  295. {
  296. out_dt = m_dt;
  297. out_dg = this.Gview_gz;
  298. }
  299. #endregion
  300. }
  301. }