ElementCompositionAvgGrid.cs 14 KB

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