duheng
2024-08-29 fb98441d18634dd73233b943eade8768193ca7a3
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
using HStation.WinFrmUI.PhartRelation;
 
namespace HStation.WinFrmUI.Xhs
{
    public partial class PumpMainCurveChoicePage : DevExpress.XtraEditors.XtraUserControl
    {
        public PumpMainCurveChoicePage()
        {
            InitializeComponent();
            this.gridView1.SetNormalView();
        }
 
        private List<PumpMainChoieViewModel> _allBindingList = null;
 
        private BLL.PumpSeries _seriesBll = null;
 
        private BLL.PumpGroup _groupBll = null;
 
        private BLL.PumpMain _pumpBll = null;
 
        private BLL.PumpGroupAndMainMap _groupMapBll = null;
 
        private readonly Lazy<BLL.XhsPumpMainPhartMappingExtensions> _bll_ex = new();
 
        private long _DbID;  //泵型号ID
        private long _Curveid;//曲线ID
        private Vmo.XhsPumpMainPhartMappingExtensions _Curveinfo; //曲线详细信息
 
        private string _SearchText;
 
        public class CurvieText
        {
            public long Dbid { get; set; }
            public long Curveid { get; set; }
            public Vmo.XhsPumpMainPhartMappingExtensions Curveinfo { get; set; }
        }
 
        /// <summary>
        /// 初始化
        /// </summary>
        public async void SetBindingData(string dbiD, string ModelType)
        {
            _seriesBll = new BLL.PumpSeries();
            _groupBll = new BLL.PumpGroup();
            _pumpBll = new BLL.PumpMain();
            _groupMapBll = new BLL.PumpGroupAndMainMap();
            this.pumpMainCurveForm1.SelectEventReload += PumpMainCurveForm1_SelectEventReload;
            if (dbiD != null)
            {
                if (long.TryParse(dbiD, out long DbID))
                {
                    var model = await _pumpBll.GetByID(DbID);
                    if (model == null)
                        return;
                    _DbID = DbID;
                    pumpMainCurveForm1.SetBindingData(model);
                }
            }
            if (ModelType != null)
            {
                _SearchText = ModelType;
                var alllist = await TreelistShow();
                if (alllist.Count <= 0)
                    return;
                var model = await _pumpBll.GetByID(alllist.First().ID);
                if (model == null)
                    return;
                _DbID = model.ID;
                pumpMainCurveForm1.SetBindingData(model);
                TextPopupPumpChoice.ShowPopup();
            }
        }
 
        //
        private async void PumpMainCurveForm1_SelectEventReload(long ID)
        {
            var vmo = await _bll_ex.Value.GetByID(ID);
            _Curveid = ID;
            _Curveinfo = vmo;
            InitChart(vmo);
        }
 
        public CurvieText GetCurrentCurveinfo()
        {
            var ss = new CurvieText
            {
                Dbid = _DbID,
                Curveid = _Curveid,
                Curveinfo = _Curveinfo
            };
            return ss;
        }
 
        //初始化图表数据
        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.PumpQH);
            var graph_qp = graph_list.Find(x => x.GraphType == HStation.PhartRelation.eGraphType.PumpQH);
 
            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 simpleLabelSearch_Click(object sender, EventArgs e)
        {
            if (TextPopupPumpChoice.EditValue == null)
                return;
            _SearchText = Convert.ToString(TextPopupPumpChoice.EditValue);
            TextPopupPumpChoice.Properties.PopupControl = popupContainerControl1;
            if (_SearchText == null)
            {
                return;
            }
            await TreelistShow();
            this.treeList1.DataSource = _allBindingList;
            TextPopupPumpChoice.ShowPopup();
        }
 
        private async Task<List<PumpMainChoieViewModel>> TreelistShow()
        {
            _allBindingList = new List<PumpMainChoieViewModel>();
            var allSeries = await _seriesBll.GetAll();
            var allGroup = await _groupBll.GetAll();
            var allPumpMain = await _pumpBll.GetAll();
            var allGroupMap = await _groupMapBll.GetAll();
            //泵型号
            foreach (var item in allPumpMain)
            {
                if (item.Name.Contains(_SearchText.Trim()))
                {
                    var groupMap = allGroupMap.Find(x => x.PumpMainID == item.ID);
                    if (groupMap != null)
                    {
                        var group = allGroup.Find(x => x.ID == groupMap.PumpGroupID);
                        if (group != null)
                        {
                            var series = allSeries.Find(x => x.ID == group.PumpSeriesID);
                            if (series != null)
                            {
                                if (_allBindingList.Find(x => x.ID == series.ID) == null)
                                {
                                    _allBindingList.Add(new PumpMainChoieViewModel(series));
                                }
                                if (_allBindingList.Find(x => x.ID == group.ID) == null)
                                {
                                    _allBindingList.Add(new PumpMainChoieViewModel(item, group.ID));
                                }
                                _allBindingList.Add(new PumpMainChoieViewModel(group));
                            }
                        }
                    }
                    else
                    {
                        var series = allSeries.Find(x => x.ID == item.PumpSeriesID);
                        if (series != null)
                        {
                            if (_allBindingList.Find(x => x.ID == series.ID) == null)
                            {
                                _allBindingList.Add(new PumpMainChoieViewModel(series));
                            }
                            _allBindingList.Add(new PumpMainChoieViewModel(item));
                        }
                    }
                }
            }
            return _allBindingList.Where(x => x.IsPump == true).ToList();
        }
 
        //模糊查询(表格显示)
        private async void simpleLabelItemVagueSearch_Click(object sender, EventArgs e)
        {
            if (TextPopupPumpChoice.EditValue == null)
            {
                return;
            }
            _allBindingList = new List<PumpMainChoieViewModel>();
            TextPopupPumpChoice.Properties.PopupControl = popupContainerControl2;
            var allPumpMain = await _pumpBll.GetAll();
            foreach (var Main in allPumpMain)
            {
                if (Main.Name.Contains(TextPopupPumpChoice.Text))
                {
                    _allBindingList.Add(new PumpMainChoieViewModel(Main));
                }
            }
            this.gridControl1.DataSource = _allBindingList;
            TextPopupPumpChoice.Size = new Size(500, 300);
            TextPopupPumpChoice.ShowPopup();
        }
 
        //选择项变换
        private async void treeList1_SelectionChanged(object sender, EventArgs e)
        {
            var vm = this.treeList1.GetCurrentViewModel(_allBindingList);
            if (vm != null)
            {
                if (!vm.IsPump)
                {
                    return;
                }
                var model = await _pumpBll.GetByID(vm.ID);
                if (model == null)
                    return;
                _DbID = vm.ID;
                pumpMainCurveForm1.SetBindingData(model);
            }
            //treeList1.CloseEditForm();
        }
 
        private void BtnAddPumpMain_Click(object sender, EventArgs e)
        {
            var dlg = new AddPumpMainDlg();
            dlg.ShowDialog();
        }
 
        private async void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm != null)
            {
                var model = await _pumpBll.GetByID(vm.ID);
                if (model == null)
                    return;
                _DbID = vm.ID;
                pumpMainCurveForm1.SetBindingData(model);
            }
        }
    }
}