WJC
2019-10-18 2bc230cf2e7a7329c2329b07307a47b059835bbc
ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs
@@ -16,13 +16,13 @@
        /// 网关控件
        /// </summary>
        private MyGatewayControl gatewayViewRow = null;
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listView = null;
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listView = null;
        /// <summary>
        /// 行控件的信息(Keys:Mac地址)
        /// </summary>
        /// </summary>
        private Dictionary<string, DeviceObjRowInfo> dicRowInfo = new Dictionary<string, DeviceObjRowInfo>();
        /// <summary>
        /// 重新获取设备的在线状态
@@ -37,22 +37,22 @@
        #region ■ 初始化_____________________________
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.DeviceManagement));
            //右上添加按钮
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.DeviceManagement));
            //右上添加按钮
            var btnAddDeviceIcon = new MostRightIconControl(69, 69);
            btnAddDeviceIcon.UnSelectedImagePath = "Item/Add.png";
            topFrameLayout.AddChidren(btnAddDeviceIcon);
            btnAddDeviceIcon.InitControl();
            btnAddDeviceIcon.ButtonClickEvent += (sender, e) =>
            {
                ZbGateway realWay = null;
            btnAddDeviceIcon.UnSelectedImagePath = "Item/Add.png";
            topFrameLayout.AddChidren(btnAddDeviceIcon);
            btnAddDeviceIcon.InitControl();
            btnAddDeviceIcon.ButtonClickEvent += (sender, e) =>
            {
                ZbGateway realWay = null;
                if (GatewayResourse.NowSelectGateway == null || HdlGatewayLogic.Current.GetRealGateway(ref realWay, GatewayResourse.NowSelectGateway) == false)
                {
                    //网关对象异常,请重新选择网关
@@ -63,26 +63,26 @@
                        form2.AddForm();
                    });
                    return;
                }
                GatewayResourse.NowSelectGateway = realWay;
                var form = new DeviceDirection.AddDeviceTypeListForm();
                form.AddForm();
            };
            //初始化中部控件
            this.InitMiddleFrame();
        }
                }
                GatewayResourse.NowSelectGateway = realWay;
                var form = new DeviceDirection.AddDeviceTypeListForm();
                form.AddForm();
            };
            //初始化中部控件
            this.InitMiddleFrame();
        }
        /// <summary>
        /// 初始化中部控件(外部可以调用)
        /// </summary>
        /// <param name="i_reGetDeviceOnlineStatu">重新获取设备的在线状态</param>
        public void InitMiddleFrame(bool i_reGetDeviceOnlineStatu = true)
        /// <param name="i_reGetDeviceOnlineStatu">重新获取设备的在线状态</param>
        public void InitMiddleFrame(bool i_reGetDeviceOnlineStatu = true)
        {
            this.reGetDeviceOnlineStatu = i_reGetDeviceOnlineStatu;
            //清空bodyFrame
            this.ClearBodyFrame();
            this.ClearBodyFrame();
            //初始化网关行控件
            GatewayResourse.NowSelectGateway = HdlGatewayLogic.Current.GetLocalGateway(GatewayResourse.AppOldSelectGatewayId);
@@ -95,13 +95,12 @@
            //初始化搜索控件
            this.InitSearchControl();
            new System.Threading.Thread(() =>
            HdlThreadLogic.Current.RunThread(() =>
            {
                //初始化设备列表控件
                this.InitDeviceListControl();
            })
            { IsBackground = true }.Start();
        }
            });
        }
        #endregion
