ElementCompositionAvgGrid.cs 14 KB

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