xm
2020-07-21 9a4b76398009cf76c508d61f7e48fb6f5cb7ac2d
ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceManagementForm.cs
@@ -14,7 +14,7 @@
        /// <summary>
        /// 桌布控件
        /// </summary>
        private FrameLayout frameTable = null;
        private NormalFrameLayout frameTable = null;
        /// <summary>
        /// 列表控件(白色背景)
        /// </summary>
@@ -23,14 +23,6 @@
        /// 整个界面的上下滑动控件
        /// </summary>
        private VerticalFrameControl listBackContr = null;
        /// <summary>
        /// 楼层顺序
        /// </summary>
        private List<string> listFloorSort = new List<string>();
        /// <summary>
        /// 房间顺序
        /// </summary>
        private List<string> listRoomSort = new List<string>();
        /// <summary>
        /// 当前APP的住宅模式 0:还没有设置有模式 1:楼层模式 2:没有楼层模式
        /// </summary>
@@ -87,13 +79,13 @@
            var btnHomeName = rowHome.frameTable.AddLeftCaption(Common.Config.Instance.Home.Name, 700, 60);
            btnHomeName.TextSize = 15;
            btnHomeName.Y = Application.GetRealHeight(35);
            rowHome.frameTable.AddChidren(btnHomeName, ChidrenBindMode.BindEventOnly);
            rowHome.frameTable.AddChidren(btnHomeName, ChidrenBindMode.BindEvent);
            //当前住宅
            var btnNowView = rowHome.frameTable.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uNowResidence), 700, 49);
            btnNowView.TextSize = 12;
            btnNowView.Y = Application.GetRealHeight(95);
            btnNowView.TextColor = UserCenterColor.Current.TextGrayColor1;
            rowHome.frameTable.AddChidren(btnNowView, ChidrenBindMode.BindEventOnly);
            rowHome.frameTable.AddChidren(btnNowView, ChidrenBindMode.BindEvent);
            //主人或者管理员才会出现这个菜单
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
            {
@@ -102,6 +94,8 @@
            }
            //经纬度
            var btnLocation = rowHome.frameTable.AddMostRightView(string.Empty, 500);
            btnLocation.IsMoreLines = true;
            btnLocation.TextSize = 10;
            btnLocation.Text = Common.Config.Instance.Home.ResidenceAddressName;
            //主人或者管理员才会出现这个菜单
@@ -152,7 +146,7 @@
                };
            }
            //初始化桌布
            this.frameTable = new FrameLayout();
            this.frameTable = new NormalFrameLayout();
            frameTable.Y = rowHome.Bottom + Application.GetRealHeight(23);
            frameTable.Height = listBackContr.frameTable.Height - rowHome.Bottom - Application.GetRealHeight(23);
            listBackContr.frameTable.AddChidren(frameTable);
@@ -280,23 +274,17 @@
        {
            //获取楼层
            var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
            this.listFloorSort.Clear();
            foreach (string keys in dicFloor.Keys)
            {
                listFloorSort.Add(keys);
            }
            if (Common.Config.Instance.Home.FloorDics.Count == 0)
            if (dicFloor.Count == 0)
            {
                return;
            }
            HdlThreadLogic.Current.RunMainInThread(() =>
            {
                int count = listFloorSort.Count - 1;
                for (int i = 0; i < listFloorSort.Count; i++)
                int count = dicFloor.Count;
                foreach (var keys in dicFloor.Keys)
                {
                    string keys = listFloorSort[i];
                    this.AddFloorRow(keys, dicFloor[keys], i != count);
                    count--;
                    this.AddFloorRow(keys, dicFloor[keys], count != 0);
                }
                //调整控件高度
                this.AdjustContrlTableHeight();
@@ -364,11 +352,11 @@
                        Common.Config.Instance.Home.FloorDics.Remove(keys);
                        if (Common.Config.Instance.Home.CurrentFloorId == keys)
                        {
                            //如果删除的是当前楼层的话
                            Common.Config.Instance.Home.CurrentFloorId = string.Empty;
                            foreach (string floorId in Common.Config.Instance.Home.FloorDics.Keys)
                            var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
                            foreach (var floorId in dicFloor.Keys)
                            {
                                //把第一个楼层ID给它
                                //把第一个楼层赋值给当前楼层
                                Common.Config.Instance.Home.CurrentFloorId = floorId;
                                break;
                            }
@@ -384,20 +372,12 @@
                                listDeleteId.Add(listAllRoom[i].Id);
                            }
                        }
                        //如果当前选择的房间是删除对象的话
                        if (HdlRoomLogic.Current.CurrentRoom.FloorId == keys)
                        {
                            HdlRoomLogic.Current.CurrentRoom = HdlRoomLogic.Current.GetLoveRoom();
                        }
                        //删除房间
                        foreach (string roomId in listDeleteId)
                        {
                            HdlRoomLogic.Current.RemoveRoom(roomId);
                        }
                        Common.Config.Instance.Home.Save();
                        //保存顺序
                        listFloorSort.Remove(keys);
                        HdlRoomLogic.Current.SaveFloorSort(listFloorSort);
                        if (Common.Config.Instance.Home.FloorDics.Count == 0)
                        {
@@ -425,6 +405,8 @@
                            //调整桌布高度
                            this.AdjustContrlTableHeight();
                        }
                        //删除楼层的话,主页需要重新刷新
                        UserView.UserPage.Instance.RefreshAllForm = true;
                    });
                };
            }
