xm
2020-04-16 6fa9d69da922c8049f5acfcbb9ce9fd26811024c
ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceManagementForm.cs
@@ -92,7 +92,7 @@
            }
            //经纬度
            var btnLocation = rowHome.frameTable.AddMostRightView(string.Empty, 500);
            btnLocation.Text = this.GetLatitudeAndLongitudeText(Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude);
            btnLocation.Text = Common.Config.Instance.Home.ResidenceAddressName;
            //主人或者管理员才会出现这个菜单
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
@@ -109,9 +109,12 @@
                        HdlThreadLogic.Current.RunThread(() =>
                        {
                            //保存住宅地址
                            this.SaveResidenceAdrress(btnLocation, mLatitude, mLongitude);
                            this.SaveResidenceAdrress(btnLocation, mLatitude, mLongitude, name);
                        });
                    }, Language.StringByID(R.MyInternationalizationString.uSelectAdrress), true, latitude, longitude, 100);
                    },
                    Language.StringByID(R.MyInternationalizationString.uSelectAdrress),
                    Language.StringByID(R.MyInternationalizationString.uSave),
                    true, latitude, longitude, 100);
                };
            }
@@ -189,12 +192,12 @@
                //没有设置过模式
                if (AppResidenceMode == 0)
                {
                    var frame = new TopRightMenuControl(2);
                    var frame = new TopRightMenuControl(2, 2);
                    //创建楼层
                    frame.AddRowMenu(Language.StringByID(R.MyInternationalizationString.uCreatFloor), "Item/CreatFloor.png", "Item/CreatFloorSelected.png", () =>
                    {
                        //创建楼层
                        this.CreatOrEditorFloor(null, string.Empty, string.Empty);
                        this.CreatOrEditorFloor(null, null, string.Empty, string.Empty);
                    });
                    //创建房间
                    frame.AddRowMenu(Language.StringByID(R.MyInternationalizationString.uCreatRoom), "Item/RoomIcon.png", "Item/RoomIconSelected.png", () =>
@@ -212,7 +215,7 @@
                else if (AppResidenceMode == 1)
                {
                    //创建楼层
                    this.CreatOrEditorFloor(null, string.Empty, string.Empty);
                    this.CreatOrEditorFloor(null, null, string.Empty, string.Empty);
                }
                //无楼层模式
                else if (AppResidenceMode == 2)
@@ -266,7 +269,7 @@
        private void InitFloorRow()
        {
            //获取楼层
            var dicFloor = Common.Room.CurrentRoom.GetFloorSortList();
            var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
            this.listFloorSort.Clear();
            foreach (string keys in dicFloor.Keys)
            {
@@ -325,17 +328,12 @@
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
            {
                //更改
                var btnChanged = new NormalViewControl(Application.GetRealWidth(184), frameRow.Height, false);
                btnChanged.BackgroundColor = 0xff4a4a4a;
                btnChanged.TextSize = 12;
                btnChanged.TextColor = UserCenterColor.Current.White;
                btnChanged.TextAlignment = TextAlignment.Center;
                var btnChanged = frameRow.AddEditorControl();
                btnChanged.TextID = R.MyInternationalizationString.uChanged1;
                frameRow.AddRightView(btnChanged);
                btnChanged.ButtonClickEvent += (sender, e) =>
                {
                    //创建或者编辑楼层
                    this.CreatOrEditorFloor(btnFloor, keys, floorName);
                    this.CreatOrEditorFloor(frameRow, btnFloor, keys, floorName);
                };
                //删除
@@ -353,32 +351,42 @@
                    {
                        //移除楼层
                        Common.Config.Instance.Home.FloorDics.Remove(keys);
                        if (Common.Room.CurrentRoom == null)
                        if (Common.Config.Instance.Home.CurrentFloorId == keys)
                        {
                            Common.Room.CurrentRoom = Common.Room.Lists[0];
                        }
                        var listDeleteFile = new List<string>();
                        for (int i = 0; i < Common.Room.Lists.Count; i++)
                        {
                            if (Common.Room.Lists[i].FloorId == keys)
                            //如果删除的是当前楼层的话
                            Common.Config.Instance.Home.CurrentFloorId = string.Empty;
                            foreach (string floorId in Common.Config.Instance.Home.FloorDics.Keys)
                            {
                                listDeleteFile.Add(Common.Room.Lists[i].FileName);
                                //把第一个楼层ID给它
                                Common.Config.Instance.Home.CurrentFloorId = floorId;
                                break;
                            }
                            //删除当前楼层的话,需要去刷新主页左边的房间列表
                            HdlRoomLogic.Current.RefreshRoomListView();
                        }
                        var listDeleteId = new List<string>();
                        var listAllRoom = HdlRoomLogic.Current.GetAllListRooms();
                        for (int i = 0; i < listAllRoom.Count; i++)
                        {
                            if (listAllRoom[i].FloorId == keys)
                            {
                                listDeleteId.Add(listAllRoom[i].Id);
                            }
                        }
                        //删除房间
                        foreach (string fileName in listDeleteFile)
                        {
                            Common.Room.CurrentRoom.Remove(fileName);
                        }
                        //如果当前选择的房间是删除对象的话
                        if (Common.Room.CurrentRoom.FloorId == keys)
                        if (HdlRoomLogic.Current.CurrentRoom.FloorId == keys)
                        {
                            Common.Room.CurrentRoom = Common.Room.Lists[0];
                            HdlRoomLogic.Current.CurrentRoom = HdlRoomLogic.Current.GetLoveRoom();
                        }
                        //删除房间
                        foreach (string roomId in listDeleteId)
                        {
                            HdlRoomLogic.Current.RemoveRoom(roomId);
                        }
                        Common.Config.Instance.Home.Save();
                        //保存顺序
                        listFloorSort.Remove(keys);
                        Common.Room.CurrentRoom.SaveFloorSort(listFloorSort);
                        HdlRoomLogic.Current.SaveFloorSort(listFloorSort);
                        if (Common.Config.Instance.Home.FloorDics.Count == 0)
                        {
@@ -401,7 +409,7 @@
        /// <param name="btnFloor"></param>
        /// <param name="keys"></param>
        /// <param name="floorName"></param>
        private void CreatOrEditorFloor(NormalViewControl btnFloor, string keys, string floorName)
        private void CreatOrEditorFloor(RowLayoutControl frameRow, NormalViewControl btnFloor, string keys, string floorName)
        {
            //生成一个弹窗画面
            var dialogForm = new DialogInputControl();
@@ -414,11 +422,21 @@
            }
            //请输入楼层名称
            dialogForm.SetTipText(Language.StringByID(R.MyInternationalizationString.uPleaseInputFloorName));
            dialogForm.Text = floorName;
            if (Common.Config.Instance.Home.FloorDics.ContainsKey(keys) == true)
            {
                dialogForm.Text = Common.Config.Instance.Home.FloorDics[keys];
                floorName = Common.Config.Instance.Home.FloorDics[keys];
            }
            else
            {
                dialogForm.Text = floorName;
            }
            //按下确认按钮
            dialogForm.ComfirmClickEvent += ((textValue) =>
            {
                //还原左右菜单
                frameRow?.HideMenu();
                if (this.CheckFloorName(keys, textValue) == false)
                {
                    //楼层名称检测
@@ -435,6 +453,12 @@
                    }
                    Common.Config.Instance.Home.FloorDics[keys] = textValue;
                    Common.Config.Instance.Home.Save();
                    if (Common.Config.Instance.Home.CurrentFloorId == string.Empty)
                    {
                        Common.Config.Instance.Home.CurrentFloorId = keys;
                        //创建第一个新的楼层的话,需要去刷新主页左边的房间列表
                        HdlRoomLogic.Current.RefreshRoomListView();
                    }
                    if (btnFloor != null)
                    {
                        btnFloor.Text = textValue;
@@ -487,7 +511,7 @@
        private void InitRoomListRow()
        {
            //获取楼层的房间
            var listRoom = Common.Room.CurrentRoom.GetFloorSortRoom(string.Empty);
            var listRoom = HdlRoomLogic.Current.GetFloorSortRoom(string.Empty);
            this.listRoomSort.Clear();
            for (int i = 0; i < listRoom.Count; i++)
            {
@@ -560,17 +584,18 @@
                //确认删除房间?
                this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uDeleteRoomMsg), () =>
                {
                    if (Common.Room.CurrentRoom.Id == room.Id)
                    if (HdlRoomLogic.Current.CurrentRoom.Id == room.Id)
                    {
                        //如果删除的是当前房间的话
                        Common.Room.CurrentRoom = Common.Room.Lists[0];
                        HdlRoomLogic.Current.CurrentRoom = HdlRoomLogic.Current.GetLoveRoom();
                    }
                    Common.Room.CurrentRoom.Remove(room.FileName);
                    HdlRoomLogic.Current.RemoveRoom(room.Id);
                    //保存顺序
                    this.listRoomSort.Remove(room.Id);
                    Common.Room.CurrentRoom.SaveRoomSort(string.Empty, this.listRoomSort);
                    HdlRoomLogic.Current.SaveRoomSort(string.Empty, this.listRoomSort);
                    if (Common.Room.Lists.Count <= 1)
                    var listAllRoom = HdlRoomLogic.Current.GetAllListRooms();
                    if (listAllRoom.Count <= 1)
                    {
                        //根据指定模式,初始化桌布控件
                        this.InitFrameTableByMode();
@@ -596,16 +621,36 @@
            //开启进度条
            this.ShowProgressBar();
            var Pra = new DeleteResidencePra();
            Pra.HomeId = Common.Config.Instance.Home.Id;
            Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
            bool result = await UserCenterLogic.GetResultStatuByRequestHttps("App/DelHome", true, Pra);
            //关闭进度条
            this.CloseProgressBar();
            if (result == false)
            if (Common.Config.Instance.Home.IsOthreShare == false)
            {
                return;
                //删除主人自己的住宅
                var Pra = new DeleteResidencePra();
                Pra.HomeId = Common.Config.Instance.Home.Id;
                Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
                bool result = await UserCenterLogic.GetResultStatuByRequestHttps("App/DelHome", true, Pra);
                if (result == false)
                {
                    //关闭进度条
                    this.CloseProgressBar();
                    return;
                }
            }
            else
            {
                //删除分享的住宅
                var Pra2 = new
                {
                    HomeId = Common.Config.Instance.Home.Id,
                    PrimaryUserId = Common.Config.Instance.Home.MainUserDistributedMark
                };
                bool result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/SubAccountDelShareHome", false, Pra2);
                if (result == false)
                {
                    //关闭进度条
                    this.CloseProgressBar();
                    return;
                }
            }
            //因为删除的是当前的住宅,所以需要先切换到别的住宅
@@ -636,9 +681,10 @@
            Common.Config.Instance.HomeId = myHouse.Id;
            Common.Global.CreateHomeDirectory(myHouse.Id);
            Common.Config.Instance.Save();
            //刷新个人中心的内存及线程
            await UserCenterLogic.InitUserCenterMenmoryAndThread();
            Common.Room.InitAllRoom();
            await UserCenterLogic.InitUserCenterMenmoryAndThread(false);
            HdlRoomLogic.Current.InitAllRoom();
            //删除住宅
            Common.House.DeleteHouseByHouseId(deleteId);
@@ -660,7 +706,8 @@
        /// <param name="btnLocation">显示控件</param>
        /// <param name="latitude">纬度</param>
        /// <param name="longitude">经度</param>
        private async void SaveResidenceAdrress(NormalViewControl btnLocation, double latitude, double longitude)
        /// <param name="addresName">位置名称</param>
        private async void SaveResidenceAdrress(NormalViewControl btnLocation, double latitude, double longitude, string addresName)
        {
            //开启进度条
            this.ShowProgressBar();
@@ -684,7 +731,13 @@
            var listGateway = HdlGatewayLogic.Current.GetAllLocalGateway();
            foreach (var gateway in listGateway)
            {
                var result = HdlGatewayLogic.Current.SetGatewaySite(gateway, longitude, latitude);
                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)
                {
                    //关闭进度条
@@ -698,10 +751,11 @@
            //保存缓存
            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 = this.GetLatitudeAndLongitudeText(longitude, latitude);
                btnLocation.Text = addresName;
            });
        }
@@ -720,7 +774,7 @@
                //拥有楼层
                return 1;
            }
            if (Common.Room.Lists.Count > 1)
            if (HdlRoomLogic.Current.GetAllListRooms().Count > 1)
            {
                //无楼层模式
                return 2;
@@ -742,7 +796,7 @@
            {
                //请输入住宅名称
                string msg = Language.StringByID(R.MyInternationalizationString.uPleaseInputFloorName);
                this.ShowMassage(ShowMsgType.Error, msg);
                this.ShowMassage(ShowMsgType.Tip, msg);
                return false;
            }
            foreach (string floorKeys in Common.Config.Instance.Home.FloorDics.Keys)
@@ -751,55 +805,11 @@
                {
                    //楼层名称已经存在
                    string msg = Language.StringByID(R.MyInternationalizationString.uFloorNameIsExist);
                    this.ShowMassage(ShowMsgType.Error, msg);
                    this.ShowMassage(ShowMsgType.Tip, msg);
                    return false;
                }
            }
            return true;
        }
        /// <summary>
        /// 获取经纬度的翻译名字
        /// </summary>
        /// <param name="Longitude">经度</param>
        /// <param name="Latitude">纬度</param>
        /// <returns></returns>
        private string GetLatitudeAndLongitudeText(double Longitude, double Latitude)
        {
            string value1 = string.Empty;
            string value2 = string.Empty;
            if (Longitude == 0)
            {
                //默认东经
                value1 = "0°00'E";
            }
            else if (Longitude > 0)
            {
                //东经
                value1 = Math.Round(Longitude, 2).ToString().Replace(".", "°") + "'E";
            }
            else if (Longitude < 0)
            {
                //西经
                value1 = Math.Round(-Longitude, 2).ToString().Replace(".", "°") + "'W";
            }
            if (Latitude == 0)
            {
                //默认北纬
                value2 = "0°00'N";
            }
            else if (Latitude > 0)
            {
                //北纬
                value2 = Math.Round(Latitude, 2).ToString().Replace(".", "°") + "'N";
            }
            else if (Latitude < 0)
            {
                //南纬
                value2 = Math.Round(-Latitude, 2).ToString().Replace(".", "°") + "'S";
            }
            return value1 + " " + value2;
        }
        #endregion