From adc150efb13a0506f45a3c344c3ee2ef2dba8e90 Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期四, 01 七月 2021 15:19:13 +0800
Subject: [PATCH] 合并嘉乐lc代码

---
 HDL_ON/UI/UI2/4-PersonalCenter/RoomListManage/RoomEditPageBLL.cs |  270 +++++++++++++++++++++++++++++------------------------
 1 files changed, 148 insertions(+), 122 deletions(-)

diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/RoomListManage/RoomEditPageBLL.cs b/HDL_ON/UI/UI2/4-PersonalCenter/RoomListManage/RoomEditPageBLL.cs
index 6232997..25a6f44 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/RoomListManage/RoomEditPageBLL.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/RoomListManage/RoomEditPageBLL.cs
@@ -2,6 +2,8 @@
 using Shared;
 using HDL_ON.Entity;
 using System.Collections.Generic;
+using HDL_ON.DAL.Server;
+using System.Threading;
 
 namespace HDL_ON.UI
 {
@@ -27,60 +29,51 @@
         {
             btnOption.MouseUpEventHandler = (sender, e) =>
             {
-                if (btnOption.TextID == StringId.Save)
+                Action action = () =>
                 {
-                    if (string.IsNullOrEmpty(room.roomName))
+                    var waitPage = new Loading();
+                    waitPage.Start();
+                    new Thread(() =>
                     {
-                        new Tip()
+                        try
                         {
-                            CloseTime = 1,
-                            Text = Language.StringByID(StringId.RoomNameCannotBeEmpty),
-                            Direction = AMPopTipDirection.None,
-                        }.Show(bodyView);
-                        return;
-                    }
-                    if (string.IsNullOrEmpty(room.floorName))
-                    {
-                        new Tip()
-                        {
-                            CloseTime = 1,
-                            Text = Language.StringByID(StringId.PlsBindFloor),
-                            Direction = AMPopTipDirection.None,
-                        }.Show(bodyView);
-                        return;
-                    }
-                    foreach (var tempRoom in DB_ResidenceData.Rooms)
-                    {
-                        if (room.roomName == tempRoom.roomName)
-                        {
-                            new PublicAssmebly().TipMsg(StringId.Tip, StringId.AddingFailed_RoomAlreadyExists);
-                            return;
-                        }
-                    }
-                    DB_ResidenceData.residenceData.AddRoom(room);
-                    room.SaveRoomData();
-                    backAction();
-                    this.RemoveFromParent();
-                }
-                if (btnOption.TextID == StringId.DeleteRoom)
-                {
-                    Action action = () =>
-                    {
-                        foreach (var f in DB_ResidenceData.functionList.GetAllFunction())
-                        {
-                            if (f.roomIds.Contains(room.uid))
+                            var delResult = SpatialInfo.CurrentSpatial.DelRoom(room);
+                            if (delResult == StateCode.SUCCESS)
                             {
-                                f.roomIds.Remove(room.uid);
+                                foreach (var f in FunctionList.List.GetDeviceFunctionList())
+                                {
+                                    if (f.roomIds.Contains(room.roomId))
+                                    {
+                                        f.roomIds.Remove(room.roomId);
+                                    }
+                                }
+                                Application.RunOnMainThread(() =>
+                                {
+                                    //鍒犻櫎浜嬩欢鍥炶皟
+                                    this.deleteAction?.Invoke();
+                                    this.RemoveFromParent();
+                                });
                             }
                         }
-                        DB_ResidenceData.residenceData.DelRoom(room);
-                        backAction();
-                        this.RemoveFromParent();
-                    };
-                    new PublicAssmebly().TipMsg(StringId.Tip, StringId.DeleteRoomTip, action);
+                        catch (Exception ex)
+                        {
+                            MainPage.Log($"娣诲姞鎴块棿澶辫触msg:{ex.Message}");
+                        }
+                        finally
+                        {
+                            Application.RunOnMainThread(() =>
+                            {
+                                waitPage.Hide();
+                                waitPage.RemoveFromParent();
+                            });
+                        }
+                    })
+                    { IsBackground = true }.Start();
                 };
+                new PublicAssmebly().TipOptionMsg(StringId.Tip, StringId.DeleteRoomTip, action);
             };
         }
