using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using DevExpress.XtraEditors; using DevExpress.XtraCharts; using System.Drawing.Imaging; using Uninpho.DBOperation.Model; using Uninpho.DBOperation.Operation; using DevExpress.XtraEditors.Controls; using System.Reflection; namespace Uninpho.Tools.components.DataManager { public partial class FrmAnalyze : DevExpress.XtraEditors.XtraForm { Series Series { get { return chartControl1.Series.Count > 0 ? chartControl1.Series[0] : null; } } SwiftPlotDiagram Diagram { get { return chartControl1.Diagram as SwiftPlotDiagram; } } AxisBase AxisX { get { return Diagram != null ? Diagram.AxisX : null; } } AxisBase AxisY { get { return Diagram != null ? Diagram.AxisY : null; } } public ChartControl ChartControl { get { return this.chartControl1; } } List lglbxMeta; List jhfxbxMeta; List lglMeta; List jhfxMeta; List ignoreColumns = new List() { "bxid", "id", "jihefenxiid", "licheng", "yswjm", "lunguiliid" }; public FrmAnalyze(string title) { InitializeComponent(); this.Text = title; } private T_metadata_account GetMeta(List metaList, string key) { T_metadata_account meta = null; metaList.ForEach(item => { if (item.name.ToLower() == key.ToLower()) { meta = item; } }); return meta; } public void SetJCRQ(string rq) { this.lb_jcrq.Text = rq; } private object getRowData(object row,string column) { object val = ""; foreach (var item in (IDictionary)row) { if (column.ToLower() == item.Key.ToLower()) { val = item.Value; break; } } return val; } /// /// 趋势分析 /// public void LoadQSFXData(List rows) { this.GetMeta(); this.combX.Properties.Items.Clear(); this.combY.Properties.Items.Clear(); //this.combX.Properties.Items.Add("检测日期"); this.combX.Properties.Items.Add("不可编辑"); this.combX.SelectedIndex = 0; this.combX.Properties.ReadOnly = true; this.BindNumericCombData(lglMeta); this.BindNumericCombData(jhfxMeta); //轮轨力数据 this.fillData(lglMeta,rows); //几何分析数据 this.fillData(jhfxMeta, rows); SetChart("检测日期", "数值", "趋势分析"); } /// /// /// /// /// private void fillData(List dataMeta, List rows) { dataMeta.ForEach(column => { if (column.ttype == "number"&& column.chname != "序号") { Series series1 = new Series(column.name, ViewType.Line); series1.LegendText = column.chname; foreach (var row in rows) { string riqi = getRowData(row, "jcrq").ToString(); series1.Tag = column.name; series1.LegendText = column.chname; object objVal = getRowData(row, column.name); if (objVal != null) { decimal val = Convert.ToDecimal(objVal.ToString()); series1.Points.Add(new SeriesPoint(riqi, val)); } } this.chartControl1.Series.Add(series1); } }); } /// /// 显示波形分析曲线图 /// /// /// public void LoadBXZSData(List yswjm_lgl, List yswjm_jhfx) { this.GetMeta(); this.combX.Properties.Items.Clear(); this.combY.Properties.Items.Clear(); this.combX.Properties.Items.Add("里程"); this.combX.SelectedIndex = 0; this.combX.Properties.ReadOnly = true; this.BindCombData(lglbxMeta); this.BindCombData(jhfxbxMeta); int m = 0; yswjm_lgl.ForEach(key => { List lglBX = DMControl.GetLGL_BXDataByIDS(key); //轮轨力波形数据 if (lglBX.Count > 0) { PropertyInfo[] PropertyList = lglBX[0].GetType().GetProperties(); foreach (PropertyInfo item in PropertyList) { string name = item.Name; if (!ignoreColumns.Contains(name.ToLower())) { Series series1 = new Series(name, ViewType.Line); series1.Tag = name; series1.LegendText = this.GetMeta(lglbxMeta, name).chname; series1.ShowInLegend = m==0; lglBX.ForEach(row => { decimal licheng = row.Licheng; object obj = item.GetValue(row); series1.Points.Add(new SeriesPoint(licheng, obj)); }); this.chartControl1.Series.Add(series1); series1.ArgumentScaleType = ScaleType.Numerical; } } m++; } else { // XtraMessageBox.Show("轮轨力波形数据为空", "提示"); } }); m = 0; yswjm_jhfx.ForEach(key => { List jhfxBX = DMControl.GetJHFX_BXDataByIDS(key); //几何分析波形数据 if (jhfxBX.Count > 0) { PropertyInfo[] PropertyList2 = jhfxBX[0].GetType().GetProperties(); foreach (PropertyInfo item in PropertyList2) { string name = item.Name; if (!ignoreColumns.Contains(name.ToLower())) { Series series1 = new Series(this.GetMeta(jhfxbxMeta, name).chname, ViewType.Line); series1.Tag = name; //series1.ShowInLegend = m == 0; jhfxBX.ForEach(row => { decimal licheng = row.Licheng; object obj = item.GetValue(row); series1.Points.Add(new SeriesPoint(licheng, obj)); }); this.chartControl1.Series.Add(series1); series1.ArgumentScaleType = ScaleType.Numerical; } } m++; } else { XtraMessageBox.Show("几何分析波形数据为空", "提示"); } }); string titile = yswjm_lgl.Count > 1 ? "波形分析" : "波形查看"; SetChart("里程", "数值", titile); } public void GetMeta() { lglbxMeta = MetaDataCtrl.GetMetaData("t_lunguili_boxing"); jhfxbxMeta = MetaDataCtrl.GetMetaData("t_jihefenxi_boxing"); lglMeta = MetaDataCtrl.GetMetaData("t_lunguili_account"); jhfxMeta = MetaDataCtrl.GetMetaData("t_jihefenxi_account"); } /// /// /// /// private void BindCombData(List dtMeta) { this.combY.Properties.Items.Clear(); dtMeta.ForEach(item => { if (!ignoreColumns.Contains(item.name)) { this.combY.Properties.Items.Add(new ComboBoxData() { Text = item.chname, Value = item.name }); } }); //是否显示 确定、取消按钮 combY.Properties.ShowButtons = false; //是否显示 取消按钮 combY.Properties.ShowPopupCloseButton = false; //默认字段全选 foreach (CheckedListBoxItem it in this.combY.Properties.Items) { it.CheckState = CheckState.Checked; } } private void BindNumericCombData(List dtMeta) { dtMeta.ForEach(item => { if (item.ttype== "number") this.combY.Properties.Items.Add(new ComboBoxData() { Text = item.chname, Value = item.name }); }); //是否显示 确定、取消按钮 combY.Properties.ShowButtons = false; //是否显示 取消按钮 combY.Properties.ShowPopupCloseButton = false; //默认字段全选 foreach (CheckedListBoxItem it in this.combY.Properties.Items) { it.CheckState = CheckState.Checked; } } private void SetChart(string xtitle, string ytitle, string charttitle) { AxisRange DIA = (AxisRange)((XYDiagram)this.chartControl1.Diagram).AxisY.Range; XYDiagram diagram = (XYDiagram)this.chartControl1.Diagram; diagram.AxisX.Title.Alignment = StringAlignment.Center; diagram.AxisX.Title.Text = xtitle; diagram.AxisX.Title.Font = new Font("Tahoma", 14, FontStyle.Bold); diagram.EnableAxisXScrolling = true;//滚动 diagram.EnableAxisYScrolling = true; diagram.EnableAxisXZooming = true;//缩放 this.chartControl1.CrosshairOptions.ShowArgumentLine = true; this.chartControl1.CrosshairOptions.ShowCrosshairLabels = true; chartControl1.CrosshairOptions.GroupHeaderPattern = "{A:d}"; chartControl1.CrosshairOptions.ShowArgumentLabels = true; //chartControl1.CrosshairOptions.ShowValueLine = true; // DIA.SetMinMaxValues(0, 1000); diagram.AxisY.Title.Alignment = StringAlignment.Center; diagram.AxisY.Title.Text = ytitle; diagram.AxisY.Title.Font = new Font("Tahoma", 14, FontStyle.Bold); ((XYDiagram)this.chartControl1.Diagram).EnableAxisXZooming = true; this.chartControl1.Titles.Add(new ChartTitle()); this.chartControl1.Titles[0].Text = charttitle; this.chartControl1.Dock = DockStyle.Fill; this.chartControl1.Refresh(); CrosshairFreePosition crosshairPosition = new CrosshairFreePosition(); crosshairPosition.DockTarget = ((XYDiagram2D)ChartControl.Diagram).DefaultPane; crosshairPosition.DockCorner = DockCorner.LeftTop; ChartControl.CrosshairOptions.CommonLabelPosition = crosshairPosition; } private void Init() { } private void simpleButton1_Click(object sender, EventArgs e) { SaveFileDialog fbd = new SaveFileDialog(); fbd.Filter = "图像文件(*.jpg;*.jpg;*.jpeg;*.png)|*.jpg;*.jpeg;*.png"; //选择导出文件位置 if (fbd.ShowDialog() == DialogResult.OK) { //导出路径 string outPath = fbd.FileName.ToString(); //输出图片到指定位置 chartControl1.ExportToImage(outPath, ImageFormat.Png); XtraMessageBox.Show("导出成功!", "提示"); } } private void simpleButton3_Click(object sender, EventArgs e) { List showList = combY.Properties.Items.GetCheckedValues().Select(it => (it as ComboBoxData).Value.ToLower()).ToList(); foreach (Series it in this.chartControl1.Series) { it.Visible = showList.Contains((it.Tag as string).ToLower()); } } } }