gxc
2019-12-25 944b87b6bcccb095cd73f13f4410fb20faf48f74
ZigbeeApp/Shared/Phone/UserCenter/Gateway/Add/WiredGatewaySearchForm.cs
@@ -29,6 +29,10 @@
        /// 获取得到了新网关
        /// </summary>
        private bool newGatewayGetting = false;
        /// <summary>
        /// 网关检测中
        /// </summary>
        private string isGatewayChecking = "0";
        #endregion
@@ -111,7 +115,7 @@
            btnMsg1.Y = picGwImage.Bottom + Application.GetRealHeight(112);
            btnMsg1.TextID = R.MyInternationalizationString.uSearchGatewayFailMsg1;
            bodyFrameLayout.AddChidren(btnMsg1);
            //1.长按ZB/RST键20秒,网关恢复出厂设置,指示灯全部熄{0}灭后,重新入网。
            //1.长按ZB/RST键20秒,网关恢复出厂设置,指示灯全部熄灭后,重新入网。
            var btnMsg2 = new NormalViewControl(930, 100, true);
            btnMsg2.X = Application.GetRealWidth(75);
            btnMsg2.Y = btnMsg1.Bottom + Application.GetRealHeight(35);
@@ -120,7 +124,7 @@
            btnMsg2.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnMsg2.IsMoreLines = true;
            bodyFrameLayout.AddChidren(btnMsg2);
            //2.点按HID/WCFG键,进入网关换绑模式,系统指示灯快闪{0}5秒。
            //2.点按HID/WCFG键,进入网关换绑模式,系统指示灯快闪5秒。
            var btnMsg3 = new NormalViewControl(930, 100, true);
            btnMsg3.X = Application.GetRealWidth(75);
            btnMsg3.Y = btnMsg2.Bottom + Application.GetRealHeight(12);
@@ -173,6 +177,11 @@
            var btnGoBack = new BottomClickButton(688);
            btnGoBack.Y = Application.GetRealHeight(1495);
            btnGoBack.TextID = R.MyInternationalizationString.uGobackGatewayManage;
            if (UserCenterResourse.DicActionForm.ContainsKey("GatewayListForm") == false)
            {
                //返回主页
                btnGoBack.TextID = R.MyInternationalizationString.uGobackToHomePage;
            }
            bodyFrameLayout.AddChidren(btnGoBack);
            btnGoBack.ButtonClickEvent += (sender, e) =>
            {
@@ -214,7 +223,7 @@
            picGwImage.AddChidren(btnRound);
            string strMsg = btnMsg.Text;
            HdlThreadLogic.Current.RunThread(async () =>
            HdlThreadLogic.Current.RunThread(() =>
            {
                //清空全部列表
                HdlGatewayLogic.Current.ClearAllRealGateway();
@@ -229,8 +238,22 @@
                    maxCount--;
                    if (maxCount % 4 == 0)
                    {
                        //每2秒检测搜索到的网关
                        await this.CheckZbGatewayAndSetRow();
                        lock(isGatewayChecking)
                        {
                            if (isGatewayChecking != "1")
                            {
                                isGatewayChecking = "1";
                                HdlThreadLogic.Current.RunThread(async () =>
                                {
                                    //每2秒检测搜索到的网关
                                    await this.CheckZbGatewayAndSetRow();
                                    lock (isGatewayChecking)
                                    {
                                        isGatewayChecking = "0";
                                    }
                                });
                            }
                        }
                    }
                    if (this.newGatewayGetting == true)
                    {
@@ -265,12 +288,15 @@
                        this.InitFailMiddleFrame();
                    });
                }
                else
                else if (newGatewayGetting == true)
                {
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        var form = new WiredGatewayListForm();
                        this.AddFromAndRemoveNowForm(form, listZbGateway, dicZbGatewayDiv);
                        if (this.Parent != null)
                        {
                            var form = new GatewayManage.GatewaySearchListForm();
                            this.AddFromAndRemoveNowForm(form, listZbGateway, dicZbGatewayDiv);
                        }
                    });
                }
            });
