using Microsoft.Web.WebView2.Core; namespace PBS.WinFrmUI.Hydro { public partial class QuickModelingPlaceWizardPage : DevExpress.XtraEditors.XtraUserControl, IWizardPageAsync { public QuickModelingPlaceWizardPage() { InitializeComponent(); this.layoutControl1.SetupLayoutControl(); this.mapSetPlaceMarkerContainer1.LoadCompletedEvent += MapSetPlaceMarkerContainer1_LoadCompletedEvent; this.mapSetPlaceMarkerContainer1.SetMarkerEvent += MapSetPlaceMarkerContainer1_SetMarkerEvent; this.mapSetPlaceMarkerContainer1.SetMapBoundsEvent += MapSetPlaceMarkerContainer1_SetMapBoundsEvent; this.imgCmbPlaceType.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.mapSetPlaceMarkerContainer1.IsInitialized) { await this.mapSetPlaceMarkerContainer1.InitialContainer(); } this.txtName.EditValue = _vm.Place.Name; this.txtTagName.EditValue = _vm.Place.TagName; this.txtAddress.EditValue = _vm.Place.Address; this.txtDescription.EditValue = _vm.Place.Description; this.placeInfoCtrl1.Set(_vm.Place.PlaceType, _vm.Place.PlaceInfo); var allFlagsList = await BLLFactory.Instance.GetBySysType(DataType.PBSPlace); this.setFlagsEditCtrl1.SetBindingData(allFlagsList?.Select(x => x.Name).Distinct().ToList(), _vm.Place.Flags); this.imgCmbPlaceType.EditValue = _vm.Place.PlaceType; _isCompleted = true; this.PageStateChangedEvent?.Invoke(); } //加载完成事件 private async void MapSetPlaceMarkerContainer1_LoadCompletedEvent() { if (_vm.Marker != null) { await this.mapSetPlaceMarkerContainer1.LoadMarker(_vm.Marker); } } //设置地图边界 private void MapSetPlaceMarkerContainer1_SetMapBoundsEvent(Yw.Model.Map.Point southWest, Yw.Model.Map.Point northEast) { _vm.SouthWest = southWest; _vm.NorthEast = northEast; } //设置点 private void MapSetPlaceMarkerContainer1_SetMarkerEvent(Yw.Model.Map.Marker marker) { _vm.Marker = marker; this.txtAddress.EditValue = marker.Address; } //场所类型变换 private void imgCmbPlaceType_EditValueChanged(object sender, EventArgs e) { var placeType = (PBS.ePlaceType)this.imgCmbPlaceType.EditValue; this.placeInfoCtrl1.Set(placeType); } //验证 private bool Verify() { return this.Invoke(() => { var isExist = true; this.dxErrorProvider1.ClearErrors(); var name = this.txtName.Text.Trim(); if (string.IsNullOrEmpty(name)) { this.dxErrorProvider1.SetError(this.txtName, "必填项"); isExist= false; } if (!this.placeInfoCtrl1.Verify()) { isExist = false; } if (_vm.Marker==null) { isExist = false; TipFormHelper.ShowWarn("请设置地图信息!"); } if (_vm.SouthWest == null || _vm.NorthEast == null) { isExist = false; TipFormHelper.ShowWarn("请设置地图边界信息!"); } return isExist; }); } //保存 private async Task Save() { if (!Verify()) { return false; } var sizeInfo= await this.mapSetPlaceMarkerContainer1.CaptureImage(_vm.TempBackgroundImageUrl,_vm.SouthWest,_vm.NorthEast); if (sizeInfo == null) { _vm.IsCaptureImage = false; TipFormHelper.ShowError("截图失败!"); return false; } _vm.BackgroundHeight = sizeInfo.Value.Height; _vm.BackgroundWidth = sizeInfo.Value.Width; _vm.Zoom = sizeInfo.Value.Zoom; _vm.IsCaptureImage = true; _vm.Place.Name = this.txtName.Text.Trim(); _vm.Place.PlaceType = (ePlaceType)this.imgCmbPlaceType.EditValue; _vm.Place.Flags = this.setFlagsEditCtrl1.SelectedFlagList; _vm.Place.TagName = this.txtTagName.Text.Trim(); _vm.Place.Address = this.txtAddress.Text.Trim(); _vm.Place.Description = this.txtDescription.Text.Trim(); _vm.Place.PlaceInfo=this.placeInfoCtrl1.Get(); return true; } /// /// 允许上一步 /// public bool AllowPrev { get { return false; } } /// /// 允许下一步 /// public bool AllowNext { get { if (!_isCompleted) { return false; } return true; } } /// /// 允许取消 /// public bool AllowCancel { get { return false; } } /// /// 允许完成 /// public bool AllowComplete { get { return false; } } /// /// 能否上一步 /// /// public Task CanPrev() { return Task.Run(() => this.AllowPrev); } /// /// 能否下一步 /// public Task CanNext() { return Task.Run(async () => await Save()); } /// /// 能否取消 /// public Task CanCancel() { return Task.Run(() => this.AllowCancel); } /// /// 能否完成 /// public Task CanComplete() { return Task.Run(() => this.AllowComplete); } } }