123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- using Sunny.UI;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Windows.Forms;
- namespace WWPipeLine.MapBasic.Results
- {
- public class RWWithChart : ResultWindow
- {
-
-
-
- protected UIDataGridView m_DataGridView;
-
-
-
- protected UIChart m_UIChart;
-
-
-
- protected UIOption m_UIOption;
-
-
-
- protected UIChartType m_ChartType = UIChartType.Bar;
-
-
-
- protected string m_ChartTitle = "统计结果";
-
-
-
- protected bool ShowDataGridView = true;
-
-
-
- protected virtual string ChartTitle { get => m_ChartTitle; set => m_ChartTitle = value; }
-
-
-
- public enum UIChartType
- {
-
-
-
- Bar,
-
-
-
- Line,
-
-
-
- Pie,
-
-
-
- BarEx,
-
-
-
- Doughnut
- }
-
-
-
-
- protected virtual void AddOptionSeries(DataTable dt)
- {
- }
-
-
-
-
- protected virtual void AddXAxis(DataTable dt)
- {
- }
-
-
-
-
- protected virtual void SetLegendItem(DataTable dt)
- {
- }
-
-
-
- protected virtual void SetOptionEx()
- {
- }
-
-
-
-
- public override void ShowData(object data)
- {
- if (!(data is DataTable))
- {
- Sunny.UI.UIMessageTip.ShowWarning("数据错误,未能显示图表"); return;
- }
- var dt = data as DataTable;
- if (ShowDataGridView)
- {
- this.CreateDataGridView(dt);
- }
- AddChart();
- m_UIOption.Title = new UITitle { Text = ChartTitle };
- AddOptionSeries(dt);
- AddXAxis(dt);
- SetLegend();
- SetLegendItem(dt);
- SetOptionEx();
- this.m_UIChart.SetOption(m_UIOption);
- }
-
-
-
-
- protected virtual void CreateDataGridView(DataTable dt)
- {
- if (m_DataGridView == null)
- {
- m_DataGridView = new Sunny.UI.UIDataGridView
- {
- Dock = DockStyle.Fill,
- AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill,
- SelectionMode = DataGridViewSelectionMode.FullRowSelect,
- DefaultCellStyle = new DataGridViewCellStyle() { ForeColor = Color.Black, Alignment = DataGridViewContentAlignment.MiddleCenter },
- ShowEditingIcon = false,
- ShowCellToolTips = false,
- AllowUserToAddRows = false,
- AllowUserToResizeRows = false,
- AllowUserToDeleteRows = false,
- AllowUserToOrderColumns = false,
- ReadOnly = true,
- MultiSelect = false,
- BorderStyle = BorderStyle.None,
- CellBorderStyle = DataGridViewCellBorderStyle.None,
- RowHeadersVisible = false
- };
- this.Controls.Add(m_DataGridView);
- }
- m_DataGridView.DataSource = dt;
- if (System.Text.RegularExpressions.Regex.IsMatch(dt.TableName?.ToString(), @"[\u4e00-\u9fa5]"))
- this.m_DataGridView.Tag = dt.TableName?.ToString();
- for (int i = 0; i < m_DataGridView.Columns.Count; i++)
- {
- m_DataGridView.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
- m_DataGridView.Columns[i].HeaderText = dt.Columns[i].Caption;
- }
- }
-
-
-
- protected virtual void AddChart()
- {
- m_UIChart.RadiusSides = UICornerRadiusSides.None;
- m_UIChart.RectSides = ToolStripStatusLabelBorderSides.None;
- this.Controls.Add(this.m_UIChart);
- if (this.ShowDataGridView)
- m_UIChart.Dock = DockStyle.Top;
- else
- m_UIChart.Dock = DockStyle.Fill;
- }
- private void UiSymbolButtonExportToImage_Click(object sender, EventArgs e)
- {
- ExportToImage(this.m_UIChart);
- }
- private void UiSymbolButtonExportToExcel_Click(object sender, EventArgs e)
- {
- ExportToExcel(this.m_DataGridView);
- }
-
-
-
- protected virtual void CreateChart()
- {
- }
-
-
-
-
- protected virtual string SetXAxisName()
- {
- return "系列";
- }
-
-
-
-
- protected virtual string SetYAxisName()
- {
- return "值";
- }
-
-
-
- protected virtual void SetLegend()
- {
- m_UIOption.Legend = new UILegend
- {
- Orient = UIOrient.Horizontal,
- Top = UITopAlignment.Bottom,
- Left = UILeftAlignment.Right
- };
- }
-
-
-
-
- protected override void OnSizeChanged(EventArgs e)
- {
- base.OnSizeChanged(e);
- if (m_UIChart == null) return;
- this.m_UIChart.Height = 2 * this.Height / 3;
- }
-
-
-
- public RWWithChart() : base()
- {
- CreateExportImageAndExcelButton();
- base.uiSymbolButtonExportToExcel.Click += UiSymbolButtonExportToExcel_Click;
- base.uiSymbolButtonExportToImage.Click += UiSymbolButtonExportToImage_Click;
- CreateChart();
- InitializeComponent();
- SetColors();
- }
- private void InitializeComponent()
- {
- this.SuspendLayout();
-
-
-
- this.m_UIChart.Dock = System.Windows.Forms.DockStyle.Fill;
- this.m_UIChart.FillColor = System.Drawing.Color.FromArgb(((int)(((byte)(244)))), ((int)(((byte)(244)))), ((int)(((byte)(244)))));
- this.m_UIChart.Font = new System.Drawing.Font("微软雅黑", 12F);
- this.m_UIChart.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(54)))), ((int)(((byte)(54)))), ((int)(((byte)(54)))));
- this.m_UIChart.Location = new System.Drawing.Point(0, 0);
- this.m_UIChart.MinimumSize = new System.Drawing.Size(1, 1);
- this.m_UIChart.Name = "uiChart";
- this.m_UIChart.Size = new System.Drawing.Size(800, 450);
- this.m_UIChart.TabIndex = 0;
- this.m_UIChart.Text = "uiChart";
-
-
-
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Name = "ResultWindowWithChart";
- this.ResumeLayout(false);
- }
- protected static List<Color> m_Colors = new List<Color>();
-
-
-
-
- private static void SetColors(int count = 100)
- {
- if (m_Colors.Count > 0)
- return;
- long tick = DateTime.Now.Ticks;
- Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
- Random ran2 = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
- for (int i = 0; i < count; i++)
- {
- int R = ran.Next(255);
- int G = ran2.Next(255);
- int B = 222;
- B = (R + G > 400) ? R + G - 400 : B;
- B = (B > 255) ? 255 : B;
- m_Colors.Add(System.Drawing.Color.FromArgb(R, G, B));
- }
- }
- }
- }
|