using DevExpress.XtraEditors; using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; //编辑原始的性能曲线 namespace IStation.WinFrmUI.Curve { public partial class ImportCurveByFeatCurveExpressGroupCtrl : DevExpress.XtraEditors.XtraUserControl { public ImportCurveByFeatCurveExpressGroupCtrl() { InitializeComponent(); this.imgCmbCurveSourceFrom.Properties.AddEnum(typeof(Model.eCurveSourceFrom), false); this.imgCmbCurveSourceFrom.EditValue = Model.eCurveSourceFrom.现场测试; this.imgCmbQHFitType.Properties.AddEnum(typeof(Model.eCurveFitType), false); this.imgCmbQHFitType.EditValue = _qhFitType; this.imgCmbQEFitType.Properties.AddEnum(typeof(Model.eCurveFitType), false); this.imgCmbQEFitType.EditValue = _qeFitType; this.imgCmbQPFitType.Properties.AddEnum(typeof(Model.eCurveFitType), false); this.imgCmbQPFitType.EditValue = _qpFitType; } Model.eCurveFitType _qhFitType = Model.eCurveFitType.CubicCurve; Model.eCurveFitType _qeFitType = Model.eCurveFitType.CubicCurve; Model.eCurveFitType _qpFitType = Model.eCurveFitType.CubicCurve; private Model.CurveExpress QhCurve = null, QeCurve = null, QpCurve = null; List QhPoints = null, QePoints = null, QpPoints = null; private bool initial = false; /// /// 初始化数据 /// public void SetBindingData() { this.chartFeatCurveViewCtrl1.Enabled = false; } //选择文件 private void btnFilePath_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { var dlg = new System.Windows.Forms.OpenFileDialog(); dlg.Filter = "EXCEL 文件(*.express)|*.express"; dlg.CheckFileExists = true; if (dlg.ShowDialog() != DialogResult.OK) return; initial = false; this.btnFilePath.Text = dlg.FileName; var json = File.ReadAllText(dlg.FileName); var express = JsonHelper.Json2Object(json); if (express == null || express.CurveQH == null) { this.QhCurve = null; this.QeCurve = null; this.QpCurve = null; this.QhPoints = null; this.QePoints = null; this.QpPoints = null; this.chartFeatCurveViewCtrl1.Enabled = false; this.chartFeatCurveViewCtrl1.ClearData(); XtraMessageBox.Show("解析失败!"); } else { this.QhPoints = null; this.QePoints = null; this.QpPoints = null; if (express.CurveQH.DefinePoints != null) this.QhPoints = express.CurveQH.DefinePoints; else this.QhPoints = express.CurveQH.GetFitPoints(12); if (express.CurveQE != null) { if (express.CurveQE.DefinePoints != null) this.QePoints = express.CurveQE.DefinePoints; else this.QePoints = express.CurveQE.GetFitPoints(12); } if (express.CurveQP != null) { if (express.CurveQP.DefinePoints != null) this.QpPoints = express.CurveQP.DefinePoints; else this.QpPoints = express.CurveQP.GetFitPoints(12); } this.txtCurveCode.Text = Path.GetFileNameWithoutExtension(dlg.FileName); this.imgCmbQHFitType.EditValue = express.CurveQH.FitType; this.imgCmbQEFitType.EditValue = express.CurveQE.FitType; this.imgCmbQPFitType.EditValue = express.CurveQP.FitType; initial = true; loadCurve(); } } //加载曲线 private bool loadCurve() { if (!initial) return false; if (QhPoints == null) { this.chartFeatCurveViewCtrl1.Enabled = false; this.chartFeatCurveViewCtrl1.ClearData(); return false; } this.chartFeatCurveViewCtrl1.Enabled = true; _qhFitType = (Model.eCurveFitType)this.imgCmbQHFitType.EditValue; _qeFitType = (Model.eCurveFitType)this.imgCmbQEFitType.EditValue; _qpFitType = (Model.eCurveFitType)this.imgCmbQPFitType.EditValue; QhCurve = new Model.CurveExpress(QhPoints, _qhFitType); QeCurve = new Model.CurveExpress(QePoints, _qeFitType); QpCurve = new Model.CurveExpress(QpPoints, _qpFitType); this.chartFeatCurveViewCtrl1.SetCurveInfo(QhCurve, QeCurve, QpCurve); this.chartFeatCurveViewCtrl1.UpdateChart(true); this.chartFeatCurveViewCtrl1.SetWorkPointQ_Auto(); return true; } public bool GetGroup(out string curveCode, out Model.eCurveSourceFrom eCurveSourceFrom, out Model.FeatCurvePointGroup featCurvePointGroup, out Model.FeatCurveExpressGroup featCurveExpressGroup) { curveCode = ""; eCurveSourceFrom = Model.eCurveSourceFrom.现场测试; featCurvePointGroup = null; featCurveExpressGroup = null; if (!loadCurve()) return false; curveCode = this.txtCurveCode.Text.Trim(); if (string.IsNullOrEmpty(curveCode)) { XtraMessageBox.Show("请输入曲线名称!"); return false; } eCurveSourceFrom = (Model.eCurveSourceFrom)this.imgCmbCurveSourceFrom.EditValue; featCurvePointGroup = new Model.FeatCurvePointGroup(QhPoints, QePoints, QpPoints); featCurveExpressGroup = new Model.FeatCurveExpressGroup(QhCurve, QeCurve, QpCurve); return true; } private void imgCmbQHFitType_SelectedIndexChanged(object sender, EventArgs e) { loadCurve(); } private void imgCmbQEFitType_SelectedIndexChanged(object sender, EventArgs e) { loadCurve(); } private void imgCmbQPFitType_SelectedIndexChanged(object sender, EventArgs e) { loadCurve(); } } }