黄学彪
2020-05-13 2be70a32d2a8c517bd9868fb60913fcc843e66fe
ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs
@@ -30,10 +30,6 @@
        /// </summary>
        private Dictionary<string, DeviceObjRowInfo> dicRowInfo = new Dictionary<string, DeviceObjRowInfo>();
        /// <summary>
        /// 重新获取设备的在线状态
        /// </summary>
        private bool reGetDeviceOnlineStatu = false;
        /// <summary>
        /// 当前正在操作的设备对象Mac地址(设备信息编辑界面用)
        /// </summary>
        private string nowActionDeviceMac = null;
@@ -59,41 +55,41 @@
            btnAddDeviceIcon.InitControl();
            btnAddDeviceIcon.ButtonClickEvent += (sender, e) =>
            {
                ZbGateway realWay = null;
                if (GatewayResourse.NowSelectGateway == null || HdlGatewayLogic.Current.GetRealGateway(ref realWay, GatewayResourse.NowSelectGateway) == false)
                {
                    //网关对象异常,请重新选择网关
                    string msg = Language.StringByID(R.MyInternationalizationString.uGatewayIsErrorAndReSelect);
                    this.ShowMassage(ShowMsgType.Error, msg, () =>
                    {
                        var form2 = new GatewayManage.GatewayListForm();
                        form2.AddForm();
                    });
                    return;
                }
                GatewayResourse.NowSelectGateway = realWay;
                var form = new DeviceDirection.AddDeviceTypeListForm();
                form.AddForm();
            };
            //初始化中部控件
            this.InitMiddleFrame();
            //开启传感器报警监视
            this.StartCheckDeviceAlarm();
            //添加接收设备在线上报的监听
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("DeviceListFormReceivePushOnline", ReceiveComandDiv.A设备在线上报, (report) =>
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //接受设备状态
                    this.ReceiveDeviceStatu(report);
                }, ShowErrorMode.NO);
            });
            //开启检测网关在线状态的线程
            HdlGatewayLogic.Current.StartCheckGatewayOnlineThread(this);
        }
        /// <summary>
        /// 初始化中部控件(外部可以调用)
        /// </summary>
        /// <param name="i_reGetDeviceOnlineStatu">重新获取设备的在线状态</param>
        public void InitMiddleFrame(bool i_reGetDeviceOnlineStatu = true)
        public void InitMiddleFrame()
        {
            this.reGetDeviceOnlineStatu = i_reGetDeviceOnlineStatu;
            //清空bodyFrame
            this.ClearBodyFrame();
            //初始化网关行控件
            GatewayResourse.NowSelectGateway = HdlGatewayLogic.Current.GetLocalGateway(GatewayResourse.AppOldSelectGatewayId);
            this.gatewayViewRow = new MyGatewayControl(GatewayResourse.NowSelectGateway);
            GatewayResourse.NowSelectGatewayId = GatewayResourse.AppOldSelectGatewayId;
            var nowGateway = HdlGatewayLogic.Current.GetLocalGateway(GatewayResourse.AppOldSelectGatewayId);
            this.gatewayViewRow = new MyGatewayControl(nowGateway);
            bodyFrameLayout.AddChidren(gatewayViewRow);
            gatewayViewRow.InitControl();
@@ -138,6 +134,9 @@
            frame.AddChidren(listView);
            listView.BeginHeaderRefreshingAction += () =>
            {
                //刷新设备的话,主页需要重新刷新
                UserView.UserPage.Instance.RefreshForm = true;
                HdlThreadLogic.Current.RunThread(() =>
                {
                    //下拉刷新
@@ -156,9 +155,8 @@
        private void InitDeviceListControl()
        {
            //获取设备列表
            string gwID = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
            var listDevice = Common.LocalDevice.Current.GetDeviceByGatewayID(gwID);
            var listSpecialOta = Common.LocalDevice.Current.GetSpecialOtaDevice(gwID);
            var listDevice = Common.LocalDevice.Current.GetDeviceByGatewayID(GatewayResourse.NowSelectGatewayId);
            var listSpecialOta = Common.LocalDevice.Current.GetSpecialOtaDevice(GatewayResourse.NowSelectGatewayId);
            listDevice.AddRange(listSpecialOta);
            this.dicRowInfo.Clear();
@@ -190,11 +188,14 @@
                    //添加设备的菜单行
                    this.AddDeviceMenuRow(macAddress);
                }
                //开启网关在线监测的线程
                this.StartGatewayOnlieCheckThread();
                //检测设备新版本
                this.CheckDeviceNewVersion(listOta);
                //如果当前不是虚拟住宅
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    //开启网关在线监测的线程
                    this.StartGatewayOnlieCheckThread();
                    //检测设备新版本
                    this.CheckDeviceNewVersion(listOta);
                }
            });
        }
