duheng
2024-12-04 ca1ccd0dd9f2d6936368f07d14a2b29b309fd151
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
167
168
169
170
171
172
173
using HStation.WinFrmUI.PhartRelation;
 
namespace HStation.WinFrmUI
{
    public partial class PumpSingleMatchingCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public PumpSingleMatchingCtrl()
        {
            InitializeComponent();
            this.gridView1.SetNormalView();
            this.gridView2.SetNormalView();
        }
 
        private List<PumpSingleMatchingViewModel> _allBindingList = null;
 
        private BLL.AssetsPumpMain _pumpBll = null;
 
        private List<PhartViewModel> _allPhartList = null;
        private readonly Lazy<BLL.XhsPumpMainPhartMappingExtensions> _bll_ex = new();
 
        private HydroPumpMatchingViewModel _pumpMatchingViewModel;
 
        public async void SetBindingData(HydroPumpMatchingViewModel pumpMatchingViewModel)
        {
            _pumpMatchingViewModel = pumpMatchingViewModel;
            _allBindingList = new List<PumpSingleMatchingViewModel>();
            _pumpBll = new BLL.AssetsPumpMain();
            var allAssetsPumpMain = await _pumpBll.GetAll();
            foreach (var Main in allAssetsPumpMain)
            {
                _allBindingList.Add(new PumpSingleMatchingViewModel(Main));
            }
            this.gridControl2.DataSource = _allBindingList;
            this.searchControl1.Text = pumpMatchingViewModel.ModelType;
            for (int i = 0; i < _allBindingList.Count; i++)
            {
                if (long.TryParse(pumpMatchingViewModel.DbId, out long dbID))
                {
                    if (_allBindingList[i].ID == dbID)
                    {
                        gridView2.FocusedRowHandle = i;
                    }
                }
            }
        }
 
        //初始化图表数据
        private void InitChart(Vmo.XhsPumpMainPhartMappingExtensions dto)
        {
            if (dto == null)
            {
                return;
            }
            var diagram = dto.Diagram;
            if (diagram == null)
            {
                return;
            }
            var graph_list = diagram.GraphList;
            if (graph_list == null || !graph_list.Any())
            {
                return;
            }
 
            var graph_qh = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQH);
            var graph_qe = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQE);
            var graph_qp = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQP);
 
            if (graph_qp == null)
            {
                return;
            }
 
            List<Yw.Geometry.Point2d> points_qh = null, points_qe = null, points_qp = null;
            points_qh = PhartPerformCurveHelper.GetFeatPointList(graph_qh.GraphType, graph_qh.GeometryInfo, 12, null);
            if (graph_qe != null)
                points_qe = PhartPerformCurveHelper.GetFeatPointList(graph_qe.GraphType, graph_qe.GeometryInfo, 12, null);
            if (graph_qp != null)
                points_qp = PhartPerformCurveHelper.GetFeatPointList(graph_qp.GraphType, graph_qp.GeometryInfo, 12, null);
 
            var cubic_spline_qh = new Yw.Geometry.CubicSpline2d(points_qh);
            var cubic_spline_qe = new Yw.Geometry.CubicSpline2d(points_qe);
            var cubic_spline_qp = new Yw.Geometry.CubicSpline2d(points_qp);
 
            var disp_paras = diagram.DispParas;
            var is_calc_disp_paras = string.IsNullOrWhiteSpace(disp_paras);
            this.xtrPerform2dChart1.SetBindingData(cubic_spline_qh, cubic_spline_qe, cubic_spline_qp, disp_paras, is_calc_disp_paras);
        }
 
        //泵型号列表选择项切换事件
        private async void gridView2_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            var vm = this.gridView2.GetCurrentViewModel(_allBindingList);
            if (vm != null)
            {
                _pumpMatchingViewModel.MatchingDbId = vm.ID.ToString();
                _pumpMatchingViewModel.MatchingModelType = vm.Name.ToString();
                _pumpMatchingViewModel.MatchingRatedH = vm.RatedHead;
                _pumpMatchingViewModel.MatchingRatedN = vm.RatedSpeed;
                _pumpMatchingViewModel.MatchingRatedP = vm.RatedPower;
                _pumpMatchingViewModel.MatchingRatedQ = vm.RatedFlow;
                var list = await _bll_ex.Value.GetByPumpMainID(vm.ID);
                _allPhartList = new List<PhartViewModel>();
                if (list != null && list.Any())
                {
                    foreach (var item in list)
                    {
                        _allPhartList.Add(new PhartViewModel { ID = item.ID, OtherName = item.OtherName, Importance = item.Importance, SortCode = item.SortCode });
                    }
                }
            }
            this.phartViewModelBindingSource.DataSource = _allPhartList;
            if (_pumpMatchingViewModel.CurveDbId != null)
            {
                for (int i = 0; i < _allPhartList.Count; i++)
                {
                    if (_allPhartList[i].ID.ToString() == _pumpMatchingViewModel.CurveDbId)
                    {
                        gridView1.FocusedRowHandle = i;
                    }
                }
            }
            this.phartViewModelBindingSource.ResetBindings(false);
        }
 
        //曲线列表选择项切换事件
        private async void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allPhartList);
            if (vm != null)
            {
                var vmo = await _bll_ex.Value.GetByID(vm.ID);
                if (vmo != null)
                {
                    _pumpMatchingViewModel.MatchingCurveDbId = vm.ID.ToString();
                    var graph_qh = vmo.Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQH);
                    var graph_qe = vmo.Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQE);
                    var graph_qp = vmo.Diagram.GraphList.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQP);
                    if (graph_qh != null)
                    {
                        var points_qh = PhartPerformCurveHelper.GetFeatPointList(graph_qh.GraphType, graph_qh.GeometryInfo, 100, null);
                        _pumpMatchingViewModel.MatchingCurveQH = new List<HydroCurvePointViewModel>();
                        foreach (var item in points_qh)
                        {
                            _pumpMatchingViewModel.MatchingCurveQH.Add(new HydroCurvePointViewModel(item.X, item.Y));
                        }
                    }
                    if (graph_qe != null)
                    {
                        var points_qe = PhartPerformCurveHelper.GetFeatPointList(graph_qe.GraphType, graph_qe.GeometryInfo, 100, null);
                        _pumpMatchingViewModel.MatchingCurveQE = new List<HydroCurvePointViewModel>();
                        foreach (var item in points_qe)
                        {
                            _pumpMatchingViewModel.MatchingCurveQE.Add(new HydroCurvePointViewModel(item.X, item.Y));
                        }
                    }
                    if (graph_qp != null)
                    {
                        var points_qp = PhartPerformCurveHelper.GetFeatPointList(graph_qp.GraphType, graph_qp.GeometryInfo, 100, null);
                        _pumpMatchingViewModel.MatchingCurveQP = new List<HydroCurvePointViewModel>();
                        foreach (var item in points_qp)
                        {
                            _pumpMatchingViewModel.MatchingCurveQP.Add(new HydroCurvePointViewModel(item.X, item.Y));
                        }
                    }
                }
                InitChart(vmo);
                return;
            }
            this.xtrPerform2dChart1.SetBindingData(null, null, null, null, false);
        }
    }
}