+
 
         /// <summary>
         /// 鏄剧ず鑳屾櫙鍥鹃�夋嫨閫夐」
@@ -113,26 +106,16 @@
                 }
                 btnRoomName.Text = str;
                 room.roomName = str;
-                if (pageTitleId == StringId.EditRoomInfo)
-                {
-                    room.SaveRoomData();
-                }
+                room.UpdataRoomInfo();
             };
             EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
             {
                 List<string> roomNameList = new List<string>();
-                foreach (var rroom in DB_ResidenceData.Rooms)
+                foreach (var rroom in SpatialInfo.CurrentSpatial.RoomList)
                 {
                     roomNameList.Add(rroom.roomName);
                 }
-                if (pageTitleId == StringId.AddRoom)
-                {
-                    new PublicAssmebly().LoadDialog_EditParater(StringId.RoomName, room.roomName, callBack, StringId.RoomNameCannotBeEmpty, StringId.RoomNameAlreadyExists, roomNameList);
-                }
-                else
-                {
-                    new PublicAssmebly().LoadDialog_EditParater(StringId.RoomName, room.roomName, callBack, StringId.RoomNameCannotBeEmpty, StringId.EidtFailed_RoomAlreadyExists, roomNameList);
-                }
+                new PublicAssmebly().LoadDialog_EditParater(StringId.RoomName, room.roomName, callBack, StringId.RoomNameCannotBeEmpty, StringId.EidtFailed_RoomAlreadyExists, roomNameList);
             };
             btnEditRoomNameIcon.MouseUpEventHandler = eventHandler;
             roomNameRow.MouseUpEventHandler = eventHandler;
@@ -149,10 +132,11 @@
                 Action floorsCallBackAction = () =>
                 {
                     btnFloorInfo.Text = room.floorName;
+                    room.UpdataRoomInfo();
                 };
-                var residentialManagePage = new FloorsManagementPage(floorsCallBackAction);
+                var residentialManagePage = new RoomBinglingFloorPage(floorsCallBackAction, room);
                 MainPage.BasePageView.AddChidren(residentialManagePage);
-                residentialManagePage.LoadPage(room, StringId.FloorAssignment);
+                residentialManagePage.LoadPage();
                 MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
             };
             btnFloorInfo.MouseUpEventHandler = eventHandler;