@@ -288,8 +314,7 @@
            List<string> listId = new List<string>();
            for (int i = 0; i < ZbGateway.GateWayList.Count; i++)
            {
                string strip = HdlGatewayLogic.Current.GetGatewayBaseInfoAttribute(ZbGateway.GateWayList[i], "IpAddress").ToString();
                if (strip == string.Empty)
                if (ZbGateway.GateWayList[i].getGatewayBaseInfo.IpAddress == string.Empty)
                {
                    //IP没有的网关,我也不知道它是干嘛的
                    continue;
@@ -321,94 +346,61 @@
                {
                    continue;
                }
                //收集网关对象
                this.listZbGateway.Add(way);
                //网关绑定模式
                GatewayBindMode mode = GatewayBindMode.BindAgain;
                if (HdlGatewayLogic.Current.HomeIdIsEmpty(way) == true)
                //如果是第一次绑定,或者是以前已经绑定过了的
                if (HdlGatewayLogic.Current.HomeIdIsEmpty(way) == true
                    || way.getGatewayBaseInfo.HomeId == Common.Config.Instance.HomeId)
                {
                    //第一次绑定,也就是网关住宅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)
                {
                    if (way.getGatewayBaseInfo.HomeId != Common.Config.Instance.HomeId)
                    {
                        //第一次绑定,也就是网关住宅ID为空
                        mode = GatewayBindMode.First;
                    }
                    else
                    {
                        //已经绑定过了
                        mode = GatewayBindMode.Binded;
                    }
                    //添加搜索到的网关到缓存(执行网关保存操作)
                    ShowErrorMode showMode = this.dicIdCheckCount[listId[i]] == 0 ? ShowErrorMode.YES : ShowErrorMode.NO;
                    var result = await this.DoSaveGateway(way, showMode);
                    var result = await HdlGatewayLogic.Current.AddNewGateway(way, ShowErrorMode.NO);
                    if (result == false)
                    {
                        continue;
                    }
                }
                //收集网关对象
                this.listZbGateway.Add(way);
                //如果它已经完全成功了的话,则将它的剩余次数置零
                this.dicIdCheckCount[listId[i]] = 0;
                if (isExist == true)
                //全部处理OK后,才能设置flage
                if (mode == GatewayBindMode.First)
                {
                    //已经绑定过了的,则不再显示
                    continue;
                    //第一次绑定
                    this.dicZbGatewayDiv[listId[i]] = 0;
                    //获取到了新网关
                    this.newGatewayGetting = true;
                }
                if (mode != GatewayBindMode.BindAgain)
                else if (mode == GatewayBindMode.Binded)
                {
                    //已经绑定过
                    this.dicZbGatewayDiv[listId[i]] = 1;
                }
                else
                {
                    //需要重新绑定
                    this.dicZbGatewayDiv[listId[i]] = 2;
                }
                if (mode == GatewayBindMode.First)
                {
                    //我觉得这里需要获取一下新网关的设备列表
                    await Common.LocalDevice.Current.SetDeviceToMemmoryByGateway(way);
                    Common.LocalDevice.Current.SetDeviceToMemmoryByGateway(way);
                }
            }
            return true;
        }
        #endregion
        #region ■ 执行网关保存_______________________
        /// <summary>
        /// 执行网关保存
        /// </summary>
        /// <param name="zbGateway">网关对象</param>
        /// <param name="mode">是否显示错误</param>
        /// <returns></returns>
        private async Task<bool> DoSaveGateway(ZbGateway zbGateway, ShowErrorMode mode)
        {
            //添加搜索到的网关到缓存
            //1:正常  -1:异常  0:当前的网关绑定在了当前账号下的不同住宅里面
            int result = await HdlGatewayLogic.Current.AddNewGateway(zbGateway, mode);
            if (result == -1)
            {
                return false;
            }
            //前的网关绑定在了当前账号下的不同住宅里面
            if (result == 0)
            {
                if (mode == ShowErrorMode.YES)
                {
                    //网关绑定在当前账号下的其他住宅里\r\n请解除绑定后再试
                    string msg = Language.StringByID(R.MyInternationalizationString.uTheGatewayInOtherResidenceMsg);
                    if (msg.Contains("{0}") == true)
                    {
                        msg = string.Format(msg, "\r\n");
                    }
                    this.ShowMassage(ShowMsgType.Tip, msg);
                }
                return false;
            }
            return true;
        }
@@ -420,7 +412,7 @@
        /// <summary>
        /// 画面关闭
        /// </summary>
        public override void CloseForm()
        public override void CloseFormBefore()
        {
            ZigBee.Common.Application.IsSearchingGateway = false;
            //断开没有执行绑定的网关的mqtt
@@ -437,16 +429,16 @@
                foreach (var way in list)
                {
                    ZbGateway.GateWayList.RemoveAll((obj) => HdlGatewayLogic.Current.GetGatewayId(obj) == HdlGatewayLogic.Current.GetGatewayId(way));
                    way.DisConnect("Search");
                    way.DisConnectLocalMqttClient("Search");
                }
            }
            if (UserCenterResourse.listActionFormId.Contains("GatewayManagementForm") == false)
            if (UserCenterResourse.listActionFormId.Contains("UserMainForm") == false)
            {
                //刷新主页
                UserView.UserPage.Instance.Fresh();
            }
            base.CloseForm();
            base.CloseFormBefore();
        }
        #endregion