黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceManagementForm.cs
@@ -42,10 +42,14 @@
            base.SetTitleText(Common.Config.Instance.Home.Name);
            //主人或者管理员才会出现这个菜单
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
            if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 1 || HdlUserCenterResourse.ResidenceOption.AuthorityNo == 2)
            {
                //初始化右上角菜单
                this.InitTopRightMenu();
                //查看模板时,不允许编辑
                if (Common.Config.Instance.Home.IsShowTemplate == false)
                {
                    //初始化右上角菜单
                    this.InitTopRightMenu();
                }
            }
            //初始化中部信息
            this.InitMiddleFrame(i_CanDeleteResidence);
@@ -87,7 +91,7 @@
            btnNowView.TextColor = UserCenterColor.Current.TextGrayColor1;
            rowHome.frameTable.AddChidren(btnNowView, ChidrenBindMode.BindEvent);
            //主人或者管理员才会出现这个菜单
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
            if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 1 || HdlUserCenterResourse.ResidenceOption.AuthorityNo == 2)
            {
                //右箭头
                rowHome.frameTable.AddRightArrow();
@@ -99,30 +103,22 @@
            btnLocation.Text = Common.Config.Instance.Home.ResidenceAddressName;
            //主人或者管理员才会出现这个菜单
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
            if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 1 || HdlUserCenterResourse.ResidenceOption.AuthorityNo == 2)
            {
                rowHome.frameTable.UseClickStatu = true;
                //查看模板时,不允许编辑
                if (Common.Config.Instance.Home.IsShowTemplate == true)
                {
                    rowHome.frameTable.CanClick = false;
                }
                rowHome.frameTable.ButtonClickEvent += (sender, e) =>
                {
                    //默认值 23.134421,113.267189
                    double latitude = Common.Config.Instance.Home.Latitude;
                    double longitude = Common.Config.Instance.Home.Longitude;
                    //地图
                    GDMapKit.Show((mLatitude, mLongitude, mRadius, name) =>
                    {
                        HdlThreadLogic.Current.RunThread(() =>
                        {
                            //保存住宅地址
                            this.SaveResidenceAdrress(btnLocation, mLatitude, mLongitude, name);
                        });
                    },
                    Language.StringByID(R.MyInternationalizationString.uSelectAdrress),
                    Language.StringByID(R.MyInternationalizationString.uSave),
                    true, latitude, longitude, 100);
                    //检测权限,然后显示地图
                    this.CheckAuthorityAndShowMap(btnLocation);
                };
            }
            if (i_CanDeleteResidence == true)
            if (i_CanDeleteResidence == true && Common.Config.Instance.Home.IsShowTemplate == false)
            {
                //删除
                var btnDelete = new NormalViewControl(Application.GetRealWidth(184), rowHome.Height, false);
@@ -324,8 +320,13 @@
                form.AddForm(keys);
            };
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
            if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 1 || HdlUserCenterResourse.ResidenceOption.AuthorityNo == 2)
            {
                //查看模板时,不允许编辑
                if (Common.Config.Instance.Home.IsShowTemplate == true)
                {
                    return;
                }
                //更改
                var btnChanged = frameRow.AddEditorControl();
                btnChanged.TextID = R.MyInternationalizationString.uChanged1;
@@ -363,6 +364,7 @@
                            //删除当前楼层的话,需要去刷新主页左边的房间列表
                            HdlRoomLogic.Current.RefreshRoomListView();
                        }
                        var uploadRoom = false;
                        var listDeleteId = new List<string>();
                        var listAllRoom = HdlRoomLogic.Current.GetAllListRooms();
                        for (int i = 0; i < listAllRoom.Count; i++)
@@ -370,6 +372,11 @@
                            if (listAllRoom[i].FloorId == keys)
                            {
                                listDeleteId.Add(listAllRoom[i].Id);
                            }
                            if (listAllRoom[i].ListDevice.Count > 0)
                            {
                                //需要上传空间区域
                                uploadRoom = true;
                            }
                        }
                        //删除房间
