gxc
2019-12-25 944b87b6bcccb095cd73f13f4410fb20faf48f74
ZigbeeApp/Shared/Phone/UserCenter/Gateway/Add/WiredGatewaySearchForm.cs
@@ -177,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) =>
            {
@@ -289,7 +294,7 @@
                    {
                        if (this.Parent != null)
                        {
                            var form = new WiredGatewayListForm();
                            var form = new GatewayManage.GatewaySearchListForm();
                            this.AddFromAndRemoveNowForm(form, listZbGateway, dicZbGatewayDiv);
                        }
                    });
@@ -309,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;
@@ -342,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;
        }
@@ -441,7 +412,7 @@
        /// <summary>
        /// 画面关闭
        /// </summary>
        public override void CloseForm()
        public override void CloseFormBefore()
        {
            ZigBee.Common.Application.IsSearchingGateway = false;
            //断开没有执行绑定的网关的mqtt
@@ -458,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