ElementCompositionAvgGrid.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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 = name;
  140. Gview_gz.Rows[add_rowindex].Cells[1].Style.BackColor = Color.Azure;
  141. Gview_gz.Rows[add_rowindex].Cells[2].Value = Math.Round(total, 2);
  142. Gview_gz.Rows[add_rowindex].Cells[2].Style.BackColor = Color.Azure;
  143. //Gview_gz.Rows[add_rowindex].Cells[3].Value = Math.Round(small, 2);
  144. Gview_gz.Rows[add_rowindex].Cells[3].Style.BackColor = Color.Azure;
  145. Gview_gz.Rows[add_rowindex].Cells[3].Value = dt.Rows[i]["con"];
  146. //Gview_gz.Rows[add_rowindex].Cells[4].Style.BackColor = Color.Azure;
  147. DataTable dtp = particledata.GetAreaByIncA(dt.Rows[i]["TypeId"].ToString(), filedAndParticl);
  148. for (int j = 4; j < Gview_gz.Columns.Count; j++)
  149. {
  150. int col = 0;
  151. foreach (DataRow dr in dtp.Rows)
  152. {
  153. if (Gview_gz.Columns[j].Name == dr["name"].ToString())
  154. {
  155. double ar = Convert.ToDouble(dr["pc"]);
  156. double p = Math.Round(ar / total, 2);
  157. Gview_gz.Rows[add_rowindex].Cells[j].Value = DrawFunction.GetProcessBitmap((float)p, Color.Azure);
  158. Gview_gz.Rows[add_rowindex].Cells[j].Tag = p;
  159. break;
  160. }
  161. col++;
  162. }
  163. if (col == dtp.Rows.Count)
  164. {
  165. Gview_gz.Rows[add_rowindex].Cells[j].Value = DrawFunction.GetProcessBitmap(0, Color.Azure);
  166. Gview_gz.Rows[add_rowindex].Cells[j].Tag = 0;
  167. }
  168. }
  169. }
  170. }
  171. /// <summary>
  172. /// 设置DataGridView样式
  173. /// </summary>
  174. private void SetDataGridViewStyle()
  175. {
  176. //用户不能调整标题的高度
  177. //Gview_gz.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  178. //用户不能调整 行高
  179. Gview_gz.AllowUserToResizeRows = false;
  180. //改变行的高度;
  181. //Gview_gz.RowTemplate.Height = 20;
  182. //点击选择整行
  183. Gview_gz.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  184. //居中显示
  185. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  186. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  187. Gview_gz.DefaultCellStyle = dataGridViewCellStyle1;
  188. Gview_gz.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  189. //再次重覆禁用拖动表头高度,居然有效果了
  190. //Gview_gz.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  191. //设置grid可以复制
  192. Gview_gz.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
  193. //设置每列的宽度
  194. Gview_gz.Columns[0].Width = 40;//第一列序号的宽度设置一下吧,要不太丑
  195. Gview_gz.Columns[1].Width = 200;
  196. //设置序号列不排序
  197. Gview_gz.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  198. //设置序号列不可以设置宽度
  199. Gview_gz.Columns[0].Resizable = DataGridViewTriState.False;
  200. //设置所有行的高度
  201. for (int i = 0; i < Gview_gz.Rows.Count; i++)
  202. {
  203. Gview_gz.Rows[i].Height = 30;
  204. }
  205. }
  206. #endregion
  207. #region 初始化构造函数
  208. /// <summary>
  209. /// 元素平均含量表,构造函数
  210. /// </summary>
  211. /// <param name="in_sec">传入,委托类对象</param>
  212. /// <param name="in_Cotsreportprojfilemgrclr">传入,项目管理类对象</param>
  213. public ElementCompositionAvgGrid(OTSIncAReportApp.frmReportApp ReportApp)
  214. {
  215. m_ReportApp = ReportApp;
  216. result = m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResult()];
  217. InitializeComponent();
  218. lan = new Language(this);
  219. table = lan.GetNameTable(this.Name);
  220. }
  221. private void ElementContentGrid_Load(object sender, EventArgs e)
  222. {
  223. particledata = new OTSIncAReportApp.DataOperation.DataAccess.ParticleData(result.FilePath);
  224. //创建datatable的列数据,及分栏,及相关行数据
  225. BindDataGridView();
  226. //设置grid风格
  227. SetDataGridViewStyle();
  228. }
  229. #endregion
  230. #region 相关事件
  231. private void ToolStripMenuItem1_Click(object sender, EventArgs e)
  232. {
  233. //复制整个表
  234. CopyAll();
  235. }
  236. private void ToolStripMenuItem2_Click(object sender, EventArgs e)
  237. {
  238. //复制选择区域
  239. CopySelected();
  240. }
  241. /// <summary>
  242. /// 复制选择区域
  243. /// </summary>
  244. public void CopySelected()
  245. {
  246. //复制选择区域
  247. object oo = Gview_gz.GetClipboardContent();
  248. Clipboard.SetDataObject(Gview_gz.GetClipboardContent());
  249. }
  250. /// <summary>
  251. /// 复制所有
  252. /// </summary>
  253. public void CopyAll()
  254. {
  255. Gview_gz.SelectAll();
  256. Clipboard.SetDataObject(Gview_gz.GetClipboardContent());
  257. }
  258. private void ToolStripMenuItem3_Click(object sender, EventArgs e)
  259. {
  260. //恢复至初始状态
  261. Gview_gz.Rows.Clear();
  262. Gview_gz.Columns.Clear();
  263. BindDataGridView();
  264. SetDataGridViewStyle();
  265. }
  266. private void Gview_gz_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
  267. {
  268. //排序中
  269. if (this.Gview_gz.Rows[e.RowIndex1].Tag != null && this.Gview_gz.Rows[e.RowIndex1].Tag.ToString() == "统计行")
  270. {
  271. //ROW1>ROW2
  272. e.SortResult = 1;
  273. if (this.Gview_gz.SortOrder == SortOrder.Descending)
  274. e.SortResult = -1;
  275. e.Handled = true;
  276. return;
  277. }
  278. if (this.Gview_gz.Rows[e.RowIndex2].Tag != null && this.Gview_gz.Rows[e.RowIndex2].Tag.ToString() == "统计行")
  279. {
  280. //ROW1<ROW2
  281. e.SortResult = -1;
  282. if (this.Gview_gz.SortOrder == SortOrder.Descending)
  283. e.SortResult = 1;
  284. e.Handled = true;
  285. return;
  286. }
  287. }
  288. private void Gview_gz_Sorted(object sender, EventArgs e)
  289. {
  290. //排序完成,重新设置序号
  291. for (int i = 0; i < Gview_gz.Rows.Count; i++)
  292. {
  293. if (Gview_gz.Rows[i].Tag != null && this.Gview_gz.Rows[i].Tag.ToString() == "统计行")
  294. { }
  295. else
  296. {
  297. Gview_gz.Rows[i].Cells[0].Value = i.ToString();
  298. }
  299. }
  300. }
  301. #endregion
  302. #region 获取向导出模块提供的DataTable和GridView对象
  303. /// <summary>
  304. /// 获取到该模块输出后形成的DataTable,和GridView
  305. /// </summary>
  306. /// <param name="out_dt"></param>
  307. /// <param name="out_dg"></param>
  308. public void GetDataTableAndGridView(out DataTable out_dt, out DataGridView out_dg)
  309. {
  310. out_dt = m_dt;
  311. out_dg = this.Gview_gz;
  312. }
  313. #endregion
  314. }
  315. }