using PBS.Vmo; namespace PBS.WinFrmUI.Hydro { public partial class QuickModelingFacilityWizardPage : DevExpress.XtraEditors.XtraUserControl, IWizardPageAsync { public QuickModelingFacilityWizardPage() { InitializeComponent(); this.layoutControl1.SetupLayoutControl(); this.textEditSupplyMode.Properties.AddEnum(); this.comboBoxWaterSupply.Properties.AddEnum(); this.imageComboBoxConnectionType.Properties.AddEnum(); } /// /// 状态改变事件 /// public event Action PageStateChangedEvent; private QuickModelingViewModel _vm = null;//操作对象 private bool _isCompleted = false;//是否创建完成 /// /// 初始化页面 /// public async 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.txtMaxHeight.EditValue = _vm.Facility.MaxHeight; 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; var allFlagsList = await BLLFactory.Instance.GetBySysType(DataType.PBSPlace); this.setFlagsEditCtrl1.SetBindingData(allFlagsList?.Select(x => x.Name).Distinct().ToList(), _vm.Place.Flags); _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 (string.IsNullOrEmpty(this.txtMaxHeight.Text.Trim())) { this.dxErrorProvider1.SetError(this.txtMaxHeight, "必填项"); 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; } if ((this.comboBoxPackages.EditValue is long id) && id < 1) { this.dxErrorProvider1.SetError(this.comboBoxPackages, "必选项"); 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; } /// /// 允许上一步 /// public bool AllowPrev { get { if (!_isCompleted) { return false; } return true; } } /// /// 允许下一步 /// public bool AllowNext { get { return true; } } /// /// 允许取消 /// public bool AllowCancel { get { return false; } } /// /// 允许完成 /// public bool AllowComplete { get { return false; } } /// /// 能否上一步 /// /// public Task CanPrev() { return Task.Run(() => { Save(); return this.AllowPrev; }); } /// /// 能否下一步 /// public Task CanNext() { return Task.Run(() => Save()); } /// /// 能否取消 /// public Task CanCancel() { return Task.Run(() => this.AllowCancel); } /// /// 能否完成 /// public Task CanComplete() { return Task.Run(() => this.AllowComplete); } } }