黄学彪
2019-10-18 97e259d966cb5cb5d73c105d5dbaadcc1f920614
ZigbeeApp/Shared/Phone/UserCenter/Gateway/Add/WiredGatewaySearchForm.cs
@@ -14,29 +14,21 @@
        #region ■ 变量声明___________________________
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalScrolViewLayout listView = null;
        /// <summary>
        /// 这是个透明的控件
        /// </summary>
        private FrameLayout frameTransparent = null;
        /// <summary>
        /// 线程执行中
        /// </summary>
        private bool IsThreadAction = true;
        /// <summary>
        /// 搜索时间
        /// </summary>
        private int searchTime = 60;
        /// <summary>
        /// 停止搜索的按键
        /// </summary>
        private BottomClickButton btnStop = null;
        /// <summary>
        /// 网关的主键(value:剩余检测次数,用于对应异常的网关)
        /// </summary>
        private Dictionary<string, int> dicGatewayId = new Dictionary<string, int>();
        private Dictionary<string, int> dicIdCheckCount = new Dictionary<string, int>();
        /// <summary>
        /// 搜索到的网关列表
        /// </summary>
        private List<ZbGateway> listZbGateway = new List<ZbGateway>();
        /// <summary>
        /// 搜索到的网关类别  0:第一次绑定 1:已经绑定 2:需要换绑
        /// </summary>
        private Dictionary<string, int> dicZbGatewayDiv = new Dictionary<string, int>();
        /// <summary>
        /// 获取得到了新网关
        /// </summary>
        private bool newGatewayGetting = false;
        #endregion
