黄学彪
2020-09-22 ade5917841b0fdcb1df7353ef7c56b1a1bdc9282
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.GatewayManage
{
    /// <summary>
    /// 搜索得到的网关的列表界面
    /// </summary>
    public class GatewaySearchListForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 搜索到的网关列表
        /// </summary>
        private List<ZbGateway> listZbGateway = null;
        /// <summary>
        /// 搜索到的网关类别  0:第一次绑定 1:已经绑定 2:需要换绑
        /// </summary>
        private Dictionary<string, int> dicZbGatewayDiv = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_listZbGateway">搜索到的网关列表</param>
        /// <param name="i_dicZbGatewayDiv">搜索到的网关类别  0:第一次绑定 1:已经绑定 2:需要换绑</param>
        public void ShowForm(List<ZbGateway> i_listZbGateway, Dictionary<string, int> i_dicZbGatewayDiv)
        {
            this.listZbGateway = i_listZbGateway;
            this.dicZbGatewayDiv = i_dicZbGatewayDiv;
 
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddGateway));
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            var frameBack = new FrameLayout();
            frameBack.Height = Application.GetRealHeight(23);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameBack);
 
            var listView = new VerticalListControl(12);
            listView.Y = frameBack.Bottom;
            listView.BackgroundColor = UserCenterColor.Current.White;
            listView.Height = bodyFrameLayout.Height - frameBack.Height;
            bodyFrameLayout.AddChidren(listView);
 
            HdlThreadLogic.Current.RunMainInThread(() =>
            {
                //添加网关行
                for (int i = 0; i < listZbGateway.Count; i++)
                {
                    this.AddGatewayRow(listView, listZbGateway[i], i != listZbGateway.Count - 1);
                }
                listView.AdjustRealHeight(Application.GetRealHeight(23));
            });
        }
 
        #endregion
 
        #region ■ 添加网关行_________________________
 
        /// <summary>
        /// 添加网关行
        /// </summary>
        /// <param name="listView"></param>
        /// <param name="gateway"></param>
        /// <param name="addLine"></param>
        private void AddGatewayRow(VerticalListControl listView, ZbGateway gateway, bool addLine)
        {
            string gwid = gateway.GwId;
            if (this.dicZbGatewayDiv[gwid] != 2)
            {
                //如果本地没有,那么应该是在之后的编辑界面删除了
                if (HdlGatewayLogic.Current.IsGatewayExist(gwid) == false)
                {
                    return;
                }
            }
 
            var frameRow = new RowLayoutControl(listView.rowSpace / 2);
            listView.AddChidren(frameRow);
            //图标
            var btnIcon = frameRow.frameTable.AddLeftIcon(81);
            HdlGatewayLogic.Current.SetGatewayIcon(btnIcon, gateway);
            //网关名
            var wayName = HdlGatewayLogic.Current.GetGatewayName(gateway);
            if (wayName == string.Empty)
            {
                //无法识别的网关设备
                wayName = Language.StringByID(R.MyInternationalizationString.uUnDistinguishTheGatewayDevice);
            }
            if (dicZbGatewayDiv[gwid] == 0)
            {
                //xxx(新)
                wayName += Language.StringByID(R.MyInternationalizationString.uNewTip1);
            }
            var btnName = frameRow.frameTable.AddLeftCaption(wayName, 700);
            btnName.TextSize = 15;
            //右箭头
            frameRow.frameTable.AddRightArrow();
            if (addLine == true)
            {
                //底线
                frameRow.frameTable.AddBottomLine();
            }
            frameRow.frameTable.ButtonClickEvent += (sender, e) =>
            {
                var form = new GatewayProductInfoForm();
                form.AddForm(gateway);
            };
 
            if (dicZbGatewayDiv[gwid] == 2)
            {
                //换绑
                var btnBind = new NormalViewControl(Application.GetRealWidth(184), frameRow.Height, false);
                btnBind.BackgroundColor = 0xfffb744a;
                btnBind.TextAlignment = TextAlignment.Center;
                btnBind.TextColor = UserCenterColor.Current.White;
                btnBind.TextSize = 12;
                btnBind.TextID = R.MyInternationalizationString.uReBindAgain;
                frameRow.AddRightView(btnBind);
                btnBind.ButtonClickEvent += (sender, e) =>
                {
                    //确认绑定旧网关?
                    string msg = Language.StringByID(R.MyInternationalizationString.uRebindGatewayMsg);
                    this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                    {
                        var form = new GatewayRebindForm();
                        form.AddForm(gateway, dicZbGatewayDiv);
                    });
                };
            }
            //定位
            var btnPosition = frameRow.AddEditorControl(false);
            btnPosition.TextID = R.MyInternationalizationString.uFixedPosition;
            btnPosition.ButtonClickEvent += (sender, e) =>
            {
                //发送定位命令
                HdlGatewayLogic.Current.SetFixedPositionCommand(gateway);
            };
        }
 
        #endregion
 
        #region ■ 界面重新激活事件___________________
 
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override int FormActionAgainEvent()
        {
            //初始化中部信息
            this.InitMiddleFrame();
            return 1;
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            var userPageForm = UserView.UserPage.Instance.GetNowActionForm();
            if (userPageForm != null && userPageForm.FormID == "UserMainForm")
            {
                //刷新主页
                UserView.UserPage.Instance.ReFreshControl();
            }
            base.CloseFormBefore();
        }
 
        #endregion
    }
}