@@ -239,13 +240,8 @@
            if (listdevice.Count > 0 && Common.LocalDevice.Current.DeviceIsCanFixedPosition(listdevice[0]) == true)
            {
                //定位
                var btnPosition = new NormalViewControl(Application.GetRealWidth(184), rowMenu.Height, false);
                var btnPosition = rowMenu.AddEditorControl(false);
                btnPosition.TextID = R.MyInternationalizationString.uFixedPosition;
                btnPosition.TextAlignment = TextAlignment.Center;
                btnPosition.TextSize = 12;
                btnPosition.TextColor = UserCenterColor.Current.White;
                btnPosition.BackgroundColor = 0xff4a4a4a;
                rowMenu.AddRightView(btnPosition);
                btnPosition.ButtonClickEvent += (sender, e) =>
                {
                    //定位
@@ -275,6 +271,8 @@
            rowMenu.frameTable.ButtonClickEvent += (sender, e) =>
            {
                //隐藏菜单
                rowMenu.HideMenu();
                //强制跳转真实设备界面
                if (UserCenterResourse.HideOption.GotoRealDeviceForm == 1)
                {
@@ -362,8 +360,7 @@
            //右箭头
            rowDevice.frameTable.AddRightArrow();
            //在线状态
            rowDevice.isOnline = device.IsOnline == 1;
            rowDevice.IsOnline = rowInfo.MenuRow.IsOnline;
            //保存控件
            string maikey = Common.LocalDevice.Current.GetDeviceMainKeys(device);
            rowInfo.dicDetailRow[maikey] = rowDevice;
@@ -372,13 +369,8 @@
            if (Common.LocalDevice.Current.DeviceIsCanFixedPosition(device) == true)
            {
                //定位
                var btnPosition = new NormalViewControl(Application.GetRealWidth(184), rowDevice.Height, false);
                var btnPosition = rowDevice.AddEditorControl(false);
                btnPosition.TextID = R.MyInternationalizationString.uFixedPosition;
                btnPosition.TextAlignment = TextAlignment.Center;
                btnPosition.TextSize = 12;
                btnPosition.TextColor = UserCenterColor.Current.White;
                btnPosition.BackgroundColor = 0xff4a4a4a;
                rowDevice.AddRightView(btnPosition);
                btnPosition.ButtonClickEvent += (sender, e) =>
                {
                    //定位
@@ -388,10 +380,16 @@
            rowDevice.frameTable.ButtonClickEvent += (sender, e) =>
            {
                //隐藏菜单
                rowDevice.HideMenu();
                //界面跳转,记录当前的正在操作的设备的Mac地址
                this.nowActionDeviceMac = device.DeviceAddr;
                //显示设备功能配置界面
                this.ShowDeviceFunctionSettionForm(device, deviceEnumInfo);
                //如果当前住宅不是虚拟住宅
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    //显示设备功能配置界面
                    this.ShowDeviceFunctionSettionForm(device, deviceEnumInfo);
                }
            };
            //左滑菜单事件
            rowDevice.OpenMenuAction += () =>
@@ -453,8 +451,18 @@
            //新风面板
            else if (deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueFreshAir)
            {
                var form = new DeviceFunctionSettionForm();
                form.AddForm(device, true);
                //方悦新风面板的按键配置
                //干接点
                if (device.Type == DeviceType.FreshAir)
                {
                    var form = new DevicePanel.PanelFangyueFreshAirButtonSettionForm();
                    form.AddForm(device);
                }
                else
                {
                    var form = new DeviceFunctionSettionForm();
                    form.AddForm(device, true);
                }
            }
            //方悦面板
            else if (deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_FangyueTwo
@@ -596,12 +604,25 @@
        /// </summary>
        private async void ListViewBeginHeaderRefreshing()
        {
            //如果当前住宅是虚拟的
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                //就显示一个特效而已
                System.Threading.Thread.Sleep(2000);
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //隐藏下拉刷新特效
                    listView.EndHeaderRefreshing();
                });
                return;
            }
            //如果是在线的
            if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(GatewayResourse.NowSelectGateway) == true)
            var nowGateway = HdlGatewayLogic.Current.GetLocalGateway(GatewayResourse.NowSelectGatewayId);
            if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(nowGateway) == true)
            {
                //检测广播到的这个网关是否拥有住宅ID
                ZbGateway realWay = null;
                if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, GatewayResourse.NowSelectGateway) == true)
                if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, nowGateway) == true)
                {
                    //重新设置住宅ID(这个应该是不经过APP,直接把网关恢复了出厂设置)
                    if (HdlGatewayLogic.Current.HomeIdIsEmpty(realWay.getGatewayBaseInfo.HomeId) == true)
@@ -624,7 +645,7 @@
            }
            //获取全部设备
            int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(GatewayResourse.NowSelectGateway);
            int result = LocalDevice.Current.SetDeviceToMemmoryByGateway(nowGateway);
            if (this.Parent == null)
            {
                return;
@@ -636,7 +657,7 @@
                if (result != -1)
                {
                    //重新刷新界面
                    this.InitMiddleFrame(false);
                    this.InitMiddleFrame();
                }
            });
        }