@@ -482,7 +464,6 @@
                    Common.Config.Instance.Home.Save();
                    if (Common.Config.Instance.Home.CurrentFloorId == string.Empty)
                    {
                        Common.Config.Instance.Home.CurrentFloorId = keys;
                        //创建第一个新的楼层的话,需要去刷新主页左边的房间列表
                        HdlRoomLogic.Current.RefreshRoomListView();
                    }
@@ -495,6 +476,8 @@
                        //根据指定模式,初始化桌布控件
                        this.InitFrameTableByMode();
                    }
                    //创建或者修改楼层的话,主页需要重新刷新
                    UserView.UserPage.Instance.RefreshAllForm = true;
                }
            });
        }
@@ -539,12 +522,6 @@
        {
            //获取楼层的房间
            var listRoom = HdlRoomLogic.Current.GetFloorSortRoom(string.Empty);
            this.listRoomSort.Clear();
            for (int i = 0; i < listRoom.Count; i++)
            {
                this.listRoomSort.Add(listRoom[i].Id);
            }
            for (int i = 0; i < listRoom.Count; i++)
            {
                //添加房间行
@@ -592,7 +569,6 @@
                //如果是分享的房间,不能编辑和修改
                return;
            }
            //编辑
            var btnEditor = frameRow.AddEditorControl();
            btnEditor.ButtonClickEvent += (sender, e) =>
@@ -612,15 +588,7 @@
                //确认删除房间?
                this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uDeleteRoomMsg), () =>
                {
                    if (HdlRoomLogic.Current.CurrentRoom.Id == room.Id)
                    {
                        //如果删除的是当前房间的话
                        HdlRoomLogic.Current.CurrentRoom = HdlRoomLogic.Current.GetLoveRoom();
                    }
                    HdlRoomLogic.Current.RemoveRoom(room.Id);
                    //保存顺序
                    this.listRoomSort.Remove(room.Id);
                    HdlRoomLogic.Current.SaveRoomSort(string.Empty, this.listRoomSort);
                    var listAllRoom = HdlRoomLogic.Current.GetAllListRooms();
                    if (listAllRoom.Count <= 1)
@@ -649,6 +617,8 @@
                        //调整桌布高度
                        this.AdjustContrlTableHeight();
                    }
                    //删除房间的话,主页需要重新刷新
                    UserView.UserPage.Instance.RefreshAllForm = true;
                });
            };
        }
