HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-10-12 dc6493db59dcb0893eac50b72122f94c24056b3f
ZigbeeApp/Shared/Phone/UserCenter/Device/Direction/AddDeviceTypeListForm.cs
@@ -20,10 +20,6 @@
        /// 当前网关对象
        /// </summary>
        private ZbGateway zbGateway = null;
        /// <summary>
        /// mini网关是否能够添加设备
        /// </summary>
        private bool MiniGatewayCanAddDevice = true;
        #endregion
@@ -37,17 +33,10 @@
            //设定标题
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDeviceType));
            //初始化中部控件
            this.InitMiddleFrame();
            this.zbGateway = HdlGatewayLogic.Current.GetLocalGateway(GatewayResourse.AppOldSelectGatewayId);
            if (zbGateway != null && zbGateway.LinuxImageType == 11)
            {
                //初始化Mini网关的界面
                this.InitControlByMiniGateway();
            }
            else
            {
                //初始化中部控件
                this.InitMiddleFrame();
            }
        }
        /// <summary>
@@ -221,14 +210,25 @@
            var rowThrid = this.AddMenuRow(objectText, unSelectPic, string.Empty, false);
            rowThrid.ButtonClickEvent += (sender, e) =>
            {
                if (this.MiniGatewayCanAddDevice == false)
                rowThrid.CanClick = false;
                HdlThreadLogic.Current.RunThread(() =>
                {
                    //Mini网关最大只能添加16个设备
                    this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uMiniGatewayMaxDeviceCountMsg));
                    return;
                }
                var form = new Device.DeviceSearchForm();
                form.AddForm(string.Empty);
                    //检测网关
                    var errorMsg = this.CheckGateway();
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        rowThrid.CanClick = true;
                        if (errorMsg != null)
                        {
                            this.ShowMassage(ShowMsgType.Tip, errorMsg);
                        }
                        else
                        {
                            var form = new Device.DeviceSearchForm();
                            form.AddForm(string.Empty);
                        }
                    });
                });
            };
            //调整列表控件的高度
@@ -237,52 +237,46 @@
        #endregion
        #region ■ mini网关___________________________
        #region ■ 检测网关___________________________
        /// <summary>
        /// 初始化Mini网关的界面
        /// 检测网关(返回错误信息,null代表没问题)
        /// </summary>
        private void InitControlByMiniGateway()
        private string CheckGateway()
        {
            //mini夜灯只能限制加入16和设备
            this.ShowProgressBar();
            if (zbGateway != null && zbGateway.LinuxImageType == 11)
            {
                //mini夜灯只能限制加入16和设备
                this.ShowProgressBar();
            HdlThreadLogic.Current.RunThread(() =>
            {
                int statu = 0;
                //重新获取设备列表
                var listDevice = Common.LocalDevice.Current.GetDeviceListFromGateway(zbGateway, ref statu, true, ShowErrorMode.NO);
                this.CloseProgressBar();
                HdlThreadLogic.Current.RunMain(() =>
                var listDevice = Common.LocalDevice.Current.GetDeviceListFromGateway(zbGateway.GwId, ref statu, true, ShowErrorMode.NO);
                if (statu != 1)
                {
                    if (statu != 1)
                    {
                        listDevice = Common.LocalDevice.Current.GetDeviceByGatewayID(zbGateway.GwId);
                    }
                    //检测mini网关的设备数
                    this.CheckMiniGatewayDeviceCount(listDevice);
                    //初始化界面
                    this.InitMiddleFrame();
                });
            });
        }
        /// <summary>
        /// 检测mini网关的设备数
        /// </summary>
        /// <param name="listDevice"></param>
        private void CheckMiniGatewayDeviceCount(List<CommonDevice> listDevice)
        {
            var listMac = new HashSet<string>();
            foreach (var device in listDevice)
            {
                if (listMac.Contains(device.DeviceAddr) == false)
                {
                    listMac.Add(device.DeviceAddr);
                    //如果
                    listDevice = Common.LocalDevice.Current.GetDeviceByGatewayID(zbGateway.GwId);
                }
            }
            MiniGatewayCanAddDevice = listMac.Count < 16;
                //检测mini网关的设备数
                var listMac = new HashSet<string>();
                foreach (var device in listDevice)
                {
                    if (listMac.Contains(device.DeviceAddr) == false)
                    {
                        listMac.Add(device.DeviceAddr);
                    }
                }
                this.CloseProgressBar();
                bool canAdd = listMac.Count < 16;
                if (canAdd == false)
                {
                    //Mini网关最大只能添加16个设备
                    return Language.StringByID(R.MyInternationalizationString.uMiniGatewayMaxDeviceCountMsg);
                }
            }
            return null;
        }
        #endregion
@@ -316,14 +310,25 @@
            {
                rowLayout.ButtonClickEvent += (sender, e) =>
                {
                    if (this.MiniGatewayCanAddDevice == false)
                    rowLayout.CanClick = false;
                    HdlThreadLogic.Current.RunThread(() =>
                    {
                        //Mini网关最大只能添加16个设备
                        this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.uMiniGatewayMaxDeviceCountMsg));
                        return;
                    }
                    //反射目标界面
                    this.LoadFormByFullName("Shared.Phone.UserCenter.DeviceDirection." + formName);
                        //检测网关
                        var errorMsg = this.CheckGateway();
                        HdlThreadLogic.Current.RunMain(() =>
                        {
                            rowLayout.CanClick = true;
                            if (errorMsg != null)
                            {
                                this.ShowMassage(ShowMsgType.Tip, errorMsg);
                            }
                            else
                            {
                                //反射目标界面
                                this.LoadFormByFullName("Shared.Phone.UserCenter.DeviceDirection." + formName);
                            }
                        });
                    });
                };
            }