@@ -650,12 +671,7 @@
        /// </summary>
        private void StartGatewayOnlieCheckThread()
        {
            if (GatewayResourse.NowSelectGateway == null)
            {
                return;
            }
            string selectGwId = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
            string selectGwId = GatewayResourse.NowSelectGatewayId;
            HdlThreadLogic.Current.RunThread(() =>
            {
                ZbGateway zbGateway = HdlGatewayLogic.Current.GetLocalGateway(selectGwId);
@@ -671,9 +687,10 @@
                    if (this.gatewayViewRow != null && this.gatewayViewRow.zbGatewayId == selectGwId)
                    {
                        bool online = HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbGateway);
                        this.gatewayViewRow.RefreshControl();
                        //开启设备在线线程
                        this.StartDeviceListControlThread(online);
                        //刷新控件在线状态
                        this.gatewayViewRow?.RefreshOnlineStatu();
                        //根据网关在线状态刷新设备在线状态
                        this.RefreshDeviceOnlineStatuByGatewayOnline(online);
                    }
                });
            });
@@ -694,7 +711,14 @@
            {
                Application.RunOnMainThread(() =>
                {
                    this.gatewayViewRow?.RefreshControl();
                    //相同的状态,不需要再次刷新
                    if (this.gatewayViewRow.isOnline != online)
                    {
                        //根据网关在线状态刷新设备在线状态
                        this.RefreshDeviceOnlineStatuByGatewayOnline(online);
                    }
                    //刷新控件在线状态
                    this.gatewayViewRow?.RefreshOnlineStatu();
                });
            }
        }
@@ -704,52 +728,43 @@
        #region ■ 设备在线检测_______________________
        /// <summary>
        /// 开启设备在线线程
        /// 根据网关在线状态刷新设备在线状态
        /// </summary>
        /// <param name="gatewayOnline">网关的在线状态</param>
        private void StartDeviceListControlThread(bool gatewayOnline)
        private void RefreshDeviceOnlineStatuByGatewayOnline(bool gatewayOnline)
        {
            if (gatewayOnline == false)
            {
                //设置全部设备离线
                this.SetAllDeviceOffLine();
                return;
            }
            //开启传感器报警监视
            this.StartCheckDeviceAlarm();
            //开启设备在线监测
            this.StartCheckDeviceOnline();
            else
            {
                //刷新设备在线状态
                this.RefreshDeviceOnlineStatu();
            }
        }
        /// <summary>
        /// 开启设备在线监测
        /// 刷新设备在线状态
        /// </summary>
        private void StartCheckDeviceOnline()
        private void RefreshDeviceOnlineStatu()
        {
            //外部调用的话,不再重新获取设备状态
            if (GatewayResourse.NowSelectGateway == null || this.reGetDeviceOnlineStatu == false)
            {
                return;
            }
            //添加接收设备在线上报的监听
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("DeviceListFormReceivePushOnline", ReceiveComandDiv.A设备在线上报, this.ReceiveDeviceStatu);
            string gwId = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
            string gwId = GatewayResourse.NowSelectGatewayId;
            HdlThreadLogic.Current.RunThread(() =>
            {
                System.Threading.Thread.Sleep(2000);
                //这里主要只是获取在线状态
                var zbway = HdlGatewayLogic.Current.GetLocalGateway(gwId);
                int statu = 0;
                var list = LocalDevice.Current.GetDeviceListFromGateway(zbway, ref statu, false, ShowErrorMode.NO);
                if (statu != -1)
                var list = LocalDevice.Current.GetDeviceOnlineList(gwId);
                HdlThreadLogic.Current.RunMain(() =>
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        //设置设备在线状态
                        this.ReceiveDeviceStatu(list[i]);
                    }
                }
                }, ShowErrorMode.NO);
            });
        }
