WJC
2019-10-28 0058d3fd5cf6052016ae744aeca2272623bfb6c8
ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceListMainForm.cs
@@ -1,4 +1,5 @@
using System;
using Shared.Common;
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
@@ -16,13 +17,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 +38,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 +64,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 +96,12 @@
            //初始化搜索控件
            this.InitSearchControl();
            new System.Threading.Thread(() =>
            HdlThreadLogic.Current.RunThread(() =>
            {
                //初始化设备列表控件
                this.InitDeviceListControl();
            })
            { IsBackground = true }.Start();
        }
            });
        }
        #endregion
@@ -140,8 +140,8 @@
        /// <summary>
        /// 初始化设备列表控件
        /// </summary>
        private void InitDeviceListControl()
        /// </summary>
        private void InitDeviceListControl()
        {
            //获取设备列表
            string gwID = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
@@ -186,41 +186,44 @@
                //开启网关在线监测的线程
                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.AddMostRightEmptyIcon(58, 58);
            rowMenu.frameTable.ChangedChidrenBindMode(btnRight, ChidrenBindMode.NotBind);
            btnRight.UseClickStatu = false;
            btnRight.UnSelectedImagePath = "Item/Next.png";
            btnRight.SelectedImagePath = "Item/Down.png";
            //提示新版本
            var btnNew = new InformationTipView(rowMenu.btnIcon);
            btnNew.Visible = false;
            rowMenu.frameTable.AddChidren(btnNew, ChidrenBindMode.BindEventOnly);
            rowMenu.AddTag("btnNew", btnNew);
            //检测设备是否拥有定位的功能
@@ -242,58 +245,59 @@
                };
            }
            //展开,折叠
            btnRight.ButtonClickEvent += (sender, e) =>
            {
                btnRight.IsSelected = !btnRight.IsSelected;
                //展开或者折叠明细列表
                this.ShowDetailList(deviceMac, btnRight.IsSelected);
            };
            rowMenu.frameTable.ButtonClickEvent += (sender, e) =>
            {
                //多回路的情况下,才会展开
                if (Common.LocalDevice.Current.GetDevicesByMac(deviceMac).Count == 1)
                {
                    var form = new DeviceMacInfoEditorForm();
                    form.AddForm(deviceMac);
                    //界面跳转,记录当前的正在操作的设备的Mac地址
                    this.nowActionDeviceMac = deviceMac;
                }
                else
                {
                    btnRight.IsSelected = !btnRight.IsSelected;
                    //展开或者折叠明细列表
                    this.ShowDetailList(deviceMac, btnRight.IsSelected);
                }
            };
                btnNew.Visible = false;
                var form = new DeviceMacInfoEditorForm();
                form.AddForm(deviceMac);
                //界面跳转,记录当前的正在操作的设备的Mac地址
                this.nowActionDeviceMac = deviceMac;
            };
        }
        #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)
                {
                    //获取这一堆设备时属于什么类型的
                    var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(listDevice);
                    foreach (CommonDevice info in listDevice)
                    {
                        //加载它的列表
                        this.AddDeviceDetailRow(rowInfo.frameTable, info);
                        this.AddDeviceDetailRow(rowInfo.frameTable, info, deviceEnumInfo);
                    }
                }
            }
            //自身高度变更
            rowInfo.frameTable.Height = heightValue;
                }
            }
            //自身高度变更
            rowInfo.frameTable.Height = heightValue;
        }
        /// <summary>
