ElementCompositionAvgGrid.cs 19 KB

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