CrabtreeOn,印度客户定制APP,迁移2.0平台版本
wxr
2022-11-01 dc14dbad8e3a55b57cadddba40c3f437e5e80fc5
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
using System;
using System.Collections.Generic;
 
namespace Shared.SimpleControl.Phone
{
    /// <summary>
    /// 调试人员管理页面
    /// </summary>
    public class DebuggerManagementView : FrameLayout
    {
 
        /// <summary>
        /// 
        /// </summary>
        VerticalScrolViewLayout bodyView;
        /// <summary>
        /// 当前住宅
        /// </summary>
        RegionInfoResNew currentHome;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="SubaccountList"></param>
        public DebuggerManagementView (RegionInfoResNew home)
        {
            BackgroundColor = SkinStyle.Current.MainColor;
            this.currentHome = home;
        }
 
        /// <summary>
        /// 
        /// </summary>
        public void ShowDebuggerManagementView ()
        {
 
            #region ---TopView---
            FrameLayout topView = new FrameLayout () {
                Height = Application.GetRealHeight (126),
                BackgroundColor = SkinStyle.Current.MainColor,
            };
            AddChidren (topView);
 
            var back = new Button () {
                Y = Application.GetRealHeight (30),
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (85),
                UnSelectedImagePath = "Item/Back.png",
                SelectedImagePath = "Item/BackSelected.png",
            };
            topView.AddChidren (back);
            back.MouseUpEventHandler += (sender, e) => {
                (Parent as PageLayout).PageIndex -= 1;
            };
 
            Button NameButton = new Button () {
                Width = Application.GetRealWidth (400),
                Height = Application.GetMinReal (90),
                Text = "Debugger Management",
                TextColor = SkinStyle.Current.TextColor1,
                Gravity = Gravity.CenterHorizontal,
                TextAlignment = TextAlignment.Center,
                Y = Application.GetRealHeight (30),
                TextSize = 20,
            };
            topView.AddChidren (NameButton);
 
            Button ItemButton = new Button () {
                Width = Application.GetRealWidth (55),
                Height = Application.GetRealHeight (55),
                UnSelectedImagePath = "Item/+.png",
                SelectedImagePath = "Item/+.png",
                Y = Application.GetRealHeight (50),
                X = Application.GetRealWidth (Application.DesignWidth - 80),
            };
            topView.AddChidren (ItemButton);
            #endregion
 
            //2020-07-01
            if (UserConfig.Instance.CurrentRegion != null && !string.IsNullOrEmpty (UserConfig.Instance.CurrentRegion.Name)) {
                NameButton.Text = UserConfig.Instance.CurrentRegion.Name;
            }
 
            EventHandler<MouseEventArgs> addSubaccountHandler = (sender, e) => {
                showAddDebugger ();
            };
            ItemButton.MouseUpEventHandler += addSubaccountHandler;
 
            FrameLayout topUserMsgView = new FrameLayout () {
                Y = Application.GetRealHeight (126),
                Height = Application.GetRealHeight (175),
                BackgroundColor = SkinStyle.Current.ViewColor
            };
            AddChidren (topUserMsgView);
 
            Button btnUserIcon = new Button () {
                X = Application.GetRealWidth (27),
                Width = Application.GetRealWidth (96),
                Height = Application.GetRealWidth (96),
                Gravity = Gravity.CenterVertical,
                Radius = 5,
                BorderColor = SkinStyle.Current.Transparent,
                BorderWidth = 0,
                UnSelectedImagePath = "AccountSettings/UserIcon.png",
            };
            topUserMsgView.AddChidren (btnUserIcon);
 
            Button btnUserName = new Button () {
                X = btnUserIcon.Right + Application.GetRealWidth (20),
                Y = Application.GetRealHeight (40),
                Width = Application.GetRealWidth (400),
                Height = Application.GetRealHeight (50),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = SkinStyle.Current.TextColor1,
                Text = MainPage.LoginUser.Name == "" ? Language.StringByID (R.MyInternationalizationString.Account) : MainPage.LoginUser.Name,
            };
            topUserMsgView.AddChidren (btnUserName);
 
            Button btnUserAccount = new Button () {
                X = btnUserName.X,
                Y = btnUserName.Bottom,
                Width = btnUserName.Width,
                Height = btnUserName.Height,
                TextAlignment = TextAlignment.CenterLeft,
                Text = "",
                TextColor = SkinStyle.Current.TextColor1
            };
            topUserMsgView.AddChidren (btnUserAccount);
            if (MainPage.LoginUser != null) {
                btnUserAccount.Text += MainPage.LoginUser.AccountString;
            }
 
            VerticalScrolViewLayout contentView = new VerticalScrolViewLayout () {
                Y = topUserMsgView.Bottom,
                Height = Application.GetRealHeight (1136 - 80) - topUserMsgView.Bottom,
                BackgroundColor = SkinStyle.Current.ViewColor,
                ScrollEnabled = false,
            };
            AddChidren (contentView);
 
 
 
            FrameLayout subaccountView = new FrameLayout () {
                Height = Application.GetRealHeight (50),
                BackgroundColor = SkinStyle.Current.MainColor
            };
            contentView.AddChidren (subaccountView);
 
            Button btnSubaccountText = new Button () {
                X = Application.GetRealWidth (40),
                Width = Application.GetRealWidth (600),
                //TextID = R.MyInternationalizationString.Subaccount,
                Text = "Debugger permissions",
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = SkinStyle.Current.TextColor1,
            };
            subaccountView.AddChidren (btnSubaccountText);
 
            Button btnSubaccountLine = new Button () {
                Y = Application.GetRealHeight (105),
                Height = Application.GetRealHeight (10),
                BackgroundColor = SkinStyle.Current.MainColor,
            };
            subaccountView.AddChidren (btnSubaccountLine);
 
            bodyView = new VerticalScrolViewLayout () {
                Height = Application.GetRealHeight (660),
            };
            contentView.AddChidren (bodyView);
 
            //addTipView ();
            //刷新调试人员管理菜单
            RefreshListView ();
        }
 