@@ -301,10 +305,14 @@
        /// </summary>
        /// <param name="frame">容器</param>
        /// <param name="device"></param>
        private void AddDeviceDetailRow(FrameListControl frame, CommonDevice device)
        /// <param name="deviceEnumInfo"></param>
        private void AddDeviceDetailRow(FrameListControl frame, CommonDevice device, DeviceEnumInfo deviceEnumInfo)
        {
            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 +322,9 @@
            //底线
            rowDevice.frameTable.AddBottomLine();
            //右箭头
            rowDevice.frameTable.AddRightIconControl();
            rowDevice.frameTable.AddRightArrow();
            //在线状态
            rowDevice.isOnline = device.IsOnline == 1;
            //保存控件
            string maikey = Common.LocalDevice.Current.GetDeviceMainKeys(device);
@@ -340,22 +350,93 @@
            rowDevice.frameTable.ButtonClickEvent += (sender, e) =>
            {
                var form = new DeviceMacInfoEditorForm();
                form.AddForm(device.DeviceAddr);
                //界面跳转,记录当前的正在操作的设备的Mac地址
                this.nowActionDeviceMac = device.DeviceAddr;
                //显示设备功能配置界面
                this.ShowDeviceFunctionSettionForm(device, deviceEnumInfo);
            };
        }
        /// <summary>
        /// 显示设备功能配置界面
        /// </summary>
        /// <param name="device"></param>
        /// <param name="deviceEnumInfo"></param>
        private void ShowDeviceFunctionSettionForm(CommonDevice device, DeviceEnumInfo deviceEnumInfo)
        {
            //智能门锁
            if (deviceEnumInfo.BeloneType == DeviceBeloneType.A智能门锁)
            {
                var form = new DeviceMacInfoEditorForm();
                form.AddForm(device.DeviceAddr);
            }
            //面板设备
            else if (deviceEnumInfo.BeloneType == DeviceBeloneType.A按键面板)
            {
                //干接点
                if (device.Type == DeviceType.OnOffSwitch)
                {
                    //河东设备
                    if (deviceEnumInfo.IsHdlDevice == true)
                    {
                        var form = new DevicePanel.PanelButtonSettionForm();
                        form.AddForm(device);
                    }
                    else
                    {
                        var form = new DeviceDryContactSettionForm();
                        form.AddForm(device);
                    }
                }
                //继电器
                else if (device.Type == DeviceType.OnOffOutput)
                {
                    //河东设备
                    if (deviceEnumInfo.IsHdlDevice == true)
                    {
                        var form = new DevicePanel.PanelFunctionSettionForm();
                        form.AddForm(device);
                    }
                    else
                    {
                        var form = new DeviceFunctionSettionForm();
                        form.AddForm(device, true);
                    }
                }
                //温湿度
                else if (device.Type == DeviceType.TemperatureSensor)
                {
                    var form = new DeviceFunctionSettionForm();
                    form.AddForm(device, true);
                }
                else
                {
                    var form = new DeviceFunctionSettionForm();
                    form.AddForm(device, true);
                }
            }
            //如果是干接点
            else if (device.Type == DeviceType.OnOffSwitch)
            {
                var form = new DeviceDryContactSettionForm();
                form.AddForm(device);
            }
            else
            {
                var form = new DeviceFunctionSettionForm();
                form.AddForm(device, true);
            }
        }
        #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 +478,8 @@
                        frameTemp.Height = Application.GetRealHeight(23);
                        listView.AddChidren(frameTemp);
                    }
                });
            }
                });
            }
        }
        #endregion
@@ -416,7 +497,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 +517,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 +599,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 +643,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 +690,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 +730,16 @@
                        }
                    });
                }
            })
            { IsBackground = true }.Start();
            });
        }
        #endregion
        #region ■ 传感器报警_________________________
        #region ■ 传感器报警_________________________
        /// <summary>
        /// 开启传感器报警监视
        /// </summary>
        /// </summary>
        private void StartCheckDeviceAlarm()
        {
            HdlDeviceAttributeLogic.Current.AddAttributeEvent("DeviceListFormSensor", "IASInfoReport", (device) =>
@@ -676,13 +761,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 +783,8 @@
                this.AddDeviceMenuRow(deviceAddr);
                return;
            }
        }
            }
        }
        #endregion
@@ -708,24 +793,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 +818,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 +827,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,32 +845,31 @@
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override void FormActionAgainEvent()
        public override int FormActionAgainEvent()
        {
            if (this.nowActionDeviceMac == null)
            if (this.nowActionDeviceMac != null)
            {
                return;
            }
            var rowInfo = this.dicRowInfo[nowActionDeviceMac];
            //检测这个设备是否被删除
            if (Common.LocalDevice.Current.GetDevicesByMac(nowActionDeviceMac).Count == 0)
            {
                //移除控件
                rowInfo.dicDetailRow = null;
                rowInfo.frameTable.RemoveFromParent();
                this.dicRowInfo.Remove(nowActionDeviceMac);
                rowInfo = null;
            }
            else
            {
                //刷新设备信息
                rowInfo.MenuRow?.RefreshControlInfo(true);
                if (rowInfo.dicDetailRow != null)
                var rowInfo = this.dicRowInfo[nowActionDeviceMac];
                //检测这个设备是否被删除
                if (Common.LocalDevice.Current.GetDevicesByMac(nowActionDeviceMac).Count == 0)
                {
                    foreach (var contr in rowInfo.dicDetailRow.Values)
                    //移除控件
                    rowInfo.dicDetailRow = null;
                    rowInfo.frameTable.RemoveFromParent();
                    this.dicRowInfo.Remove(nowActionDeviceMac);
                    rowInfo = null;
                }
                else
                {
                    //刷新设备信息
                    rowInfo.MenuRow?.RefreshControlInfo(true);
                    if (rowInfo.dicDetailRow != null)
                    {
                        contr?.RefreshControlInfo();
                        foreach (var contr in rowInfo.dicDetailRow.Values)
                        {
                            contr?.RefreshControlInfo();
                        }
                    }
                }
            }
@@ -795,6 +877,8 @@
            this.nowActionDeviceMac = null;
            //网关控件刷新
            this.gatewayViewRow.RefreshControl();
            return 1;
        }
        #endregion
@@ -891,7 +975,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);