HDL_ON/UI/UI2/4-PersonalCenter/MemberManagement/MemberPermissionPage.cs
@@ -4,11 +4,12 @@
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
    {
@@ -30,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()
            {
@@ -131,6 +132,7 @@
            List<Function> allFunctionList = FunctionList.List.GetDeviceFunctionList();
            //未分配区域的功能
            List<Function> unallocatedList = new List<Function>();
            //
            foreach (var function in allFunctionList)
            {
                function.roomIds.Remove(null);
@@ -145,14 +147,14 @@
            }
            //移除当前住宅已经不存在的功能
            for (int i = 0; i < memberInfo.CurResidenceShareDate.Count;)
            for (int i = 0; i < memberInfo.CurResidenceShareData.Count;)
            {
                var sd = memberInfo.CurResidenceShareDate[i];
                var sd = memberInfo.CurResidenceShareData[i];
                if (allFunctionList.Find((obj) => obj.deviceId == sd.shareTypeId) == null)
                {
                    //new DAL.Server.HttpServerRequest().DeleteShareData(sd);
                    //待确认是否同步云端删除分享
                    memberInfo.CurResidenceShareDate.Remove(sd);
                    memberInfo.CurResidenceShareData.Remove(sd);
                }
                else
                {
@@ -160,118 +162,57 @@
                }
            }
            foreach (var room in SpatialInfo.CurrentSpatial.RoomList)
            try
            {
                var roomView = new RowLayout()
                //遍历加载房间分享个数统计状态RowLayout
                foreach (var room in SpatialInfo.CurrentSpatial.RoomList)
                {
                    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);
                //计算已经加入房间的设备数量
                int addCount = 0;
                foreach (var sd in memberInfo.CurResidenceShareDate)
                {
                    if (room.GetRoomFunctions(false).Find((obj) => obj.deviceId == sd.shareTypeId) != null)
                    {
                        addCount++;
                    }
                    AddRoomFunctionRowLayout(room);
                }
                ////移除当前住宅已经不存在的功能
                //for (int i = 0; i < memberInfo.CurResidenceShareDate.Count;)
                //{
                //    var sd = memberInfo.CurResidenceShareDate[i];
                //    if (allFunctionList.Find((obj) => obj.deviceId == sd.shareTypeId) == 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);
                //分割线
                var lineView = new LineView(roomView.Height - Application.GetRealHeight(1));
                roomView.AddChidren(lineView);
                //删除按钮
                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) =>
                {
                    //删除事件
                };
                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;
                btnFunctionCount.MouseUpEventHandler = eHandler;
                //2020-12-16 加载未分配区域功能RowLayout
                AddNoAreaFunctionRowLayout(unallocatedList);
            }
            //2020-12-16 加载未分配区域功能
            AddNoAreaFunction(unallocatedList);
            catch
            {
                Utlis.WriteLine("AddRoomFunctionRowLayout error");
            }
        }
        /// <summary>
        /// 添加未分配区域功能
        /// 添加房间分享个数统计状态的RowLayout
        /// </summary>
        /// <param name="unallocatedList"></param>
        void AddNoAreaFunction(List<Function> unallocatedList)
        /// <param name="mRoom"></param>
        void AddRoomFunctionRowLayout(Room mRoom)
        {
            ShowBaseRoomFunOrNoAreaFunRowLayout(mRoom, null);
        }
        /// <summary>
        /// 添加未分配区域功能 的个数统计状态的RowLayout
        /// </summary>
        /// <param name="unallocatedList">未分配的所有功能列表</param>
        void AddNoAreaFunctionRowLayout(List<Function> unallocatedList)
        {
            ShowBaseRoomFunOrNoAreaFunRowLayout(null, unallocatedList);
        }
        /// <summary>
        /// 2020-12-17 重新调整
        /// 添加房间分享或者无区域分配 个数统计状态的RowLayout
        /// </summary>
        /// <param name="room">如果房间为空,代表管理无分配区域</param>
        /// <param name="unallocatedList">管理无分配区域才有效</param>
        void ShowBaseRoomFunOrNoAreaFunRowLayout(Room mRoom, List<Function> unallocatedList)
        {
            /// 当前房间或者无分配区域分享列表
            List<ShareData> funs_RoomAll = new List<ShareData>();
            /// <summary>
            /// 房间或者无分配区域所有功能列表
            /// </summary>
            List<Function> roomFunctionList = new List<Function>();
            /// 房间ID
            string roomId = "";
            var roomView = new RowLayout()
            {
                Height = Application.GetRealWidth(50),
@@ -289,33 +230,25 @@
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.TextFontSize,
                TextID = StringId.NoAreaFunction
                //Text = room.roomName,
            };
            roomView.AddChidren(btnRoomName);
            //计算已经加入房间的设备数量
            int addCount = 0;
            foreach (var sd in memberInfo.CurResidenceShareDate)
            //如果房间为空,代表管理无分配区域
            if (mRoom != null)
            {
                if (unallocatedList.Find((obj) => obj.deviceId == sd.shareTypeId) != null)
                {
                    addCount++;
                }
                //显示房间名
                btnRoomName.Text = mRoom.roomName;
                roomFunctionList = mRoom.GetRoomFunctions(false);
                roomId = mRoom.roomId;
            }
            ////移除当前住宅已经不存在的功能
            //for (int i = 0; i < memberInfo.CurResidenceShareDate.Count;)
            //{
            //    var sd = memberInfo.CurResidenceShareDate[i];
            //    if (allFunctionList.Find((obj) => obj.deviceId == sd.shareTypeId) == null)
            //    {
            //        //new DAL.Server.HttpServerRequest().DeleteShareData(sd);
            //        memberInfo.CurResidenceShareDate.Remove(sd);
            //    }
            //    else
            //    {
            //        i++;
            //    }
            //}
            else
            {
                //显示无区域功能
                btnRoomName.TextID = StringId.NoAreaFunction;
                roomFunctionList = unallocatedList;
                roomId = null;
            }
            var btnFunctionCount = new Button()
            {
@@ -326,7 +259,7 @@
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.PromptingColor1,
                TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
                Text = addCount + "/" + unallocatedList.Count.ToString(),
                //Text = addCount + "/" + room.GetRoomFunctions(false).Count.ToString(),
            };
            roomView.AddChidren(btnFunctionCount);
@@ -339,9 +272,9 @@
                UnSelectedImagePath = "Public/Right.png",
            };
            roomView.AddChidren(btnRight);
            ////分割线
            //var lineView = new LineView(roomView.Height - Application.GetRealHeight(1));
            //roomView.AddChidren(lineView);
            //分割线
            var lineView = new LineView(roomView.Height - Application.GetRealHeight(1));
            roomView.AddChidren(lineView);
            //删除按钮
            var deleteBtn = new Button()
            {
@@ -353,25 +286,41 @@
            roomView.AddRightView(deleteBtn);
            deleteBtn.MouseUpEventHandler = (sender, e) =>
            {
                //删除事件
                //一键删除所有分享
                DeleteRoomAllShare(funs_RoomAll, roomFunctionList, roomId, btnFunctionCount, roomView);
            };
            //计算已经加入房间的设备数量的Action事件
            Action RefreshAction = () => {
                funs_RoomAll = new List<ShareData>();
                int addCount = 0;
                foreach (var sd in memberInfo.CurResidenceShareData)
                {
                    if (roomFunctionList.Find((obj) => obj.deviceId == sd.shareTypeId) != null)
                    {
                        addCount++;
                        funs_RoomAll.Add(sd);
                    }
                }
                btnFunctionCount.Text = addCount + "/" + roomFunctionList.Count.ToString();
                //Utlis.WriteLine("刷新成功");
            };
            //点击调整事件
            EventHandler<MouseEventArgs> eHandler = (sender, e) =>
            {
                Action<string> refreshFunctionCount = (newCount) => {
                    btnFunctionCount.Text = newCount + "/" + unallocatedList.Count.ToString();
                };
                //var mmp = new MemberFunctionPermissionPage(memberInfo, room, refreshFunctionCount);
                //MainPage.BasePageView.AddChidren(mmp);
                //mmp.LoadPage(StringId.PermissionToUse);
                //MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                var mmp = new MemberFunctionPermissionPage(memberInfo, roomFunctionList, 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();
        }
    }
}