@@ -50,142 +42,237 @@
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddWiredGateway));
            //初始化中部控件
            this.InitMiddleFrame();
            //开启线程
            this.StartThread();
            //初始化初始中部控件
            this.InitDefultMiddleFrame();
        }
        /// <summary>
        /// 初始化中部控件
        /// 初始化初始中部控件
        /// </summary>
        private void InitMiddleFrame()
        private void InitDefultMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
            //网关列表,这个控件置于背部
            listView = new VerticalScrolViewLayout();
            listView.Height = ControlCommonResourse.ListViewRowHeight * 5;
            bodyFrameLayout.AddChidren(listView);
            //图标
            var picGwImage = new FrameLayout();
            picGwImage.Width = Application.GetMinRealAverage(861);
            picGwImage.Height = Application.GetMinRealAverage(478);
            picGwImage.Y = Application.GetRealWidth(251);
            picGwImage.Gravity = Gravity.CenterHorizontal;
            picGwImage.BackgroundImagePath = "Gateway/WiredGatewaySearching.png";
            bodyFrameLayout.AddChidren(picGwImage);
            //图片,背景要透明
            frameTransparent = new FrameLayout
            //正在搜索网关…
            var btnMsg = new NormalViewControl(bodyFrameLayout.Width, false);
            btnMsg.TextID = R.MyInternationalizationString.uGatewaySearching;
            btnMsg.Y = Application.GetRealHeight(1008);
            btnMsg.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnMsg.TextAlignment = TextAlignment.Center;
            bodyFrameLayout.AddChidren(btnMsg);
            //初始化连接的假想动画效果
            this.InitConcetionAnimete(picGwImage, btnMsg);
        }
        /// <summary>
        /// 初始化失败模式的中部控件
        /// </summary>
        private void InitFailMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
            //图标
            var picGwImage = new FrameLayout();
            picGwImage.Width = Application.GetMinRealAverage(861);
            picGwImage.Height = Application.GetMinRealAverage(478);
            picGwImage.Y = Application.GetRealWidth(158);
            picGwImage.Gravity = Gravity.CenterHorizontal;
            picGwImage.BackgroundImagePath = "Gateway/WiredGatewaySearching.png";
            bodyFrameLayout.AddChidren(picGwImage);
            var btnFailIcon = new PicViewControl(66, 66);
            btnFailIcon.UnSelectedImagePath = "Item/FailIcon.png";
            btnFailIcon.Gravity = Gravity.CenterHorizontal;
            btnFailIcon.Y = Application.GetMinRealAverage(181);
            picGwImage.AddChidren(btnFailIcon);
            //搜索失败
            var btnFailView = new NormalViewControl(300, 60, true);
            btnFailView.TextAlignment = TextAlignment.Center;
            btnFailView.Y = Application.GetMinRealAverage(305);
            btnFailView.Gravity = Gravity.CenterHorizontal;
            btnFailView.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnFailView.TextID = R.MyInternationalizationString.uSearchFail;
            picGwImage.AddChidren(btnFailView);
            //解决方法,可选择执行以下任意一种方式:
            var btnMsg1 = new NormalViewControl(930, 60, true);
            btnMsg1.X = Application.GetRealWidth(75);
            btnMsg1.Y = picGwImage.Bottom + Application.GetRealHeight(112);
            btnMsg1.TextID = R.MyInternationalizationString.uSearchGatewayFailMsg1;
            bodyFrameLayout.AddChidren(btnMsg1);
            //1.长按ZB/RST键20秒,网关恢复出厂设置,指示灯全部熄{0}灭后,重新入网。
            var btnMsg2 = new NormalViewControl(930, 100, true);
            btnMsg2.X = Application.GetRealWidth(75);
            btnMsg2.Y = btnMsg1.Bottom + Application.GetRealHeight(35);
            btnMsg2.Text = Language.StringByID(R.MyInternationalizationString.uSearchGatewayFailMsg2).Replace("{0}", "\r\n");
            btnMsg2.TextSize = 12;
            btnMsg2.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnMsg2.IsMoreLines = true;
            bodyFrameLayout.AddChidren(btnMsg2);
            //2.点按HID/WCFG键,进入网关换绑模式,系统指示灯快闪{0}5秒。
            var btnMsg3 = new NormalViewControl(930, 100, true);
            btnMsg3.X = Application.GetRealWidth(75);
            btnMsg3.Y = btnMsg2.Bottom + Application.GetRealHeight(12);
            btnMsg3.Text = Language.StringByID(R.MyInternationalizationString.uSearchGatewayFailMsg3).Replace("{0}", "\r\n");
            btnMsg3.TextSize = 12;
            btnMsg3.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnMsg3.IsMoreLines = true;
            bodyFrameLayout.AddChidren(btnMsg3);
            //3.请重试,重新添加网关。
            var btnMsg4 = new NormalViewControl(930, 50, true);
            btnMsg4.X = Application.GetRealWidth(75);
            btnMsg4.Y = btnMsg3.Bottom + Application.GetRealHeight(12);
            btnMsg4.Text = Language.StringByID(R.MyInternationalizationString.uSearchGatewayFailMsg4);
            btnMsg4.TextSize = 12;
            btnMsg4.TextColor = UserCenterColor.Current.TextGrayColor1;
            bodyFrameLayout.AddChidren(btnMsg4);
            //4.返回网关管理。
            var btnMsg5 = new NormalViewControl(930, 50, true);
            btnMsg5.X = Application.GetRealWidth(75);
            btnMsg5.Y = btnMsg4.Bottom + Application.GetRealHeight(12);
            btnMsg5.Text = Language.StringByID(R.MyInternationalizationString.uSearchGatewayFailMsg5);
            btnMsg5.TextSize = 12;
            btnMsg5.TextColor = UserCenterColor.Current.TextGrayColor1;
            bodyFrameLayout.AddChidren(btnMsg5);
            //重试
            var frameback = new FrameLayoutControl();
            frameback.UseClickStatu = false;
            frameback.Y = Application.GetRealHeight(1259);
            frameback.Gravity = Gravity.CenterHorizontal;
            frameback.Width = Application.GetRealWidth(746);
            frameback.Height = Application.GetRealHeight(184);
            frameback.BackgroundImagePath = "Item/BottomButtonGround.png";
            bodyFrameLayout.AddChidren(frameback);
            var btnReDo = new NormalViewControl(300, 65, true);
            btnReDo.TextColor = UserCenterColor.Current.White;
            btnReDo.TextSize = 16;
            btnReDo.Y = Application.GetRealHeight(49);
            btnReDo.Gravity = Gravity.CenterHorizontal;
            btnReDo.TextAlignment = TextAlignment.Center;
            btnReDo.TextID = R.MyInternationalizationString.uReDoAgain;
            frameback.AddChidren(btnReDo, ChidrenBindMode.BindEventOnly);
            frameback.ButtonClickEvent += (sender, e) =>
            {
                Width = bodyFrameLayout.Width,
                Height = bodyFrameLayout.Height,
                Gravity = Gravity.CenterHorizontal,
                BackgroundColor = UserCenterColor.Current.Transparent
                //初始化初始中部控件
                this.InitDefultMiddleFrame();
            };
            bodyFrameLayout.AddChidren(frameTransparent);
            //图片
            var btnimage = new PicViewControl(620, 620);
            btnimage.Y = ControlCommonResourse.ListViewRowHeight * 2;
            btnimage.Gravity = Gravity.CenterHorizontal;
            btnimage.UnSelectedImagePath = "Gateway/SearchGateway.png";
            frameTransparent.AddChidren(btnimage);
            //智能网关配置网络中
            var btnText1 = new NormalViewControl(bodyFrameLayout.Width, false);
            btnText1.Y = btnimage.Bottom + Application.GetRealHeight(60);
            btnText1.Gravity = Gravity.CenterHorizontal;
            btnText1.TextID = R.MyInternationalizationString.uGatewaySetting;
            frameTransparent.AddChidren(btnText1);
            //请稍候
            var btnText2 = new NormalViewControl(bodyFrameLayout.Width, false);
            btnText2.Y = btnText1.Bottom + Application.GetRealHeight(30);
            btnText2.Gravity = Gravity.CenterHorizontal;
            btnText2.TextID = R.MyInternationalizationString.uPleaseWait;
            frameTransparent.AddChidren(btnText2);
            //停止搜索
            btnStop = new BottomClickButton();
            btnStop.TextID = R.MyInternationalizationString.uStopSearch;
            frameTransparent.AddChidren(btnStop);
            btnStop.MouseUpEventHandler += this.btnStop_MouseClick;
            //返回网关管理
            var btnGoBack = new BottomClickButton(688);
            btnGoBack.Y = Application.GetRealHeight(1495);
            btnGoBack.TextID = R.MyInternationalizationString.uGobackGatewayManage;
            bodyFrameLayout.AddChidren(btnGoBack);
            btnGoBack.ButtonClickEvent += (sender, e) =>
            {
                this.CloseForm();
                //关闭指定界面
                this.CloseFormByFormName("NewGateWayMenuSelectForm");
            };
        }
        #endregion
        #region ■ 开启线程___________________________
        #region ■ 假想动画(网关检测)_________________
        /// <summary>
        /// 开启搜索网关的子线程
        /// 初始化连接的假想动画效果
        /// </summary>
        private void StartThread()
        private void InitConcetionAnimete(FrameLayout picGwImage, NormalViewControl btnMsg)
        {
            string textValue = btnStop.Text;
            //清空保存的主键
            this.dicGatewayId.Clear();
            //线程运行中
            this.IsThreadAction = true;
            //首格的X轴
            int firstPoint = Application.GetMinRealAverage(288);
            //一格的宽度
            int width = Application.GetMinRealAverage(22);
            //间距大小
            int space = Application.GetMinRealAverage(12);
            //清空全部列表
            HdlGatewayLogic.Current.ClearAllRealGateway();
            ZigBee.Common.Application.IsSearchingGateway = true;
            //生成格子坐标
            var listPoint = new List<int>();
            for (int i = 0; i < 9; i++)
            {
                listPoint.Add(firstPoint + (width + space) * i);
            }
            //开启倒计时线程
            this.StartTimeCountThread(textValue);
            //开启连接的假想动画效果线程
            var btnRound = new PicViewControl(width, width, false);
            btnRound.Radius = (uint)width / 2;
            btnRound.BackgroundColor = UserCenterColor.Current.ConcetionRoundColor;
            btnRound.Y = Application.GetMinRealAverage(202);
            btnRound.X = listPoint[0];
            picGwImage.AddChidren(btnRound);
            string strMsg = btnMsg.Text;
            HdlThreadLogic.Current.RunThread(async () =>
            {
                while (this.IsThreadAction)
                //清空全部列表
                HdlGatewayLogic.Current.ClearAllRealGateway();
                ZigBee.Common.Application.IsSearchingGateway = true;
                int index = 1;
                int maxCount = 120 * 2;
                int timeCount = 120;
                while (picGwImage.Parent != null)
                {
                    await Task.Delay(2500);
                    //异步网关检测中(先等个5秒,然后等mqtt连接)
                    if (this.searchTime > 55)
                    System.Threading.Thread.Sleep(500);
                    maxCount--;
                    if (maxCount % 4 == 0)
                    {
                        continue;
                        //每2秒检测搜索到的网关
                        await this.CheckZbGatewayAndSetRow();
                    }
                    //检测搜索到的网关,然后添加到画面的行里面
                    await this.CheckZbGatewayAndSetRow();
                }
            });
        }
        /// <summary>
        /// 开启倒计时线程
        /// </summary>
        /// <param name="textValue"></param>
        private void StartTimeCountThread(string textValue)
        {
            //搜索时间
            this.searchTime = 60;
            HdlThreadLogic.Current.RunThread(() =>
            {
                while (this.IsThreadAction)
                {
                    System.Threading.Thread.Sleep(1000);
                    this.searchTime--;
                    if (this.searchTime == 0 || this.IsThreadAction == false)
                    if (this.newGatewayGetting == true)
                    {
                        //时间截止
                        this.btnStop_MouseClick(null, null);
                        //获取得到新网关,则中断线程
                        break;
                    }
                    if (maxCount % 2 == 0)
                    {
                        timeCount--;
                    }
                    if (maxCount <= 0)
                    {
                        break;
                    }
                    Application.RunOnMainThread(() =>
                    {
                        if (btnStop != null)
                        btnRound.X = listPoint[index];
                        index++;
                        if (index == listPoint.Count)
                        {
                            //倒计时显示
                            btnStop.Text = textValue + "(" + searchTime + ")";
                            index = 0;
                        }
                        //正在搜索网关…XXs
                        btnMsg.Text = strMsg + timeCount + "s";
                    });
                }
                Application.RunOnMainThread(() =>
                if (maxCount <= 0)
                {
                    if (btnStop != null)
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        btnStop.Text = textValue;
                    }
                });
                        //初始化失败模式的中部控件
                        this.InitFailMiddleFrame();
                    });
                }
                else
                {
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        var form = new WiredGatewayListForm();
                        this.AddFromAndRemoveNowForm(form, listZbGateway, dicZbGatewayDiv);
                    });
                }
            });
        }