@@ -783,20 +798,14 @@
                localDevice.ReSave();
            }
            HdlThreadLogic.Current.RunMain(() =>
            rowInfo.MenuRow.IsOnline = Common.LocalDevice.Current.CheckDeviceIsOnline(device);
            if (rowInfo.dicDetailRow != null)
            {
                if (rowInfo != null)
                foreach (var detailRow in rowInfo.dicDetailRow.Values)
                {
                    rowInfo.MenuRow.isOnline = device.IsOnline == 1;
                    if (rowInfo.dicDetailRow != null)
                    {
                        foreach (var detailRow in rowInfo.dicDetailRow.Values)
                        {
                            detailRow.isOnline = rowInfo.MenuRow.isOnline;
                        }
                    }
                    detailRow.IsOnline = rowInfo.MenuRow.IsOnline;
                }
            });
            }
        }
        /// <summary>
@@ -804,17 +813,20 @@
        /// </summary>
        private void SetAllDeviceOffLine()
        {
            lock (dicRowInfo)
            foreach (var rowInfo in this.dicRowInfo.Values)
            {
                foreach (var rowInfo in this.dicRowInfo.Values)
                //菜单
                if (rowInfo.MenuRow != null)
                {
                    Application.RunOnMainThread(() =>
                    rowInfo.MenuRow.IsOnline = false;
                }
                //明细
                if (rowInfo.dicDetailRow != null)
                {
                    foreach (var detailRow in rowInfo.dicDetailRow.Values)
                    {
                        if (rowInfo.MenuRow != null)
                        {
                            rowInfo.MenuRow.isOnline = false;
                        }
                    });
                        detailRow.IsOnline = false;
                    }
                }
            }
        }
@@ -900,7 +912,7 @@
        #region ■ 实现外部调用_______________________
        /// <summary>
        /// 添加新的设备到界面桌布中
        /// 添加新的设备到界面桌布中(外部调用)
        /// </summary>
        /// <param name="deviceAddr">设备Mac地址</param>
        public void AddDeviceToFormTable(string deviceAddr)
@@ -928,6 +940,30 @@
                //创建新的行
                this.AddDeviceMenuRow(deviceAddr);
                //记录当前的正在操作的设备的Mac地址
                this.nowActionDeviceMac = deviceAddr;
            }
        }
        /// <summary>
        /// 刷新指定设备行的信息(外部调用)
        /// </summary>
        /// <param name="deviceAddr">设备Mac地址</param>
        public void RefreshDeviceRow(string deviceAddr)
        {
            if (this.dicRowInfo.ContainsKey(deviceAddr) == true)
            {
                var row = this.dicRowInfo[deviceAddr];
                row.MenuRow?.RefreshControlInfo(true);
                //明细
                if (row.dicDetailRow != null)
                {
                    foreach (var detailRow in row.dicDetailRow.Values)
                    {
                        detailRow.RefreshControlInfo();
                    }
                }
            }
        }
@@ -1022,8 +1058,6 @@
            HdlGatewayReceiveLogic.Current.RemoveEvent("DeviceListFormSensor");
            HdlGatewayReceiveLogic.Current.RemoveEvent("DeviceListFormReceivePushOnline");
            GatewayResourse.NowSelectGateway = null;
            base.CloseFormBefore();
        }
