using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter
{
///
/// 做成一个显示设备类型+设备MAC备注的RowLayout
///
public class DeviceObjectControl : RowLayoutControl
{
#region ■ 变量声明___________________________
///
/// 设备的Mac地址
///
public string deviceMac = string.Empty;
///
/// 只会刷新一次
///
private bool hadRefresh = false;
///
/// 在线状态
///
private bool m_isOnline = false;
///
/// 在线状态
///
public bool isOnline
{
get { return m_isOnline; }
set
{
m_isOnline = value;
//设置在线状态的特效
this.SetOnlineStatu(m_isOnline);
}
}
///
/// 图标控件
///
public IconViewControl btnIcon = null;
///
/// 设备类型控件
///
private NormalViewControl btnDeviceObject = null;
///
/// 设备备注控件
///
private NormalViewControl btnDeviceName = null;
#endregion
#region ■ 初始化_____________________________
///
/// 做成一个显示设备类型+设备MAC备注的RowLayout
///
/// 设备的Mac地址
/// 子控件Y轴偏移量(真实值,有些界面需要这种特殊操作)
public DeviceObjectControl(string i_deviceMac, int i_ChidrenYaxis = 0) : base(i_ChidrenYaxis)
{
this.deviceMac = i_deviceMac;
}
///
/// 初始化内部控件
///
public void InitControl()
{
var listDevice = Common.LocalDevice.Current.GetDevicesByMac(this.deviceMac);
//图标
btnIcon = frameTable.AddLeftIcon(81);
Common.LocalDevice.Current.SetDeviceBeloneIconToControl(btnIcon, listDevice);
//设备类型
string objText = Common.LocalDevice.Current.GetDeviceObjectText(listDevice);
btnDeviceObject = frameTable.AddLeftCaption(objText, 800, 60, true);
btnDeviceObject.TextSize = 15;
//这个坐标有点特殊
btnDeviceObject.Y = Application.GetRealHeight(12) + this.chidrenYaxis;
btnDeviceObject.Text = Common.LocalDevice.Current.GetDeviceObjectText(listDevice);
frameTable.AddChidren(btnDeviceObject, ChidrenBindMode.BindEventOnly);
//设备
string deviceName = Common.LocalDevice.Current.GetDeviceMacName(listDevice[0]);
btnDeviceName = frameTable.AddLeftCaption(deviceName, 800, 49, true);
//这个坐标有点特殊
btnDeviceName.Y = Application.GetRealHeight(72) + this.chidrenYaxis;
btnDeviceName.TextSize = 12;
btnDeviceName.TextColor = UserCenterColor.Current.TextGrayColor1;
btnDeviceName.Text = Common.LocalDevice.Current.GetDeviceMacName(listDevice[0]);
frameTable.AddChidren(btnDeviceName, ChidrenBindMode.BindEventOnly);
//底线
frameTable.AddBottomLine();
//设置在线状态的特效
this.isOnline = listDevice[0].IsOnline == 1;
listDevice = null;
}
#endregion
#region ■ 一般方法___________________________
///
/// 设置在线状态的特效
///
///
private void SetOnlineStatu(bool isOnline)
{
if (isOnline == false)
{
btnDeviceObject.TextColor = UserCenterColor.Current.TextGrayColor1;
}
else
{
btnDeviceObject.TextColor = UserCenterColor.Current.TextColor1;
}
}
///
/// 刷新全部显示信息
///
/// 是否强制执行
public void RefreshControlInfo(bool compel = false)
{
if (hadRefresh == true && compel == false)
{
return;
}
hadRefresh = true;
var listDevice = Common.LocalDevice.Current.GetDevicesByMac(this.deviceMac);
//图标
Common.LocalDevice.Current.SetDeviceBeloneIconToControl(btnIcon, listDevice);
//设备类型
btnDeviceObject.Text = Common.LocalDevice.Current.GetDeviceObjectText(listDevice);
//设备
btnDeviceName.Text = Common.LocalDevice.Current.GetDeviceMacName(listDevice[0]);
//设置在线状态的特效
this.isOnline = listDevice[0].IsOnline == 1;
listDevice = null;
}
#endregion
}
}