ningshuxia
2025-03-20 d1807075581920a8c94a409b11a9c88dd869be1e
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
using PBS.Vmo;
 
namespace PBS.WinFrmUI.Hydro
{
    public partial class QuickModelingFacilityWizardPage : DevExpress.XtraEditors.XtraUserControl, IWizardPageAsync<QuickModelingViewModel>
    {
        public QuickModelingFacilityWizardPage()
        {
            InitializeComponent();
            this.layoutControl1.SetupLayoutControl();
            this.textEditSupplyMode.Properties.AddEnum<PBS.eSupplyMode>();
            this.comboBoxWaterSupply.Properties.AddEnum<PBS.eWaterSupply>();
            this.imageComboBoxConnectionType.Properties.AddEnum<PBS.eConnectionType>();
        }
 
        /// <summary>
        /// 状态改变事件
        /// </summary>
        public event Action PageStateChangedEvent;
 
        private QuickModelingViewModel _vm = null;//操作对象
        private bool _isCompleted = false;//是否创建完成 
 
 
 
        /// <summary>
        /// 初始化页面
        /// </summary>
        public void InitialPage(QuickModelingViewModel vm)
        {
            if (vm == null)
            {
                return;
            }
            _vm = vm;
            _isCompleted = false;
 
            if (!this.comboBoxPackages.Properties.Items.Any())
            {
                foreach (var item in _vm.AssetsPackageList)
                {
                    this.comboBoxPackages.Properties.Items.Add(item.Name, item.ID, -1);
                }
            }
 
            this.txtName.EditValue = _vm.Facility.Name;
            this.txtFloor.EditValue = _vm.Facility.Floor;
            this.txtHouseholds.EditValue = _vm.Facility.Households;
            this.txtFloorHeight.EditValue = _vm.Facility.FloorHeight;
            this.txtMaxWaterDemand.EditValue = _vm.Facility.MaxWaterDemand;
            this.txtTerminalPressure.EditValue = _vm.Facility.TerminalPressure;
            this.comboBoxWaterSupply.EditValue = _vm.Facility.WaterSupply;
            this.txtConstantPressure.EditValue = _vm.Facility.ConstantPressure;
            this.textEditSupplyMode.EditValue = _vm.Facility.SupplyMode;
            this.comboBoxPackages.EditValue = _vm.Facility.PackageID;
            this.imageComboBoxConnectionType.EditValue = _vm.Facility.ConnectionType;
            this.textEditConnectionAddress.EditValue = _vm.Facility.ConnectionAddress;
 
            _isCompleted = true;
            this.PageStateChangedEvent?.Invoke();
        }
 
 
        //验证
        public bool Verify()
        {
            return this.Invoke(() =>
            {
                bool isExist = true;
                this.dxErrorProvider1.ClearErrors();
                if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
                {
                    this.dxErrorProvider1.SetError(this.txtName, "必填项");
                    isExist = false;
                }
                if (string.IsNullOrEmpty(this.txtFloor.Text.Trim()))
                {
                    this.dxErrorProvider1.SetError(this.txtFloor, "必填项");
                    isExist = false;
                }
                if (string.IsNullOrEmpty(this.txtFloorHeight.Text.Trim()))
                {
                    this.dxErrorProvider1.SetError(this.txtFloorHeight, "必填项");
                    isExist = false;
                }
                if (string.IsNullOrEmpty(this.txtHouseholds.Text.Trim()))
                {
                    this.dxErrorProvider1.SetError(this.txtHouseholds, "必填项");
                    isExist = false;
                }
                if (string.IsNullOrEmpty(this.txtConstantPressure.Text.Trim()))
                {
                    this.dxErrorProvider1.SetError(this.txtConstantPressure, "必填项");
                    isExist = false;
                }
 
                if (this.textEditSupplyMode.EditValue == null)
                {
                    this.dxErrorProvider1.SetError(this.textEditSupplyMode, "必填项");
                    isExist = false;
                }
                if (this.comboBoxWaterSupply.Text == "请选择")
                {
                    this.dxErrorProvider1.SetError(this.comboBoxWaterSupply, "必填项");
                    isExist = false;
                }
                if (string.IsNullOrEmpty(this.txtMaxWaterDemand.Text.Trim()))
                {
                    this.dxErrorProvider1.SetError(this.txtMaxWaterDemand, "必填项");
                    isExist = false;
                }
                if (string.IsNullOrEmpty(this.txtTerminalPressure.Text.Trim()))
                {
                    this.dxErrorProvider1.SetError(this.txtTerminalPressure, "必填项");
                    isExist = false;
                }
                return isExist;
            });
        }
 
        //保存
        private bool Save()
        {
            if (!Verify())
            {
                return false;
            }
            _vm.Facility.Name = this.txtName.Text.Trim(); 
            _vm.Facility.Floor = Convert.ToInt32(this.txtFloor.EditValue);
            _vm.Facility.FloorHeight = Convert.ToDouble(this.txtFloorHeight.EditValue);
            _vm.Facility.Households = Convert.ToInt32(this.txtHouseholds.EditValue);
 
            _vm.Facility.SupplyMode = (PBS.eSupplyMode)this.textEditSupplyMode.EditValue;
            _vm.Facility.MaxWaterDemand = Convert.ToDouble(this.txtMaxWaterDemand.EditValue);
            _vm.Facility.TerminalPressure = Convert.ToDouble(this.txtTerminalPressure.EditValue);
            _vm.Facility.ConstantPressure = Convert.ToDouble(this.txtConstantPressure.EditValue);
            if (this.comboBoxPackages.EditValue != null)
                _vm.Facility.PackageID = (long)this.comboBoxPackages.EditValue;
 
            _vm.Facility.WaterSupply = (PBS.eWaterSupply)this.comboBoxWaterSupply.EditValue;
            _vm.Facility.ConnectionType = (PBS.eConnectionType)this.imageComboBoxConnectionType.EditValue; 
            _vm.Facility.ConnectionAddress = this.textEditConnectionAddress.Text;  
            _vm.Facility.UseStatus = Yw.Vmo.eUseStatus.Enable;
            return true;
        }
 
 
        /// <summary>
        /// 允许上一步
        /// </summary>
        public bool AllowPrev
        {
            get
            {
                if (!_isCompleted)
                {
                    return false;
                }
             
                return true;
            }
        }
 
        /// <summary>
        /// 允许下一步
        /// </summary>
        public bool AllowNext
        {
            get
            { 
                return true;
            }
        }
 
        /// <summary>
        /// 允许取消
        /// </summary>
        public bool AllowCancel
        {
            get
            { 
               
                return false;
            }
        }
 
        /// <summary>
        /// 允许完成
        /// </summary>
        public bool AllowComplete
        {
            get
            {
                return false;
            }
        }
 
        /// <summary>
        /// 能否上一步
        /// </summary>
        /// <returns></returns>
        public Task<bool> CanPrev()
        {
            return Task.Run(() => this.AllowPrev);
        }
 
        /// <summary>
        /// 能否下一步
        /// </summary>
        public Task<bool> CanNext()
        {
            return Task.Run(() => Save());
        }
 
        /// <summary>
        /// 能否取消
        /// </summary>
        public Task<bool> CanCancel()
        {
            return Task.Run(() => this.AllowCancel);
        }
 
        /// <summary>
        /// 能否完成
        /// </summary>
        public Task<bool> CanComplete()
        {
            return Task.Run(() => this.AllowComplete);
        }
 
     
    }
}