@@ -209,16 +296,16 @@
                }
                string gwId = HdlGatewayLogic.Current.GetGatewayId(ZbGateway.GateWayList[i]);
                //重复添加检测
                if (this.dicGatewayId.ContainsKey(gwId) == false)
                if (this.dicIdCheckCount.ContainsKey(gwId) == false)
                {
                    //允许五次检测
                    this.dicGatewayId[gwId] = 5;
                    this.dicIdCheckCount[gwId] = 5;
                    listId.Add(gwId);
                }
                else if (this.dicGatewayId[gwId] > 0)
                else if (this.dicIdCheckCount[gwId] > 0)
                {
                    //如果前一次检测失败了的话,它的次数-1
                    this.dicGatewayId[gwId] = this.dicGatewayId[gwId] - 1;
                    this.dicIdCheckCount[gwId] = this.dicIdCheckCount[gwId] - 1;
                    listId.Add(gwId);
                }
            }
@@ -234,145 +321,58 @@
                {
                    continue;
                }
                //收集网关对象
                this.listZbGateway.Add(way);
                //网关绑定模式
                GatewayBindMode mode = GatewayBindMode.BindAgain;
                if (way.getGatewayBaseInfo.HomeId == Common.Config.Instance.HomeId)
                {
                    //已经绑定过了
                    mode = GatewayBindMode.Binded;
                }
                else if (HdlGatewayLogic.Current.HomeIdIsEmpty(way) == true)
                if (HdlGatewayLogic.Current.HomeIdIsEmpty(way) == true)
                {
                    //第一次绑定,也就是网关住宅ID为空
                    mode = GatewayBindMode.First;
                    this.dicZbGatewayDiv[listId[i]] = 0;
                    //获取到了新网关
                    this.newGatewayGetting = true;
                }
                else if (way.getGatewayBaseInfo.HomeId == Common.Config.Instance.HomeId)
                {
                    //已经绑定过了
                    this.dicZbGatewayDiv[listId[i]] = 1;
                    mode = GatewayBindMode.Binded;
                }
                else
                {
                    //需要换绑
                    this.dicZbGatewayDiv[listId[i]] = 2;
                    mode = GatewayBindMode.BindAgain;
                }
                //本地是否有这个网关
                bool isExist = HdlGatewayLogic.Current.IsGatewayExist(way);
                //如果
                if (mode != GatewayBindMode.BindAgain)
                {
                    //添加搜索到的网关到缓存(执行网关保存操作)
                    ShowErrorMode showMode = this.dicGatewayId[listId[i]] == 0 ? ShowErrorMode.YES : ShowErrorMode.NO;
                    var result = await this.DoSaveGateway(way, showMode, mode);
                    ShowErrorMode showMode = this.dicIdCheckCount[listId[i]] == 0 ? ShowErrorMode.YES : ShowErrorMode.NO;
                    var result = await this.DoSaveGateway(way, showMode);
                    if (result == false)
                    {
                        //当使用完次数之后,并且本地不存在的,才显示出来
                        if (this.dicGatewayId[listId[i]] == 0 && isExist == false)
                        {
                            Application.RunOnMainThread(() =>
                            {
                                //添加失败的网关到画面
                                this.AddFailRowLayout(way);
                            });
                        }
                        continue;
                    }
                }
                //如果它已经完全成功了的话,则将它的剩余次数置零
                this.dicGatewayId[listId[i]] = 0;
                this.dicIdCheckCount[listId[i]] = 0;
                if (isExist == true)
                {
                    //已经绑定过了的,则不再显示
                    continue;
                }
                if (mode != GatewayBindMode.BindAgain)
                {
                    //我觉得这里需要获取一下新网关的设备列表
                    await Common.LocalDevice.Current.SetDeviceToMemmoryByGateway(way);
                }
                Application.RunOnMainThread(() =>
                {
                    if (this.Parent != null)
                    {
                        //添加搜索到的网关到画面
                        this.AddRowLayout(way, mode);
                    }
                });
            }
            return true;
        }
        #endregion
        #region ■ 添加网关行控件_____________________
        /// <summary>
        /// 添加搜索到的网关到画面
        /// </summary>
        /// <param name="zbGateway">Zb gateway.</param>
        /// <param name="mode">网关绑定模式</param>
        private void AddRowLayout(ZbGateway zbGateway, GatewayBindMode mode)
        {
            if (listView == null)
            {
                return;
            }
            //网关列表控件
            var gatewayRow = new GatewayRowControl(zbGateway);
            listView.AddChidren(gatewayRow);
            gatewayRow.InitControl(69);
            //不需要在线控件
            gatewayRow.btnOnline.RemoveFromParent();
            gatewayRow.btnOnline = null;
            gatewayRow.frameTable.ButtonClickEvent += (sender, e) =>
            {
                //打开网关编辑界面
                this.OpenEditorGatewayForm(gatewayRow, mode);
            };
            //向右图标
            gatewayRow.frameTable.AddRightArrow();
            //绑定
            var btnBind = gatewayRow.frameTable.AddMostRightView("", 300);
            if (mode != GatewayBindMode.BindAgain)
            {
                //已绑定
                btnBind.TextID = R.MyInternationalizationString.uBinded;
                btnBind.TextColor = UserCenterColor.Current.Green;
            }
            else
            {
                //需重新绑定
                btnBind.TextID = R.MyInternationalizationString.uNeedReBinding;
                btnBind.TextColor = UserCenterColor.Current.Red;
                //这里只是临时追加,后面可以会移动到别的地方
                var btnConfirm = new NormalViewControl(Application.GetRealWidth(184), gatewayRow.Height, false);
                btnConfirm.Text = "网关识别";
                gatewayRow.AddRightView(btnConfirm);
                btnConfirm.MouseUpEventHandler += (sender, e) =>
                {
                    HdlGatewayLogic.Current.SetTestCommand(zbGateway);
                };
            }
            gatewayRow.AddTag("btnBind", btnBind);
        }
        /// <summary>
        /// 添加搜索到的网关到画面的行
        /// </summary>
        /// <param name="zbGateway">Zb gateway.</param>
        private void AddFailRowLayout(ZbGateway zbGateway)
        {
            if (listView == null)
            {
                return;
            }
            //网关列表控件
            var gatewayRow = new GatewayRowControl(zbGateway);
            listView.AddChidren(gatewayRow);
            gatewayRow.InitControl(69);
            //不需要在线控件
            gatewayRow.btnOnline.RemoveFromParent();
            gatewayRow.btnOnline = null;
            //智能跳过
            var btnBind = gatewayRow.frameTable.AddMostRightView("", 300);
            btnBind.TextID = R.MyInternationalizationString.uIntelligentSkip;
            btnBind.TextColor = UserCenterColor.Current.Red;
        }
        #endregion