@@ -1079,6 +1113,10 @@
            /// 网关名字控件
            /// </summary>
            private NormalViewControl btnName = null;
            /// <summary>
            /// 在线状态
            /// </summary>
            public bool isOnline = false;
            /// <summary>
            /// 自定义网关控件
@@ -1087,7 +1125,10 @@
            public MyGatewayControl(ZbGateway i_zbGateway)
            {
                this.UseClickStatu = false;
                this.zbGatewayId = HdlGatewayLogic.Current.GetGatewayId(i_zbGateway);
                if (i_zbGateway != null)
                {
                    this.zbGatewayId = HdlGatewayLogic.Current.GetGatewayId(i_zbGateway);
                }
                this.BackgroundColor = UserCenterColor.Current.White;
                this.Height = Application.GetRealHeight(173);
            }
@@ -1101,16 +1142,34 @@
                ZbGateway zbway = HdlGatewayLogic.Current.GetLocalGateway(zbGatewayId);
                //图标
                var btnIcon = this.AddLeftIcon(81);
                HdlGatewayLogic.Current.SetGatewayIcon(btnIcon, zbway);
                if (zbway != null)
                {
                    HdlGatewayLogic.Current.SetGatewayIcon(btnIcon, zbway);
                }
                else
                {
                    btnIcon.UnSelectedImagePath = "Gateway/GatewayIcon1.png";
                }
                //显示文本
                btnName = this.AddLeftCaption(HdlGatewayLogic.Current.GetGatewayName(zbway), 700);
                btnName = this.AddLeftCaption(string.Empty, 700);
                btnName.Height = Application.GetRealHeight(60);
                btnName.TextSize = 15;
                btnName.Y = Application.GetRealHeight(35);
                if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbway) == false)
                if (zbway != null)
                {
                    btnName.TextColor = UserCenterColor.Current.TextGrayColor1;
                    btnName.Text = HdlGatewayLogic.Current.GetGatewayName(zbway);
                    //在线状态
                    this.isOnline = HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbway);
                    if (this.isOnline == false)
                    {
                        btnName.TextColor = UserCenterColor.Current.TextGrayColor1;
                    }
                }
                else
                {
                    //虚拟网关
                    btnName.Text = Language.StringByID(R.MyInternationalizationString.uVirtualGateway);
                }
                //当前网关
@@ -1127,15 +1186,19 @@
                var btnMament = this.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uGatewayManagement), 300);
                btnMament.Name = "btnMament";
                this.ButtonClickEvent += (sernder, e) =>
                //当前不是虚拟住宅的话
                if (Common.Config.Instance.Home.IsVirtually == false)
                {
                    if (string.IsNullOrEmpty(((View)sernder).Name) == false)
                    this.ButtonClickEvent += (sernder, e) =>
                    {
                        //打开网关列表界面
                        var form = new GatewayManage.GatewayListForm();
                        form.AddForm();
                    }
                };
                        if (string.IsNullOrEmpty(((View)sernder).Name) == false)
                        {
                            //打开网关列表界面
                            var form = new GatewayManage.GatewayListForm();
                            form.AddForm();
                        }
                    };
                }
            }
            /// <summary>
@@ -1150,13 +1213,34 @@
                    return;
                }
                btnName.Text = HdlGatewayLogic.Current.GetGatewayName(zbway);
                if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbway) == false)
                //刷新控件在线状态
                this.RefreshOnlineStatu();
            }
            /// <summary>
            /// 刷新控件在线状态
            /// </summary>
            public void RefreshOnlineStatu()
            {
                //获取本地网关对象
                ZbGateway zbway = HdlGatewayLogic.Current.GetLocalGateway(zbGatewayId);
                if (zbway == null)
                {
                    btnName.TextColor = UserCenterColor.Current.TextGrayColor1;
                    return;
                }
                else
                //在线状态
                bool statu = HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbway);
                if (this.isOnline != statu)
                {
                    btnName.TextColor = UserCenterColor.Current.TextColor1;
                    this.isOnline = statu;
                    if (this.isOnline == false)
                    {
                        btnName.TextColor = UserCenterColor.Current.TextGrayColor1;
                    }
                    else
                    {
                        btnName.TextColor = UserCenterColor.Current.TextColor1;
                    }
                }
            }
        }