using Shared.Common;
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.Device
{
///
/// 设备列表的主界面
///
public class DeviceListMainForm : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// 网关控件
///
private MyGatewayControl gatewayViewRow = null;
///
/// 列表控件
///
private VerticalListControl listView = null;
///
/// 行控件的信息(Keys:Mac地址)
///
private Dictionary dicRowInfo = new Dictionary();
///
/// 重新获取设备的在线状态
///
private bool reGetDeviceOnlineStatu = false;
///
/// 当前正在操作的设备对象Mac地址(设备信息编辑界面用)
///
private string nowActionDeviceMac = null;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
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;
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();
}
///
/// 初始化中部控件(外部可以调用)
///
/// 重新获取设备的在线状态
public void InitMiddleFrame(bool i_reGetDeviceOnlineStatu = true)
{
this.reGetDeviceOnlineStatu = i_reGetDeviceOnlineStatu;
//清空bodyFrame
this.ClearBodyFrame();
//初始化网关行控件
GatewayResourse.NowSelectGateway = HdlGatewayLogic.Current.GetLocalGateway(GatewayResourse.AppOldSelectGatewayId);
this.gatewayViewRow = new MyGatewayControl(GatewayResourse.NowSelectGateway);
bodyFrameLayout.AddChidren(gatewayViewRow);
gatewayViewRow.InitControl();
//设置网关接受在线状态推送
this.AddGatewayOnlinePush();
//初始化搜索控件
this.InitSearchControl();
HdlThreadLogic.Current.RunThread(() =>
{
//初始化设备列表控件
this.InitDeviceListControl();
});
}
#endregion
#region ■ 初始化搜索控件_____________________
///
/// 初始化搜索控件
///
private void InitSearchControl()
{
//白色背景
var frame = new FrameLayout();
frame.BackgroundColor = UserCenterColor.Current.White;
frame.Y = this.gatewayViewRow.Bottom + Application.GetRealHeight(23);
frame.Height = bodyFrameLayout.Height - this.gatewayViewRow.Bottom - Application.GetRealHeight(23);
bodyFrameLayout.AddChidren(frame);
//搜索设备关键词
string textTip = Language.StringByID(R.MyInternationalizationString.uSearchDeviceKeyWorld);
var txtSearchControl = new SearchTextControl(textTip);
frame.AddChidren(txtSearchControl);
txtSearchControl.Y = Application.GetRealHeight(46);
//绑定回调函数
txtSearchControl.BindEvent(this.SetRowDataBySearchKeys);
//列表控件
listView = new VerticalListControl(29);
listView.Y = txtSearchControl.Bottom + Application.GetRealHeight(29);
listView.Height = frame.Height - txtSearchControl.Bottom - Application.GetRealHeight(29);
frame.AddChidren(listView);
}
#endregion
#region ■ 初始化设备列表控件_________________
///
/// 初始化设备列表控件
///
private void InitDeviceListControl()
{
//获取设备列表
string gwID = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
var listDevice = Common.LocalDevice.Current.GetDeviceByGatewayID(gwID);
this.dicRowInfo.Clear();
//没有设备
if (listDevice.Count == 0)
{
return;
}
//根据MAC合并设备列表
this.MargeAllDeviceByMac(listDevice);
Application.RunOnMainThread(() =>
{
if (this.Parent == null)
{
return;
}
var listOta = new List();
foreach (var macAddress in this.dicRowInfo.Keys)
{
//获取ota设备
var ota = Common.LocalDevice.Current.GetOTADevice(macAddress);
if (ota != null)
{
listOta.Add(ota);
}
//添加设备的菜单行
this.AddDeviceMenuRow(macAddress);
}
//添加底部间隙
var frameTemp = new FrameLayout();
frameTemp.Height = Application.GetRealHeight(23);
listView.AddChidren(frameTemp);
//开启设备属性变更监听
this.AddDeviceAttributePush();
//开启网关在线监测的线程
this.StartGatewayOnlieCheckThread();
//检测设备新版本
this.CheckDeviceNewVersion(listOta);
});
}
#endregion
#region ■ 添加设备菜单行_____________________
///
/// 添加设备的菜单行
///
/// 设备Mac地址
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;
//控件
var rowMenu = new DeviceObjectControl(deviceMac, listView.rowSpace / 2);
frameTable.AddChidren(rowMenu);
rowMenu.InitControl();
rowInfo.MenuRow = rowMenu;
//向右图标
var btnRight = rowMenu.frameTable.AddMostRightEmptyIcon(58, 58);
btnRight.UnSelectedImagePath = "Item/Next.png";
btnRight.SelectedImagePath = "Item/Down.png";
rowMenu.frameTable.ChangedChidrenBindMode(btnRight, ChidrenBindMode.NotBind);
//提示新版本
var btnNew = new InformationTipView(rowMenu.btnIcon);
btnNew.Visible = false;
rowMenu.frameTable.AddChidren(btnNew, ChidrenBindMode.BindEventOnly);
rowMenu.AddTag("btnNew", btnNew);
//检测设备是否拥有定位的功能
var listdevice = Common.LocalDevice.Current.GetDevicesByMac(deviceMac);
if (Common.LocalDevice.Current.DeviceIsCanFixedPosition(listdevice[0]) == true)
{
//定位
var btnPosition = new NormalViewControl(Application.GetRealWidth(184), rowMenu.Height, 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) =>
{
//定位
Common.LocalDevice.Current.SetFixedPositionCommand(listdevice[0]);
};
}
//展开,折叠
btnRight.ButtonClickEvent += (sender, e) =>
{
//回路数大于1才展开
if (Common.LocalDevice.Current.GetDevicesCountByMac(deviceMac) > 1)
{
btnRight.IsSelected = !btnRight.IsSelected;
//展开或者折叠明细列表
this.ShowDetailList(deviceMac, btnRight.IsSelected);
}
else
{
btnNew.Visible = false;
var form = new DeviceMacInfoEditorForm();
form.AddForm(deviceMac);
//界面跳转,记录当前的正在操作的设备的Mac地址
this.nowActionDeviceMac = deviceMac;
}
};
rowMenu.frameTable.ButtonClickEvent += (sender, e) =>
{
btnNew.Visible = false;
var form = new DeviceMacInfoEditorForm();
form.AddForm(deviceMac);
//界面跳转,记录当前的正在操作的设备的Mac地址
this.nowActionDeviceMac = deviceMac;
};
}
#endregion
#region ■ 展开折叠___________________________
///
/// 展开或者隐藏列表
///
/// 设备Mac地址
/// 是否展开
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, deviceEnumInfo);
}
}
}
//自身高度变更
rowInfo.frameTable.Height = heightValue;
}
///
/// 添加设备的明细行
///
/// 容器
///
///
private void AddDeviceDetailRow(FrameListControl frame, CommonDevice device, DeviceEnumInfo deviceEnumInfo)
{
var rowInfo = this.dicRowInfo[device.DeviceAddr];
if (rowInfo.dicDetailRow == null)
{
rowInfo.dicDetailRow = new Dictionary();
}
//行控件
var rowDevice = new DeviceRoomControl(device, frame.rowSpace / 2);
frame.AddChidren(rowDevice);
rowDevice.frameTable.LeftOffset = Application.GetRealWidth(173) - ControlCommonResourse.XXLeft;
rowDevice.InitControl();
//底线
rowDevice.frameTable.AddBottomLine();
//右箭头
rowDevice.frameTable.AddRightArrow();
//在线状态
rowDevice.isOnline = device.IsOnline == 1;
//保存控件
string maikey = Common.LocalDevice.Current.GetDeviceMainKeys(device);
rowInfo.dicDetailRow[maikey] = rowDevice;
//检测设备是否拥有定位的功能
if (Common.LocalDevice.Current.DeviceIsCanFixedPosition(device) == true)
{
//定位
var btnPosition = new NormalViewControl(Application.GetRealWidth(184), rowDevice.Height, 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) =>
{
//定位
Common.LocalDevice.Current.SetFixedPositionCommand(device);
};
}
rowDevice.frameTable.ButtonClickEvent += (sender, e) =>
{
//界面跳转,记录当前的正在操作的设备的Mac地址
this.nowActionDeviceMac = device.DeviceAddr;
//显示设备功能配置界面
this.ShowDeviceFunctionSettionForm(device, deviceEnumInfo);
};
}
///
/// 显示设备功能配置界面
///
///
///
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窗帘)
{
var form = new DeviceMacInfoEditorForm();
form.AddForm(device.DeviceAddr);
}
//pir传感器
else if (deviceEnumInfo.ConcreteType == DeviceConcreteType.Sensor_Pir)
{
var form = new DevicePirSensor.PirSensorBindTargetSettionForm();
form.AddForm((IASZone)device);
}
//中央空调
else if (deviceEnumInfo.ConcreteType == DeviceConcreteType.AirConditioner_ZbGateway)
{
var form = new DeviceAirConditioner.IndoorUnitSettionForm();
form.AddForm((AC)device);
}
//面板设备
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 ■ 键值搜索___________________________
///
/// 根据搜索键值,设定列表数据
///
/// Search key.
private void SetRowDataBySearchKeys(string searchKey)
{
lock (dicRowInfo)
{
Application.RunOnMainThread(() =>
{
if (this.listView == null)
{
return;
}
//首先先移除列表所有控件
this.listView.RemoveAll();
//如果搜索键值为空,则还原为原始状态:显示设备类型总览
if (searchKey == string.Empty)
{
foreach (var deviceMac in dicRowInfo.Keys)
{
//添加设备的行
this.AddDeviceMenuRow(deviceMac);
}
//添加底部间隙
var frameTemp = new FrameLayout();
frameTemp.Height = Application.GetRealHeight(23);
listView.AddChidren(frameTemp);
}
else
{
//搜索名字里面包含键值的设备
foreach (var rowInfo in this.dicRowInfo.Values)
{
if ((rowInfo.MacName != null && rowInfo.MacName.Contains(searchKey) == true)
|| rowInfo.DeviveTypeName.Contains(searchKey) == true)
{
//添加设备的行
this.AddDeviceMenuRow(rowInfo.DeviceMac);
}
}
//添加底部间隙
var frameTemp = new FrameLayout();
frameTemp.Height = Application.GetRealHeight(23);
listView.AddChidren(frameTemp);
}
});
}
}
#endregion
#region ■ 网关在线检测_______________________
///
/// 开启网关在线监测的线程
///
private void StartGatewayOnlieCheckThread()
{
if (GatewayResourse.NowSelectGateway == null)
{
return;
}
string selectGwId = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
HdlThreadLogic.Current.RunThread(() =>
{
ZbGateway zbGateway = HdlGatewayLogic.Current.GetLocalGateway(selectGwId);
if (zbGateway == null)
{
return;
}
//刷新网关在线状态
HdlGatewayLogic.Current.RefreshGatewayOnlineStatu(new List() { zbGateway });
Application.RunOnMainThread(() =>
{
if (this.gatewayViewRow != null && this.gatewayViewRow.zbGatewayId == selectGwId)
{
bool online = HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbGateway);
this.gatewayViewRow.RefreshControl();
//开启设备在线线程
this.StartDeviceListControlThread(online);
}
});
});
}
///
/// 网关在线状态变更
///
/// 网关对象
/// 在线状态变更后的状态
public override void GatewayOnlinePush(ZbGateway gateWay, bool online)
{
if (this.gatewayViewRow == null)
{
return;
}
if (HdlGatewayLogic.Current.GetGatewayId(gateWay) == this.gatewayViewRow.zbGatewayId)
{
Application.RunOnMainThread(() =>
{
this.gatewayViewRow?.RefreshControl();
});
}
}
#endregion
#region ■ 设备属性变更推送___________________
///
/// 设备属性变更推送
///
///
public override void DeviceAttributePush(CommonDevice device)
{
if (dicRowInfo.ContainsKey(device.DeviceAddr) == false)
{
return;
}
var rowInfo = dicRowInfo[device.DeviceAddr];
Application.RunOnMainThread(() =>
{
//刷新菜单
rowInfo.MenuRow?.RefreshControlInfo(false);
});
}
#endregion
#region ■ 开启设备在线线程___________________
///
/// 开启设备在线线程
///
/// 网关的在线状态
private void StartDeviceListControlThread(bool gatewayOnline)
{
if (gatewayOnline == false)
{
//设置全部设备离线
this.SetAllDeviceOffLine();
return;
}
//开启传感器报警监视
this.StartCheckDeviceAlarm();
//开启设备在线监测
this.StartCheckDeviceOnline();
}
#endregion
#region ■ 设备在线___________________________
///
/// 开启设备在线监测
///
private void StartCheckDeviceOnline()
{
//外部调用的话,不再重新获取设备状态
if (GatewayResourse.NowSelectGateway == null || this.reGetDeviceOnlineStatu == false)
{
return;
}
string gwId = HdlGatewayLogic.Current.GetGatewayId(GatewayResourse.NowSelectGateway);
HdlThreadLogic.Current.RunThread(() =>
{
//这里主要只是获取在线状态
var zbway = HdlGatewayLogic.Current.GetLocalGateway(gwId);
var result = Common.LocalDevice.Current.GetDeviceListFromGateway(zbway, false, this.ReceiveDeviceStatuPush, ShowErrorMode.NO);
});
}
///
/// 接受设备在线推送
///
///
private void ReceiveDeviceStatuPush(CommonDevice device)
{
lock (dicRowInfo)
{
if (this.Parent == null)
{
return;
}
DeviceObjRowInfo rowInfo = null;
if (this.dicRowInfo.ContainsKey(device.DeviceAddr) == true)
{
rowInfo = this.dicRowInfo[device.DeviceAddr];
}
if (rowInfo == null || rowInfo.MenuRow == null)
{
return;
}
//刷新设备的在线状态
string mainkeys = Common.LocalDevice.Current.GetDeviceMainKeys(device);
var localDevice = Common.LocalDevice.Current.GetDevice(mainkeys);
if (localDevice != null)
{
//在线状态一样的话,不需要刷新
if (localDevice.IsOnline == device.IsOnline)
{
return;
}
//保存状态
localDevice.IsOnline = device.IsOnline;
localDevice.ReSave();
}
HdlThreadLogic.Current.RunMain(() =>
{
if (rowInfo != null)
{
rowInfo.MenuRow.isOnline = device.IsOnline == 1;
if (rowInfo.dicDetailRow != null)
{
foreach (var detailRow in rowInfo.dicDetailRow.Values)
{
detailRow.isOnline = rowInfo.MenuRow.isOnline;
}
}
}
});
}
}
///
/// 设置全部设备离线
///
private void SetAllDeviceOffLine()
{
lock (dicRowInfo)
{
foreach (var rowInfo in this.dicRowInfo.Values)
{
Application.RunOnMainThread(() =>
{
if (rowInfo.MenuRow != null)
{
rowInfo.MenuRow.isOnline = false;
}
});
}
}
}
#endregion
#region ■ 设备新版本_________________________
///
/// 检测设备新版本
///
/// ota设备
private void CheckDeviceNewVersion(List list)
{
HdlThreadLogic.Current.RunThread(async () =>
{
await System.Threading.Tasks.Task.Delay(2000);
foreach (var ota in list)
{
if (this.Parent == null)
{
return;
}
//添加升级固件信息(成不成功都无所谓)
var result = await HdlFirmwareUpdateLogic.AddFirmwareVersionInfo(FirmwareLevelType.ZigbeeDevice, ota.HwVersion.ToString(), ota.ImgTypeId.ToString());
//获取设备最新版本
var deviceFirmware = HdlFirmwareUpdateLogic.GetFirmwareMostVersionInfo(FirmwareLevelType.ZigbeeDevice,
ota.HwVersion.ToString(),
ota.ImgTypeId.ToString(),
ota.ImgVersion);
if (deviceFirmware == null)
{
continue;
}
//拥有新版本
Application.RunOnMainThread(() =>
{
if (this.dicRowInfo.ContainsKey(ota.DeviceAddr) == true)
{
var row = this.dicRowInfo[ota.DeviceAddr].MenuRow;
if (row != null)
{
var btnNew = (InformationTipView)row.GetTagByKey("btnNew");
if (btnNew != null)
{
btnNew.Visible = true;
}
}
}
});
}
});
}
#endregion
#region ■ 传感器报警_________________________
///
/// 开启传感器报警监视
///
private void StartCheckDeviceAlarm()
{
HdlDeviceAttributeLogic.Current.AddAttributeEvent("DeviceListFormSensor", "IASInfoReport", (device) =>
{
Application.RunOnMainThread(() =>
{
if (this.dicRowInfo.ContainsKey(device.DeviceAddr) == false)
{
return;
}
var row = this.dicRowInfo[device.DeviceAddr].MenuRow;
if (row != null)
{
row.frameTable.StartSelectStatuAppeal(3000);
}
});
});
}
#endregion
#region ■ 实现外部调用_______________________
///
/// 添加新的设备到界面桌布中
///
/// 设备Mac地址
public void AddDeviceToFormTable(string deviceAddr)
{
//新建一个对象
if (this.dicRowInfo.ContainsKey(deviceAddr) == false)
{
var localDevice = Common.LocalDevice.Current.GetDevicesByMac(deviceAddr);
var rowNewInfo = new DeviceObjRowInfo();
rowNewInfo.DeviceMac = deviceAddr;
rowNewInfo.MacName = Common.LocalDevice.Current.GetDeviceMacName(localDevice[0]);
rowNewInfo.DeviveTypeName = Common.LocalDevice.Current.GetDeviceObjectText(localDevice);
this.dicRowInfo[deviceAddr] = rowNewInfo;
//创建新的行
this.AddDeviceMenuRow(deviceAddr);
return;
}
}
#endregion
#region ■ 合并数据___________________________
///
/// 根据MAC合并设备列表
///
///
private void MargeAllDeviceByMac(List listDevice)
{
//根据Mac全部分组
var dic = new Dictionary>();
foreach (CommonDevice device in listDevice)
{
if (device == null || device.DeviceAddr == null)
{
continue;
}
if (dic.ContainsKey(device.DeviceAddr) == false)
{
dic[device.DeviceAddr] = new List();
}
dic[device.DeviceAddr].Add(device);
}
//获取信息
foreach (var mac in dic.Keys)
{
var info = new DeviceObjRowInfo();
info.DeviceMac = mac;
info.MacName = Common.LocalDevice.Current.GetDeviceMacName(dic[mac][0]);
info.DeviveTypeName = Common.LocalDevice.Current.GetDeviceObjectText(dic[mac]);
this.dicRowInfo[mac] = info;
}
}
#endregion
#region ■ 关闭界面___________________________
///
/// 画面关闭
///
public override void CloseForm()
{
HdlDeviceAttributeLogic.Current.RemoveEvent("DeviceListFormSensor");
HdlDeviceAttributeLogic.Current.RemoveEvent("DeviceListFormReceivePushOnline");
GatewayResourse.NowSelectGateway = null;
base.CloseForm();
}
#endregion
#region ■ 界面重新激活事件___________________
///
/// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
///
public override int FormActionAgainEvent()
{
if (this.nowActionDeviceMac != null)
{
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)
{
foreach (var contr in rowInfo.dicDetailRow.Values)
{
contr?.RefreshControlInfo();
}
}
}
}
//清空记录
this.nowActionDeviceMac = null;
//网关控件刷新
this.gatewayViewRow.RefreshControl();
return 1;
}
#endregion
#region ■ 结构体类___________________________
///
/// 设备行信息
///
private class DeviceObjRowInfo
{
///
/// 设备Mac地址
///
public string DeviceMac = string.Empty;
///
/// 设备的MAC名字
///
public string MacName = string.Empty;
///
/// 设备类型的文本信息
///
public string DeviveTypeName = string.Empty;
///
/// 菜单行
///
public DeviceObjectControl MenuRow = null;
///
/// 桌布FrameLayout
///
public FrameListControl frameTable = null;
///
/// 明细行
///
public Dictionary dicDetailRow = null;
}
#endregion
#region ■ 自定义网关控件_____________________
///
/// 自定义网关控件
///
private class MyGatewayControl : FrameRowControl
{
///
/// 网关ID
///
public string zbGatewayId = string.Empty;
///
/// 网关名字控件
///
private NormalViewControl btnName = null;
///
/// 自定义网关控件
///
/// 网关对象
public MyGatewayControl(ZbGateway i_zbGateway)
{
this.UseClickStatu = false;
this.zbGatewayId = HdlGatewayLogic.Current.GetGatewayId(i_zbGateway);
this.BackgroundColor = UserCenterColor.Current.White;
this.Height = Application.GetRealHeight(173);
}
///
/// 初始化控件
///
public void InitControl()
{
//获取本地网关对象
ZbGateway zbway = HdlGatewayLogic.Current.GetLocalGateway(zbGatewayId);
//图标
var btnIcon = this.AddLeftIcon(81);
HdlGatewayLogic.Current.SetGatewayIcon(btnIcon, zbway);
//显示文本
btnName = this.AddLeftCaption(HdlGatewayLogic.Current.GetGatewayName(zbway), 700);
btnName.Height = Application.GetRealHeight(60);
btnName.TextSize = 15;
btnName.Y = Application.GetRealHeight(35);
if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbway) == false)
{
btnName.TextColor = UserCenterColor.Current.TextGrayColor1;
}
//当前网关
var btnNowGw = this.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uNowGateway), 700);
btnNowGw.Height = Application.GetRealHeight(49);
btnNowGw.TextSize = 12;
btnNowGw.Y = Application.GetRealHeight(95);
btnNowGw.TextColor = UserCenterColor.Current.TextGrayColor1;
//向右图标
var btnRight = this.AddRightArrow();
btnRight.Name = "btnRight";
//网关管理
var btnMament = this.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uGatewayManagement), 300);
btnMament.Name = "btnMament";
this.ButtonClickEvent += (sernder, e) =>
{
if (string.IsNullOrEmpty(((View)sernder).Name) == false)
{
//打开网关列表界面
var form = new GatewayManage.GatewayListForm();
form.AddForm();
}
};
}
///
/// 刷新控件信息
///
public void RefreshControl()
{
//获取本地网关对象
ZbGateway zbway = HdlGatewayLogic.Current.GetLocalGateway(zbGatewayId);
if (zbway == null)
{
return;
}
btnName.Text = HdlGatewayLogic.Current.GetGatewayName(zbway);
if (HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbway) == false)
{
btnName.TextColor = UserCenterColor.Current.TextGrayColor1;
}
else
{
btnName.TextColor = UserCenterColor.Current.TextColor1;
}
}
}
#endregion
}
}