        void addTipView ()
        {
            var TipView = new Button () {
                Width = LayoutParams.MatchParent,
                Y = Application.GetRealHeight (Application.DesignHeight - 80),
                Height = Application.GetRealHeight (80),
                BackgroundColor = 0xFFFFFFE0,
                TextSize = 11,
                TextColor = 0xFF1F1F1F,
                TextAlignment = TextAlignment.Center,
                IsMoreLines = true,
                Text = "Debugger permissions \n Tips: Management staff remotely access your gateway.",
 
            };
            AddChidren (TipView);
        }
 
        /// <summary>
        /// 刷新调试人员管理菜单
        /// </summary>
        void RefreshListView ()
        {
            bodyView.RemoveAll ();
 
            if (!string.IsNullOrEmpty (currentHome.debugStaffUserId) && currentHome.debugStaffUserId != "-1") {
                RowLayout subaccountRowView = new RowLayout () {
                    Height = Application.GetRealHeight (110),
                };
                bodyView.AddChidren (subaccountRowView);
 
                Button btnDebugTitle = new Button () {
                    X = Application.GetRealWidth (40),
                    //Y = btnSubaccountReamrk.Bottom, 
                    //Height = Application.GetRealHeight(50),
                    Text = "Debugger",
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = SkinStyle.Current.TextColor1,
                };
                subaccountRowView.AddChidren (btnDebugTitle);
 
                Button tipBtn = new Button {
                    X = Application.GetRealWidth (40),
                    Y = Application.GetRealHeight (80),
                    Height = Application.GetRealHeight (20),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = SkinStyle.Current.TextColor1,
                    TextSize = 11,
                    Text = "Allows debuggers remote access to your gateway"
                };
                subaccountRowView.AddChidren (tipBtn);
 
                Button btnRowLine = new Button () {
                    Y = Application.GetRealHeight (105),
                    Height = Application.GetRealHeight (5),
                    BackgroundColor = SkinStyle.Current.MainColor,
                };
                subaccountRowView.AddChidren (btnRowLine);
 
                Button btnDel = new Button () {
                    TextID = R.MyInternationalizationString.Del,
                    BackgroundColor = SkinStyle.Current.DelColor
                };
                subaccountRowView.AddRightView (btnDel);
                btnDel.MouseUpEventHandler += (sender2, e2) => {
                    showDeleteDebuggerAlert ();
                };
 
                var tempSwitch = new Button () {
                    Width = Application.GetMinRealAverage (90),
                    Height = Application.GetMinRealAverage (53),
                    X = Application.GetRealWidth (Application.DesignWidth - 90 - 20),
                    Gravity = Gravity.CenterVertical,
                    UnSelectedImagePath = "Item/SwitchClose.png",
                    SelectedImagePath = "Item/SwitchOpen.png",
                };
                subaccountRowView.AddChidren (tempSwitch);
 
                tempSwitch.IsSelected = currentHome.debugPerm;
                tempSwitch.MouseUpEventHandler += (sender3, e3) => {
                    updateDebugger (tempSwitch);
                };
            }
 
 
 
        }
 
 
 