@@ -140,8 +139,8 @@
        /// <summary>
        /// 初始化设备列表控件
        /// </summary>
        private void InitDeviceListControl()
        /// </summary>
        private void InitDeviceListControl()
        {
            //获取设备列表
            string gwID = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
@@ -186,41 +185,41 @@
                //开启网关在线监测的线程
                this.StartGatewayOnlieCheckThread();
                //检测设备新版本
                this.CheckDeviceNewVersion(listOta);
            });
                this.CheckDeviceNewVersion(listOta);
            });
        }
        #endregion
        #region ■ 添加设备菜单行_____________________
        /// <summary>
        /// 添加设备的菜单行
        /// </summary>
        /// <param name="deviceMac">设备Mac地址</param>
        private void AddDeviceMenuRow(string deviceMac)
        /// <summary>
        /// 添加设备的菜单行
        /// </summary>
        /// <param name="deviceMac">设备Mac地址</param>
        private void AddDeviceMenuRow(string deviceMac)
        {
            var rowInfo = this.dicRowInfo[deviceMac];
            //创建一个可以展开和收缩的FrameLayout,相当于菜单栏
            var frameTable = new FrameListControl(29);
            frameTable.Height = ControlCommonResourse.ListViewRowHeight + frameTable.rowSpace;
            listView.AddChidren(frameTable);
            rowInfo.frameTable = frameTable;
            frameTable.Height = ControlCommonResourse.ListViewRowHeight + frameTable.rowSpace;
            listView.AddChidren(frameTable);
            rowInfo.frameTable = frameTable;
            //控件
            var rowMenu = new DeviceObjectControl(deviceMac, listView.rowSpace / 2);
            frameTable.AddChidren(rowMenu);
            var rowMenu = new DeviceObjectControl(deviceMac, listView.rowSpace / 2);
            frameTable.AddChidren(rowMenu);
            rowMenu.InitControl();
            rowInfo.MenuRow = rowMenu;
            //向右图标
            var btnRight = rowMenu.frameTable.AddRightIconControl();
            btnRight.SelectedImagePath = "Item/Down.png";
            //提示新版本
            var btnNew = new InformationTipView(rowMenu.btnIcon);
            btnNew.Visible = false;
            rowMenu.frameTable.AddChidren(btnNew, ChidrenBindMode.BindEventOnly);
            rowInfo.MenuRow = rowMenu;
            //向右图标
            var btnRight = rowMenu.frameTable.AddRightArrow();
            btnRight.SelectedImagePath = "Item/Down.png";
            //提示新版本
            var btnNew = new InformationTipView(rowMenu.btnIcon);
            btnNew.Visible = false;
            rowMenu.frameTable.AddChidren(btnNew, ChidrenBindMode.BindEventOnly);
            rowMenu.AddTag("btnNew", btnNew);
            //检测设备是否拥有定位的功能
@@ -258,29 +257,29 @@
                    //展开或者折叠明细列表
                    this.ShowDetailList(deviceMac, btnRight.IsSelected);
                }
            };
            };
        }
        #endregion
        #region ■ 展开折叠___________________________
        /// <summary>
        /// 展开或者隐藏列表
        /// </summary>
        /// <param name="deviceMac">设备Mac地址</param>
        /// <param name="isShow">是否展开</param>
        private void ShowDetailList(string deviceMac, bool isShow)
        {
            var rowInfo = this.dicRowInfo[deviceMac];
            //它原来的高度
            int oldHeight = rowInfo.frameTable.Height;
            //变更的高度,默认为列表隐藏
            int heightValue = ControlCommonResourse.ListViewRowHeight + rowInfo.frameTable.rowSpace;
            var listDevice = Common.LocalDevice.Current.GetDevicesByMac(deviceMac);
            if (isShow == true)
            {
                //展开模式时,扩大依据为:它有几个子控件
        /// <summary>
        /// 展开或者隐藏列表
        /// </summary>
        /// <param name="deviceMac">设备Mac地址</param>
        /// <param name="isShow">是否展开</param>
        private void ShowDetailList(string deviceMac, bool isShow)
        {
            var rowInfo = this.dicRowInfo[deviceMac];
            //它原来的高度
            int oldHeight = rowInfo.frameTable.Height;
            //变更的高度,默认为列表隐藏
            int heightValue = ControlCommonResourse.ListViewRowHeight + rowInfo.frameTable.rowSpace;
            var listDevice = Common.LocalDevice.Current.GetDevicesByMac(deviceMac);
            if (isShow == true)
            {
                //展开模式时,扩大依据为:它有几个子控件
                heightValue = (listDevice.Count + 1) * (ControlCommonResourse.ListViewRowHeight + rowInfo.frameTable.rowSpace);
                //标题自己就是一个子控件
                if (rowInfo.frameTable.ChildrenCount == 1)
@@ -290,10 +289,10 @@
                        //加载它的列表
                        this.AddDeviceDetailRow(rowInfo.frameTable, info);
                    }
                }
            }
            //自身高度变更
            rowInfo.frameTable.Height = heightValue;
                }
            }
            //自身高度变更
            rowInfo.frameTable.Height = heightValue;
        }
        /// <summary>
