gxc
2019-10-28 1c4904d77f484c075080942d87785481b52b6fb2
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.GatewayAdd
{
    /// <summary>
    /// 编辑新添加的网关信息的画面UI
    /// </summary>
    public class GatewayInfoAddForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 网关名称控件
        /// </summary>
        private FrameCaptionInputControl rowGateway = null;
        /// <summary>
        /// 网关名字修改后的回调函数
        /// </summary>
        public Action<ZbGateway> ActionGatewayReName = null;
        /// <summary>
        /// 当前选择的网关
        /// </summary>
        private ZbGateway zbGateway = null;
        /// <summary>
        /// 设备明细列表控件的桌布
        /// </summary>
        private DeviceInformationListControl listDeviceControl = 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.SetTestCommand(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, 3);
 
            //设备编辑
            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();
 
            //网关类型
            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();
        }
 
        #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.ActionGatewayReName?.Invoke(zbGateway);
                //关闭界面
                this.CloseForm();
            });
        }
        #endregion
 
        #region ■ 关闭界面___________________________
 
        /// <summary>
        /// 画面关闭
        /// </summary>
        public override void CloseForm()
        {
            this.ActionGatewayReName = null;
            base.CloseForm();
        }
 
        #endregion
    }
}