HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-10-18 97e259d966cb5cb5d73c105d5dbaadcc1f920614
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
using System;
using ZigBee.Device;
using System.Collections.Generic;
 
namespace Shared.Phone.UserCenter.GatewayManage
{
    /// <summary>
    /// 编辑网关信息的画面UI★
    /// </summary>
    public class GatewayInfoEditorForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 网关名称控件
        /// </summary>
        private FrameCaptionInputControl rowGateway = null;
        /// <summary>
        /// 设备明细列表控件的桌布
        /// </summary>
        private DeviceInformationListControl listDeviceControl = null;
        /// <summary>
        /// 当前选择的网关
        /// </summary>
        private ZbGateway zbGateway = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_zbGateway">当前选择的网关</param>
        public void ShowForm(ZbGateway i_zbGateway)
        {
            this.zbGateway = i_zbGateway;
 
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uEditorGatewayInformation));
 
            //网关定位
            var btnIcon = new MostRightIconControl(69, 69);
            btnIcon.UnSelectedImagePath = "Item/Test.png";
            topFrameLayout.AddChidren(btnIcon);
            btnIcon.InitControl();
 
            btnIcon.ButtonClickEvent += (sender, e) =>
            {
                //测试
                HdlGatewayLogic.Current.SetFixedPositionCommand(i_zbGateway);
            };
 
            //初始化中部控件
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //图片上下的间距(上下间距一致)
            int picSpcae = Application.GetRealHeight(100);
            //图片
            var btnImage = new PicViewControl(838, 530, true);
            btnImage.Y = picSpcae;
            btnImage.Gravity = Gravity.CenterHorizontal;
            HdlGatewayLogic.Current.SetRealGatewayPictrue(btnImage, zbGateway);
            bodyFrameLayout.AddChidren(btnImage);
 
            //完成按钮
            var btnFinish = new BottomClickButton();
            btnFinish.TextID = R.MyInternationalizationString.uFinish;
            bodyFrameLayout.AddChidren(btnFinish);
            btnFinish.MouseUpEventHandler += (sender, e) =>
            {
                //完成按钮按下
                this.FinishButtonClick();
            };
 
            //白色底部背景
            var frameBottomWhite = new FrameLayout();
            frameBottomWhite.Y = btnFinish.Y - ControlCommonResourse.BottomButtonAndListViewSpace;
            frameBottomWhite.Height = bodyFrameLayout.Height - btnFinish.Y + ControlCommonResourse.BottomButtonAndListViewSpace;
            frameBottomWhite.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameBottomWhite);
            //将完成按钮置顶
            btnFinish.BringToFront();
 
            //自定义的设备列表容器
            this.listDeviceControl = new DeviceInformationListControl();
            //列表控件最大的高度(完成按钮的Y轴 - 设置的间隔 - 图片Y轴 - 图片的三分之一)
            int listViewMaxHeight = btnFinish.Y - ControlCommonResourse.BottomButtonAndListViewSpace - btnImage.Y - btnImage.Height / 3;
            //明细Frame的最小高度(底部frame的Y轴 - 图片底部 - 图片与弧度圆的间距 - 弧度圆高度)
            int minDetailHeight = frameBottomWhite.Y - btnImage.Bottom - picSpcae - listDeviceControl.halfRoundHeigth;
            //初始化控件
            listDeviceControl.InitControl(bodyFrameLayout, frameBottomWhite.Height, listViewMaxHeight, minDetailHeight, 4);
 
            //设备编辑
            var btnTitle = new DetailTitleControl(Application.GetRealWidth(800), listDeviceControl.titleHeight, false);
            btnTitle.TextID = R.MyInternationalizationString.uDeviceEditor;
            listDeviceControl.AddChidren(btnTitle);
 
            //添加全部菜单行
            this.AddAllMenuRow();
        }
 
        #endregion
 
        #region ■ 添加全部菜单行_____________________
 
        /// <summary>
        /// 添加全部菜单行
        /// </summary>
        private void AddAllMenuRow()
        {
            //网关名称
            string caption = Language.StringByID(R.MyInternationalizationString.uGatewayName);
            string nameValue = HdlGatewayLogic.Current.GetGatewayName(zbGateway);
            this.rowGateway = new FrameCaptionInputControl(caption, nameValue);
            listDeviceControl.AddChidren(rowGateway);
            rowGateway.InitControl();
            rowGateway.AddBottomLine();
 
            //网关IP
            caption = Language.StringByID(R.MyInternationalizationString.uGatewayIP);
            nameValue = HdlGatewayLogic.Current.GetGatewayBaseInfoAttribute(zbGateway, "IpAddress").ToString();
            var btnIp = new FrameCaptionViewControl(caption, nameValue);
            listDeviceControl.AddChidren(btnIp);
            btnIp.InitControl();
            btnIp.txtView.TextColor = UserCenterColor.Current.TextGrayColor;
            btnIp.AddBottomLine();
            //主网关或者子网关标识
            var btnFlage = new RowMostRightTextView();
            btnFlage.TextColor = UserCenterColor.Current.TextGrayColor;
            btnIp.AddChidren(btnFlage, ChidrenBindMode.NotBind);
            int result = HdlGatewayLogic.Current.IsMainGateway(this.zbGateway);
            //主网关
            if (result == 1) { btnFlage.TextID = R.MyInternationalizationString.uMainGateway; }
            //子网关
            else if (result == 0) { btnFlage.TextID = R.MyInternationalizationString.uChidrenGateway; }
 
            //网关类型
            caption = Language.StringByID(R.MyInternationalizationString.uGatewayType);
            //nameValue = HdlGatewayLogic.Current.GetGatewayImageText(this.zbGateway);
            var btnObject = new FrameCaptionViewControl(caption, nameValue);
            listDeviceControl.AddChidren(btnObject);
            btnObject.InitControl();
            btnObject.txtView.TextColor = UserCenterColor.Current.TextGrayColor;
            btnObject.AddBottomLine();
 
            //固件信息
            this.AddHardWareInfoRow();
        }
 
        #endregion
 
        #region ■ 添加固件信息行_____________________
 
        /// <summary>
        /// 添加固件信息行
        /// </summary>
        private void AddHardWareInfoRow()
        {
            var rowInfo = new RowLayoutControl();
            listDeviceControl.AddChidren(rowInfo);
 
            //固件信息
            //var btnInfo = new RowCenterViewControl(false, 14);
            //btnInfo.TextID = R.MyInternationalizationString.uFirmwareInformation;
            //rowInfo.AddChidren(btnInfo);
 
            //向右图标
            //rowInfo.AddRightArrow();
 
            //新版本提示控件
            var btnNewVersion = new RowNewVersionTipView();
            btnNewVersion.Visible = false;
            rowInfo.AddChidren(btnNewVersion);
 
            //rowInfo.MouseUpEvent += (sender, e) =>
            //{
            //    btnNewVersion.Visible = false;
            //    var form = new GatewayFirmwareInfoForm();
            //    form.AddForm(zbGateway);
            //};
 
            //检测新版本
            this.CheckNewVersion(btnNewVersion);
        }
 
        /// <summary>
        /// 检测新版本
        /// </summary>
        /// <param name="btnNewVersion">提示有新版本的控件</param>
        private async void CheckNewVersion(RowNewVersionTipView btnNewVersion)
        {
            //打开进度条
            this.ShowProgressBar();
 
            //获取网关版本信息
            var result = await HdlGatewayLogic.Current.GetGatewayAllNewVersion(this.zbGateway);
            if (result == null)
            {
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                return;
            }
            //关闭进度条
            this.CloseProgressBar();
 
            Application.RunOnMainThread(() =>
            {
                if (this.rowGateway != null)
                {
                    //设置网关名称
                    this.rowGateway.Text = HdlGatewayLogic.Current.GetGatewayName(zbGateway);
                    if (result[0] != null || result[1] != null || result[2] != null)
                    {
                        //提示有新版本
                        btnNewVersion.Visible = true;
                    }
                }
            });
        }
 
        #endregion
 
        #region ■ 完成按钮按下_______________________
 
        /// <summary>
        /// 完成按钮按下
        /// </summary>
        private void FinishButtonClick()
        {
            if (string.IsNullOrEmpty(this.rowGateway.Text) == true)
            {
                //请输入网关名称
                this.rowGateway.Text = string.Empty;
                string msg = Language.StringByID(R.MyInternationalizationString.uGatewayNameMastInput);
                this.ShowMassage(ShowMsgType.Error, msg);
                return;
            }
            string nameValue = HdlGatewayLogic.Current.GetGatewayName(zbGateway);
            if (nameValue == this.rowGateway.Text)
            {
                //同名不需要处理
                this.CloseForm();
                return;
            }
            //修改名字
            this.SetGatewayName(this.rowGateway.Text);
        }
 
        #endregion
 
        #region ■ 修改名字___________________________
 
        /// <summary>
        /// 设置网关名字
        /// </summary>
        /// <param name="gatewayName">网关名称</param>
        private async void SetGatewayName(string gatewayName)
        {
            //打开进度条
            this.ShowProgressBar();
            //修改网关名
            var result = await HdlGatewayLogic.Current.ReName(zbGateway, gatewayName);
            //关闭进度条
            this.CloseProgressBar();
 
            //网关修改失败
            if (result == false)
            {
                return;
            }
            Application.RunOnMainThread(() =>
            {
                //关闭界面
                this.CloseForm();
            });
        }
        #endregion
    }
}