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
219
220
221
222
223
224
225
226
227
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 做成一个显示网关信息的RowLayout(左边有个图标)
    /// </summary>
    public class GatewayViewRow : StatuRowLayout
    {
        /// <summary>
        /// 网关对象
        /// </summary>
        private ZbGateway m_zbGateway = null;
        /// <summary>
        /// 网关对象(优先缓存的网关对象,其次才是真实网关)
        /// </summary>
        public ZbGateway zbGateway
        {
            get { return m_zbGateway; }
            set
            {
                string gwID = Common.LocalGateway.Current.GetGatewayId(value);
                var way = Common.LocalGateway.Current.GetLocalGateway(gwID);
                if (way != null)
                {
                    m_zbGateway = way;
                }
                else
                {
                    m_zbGateway = value;
                }
            }
        }
        /// <summary>
        /// 图标控件
        /// </summary>
        public RowLeftIconView btnIcon = null;
        /// <summary>
        /// 显示文本控件
        /// </summary>
        public RowTopBlackView btnName = null;
        /// <summary>
        /// 在线状态的控件
        /// </summary>
        public RowSecondRightTextView btnOnline = null;
        /// <summary>
        /// IP的控件
        /// </summary>
        public RowBottomGrayView btnIP = null;
 
        private bool m_IsOnline = false;
        /// <summary>
        /// 在线状态
        /// </summary>
        public bool IsOnline
        {
            get { return m_IsOnline; }
            set
            {
                m_IsOnline = value;
                //变更状态
                this.SetOnlineStatu(m_IsOnline);
            }
        }
 
        /// <summary>
        /// 显示主或者子网关的字样
        /// </summary>
        private bool m_ShowMainGatewayTip = true;
        /// <summary>
        /// 显示主或者子网关的字样
        /// </summary>
        public bool ShowMainGatewayTip
        {
            get { return m_ShowMainGatewayTip; }
            set
            {
                m_ShowMainGatewayTip = value;
                //设置IP的文本信息
                this.SetbtnIpText();
            }
        }
 
        /// <summary>
        /// 做成一个显示网关信息的RowLayout(左边有个图标)
        /// </summary>
        /// <param name="listView">列表控件</param>
        /// <param name="i_zbGateway">网关对象</param>
        public GatewayViewRow(VerticalScrolViewLayout listView, ZbGateway i_zbGateway)
        {
            this.m_zbGateway = i_zbGateway;
 
            listView.AddChidren(this);
            //初始化内部控件之前
            this.InitControlBefore(i_zbGateway);
            //初始化内部控件
            this.InitControl();
        }
 
        /// <summary>
        /// 做成一个显示网关信息的RowLayout(左边有个图标),添加此控件到容器后,调用【InitControl()】完成初始化
        /// </summary>
        /// <param name="i_zbGateway">网关对象</param>
        public GatewayViewRow(ZbGateway i_zbGateway)
        {
            this.m_zbGateway = i_zbGateway;
 
            //初始化内部控件之前
            this.InitControlBefore(i_zbGateway);
        }
 
        /// <summary>
        /// 初始化内部控件
        /// </summary>
        public void InitControl()
        {
            //图标
            this.AddChidren(this.btnIcon);
 
            //显示文本
            this.AddChidren(this.btnName);
 
            //IP
            this.AddChidren(this.btnIP);
 
            //在线状态
            this.AddChidren(this.btnOnline, ChidrenBindMode.BindEventOnly);
        }
 
        /// <summary>
        /// 刷新控件
        /// </summary>
        /// <param name="online"></param>
        public void RefreshControl(bool online)
        {
            this.IsOnline = online;
            this.btnName.Text = Common.LocalGateway.Current.GetGatewayName(this.m_zbGateway);
 
            this.SetbtnIpText();
        }
 
        /// <summary>
        /// 初始化内部控件之前
        /// </summary>
        /// <param name="i_zbGateway">网关</param>
        private void InitControlBefore(ZbGateway i_zbGateway)
        {
            this.btnIcon = new RowLeftIconView();
            Common.LocalGateway.Current.SetGatewayIcon(btnIcon, i_zbGateway);
 
            this.btnName = new RowTopBlackView();
            this.btnName.Text = Common.LocalGateway.Current.GetGatewayName(i_zbGateway);
            if (this.btnName.Text == string.Empty)
            {
                //无法识别的网关设备
                this.btnName.TextID = R.MyInternationalizationString.uUnDistinguishTheGatewayDevice;
            }
 
            this.btnOnline = new RowSecondRightTextView();
            this.btnOnline.Radius = 4;
 
            ZbGateway realWay = null;
            bool bonline = false;
            if (Common.LocalGateway.Current.GetRealGateway(ref realWay, i_zbGateway) == true)
            {
                bonline = Common.LocalGateway.Current.CheckGatewayOnlineByFlag(realWay);
            }
            this.SetOnlineStatu(bonline);
 
            this.btnIP = new RowBottomGrayView();
            //设置IP的文本信息
            this.SetbtnIpText();
        }
 
        /// <summary>
        /// 设置IP的文本信息
        /// </summary>
        private void SetbtnIpText()
        {
            this.btnIP.Text = Common.LocalGateway.Current.GetGatewayBaseInfoAttribute(this.m_zbGateway, "IpAddress").ToString();
            if (string.IsNullOrEmpty(this.btnIP.Text) == false && m_ShowMainGatewayTip == true && this.m_IsOnline == true)
            {
                int result = Common.LocalGateway.Current.IsMainGateway(this.m_zbGateway);
                if (result == 1)
                {
                    //主网关
                    this.btnIP.Text += " (" + Language.StringByID(R.MyInternationalizationString.uMainGateway) + ")";
                }
                else if (result == 0)
                {
                    //子网关
                    this.btnIP.Text += " (" + Language.StringByID(R.MyInternationalizationString.uChidrenGateway) + ")";
                }
            }
        }
 
        /// <summary>
        /// 设置在线状态
        /// </summary>
        /// <param name="online"></param>
        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;
            }
        }
    }
}