ElementCompositionAvgGrid.cs 14 KB

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