ElementCompositionAvgGrid.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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. dt = particledata.GetAreaByAllIncA(filedAndParticl);
  73. for (int i = 0; i < dt.Rows.Count; i++)
  74. {
  75. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) < 100)
  76. {
  77. continue;
  78. }
  79. double total = Convert.ToDouble(dt.Rows[i]["ar"]);
  80. //double small = Convert.ToDouble(dt.Rows[i]["small"]);
  81. int add_rowindex = gridView.Rows.Add();
  82. gridView.Rows[add_rowindex].Cells[0].Value = add_rowindex + 1;
  83. gridView.Rows[add_rowindex].Cells[1].Value = dt.Rows[i]["TypeName"];
  84. gridView.Rows[add_rowindex].Cells[1].Style.BackColor = Color.Azure;
  85. gridView.Rows[add_rowindex].Cells[2].Value = Math.Round(total, 2);
  86. gridView.Rows[add_rowindex].Cells[2].Style.BackColor = Color.Azure;
  87. //Gview_gz.Rows[add_rowindex].Cells[3].Value = Math.Round(small, 2);
  88. //Gview_gz.Rows[add_rowindex].Cells[3].Style.BackColor = Color.Azure;
  89. gridView.Rows[add_rowindex].Cells[3].Value = dt.Rows[i]["con"];
  90. gridView.Rows[add_rowindex].Cells[3].Style.BackColor = Color.Azure;
  91. DataTable dtp = particledata.GetAreaByIncA(dt.Rows[i]["TypeId"].ToString(), filedAndParticl);
  92. for (int j = 4; j < gridView.Columns.Count; j++)
  93. {
  94. int col = 0;
  95. foreach (DataRow dr in dtp.Rows)
  96. {
  97. if (gridView.Columns[j].Name == dr["name"].ToString())
  98. {
  99. double ar = Convert.ToDouble(dr["pc"]);
  100. double p = Math.Round(ar / total, 2);
  101. gridView.Rows[add_rowindex].Cells[j].Value = DrawFunction.GetProcessBitmap((float)p, Color.Azure);
  102. gridView.Rows[add_rowindex].Cells[j].Tag = p;
  103. break;
  104. }
  105. col++;
  106. }
  107. if (col == dtp.Rows.Count)
  108. {
  109. gridView.Rows[add_rowindex].Cells[j].Value = DrawFunction.GetProcessBitmap(0, Color.Azure);
  110. gridView.Rows[add_rowindex].Cells[j].Tag = 0;
  111. }
  112. }
  113. }
  114. for (int i = 0; i < dt.Rows.Count; i++)
  115. {
  116. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) > 100)
  117. {
  118. continue;
  119. }
  120. int add_rowindex = gridView.Rows.Add();
  121. gridView.Rows[add_rowindex].Cells[0].Value = add_rowindex + 1;
  122. int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[i]["TypeId"]));
  123. if (index == -1)
  124. {
  125. index = 7;
  126. }
  127. string name = NameList[index];
  128. double total = Convert.ToDouble(dt.Rows[i]["ar"]);
  129. //double small = Convert.ToDouble(dt.Rows[i]["small"]);
  130. gridView.Rows[add_rowindex].Cells[1].Value = dt.Rows[i]["TypeName"];
  131. //Gview_gz.Rows[add_rowindex].Cells[1].Value = name;
  132. gridView.Rows[add_rowindex].Cells[1].Style.BackColor = Color.Azure;
  133. gridView.Rows[add_rowindex].Cells[2].Value = Math.Round(total, 2);
  134. gridView.Rows[add_rowindex].Cells[2].Style.BackColor = Color.Azure;
  135. //Gview_gz.Rows[add_rowindex].Cells[3].Value = Math.Round(small, 2);
  136. gridView.Rows[add_rowindex].Cells[3].Style.BackColor = Color.Azure;
  137. gridView.Rows[add_rowindex].Cells[3].Value = dt.Rows[i]["con"];
  138. //Gview_gz.Rows[add_rowindex].Cells[4].Style.BackColor = Color.Azure;
  139. DataTable dtp = particledata.GetAreaByIncA(dt.Rows[i]["TypeId"].ToString(), filedAndParticl);
  140. for (int j = 4; j < gridView.Columns.Count; j++)
  141. {
  142. int col = 0;
  143. foreach (DataRow dr in dtp.Rows)
  144. {
  145. if (gridView.Columns[j].Name == dr["name"].ToString())
  146. {
  147. double ar = Convert.ToDouble(dr["pc"]);
  148. double p = Math.Round(ar / total, 2);
  149. gridView.Rows[add_rowindex].Cells[j].Value = DrawFunction.GetProcessBitmap((float)p, Color.Azure);
  150. gridView.Rows[add_rowindex].Cells[j].Tag = p;
  151. break;
  152. }
  153. col++;
  154. }
  155. if (col == dtp.Rows.Count)
  156. {
  157. gridView.Rows[add_rowindex].Cells[j].Value = DrawFunction.GetProcessBitmap(0, Color.Azure);
  158. gridView.Rows[add_rowindex].Cells[j].Tag = 0;
  159. }
  160. }
  161. }
  162. gridView.Name = "gridView" + num.ToString();
  163. dgv = gridView;
  164. //设置grid风格
  165. SetDataGridViewStyle(gridView);
  166. panel1.Controls.Add(gridView);
  167. }
  168. /// <summary>
  169. /// 设置DataGridView样式
  170. /// </summary>
  171. private void SetDataGridViewStyle(OTSGridView gridView)
  172. {
  173. //用户不能调整标题的高度
  174. gridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  175. //用户不能调整 行高
  176. gridView.AllowUserToResizeRows = false;
  177. //改变行的高度;
  178. //gridView.RowTemplate.Height = 20;
  179. //点击选择整行
  180. gridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  181. //居中显示
  182. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  183. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  184. gridView.DefaultCellStyle = dataGridViewCellStyle1;
  185. gridView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  186. //再次重覆禁用拖动表头高度,居然有效果了
  187. gridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  188. //设置grid可以复制
  189. gridView.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
  190. //设置每列的宽度
  191. gridView.Columns[0].Width = 40;//第一列序号的宽度设置一下吧,要不太丑
  192. gridView.Columns[1].Width = 200;
  193. //设置序号列不排序
  194. gridView.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  195. //设置序号列不可以设置宽度
  196. gridView.Columns[0].Resizable = DataGridViewTriState.False;
  197. gridView.AllowUserToAddRows = false;
  198. gridView.AllowUserToDeleteRows = false;
  199. gridView.AllowUserToResizeRows = false;
  200. gridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
  201. gridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  202. gridView.ContextMenuStrip = this.contextMenuStrip1;
  203. gridView.BorderStyle = 0;
  204. //gridView.Dock = System.Windows.Forms.DockStyle.Fill;
  205. //gridView.Location = new System.Drawing.Point(0, 0);
  206. gridView.Location = new System.Drawing.Point(0, gridheight);
  207. gridView.Margin = new System.Windows.Forms.Padding(2);
  208. gridView.MergeColumnHeaderBackColor = System.Drawing.SystemColors.ButtonHighlight;
  209. //gridView.Name = "Gview_gz";
  210. gridView.ReadOnly = true;
  211. gridView.RowHeadersVisible = false;
  212. gridView.RowHeadersWidth = 40;
  213. gridView.RowTemplate.Height = 30;
  214. //gridView.Size = new System.Drawing.Size(667, 520);
  215. gridView.Size = new System.Drawing.Size(gridView.ColumnCount * 100 + 60, gridView.RowCount * 30 + 30);
  216. gridheight = gridheight + gridView.RowCount * 30 + 80;
  217. gridView.TabIndex = 0;
  218. gridView.SortCompare += new System.Windows.Forms.DataGridViewSortCompareEventHandler(this.Gview_gz_SortCompare);
  219. gridView.Sorted += new System.EventHandler(this.Gview_gz_Sorted);
  220. //先设置一下头的高度,否则会太矮不好看
  221. gridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
  222. gridView.ColumnHeadersHeight = 40;
  223. }
  224. #endregion
  225. #region 初始化构造函数
  226. /// <summary>
  227. /// 元素平均含量表,构造函数
  228. /// </summary>
  229. /// <param name="in_sec">传入,委托类对象</param>
  230. /// <param name="in_Cotsreportprojfilemgrclr">传入,项目管理类对象</param>
  231. public ElementCompositionAvgGrid(OTSIncAReportApp.frmReportApp ReportApp)
  232. {
  233. m_ReportApp = ReportApp;
  234. result = m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResultId()];
  235. m_condition = ReportApp.m_conditionChoose;
  236. InitializeComponent();
  237. lan = new Language(this);
  238. table = lan.GetNameTable(this.Name);
  239. m_DataMgr = ReportApp.m_rstDataMgr;
  240. }
  241. private void ElementContentGrid_Load(object sender, EventArgs e)
  242. {
  243. string sou = "";
  244. int sel = 0;
  245. if (Report)
  246. {
  247. sou = m_DataMgr.ResultFilesList[m_DataMgr.getSelectedIndex()].anotherFileName.ToString();
  248. if (ParticleRange)
  249. {
  250. sel = 0;
  251. }
  252. else
  253. {
  254. sel = 1;
  255. }
  256. }
  257. else
  258. {
  259. sou = m_condition.m_CurrentConditions[OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE].itemDisplayVal.ToString();
  260. sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  261. }
  262. Report = false;
  263. //string sou = m_ReportApp.m_conditionChoose.m_SourceGridData.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  264. if (sou.Contains("+"))
  265. {
  266. for (int i = 0; i < sou.Split('+').Length; i++)
  267. {
  268. ResultFile resultFile = m_ReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
  269. if (resultFile != null)
  270. {
  271. BindDataGridView(resultFile.FilePath, i, resultFile.anotherFileName, sel);
  272. }
  273. }
  274. }
  275. else
  276. {
  277. for (int i = 0; i < m_ReportApp.m_rstDataMgr.ResultFilesList.Count; i++)
  278. {
  279. if (sou == m_ReportApp.m_rstDataMgr.ResultFilesList[i].anotherFileName.ToString())
  280. {
  281. BindDataGridView(m_ReportApp.m_rstDataMgr.ResultFilesList[i].FilePath, 0, m_ReportApp.m_rstDataMgr.ResultFilesList[i].anotherFileName, sel);
  282. }
  283. }
  284. //BindDataGridView(m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResult()].FilePath, 0, m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResult()].FileName);
  285. ////设置grid风格
  286. //SetDataGridViewStyle();
  287. }
  288. //particledata = new OTSIncAReportApp.DataOperation.DataAccess.ParticleData(result.FilePath);
  289. ////创建datatable的列数据,及分栏,及相关行数据
  290. //BindDataGridView();
  291. ////设置grid风格
  292. //SetDataGridViewStyle();
  293. }
  294. #endregion
  295. #region 相关事件
  296. private void ToolStripMenuItem1_Click(object sender, EventArgs e)
  297. {
  298. //复制整个表
  299. CopyAll();
  300. }
  301. private void ToolStripMenuItem2_Click(object sender, EventArgs e)
  302. {
  303. //复制选择区域
  304. CopySelected();
  305. }
  306. /// <summary>
  307. /// 复制选择区域
  308. /// </summary>
  309. public void CopySelected()
  310. {
  311. //复制选择区域
  312. object oo = Gview_gz.GetClipboardContent();
  313. Clipboard.SetDataObject(Gview_gz.GetClipboardContent());
  314. }
  315. /// <summary>
  316. /// 复制所有
  317. /// </summary>
  318. public void CopyAll()
  319. {
  320. Gview_gz.SelectAll();
  321. Clipboard.SetDataObject(Gview_gz.GetClipboardContent());
  322. }
  323. private void ToolStripMenuItem3_Click(object sender, EventArgs e)
  324. {
  325. //恢复至初始状态
  326. Gview_gz.Rows.Clear();
  327. Gview_gz.Columns.Clear();
  328. //BindDataGridView();
  329. //SetDataGridViewStyle();
  330. }
  331. private void Gview_gz_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
  332. {
  333. //排序中
  334. if (this.Gview_gz.Rows[e.RowIndex1].Tag != null && this.Gview_gz.Rows[e.RowIndex1].Tag.ToString() == "统计行")
  335. {
  336. //ROW1>ROW2
  337. e.SortResult = 1;
  338. if (this.Gview_gz.SortOrder == SortOrder.Descending)
  339. e.SortResult = -1;
  340. e.Handled = true;
  341. return;
  342. }
  343. if (this.Gview_gz.Rows[e.RowIndex2].Tag != null && this.Gview_gz.Rows[e.RowIndex2].Tag.ToString() == "统计行")
  344. {
  345. //ROW1<ROW2
  346. e.SortResult = -1;
  347. if (this.Gview_gz.SortOrder == SortOrder.Descending)
  348. e.SortResult = 1;
  349. e.Handled = true;
  350. return;
  351. }
  352. }
  353. private void Gview_gz_Sorted(object sender, EventArgs e)
  354. {
  355. //排序完成,重新设置序号
  356. for (int i = 0; i < Gview_gz.Rows.Count; i++)
  357. {
  358. if (Gview_gz.Rows[i].Tag != null && this.Gview_gz.Rows[i].Tag.ToString() == "统计行")
  359. { }
  360. else
  361. {
  362. Gview_gz.Rows[i].Cells[0].Value = i.ToString();
  363. }
  364. }
  365. }
  366. #endregion
  367. #region 获取向导出模块提供的DataTable和GridView对象
  368. /// <summary>
  369. /// 获取到该模块输出后形成的DataTable,和GridView
  370. /// </summary>
  371. /// <param name="out_dt"></param>
  372. /// <param name="out_dg"></param>
  373. public void GetDataTableAndGridView(out DataTable out_dt, out DataGridView out_dg)
  374. {
  375. out_dt = m_dt;
  376. //out_dt = (this.Gview_gz.DataSource as DataTable);
  377. //out_dg = this.Gview_gz;
  378. out_dg = dgv;
  379. }
  380. #endregion
  381. }
  382. }