陈嘉乐
2020-10-13 611786df5108dca0bdcff03834cc285cba4b8e61
HDL_ON/UI/UI2/4-PersonalCenter/ResidentialManage/FloorsManagementPage.cs
@@ -34,17 +34,25 @@
        /// <summary>
        /// 标题栏修改楼层之后的回调事件
        /// </summary>
        Action<string,string> topCallBack;
        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;
@@ -57,11 +65,10 @@
        {
            bodyView.RemoveAll();
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            topCallBack = (type,floor) => {
                ChangeFloorsListView(type, floor);
            refreshFloorList = (type,floorName) => {
                RefreshFloorsListView(type, floorName);
            };
            new TopViewDiv(bodyView, Language.StringByID(StringId.FloorsManagement)).LoadTopView("floors",topCallBack,backAction);
            //new PublicAssmebly().LoadTopView(bodyView, Language.StringByID(StringId.FloorsManagement),"floors",topCallBcak);
            new TopViewDiv(bodyView, Language.StringByID(StringId.FloorsManagement)).LoadTopView("floors",refreshFloorList,backAction);
            int count = DB_ResidenceData.residenceData.floors.Count > 8 ? 8 : DB_ResidenceData.residenceData.floors.Count;
            var contentViewHeight = (count + 1) * Application.GetRealHeight(50);
@@ -89,6 +96,12 @@
                TextColor = CSS_Color.FirstLevelTitleColor,
            };
            contentView.AddChidren(btnFloorTitle);
            contentView.AddChidren(new Button()
            {
                Height = Application.GetRealHeight(1),
                Y = Application.GetRealHeight(49),
                BackgroundColor = CSS_Color.DividingLineColor,
            });
            floorsListView = new VerticalScrolViewLayout()
            {
@@ -107,20 +120,13 @@
        /// 加载楼层Row
        /// </summary>
        /// <param name="floor"></param>
        void LoadFloorRow(string floor)
        void LoadFloorRow(Floor floor)
        {
            floorsListView.AddChidren(
                  new Button()
                  {
                      Height = Application.GetRealHeight(1),
                      BackgroundColor = CSS_Color.DividingLineColor,
                      Tag = floor + "line"
                  });
            var row = new RowLayout()
            {
                Height = Application.GetRealHeight(50),
                Tag = floor
                Tag = floor.name,
                LineColor = CSS_Color.DividingLineColor,
            };
            floorsListView.AddChidren(row);
@@ -131,40 +137,44 @@
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextColor = CSS_Color.TextualColor,
                SelectedTextColor = CSS_Color.MainColor,
                Text = floor,
                Text = floor.name,
                Tag = floor.sid,
            };
            row.AddChidren(btnFloor);
            if (room == null)
            {
                LoadEvent_FloorNamgeChange(floor, btnFloor);
                var btnDel = new Button()
                {
                    TextID = StringId.Del,
                    BackgroundColor = CSS_Color.WarningColor,
                    TextColor = CSS_Color.MainBackgroundColor,
                    Tag = floor
                    Tag = floor.name
                };
                row.AddRightView(btnDel);
                LoadEvent_DelFloor(btnDel);
                LoadEvent_FloorNamgeChange(btnFloor,btnDel,row,floor);
            }
            else {
                LoadEvent_FloorChoose(btnFloor);
                if (room.floorId == floor.sid)
                {
                    lastButton = btnFloor;
                    btnFloor.IsSelected = true;
                }
            }
        }
        void ChangeFloorsListView(string changeType,string floorName)
        void RefreshFloorsListView(string changeType,string floorName)
        {
            int count = DB_ResidenceData.residenceData.floors.Count > 10 ? 10 : DB_ResidenceData.residenceData.floors.Count;
            floorsListView.Height = Application.GetRealHeight(50 * count);
            contentView.Height = Application.GetRealHeight(50 * (count + 1));
            switch (changeType)
            {
                case "add":
                    try
                    {
                        LoadFloorRow(floorName);
                        var f = new Floor() { sid = Guid.NewGuid().ToString(), name = floorName };
                        DB_ResidenceData.residenceData.floors.Add(f);
                        LoadFloorRow(f);
                    }
                    catch (Exception ex)
                    {
@@ -190,16 +200,16 @@
                    }
                    break;
                case "del":
                    //该楼层删除之后,绑定该楼层的房间要重置绑定的楼层
                    foreach (var r in DB_ResidenceData.residenceData.rooms)
                    {
                        if (r.floorId == DB_ResidenceData.residenceData.floors.Find((obj) => obj.name == floorName).sid)
                        {
                            r.floorId = "";
                        }
                    }
                    for (int i = 0; i < floorsListView.ChildrenCount; i++)
                    {
                        //该楼层删除之后,绑定该楼层的房间要重置绑定的楼层
                        foreach (var r in DB_ResidenceData.residenceData.rooms)
                        {
                            if (r.floorIndex == DB_ResidenceData.residenceData.floors.IndexOf(floorName))
                            {
                                r.floorIndex = -1;
                            }
                        }
                        if (floorsListView.GetChildren(i).GetType() == typeof(Button))
                        {
                            Button btn = floorsListView.GetChildren(i) as Button;
@@ -215,14 +225,19 @@
                            RowLayout row = floorsListView.GetChildren(i) as RowLayout;
                            if (row.Tag == null)
                                continue;
                            if (row.Tag.ToString() == floorName )
                            if (row.Tag.ToString() == floorName)
                            {
                                row.RemoveFromParent();
                            }
                        }
                        DB_ResidenceData.residenceData.floors.Remove(DB_ResidenceData.residenceData.floors.Find((obj) => obj.name == floorName));
                    }
                    break;
            }
            DB_ResidenceData.residenceData.SaveResidenceData();
            int count = DB_ResidenceData.residenceData.floors.Count > 10 ? 10 : DB_ResidenceData.residenceData.floors.Count;
            floorsListView.Height = Application.GetRealHeight(50 * count);
            contentView.Height = Application.GetRealHeight(50 * (count + 1));
        }
        /// <summary>