From eda3fb873e59544ff36301b51e05aef64f87b0f9 Mon Sep 17 00:00:00 2001
From: wei <kaede@kaededeMacBook-Air.local>
Date: 星期五, 27 八月 2021 13:21:21 +0800
Subject: [PATCH] Merge branch 'newBranch1' of http://172.16.1.23:6688/r/~wxr/HDL_APP_Project into newBranch1

---
 HDL_ON/UI/UI2/4-PersonalCenter/MemberManagement/MemberPermissionPage.cs |  441 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 303 insertions(+), 138 deletions(-)

diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/MemberManagement/MemberPermissionPage.cs b/HDL_ON/UI/UI2/4-PersonalCenter/MemberManagement/MemberPermissionPage.cs
index 0afb065..e7454e3 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/MemberManagement/MemberPermissionPage.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/MemberManagement/MemberPermissionPage.cs
@@ -4,13 +4,18 @@
 using HDL_ON.Entity;
 using System.Collections.Generic;
 using HDL_ON.DAL;
+using HDL_ON.DAL.Server;
 
 namespace HDL_ON.UI
 {
+    /// <summary>
+    /// 鎴愬憳鏉冮檺绠$悊椤甸潰
+    /// </summary>
     public partial class MemberPermissionPage : FrameLayout
     {
         MemberPermissionPage bodyView;
         Button btnDelMember;
+        VerticalScrolViewLayout roomListView;
 
         ResidenceMemberInfo memberInfo;
 
@@ -26,7 +31,7 @@
         public void LoadPage()
         {
             bodyView.BackgroundColor = CSS_Color.BackgroundColor;
-            new TopViewDiv(bodyView, Language.StringByID(StringId.PermissionToUse)).LoadTopView();
+            new TopViewDiv(bodyView, Language.StringByID(StringId.MemberPermissionManagement)).LoadTopView();
 
             FrameLayout headPortraitView = new FrameLayout()
             {
@@ -54,18 +59,46 @@
                 TextAlignment = TextAlignment.CenterLeft,
                 TextColor = CSS_Color.FirstLevelTitleColor,
                 TextSize = CSS_FontSize.TextFontSize,
-                Text = memberInfo.nickName + "(" + memberInfo.Account + ")",
+                //Text = memberInfo.nickName + "(" + memberInfo.UserName + ")",
             };
             headPortraitView.AddChidren(btnMemberName);
+            string username = HDLCommon.Current.GetUserName(memberInfo.memberName);
+            btnMemberName.Text = memberInfo.nickName + "(" + username + ")";
 
             #region RoomList
-            VerticalScrolViewLayout roomListView = new VerticalScrolViewLayout()
+            roomListView = new VerticalScrolViewLayout()
             {
                 Y = Application.GetRealHeight(138),
                 Height = Application.GetRealHeight(471),
                 //BackgroundColor = CSS_Color.MainBackgroundColor,
             };
             bodyView.AddChidren(roomListView);
+            #endregion
+
+            btnDelMember = new Button()
+            {
+                Y = Application.GetRealHeight(617),
+                //Height = MainPage.Increase ? Application.GetRealHeight(70) : Application.GetRealHeight(50),
+                Height = Application.GetRealHeight(50),
+                TextAlignment = TextAlignment.Center,
+                TextSize = CSS_FontSize.SubheadingFontSize,
+                TextColor = CSS_Color.WarningColor,
+                TextID = StringId.RemoveTheMember,
+                BackgroundColor = CSS_Color.MainBackgroundColor,
+            };
+            bodyView.AddChidren(btnDelMember);
+
+            LoadEventList();
+
+            GetShareDataByAccount();
+        }
+
+        /// <summary>
+        /// 鍔犺浇鎴块棿鍒楄〃,缁熻鍒嗕韩鐨勬暟鎹�
+        /// </summary>
+        void ShowRoomListView()
+        {
+            roomListView.RemoveAll();
 
             var titleView = new FrameLayout()
             {
@@ -87,156 +120,288 @@
             var btnLine = new Button()
             {
                 X = Application.GetRealWidth(16),
-                Y = btnTitle.Bottom,
+                Y = titleView.Height - Application.GetRealHeight(2),
                 Width = Application.GetRealWidth(360),
                 Height = Application.GetRealHeight(1),
                 BackgroundColor = CSS_Color.DividingLineColor,
             };
-            roomListView.AddChidren(btnLine);
+            titleView.AddChidren(btnLine);
 
             //---------------------------------------------
-            //var roomListView = new VerticalScrolViewLayout()
-            //{
-            //    Y = btnLine.Bottom,
-            //    Height = Application.GetRealHeight(440),
-            //};
-            //contentView.AddChidren(roomListView);
-
-            //List<Function> funss = new List<Function>();
-            //if (memberInfo.CurResidenceShareDate.Count > 0)
-            //{
-            //    foreach (var sd in memberInfo.CurResidenceShareDate)
-            //    {
-            //        funss.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<ShareData>(System.Text.Encoding.UTF8.GetString(sd.ShareDataBytes)));
-            //    }
-            //}
-            foreach (var room in DB_ResidenceData.Rooms)
+            //鏈垎閰嶅尯鍩熺殑鍔熻兘
+            List<Function> allFunctionList = FunctionList.List.GetDeviceFunctionList();
+            //鏈垎閰嶅尯鍩熺殑鍔熻兘
+            List<Function> unallocatedList = new List<Function>();
+            //
+            foreach (var function in allFunctionList)
             {
-                var roomView = new FrameLayout()
+                function.roomIds.Remove(null);
+                if (function.roomIds.Count > 0)
                 {
-                    Height = Application.GetRealWidth(50),
-                    BackgroundColor = CSS_Color.MainBackgroundColor,
-                };
-                roomListView.AddChidren(roomView);
-
-                var btnRoomName = new Button()
-                {
-                    X = Application.GetRealWidth(16),
-                    Y = Application.GetRealWidth(4),
-                    Width = Application.GetRealWidth(330),
-                    Height = Application.GetRealWidth(24),
-                    TextAlignment = TextAlignment.CenterLeft,
-                    TextColor = CSS_Color.FirstLevelTitleColor,
-                    TextSize = CSS_FontSize.TextFontSize,
-                    Text = room.roomName,
-                };
-                roomView.AddChidren(btnRoomName);
-
-                //璁$畻宸茬粡鍔犲叆鎴块棿鐨勮澶囨暟閲�
-                int addCount = 0;
-                foreach (var sd in memberInfo.CurResidenceShareDate)
-                {
-                    if (room.GetRoomFunctions(false).Find((obj) => obj.sid == sd.fileName) != null)
-                    {
-                        addCount++;
-                    }
+                    //allocatedList.Add(function);
                 }
-                //绉婚櫎褰撳墠浣忓畢宸茬粡涓嶅瓨鍦ㄧ殑鍔熻兘
-                for(int i= 0;i< memberInfo.CurResidenceShareDate.Count;)
+                else
                 {
-                    var sd = memberInfo.CurResidenceShareDate[i];
-                    if (DB_ResidenceData.functionList.GetAllFunction().Find((obj) => obj.sid == sd.fileName) == null)
-                    {
-                        new DAL.Server.HttpServerRequest().DeleteShareData(sd);
-                        memberInfo.CurResidenceShareDate.Remove(sd);
-                    }
-                    else
-                    {
-                        i++;
-                    }
-                }
-
-                var btnFunctionCount = new Button()
-                {
-                    X = Application.GetRealWidth(16),
-                    Y = btnRoomName.Bottom,
-                    Width = Application.GetRealWidth(330),
-                    Height = Application.GetRealWidth(18),
-                    TextAlignment = TextAlignment.CenterLeft,
-                    TextColor = CSS_Color.PromptingColor1,
-                    TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
-                    Text = addCount + "/" + room.GetRoomFunctions(false).Count.ToString(),
-                };
-                roomView.AddChidren(btnFunctionCount);
-
-                var btnRight = new Button()
-                {
-                    X = Application.GetRealWidth(351),
-                    Gravity = Gravity.CenterVertical,
-                    Width = Application.GetMinRealAverage(16),
-                    Height = Application.GetMinRealAverage(16),
-                    UnSelectedImagePath = "Public/Right.png",
-                };
-                roomView.AddChidren(btnRight);
-
-                EventHandler<MouseEventArgs> eHandler = (sender, e) =>
-                {
-                    Action<string> refreshFunctionCount = (newCount) => {
-                        btnFunctionCount.Text = newCount + "/" + room.GetRoomFunctions(false).Count.ToString();
-                    };
-                    var mmp = new MemberFunctionPermissionPage(memberInfo, room,refreshFunctionCount);
-                    MainPage.BasePageView.AddChidren(mmp);
-                    mmp.LoadPage(StringId.PermissionToUse);
-                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
-                };
-                roomView.MouseUpEventHandler = eHandler;
-                btnRoomName.MouseUpEventHandler = eHandler;
-                btnRight.MouseUpEventHandler = eHandler;
-
-                if (DB_ResidenceData.Rooms.IndexOf(room) < DB_ResidenceData.Rooms.Count - 2)
-                {
-                    var btnRoomLine = new Button()
-                    {
-                        X = Application.GetRealWidth(16),
-                        Y = Application.GetRealWidth(49),
-                        Width = Application.GetRealWidth(343),
-                        Height = Application.GetRealWidth(1),
-                        BackgroundColor = CSS_Color.DividingLineColor,
-                    };
-                    roomView.AddChidren(btnRoomLine);
+                    unallocatedList.Add(function);
                 }
             }
 
-            //if (DB_ResidenceData.rooms.Count > 10)
-            //{
-            //    roomListView.ScrollEnabled = true;
-            //}
-            //else
-            //{
-            //    roomListView.ScrollEnabled = false;
-
-            //    roomListView.AddChidren(new Button()
-            //    {
-            //        Height = Application.GetRealWidth(441),
-            //        BackgroundColor = CSS_Color.BackgroundColor,
-            //    });
-            //}
-            #endregion
-
-            btnDelMember = new Button()
+            //鎵�鏈夊満鏅�
+            List<Scene> allSceneList = FunctionList.List.scenes;
+            //鍏ㄥ眬鍦烘櫙鍦烘櫙
+            List<Scene> globalSceneList = new List<Scene>();
+            //鎵惧嚭鎵�鏈夌殑鍏ㄥ眬鍦烘櫙
+            foreach (var mScene in allSceneList)
             {
-                Y = Application.GetRealHeight(617),
-                //Height = MainPage.Increase ? Application.GetRealHeight(70) : Application.GetRealHeight(50),
-                Height = Application.GetRealHeight(50),
-                TextAlignment = TextAlignment.Center,
-                TextSize = CSS_FontSize.SubheadingFontSize,
-                TextColor = CSS_Color.WarningColor,
-                TextID = StringId.RemoveTheMember,
-                BackgroundColor = CSS_Color.MainBackgroundColor,
-            };
-            bodyView.AddChidren(btnDelMember);
 
-            LoadEventList();
+                //roomIds澶т簬0 浠h〃鍒嗛厤鍒版埧闂�
+                mScene.roomIds.Remove(null);
+                if (mScene.roomIds.Count > 0)
+                {
+                    //allocatedList.Add(function);
+                }
+                else
+                {
+                    globalSceneList.Add(mScene);
+                }
+            }
+
+            ////绉婚櫎褰撳墠浣忓畢宸茬粡涓嶅瓨鍦ㄧ殑鍔熻兘
+            //for (int i = 0; i < memberInfo.CurResidenceShareData.Count;)
+            //{
+            //    var sd = memberInfo.CurResidenceShareData[i];
+            //    if (allFunctionList.Find((obj) => obj.deviceId == sd.shareTypeId) == null)
+            //    {
+            //        //new DAL.Server.HttpServerRequest().DeleteShareData(sd);
+            //        //寰呯‘璁ゆ槸鍚﹀悓姝ヤ簯绔垹闄ゅ垎浜�
+            //        memberInfo.CurResidenceShareData.Remove(sd);
+            //    }
+            //    else
+            //    {
+            //        i++;
+            //    }
+            //}
+
+            try
+            {
+                //閬嶅巻鍔犺浇鎴块棿鍒嗕韩涓暟缁熻鐘舵�丷owLayout
+                foreach (var room in SpatialInfo.CurrentSpatial.RoomList)
+                {
+                    AddRoomFunctionRowLayout(room);
+                }
+                //2020-12-16 鍔犺浇鏈垎閰嶅尯鍩熷姛鑳絉owLayout
+                AddNoAreaFunctionRowLayout(unallocatedList, globalSceneList);
+            }
+            catch
+            {
+                Utlis.WriteLine("AddRoomFunctionRowLayout error");
+            }
         }
+
+        /// <summary>
+        /// 娣诲姞鎴块棿鍒嗕韩涓暟缁熻鐘舵�佺殑RowLayout
+        /// </summary>
+        /// <param name="mRoom"></param>
+        void AddRoomFunctionRowLayout(Room mRoom)
+        {
+            ShowBaseRoomFunOrNoAreaFunRowLayout(mRoom, null, null);
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="unallocatedList">鏈垎閰嶇殑鎵�鏈夊姛鑳藉垪琛�</param>
+        /// <param name="globalSceneList">鍏ㄥ尯鍩熺殑鍦烘櫙</param>
+        void AddNoAreaFunctionRowLayout(List<Function> unallocatedList, List<Scene> globalSceneList)
+        {
+            ShowBaseRoomFunOrNoAreaFunRowLayout(null, unallocatedList, globalSceneList);
+        }
+
+        /// <summary>
+        /// 2020-12-17 閲嶆柊璋冩暣
+        /// 娣诲姞鎴块棿鍒嗕韩鎴栬�呮棤鍖哄煙鍒嗛厤 涓暟缁熻鐘舵�佺殑RowLayout
+        /// </summary>
+        /// <param name="room">濡傛灉鎴块棿涓虹┖锛屼唬琛ㄧ鐞嗘棤鍒嗛厤鍖哄煙</param>
+        /// <param name="unallocatedList">绠$悊鏃犲垎閰嶅尯鍩熸墠鏈夋晥</param>
+        /// <param name="globalSceneList">鍏ㄥ眬鍦烘櫙</param>
+        void ShowBaseRoomFunOrNoAreaFunRowLayout(Room mRoom, List<Function> unallocatedList, List<Scene> globalSceneList)
+        {
+            /// 褰撳墠鎴块棿鎴栬�呮棤鍒嗛厤鍖哄煙鍒嗕韩鍒楄〃
+            List<ShareData> funs_RoomAll = new List<ShareData>();
+      
+            /// 鎴块棿鎵�鏈夊姛鑳藉拰鑰呭満鏅垪琛�
+            List<RoomData> roomFunctionOrSceneList = new List<RoomData>();
+
+            /// 鎴块棿ID
+            string roomId = "";
+
+            var roomView = new RowLayout()
+            {
+                Height = Application.GetRealWidth(50),
+                BackgroundColor = CSS_Color.MainBackgroundColor,
+                LineColor = CSS_Color.MainBackgroundColor,
+            };
+            roomListView.AddChidren(roomView);
+
+            var btnRoomName = new Button()
+            {
+                X = Application.GetRealWidth(16),
+                Y = Application.GetRealWidth(4),
+                Width = Application.GetRealWidth(330),
+                Height = Application.GetRealWidth(24),
+                TextAlignment = TextAlignment.CenterLeft,
+                TextColor = CSS_Color.FirstLevelTitleColor,
+                TextSize = CSS_FontSize.TextFontSize,
+                //Text = room.roomName,
+            };
+            roomView.AddChidren(btnRoomName);
+
+           
+
+            var btnFunctionCount = new Button()
+            {
+                X = Application.GetRealWidth(16),
+                Y = btnRoomName.Bottom,
+                Width = Application.GetRealWidth(330),
+                Height = Application.GetRealWidth(18),
+                TextAlignment = TextAlignment.CenterLeft,
+                TextColor = CSS_Color.PromptingColor1,
+                TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
+                //Text = addCount + "/" + room.GetRoomFunctions(false).Count.ToString(),
+            };
+            roomView.AddChidren(btnFunctionCount);
+
+            var btnRight = new Button()
+            {
+                X = Application.GetRealWidth(351),
+                Gravity = Gravity.CenterVertical,
+                Width = Application.GetMinRealAverage(16),
+                Height = Application.GetMinRealAverage(16),
+                UnSelectedImagePath = "Public/Right.png",
+            };
+            roomView.AddChidren(btnRight);
+
+            //濡傛灉鎴块棿涓虹┖锛屼唬琛ㄧ鐞嗘棤鍒嗛厤鍖哄煙
+            if (mRoom != null)
+            {
+                //鏄剧ず鎴块棿鍚�
+                btnRoomName.Text = mRoom.roomName;
+                var mRoomFunctionList = mRoom.GetRoomFunctions(false);
+                var mRoomSceneList = mRoom.GetRoomScenes(true);
+                //閬嶅巻鎵�鏈夊姛鑳藉垪琛�
+                if (mRoomFunctionList != null)
+                {
+                    foreach (var fun in mRoomFunctionList)
+                    {
+                        roomFunctionOrSceneList.Add(new RoomData()
+                        {
+                            shareTypeId = fun.deviceId,
+                            shareType = ShareType.DEVICE.ToString(),
+                            name = fun.name,
+                        });
+                    }
+                }
+
+                //閬嶅巻鎵�鏈夊満鏅垪琛�
+                if (mRoomSceneList != null)
+                {
+                    foreach (var roomScene in mRoomSceneList)
+                    {
+                        roomFunctionOrSceneList.Add(new RoomData()
+                        {
+                            shareTypeId = roomScene.userSceneId,
+                            shareType = ShareType.SCENE.ToString(),
+                            name = roomScene.name,
+                        });
+                    }
+                }
+
+                roomId = mRoom.roomId;
+                //娣诲姞鍒嗗壊绾�
+                var lineView = new LineView(roomView.Height - Application.GetRealHeight(1));
+                roomView.AddChidren(lineView);
+            }
+            else
+            {
+                //鏄剧ず鏃犲尯鍩熷姛鑳�
+                btnRoomName.TextID = StringId.NoAreaFunction;
+                roomId = null;
+
+                //閬嶅巻鎵�鏈夊姛鑳藉垪琛�
+                if (unallocatedList != null)
+                {
+                    foreach (var fun in unallocatedList)
+                    {
+                        roomFunctionOrSceneList.Add(new RoomData()
+                        {
+                            shareTypeId = fun.deviceId,
+                            shareType = ShareType.DEVICE.ToString(),
+                            name = fun.name,
+                        });
+                    }
+                }
+
+                //閬嶅巻鎵�鏈夊満鏅垪琛�
+                if (globalSceneList != null)
+                {
+                    foreach (var roomScene in globalSceneList)
+                    {
+                        roomFunctionOrSceneList.Add(new RoomData()
+                        {
+                            shareTypeId = roomScene.userSceneId,
+                            shareType = ShareType.SCENE.ToString(),
+                            name = roomScene.name,
+                        });
+                    }
+                }
+            }
+
+            //鍒犻櫎鎸夐挳
+            var deleteBtn = new Button()
+            {
+                TextID = StringId.Del,
+                BackgroundColor = CSS_Color.AuxiliaryColor2,
+                TextColor = CSS_Color.MainBackgroundColor,
+                TextSize = CSS_FontSize.TextFontSize,
+            };
+            roomView.AddRightView(deleteBtn);
+            deleteBtn.MouseUpEventHandler = (sender, e) =>
+            {
+                //涓�閿垹闄ゆ墍鏈夊垎浜�
+                DeleteRoomAllShare(funs_RoomAll, roomFunctionOrSceneList, roomId, btnFunctionCount, roomView);
+            };
+
+            //璁$畻宸茬粡鍔犲叆鎴块棿鐨勮澶囨暟閲忕殑Action浜嬩欢
+            Action RefreshAction = () => {
+                funs_RoomAll = new List<ShareData>();
+                int addCount = 0;
+                foreach (var sd in memberInfo.CurResidenceShareData)
+                {
+                    if (roomFunctionOrSceneList.Find((obj) => obj.shareTypeId == sd.shareTypeId) != null)
+                    {
+                        addCount++;
+                        funs_RoomAll.Add(sd);
+                    }
+                }
+                btnFunctionCount.Text = addCount + "/" + roomFunctionOrSceneList.Count.ToString();
+                //Utlis.WriteLine("鍒锋柊鎴愬姛");
+            };
+            //鐐瑰嚮璋冩暣浜嬩欢
+            EventHandler<MouseEventArgs> eHandler = (sender, e) =>
+            {
+                var mmp = new MemberFunctionPermissionPage(memberInfo, roomFunctionOrSceneList, funs_RoomAll, roomId, RefreshAction);
+                MainPage.BasePageView.AddChidren(mmp);
+                mmp.LoadPage(StringId.MemberPermissionManagement);
+                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+            };
+            roomView.MouseUpEventHandler = eHandler;
+            btnRoomName.MouseUpEventHandler = eHandler;
+            btnRight.MouseUpEventHandler = eHandler;
+            btnFunctionCount.MouseUpEventHandler = eHandler;
+
+            RefreshAction?.Invoke();
+        }
+
+
     }
 }

--
Gitblit v1.8.0