ningshuxia
2025-03-24 7b8ae93d47186c442ff890a1a83d108f115924c7
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
using Microsoft.Web.WebView2.Core;
 
namespace PBS.WinFrmUI.Hydro
{
    public partial class QuickModelingPlaceWizardPage : DevExpress.XtraEditors.XtraUserControl, IWizardPageAsync<QuickModelingViewModel>
    {
        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<PBS.ePlaceType>();
        }
 
 
        /// <summary>
        /// 状态改变事件
        /// </summary>
        public event Action PageStateChangedEvent;
 
        private QuickModelingViewModel _vm = null;//操作对象
        private bool _isCompleted = false;//是否创建完成 
 
 
 
        /// <summary>
        /// 初始化页面
        /// </summary>
        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<Yw.BLL.SysFlag>.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<bool> 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;
        }
 
 
        /// <summary>
        /// 允许上一步
        /// </summary>
        public bool AllowPrev
        {
            get
            { 
                return false;
            }
        }
 
        /// <summary>
        /// 允许下一步
        /// </summary>
        public bool AllowNext
        {
            get
            {
                if (!_isCompleted)
                {
                    return false;
                } 
                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(async () => await Save());
        }
 
        /// <summary>
        /// 能否取消
        /// </summary>
        public Task<bool> CanCancel()
        {
            return Task.Run(() => this.AllowCancel);
        }
 
        /// <summary>
        /// 能否完成
        /// </summary>
        public Task<bool> CanComplete()
        {
            return Task.Run(() => this.AllowComplete);
        }
 
    }
}