        /// <summary>
        /// 添加调试人员
        /// </summary>
        void showAddDebugger ()
        {
 
            Dialog dialog = new Dialog ();
            FrameLayout subaccountDialogView = new FrameLayout () {
                Width = Application.GetRealWidth (500),
                //Height = Application.GetRealHeight (650 - 100),
                Height = Application.GetRealHeight (390),
                BackgroundColor = SkinStyle.Current.DialogColor,
                Radius = 5,
                BorderColor = SkinStyle.Current.Transparent,
                BorderWidth = 0,
                Gravity = Gravity.Center,
            };
            dialog.AddChidren (subaccountDialogView);
 
            Button btnTitle = new Button () {
                Height = Application.GetRealHeight (80),
                BackgroundColor = SkinStyle.Current.DialogTitle,
                TextAlignment = TextAlignment.Center,
                //TextID = R.MyInternationalizationString.AddSubaccount,
                Text = "Add debugger",
                TextColor = SkinStyle.Current.DialogTextColor,
            };
            subaccountDialogView.AddChidren (btnTitle);
 
            bool isChange = false;
            if (!string.IsNullOrEmpty (currentHome.debugStaffUserId) && currentHome.debugStaffUserId != "-1") {
                isChange = true;
                btnTitle.Text = "Change debugger";
            }
 
            Button btnEmail = new Button () {
                X = Application.GetRealWidth (40),
                Y = btnTitle.Bottom + Application.GetRealHeight (30),
                Width = Application.GetRealWidth (420),
                Height = Application.GetRealHeight (40),
                Text = "Account",
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = SkinStyle.Current.TextColor,
            };
            subaccountDialogView.AddChidren (btnEmail);
 
            EditText etEmail = new EditText () {
                X = Application.GetRealWidth (40),
                Y = btnEmail.Bottom,
                Width = Application.GetRealWidth (420),
                Height = Application.GetRealHeight (80),
                TextColor = SkinStyle.Current.TextColor,
                Radius = 5,
                BorderColor = SkinStyle.Current.DialogTitle,
                BorderWidth = 2,
                TextAlignment = TextAlignment.Center,
            };
            subaccountDialogView.AddChidren (etEmail);
 
 
 
            FrameLayout bottomView = new FrameLayout () {
                Y = subaccountDialogView.Height - Application.GetRealHeight (90),
                Height = Application.GetRealHeight (90),
                BackgroundColor = SkinStyle.Current.DialogTitle,
            };
            subaccountDialogView.AddChidren (bottomView);
 
            Button btnCancel = new Button () {
                Width = Application.GetRealWidth (249),
                TextAlignment = TextAlignment.Center,
                TextColor = SkinStyle.Current.DialogTextColor,
                TextID = R.MyInternationalizationString.cancel,
            };
            bottomView.AddChidren (btnCancel);
            btnCancel.MouseUpEventHandler += (sender3, e3) => {
                dialog.Close ();
            };
 
            Button btnBottomLine = new Button () {
                X = btnCancel.Right,
                Width = Application.GetRealWidth (2),
                BackgroundColor = SkinStyle.Current.White20Transparent,
            };
            bottomView.AddChidren (btnBottomLine);
 
            Button btnSaveSubaccount = new Button () {
                X = btnBottomLine.Right,
                Width = Application.GetRealWidth (248),
                TextID = R.MyInternationalizationString.SAVE,
                TextColor = SkinStyle.Current.DialogTextColor,
                TextAlignment = TextAlignment.Center,
            };
            bottomView.AddChidren (btnSaveSubaccount);
 
            btnSaveSubaccount.MouseUpEventHandler += (sender3, e3) => {
                string addSubaccount = etEmail.Text.Trim ();
                if (string.IsNullOrEmpty (addSubaccount)) {
                    new Tip () { MaxWidth = 250, Text = Language.StringByID (R.MyInternationalizationString.TipEntrySubaccount), Direction = AMPopTipDirection.Down, CloseTime = 3 }.Show (etEmail);
                    return;
                }
                MainPage.Loading.Start ("Please wait...");
 
                System.Threading.Tasks.Task.Run (() => {
                    try {
 
                        //添加调试人员
                        var revertObj = HttpServerRequest.Current.AddDebugStaff (addSubaccount);
                        if (revertObj.Code == StateCode.SUCCESS) {
                            currentHome.debugPerm = true;
                            currentHome.debugStaffUserId = addSubaccount;
                            Application.RunOnMainThread (() => {
                                if (isChange) {
                                    new Alert ("", "Changed successfully",
                                              Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                } else {
                                    new Alert ("", Language.StringByID (R.MyInternationalizationString.AddedSuccessfully),
                                               Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                }
 
                                dialog.Close ();
                                RefreshListView ();
                            });
                        } else {
                            //BindSubAccount错误提示
                            IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code);
                        }
 
                    } catch (Exception ex) {
                        Application.RunOnMainThread (() => {
                            new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToServer),
                                       Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                        });
                        Utlis.WriteLine (ex.ToString ());
                    } finally {
                        Application.RunOnMainThread (() => {
                            MainPage.Loading.Hide ();
                        });
                    }
                });
            };
 
            dialog.Show ();
        }
 
