xm
2019-07-16 b910cb79c9b5bcc204022a3cf9e6950f0a64dfbd
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
using System;
using System.Collections.Generic;
 
namespace Shared.Phone.UserCenter.User
{
    /// <summary>
    /// 个人中心主画面
    /// </summary>
    public class UserMainForm : UserCenterCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 个人布局的FrameLayout
        /// </summary>
        private SpecialFrameLayout persionFrameLayout = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建),
        /// 注意:因为外面的框架问题,在外面不能使用底层的方法
        /// 不然,可能会有些共通参数出错
        /// </summary>
        public void ShowForm()
        {
            //特殊处理:恢复可关闭进度条,别问为什么,我也不知道为什么,以防万一而已
            ProgressBar.SetCloseBarFlag(false);
            //复原管理员标识
            Common.Config.Instance.isAdministrator = false;
 
            //初始化框架
            this.InitForm();
 
            //移除返回键
            base.RemoveBackButton();
            //设定标题
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.UserCenter));
 
            //底层固定了加上底部的高度,这个画面需要显示底部,所以要减去底部高度
            bodyFrameLayout.Height -= ControlCommonResourse.BottomFrameHeight;
            //为了能够显示模块图样
            bodyFrameLayout.BackgroundColor = UserCenterColor.Current.TopFrameLayout;
 
            //初始化中部控件
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            bodyFrameLayout.RemoveAll();
 
            //初始化个人图标FrameLayout
            this.InitPersionFrameLayout();
 
            //初始化菜单列表的FrameLayout
            this.InitMenuFrameLayout();
        }
 
        /// <summary>
        /// 初始化个人布局的FrameLayout
        /// </summary>
        private void InitPersionFrameLayout()
        {
            persionFrameLayout = new SpecialFrameLayout(260, 30);
            persionFrameLayout.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
            bodyFrameLayout.AddChidren(persionFrameLayout);
 
            //用户头像
            var btnUserIcon = new ProfilePhotoControl();
            btnUserIcon.X = ControlCommonResourse.XXLeft;
            btnUserIcon.Gravity = Gravity.CenterVertical;
            btnUserIcon.UnSelectedImagePath = "Account/Admin.png";
            persionFrameLayout.AddChidren(btnUserIcon);
 
            var frameStatu = new StatuFrameLayout(ControlCommonResourse.NormalControlHeight * 2, false);
            frameStatu.X = btnUserIcon.Right + Application.GetRealWidth(50);
            frameStatu.Gravity = Gravity.CenterVertical;
            frameStatu.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
            persionFrameLayout.AddChidren(frameStatu, HeightAutoMode.IncreaseOnly);
 
            //用户昵称
            var btnUserName = new ViewNormalControl(800, true);
            if (UserCenterResourse.UserInfo != null)
            {
                btnUserName.Text = UserCenterResourse.UserInfo.UserName;
            }
            frameStatu.AddChidren(btnUserName);
            //用户身份
            var btnAuthority = new ViewNormalControl(800, true);
            btnAuthority.Y = btnUserName.Bottom;
            btnAuthority.TextColor = UserCenterColor.Current.Gray;
            if (UserCenterResourse.UserInfo != null)
            {
                btnAuthority.Text = UserCenterResourse.UserInfo.AuthorityText;
            }
            frameStatu.AddChidren(btnAuthority);
 
            //右图标
            var btnRight = new RowRightIconView();
            frameStatu.AddChidren(btnRight);
            //左边有个头像,所以它移动位置了
            btnRight.X -= frameStatu.X;
            //单击事件
            frameStatu.MouseUpEvent += (sender, e) =>
            {
                var form = new UserInformationForm();
                base.AddForm(form);
            };
        }
 
        /// <summary>
        /// 初始化菜单列表的FrameLayout
        /// </summary>
        private void InitMenuFrameLayout()
        {
            var frameLayout = new FrameLayout();
            frameLayout.Height = bodyFrameLayout.Height - persionFrameLayout.Height - Application.GetRealHeight(50);
            frameLayout.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
            frameLayout.Y = persionFrameLayout.Bottom + Application.GetRealHeight(50);
            bodyFrameLayout.AddChidren(frameLayout);
 
            var listView = new VerticalScrolViewLayout();
            listView.Height = frameLayout.Height;
            frameLayout.AddChidren(listView);
 
            //添加菜单到MenuFrameLayout
            this.AddRowToMenuFrameLayout(listView);
        }
 
        #endregion
 
        #region ■ 添加菜单___________________________
 
        /// <summary>
        /// 添加菜单到MenuFrameLayout
        /// </summary>
        /// <param name="listView">listView</param>
        private void AddRowToMenuFrameLayout(VerticalScrolViewLayout listView)
        {
            //成员管理
            StatuRowLayout rowLayout = null;
            string unSelectPic = "Center/MenberManagement.png";
            string selectPic = "Center/MenberManagementSelected.png";
            int TextID = R.MyInternationalizationString.MenberManagement;
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
            {
                //添加控件
                rowLayout = this.AddRowLayout(listView, TextID, unSelectPic, selectPic);
                rowLayout.MouseUpEvent += (sender, e) =>
                {
                    //高胜的接口不用特殊Token
                    Common.Config.Instance.isAdministrator = false;
                    var form = new Member.MemberListForm();
                    base.AddForm(form);
                };
            }
 
            //设备管理
            rowLayout = null;
            unSelectPic = "Center/DeviceManagement.png";
            selectPic = "Center/DeviceManagementSelected.png";
            TextID = R.MyInternationalizationString.DeviceManagement;
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
            {
                //添加控件
                rowLayout = this.AddRowLayout(listView, TextID, unSelectPic, selectPic);
                rowLayout.MouseUpEvent += (sender, e) =>
                {
                    if (UserCenterResourse.UserInfo.AuthorityNo == 2)
                    {
                        //启用管理员标识
                        Common.Config.Instance.isAdministrator = true;
                    }
                    Common.LocalGateway.Current.RefreshAppOldSelectGatewayId();
                    if (string.IsNullOrEmpty(GatewayResourse.AppOldSelectGatewayId) == false)
                    {
                        var form = new Device.DeviceManagementMainForm();
                        base.AddForm(form);
                    }
                    else
                    {
                        var form = new Gateway.GatewayManagementForm();
                        base.AddForm(form);
                    }
                };
            }
            else if (UserCenterResourse.UserInfo.AuthorityNo == 3)
            {
                //添加控件
                rowLayout = this.AddRowLayout(listView, TextID, unSelectPic, selectPic);
                rowLayout.MouseUpEvent += (sender, e) =>
                {
                    var form = new DeviceShard.ShardDeviceManagementMainForm();
                    base.AddForm(form);
                };
            }
 
            //住宅管理
            rowLayout = null;
            unSelectPic = "Center/ResidenceManagement.png";
            selectPic = "Center/ResidenceManagementSelected.png";
            TextID = R.MyInternationalizationString.ResidenceManagement;
            if (UserCenterResourse.UserInfo.AuthorityNo == 1)
            {
                //添加控件
                rowLayout = this.AddRowLayout(listView, TextID, unSelectPic, selectPic);
                rowLayout.MouseUpEvent += (sender, e) =>
                {
                    //住宅接口不需要特殊的登陆Token
                    var form = new Residence.ResidenceManagementForm();
                    base.AddForm(form);
                };
            }
 
            //安防管理
            rowLayout = null;
            unSelectPic = "Center/SafetyManagement.png";
            selectPic = "Center/SafetyManagementSelected.png";
            TextID = R.MyInternationalizationString.SafetyManagement;
            //这个账号拥有网关的情况下,才显示这个菜单
            if (Common.LocalGateway.Current.GetAllLocalGateway().Count > 0)
            {
                //添加控件
                rowLayout = this.AddRowLayout(listView, TextID, unSelectPic, selectPic);
                rowLayout.MouseUpEvent += (sender, e) =>
                {
                    if (UserCenterResourse.UserInfo.AuthorityNo == 2)
                    {
                        //启用管理员标识
                        Common.Config.Instance.isAdministrator = true;
                    }
                    var form = new Safety.SafetyManagementMainForm();
                    base.AddForm(form);
                };
            }
 
            //数据备份
            rowLayout = null;
            unSelectPic = "Center/Backup.png";
            selectPic = "Center/BackupSelected.png";
            TextID = R.MyInternationalizationString.uDataBackup;
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
            {
                //添加控件
                rowLayout = this.AddRowLayout(listView, TextID, unSelectPic, selectPic);
                rowLayout.MouseUpEvent += (sender, e) =>
                {
                    if (UserCenterResourse.UserInfo.AuthorityNo == 2)
                    {
                        //启用管理员标识
                        Common.Config.Instance.isAdministrator = true;
                    }
                    var form = new HdlBackup.HdlBackupMenuForm();
                    this.AddForm(form);
                };
            }
 
            //意见反馈
            rowLayout = null;
            unSelectPic = "Center/Opinion.png";
            selectPic = "Center/OpinionSelected.png";
            TextID = R.MyInternationalizationString.Suggestions;
            //添加控件
            //rowLayout = this.AddRowLayout(listView, TextID, unSelectPic, selectPic);
            //rowLayout.MouseUpEvent += (sender, e) =>
            //{
            //    var form = new User.NotFunctionForm();
            //    this.AddForm(form);
            //};
 
            //关于
            rowLayout = null;
            unSelectPic = "Center/Abount.png";
            selectPic = "Center/AbountSelected.png";
            TextID = R.MyInternationalizationString.uAbout;
            //添加控件
            rowLayout = this.AddRowLayout(listView, TextID, unSelectPic, selectPic);
            rowLayout.MouseUpEvent += (sender, e) =>
            {
                Common.Config.Instance.isAdministrator = false;
                var form = new Abount.AbountForm();
                this.AddForm(form);
            };
        }
 
        #endregion
 
        #region ■ 添加行_____________________________
 
        /// <summary>
        /// 添加行
        /// </summary>
        /// <returns>The row layout.</returns>
        /// <param name="listView">listView</param>
        /// <param name="textId">TextID</param>
        /// <param name="UnSelectPic">图片对象</param>
        /// <param name="SelectPic">图片对象</param>
        private StatuRowLayout AddRowLayout(VerticalScrolViewLayout listView, int textId, string UnSelectPic, string SelectPic)
        {
            var rowLayout = new StatuRowLayout(listView);
 
            //图标
            var btnIcon = new RowLeftIconView();
            btnIcon.UnSelectedImagePath = UnSelectPic;
            btnIcon.SelectedImagePath = SelectPic;
            rowLayout.AddChidren(btnIcon);
 
            //文字
            var btnText = new RowCenterView();
            btnText.TextID = textId;
            rowLayout.AddChidren(btnText);
 
            return rowLayout;
        }
        #endregion
 
        #region ■ 界面重新激活事件___________________
 
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override void FormActionAgainEvent()
        {
            //复原管理员标识
            Common.Config.Instance.isAdministrator = false;
            //重新刷新界面
            this.InitMiddleFrame();
        }
 
        #endregion
    }
}