lixiaojun
2024-12-09 725f20b576bdd40d57d9a1e806ce3f6f39181a84
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
using HStation.WinFrmUI.PhartRelation;
using HStation.WinFrmUI.Xhs;
 
namespace HStation.WinFrmUI
{
    public partial class ValveSingleMatchingCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public ValveSingleMatchingCtrl()
        {
            InitializeComponent();
            this.gridView1.SetNormalView();
            this.gridView3.SetNormalView();
        }
 
        public class PhartViewModel
        {
            public long ID { get; set; }
            public string OtherName { get; set; }
            public int Importance { get; set; }
            public int SortCode { get; set; }
            public string MinorLossCurve { get; set; }
 
            public string OpenLossCurve { get; set; }
        }
 
        public class CurvieInfo
        {
            public long? Dbid { get; set; }
            public long? Curveid { get; set; }
            public Vmo.XhsValveMainPhartMappingExtensions Curveinfo { get; set; }
        }
 
        private List<ValveSingleMatchingViewModel> _allBindingList = null;
 
        private BLL.AssetsValveMain _valveBll = null;
 
        private List<PhartViewModel> _allPhartList = null;
        private readonly Lazy<BLL.AssetsValveCoefficient> _bll_ex = new();
 
        private HydroValveMatchingViewModel _valveMatchingViewModel;
 
        private List<HydroCurvePointViewModel> _currentCurvePoint;
 
        public async void SetBindingData(HydroValveMatchingViewModel valveMatchingViewModel)
        {
            _valveMatchingViewModel = valveMatchingViewModel;
            _allBindingList = new List<ValveSingleMatchingViewModel>();
            _valveBll = new BLL.AssetsValveMain();
            var allAssetsPumpMain = await _valveBll.GetAll();
            foreach (var Main in allAssetsPumpMain)
            {
                _allBindingList.Add(new ValveSingleMatchingViewModel(Main));
            }
            this.valveSingleMatchingViewModelBindingSource.DataSource = _allBindingList;
            this.searchControl1.Text = _valveMatchingViewModel.ModelType;
            for (int i = 0; i < _allBindingList.Count; i++)
            {
                if (long.TryParse(valveMatchingViewModel.DbId, out long dbID))
                {
                    if (_allBindingList[i].ID == dbID)
                    {
                        this.gridView3.FocusedRowHandle = i;
                    }
                }
            }
            _currentCurvePoint = new List<HydroCurvePointViewModel>();
        }
 
        //阀门型号列表选择项切换事件
        private async void gridView2_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            _allPhartList = new List<PhartViewModel>();
            var vm = this.gridView3.GetCurrentViewModel(_allBindingList);
            if (vm != null)
            {
                if (vm.SeriesType == HStation.Assets.eValveType.GPV || vm.SeriesType == HStation.Assets.eValveType.TCV)
                {
                    layoutControlGroup2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
                }
                else
                {
                    layoutControlGroup2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
                }
                _valveMatchingViewModel.MatchingDbId = vm.ID.ToString();
                _valveMatchingViewModel.MatchingModelType = vm.Name.ToString();
                if (double.TryParse(vm.Caliber, out double caliber))
                {
                    _valveMatchingViewModel.MatchingDiameter = caliber;
                }
                _valveMatchingViewModel.MatchingMinorLoss = vm.Coefficient;
                _valveMatchingViewModel.MatchingMaterial = vm.Material;
                _valveMatchingViewModel.MatchingValveType = (eValveType?)vm.SeriesType;
                _valveMatchingViewModel.MatchingValveSetting = vm.ValveSetting;
                var list = await _bll_ex.Value.GetByMainID(vm.ID);
                if (list != null && list.Any())
                {
                    foreach (var item in list)
                    {
                        _allPhartList.Add(new PhartViewModel { ID = item.ID, OtherName = "默认曲线", MinorLossCurve = item.MinorLossCurve, OpenLossCurve = item.OpenLossCurve, Importance = 1 });
                    }
                }
            }
            if (_valveMatchingViewModel.MatchingCurveDbId != null)
            {
                for (int i = 0; i < _allPhartList.Count; i++)
                {
                    if (_allBindingList[i].ID.ToString() == _valveMatchingViewModel.MatchingCurveDbId)
                    {
                        gridView1.FocusedRowHandle = i;
                    }
                }
            }
            this.gridControl1.DataSource = _allPhartList;
            this.gridView1.FocusInvalidRow();
        }
 
        //查看曲线
        private async void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            if (e.Column == this.ColShowChart)
            {
                var vm = this.gridView1.GetCurrentViewModel(_allPhartList);
 
                var vmo = await _bll_ex.Value.GetByID(vm.ID);
                if (vmo != null)
                {
                    var dlg = new ValveChartShowDlg();
                    if (vmo.MinorLossCurve != null)
                    {
                        dlg.InitChart(vmo.MinorLossCurve, false);
                    }
                    else if (vmo.OpenLossCurve != null)
                    {
                        dlg.InitChart(vmo.OpenLossCurve, true);
                    }
                    dlg.ShowDialog();
                }
                return;
            }
        }
 
        private async void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allPhartList);
            _currentCurvePoint.Clear();
            if (vm == null)
                return;
            var vmo = await _bll_ex.Value.GetByID(vm.ID);
            if (vmo != null)
            {
                _valveMatchingViewModel.MatchingCurveDbId = vm.ID.ToString();
                if (!string.IsNullOrEmpty(vm.OpenLossCurve))
                {
                    var pt_list = Yw.JsonHelper.Json2Object<List<HydroCurvePointViewModel>>(vm.OpenLossCurve);
                    _valveMatchingViewModel.MatchingCurveOL = pt_list;
                    _valveMatchingViewModel.MatchingCurveQL = null;
                }
                if (!string.IsNullOrEmpty(vm.MinorLossCurve))
                {
                    var pt_list = Yw.JsonHelper.Json2Object<List<HydroCurvePointViewModel>>(vm.MinorLossCurve);
                    _valveMatchingViewModel.MatchingCurveQL = pt_list;
                    _valveMatchingViewModel.MatchingCurveOL = null;
                }
            }
        }
    }
}