@@ -404,6 +411,11 @@
                            frameRow.RemoveFromParent();
                            //调整桌布高度
                            this.AdjustContrlTableHeight();
                        }
                        if (uploadRoom == true)
                        {
                            //上传空间区域信息
                            HdlRoomLogic.Current.SetRoomInfoToGateway();
                        }
                        //删除楼层的话,主页需要重新刷新
                        UserView.UserPage.Instance.RefreshAllForm = true;
@@ -460,13 +472,15 @@
                    {
                        keys = Guid.NewGuid().ToString();
                    }
                    bool hadFloor = Common.Config.Instance.Home.CurrentFloorId != string.Empty;
                    Common.Config.Instance.Home.FloorDics[keys] = textValue;
                    Common.Config.Instance.Home.Save();
                    if (Common.Config.Instance.Home.CurrentFloorId == string.Empty)
                    if (hadFloor == false)
                    {
                        //创建第一个新的楼层的话,需要去刷新主页左边的房间列表
                        HdlRoomLogic.Current.RefreshRoomListView();
                    }
                    if (btnFloor != null)
                    {
                        btnFloor.Text = textValue;
@@ -580,7 +594,12 @@
                    btnName.Text = roomName;
                };
            };
            //查看模板时,不允许编辑
            if (Common.Config.Instance.Home.IsShowTemplate == true)
            {
                btnEditor.Text = Language.StringByID(R.MyInternationalizationString.uSearch1);
                return;
            }
            //删除
            var btnDelete = frameRow.AddDeleteControl();
            btnDelete.ButtonClickEvent += (sender, e) =>
@@ -617,6 +636,11 @@
                        //调整桌布高度
                        this.AdjustContrlTableHeight();
                    }
                    if (room.ListDevice.Count > 0)
                    {
                        //上传空间区域信息
                        HdlRoomLogic.Current.SetRoomInfoToGateway();
                    }
                    //删除房间的话,主页需要重新刷新
                    UserView.UserPage.Instance.RefreshAllForm = true;
                });
