ElementCompositionAvgGrid.cs 18 KB

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