| | |
| | | using Shared.Common;
|
| | | using Shared.Phone.UserCenter.SmartSound;
|
| | | using System;
|
| | | using System.Collections.Generic;
|
| | | using System.Text;
|
| | |
| | | public class DeviceListMainForm : EditorCommonForm
|
| | | {
|
| | | #region ■ 变量声明___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 智能音箱
|
| | | /// </summary>
|
| | | private MySmartSoundControl smmartSoundView = null;
|
| | | /// <summary>
|
| | | /// 网关控件
|
| | | /// </summary>
|
| | |
| | | /// 行控件的信息(Keys:Mac地址)
|
| | | /// </summary>
|
| | | private Dictionary<string, DeviceObjRowInfo> dicRowInfo = new Dictionary<string, DeviceObjRowInfo>();
|
| | | /// <summary>
|
| | | /// 重新获取设备的在线状态
|
| | | /// </summary>
|
| | | private bool reGetDeviceOnlineStatu = false;
|
| | | /// <summary>
|
| | | /// 当前正在操作的设备对象Mac地址(设备信息编辑界面用)
|
| | | /// </summary>
|
| | |
| | |
|
| | | //初始化中部控件
|
| | | 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();
|
| | |
|
| | | smmartSoundView = new MySmartSoundControl();
|
| | | bodyFrameLayout.AddChidren(smmartSoundView);
|
| | | smmartSoundView.InitControl();
|
| | | //当前不是虚拟住宅的话
|
| | | if (Config.Instance.Home.IsVirtually == false)
|
| | | {
|
| | | smmartSoundView.ButtonClickEvent += (sernder, e) =>
|
| | | {
|
| | | var form = new SmartSoundListForm();
|
| | | form.AddForm();
|
| | | };
|
| | | }
|
| | | //初始化网关行控件
|
| | | GatewayResourse.NowSelectGatewayId = GatewayResourse.AppOldSelectGatewayId;
|
| | | var nowGateway = HdlGatewayLogic.Current.GetLocalGateway(GatewayResourse.AppOldSelectGatewayId);
|
| | |
| | | frame.AddChidren(listView);
|
| | | listView.BeginHeaderRefreshingAction += () =>
|
| | | {
|
| | | //刷新设备的话,主页需要重新刷新
|
| | | UserView.UserPage.Instance.RefreshForm = true;
|
| | |
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | //下拉刷新
|
| | |
| | | //提示新版本
|
| | | var btnNew = new InformationTipView(rowMenu.btnIcon);
|
| | | btnNew.Visible = false;
|
| | | rowMenu.frameTable.AddChidren(btnNew, ChidrenBindMode.BindEventOnly);
|
| | | rowMenu.frameTable.AddChidren(btnNew, ChidrenBindMode.BindEvent);
|
| | | rowMenu.AddTag("btnNew", btnNew);
|
| | |
|
| | | //检测设备是否拥有定位的功能
|
| | |
| | | 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);
|
| | | if (deviceEnumInfo.ConcreteType == DeviceConcreteType.ButtonPanel_SimpleMultifunction)
|
| | | {
|
| | | //获取这一堆设备时属于什么类型的
|
| | | var deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(listDevice);
|
| | | foreach (CommonDevice info in listDevice)
|
| | | var listTemp = Common.LocalDevice.Current.GetMutilfunctionPanelByMac(listDevice);
|
| | | //展开模式时,扩大依据为:它有几个子控件
|
| | | heightValue = (listTemp.Count + 1) * (ControlCommonResourse.ListViewRowHeight + rowInfo.frameTable.rowSpace);
|
| | | //标题自己就是一个子控件
|
| | | if (rowInfo.frameTable.ChildrenCount == 1)
|
| | | {
|
| | | //加载它的列表
|
| | | this.AddDeviceDetailRow(rowInfo.frameTable, info, deviceEnumInfo);
|
| | | foreach (CommonDevice info in listTemp)
|
| | | {
|
| | | //加载它的列表
|
| | | this.AddDeviceDetailRow(rowInfo.frameTable, info, deviceEnumInfo);
|
| | | }
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | //展开模式时,扩大依据为:它有几个子控件
|
| | | heightValue = (listDevice.Count + 1) * (ControlCommonResourse.ListViewRowHeight + rowInfo.frameTable.rowSpace);
|
| | | //标题自己就是一个子控件
|
| | | if (rowInfo.frameTable.ChildrenCount == 1)
|
| | | {
|
| | | foreach (CommonDevice info in listDevice)
|
| | | {
|
| | | //加载它的列表
|
| | | this.AddDeviceDetailRow(rowInfo.frameTable, info, deviceEnumInfo);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | //右箭头
|
| | | rowDevice.frameTable.AddRightArrow();
|
| | | //在线状态
|
| | | rowDevice.isOnline = device.IsOnline == 1;
|
| | |
|
| | | rowDevice.IsOnline = rowInfo.MenuRow.IsOnline;
|
| | | //保存控件
|
| | | string maikey = Common.LocalDevice.Current.GetDeviceMainKeys(device);
|
| | | rowInfo.dicDetailRow[maikey] = rowDevice;
|
| | |
| | | {
|
| | | //方悦面板的功能配置
|
| | | var form = new DevicePanel.PanelFangyueFunctionSettionForm();
|
| | | form.AddForm(device);
|
| | | form.AddForm(device, deviceEnumInfo);
|
| | | }
|
| | | else
|
| | | {
|
| | |
| | | if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, nowGateway) == true)
|
| | | {
|
| | | //重新设置住宅ID(这个应该是不经过APP,直接把网关恢复了出厂设置)
|
| | | if (HdlGatewayLogic.Current.HomeIdIsEmpty(realWay.getGatewayBaseInfo.HomeId) == true)
|
| | | if (HdlGatewayLogic.Current.HomeIdIsEmpty(realWay.HomeId) == true)
|
| | | {
|
| | | //显示进度条
|
| | | ProgressBar.Show();
|
| | |
| | | if (result != -1)
|
| | | {
|
| | | //重新刷新界面
|
| | | this.InitMiddleFrame(false);
|
| | | this.InitMiddleFrame();
|
| | | }
|
| | | });
|
| | | }
|
| | |
| | | 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);
|
| | | }
|
| | | });
|
| | | });
|
| | |
| | | /// </summary>
|
| | | /// <param name="gateWay">网关对象</param>
|
| | | /// <param name="online">在线状态变更后的状态</param>
|
| | | public override void GatewayOnlinePush(ZbGateway gateWay, bool online)
|
| | | /// <param name="hadGwOnline">2020.05.25追加:此住宅是否拥有网关在线</param>
|
| | | public override void GatewayOnlinePush(ZbGateway gateWay, bool online, bool hadGwOnline)
|
| | | {
|
| | | if (this.gatewayViewRow == null)
|
| | | {
|
| | | return;
|
| | | }
|
| | | if (HdlGatewayLogic.Current.GetGatewayId(gateWay) == this.gatewayViewRow.zbGatewayId)
|
| | | if (gateWay.GwId == this.gatewayViewRow.zbGatewayId)
|
| | | {
|
| | | Application.RunOnMainThread(() =>
|
| | | {
|
| | | this.gatewayViewRow?.RefreshControl();
|
| | | //相同的状态,不需要再次刷新
|
| | | if (this.gatewayViewRow.isOnline != online)
|
| | | {
|
| | | //根据网关在线状态刷新设备在线状态
|
| | | this.RefreshDeviceOnlineStatuByGatewayOnline(online);
|
| | | }
|
| | | //刷新控件在线状态
|
| | | this.gatewayViewRow?.RefreshOnlineStatu();
|
| | | });
|
| | | }
|
| | | }
|
| | |
| | | #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 (this.reGetDeviceOnlineStatu == false)
|
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | //添加接收设备在线上报的监听
|
| | | HdlGatewayReceiveLogic.Current.AddAttributeEvent("DeviceListFormReceivePushOnline", ReceiveComandDiv.A设备在线上报, this.ReceiveDeviceStatu);
|
| | |
|
| | | 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);
|
| | | });
|
| | | }
|
| | |
|
| | |
| | | if (localDevice != null)
|
| | | {
|
| | | //在线状态一样的话,不需要刷新
|
| | | if (localDevice.IsOnline == device.IsOnline)
|
| | | if (localDevice.IsOnline != device.IsOnline)
|
| | | {
|
| | | return;
|
| | | //保存状态
|
| | | localDevice.IsOnline = device.IsOnline;
|
| | | localDevice.ReSave();
|
| | | }
|
| | | //保存状态
|
| | | localDevice.IsOnline = device.IsOnline;
|
| | | 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>
|
| | |
| | | /// </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;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | #region ■ 实现外部调用_______________________
|
| | |
|
| | | /// <summary>
|
| | | /// 添加新的设备到界面桌布中
|
| | | /// 添加新的设备到界面桌布中(外部调用)
|
| | | /// </summary>
|
| | | /// <param name="deviceAddr">设备Mac地址</param>
|
| | | public void AddDeviceToFormTable(string deviceAddr)
|
| | |
| | |
|
| | | //创建新的行
|
| | | 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();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | /// 网关名字控件
|
| | | /// </summary>
|
| | | private NormalViewControl btnName = null;
|
| | | /// <summary>
|
| | | /// 在线状态
|
| | | /// </summary>
|
| | | public bool isOnline = false;
|
| | |
|
| | | /// <summary>
|
| | | /// 自定义网关控件
|
| | |
| | | this.UseClickStatu = false;
|
| | | if (i_zbGateway != null)
|
| | | {
|
| | | this.zbGatewayId = HdlGatewayLogic.Current.GetGatewayId(i_zbGateway);
|
| | | this.zbGatewayId = i_zbGateway.GwId;
|
| | | }
|
| | | this.BackgroundColor = UserCenterColor.Current.White;
|
| | | this.Y = Application.GetRealHeight(174);
|
| | | this.Height = Application.GetRealHeight(173);
|
| | | }
|
| | |
|
| | |
| | | if (zbway != null)
|
| | | {
|
| | | btnName.Text = HdlGatewayLogic.Current.GetGatewayName(zbway);
|
| | | if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbway) == false)
|
| | | //在线状态
|
| | | this.isOnline = HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbway);
|
| | | if (this.isOnline == false)
|
| | | {
|
| | | btnName.TextColor = UserCenterColor.Current.TextGrayColor1;
|
| | | }
|
| | |
| | | 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;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | #endregion
|
| | |
|
| | | #region ■ 自定义智能音箱控件_____________________
|
| | |
|
| | | /// <summary>
|
| | | /// 自定义网关控件
|
| | | /// </summary>
|
| | | private class MySmartSoundControl : FrameRowControl
|
| | | {
|
| | |
|
| | | /// <summary>
|
| | | /// 网关名字控件
|
| | | /// </summary>
|
| | | private NormalViewControl btnName = null;
|
| | |
|
| | | /// <summary>
|
| | | /// 自定音箱关控件
|
| | | /// </summary>
|
| | | public MySmartSoundControl()
|
| | | {
|
| | | this.UseClickStatu = false;
|
| | | this.BackgroundColor = UserCenterColor.Current.White;
|
| | | this.Height = Application.GetRealHeight(173);
|
| | |
|
| | | //this.InitControl();
|
| | | }
|
| | |
|
| | |
|
| | | /// <summary>
|
| | | /// 初始化控件
|
| | | /// </summary>
|
| | | public void InitControl()
|
| | | {
|
| | | //图标
|
| | | var btnIcon = this.AddLeftIcon(81);
|
| | | btnIcon.UnSelectedImagePath = "SmartSound/SoundIcon.png";
|
| | |
|
| | | //显示文本
|
| | | btnName = this.AddLeftCaption(string.Empty, 700);
|
| | | btnName.Height = Application.GetRealHeight(60);
|
| | | btnName.TextSize = 15;
|
| | | btnName.Y = Application.GetRealHeight(57);
|
| | | btnName.Text = "小度小度";
|
| | |
|
| | | this.AddRightArrow();
|
| | | this.AddMostRightView("", 300, false).Name = "smartSoundLayout";
|
| | | this.AddBottomLine();
|
| | | }
|
| | | }
|
| | | #endregion
|
| | | }
|
| | | }
|