From c0be7c001375f73e2c3b49a1b1d447b6fc297bdd Mon Sep 17 00:00:00 2001
From: duheng <2286773002@qq.com>
Date: 星期五, 21 三月 2025 13:43:00 +0800
Subject: [PATCH] Merge branch 'master' of http://47.103.154.90:83/r/HStation/XHS.V1.0

---
 WinFrmUI/PBS.WinFrmUI.Hydro/02-quick-modeling/02-place/QuickModelingPlaceWizardPage.cs |  354 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 293 insertions(+), 61 deletions(-)

diff --git a/WinFrmUI/PBS.WinFrmUI.Hydro/02-quick-modeling/02-place/QuickModelingPlaceWizardPage.cs b/WinFrmUI/PBS.WinFrmUI.Hydro/02-quick-modeling/02-place/QuickModelingPlaceWizardPage.cs
index 7fc1c0f..1406762 100644
--- a/WinFrmUI/PBS.WinFrmUI.Hydro/02-quick-modeling/02-place/QuickModelingPlaceWizardPage.cs
+++ b/WinFrmUI/PBS.WinFrmUI.Hydro/02-quick-modeling/02-place/QuickModelingPlaceWizardPage.cs
@@ -1,4 +1,6 @@
-锘縩amespace PBS.WinFrmUI.Hydro
+锘縰sing Microsoft.Web.WebView2.Core;
+
+namespace PBS.WinFrmUI.Hydro
 {
     public partial class QuickModelingPlaceWizardPage : DevExpress.XtraEditors.XtraUserControl, IWizardPageAsync<QuickModelingViewModel>
     {
@@ -6,9 +8,7 @@
         {
             InitializeComponent();
             this.layoutControl1.SetupLayoutControl();
-            this.mapSetSimpleMarkerContainer1.LoadCompletedEvent += MapSetSimpleMarkerContainer1_LoadCompletedEvent;
-            this.mapSetSimpleMarkerContainer1.SetMarkerEvent += MapSetSimpleMarkerContainer1_SetMarkerEvent;
-
+             this.imgCmbPlaceType.Properties.AddEnum<PBS.ePlaceType>();
         }
 
         /// <summary>
@@ -17,10 +17,9 @@
         public event Action PageStateChangedEvent;
 
         private QuickModelingViewModel _vm = null;//鎿嶄綔瀵硅薄
-        private bool _isCompleted = false;//鏄惁鍒涘缓瀹屾垚
-        private bool _createResult = false;//鍒涘缓缁撴灉
+        private bool _isCompleted = false;//鏄惁鍒涘缓瀹屾垚 
+        private bool _isInitialMap = false;//鏄惁鍒濆鍖栧湴鍥�
 
-         
 
         /// <summary>
         /// 鍒濆鍖栭〉闈�
@@ -31,53 +30,299 @@
             {
                 return;
             }
-            _vm = vm;
+            _vm = vm;  
             _isCompleted = false;
-            _createResult = false;
-        
-            //_createResult = await QuickModelingHelper.Create(vm, (msg, color) =>
-            // {
-            //     var drawItem = new DrawItemViewModel
-            //     {
-            //         Text = msg,
-            //         Color = color
-            //     };
-            //     this.listBoxControl1.Items.Add(drawItem);
-            // }, (max, current) =>
-            // {
-            //     this.progressBarControl1.Properties.Maximum = max;
-            //     this.progressBarControl1.Position = current;
-            //     //鏇夸唬鏂规
-            //     // this.progressBarControl1.Properties.Step = current;
-            //     // this.progressBarControl1.PerformStep();
-            // });
-            _isCompleted = true;
-            if (!_createResult)
+
+            if (!_isInitialMap)
             {
-                //this.progressBarControl1.Position = 0;
-                //this.itemForProgress.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
-            }
+                this.webView.Source = new Uri(AppDomain.CurrentDomain.BaseDirectory + "/web/html/map_select.html");
+                this.webView.WebMessageReceived += WebView_WebMessageReceived; 
+            } 
+
+            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 MapSetSimpleMarkerContainer1_LoadCompletedEvent()
+        public class AmapLocationViewModel
         {
-            if (_vm.Marker != null)
+            public AmapLocationViewModel()
             {
-                await this.mapSetSimpleMarkerContainer1.LoadMarker(_vm.Marker);
+                location = new Location();
+            } 
+            public string id { get; set; }
+            public string name { get; set; }
+            public string address { get; set; }
+            public Location location { get; set; } 
+            public long BuildTypeID { get; set; } 
+            public string NorthEast { get; set; }
+            public string SouthWest { get; set; }
+
+        }
+        public class FixationReceivedViewModel
+        {
+            public string Oper { get; set; }
+
+            public string Json { get; set; }
+        }
+          
+        public new class Location
+        {
+            public float lng { get; set; }
+            public float lat { get; set; }
+        }
+
+        public class Coordinate
+        {
+            public Coordinate(double lat, double lon)
+            {
+                this.lat = lat;
+                this.lon = lon;
+            }
+            /// <summary>
+            /// 绾害
+            /// </summary>
+            public double lat { get; set; }
+            /// <summary>
+            /// 缁忓害
+            /// </summary>
+            public double lon { get; set; }
+        }
+ 
+
+        public static class AmapBounds
+        {
+            public static double Distance(Coordinate coordinate1, Coordinate coordinate2)
+            {
+                var a = coordinate1;
+                var lat1 = a.lat;
+                var lon1 = a.lon;
+                var b = coordinate2;
+                var lat2 = b.lat;
+                var lon2 = b.lon;
+
+                if (lat1 == lat2 && lon1 == lon2)
+                {
+                    return 0;
+                }
+
+                a.lon = VC(a.lon, -180, 180);
+                a.lat = aD(a.lat, -74, 74);
+                b.lon = VC(b.lon, -180, 180);
+                b.lat = aD(b.lat, -74, 74);
+                double ret;
+                ret = JF(JK(a.lon), JK(b.lon), JK(a.lat), JK(b.lat));
+                return ret;
+            }
+            public static double aD(double a, double b, double c)
+            {
+                if (b != null)
+                {
+                    a = Math.Max(a, b);
+                }
+                if (b != null)
+                {
+                    a = Math.Min(a, c);
+                }
+                return a;
+            }
+            public static double VC(double a, double b, double c)
+            {
+                if (a > c)
+                {
+                    a -= c - b;
+                }
+                if (a < b)
+                {
+                    a += c - b;
+                }
+                return a;
+            }
+            public static double JK(double a)
+            {
+                double ret = Math.PI * a / 180.0;
+                return ret;
+            }
+            public static double JF(double a, double b, double c, double e)
+            {
+                const double Ou = 6370996.81;
+                return Ou * Math.Acos(Math.Sin(c) * Math.Sin(e) + Math.Cos(c) * Math.Cos(e) * Math.Cos(b - a));
             }
         }
 
-        //璁剧疆
-        private void MapSetSimpleMarkerContainer1_SetMarkerEvent(Yw.Model.Map.Marker obj)
+        private async void CaptureImage()
         {
-            _vm.Marker = obj;
-            if (string.IsNullOrEmpty(this.txtAddress.Text.Trim()))
+            await webView.EnsureCoreWebView2Async();
+            CoreWebView2 coreWebView = webView.CoreWebView2;
+            int pageWidth = webView.ClientSize.Width;
+            int pageHeight = webView.ClientSize.Height;
+            webView.Width = pageWidth;
+            webView.Height = pageHeight;
+
+            var directory = Path.GetDirectoryName(_vm.tempBackgroundImageUrl);
+            if (!Directory.Exists(directory))
             {
-                this.txtAddress.EditValue = obj.Address;
+                Directory.CreateDirectory(directory);
+            } 
+            var fileStream = new FileStream(_vm.tempBackgroundImageUrl + "_t.png", FileMode.Create);
+            await coreWebView.CapturePreviewAsync(CoreWebView2CapturePreviewImageFormat.Png, fileStream);
+            var bt = new Bitmap(fileStream);
+            var pWidth = pageWidth - 50;
+            var pHeight = pageHeight - 50;
+            try
+            {
+                bt.Clone(new Rectangle(50, 50, pWidth, pHeight), System.Drawing.Imaging.PixelFormat.DontCare).Save(_vm.tempBackgroundImageUrl);
             }
+            catch (Exception ex)
+            {
+            }
+            fileStream.Close();
+            var screen = Screen.PrimaryScreen;
+            var bound = screen.Bounds;
+            var bo = (double)bound.Height / bound.Width;
+            var dpi = Math.Round(bo, 3);//0.56
+            fileStream.Dispose();
+
+            #region 闀垮璁$畻
+
+            double lat = Convert.ToDouble(_vm.NorthEast.Split(',')[1]);
+            double lon = Convert.ToDouble(_vm.NorthEast.Split(',')[0]);
+            //鍙充笂瑙掑潗鏍�
+            Coordinate coordinate1 = new Coordinate(lat, lon);
+
+            double lat2 = Convert.ToDouble(_vm.SouthWest.Split(',')[1]);
+            double lon2 = Convert.ToDouble(_vm.SouthWest.Split(',')[0]);
+            //宸︿笅瑙掑潗鏍�
+            Coordinate coordinate2 = new Coordinate(lat2, lon2);
+
+            //鍙充笅瑙掑潗鏍�
+            Coordinate coordinate3 = new Coordinate(coordinate1.lat, coordinate2.lon);
+
+            //宸︿笂瑙掑潗鏍�
+            Coordinate coordinate4 = new Coordinate(coordinate2.lat, coordinate1.lon);
+            //璋冪敤Distance鏂规硶璁$畻涓ょ偣涔嬮棿鐨勮窛绂�
+            //甯垜璁$畻coordinate1鍜宑oordinate4涔嬮棿鐨勮窛绂�
+
+            double distanceHeight = AmapBounds.Distance(coordinate1, coordinate4);
+            double distanceWidth = AmapBounds.Distance(coordinate1, coordinate3);
+            _vm.BackgroundWidth = distanceWidth;
+            _vm.BackgroundHeight = distanceHeight;
+            var w = pageWidth / _vm.BackgroundWidth;
+            var h = pageHeight / _vm.BackgroundHeight;
+            _vm.Zoom = w > h ? w : h;
+
+            #endregion 闀垮璁$畻
+
+            _vm.IsCaptureImage = true;
+            File.Delete(_vm.tempBackgroundImageUrl + "_t.png");
+        }
+
+        private void WebView_WebMessageReceived(object sender, Microsoft.Web.WebView2.Core.CoreWebView2WebMessageReceivedEventArgs e)
+        {
+            var j = JsonHelper.Json2Object<FixationReceivedViewModel>(e.WebMessageAsJson);
+            switch (j.Oper)
+            {
+                case "loadCompleted":
+                
+                    var obl = JsonHelper.Json2Object<AmapLocationViewModel>(j.Json);
+                    _vm.NorthEast = obl.NorthEast;
+                    _vm.SouthWest = obl.SouthWest;
+                    break;
+
+                case "save":
+                    if (string.IsNullOrEmpty(_vm.SouthWest))
+                    {
+                        TipFormHelper.ShowWarn("鍏堣杈撳叆鍏抽敭瀛楁煡鎵惧埌寤虹瓚!");
+                        return;
+                    }
+              
+                    CaptureImage();
+                 
+                    break; 
+                case "getMapBounds":
+                    var ob = JsonHelper.Json2Object<AmapLocationViewModel>(j.Json);
+                    _vm.NorthEast = ob.NorthEast;
+                    _vm.SouthWest = ob.SouthWest;
+                    break;
+
+                case "getLocation":
+                    var o = JsonHelper.Json2Object<AmapLocationViewModel>(j.Json); 
+                    _vm.Marker = new Yw.Model.Map.Marker();
+                    _vm.Marker.Point = new Yw.Model.Map.Point(o.location.lng, o.location.lat);
+                    _vm.Marker.Address = o.name + o.address;
+                    this.txtAddress.Text = _vm.Marker.Address; 
+                    break; 
+                case "showMessage":
+                    TipFormHelper.ShowInfo(j.Json.ToString());
+                    break;
+            }
+        }
+         
+
+
+        //鍦烘墍绫诲瀷鍙樻崲
+        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.IsCaptureImage)
+                {
+                    isExist = false;
+                    TipFormHelper.ShowWarn("璇疯缃湴鍥句俊鎭紒");
+                }
+                //if (_vm.Marker==null)
+                //{
+                //    isExist = false;
+                //    TipFormHelper.ShowWarn("璇疯缃湴鍥句俊鎭紒");
+                //}
+                return isExist;
+            });
+        }
+
+        //淇濆瓨
+        private bool Save()
+        {
+            if (!Verify())
+            {
+                return false;
+            }
+
+            _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;
         }
 
 
@@ -87,15 +332,7 @@
         public bool AllowPrev
         {
             get
-            {
-                if (!_isCompleted)
-                {
-                    return false;
-                }
-                if (!_createResult)
-                {
-                    return true;
-                }
+            { 
                 return false;
             }
         }
@@ -107,11 +344,11 @@
         {
             get
             {
-                if (_createResult)
+                if (!_isCompleted)
                 {
-                    return true;
-                }
-                return false;
+                    return false;
+                } 
+                return true;
             }
         }
 
@@ -121,11 +358,7 @@
         public bool AllowCancel
         {
             get
-            {
-                if (!_createResult)
-                {
-                    return true;
-                }
+            { 
                 return false;
             }
         }
@@ -155,7 +388,7 @@
         /// </summary>
         public Task<bool> CanNext()
         {
-            return Task.Run(() => this.AllowNext);
+            return Task.Run(() => Save());
         }
 
         /// <summary>
@@ -174,6 +407,5 @@
             return Task.Run(() => this.AllowComplete);
         }
 
-     
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3