黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone
{
    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.RefreshGatewayInfo(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
    }
}