@@ -230,22 +214,12 @@
             btnTakePicture.MouseUpEventHandler = (sender, e) =>
             {
                 btnTakePicture.IsSelected = false;
-                //var pid = Guid.NewGuid();
-                //CropImage.TakePicture((imagePath) =>
-                //{
-                //    if (imagePath != null)
-                //    {
-                //        btnRoomBg.ImagePath = imagePath.ToString();
-                //        room.backgroundImage = btnRoomBg.ImagePath;
-                //        MainPage.Log("SelectPicture 瑁佸壀鍥剧墖杩斿洖璺緞: " + imagePath);
-                //    }
-                //}, pid.ToString(), 16, 9);
-
-                //var imageName = Guid.NewGuid().ToString();
-                var imageName = room.uid;
+               
+                var imageName = Guid.NewGuid().ToString();
+                //var imageName = room.sid;
                 CropImage.TakePicture((imagePath) =>
                 {
-                    CropImageCallBack(imagePath, imageName);
+                    CropImageCallBack(imagePath);
 
                 }, imageName, 16, 9);
 
@@ -260,23 +234,13 @@
             btnAlbum.MouseUpEventHandler = (sender, e) =>
             {
                 btnAlbum.IsSelected = false;
-                //var pid = Guid.NewGuid();
-                //CropImage.SelectPicture((imagePath) =>
-                //{
-                //    if (imagePath != null)
-                //    {
-                //        btnRoomBg.ImagePath = imagePath.ToString();
-                //        room.backgroundImage = btnRoomBg.ImagePath;
-                //        MainPage.Log("SelectPicture 瑁佸壀鍥剧墖杩斿洖璺緞: " + imagePath);
-                //    }
-                //}, pid.ToString(), 16, 9);
 
                 //浠庣浉鍐岄�夋嫨鍥剧墖瑁佸壀
-                //var imageName = Guid.NewGuid().ToString();
-                var imageName = room.uid;
+                var imageName = Guid.NewGuid().ToString();
+                //var imageName = room.sid;
                 CropImage.SelectPicture((imagePath) =>
                 {
-                    CropImageCallBack(imagePath, imageName);
+                    CropImageCallBack(imagePath);
 
                 }, imageName, 16, 9);
 
@@ -287,13 +251,13 @@
             //鎴块棿榛樿鍥惧簱
             btnDefaultGallery.MouseUpEventHandler = (sender, e) => {
                 pictureOptionView.Parent.RemoveFromParent();
-                Action<string> action = (obj) => {
+                Action<string> action = (obj) =>
+                {
                     room.backgroundImage = obj;
+                    btnRoomBg.ImageBytes = null;//瑙e喅鏈塈mageBytes涓嶅姞杞絀magePath
                     btnRoomBg.ImagePath = room.backgroundImage;
-                    if (pageTitleId == StringId.EditRoomInfo)
-                    {
-                        room.SaveRoomData();
-                    }
+                    room.UpdataRoomInfo();
+                    modifyImageAction?.Invoke();
                 };
 
                 var galleryPage = new RoomGalleryPage(room.backgroundImage, action);
@@ -309,46 +273,108 @@
         /// </summary>
         /// <param name="imagePath">瑁佸壀鍚庣殑鐪熷疄璺緞</param>
         /// <param name="imageName">鑷畾涔夌殑鍥剧墖鍚嶇О</param>
-        void CropImageCallBack(string imagePath, string imageName)
+        void CropImageCallBack(string selectImagePath)
         {
-            if (string.IsNullOrEmpty(imagePath) == true)
+            if (string.IsNullOrEmpty(selectImagePath) == true)
             {
                 return;
             }
+            //涓婁紶鎴愬姛鍒板洖璋�
+            Action<string> uploadSuccessAction = (imageUrl) =>
+            {
+                //2020-12-03 闇�瑕佽鏈�鏂扮殑鍥剧墖璺緞鍚屾鍒颁簯绔�
+                room.backgroundImage = imageUrl;
+                room.UpdataRoomInfo();
+                modifyImageAction?.Invoke();
+            };
+            //涓婁紶鍥剧墖鍒颁簯绔�
+            UploadImage(selectImagePath, btnRoomBg, room, uploadSuccessAction);
+        }
+
+        /// <summary>
+        /// 涓婁紶鍥剧墖鏂规硶
+        /// </summary>
+        /// <param name="selectImagePath">瑁佸壀鍚庣殑鍥剧墖璺緞</param>
+        /// <param name="imageView"></param>
+        /// <param name="uploadSuccessAction"></param>
+        void UploadImage(string selectImagePath, ImageView imageView, Room mRoom, Action<string> uploadSuccessAction)
+        {
             try
             {
-                var mPath = imagePath;
-                MainPage.Log("SelectPicture 瑁佸壀鍥剧墖杩斿洖璺緞: " + imagePath);
-#if __IOS__
+                //MainPage.Log("SelectPicture 瑁佸壀鍥剧墖杩斿洖璺緞: " + selectImagePath);
+                //1.璇诲彇瑁佸壀鍚庣殑鍥剧墖锛岀劧鍚庡垹闄�
+                var imageBytes = Shared.IO.FileUtils.ReadFile(selectImagePath);
+                System.IO.File.Delete(selectImagePath);
 
-
-#else
-            //imageName = imageName + ".png";
-
-            //1.浣跨敤鏂板悕瀛楋紝瑙e喅鐩稿悓璺緞涓嶅埛鏂板浘鐗囬棶棰�
-            imageName = Guid.NewGuid().ToString() + ".png";
-            //1.2濡傛灉鏄嚜瀹氫箟鍥剧墖鍒犻櫎涔嬪墠鐨�
-            if (!btnRoomBg.ImagePath.Contains("Room")) {
-                Utlis.WriteLine("鍒犻櫎: " + btnRoomBg.ImagePath);
-                System.IO.File.Delete(btnRoomBg.ImagePath);
-            }
-            //1.3濡傛灉鏄畨鍗撻渶瑕佹嫹璐濆洖鏉PP鏍圭洰褰�
-            FileUtils.FileCopyToRootPath(imagePath, imageName);
-            System.IO.File.Delete(imagePath);
-            mPath = imageName;
-#endif
-                //娓呯┖鍘熸潵鍥剧墖
-                btnRoomBg.ImagePath = "NULL";
-                //鐢熸垚鍥剧墖
-                room.backgroundImage = mPath;
-                btnRoomBg.ImagePath = mPath;
-
-                if (pageTitleId == StringId.EditRoomInfo)
+                var waitPage = new Loading();
+                bodyView.AddChidren(waitPage);
+                waitPage.Start(Language.StringByID(StringId.PleaseWait));
+                //寮�濮嬩笂浼�
+                new Thread(() =>
                 {
-                    room.SaveRoomData();
-                }
+                    try
+                    {
+                        var newImageName = mRoom.roomName.Trim() +  ".png";
+                        var uploadImageObj = new UploadImageObj()
+                        {
+                            prefix = "Room" + Utlis.GetTimestamp(),
+                            fileName = newImageName,
+                            uid = mRoom.uid,
+                            content = imageBytes,
+                        };
+
+                        var imageUrl = ImageUtlis.Current.UploadImage(uploadImageObj);
+                        if (!string.IsNullOrEmpty(imageUrl) && imageUrl.Contains(newImageName))
+                        {
+                            //涓婁紶鎴愬姛
+                            Application.RunOnMainThread(() =>
+                            {
+                                //Utlis.WriteLine("涓婁紶鎴愬姛锛�" + imageUrl);
+                                //1.2濡傛灉鏄嚜瀹氫箟鍥剧墖鍒犻櫎涔嬪墠鐨�
+                                if (!string.IsNullOrEmpty(imageView.ImagePath) && !imageView.ImagePath.Contains("Classification/Room/Roombg"))
+                                {
+                                    //Utlis.WriteLine("鍒犻櫎: " + imageView.ImagePath);
+                                    System.IO.File.Delete(imageView.ImagePath);
+                                }
+                                //閲嶅懡鍚嶄繚瀛�
+                                ImageUtlis.Current.WriteFileByBytes(imageUrl, imageBytes);
+                                imageView.ImagePath = null;
+                                imageView.ImageBytes = imageBytes;
+                                //涓婁紶鎴愬姛
+                                Utlis.ShowTip(Language.StringByID(StringId.UploadSuccessfully));
+                                uploadSuccessAction?.Invoke(imageUrl);
+                            });
+                        }
+                        else
+                        {
+                            //涓婁紶澶辫触
+                            Application.RunOnMainThread(() =>
+                            {
+                                //涓婁紶澶辫触
+                                Utlis.ShowTip(Language.StringByID(StringId.UploadFailed));
+                            });
+                        }
+
+                    }
+                    catch (Exception ex)
+                    {
+                    }
+                    finally
+                    {
+                        Application.RunOnMainThread(() =>
+                        {
+                            if (waitPage != null)
+                            {
+                                waitPage.RemoveFromParent();
+                                waitPage = null;
+                            }
+                        });
+                    }
+                })
+                { IsBackground = true }.Start();
             }
             catch { }
         }
+
     }
 }
\ No newline at end of file

--
Gitblit v1.8.0