wxr
2021-07-01 adc150efb13a0506f45a3c344c3ee2ef2dba8e90
HDL_ON/UI/UI2/4-PersonalCenter/RoomListManage/FloorsManagementPage.cs
@@ -21,56 +21,24 @@
        /// </summary>
        Button btnFloorTitle;
        /// <summary>
        /// 房间绑定楼层的确定按钮
        /// </summary>
        Button btnConfrim;
        /// <summary>
        /// 当页面是编辑楼层时,该变量为空
        /// 当页面是给房间绑定楼层时,该变量不为空
        /// </summary>
        Room room;
        /// <summary>
        /// 标题栏修改楼层之后的回调事件
        /// </summary>
        Action<string,string> refreshFloorList;
        /// <summary>
        /// 后退回调事件
        /// </summary>
        Action backAction;
        /// <summary>
        /// 最后一次点击的按钮
        /// </summary>
        Button lastButton;
        public FloorsManagementPage()
        {
            bodyView = this;
        }
        /// <summary>
        /// 从房间进入楼层修改界面,需要回调事件更新房间的楼层信息
        /// </summary>
        /// <param name="action"></param>
        public FloorsManagementPage(Action action)
        {
            bodyView = this;
            backAction = action;
        }
        /// <summary>
        /// 加载界面
        /// </summary>
        public void LoadPage(int titleId)
        public void LoadPage()
        {
            bodyView.RemoveAll();
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            refreshFloorList = (type,floorName) => {
                RefreshFloorsListView(type, floorName);
            Action<string> addFloorAction = (floorName) =>
            {
                RefreshFloorsListView(floorName);
            };
            new TopViewDiv(bodyView, Language.StringByID(titleId)).LoadTopView_AddIcon_BackAction("floors",refreshFloorList,backAction);
            new TopViewDiv(bodyView, Language.StringByID(StringId.FloorsManagement)).LoadTopView_FloorTopView(addFloorAction, null);
            int count = Floor.InsFloor.Floors.Count > 8 ? 8 : Floor.InsFloor.Floors.Count;
            int count = SpatialInfo.CurrentSpatial.FloorList.Count > 8 ? 8 : SpatialInfo.CurrentSpatial.FloorList.Count;
            var contentViewHeight = (count + 1) * Application.GetRealHeight(50);
            contentView = new FrameLayout()
@@ -86,8 +54,7 @@
            };
            bodyView.AddChidren(contentView);
             btnFloorTitle = new Button()
            btnFloorTitle = new Button()
            {
                Height = Application.GetRealHeight(50),
                TextID = StringId.Floors,
@@ -110,7 +77,7 @@
            };
            contentView.AddChidren(floorsListView);
            foreach(var floor in Floor.InsFloor.Floors)
            foreach (var floor in SpatialInfo.CurrentSpatial.FloorList)
            {
                LoadFloorRow(floor);
            }
@@ -120,12 +87,12 @@
        /// 加载楼层Row
        /// </summary>
        /// <param name="floor"></param>
        void LoadFloorRow(Floor floor)
        void LoadFloorRow(SpatialInfo floor)
        {
            var row = new RowLayout()
            {
                Height = Application.GetRealHeight(50),
                Tag = floor.roomName,
                Tag = floor.roomId,
                LineColor = CSS_Color.DividingLineColor,
            };
            floorsListView.AddChidren(row);
@@ -138,133 +105,67 @@
                TextColor = CSS_Color.TextualColor,
                SelectedTextColor = CSS_Color.MainColor,
                Text = floor.roomName,
                Tag = floor.uid,
                Tag = floor.roomId,
            };
            row.AddChidren(btnFloor);
            if (room == null)
            var btnDel = new Button()
            {
                var btnDel = new Button()
                {
                    TextID = StringId.Del,
                    BackgroundColor = CSS_Color.WarningColor,
                    TextColor = CSS_Color.MainBackgroundColor,
                    Tag = floor.roomName
                };
                row.AddRightView(btnDel);
                LoadEvent_DelFloor(btnDel);
                LoadEvent_FloorNamgeChange(btnFloor, btnDel, row, floor);
            }
            else
            {
                LoadEvent_FloorChoose(btnFloor);
                if (room.parentId == floor.uid)
                {
                    lastButton = btnFloor;
                    btnFloor.IsSelected = true;
                }
            }
                TextID = StringId.Del,
                BackgroundColor = CSS_Color.WarningColor,
                TextColor = CSS_Color.MainBackgroundColor,
                Tag = floor.roomId
            };
            row.AddRightView(btnDel);
            LoadEvent_DelFloor(btnDel);
            LoadEvent_FloorNamgeChange(btnFloor, floor);
        }
        void RefreshFloorsListView(string changeType,string floorName)
        void RefreshFloorsListView(string floorName)
        {
            switch (changeType)
            try
            {
                case "add":
                var waitPage = new Loading();
                MainPage.BaseView.AddChidren(waitPage);
                waitPage.Start(Language.StringByID(StringId.PleaseWait));
                new System.Threading.Thread(() =>
                {
                    try
                    {
                        var f = new Floor() { roomName = floorName };
                        Floor.InsFloor.AddFloor(f);
                        LoadFloorRow(f);
                    }
                    catch (Exception ex)
                    {
                        MainPage.Log("add floor eroor : " + ex.Message);
                    }
                    break;
                case "edit":
                    for (int i = 0; i < floorsListView.ChildrenCount; i++)
                    {
                        if (floorsListView.GetChildren(i).GetType() == typeof(Button))
                        var f = new SpatialInfo("FLOOR") { roomName = floorName, parentId = DB_ResidenceData.Instance.CurrentRegion.id };
                        var addResult = SpatialInfo.CurrentSpatial.AddFloor(f, out f);
                        if (addResult == DAL.Server.StateCode.SUCCESS)
                        {
                            Button btn = floorsListView.GetChildren(i) as Button;
                            if (floorName == "")
                            Application.RunOnMainThread(() =>
                            {
                                btn.Text = floorName;
                                return;
                            }
                            if (btn.Tag.ToString() == floorName || btn.Tag.ToString() == floorName + "line")
                            {
                                btn.RemoveFromParent();
                            }
                                LoadFloorRow(f);
                                int count2 = SpatialInfo.CurrentSpatial.FloorList.Count > 8 ? 8 : SpatialInfo.CurrentSpatial.FloorList.Count;
                                var contentViewHeight = (count2 + 1) * Application.GetRealHeight(50);
                                contentView.Height = contentViewHeight;
                                floorsListView.Height = count2 * Application.GetRealHeight(50);
                            });
                        }
                    }
                    break;
                case "del":
                    //该楼层删除之后,绑定该楼层的房间要重置绑定的楼层
                    foreach (var r in DB_ResidenceData.Rooms)
                    catch { }
                    finally
                    {
                        if (r.parentId == Floor.InsFloor.Floors.Find((obj) => obj.roomName == floorName).uid)
                        {
                            r.parentId = "";
                        }
                        Application.RunOnMainThread(() => {
                            waitPage.Hide();
                            waitPage.RemoveFromParent();
                        });
                    }
                    for (int i = 0; i < floorsListView.ChildrenCount; i++)
                    {
                        if (floorsListView.GetChildren(i).GetType() == typeof(Button))
                        {
                            Button btn = floorsListView.GetChildren(i) as Button;
                            if (btn.Tag == null)
                                continue;
                            if (btn.Tag.ToString() == floorName + "line")
                            {
                                btn.RemoveFromParent();
                            }
                        }
                        if (floorsListView.GetChildren(i).GetType() == typeof(RowLayout))
                        {
                            RowLayout row = floorsListView.GetChildren(i) as RowLayout;
                            if (row.Tag == null)
                                continue;
                            if (row.Tag.ToString() == floorName)
                            {
                                row.RemoveFromParent();
                            }
                        }
                        Floor.InsFloor.DelFloor(Floor.InsFloor.Floors.Find((obj) => obj.roomName == floorName));
                    }
                    break;
                })
                { IsBackground = true }.Start();
            }
            int count = Floor.InsFloor.Floors.Count > 10 ? 10 : Floor.InsFloor.Floors.Count;
            catch (Exception ex)
            {
                MainPage.Log("add floor eroor : " + ex.Message);
            }
            int count = SpatialInfo.CurrentSpatial.FloorList.Count > 10 ? 10 : SpatialInfo.CurrentSpatial.FloorList.Count;
            floorsListView.Height = Application.GetRealHeight(50 * count);
            contentView.Height = Application.GetRealHeight(50 * (count + 1));
        }
        /// <summary>
        /// 分配给room楼层关系
        /// </summary>
        public void LoadPage(Room r,int titleId)
        {
            room = r;
            LoadPage(titleId);
            btnConfrim = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(582),
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealWidth(44),
                Radius = (uint)Application.GetRealWidth(22),
                BackgroundColor = CSS_Color .MainColor,
                TextColor = CSS_Color.MainBackgroundColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextAlignment = TextAlignment.Center,
                IsBold = true,
                TextID = StringId.Confirm,
            };
            bodyView.AddChidren(btnConfrim);
            LoadEvent_BindFloor();
        }
    }
}