黄学彪
2019-10-24 31497bb69602433d94c8a28ea01c3ee3c7cc8576
ZigbeeApp/Shared/Phone/UserCenter/Gateway/Manage/GatewayListForm.cs
@@ -142,15 +142,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);
            };
            //切换
@@ -177,7 +178,7 @@
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    //执行切换网关操作
                    this.DoSwitchGateway(strWayId, gatewayRow.IsOnline);
                    this.DoSwitchGateway(strWayId);
                });
            };
@@ -219,9 +220,9 @@
            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);
            }
        }
@@ -247,7 +248,7 @@
            {
                //如果解除绑定的网关是当前所选择的网关的话,则关闭设备管理界面
                this.closeDeviceManagForm = true;
                this.SaveGatewayIdToLocation(string.Empty);
                HdlGatewayLogic.Current.SaveGatewayIdToLocation(string.Empty);
            }
            //移除
@@ -267,19 +268,13 @@
        /// </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;
@@ -296,79 +291,6 @@
                //刷新主画面(不重新获取设备状态)
                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)
                {
                    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;
                }
            }
            if (getGatewayInfo == true)
            {
                //获取网关信息
                var info = await HdlGatewayLogic.Current.GetGatewayNewInfoAsync(gateway);
                if (info == null)
                {
                    //关闭进度条
                    this.CloseProgressBar();
                    return 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 +394,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;
@@ -494,7 +416,7 @@
        {
            base.CloseForm();
            if (string.IsNullOrEmpty(GatewayResourse.AppOldSelectGatewayId) == true && this.closeDeviceManagForm == true)
            if (this.closeDeviceManagForm == true)
            {
                //关闭界面
                HdlGatewayLogic.Current.RefreshAppOldSelectGatewayId();
@@ -511,6 +433,12 @@
        /// </summary>
        public override int FormActionAgainEvent()
        {
            //进到这个界面,理论上前回的网关id是有的,如果为空了,应该是当前的网关被解绑了
            if (GatewayResourse.AppOldSelectGatewayId == string.Empty)
            {
                //关闭设备列表
                this.closeDeviceManagForm = true;
            }
            //初始化中部控件
            this.InitMiddleFrame();
            return 1;