@@ -304,7 +303,10 @@
        private void AddDeviceDetailRow(FrameListControl frame, CommonDevice device)
        {
            var rowInfo = this.dicRowInfo[device.DeviceAddr];
            rowInfo.dicDetailRow = new Dictionary<string, DeviceRoomControl>();
            if (rowInfo.dicDetailRow == null)
            {
                rowInfo.dicDetailRow = new Dictionary<string, DeviceRoomControl>();
            }
            //行控件
            var rowDevice = new DeviceRoomControl(device, frame.rowSpace / 2);
@@ -314,7 +316,9 @@
            //底线
            rowDevice.frameTable.AddBottomLine();
            //右箭头
            rowDevice.frameTable.AddRightIconControl();
            rowDevice.frameTable.AddRightArrow();
            //在线状态
            rowDevice.isOnline = device.IsOnline == 1;
            //保存控件
            string maikey = Common.LocalDevice.Current.GetDeviceMainKeys(device);
@@ -349,13 +353,13 @@
        #endregion
        #region ■ 键值搜索___________________________
        #region ■ 键值搜索___________________________
        /// <summary>
        /// 根据搜索键值,设定列表数据
        /// </summary>
        /// <param name="searchKey">Search key.</param>
        private void SetRowDataBySearchKeys(string searchKey)
        /// <summary>
        /// 根据搜索键值,设定列表数据
        /// </summary>
        /// <param name="searchKey">Search key.</param>
        private void SetRowDataBySearchKeys(string searchKey)
        {
            lock (dicRowInfo)
            {
@@ -397,8 +401,8 @@
                        frameTemp.Height = Application.GetRealHeight(23);
                        listView.AddChidren(frameTemp);
                    }
                });
            }
                });
            }
        }
        #endregion
@@ -416,7 +420,7 @@
            }
            string selectGwId = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
            new System.Threading.Thread(() =>
            HdlThreadLogic.Current.RunThread(() =>
            {
                ZbGateway zbGateway = HdlGatewayLogic.Current.GetLocalGateway(selectGwId);
                if (zbGateway == null)
@@ -436,14 +440,13 @@
                        this.StartDeviceListControlThread(online);
                    }
                });
            })
            { IsBackground = true }.Start();
            });
        }
        /// <summary>
        /// 网关在线状态变更
        /// </summary>
        /// <param name="gateWay">网关对象</param>
        /// <param name="gateWay">网关对象</param>
        /// <param name="online">在线状态变更后的状态</param>
        public override void GatewayOnlinePush(ZbGateway gateWay, bool online)
        {
@@ -519,33 +522,32 @@
                return;
            }
            string gwId = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
            new System.Threading.Thread(async () =>
            HdlThreadLogic.Current.RunThread(async () =>
            {
                //这里主要只是获取在线状态
                var zbway = HdlGatewayLogic.Current.GetLocalGateway(gwId);
                var result = await Common.LocalDevice.Current.GetDeviceListFromGateway(zbway, this.ReceiveDeviceStatuPush);
            })
            { IsBackground = true }.Start();
                var result = await Common.LocalDevice.Current.GetDeviceListFromGateway(zbway, false, this.ReceiveDeviceStatuPush, ShowErrorMode.NO);
            });
        }
        /// <summary>
        /// 接受设备在线推送(网关在线推送即在线)
        /// 接受设备在线推送
        /// </summary>
        /// <param name="device"></param>
        private void ReceiveDeviceStatuPush(CommonDevice device)
        {
            lock (dicRowInfo)
            {
                if (device == null || this.Parent == null)
                if (this.Parent == null)
                {
                    return;
                }
                DeviceObjectControl row = null;
                DeviceObjRowInfo rowInfo = null;
                if (this.dicRowInfo.ContainsKey(device.DeviceAddr) == true)
                {
                    row = this.dicRowInfo[device.DeviceAddr].MenuRow;
                    rowInfo = this.dicRowInfo[device.DeviceAddr];
                }
                if (row == null)
                if (rowInfo == null || rowInfo.MenuRow == null)
                {
                    return;
                }
@@ -564,11 +566,18 @@
                    localDevice.ReSave();
                }
                Application.RunOnMainThread(() =>
                HdlThreadLogic.Current.RunMain(() =>
                {
                    if (row != null)
                    if (rowInfo != null)
                    {
                        row.isOnline = device.IsOnline == 1;
                        rowInfo.MenuRow.isOnline = device.IsOnline == 1;
                        if (rowInfo.dicDetailRow != null)
                        {
                            foreach (var detailRow in rowInfo.dicDetailRow.Values)
                            {
                                detailRow.isOnline = rowInfo.MenuRow.isOnline;
                            }
                        }
                    }
                });
            }
@@ -604,7 +613,7 @@
        /// <param name="list">ota设备</param>
        private void CheckDeviceNewVersion(List<OTADevice> list)
        {
            new System.Threading.Thread(async () =>
            HdlThreadLogic.Current.RunThread(async () =>
            {
                await System.Threading.Tasks.Task.Delay(2000);
                foreach (var ota in list)
@@ -644,17 +653,16 @@
                        }
                    });
                }
            })
            { IsBackground = true }.Start();
            });
        }
        #endregion
        #region ■ 传感器报警_________________________
        #region ■ 传感器报警_________________________
        /// <summary>
        /// 开启传感器报警监视
        /// </summary>
        /// </summary>
        private void StartCheckDeviceAlarm()
        {
            HdlDeviceAttributeLogic.Current.AddAttributeEvent("DeviceListFormSensor", "IASInfoReport", (device) =>
@@ -676,13 +684,13 @@
        #endregion
        #region ■ 实现外部调用_______________________
        #region ■ 实现外部调用_______________________
        /// <summary>
        /// 添加新的设备到界面桌布中
        /// </summary>
        /// <param name="deviceAddr">设备Mac地址</param>
        public void AddDeviceToFormTable(string deviceAddr)
        /// <summary>
        /// 添加新的设备到界面桌布中
        /// </summary>
        /// <param name="deviceAddr">设备Mac地址</param>
        public void AddDeviceToFormTable(string deviceAddr)
        {
            //新建一个对象
            if (this.dicRowInfo.ContainsKey(deviceAddr) == false)
@@ -698,8 +706,8 @@
                this.AddDeviceMenuRow(deviceAddr);
                return;
            }
        }
            }
        }
        #endregion
