From dcb9b9b5561b4e6d1eaf1e602e8ae054e578ec6e Mon Sep 17 00:00:00 2001 From: 陈嘉乐 <cjl@hdlchina.com.cn> Date: 星期五, 04 十二月 2020 16:06:47 +0800 Subject: [PATCH] Merge branch 'master' into WJC --- HDL_ON/UI/UI2/4-PersonalCenter/RoomListManage/RoomEditPageBLL.cs | 188 +++++++++++++++++++++++++++++----------------- 1 files changed, 119 insertions(+), 69 deletions(-) diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/RoomListManage/RoomEditPageBLL.cs b/HDL_ON/UI/UI2/4-PersonalCenter/RoomListManage/RoomEditPageBLL.cs index 8cd2f51..59a8daf 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 { @@ -29,7 +31,7 @@ { if (btnOption.TextID == StringId.Save) { - if (string.IsNullOrEmpty(room.name)) + if (string.IsNullOrEmpty(room.roomName)) { new Tip() { @@ -49,15 +51,15 @@ }.Show(bodyView); return; } - foreach (var tempRoom in DB_ResidenceData.rooms) + foreach (var tempRoom in DB_ResidenceData.residenceData.Rooms) { - if (room.name == tempRoom.name) + if (room.roomName == tempRoom.roomName) { new PublicAssmebly().TipMsg(StringId.Tip, StringId.AddingFailed_RoomAlreadyExists); return; } } - DB_ResidenceData.rooms.Add(room); + SpatialInfo.CurrentSpatial.AddRoom(room); room.SaveRoomData(); backAction(); this.RemoveFromParent(); @@ -68,13 +70,16 @@ { foreach (var f in DB_ResidenceData.functionList.GetAllFunction()) { - if (f.roomIds.Contains(room.sid)) + if (f.roomIds.Contains(room.uid)) { - f.roomIds.Remove(room.sid); + f.roomIds.Remove(room.uid); } } - DB_ResidenceData.DelRoom(room); - backAction(); + SpatialInfo.CurrentSpatial.DelRoom(room); + // backAction(); + // DB_ResidenceData.DelRoom(room); + //鍒犻櫎浜嬩欢鍥炶皟 + this.deleteAction?.Invoke(); this.RemoveFromParent(); }; new PublicAssmebly().TipMsg(StringId.Tip, StringId.DeleteRoomTip, action); @@ -112,7 +117,7 @@ return; } btnRoomName.Text = str; - room.name = str; + room.roomName = str; if (pageTitleId == StringId.EditRoomInfo) { room.SaveRoomData(); @@ -121,17 +126,17 @@ EventHandler<MouseEventArgs> eventHandler = (sender, e) => { List<string> roomNameList = new List<string>(); - foreach (var rroom in DB_ResidenceData.rooms) + foreach (var rroom in DB_ResidenceData.residenceData.Rooms) { - roomNameList.Add(rroom.name); + roomNameList.Add(rroom.roomName); } if (pageTitleId == StringId.AddRoom) { - new PublicAssmebly().LoadDialog_EditParater(StringId.RoomName, room.name, callBack, StringId.RoomNameCannotBeEmpty, StringId.RoomNameAlreadyExists, roomNameList); + new PublicAssmebly().LoadDialog_EditParater(StringId.RoomName, room.roomName, callBack, StringId.RoomNameCannotBeEmpty, StringId.RoomNameAlreadyExists, roomNameList); } else { - new PublicAssmebly().LoadDialog_EditParater(StringId.RoomName, room.name, 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; @@ -230,22 +235,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.sid; + + var imageName = Guid.NewGuid().ToString(); + //var imageName = room.sid; CropImage.TakePicture((imagePath) => { - CropImageCallBack(imagePath, imageName); + CropImageCallBack(imagePath); }, imageName, 16, 9); @@ -260,23 +255,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.sid; + var imageName = Guid.NewGuid().ToString(); + //var imageName = room.sid; CropImage.SelectPicture((imagePath) => { - CropImageCallBack(imagePath, imageName); + CropImageCallBack(imagePath); }, imageName, 16, 9); @@ -309,46 +294,111 @@ /// </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; } - try + //涓婁紶鎴愬姛鍒板洖璋� + Action<string> uploadSuccessAction = (imageUrl) => { - var mPath = imagePath; - MainPage.Log("SelectPicture 瑁佸壀鍥剧墖杩斿洖璺緞: " + imagePath); -#if __IOS__ - - -#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; - + //2020-12-03 闇�瑕佽鏈�鏂扮殑鍥剧墖璺緞鍚屾鍒颁簯绔� + room.backgroundImage = imageUrl; if (pageTitleId == StringId.EditRoomInfo) { room.SaveRoomData(); + } + }; + //涓婁紶鍥剧墖鍒颁簯绔� + 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 + { + MainPage.Log("SelectPicture 瑁佸壀鍥剧墖杩斿洖璺緞: " + selectImagePath); + //1.璇诲彇瑁佸壀鍚庣殑鍥剧墖锛岀劧鍚庡垹闄� + var imageBytes = Shared.IO.FileUtils.ReadFile(selectImagePath); + System.IO.File.Delete(selectImagePath); + + var waitPage = new Loading(); + bodyView.AddChidren(waitPage); + waitPage.Start(Language.StringByID(StringId.PleaseWait)); + //寮�濮嬩笂浼� + new Thread(() => + { + try + { + var newImageName = mRoom.roomName.Trim() + ".png"; + var uploadImageObj = new UploadImageObj() + { + prefix = "ONR", + 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 (!imageView.ImagePath.Contains("Classification/Room/Roombg")) + { + Utlis.WriteLine("鍒犻櫎: " + imageView.ImagePath); + System.IO.File.Delete(imageView.ImagePath); + } + //閲嶅懡鍚嶄繚瀛� + FileUtils.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