Shuxia Ning
2024-08-12 d2cee56db11f0ee475e9f9dbdc8bfd03ad982e18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
 
 
//编辑原始的性能曲线
namespace AStation.WinFrmUI.Chart
{
    public partial class ImportCurveByCurveExpressCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public ImportCurveByCurveExpressCtrl()
        {
            InitializeComponent();
 
            this.imgCmbCurveSourceFrom.Properties.AddEnum(typeof(AStation.Chart.eSourceWay), false);
            this.imgCmbCurveSourceFrom.EditValue = AStation.Chart.eSourceWay.SCADA数据分析;
 
            this.imgCmbQHFitType.Properties.AddEnum(typeof(AStation.Curve.eFitType), false);
            this.imgCmbQHFitType.EditValue = _qhFitType;
 
            this.imgCmbQEFitType.Properties.AddEnum(typeof(AStation.Curve.eFitType), false);
            this.imgCmbQEFitType.EditValue = _qeFitType;
 
            this.imgCmbQPFitType.Properties.AddEnum(typeof(AStation.Curve.eFitType), false);
            this.imgCmbQPFitType.EditValue = _qpFitType;
 
            this.txtCurveCode.Text = "SCADA数据分析";
            this.chartFeatCurveViewCtrl1.Enabled = false;
        }
 
 
        AStation.Curve.eFitType _qhFitType = AStation.Curve.eFitType.CubicCurve;
        AStation.Curve.eFitType _qeFitType = AStation.Curve.eFitType.CubicCurve;
        AStation.Curve.eFitType _qpFitType = AStation.Curve.eFitType.CubicCurve;
 
 
        private AStation.Curve.CurveExpress QhCurve = null, QeCurve = null, QpCurve = null;
        List<AStation.Curve.CurvePoint> QhPoints = null, QePoints = null, QpPoints = null;
 
        private bool initial = 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<Model.PumpCurveInfo>(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.InitialChartData();
                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 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();
        }
 
 
        //加载曲线
        private bool loadCurve()
        {
            if (!initial)
                return false;
            if (QhPoints == null)
            {
                this.chartFeatCurveViewCtrl1.Enabled = false;
                this.chartFeatCurveViewCtrl1.InitialChartData();
                return false;
            }
 
            this.chartFeatCurveViewCtrl1.Enabled = true;
            _qhFitType = (AStation.Curve.eFitType)this.imgCmbQHFitType.EditValue;
            _qeFitType = (AStation.Curve.eFitType)this.imgCmbQEFitType.EditValue;
            _qpFitType = (AStation.Curve.eFitType)this.imgCmbQPFitType.EditValue;
 
 
 
            QhCurve = AStation.Curve.FitHelper.BuildCurveExpress(QhPoints, _qhFitType);
            QeCurve = AStation.Curve.FitHelper.BuildCurveExpress(QePoints, _qeFitType);
            QpCurve = AStation.Curve.FitHelper.BuildCurveExpress(QpPoints, _qpFitType);
 
            this.chartFeatCurveViewCtrl1.SetBindingData(QhCurve, QeCurve, QpCurve);
 
            return true;
        }
 
 
        public bool GetCurve(out string curveCode, out AStation.Chart.eSourceWay eCurveSourceFrom, out Model.PumpCurveInfo featCurveExpressGroup)
        {
            curveCode = "";
            eCurveSourceFrom = AStation.Chart.eSourceWay.SCADA数据分析;
            featCurveExpressGroup = null;
            if (!loadCurve())
                return false;
            curveCode = this.txtCurveCode.Text.Trim();
            if (string.IsNullOrEmpty(curveCode))
            {
                XtraMessageBox.Show("请输入曲线名称!");
                return false;
            }
            eCurveSourceFrom = (AStation.Chart.eSourceWay)this.imgCmbCurveSourceFrom.EditValue;
            featCurveExpressGroup = new Model.PumpCurveInfo(QhCurve, QeCurve, QpCurve);
            return true;
        }
    }
}