ParticlesSizeGrid.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. 
  2. using DevExpress.Utils;
  3. using DevExpress.XtraCharts;
  4. using OTSIncAReportApp._1_UI.Control_DEVCharts;
  5. using OTSIncAReportApp.OTSRstMgrFunction;
  6. using OTSIncAReportApp.OTSSampleReportInfo;
  7. using OTSIncAReportApp.SysMgrTools;
  8. using OTSIncAReportGraph.Class;
  9. using System;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Linq;
  15. using System.Windows.Forms;
  16. namespace OTSIncAReportGrids
  17. {
  18. /// <summary>
  19. /// 颗粒尺寸分布表 颗粒尺寸表
  20. /// </summary>
  21. public partial class ParticlesSizeGrid : UserControl
  22. {
  23. #region 设置变量
  24. //设置模拟数据表
  25. public DataTable m_dt = new DataTable();
  26. //国际化
  27. Language lan;
  28. Hashtable table;
  29. //测量结果
  30. ResultFile result = null;
  31. OTSIncAReportApp.OTSSampleReportInfo.ReportCondition source;
  32. OTSIncAReportApp.frmReportApp m_ReportApp;
  33. int gridheight = 0;
  34. int gridwidth = 0;
  35. public string condition = "";
  36. List<DataTable> list_table_data = new List<DataTable>();
  37. List<Point> list_table_size = new List<Point>();
  38. List<Point> list_table_Point = new List<Point>();
  39. List<string> list_fileName = new List<string>();
  40. #endregion
  41. #region 自定义方法
  42. private string getWhere(string max, string min, string col, string partic)
  43. {
  44. if (col == "Area")
  45. {
  46. return col + ">=" + ((Convert.ToDouble(min)/2) * (Convert.ToDouble(min)/2) * Math.PI).ToString() + " and " + col + "<" + ((Convert.ToDouble(max)/2) * (Convert.ToDouble(max)/2) * Math.PI).ToString() + " and TypeId=" + partic;
  47. }
  48. else
  49. {
  50. return col + ">=" + min + " and " + col + "<" + max + " and TypeId=" + partic;
  51. }
  52. }
  53. /// <summary>
  54. /// 绑定datagridview数据
  55. /// </summary>
  56. public void BindDataGridView(string path, int num, string filename)
  57. {
  58. List<string> colid = new List<string>() { "rowid", "pname", "color", "TypeId", "Largest", "Total" };
  59. List<string> colname = new List<string>() { table["str1"].ToString(), table["str8"].ToString(), table["str9"].ToString(), "TypeId", table["str10"].ToString(), table["str11"].ToString() };
  60. OTSGridView gridView = new OTSGridView();
  61. OTSIncAReportApp.DataOperation.DataAccess.ParticleData particledata = new OTSIncAReportApp.DataOperation.DataAccess.ParticleData(path);
  62. DataTable dtp = particledata.GetParticleAll("");
  63. string sizestr = null;
  64. string con = "";
  65. if (condition != "")
  66. {
  67. con = condition;
  68. }
  69. else
  70. {
  71. con = source.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.SIZE_CAL_METHOD_TYPE).ToString();
  72. }
  73. string po = "";
  74. switch (con)
  75. {
  76. case "DMAX":
  77. po = "DMAX";
  78. break;
  79. case "DMIN":
  80. po = "DMIN";
  81. break;
  82. case "ECD":
  83. po = "Area";
  84. break;
  85. case "FERET":
  86. po = "DFERET";
  87. break;
  88. }
  89. //获取粒级表
  90. if (m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile == "AUTO.psf")
  91. {
  92. double dn = 99999;
  93. string sou = source.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  94. if (sou.Contains("+"))
  95. {
  96. for (int i = 0; i < sou.Split('+').Length; i++)
  97. {
  98. ResultFile resultFile = m_ReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
  99. if (resultFile != null)
  100. {
  101. if(dn> resultFile.GetParticleMINECD())
  102. {
  103. dn = resultFile.GetParticleMINECD();
  104. }
  105. }
  106. }
  107. }
  108. else
  109. {
  110. ResultFile resultFile = m_ReportApp.m_rstDataMgr.CurResultFile;
  111. dn = resultFile.GetParticleMINECD();
  112. }
  113. sizestr = dn.ToString()+",";
  114. for(double p= dn; p<50;p=p * Math.Sqrt(2))
  115. {
  116. if(p > dn&& p <= 50.5)
  117. {
  118. double dd = Math.Round(p);
  119. sizestr += dd.ToString() + ",";
  120. }
  121. }
  122. sizestr = sizestr.Remove(sizestr.Length - 1, 1);
  123. }
  124. else
  125. {
  126. string path1 = m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFileFolder + m_ReportApp.m_rstDataMgr.m_RptConfigFile.PartSizeFile;
  127. DataSet ds = OTSIncAReportApp.DataOperation.DataAccess.XMLoperate.GetXml(path1);
  128. sizestr = ds.Tables[0].Rows[0]["Sizes"].ToString();
  129. }
  130. for (int i = 0; i < sizestr.Split(',').Length - 1; i++)
  131. {
  132. if (sizestr.Split(',')[i].Length > 0)
  133. {
  134. double d1 = Convert.ToDouble(sizestr.Split(',')[i]);
  135. double d2 = Convert.ToDouble(sizestr.Split(',')[i + 1]);
  136. colid.Add(d1.ToString() + "~" + d2.ToString());
  137. colname.Add(d1.ToString() + "~" + d2.ToString());
  138. }
  139. }
  140. double d = Convert.ToDouble(sizestr.Split(',')[sizestr.Split(',').Length - 1]);
  141. colid.Add(d.ToString() + "~MAX");
  142. colname.Add(d.ToString() + "~MAX");
  143. //创建Grid的列 创建Datatable的列
  144. for (int i = 0; i < colid.Count; i++)
  145. {
  146. gridView.Columns.Add(colid[i], colname[i]);
  147. if (!m_dt.Columns.Contains(colid[i]))
  148. m_dt.Columns.Add(colid[i]);
  149. }
  150. if (!m_dt.Columns.Contains("Class"))
  151. m_dt.Columns.Add("Class");
  152. //设置grid默认值的样式,防止图像为空时有红x
  153. for (int i = 0; i < gridView.Columns.Count; i++)
  154. {
  155. gridView.Columns[i].DefaultCellStyle.NullValue = null;
  156. }
  157. List<int> FLID = new List<int>() { 0, 1, 2, 4, 6, 7, 8, 9 };
  158. 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() };
  159. //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  160. //int sel = m_ReportApp.SourceGridData.ConditionItemList[idx].comboDownList.IndexOf(m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString());
  161. int sel = m_ReportApp.m_conditionChoose.m_conditionData.GetComboDownListIndexByItemName(OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE_TYPE);
  162. string filedAndParticl = "";
  163. DataTable dt;
  164. dt = particledata.GetParticleListForParticlSize("area", filedAndParticl);
  165. gridView.MergeColumnNames.Add(filename);
  166. gridView.AddSpanHeader(1, gridView.Columns.Count - 1, filename);
  167. for (int i = 0; i < dt.Rows.Count; i++)
  168. {
  169. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) < 100)
  170. {
  171. continue;
  172. }
  173. int add_rowindex = gridView.Rows.Add();
  174. gridView.Rows[add_rowindex].Cells[0].Value = add_rowindex + 1;
  175. gridView.Rows[add_rowindex].Cells[1].Value = dt.Rows[i]["TypeName"];
  176. gridView.Rows[add_rowindex].Cells[1].Style.BackColor = Color.Azure;
  177. string color = dt.Rows[i]["TypeColor"].ToString();
  178. if (!color.Contains("#"))
  179. {
  180. color = "#" + dt.Rows[i]["TypeColor"].ToString();
  181. }
  182. gridView.Rows[add_rowindex].Cells[2].Style.BackColor = DrawFunction.colorHx16toRGB(color);
  183. gridView.Rows[add_rowindex].Cells[3].Value = dt.Rows[i]["TypeId"];
  184. gridView.Rows[add_rowindex].Cells[4].Value = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2);
  185. gridView.Rows[add_rowindex].Cells[4].Style.BackColor = Color.Azure;
  186. gridView.Rows[add_rowindex].Cells[5].Value = dt.Rows[i]["con"];
  187. gridView.Rows[add_rowindex].Cells[5].Style.BackColor = Color.Azure;
  188. m_dt.Rows.Add();
  189. m_dt.Rows[add_rowindex]["pname"]= dt.Rows[i]["TypeName"];
  190. m_dt.Rows[add_rowindex]["TypeId"]=dt.Rows[i]["TypeId"];
  191. m_dt.Rows[add_rowindex]["Largest"] = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2);
  192. m_dt.Rows[add_rowindex]["Total"]= dt.Rows[i]["con"];
  193. m_dt.Rows[add_rowindex]["Class"] = dt.Rows[i]["GroupName"];
  194. }
  195. for (int i = 0; i < dt.Rows.Count; i++)
  196. {
  197. if (Convert.ToInt32(dt.Rows[i]["TypeId"]) > 100)
  198. {
  199. continue;
  200. }
  201. int add_rowindex = gridView.Rows.Add();
  202. gridView.Rows[add_rowindex].Cells[0].Value = add_rowindex + 1;
  203. int index = FLID.IndexOf(Convert.ToInt32(dt.Rows[i]["TypeId"]));
  204. if (index == -1)
  205. {
  206. index = 7;
  207. }
  208. string name = NameList[index];
  209. //gridView.Rows[add_rowindex].Cells[1].Value = name;
  210. gridView.Rows[add_rowindex].Cells[1].Value = dt.Rows[i]["TypeName"];
  211. gridView.Rows[add_rowindex].Cells[1].Style.BackColor = Color.Azure;
  212. string color = "#000000";
  213. gridView.Rows[add_rowindex].Cells[2].Style.BackColor = DrawFunction.colorHx16toRGB(color);
  214. gridView.Rows[add_rowindex].Cells[3].Value = dt.Rows[i]["TypeId"];
  215. gridView.Rows[add_rowindex].Cells[4].Value = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2);
  216. gridView.Rows[add_rowindex].Cells[4].Style.BackColor = Color.Azure;
  217. gridView.Rows[add_rowindex].Cells[5].Value = dt.Rows[i]["con"];
  218. gridView.Rows[add_rowindex].Cells[5].Style.BackColor = Color.Azure;
  219. m_dt.Rows.Add();
  220. m_dt.Rows[add_rowindex]["pname"] = dt.Rows[i]["TypeName"];
  221. m_dt.Rows[add_rowindex]["TypeId"] = dt.Rows[i]["TypeId"];
  222. m_dt.Rows[add_rowindex]["Largest"] = Math.Round(Convert.ToDouble(dt.Rows[i]["max"]), 2);
  223. m_dt.Rows[add_rowindex]["Total"] = dt.Rows[i]["con"];
  224. m_dt.Rows[add_rowindex]["Class"] = dt.Rows[i]["GroupName"];
  225. }
  226. for (int i = 0; i < gridView.Rows.Count - 1; i++)
  227. {
  228. for (int j = 6; j < colid.Count; j++)
  229. {
  230. string d1 = colid[j].Split('~')[0];
  231. string d2 = colid[j].Split('~')[1];
  232. if (d2 == "MAX")
  233. {
  234. d2 = "999";
  235. }
  236. DataRow[] datas = dtp.Select(getWhere(d2, d1, po, gridView.Rows[i].Cells[3].Value.ToString()));
  237. gridView.Rows[i].Cells[j].Value = datas.Count();
  238. gridView.Rows[i].Cells[j].Style.BackColor = Color.Azure;
  239. m_dt.Rows[i][colid[j]]= datas.Count();
  240. }
  241. }
  242. gridView.Columns[3].Visible = false;
  243. //设置grid默认值的样式,防止图像为空时有红x
  244. for (int i = 0; i < gridView.Columns.Count; i++)
  245. {
  246. gridView.Columns[i].DefaultCellStyle.NullValue = null;
  247. }
  248. gridView.Name = "gridView" + num.ToString();
  249. int a1=gridView.Rows.Add();
  250. gridView.Rows[a1].Cells[1].Value = "Sum";
  251. for(int j=0;j< gridView.Rows.Count-2;j++)
  252. {
  253. for(int k=4;k< gridView.Columns.Count;k++)
  254. {
  255. if (gridView.Rows[a1].Cells[k].Value == null)
  256. gridView.Rows[a1].Cells[k].Value = 0;
  257. gridView.Rows[a1].Cells[k].Value = Convert.ToInt32(gridView.Rows[a1].Cells[k].Value)+ Convert.ToInt32(gridView.Rows[j].Cells[k].Value);
  258. }
  259. }
  260. list_table_Point.Add(SetDataGridViewStyle(gridView));
  261. panel1.Controls.Add(gridView);
  262. list_table_data.Add(m_dt);
  263. }
  264. /// <summary>
  265. /// 设置DataGridView样式
  266. /// </summary>
  267. private Point SetDataGridViewStyle(OTSGridView gridView)
  268. {
  269. //用户不能调整标题的高度
  270. gridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  271. //用户不能调整 行高
  272. gridView.AllowUserToResizeRows = false;
  273. //改变行的高度;
  274. //gridView.RowTemplate.Height = 20;
  275. //点击选择整行
  276. gridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
  277. //居中显示
  278. System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
  279. dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
  280. gridView.DefaultCellStyle = dataGridViewCellStyle1;
  281. gridView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
  282. //再次重覆禁用拖动表头高度,居然有效果了
  283. gridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
  284. //设置grid可以复制
  285. gridView.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
  286. //设置每列的宽度
  287. gridView.Columns[0].Width = 40;//第一列序号的宽度设置一下吧,要不太丑
  288. gridView.Columns[1].Width = 200;
  289. //设置序号列不排序
  290. gridView.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
  291. //设置序号列不可以设置宽度
  292. gridView.Columns[0].Resizable = DataGridViewTriState.False;
  293. gridView.AllowUserToAddRows = false;
  294. gridView.AllowUserToDeleteRows = false;
  295. gridView.AllowUserToResizeRows = false;
  296. gridView.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
  297. gridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
  298. gridView.ContextMenuStrip = this.contextMenuStrip1;
  299. gridView.BorderStyle = 0;
  300. int outpos = gridwidth;
  301. gridView.Location = new System.Drawing.Point(gridwidth, 0);
  302. gridView.Margin = new System.Windows.Forms.Padding(2);
  303. gridView.MergeColumnHeaderBackColor = System.Drawing.SystemColors.ButtonHighlight;
  304. gridView.ReadOnly = true;
  305. gridView.RowHeadersVisible = false;
  306. gridView.RowHeadersWidth = 40;
  307. gridView.RowTemplate.Height = 30;
  308. //gridView.Size = new System.Drawing.Size(gridView.ColumnCount * 100 + 60, gridView.RowCount * 30 + 30);
  309. int gridView_Width = 0;
  310. for (int i = 0; i < gridView.ColumnCount; i++)
  311. {
  312. gridView_Width = gridView_Width + gridView.Columns[i].Width;
  313. }
  314. gridView.Size = new System.Drawing.Size(gridView_Width, gridView.RowCount * 30);
  315. //gridheight = gridheight + gridView.RowCount * 30 + 80;
  316. gridheight = gridheight + gridView.RowCount * 30 + 5;
  317. gridwidth = gridwidth + gridView.ColumnCount * 100;
  318. gridView.TabIndex = 0;
  319. gridView.SortCompare += Gview_gz_SortCompare;
  320. gridView.Sorted += Gview_gz_Sorted;
  321. //先设置一下头的高度,否则会太矮不好看
  322. gridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing;
  323. gridView.ColumnHeadersHeight = 40;
  324. gridView.Columns[4].Visible = false;
  325. list_table_size.Add(new Point(gridView.ColumnCount * 100 - 40, gridView.RowCount * 30));
  326. return new Point(outpos, gridheight);
  327. //list_table_Point.Add(new Point(gridwidth, gridheight));
  328. }
  329. #endregion
  330. #region 窗体加载及初始化
  331. public ParticlesSizeGrid()
  332. {
  333. InitializeComponent();
  334. }
  335. /// <summary>
  336. /// 成份分布表,构造函数
  337. /// </summary>
  338. /// <param name="in_sec">传入,委托类对象</param>
  339. /// <param name="in_Cotsreportprojfilemgrclr">传入,项目管理类对象</param>
  340. public ParticlesSizeGrid(OTSIncAReportApp.frmReportApp ReportApp)
  341. {
  342. m_ReportApp = ReportApp;
  343. result = m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResultId()];
  344. source = m_ReportApp.m_conditionChoose.m_conditionData;
  345. InitializeComponent();
  346. //国际化
  347. lan = new Language(this);
  348. table = lan.GetNameTable(this.Name);
  349. }
  350. private void ParticlesSizeGrid_Load(object sender, EventArgs e)
  351. {
  352. list_table_data.Clear();
  353. list_table_size.Clear();
  354. list_table_Point.Clear();
  355. list_fileName.Clear();
  356. string sou = source.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  357. if (sou.Contains("+"))
  358. {
  359. for (int i = 0; i < sou.Split('+').Length; i++)
  360. {
  361. ResultFile resultFile = m_ReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
  362. if (resultFile != null)
  363. {
  364. BindDataGridView(resultFile.FilePath, i, resultFile.anotherFileName);
  365. list_fileName.Add(resultFile.anotherFileName);
  366. }
  367. }
  368. }
  369. else
  370. {
  371. for (int i=0;i< m_ReportApp.m_rstDataMgr.ResultFilesList.Count;i++)
  372. {
  373. if (sou == m_ReportApp.m_rstDataMgr.ResultFilesList[i].anotherFileName.ToString())
  374. {
  375. BindDataGridView(m_ReportApp.m_rstDataMgr.ResultFilesList[i].FilePath, 0, m_ReportApp.m_rstDataMgr.ResultFilesList[i].anotherFileName);
  376. list_fileName.Add(m_ReportApp.m_rstDataMgr.ResultFilesList[i].anotherFileName);
  377. }
  378. }
  379. }
  380. }
  381. public void SetGraphicType(ReportCondition sourceGridData)
  382. {
  383. string stdId = "";
  384. int stdIdIndex = 0;
  385. //find the stdId condition
  386. var STDIdItm = sourceGridData.ConditionItemList.Find(s => s.iItemId == OTS_REPORT_PROP_GRID_ITEMS.STD_ID);
  387. if (STDIdItm != null)
  388. {
  389. stdId = STDIdItm.itemDisplayVal.ToString();
  390. stdIdIndex = STDIdItm.comboDownList.IndexOf(stdId);
  391. }
  392. int high = 0;
  393. for (int i = 0; i < list_table_Point.Count; i++)
  394. {
  395. if (high < list_table_Point[i].Y)
  396. {
  397. high = list_table_Point[i].Y;
  398. }
  399. }
  400. for (int i = 0; i < list_table_data.Count; i++)
  401. {
  402. Graphics_Stacking(list_table_data[i], stdId, list_table_size[i],list_table_Point[i], high);
  403. }
  404. }
  405. /// <summary>
  406. /// chart图创建
  407. /// </summary>
  408. /// <param name="dt"></param>
  409. /// <param name="stdId"></param>
  410. private void Graphics_Stacking(DataTable dt, string stdId, Point a_size ,Point a_Location,int location_hig)
  411. {
  412. ChartControl chartControl1 = new ChartControl();
  413. chartControl1.Series.Clear();
  414. chartControl1.Size = new Size(a_size.X, a_size.Y);
  415. chartControl1.Location = new Point(a_Location.X, location_hig);
  416. DataTable dataTable = new DataTable();
  417. dataTable.Columns.Add("name");
  418. dataTable.Columns.Add("size");
  419. if (stdId != "All")
  420. {
  421. for (int i = 0; i < dt.Rows.Count; i++)
  422. {
  423. if (dt.Rows[i]["pname"].ToString() == stdId)
  424. {
  425. for (int a = 7; a < dt.Columns.Count-1; a++)
  426. {
  427. DataRow dr = dataTable.NewRow();
  428. dr["name"] = dt.Columns[a].ColumnName;
  429. dr["size"] = Convert.ToInt16(dt.Rows[i][a]);
  430. dataTable.Rows.Add(dr);
  431. }
  432. }
  433. }
  434. }
  435. if (stdId == "All")
  436. {
  437. List<Series> seriesList = new List<Series>();
  438. DataTable data = new DataTable();
  439. data.Columns.Add("name");
  440. data.Columns.Add("range");
  441. data.Columns.Add("num");
  442. for (int i = 0; i < dt.Rows.Count; i++)
  443. {
  444. if (dt.Rows[i]["pname"].ToString() != "")
  445. {
  446. for (int a = 6; a < dt.Columns.Count - 1; a++)
  447. {
  448. DataRow dr = data.NewRow();
  449. dr["name"] = dt.Rows[i]["pname"].ToString();
  450. dr["range"] = dt.Columns[a].ColumnName;
  451. dr["num"] = dt.Rows[i][a].ToString();
  452. data.Rows.Add(dr);
  453. }
  454. }
  455. }
  456. foreach (DataRow dr in data.DefaultView.ToTable(true, "name").Rows)
  457. {
  458. Series s = new Series(dr["name"].ToString(), ViewType.StackedBar)
  459. {
  460. LegendTextPattern = dr["name"].ToString(),
  461. ArgumentScaleType = ScaleType.Qualitative,
  462. };
  463. foreach (DataRow drl in data.Select("name='" + dr["name"].ToString() + "'"))
  464. s.Points.Add(new SeriesPoint(drl["range"].ToString(), int.Parse(drl["num"].ToString())));
  465. s.LabelsVisibility = DefaultBoolean.False;
  466. seriesList.Add(s);
  467. }
  468. foreach (Series sr in seriesList.ToArray())
  469. chartControl1.Series.Add(sr);
  470. }
  471. else
  472. {
  473. // 假设你已经有一个 ChartControl 实例,并且已经添加了一个饼图 Series
  474. Series series = new Series(stdId, ViewType.Bar);
  475. for (int a = 0; a < dataTable.Rows.Count; a++)
  476. {
  477. string name = dataTable.Rows[a]["name"].ToString();
  478. double Cunt = Convert.ToDouble(dataTable.Rows[a]["size"]);
  479. series.Points.Add(new SeriesPoint(name, Cunt));
  480. }
  481. series.LabelsVisibility = DefaultBoolean.True;
  482. chartControl1.Series.Add(series);
  483. }
  484. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Text = "";
  485. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Text = "";
  486. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Visibility = DefaultBoolean.True;
  487. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Visibility = DefaultBoolean.True;
  488. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Font = new Font("Tahoma", 9);
  489. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Font = new Font("Tahoma", 9);
  490. ((XYDiagram)chartControl1.Diagram).AxisY.Title.Alignment = System.Drawing.StringAlignment.Far;
  491. ((XYDiagram)chartControl1.Diagram).AxisX.Title.Alignment = System.Drawing.StringAlignment.Far;
  492. //图例的位置定义
  493. chartControl1.Legend.AlignmentVertical = LegendAlignmentVertical.Top;
  494. chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.RightOutside;
  495. chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
  496. chartControl1.Legend.Direction = LegendDirection.TopToBottom;
  497. //十字准线光标
  498. chartControl1.CrosshairEnabled = DefaultBoolean.True;
  499. chartControl1.CrosshairOptions.ShowValueLine = true;
  500. chartControl1.CrosshairOptions.ShowArgumentLabels = true;
  501. panel1.Controls.Add(chartControl1);
  502. }
  503. #endregion
  504. #region 相关事件
  505. private void ToolStripMenuItem1_Click(object sender, EventArgs e)
  506. {
  507. //复制整个表
  508. CopyAll();
  509. }
  510. private void ToolStripMenuItem2_Click(object sender, EventArgs e)
  511. {
  512. CopySelected();
  513. }
  514. /// <summary>
  515. /// 复制选择区域
  516. /// </summary>
  517. public void CopySelected()
  518. {
  519. foreach (var item in panel1.Controls)
  520. {
  521. if (item.GetType().ToString() == "OTSGridView")
  522. {
  523. //复制选择区域
  524. object oo = ((OTSGridView)item).GetClipboardContent();
  525. Clipboard.SetDataObject(((OTSGridView)item).GetClipboardContent());
  526. }
  527. }
  528. }
  529. /// <summary>
  530. /// 复制所有
  531. /// </summary>
  532. public void CopyAll()
  533. {
  534. foreach (var item in panel1.Controls)
  535. {
  536. if (item.GetType().ToString() == "OTSGridView")
  537. {
  538. ((OTSGridView)item).SelectAll();
  539. Clipboard.SetDataObject(((OTSGridView)item).GetClipboardContent());
  540. }
  541. }
  542. }
  543. private void ToolStripMenuItem3_Click(object sender, EventArgs e)
  544. {
  545. foreach (var item in panel1.Controls)
  546. {
  547. if (item.GetType().ToString() == "OTSGridView")
  548. {
  549. panel1.Controls.Remove((OTSGridView)item);
  550. }
  551. }
  552. gridheight = 0;
  553. //int idx = m_ReportApp.m_DataMgrFun.GetPropIndexByPropItemName(m_ReportApp.SourceGridData.ConditionItemList, OTSIncAReportApp.OTSSampleReportInfo.OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE);
  554. //string sou = m_ReportApp.SourceGridData.ConditionItemList[idx].itemVal.ToString();
  555. string sou = source.GetPropItemDisplayValueByPropItemName(OTS_REPORT_PROP_GRID_ITEMS.DATA_SOURCE).ToString();
  556. if (sou.Contains("+"))
  557. {
  558. for (int i = 0; i < sou.Split('+').Length; i++)
  559. {
  560. ResultFile resultFile = m_ReportApp.m_rstDataMgr.ResultFilesList.Find(s => s.anotherFileName == sou.Split('+')[i]);
  561. if (resultFile != null)
  562. {
  563. BindDataGridView(resultFile.FilePath, i, resultFile.anotherFileName);
  564. }
  565. }
  566. }
  567. else
  568. {
  569. BindDataGridView(m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResultId()].FilePath, 0, m_ReportApp.m_rstDataMgr.ResultFilesList[m_ReportApp.m_rstDataMgr.GetWorkingResultId()].anotherFileName);
  570. }
  571. }
  572. private void Gview_gz_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
  573. {
  574. //排序中
  575. if (((OTSGridView)sender).Rows[e.RowIndex1].Tag != null && ((OTSGridView)sender).Rows[e.RowIndex1].Tag.ToString() == "统计行")
  576. {
  577. //ROW1>ROW2
  578. e.SortResult = 1;
  579. if (((OTSGridView)sender).SortOrder == SortOrder.Descending)
  580. e.SortResult = -1;
  581. e.Handled = true;
  582. return;
  583. }
  584. if (((OTSGridView)sender).Rows[e.RowIndex2].Tag != null && ((OTSGridView)sender).Rows[e.RowIndex2].Tag.ToString() == "统计行")
  585. {
  586. //ROW1<ROW2
  587. e.SortResult = -1;
  588. if (((OTSGridView)sender).SortOrder == SortOrder.Descending)
  589. e.SortResult = 1;
  590. e.Handled = true;
  591. return;
  592. }
  593. }
  594. private void Gview_gz_Sorted(object sender, EventArgs e)
  595. {
  596. //排序完成,重新设置序号
  597. for (int i = 0; i < ((OTSGridView)sender).Rows.Count; i++)
  598. {
  599. if (((OTSGridView)sender).Rows[i].Tag != null && ((OTSGridView)sender).Rows[i].Tag.ToString() == "统计行")
  600. { }
  601. else
  602. {
  603. ((OTSGridView)sender).Rows[i].Cells[0].Value = i.ToString();
  604. }
  605. }
  606. }
  607. #endregion
  608. #region 获取向导出模块提供的DataTable和GridView对象
  609. /// <summary>
  610. /// 获取到该模块输出后形成的DataTable,和GridView
  611. /// </summary>
  612. /// <param name="out_dt"></param>
  613. /// <param name="out_dg"></param>
  614. public void GetDataTableAndGridView(out DataTable out_dt, out DataGridView out_dg)
  615. {
  616. out_dt = m_dt;
  617. out_dg = null;
  618. foreach (var item in panel1.Controls)
  619. {
  620. if (item.GetType().ToString() == "OTSGridView")
  621. {
  622. out_dg = ((OTSGridView)item);
  623. }
  624. }
  625. }
  626. #endregion
  627. }
  628. }