@@ -384,21 +384,12 @@
        /// </summary>
        /// <param name="zbGateway">网关对象</param>
        /// <param name="mode">是否显示错误</param>
        /// <param name="bindMode">绑定方式</param>
        /// <returns></returns>
        private async Task<bool> DoSaveGateway(ZbGateway zbGateway, ShowErrorMode mode, GatewayBindMode bindMode)
        private async Task<bool> DoSaveGateway(ZbGateway zbGateway, ShowErrorMode mode)
        {
            //添加搜索到的网关到缓存
            //1:正常  -1:异常  0:当前的网关绑定在了当前账号下的不同住宅里面
            int result = 0;
            if (bindMode == GatewayBindMode.BindAgain)
            {
                result = await HdlGatewayLogic.Current.ReBindNewGateway(zbGateway);
            }
            else
            {
                result = await HdlGatewayLogic.Current.AddNewGateway(zbGateway, mode);
            }
            int result = await HdlGatewayLogic.Current.AddNewGateway(zbGateway, mode);
            if (result == -1)
            {
                return false;
@@ -424,121 +415,6 @@
        #endregion
        #region ■ 打开编辑界面_______________________
        /// <summary>
        /// 打开网关编辑界面
        /// </summary>
        /// <param name="viewRow"></param>
        /// <param name="mode"></param>
        private void OpenEditorGatewayForm(GatewayRowControl viewRow, GatewayBindMode mode)
        {
            //已经绑定了,就不用再显示提示
            if (mode == GatewayBindMode.BindAgain && viewRow.GetTagByKey("btnBind") != null)
            {
                //是否重新绑定网关?
                string msg = Language.StringByID(R.MyInternationalizationString.uRebindGatewayMsg);
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    this.ShowConfirmMsgBeforShowForm(viewRow);
                });
            }
            else
            {
                //打开网关名称编辑画面
                var form = new GatewayInfoAddForm();
                form.AddForm(viewRow.zbGateway);
                form.ActionGatewayReName += ((way) =>
                {
                    viewRow.RefreshControl(way);
                });
            }
        }
        /// <summary>
        /// 在打开编辑画面之前,弹出确认窗口(重新绑定专用)
        /// </summary>
        /// <param name="viewRow"></param>
        private async void ShowConfirmMsgBeforShowForm(GatewayRowControl viewRow)
        {
            var realway = ZbGateway.GateWayList.Find((obj) =>
             HdlGatewayLogic.Current.GetGatewayId(obj) == HdlGatewayLogic.Current.GetGatewayId(viewRow.zbGateway));
            //显示进度条
            this.ShowProgressBar();
            var result = await this.DoSaveGateway(realway, ShowErrorMode.YES, GatewayBindMode.BindAgain);
            if (result == false)
            {
                //关闭进度条
                this.CloseProgressBar();
                return;
            }
            //获取设备列表中,请稍后
            this.SetProgressValue(Language.StringByID(R.MyInternationalizationString.uDeviceIsGettingPleaseWait));
            //我觉得这里需要获取一下新网关的设备列表
            result = await Common.LocalDevice.Current.SetDeviceToMemmoryByGateway(realway);
            //关闭进度条
            this.CloseProgressBar();
            Application.RunOnMainThread(() =>
            {
                //已绑定
                var btnBind = (NormalViewControl)viewRow.GetTagByKey("btnBind");
                btnBind.TextID = R.MyInternationalizationString.uBinded;
                btnBind.TextColor = UserCenterColor.Current.Green;
                viewRow.RemoveTag("btnBind");
                //打开网关名称编辑画面
                var form = new GatewayInfoAddForm();
                form.AddForm(viewRow.zbGateway);
                form.ActionGatewayReName += ((way) =>
                {
                    viewRow.RefreshControl(way);
                });
            });
        }
        #endregion
        #region ■ 按钮事件___________________________
        /// <summary>
        /// 停止按钮按下
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">E.</param>
        private void btnStop_MouseClick(object sender, MouseEventArgs e)
        {
            //存在误按的可能,画面开启的2秒前,禁止按下停止按钮
            if (this.searchTime >= 58 || this.Parent == null)
            {
                return;
            }
            //超时
            if (e == null && listView.ChildrenCount == 0)
            {
                //没有发现新网关,请检查网关链接是否正常
                string msg = Language.StringByID(R.MyInternationalizationString.uNotFoundNewGatewayPleaseCheckMsg);
                this.ShowMassage(ShowMsgType.Tip, msg);
            }
            Application.RunOnMainThread(() =>
            {
                this.IsThreadAction = false;
                if (frameTransparent != null)
                {
                    frameTransparent.Visible = false;
                }
                if (listView != null)
                {
                    listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(18);
                }
                this.searchTime = 60;
            });
        }
        #endregion
        #region ■ 界面关闭___________________________
        /// <summary>
@@ -546,8 +422,6 @@
        /// </summary>
        public override void CloseForm()
        {
            this.IsThreadAction = false;
            ZigBee.Common.Application.IsSearchingGateway = false;
            //断开没有执行绑定的网关的mqtt
            var list = new List<ZbGateway>();
@@ -574,10 +448,6 @@
            base.CloseForm();
        }
        #endregion
        #region ■ 一般方法___________________________
        #endregion
    }