gxc
2019-12-25 944b87b6bcccb095cd73f13f4410fb20faf48f74
ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs
@@ -88,19 +88,7 @@
            if (listway.Count == 0)
            {
                //还没有绑定网关哦
                var btnPic = new PicViewControl(683, 392);
                btnPic.UnSelectedImagePath = "Item/NoFunction.png";
                btnPic.Y = (int)(bodyFrameLayout.Height * 0.382) - Application.GetRealHeight(392 / 2);
                btnPic.Gravity = Gravity.CenterHorizontal;
                bodyFrameLayout.AddChidren(btnPic);
                var btnView = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(50), false);
                btnView.Y = btnPic.Bottom + Application.GetRealHeight(32);
                btnView.TextID = R.MyInternationalizationString.uHadNotBindGatewayMsg;
                btnView.TextAlignment = TextAlignment.Center;
                btnView.TextSize = 12;
                btnView.TextColor = UserCenterColor.Current.TextGrayColor1;
                bodyFrameLayout.AddChidren(btnView);
                this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uHadNotBindGatewayMsg));
                return;
            }
@@ -114,8 +102,6 @@
            //调整列表控件的高度
            this.listview.AdjustRealHeight(Application.GetRealHeight(23));
            //设置接受在线状态推送
            this.AddGatewayOnlinePush();
            //开启网关在线监测的线程
            this.StartGatewayOnlieCheckThread(listway);
        }
@@ -142,15 +128,16 @@
            {
                gatewayRow.frameTable.AddBottomLine();
            }
            //提示有新版本
            var btnNew = new RowNewVersionTipView();
            //提示新版本
            var btnNew = new InformationTipView(gatewayRow.btnIcon);
            btnNew.Visible = false;
            gatewayRow.frameTable.AddChidren(btnNew, ChidrenBindMode.BindEventOnly);
            gatewayRow.AddTag("btnNew", btnNew);
            //单击事件
            gatewayRow.frameTable.ButtonClickEvent += (sender, e) =>
            {
                var form = new GatewayInfoEditorForm();
                form.AddForm(gateway);
            };
            //切换
@@ -176,8 +163,11 @@
                }
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    //执行切换网关操作
                    this.DoSwitchGateway(strWayId, gatewayRow.IsOnline);
                    HdlThreadLogic.Current.RunThread(() =>
                    {
                        //执行切换网关操作
                        this.DoSwitchGateway(strWayId);
                    });
                });
            };
@@ -213,16 +203,29 @@
                }
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    this.DeleteGateway(strWayId, gatewayRow);
                    HdlThreadLogic.Current.RunThread(() =>
                    {
                        this.DeleteGateway(strWayId, gatewayRow);
                    });
                });
            };
            this.dicRowContr[strWayId] = gatewayRow;
            //设置一个选择网关的默认值
            if (string.IsNullOrEmpty(GatewayResourse.AppOldSelectGatewayId) == true && gatewayRow.IsOnline == true)
            if (string.IsNullOrEmpty(GatewayResourse.AppOldSelectGatewayId) == true)
            {
                this.SaveGatewayIdToLocation(strWayId);
                HdlGatewayLogic.Current.SaveGatewayIdToLocation(strWayId);
            }
            //当前网关的角标
            //if (strWayId == GatewayResourse.AppOldSelectGatewayId)
            //{
            //    var btnNow = new IconViewControl(52);
            //    btnNow.Y = Application.GetMinReal(23) + gatewayRow.frameTable.chidrenYaxis;
            //    btnNow.UnSelectedImagePath = "Item/NowAcctionTip.png";
            //    btnNow.X = gatewayRow.btnName.X + gatewayRow.btnName.GetRealWidthByText(15);
            //    gatewayRow.frameTable.AddChidren(btnNow, ChidrenBindMode.BindEventOnly);
            //}
        }
        #endregion
@@ -236,8 +239,12 @@
        /// <param name="row"></param>
        private async void DeleteGateway(string strWayId, GatewayRowControl row)
        {
            //打开进度条
            this.ShowProgressBar();
            //删除云端网关
            bool result = await HdlGatewayLogic.Current.DeleteGateway(strWayId);
            //关闭进度条
            this.CloseProgressBar();
            if (result == false)
            {
                return;
@@ -247,15 +254,13 @@
            {
                //如果解除绑定的网关是当前所选择的网关的话,则关闭设备管理界面
                this.closeDeviceManagForm = true;
                this.SaveGatewayIdToLocation(string.Empty);
                HdlGatewayLogic.Current.SaveGatewayIdToLocation(string.Empty);
            }
            //移除
            if (this.dicRowContr.ContainsKey(strWayId) == true)
            HdlThreadLogic.Current.RunMain(() =>
            {
                this.dicRowContr.Remove(strWayId);
            }
            row?.RemoveFromParent();
                //初始化中部控件
                this.InitMiddleFrame();
            });
        }
        #endregion
