xm
2020-12-14 d6fb0646531172f23648441c224cdcccd721b894
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/DeviceControls/GatewayRowControl.cs
New file
@@ -0,0 +1,218 @@
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
namespace Shared.Phone.UserCenter
{
    public class GatewayRowControl : RowLayoutControl
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 网关ID
        /// </summary>
        private string zbGatewayId = string.Empty;
        /// <summary>
        /// 网关对象(优先缓存的网关对象,其次才是真实网关)
        /// </summary>
        public ZbGateway zbGateway
        {
            get
            {
                //获取本地网关对象
                ZbGateway zbway = HdlGatewayLogic.Current.GetLocalGateway(zbGatewayId);
                if (zbway != null)
                {
                    return zbway;
                }
                //获取真实物理网关对象
                HdlGatewayLogic.Current.GetRealGateway(ref zbway, zbGatewayId);
                return zbway;
            }
        }
        /// <summary>
        /// 显示文本控件
        /// </summary>
        public NormalViewControl btnName = null;
        /// <summary>
        /// 图标控件
        /// </summary>
        public IconViewControl btnIcon = null;
        /// <summary>
        /// 显示IP控件
        /// </summary>
        public NormalViewControl btnIp = null;
        /// <summary>
        /// 在线状态
        /// </summary>
        private bool m_IsOnline = false;
        /// <summary>
        /// 在线状态
        /// </summary>
        public bool IsOnline
        {
            get { return m_IsOnline; }
            set
            {
                if (m_IsOnline != value)
                {
                    m_IsOnline = value;
                    //变更状态
                    this.SetOnlineStatu(m_IsOnline);
                }
            }
        }
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 做成一个显示网关信息的RowLayout,添加此控件到容器后,调用【InitControl()】完成初始化
        /// </summary>
        /// <param name="i_zbGateway">网关对象</param>
        /// <param name="ChidrenYaxis">子控件Y轴偏移量(【列表控件的rowSpace/2】即可,不懂默认为0即可)</param>
        public GatewayRowControl(ZbGateway i_zbGateway, int i_ChidrenYaxis = 0) : base(i_ChidrenYaxis)
        {
            this.zbGatewayId = i_zbGateway.GwId;
        }
        /// <summary>
        /// 初始化内部控件
        /// </summary>
        /// <param name="iconSize">左边图标大小(有些界面图标大小不一致)</param>
        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.AddTopView(wayName, 700);
            //IP
            this.btnIp = frameTable.AddBottomView(tempWay != null ? tempWay.GwIP : string.Empty, 600);
            //初始值在线
            this.IsOnline = true;
            if (tempWay != null)
            {
                //刷新网关信息
                HdlThreadLogic.Current.RunThread(() =>
                {
                    var result = HdlGatewayLogic.Current.GetGatewayInfo(tempWay, false, ShowErrorMode.NO);
                    if (result != null)
                    {
                        HdlThreadLogic.Current.RunMain(() =>
                        {
                            //刷新控件
                            this.RefreshControl(tempWay);
                        });
                    }
                });
            }
        }
        #endregion
        #region ■ 刷新控件___________________________
        /// <summary>
        /// 刷新控件
        /// </summary>
        /// <param name="zbway">网关对象(为null时,使用控件内部的数据进行刷新)</param>
        public void RefreshControl(ZbGateway zbway)
        {
            if (zbway != null)
            {
                this.zbGatewayId = zbway.GwId;
            }
            bool bonline = HdlGatewayLogic.Current.CheckGatewayOnlineByMemory(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 ■ 在线状态___________________________
        /// <summary>
        /// 设置在线状态
        /// </summary>
        /// <param name="online"></param>
        private void SetOnlineStatu(bool online)
        {
            m_IsOnline = online;
            if (online == false)
            {
                btnName.TextColor = UserCenterColor.Current.TextGrayColor2;
            }
            else
            {
                btnName.TextColor = UserCenterColor.Current.TextColor1;
            }
        }
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
        /// 更改控件高度
        /// </summary>
        /// <param name="i_height">非真实值</param>
        public void ChangedHight(int i_height)
        {
            if (frameTable != null)
            {
                frameTable.Height = Application.GetRealHeight(i_height);
            }
            this.Height = Application.GetRealHeight(i_height);
        }
        #endregion
    }
}