ElementCompositionAvgGrid.cs 25 KB

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