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 IconViewControl btnIcon = null; /// /// 显示文本控件 /// public NormalViewControl btnName = null; /// /// 在线状态的控件 /// public NormalViewControl btnOnline = 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); } this.btnName = frameTable.AddLeftCaption(wayName, 700); this.btnName.Text = wayName; tempWay = null; } #endregion #region ■ 刷新控件___________________________ /// /// 刷新控件 /// /// 网关对象(为null时,使用控件内部的数据进行刷新) public void RefreshControl(ZbGateway zbway) { if (zbway != null) { this.zbGatewayId = HdlGatewayLogic.Current.GetGatewayId(zbway); } ZbGateway realWay = null; bool bonline = false; if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, this.zbGatewayId) == true) { bonline = HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(realWay); } this.IsOnline = bonline; this.btnName.Text = HdlGatewayLogic.Current.GetGatewayName(this.zbGateway); realWay = null; } #endregion #region ■ 在线状态___________________________ /// /// 添加在线状态的控件(右边有图标的话,先添加图标,再添加此控件) /// public void AddOnLineControl() { this.btnOnline = frameTable.AddMostRightView(string.Empty, 270); ZbGateway realWay = null; bool bonline = false; if (HdlGatewayLogic.Current.GetRealGateway(ref realWay, zbGateway) == true) { bonline = HdlGatewayLogic.Current.CheckGatewayOnlineByFlag(realWay); } this.SetOnlineStatu(bonline); } /// /// 设置在线状态 /// /// private void SetOnlineStatu(bool online) { m_IsOnline = online; if (btnOnline == null) { return; } if (online == false) { //初始值:离线 btnOnline.TextID = R.MyInternationalizationString.uOffLine; //初始值:灰色 btnOnline.TextColor = UserCenterColor.Current.Gray; } else { //在线 btnOnline.TextID = R.MyInternationalizationString.uOnline; //绿色 btnOnline.TextColor = UserCenterColor.Current.Green; } } #endregion #region ■ 一般方法___________________________ /// /// 更改控件高度 /// /// 非真实值 public void ChangedHight(int i_height) { if (frameTable != null) { frameTable.Height = Application.GetRealHeight(i_height); } this.Height = Application.GetRealHeight(i_height); } #endregion } }