WJC
2020-04-02 94e4e5b9fd3da964c44b7b14227d6fe2bbb426d7
ZigbeeApp/Shared/Phone/UserCenter/Residence/ResidenceManagementForm.cs
@@ -68,6 +68,7 @@
            rowHome.Height = Application.GetRealHeight(173);
            rowHome.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(rowHome);
            rowHome.frameTable.UseClickStatu = false;
            var btnAdreeIcon = rowHome.frameTable.AddLeftIcon(81);
            btnAdreeIcon.UnSelectedImagePath = "Item/FixedPositionSelected.png";
@@ -83,8 +84,36 @@
            btnNowView.Y = Application.GetRealHeight(95);
            btnNowView.TextColor = UserCenterColor.Current.TextGrayColor1;
            rowHome.frameTable.AddChidren(btnNowView, ChidrenBindMode.BindEventOnly);
            //右箭头
            rowHome.frameTable.AddRightArrow();
            //主人或者管理员才会出现这个菜单
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
            {
                //右箭头
                rowHome.frameTable.AddRightArrow();
            }
            //经纬度
            var btnLocation = rowHome.frameTable.AddMostRightView(string.Empty, 500);
            btnLocation.Text = this.GetLatitudeAndLongitudeText(Common.Config.Instance.Home.Longitude, Common.Config.Instance.Home.Latitude);
            //主人或者管理员才会出现这个菜单
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
            {
                rowHome.frameTable.UseClickStatu = true;
                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);
                        });
                    }, Language.StringByID(R.MyInternationalizationString.uSelectAdrress), true, latitude, longitude, 100);
                };
            }
            if (i_CanDeleteResidence == true)
            {
@@ -160,12 +189,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", () =>
@@ -183,7 +212,7 @@
                else if (AppResidenceMode == 1)
                {
                    //创建楼层
                    this.CreatOrEditorFloor(null, string.Empty, string.Empty);
                    this.CreatOrEditorFloor(null, null, string.Empty, string.Empty);
                }
                //无楼层模式
                else if (AppResidenceMode == 2)
@@ -237,7 +266,7 @@
        private void InitFloorRow()
        {
            //获取楼层
            var dicFloor = Common.Room.CurrentRoom.GetFloorSortList();
            var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
            this.listFloorSort.Clear();
            foreach (string keys in dicFloor.Keys)
            {
@@ -306,7 +335,7 @@
                btnChanged.ButtonClickEvent += (sender, e) =>
                {
                    //创建或者编辑楼层
                    this.CreatOrEditorFloor(btnFloor, keys, floorName);
                    this.CreatOrEditorFloor(frameRow, btnFloor, keys, floorName);
                };
                //删除
@@ -324,32 +353,40 @@
                    {
                        //移除楼层
                        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;
                            }
                        }
                        //删除房间
                        foreach (string fileName in listDeleteFile)
                        var listDeleteId = new List<string>();
                        var listAllRoom = HdlRoomLogic.Current.GetAllListRooms();
                        for (int i = 0; i < listAllRoom.Count; i++)
                        {
                            Common.Room.CurrentRoom.Remove(fileName);
                            if (listAllRoom[i].FloorId == keys)
                            {
                                listDeleteId.Add(listAllRoom[i].Id);
                            }
                        }
                        //如果当前选择的房间是删除对象的话
                        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)
                        {
@@ -372,10 +409,10 @@
        /// <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 DialogInputFrameControl(this, DialogFrameMode.OnlyInput);
            var dialogForm = new DialogInputControl();
            //创建楼层
            dialogForm.SetTitleText(Language.StringByID(R.MyInternationalizationString.uCreatFloor));
            if (keys != string.Empty)
@@ -385,8 +422,15 @@
            }
            //请输入楼层名称
            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) =>
            {
@@ -397,6 +441,8 @@
                }
                //画面关闭
                dialogForm.CloseDialog();
                //还原左右菜单
                frameRow?.HideMenu();
                if (floorName != textValue)
                {
                    //编辑或者创建楼层名称
@@ -406,6 +452,10 @@
                    }
                    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;
                    }
                    if (btnFloor != null)
                    {
                        btnFloor.Text = textValue;
@@ -458,7 +508,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++)
            {
@@ -516,6 +566,8 @@
            var btnEditor = frameRow.AddEditorControl();
            btnEditor.ButtonClickEvent += (sender, e) =>
            {
                //关闭左右菜单
                frameRow.HideMenu();
                var form = new EditorRoomInforForm();
                form.AddForm(room);
                form.FinishEditorEvent += (roomName) =>
@@ -531,17 +583,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();
@@ -572,10 +625,10 @@
            Pra.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
            bool result = await UserCenterLogic.GetResultStatuByRequestHttps("App/DelHome", true, Pra);
            //关闭进度条
            this.CloseProgressBar();
            if (result == false)
            {
                //关闭进度条
                this.CloseProgressBar();
                return;
            }
@@ -607,9 +660,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);
@@ -618,6 +672,67 @@
            {
                //关闭界面
                this.CloseForm();
            });
        }
        #endregion
        #region ■ 保存住宅地图地址___________________
        /// <summary>
        /// 保存住宅地址
        /// </summary>
        /// <param name="btnLocation">显示控件</param>
        /// <param name="latitude">纬度</param>
        /// <param name="longitude">经度</param>
        private async void SaveResidenceAdrress(NormalViewControl btnLocation, double latitude, double longitude)
        {
            //开启进度条
            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)
            {
                //关闭进度条
                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.Save();
            HdlThreadLogic.Current.RunMain(() =>
            {
                btnLocation.Text = this.GetLatitudeAndLongitudeText(longitude, latitude);
            });
        }
@@ -636,7 +751,7 @@
                //拥有楼层
                return 1;
            }
            if (Common.Room.Lists.Count > 1)
            if (HdlRoomLogic.Current.GetAllListRooms().Count > 1)
            {
                //无楼层模式
                return 2;
@@ -674,6 +789,50 @@
            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
        #region ■ 结构体_____________________________