@@ -660,7 +630,7 @@
        /// <summary>
        /// 删除住宅
        /// </summary>
        public async void DeleteResidence()
        private void DeleteResidence()
        {
            //开启进度条
            this.ShowProgressBar();
@@ -672,7 +642,7 @@
                Pra.HomeId = Common.Config.Instance.Home.Id;
                Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
                bool result = await UserCenterLogic.GetResultStatuByRequestHttps("App/DelHome", true, Pra);
                bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/DelHome", true, Pra);
                if (result == false)
                {
                    //关闭进度条
@@ -688,7 +658,7 @@
                    HomeId = Common.Config.Instance.Home.Id,
                    PrimaryUserId = Common.Config.Instance.Home.MainUserDistributedMark
                };
                bool result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/SubAccountDelShareHome", false, Pra2);
                bool result = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/SubAccountDelShareHome", false, Pra2);
                if (result == false)
                {
                    //关闭进度条
@@ -720,18 +690,17 @@
                }
            }
            var myHouse = Common.House.GetHouseByFilePath(Common.Config.Instance.HomeFilePathList[index]);
            var myHouse = HdlResidenceLogic.Current.GetHouseByFilePath(Common.Config.Instance.HomeFilePathList[index]);
            //切换住宅
            Common.Config.Instance.HomeId = myHouse.Id;
            Common.Global.CreateHomeDirectory(myHouse.Id);
            Common.Config.Instance.Save();
            //刷新个人中心的内存及线程
            await UserCenterLogic.InitUserCenterMenmoryAndThread(false);
            HdlRoomLogic.Current.InitAllRoom();
            UserCenterLogic.InitUserCenterMenmoryAndThread(false);
            //删除住宅
            Common.House.DeleteHouseByHouseId(deleteId);
            HdlResidenceLogic.Current.DeleteHouseMemmory(deleteId);
            Application.RunOnMainThread(() =>
            {
@@ -751,47 +720,51 @@
        /// <param name="latitude">纬度</param>
        /// <param name="longitude">经度</param>
        /// <param name="addresName">位置名称</param>
        private async void SaveResidenceAdrress(NormalViewControl btnLocation, double latitude, double longitude, string addresName)
        private void SaveResidenceAdrress(NormalViewControl btnLocation, double latitude, double longitude, string addresName)
        {
            //开启进度条
            this.ShowProgressBar();
            var Pra = new EditorResidencePra();
            Pra.HomeId = Common.Config.Instance.Home.Id;
            Pra.Name = Common.Config.Instance.Home.Name;
            Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
            Pra.Latitude = latitude;
            Pra.Longitude = longitude;
            //编辑住宅
            bool flage = await UserCenterLogic.GetResultStatuByRequestHttps("App/EditHome", true, Pra);
            if (flage == false)
            //如果不是虚拟住宅,才更新云端
            if (Common.Config.Instance.Home.IsVirtually == false)
            {
                //关闭进度条
                this.CloseProgressBar();
                return;
            }
            //设置全部网关的住宅地址
            var listGateway = HdlGatewayLogic.Current.GetAllLocalGateway();
            foreach (var gateway in listGateway)
            {
                ZigBee.Device.ZbGateway realWay = null;
                if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, gateway) == false)
                {
                    //错误:网关对象丢失
                    continue;
                }
                var result = HdlGatewayLogic.Current.SetGatewaySite(gateway, longitude, latitude, ShowErrorMode.YES);
                if (result == false)
                //开启进度条
                this.ShowProgressBar();
                var Pra = new EditorResidencePra();
                Pra.HomeId = Common.Config.Instance.Home.Id;
                Pra.Name = Common.Config.Instance.Home.Name;
                Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
                Pra.Latitude = latitude;
                Pra.Longitude = longitude;
                //编辑住宅
                bool flage = UserCenterLogic.GetResultStatuByRequestHttps("App/EditHome", true, Pra);
                if (flage == false)
                {
                    //关闭进度条
                    this.CloseProgressBar();
                    return;
                }
                //设置全部网关的住宅地址
                var listGateway = HdlGatewayLogic.Current.GetAllLocalGateway();
                foreach (var gateway in listGateway)
                {
                    ZigBee.Device.ZbGateway realWay = null;
                    if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, gateway) == false)
                    {
                        //错误:网关对象丢失
                        continue;
                    }
                    var result = HdlGatewayLogic.Current.SetGatewaySite(gateway, longitude, latitude, ShowErrorMode.YES);
                    if (result == false)
                    {
                        //关闭进度条
                        this.CloseProgressBar();
                        return;
                    }
                }
                //关闭进度条
                this.CloseProgressBar();
            }
            //关闭进度条
            this.CloseProgressBar();
            //保存缓存
            Common.Config.Instance.Home.Longitude = longitude;
            Common.Config.Instance.Home.Latitude = latitude;