using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.UserCenter
{
public class GatewayRowControl : RowLayoutControl
{
#region ■ 变量声明___________________________
///
/// 网关ID
///
private string zbGatewayId = string.Empty;
///
/// 网关对象(优先缓存的网关对象,其次才是真实网关)
///
public ZbGateway zbGateway
{
get
{
//获取本地网关对象
ZbGateway zbway = HdlGatewayLogic.Current.GetLocalGateway(zbGatewayId);
if (zbway != null)
{
return zbway;
}
//获取真实物理网关对象
HdlGatewayLogic.Current.GetRealGateway(ref zbway, zbGatewayId);
return zbway;
}
}
///
/// 显示文本控件
///
public NormalViewControl btnName = null;
///
/// 图标控件
///
public IconViewControl btnIcon = null;
///
/// 显示IP控件
///
private NormalViewControl btnIp = null;
///
/// 在线状态
///
private bool m_IsOnline = false;
///
/// 在线状态
///
public bool IsOnline
{
get { return m_IsOnline; }
set
{
m_IsOnline = value;
//变更状态
this.SetOnlineStatu(m_IsOnline);
}
}
#endregion
#region ■ 初始化_____________________________
///
/// 做成一个显示网关信息的RowLayout,添加此控件到容器后,调用【InitControl()】完成初始化
///
/// 网关对象
/// 子控件Y轴偏移量(有些界面需要这种特殊操作)
public GatewayRowControl(ZbGateway i_zbGateway, int i_ChidrenYaxis = 0) : base(i_ChidrenYaxis)
{
this.zbGatewayId = HdlGatewayLogic.Current.GetGatewayId(i_zbGateway);
}
///
/// 初始化内部控件
///
/// 左边图标大小(有些界面图标大小不一致)
public void InitControl(int iconSize)
{
var tempWay = this.zbGateway;
//图标
this.btnIcon = frameTable.AddLeftIcon(iconSize);
if (tempWay != null)
{
HdlGatewayLogic.Current.SetGatewayIcon(btnIcon, tempWay);
}
//显示文本
var wayName = tempWay != null ? HdlGatewayLogic.Current.GetGatewayName(tempWay) : string.Empty;
if (wayName == string.Empty)
{
//无法识别的网关设备
wayName = Language.StringByID(R.MyInternationalizationString.uUnDistinguishTheGatewayDevice);
}
else
{
var value = HdlGatewayLogic.Current.IsMainGateway(this.zbGatewayId);
if (value == 1)
{
//主网关
wayName += "(" + Language.StringByID(R.MyInternationalizationString.uMainGateway) + ")";
}
else if (value == 2)
{
//从网关
wayName += "(" + Language.StringByID(R.MyInternationalizationString.uChidrenGateway) + ")";
}
}
this.btnName = frameTable.AddLeftCaption(wayName, 700, 60);
btnName.TextSize = 15;
//这个坐标有点特殊
btnName.Y = Application.GetRealHeight(12) + this.chidrenYaxis;
frameTable.AddChidren(btnName, ChidrenBindMode.BindEventOnly);
//房间
string strIp = string.Empty;
if (tempWay != null)
{
strIp = tempWay.getGatewayBaseInfo.IpAddress;
}
this.btnIp = frameTable.AddLeftCaption(strIp, 600, 50, true);
//这个坐标有点特殊
btnIp.Y = Application.GetRealHeight(72) + this.chidrenYaxis;
btnIp.TextSize = 12;
btnIp.TextColor = UserCenterColor.Current.TextGrayColor1;
frameTable.AddChidren(btnIp, ChidrenBindMode.BindEventOnly);
//初始值在线
this.IsOnline = true;
}
#endregion
#region ■ 刷新控件___________________________
///
/// 刷新控件
///
/// 网关对象(为null时,使用控件内部的数据进行刷新)
public void RefreshControl(ZbGateway zbway)
{
if (zbway != null)
{
this.zbGatewayId = HdlGatewayLogic.Current.GetGatewayId(zbway);
}
bool bonline = HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(zbway);
this.IsOnline = bonline;
string wayName = HdlGatewayLogic.Current.GetGatewayName(this.zbGateway);
var value = HdlGatewayLogic.Current.IsMainGateway(this.zbGatewayId);
if (value == 1)
{
//主网关
wayName += "(" + Language.StringByID(R.MyInternationalizationString.uMainGateway) + ")";
}
else if (value == 2)
{
//从网关
wayName += "(" + Language.StringByID(R.MyInternationalizationString.uChidrenGateway) + ")";
}
this.btnName.Text = wayName;
}
#endregion
#region ■ 在线状态___________________________
///
/// 设置在线状态
///
///
private void SetOnlineStatu(bool online)
{
m_IsOnline = online;
if (online == false)
{
btnName.TextColor = UserCenterColor.Current.TextGrayColor2;
}
else
{
btnName.TextColor = UserCenterColor.Current.TextColor1;
}
}
#endregion
#region ■ 一般方法___________________________
///
/// 更改控件高度
///
/// 非真实值
public void ChangedHight(int i_height)
{
if (frameTable != null)
{
frameTable.Height = Application.GetRealHeight(i_height);
}
this.Height = Application.GetRealHeight(i_height);
}
#endregion
}
}