@@ -708,24 +716,22 @@
        /// <summary>
        /// 根据MAC合并设备列表
        /// </summary>
        /// <param name="listDevice"></param>
        private void MargeAllDeviceByMac(List<CommonDevice> listDevice)
        /// <param name="listDevice"></param>
        private void MargeAllDeviceByMac(List<CommonDevice> listDevice)
        {
            //设备排序
            List<CommonDevice> listSort = Common.LocalDevice.Current.SortDeviceList(listDevice);
            //根据Mac全部分组
            var dic = new Dictionary<string, List<CommonDevice>>();
            foreach (CommonDevice device in listSort)
            {
            foreach (CommonDevice device in listDevice)
            {
                if (device == null || device.DeviceAddr == null)
                {
                    continue;
                }
                if (dic.ContainsKey(device.DeviceAddr) == false)
                {
                    dic[device.DeviceAddr] = new List<CommonDevice>();
                }
                dic[device.DeviceAddr].Add(device);
                }
                if (dic.ContainsKey(device.DeviceAddr) == false)
                {
                    dic[device.DeviceAddr] = new List<CommonDevice>();
                }
                dic[device.DeviceAddr].Add(device);
            }
            //获取信息
            foreach (var mac in dic.Keys)
@@ -735,7 +741,7 @@
                info.MacName = Common.LocalDevice.Current.GetDeviceMacName(dic[mac][0]);
                info.DeviveTypeName = Common.LocalDevice.Current.GetDeviceObjectText(dic[mac]);
                this.dicRowInfo[mac] = info;
            }
            }
        }
        #endregion
@@ -744,15 +750,15 @@
        /// <summary>
        /// 画面关闭
        /// </summary>
        public override void CloseForm()
        /// </summary>
        public override void CloseForm()
        {
            HdlDeviceAttributeLogic.Current.RemoveEvent("DeviceListFormSensor");
            HdlDeviceAttributeLogic.Current.RemoveEvent("DeviceListFormReceivePushOnline");
            HdlDeviceAttributeLogic.Current.RemoveEvent("DeviceListFormReceivePushOnline");
            GatewayResourse.NowSelectGateway = null;
            base.CloseForm();
            GatewayResourse.NowSelectGateway = null;
            base.CloseForm();
        }
        #endregion
@@ -762,11 +768,11 @@
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override void FormActionAgainEvent()
        public override int FormActionAgainEvent()
        {
            if (this.nowActionDeviceMac == null)
            {
                return;
                return 1;
            }
            var rowInfo = this.dicRowInfo[nowActionDeviceMac];
            //检测这个设备是否被删除
@@ -795,6 +801,8 @@
            this.nowActionDeviceMac = null;
            //网关控件刷新
            this.gatewayViewRow.RefreshControl();
            return 1;
        }
        #endregion
@@ -891,7 +899,7 @@
                btnNowGw.TextColor = UserCenterColor.Current.TextGrayColor1;
                //向右图标
                var btnRight = this.AddRightIconControl();
                var btnRight = this.AddRightArrow();
                btnRight.Name = "btnRight";
                //网关管理
                var btnMament = this.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uGatewayManagement), 300);