@@ -635,14 +659,10 @@
            //开启进度条
            this.ShowProgressBar();
            if (Common.Config.Instance.Home.IsOthreShare == false)
            if (Common.Config.Instance.Home.IsOtherShare == false)
            {
                //删除主人自己的住宅
                var Pra = new DeleteResidencePra();
                Pra.HomeId = Common.Config.Instance.Home.Id;
                Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
                bool result = UserCenterLogic.GetResultStatuByRequestHttps("App/DelHome", true, Pra);
                var result = HdlResidenceLogic.Current.DeleteCloundHouse(Common.Config.Instance.Home.Id);
                if (result == false)
                {
                    //关闭进度条
@@ -652,13 +672,8 @@
            }
            else
            {
                //删除分享的住宅
                var Pra2 = new
                {
                    HomeId = Common.Config.Instance.Home.Id,
                    PrimaryUserId = Common.Config.Instance.Home.MainUserDistributedMark
                };
                bool result = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/SubAccountDelShareHome", false, Pra2);
                //删除分享的住宅,使用主人的Token,把自己删了
                var result = HdlMemberLogic.Current.DeleteMember(Common.Config.Instance.Guid);
                if (result == false)
                {
                    //关闭进度条
@@ -668,51 +683,95 @@
            }
            //因为删除的是当前的住宅,所以需要先切换到别的住宅
            string deleteId = Common.Config.Instance.Home.Id;
            string deleteFile = Common.Config.Instance.Home.FileName;
            int index = 0;
            for (; index < Common.Config.Instance.HomeFilePathList.Count; index++)
            var listLocalHouse = HdlResidenceLogic.Current.GetAllLocalResidenceListByDirectory();
            //取一个住宅id
            string houseId = string.Empty;
            foreach (var myHouse in listLocalHouse)
            {
                if (Common.Config.Instance.HomeFilePathList[index] == deleteFile)
                houseId = myHouse.Id;
                if (houseId != Common.Config.Instance.Home.Id)
                {
                    //当前住宅所处的位置(住宅数肯定大于1,不然不会出现删除按钮)
                    if (index == 0)
                    {
                        //取下一位
                        index++;
                    }
                    else
                    {
                        //取前一位
                        index--;
                    }
                    //随便取一个和当前住宅不相等的ID
                    break;
                }
            }
            var myHouse = HdlResidenceLogic.Current.GetHouseByFilePath(Common.Config.Instance.HomeFilePathList[index]);
            //当前住宅ID
            string nowHouseId = Common.Config.Instance.Home.Id;
            //切换住宅
            Common.Config.Instance.HomeId = myHouse.Id;
            Common.Config.Instance.Home = HdlResidenceLogic.Current.GetHouseByHouseId(myHouse.Id);
            Common.Global.CreateHomeDirectory(myHouse.Id);
            Common.Config.Instance.Save();
            //刷新个人中心的内存及线程
            bool result2 = UserCenterLogic.InitUserCenterMenmoryAndThread(false);
            bool result2 = HdlResidenceLogic.Current.SwitchResidence(houseId);
            //删掉这个文件夹
            HdlResidenceLogic.Current.DeleteHouseMemmory(nowHouseId);
            if (result2 == false)
            {
                //开启了调试功能
                return;
            }
            //删除住宅
            HdlResidenceLogic.Current.DeleteHouseMemmory(deleteId);
            HdlThreadLogic.Current.RunMain(() =>
            {
                //关闭界面
                this.CloseForm();
            });
        }
        #endregion
        #region ■ 显示地图___________________________
        /// <summary>
        /// 检测权限,然后显示地图
        /// </summary>
        /// <param name="btnLocation">地址显示控件</param>
        private void CheckAuthorityAndShowMap(NormalViewControl btnLocation)
        {
#if Android
            //申请定位权限
            ((BaseActivity)Application.Activity).SetGPSLocationPermission((result1) =>
            {
                if (result1 == false) { return; }
                //申请允许程序写入外部存储,如SD卡上写文件
                ((BaseActivity)Application.Activity).SetPermission((result2) =>
                {
                    if (result2 == false) { return; }
                     //读取电话状态权限
                     ((BaseActivity)Application.Activity).SetPermission((result3) =>
                     {
                         if (result3 == false) { return; }
                         //显示地图
                         this.ShowMap(btnLocation);
                     }, "android.permission.READ_PHONE_STATE");
                }, "android.permission.WRITE_EXTERNAL_STORAGE");
            });
#endif
#if iOS
            //显示地图
            this.ShowMap(btnLocation);
#endif
        }
        /// <summary>
        /// 显示地图
        /// </summary>
        /// <param name="btnLocation">地址显示控件</param>
        private void ShowMap(NormalViewControl btnLocation)
        {
            //默认值 23.134421,113.267189
            double latitude = Common.Config.Instance.Home.Latitude;
            double longitude = Common.Config.Instance.Home.Longitude;
            //地图
            GDMapKit.Show((mLatitude, mLongitude, mRadius, name) =>
            {
                HdlThreadLogic.Current.RunThread(() =>
                {
                    //保存住宅地址
                    this.SaveResidenceAdrress(btnLocation, mLatitude, mLongitude, name);
                });
            },
            Language.StringByID(R.MyInternationalizationString.uSelectAdrress),
            Language.StringByID(R.MyInternationalizationString.uSave),
            true, latitude, longitude, 100);
        }
        #endregion
@@ -734,48 +793,16 @@
                //开启进度条
                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)
                var result = HdlResidenceLogic.Current.EditorResidenceLongitudeAndLatitude(latitude, longitude, addresName);
                if (result == 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();
            }
            //保存缓存
            Common.Config.Instance.Home.Longitude = longitude;
            Common.Config.Instance.Home.Latitude = latitude;
            Common.Config.Instance.Home.ResidenceAddressName = addresName;
            Common.Config.Instance.Home.Save();
            HdlThreadLogic.Current.RunMain(() =>
            {
                btnLocation.Text = addresName;