@@ -267,108 +272,32 @@
        /// </summary>
        /// <param name="gatewayId"></param>
        /// <param name="online"></param>
        private async void DoSwitchGateway(string gatewayId,bool online)
        private async void DoSwitchGateway(string gatewayId)
        {
            if (online == true)
            var result = await HdlGatewayLogic.Current.DoSwitchGateway(gatewayId);
            if (result == false)
            {
                //重新获取在线网关的信息
                var result = await this.GetOnlineGatewayInfo(gatewayId);
                if (result == false)
                {
                    return;
                }
                return;
            }
            //切换网关,保存缓存
            this.SaveGatewayIdToLocation(gatewayId);
            //如果选择了刷新的网关,则不关闭管理界面
            this.closeDeviceManagForm = false;
            if (UserCenterResourse.DicActionForm.ContainsKey("DeviceListMainForm") == false)
            HdlThreadLogic.Current.RunMain(() =>
            {
                //刷新主画面
                var form = new Device.DeviceListMainForm();
                this.AddFromAndRemoveNowForm(form);
            }
            else
            {
                //关闭界面
                this.CloseForm();
                //刷新主画面(不重新获取设备状态)
                this.LoadFormMethodByName("DeviceListMainForm", "InitMiddleFrame", false);
            }
        }
        /// <summary>
        /// 获取在线网关信息
        /// </summary>
        /// <param name="gatewayId"></param>
        /// <returns></returns>
        private async Task<bool> GetOnlineGatewayInfo(string gatewayId)
        {
            //显示进度条
            this.ShowProgressBar();
            //获取网关
            var gateway = HdlGatewayLogic.Current.GetLocalGateway(gatewayId);
            //检测广播到的这个网关是否拥有住宅ID
            ZbGateway realWay = null;
            bool getGatewayInfo = true;
            if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, gatewayId) == true)
            {
                //重新设置住宅ID(这个应该是不经过APP,直接把网关恢复了出厂设置)
                if (HdlGatewayLogic.Current.HomeIdIsEmpty(realWay.getGatewayBaseInfo.HomeId) == true)
                if (UserCenterResourse.DicActionForm.ContainsKey("DeviceListMainForm") == false)
                {
                    int result2 = await HdlGatewayLogic.Current.ReBindNewGateway(realWay);
                    if (result2 == 0)
                    {
                        //出现未知错误,请稍后再试
                        this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uUnKnowErrorAndResetAgain));
                        //关闭进度条
                        this.CloseProgressBar();
                    }
                    else if (result2 == -1)
                    {
                        //关闭进度条
                        this.CloseProgressBar();
                        return false;
                    }
                    //重新绑定网关里面已经重新获取了网关信息
                    getGatewayInfo = false;
                    //刷新主画面
                    var form = new Device.DeviceListMainForm();
                    this.AddFromAndRemoveNowForm(form);
                }
            }
            if (getGatewayInfo == true)
            {
                //获取网关信息
                var info = await HdlGatewayLogic.Current.GetGatewayNewInfoAsync(gateway);
                if (info == null)
                else
                {
                    //关闭进度条
                    this.CloseProgressBar();
                    return false;
                    //关闭界面
                    this.CloseForm();
                    //刷新主画面(不重新获取设备状态)
                    this.LoadFormMethodByName("DeviceListMainForm", "InitMiddleFrame", false);
                }
            }
            //获取全部设备
            bool result = await Common.LocalDevice.Current.SetDeviceToMemmoryByGateway(gateway);
            //关闭进度条
            this.CloseProgressBar();
            if (result == false)
            {
                return false;
            }
            return true;
        }
        /// <summary>
        /// 保存选择的网关ID到本地
        /// </summary>
        /// <param name="gatewayId"></param>
        private void SaveGatewayIdToLocation(string gatewayId)
        {
            GatewayResourse.AppOldSelectGatewayId = gatewayId;
            byte[] data = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(GatewayResourse.AppOldSelectGatewayId));
            Global.WriteFileToDirectoryByBytes(DirNameResourse.LocalMemoryDirectory, DirNameResourse.AppOldSelectGatewayFile, data);
            });
        }
        #endregion
@@ -472,7 +401,7 @@
                    {
                        if (this.dicRowContr.ContainsKey(gwid) == true && this.dicRowContr[gwid] != null)
                        {
                            var btnNew = (RowNewVersionTipView)this.dicRowContr[gwid].GetTagByKey("btnNew");
                            var btnNew = (InformationTipView)this.dicRowContr[gwid].GetTagByKey("btnNew");
                            if (btnNew != null)
                            {
                                btnNew.Visible = true;
@@ -490,11 +419,11 @@
        /// <summary>
        /// 画面关闭
        /// </summary>
        public override void CloseForm()
        public override void CloseFormBefore()
        {
            base.CloseForm();
            base.CloseFormBefore();
            if (string.IsNullOrEmpty(GatewayResourse.AppOldSelectGatewayId) == true && this.closeDeviceManagForm == true)
            if (this.closeDeviceManagForm == true)
            {
                //关闭界面
                HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
@@ -511,6 +440,12 @@
        /// </summary>
        public override int FormActionAgainEvent()
        {
            //进到这个界面,理论上前回的网关id是有的,如果为空了,应该是当前的网关被解绑了
            if (GatewayResourse.AppOldSelectGatewayId == string.Empty)
            {
                //关闭设备列表
                this.closeDeviceManagForm = true;
            }
            //初始化中部控件
            this.InitMiddleFrame();
            return 1;