        /// <summary>
        /// 删除调试人员
        /// </summary>
        void showDeleteDebuggerAlert ()
        {
            Alert delSubaccount = new Alert ("", "Do you want to delete the debugger?",
                                                        Language.StringByID (R.MyInternationalizationString.cancel),
                                                        Language.StringByID (R.MyInternationalizationString.confirm));
            delSubaccount.Show ();
            delSubaccount.ResultEventHandler += (sender, e) => {
                if (e) {
                    MainPage.Loading.Start ("Please wait...");
                    System.Threading.Tasks.Task.Run (() => {
                        try {
                            var revertObj = HttpServerRequest.Current.DelDebugStaff ();
                            if (revertObj.Code == StateCode.SUCCESS) {
                                currentHome.debugPerm = false;
                                currentHome.debugStaffUserId = "-1";
                                Application.RunOnMainThread (() => {
                                    bodyView.RemoveAll ();
                                });
                            } else {
                                //错误提示
                                IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code);
                            }
                        } catch {
                            MainPage.FailureToServer ();
                        } finally {
                            Application.RunOnMainThread (() => {
                                MainPage.Loading.Hide ();
                            });
                        }
                    });
                }
            };
        }
 
        /// <summary>
        /// 更新调试人员调试权限
        /// </summary>
        /// <param name="tempSwitch"></param>
        void updateDebugger (Button tempSwitch)
        {
            bool isSelected = !tempSwitch.IsSelected;
            MainPage.Loading.Start ("Please wait...");
            System.Threading.Tasks.Task.Run (() => {
                try {
                    var revertObj = HttpServerRequest.Current.UpdateDebugPerm (isSelected);
                    if (revertObj.Code == StateCode.SUCCESS) {
                        Application.RunOnMainThread (() => {
                            tempSwitch.IsSelected = isSelected;
                            currentHome.debugPerm = isSelected;
                        });
                    } else {
                        //错误提示
                        IMessageCommon.Current.ShowErrorInfoAlter (revertObj.Code);
                    }
                } catch {
                    MainPage.FailureToServer ();
                } finally {
                    Application.RunOnMainThread (() => {
                        MainPage.Loading.Hide ();
                    });
                }
            });
 
        }
    }
}