JLChen
2020-06-04 6d55af8792cf8fbef0055e677b900fc352dba9a2
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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
using System;
using System.Collections.Generic;
using Shared.SimpleControl.Phone.Music;
 
namespace Shared.SimpleControl.Phone
{
    public static class UserMiddle
    {
        public static int userMenuItemHeight {
            get {
                //if (Application.PixelScale > 1) {
                //    return Convert.ToInt32 (90 * Application.PixelScale + 20);
                //} else {
                    return Convert.ToInt32 (90 * MainPage.PixelScale);
                //}
            }
        }
 
        public static FrameLayout UserPageView = new FrameLayout ();
 
        public static Button LinkStatusTip = new Button () {
            Height = Application.GetRealHeight (Convert.ToInt32 (36 * MainPage.PixelScale)),
            BackgroundColor = SkinStyle.Current.LinkStatusTipColor
        };
 
        public static PageLayout FavoritePageView = new PageLayout () {
            IsShowPoint = false,
        };
        public static FrameLayout FavoriteBodyView = new FrameLayout () {
            //BackgroundColor = 0xFF00FF00,
            //Width = Application.GetRealWidth (640),
            //Height = Application.GetRealHeight (Application.DesignHeight)
        };
        public static UserRoom FavoriteRoom = new UserRoom () {
            //BackgroundColor = 0xFF0000ff,
            Height = Application.GetRealHeight (Application.DesignHeight - userMenuItemHeight)
        };
 
        public static PageLayout DevicePageView = new PageLayout () {
            IsShowPoint = false,
        };
        public static FrameLayout DeviceBodyView = new FrameLayout () {
            Height = Application.GetRealHeight (Application.DesignHeight)
        };
        public static VerticalScrolViewLayout DeviceView = new VerticalScrolViewLayout () {
            Y = Application.GetRealHeight (126),
            Height = Application.GetRealHeight (Application.DesignHeight - 126 - userMenuItemHeight),
        };
 
        public static PageLayout RoomPageView = new PageLayout () {
            IsShowPoint = false,
        };
        public static FrameLayout RoomBodyView = new FrameLayout () {
            Width = Application.GetRealWidth (640),
            Height = Application.GetRealHeight (Application.DesignHeight)
        };
 
        public static PageLayout SettingPageView = new PageLayout () {
            IsShowPoint = false,
        };
        public static FrameLayout SettingBodyView = new FrameLayout () {
            BackgroundColor = SkinStyle.Current.MainColor,
            Height = Application.GetRealHeight (Application.DesignHeight)
        };
        public static VerticalScrolViewLayout SettingView = new VerticalScrolViewLayout () {
            Y = Application.GetRealHeight (126),
            Width = Application.GetRealWidth (640),
            Height = Application.GetRealHeight (Application.DesignHeight - 126 - userMenuItemHeight),
            BackgroundColor = SkinStyle.Current.ViewColor,
            ScrollEnabled = false
        };
        //public static Button btnVersion = new Button () {
        //    Y = Application.GetRealHeight (Application.DesignHeight - userMenuItemHeight - 90),
        //    Width = Application.GetRealWidth (640),
        //    Height = Application.GetRealHeight (90),
        //    Text = Language.StringByID (R.MyInternationalizationString.Version) + " : " + MainPage.CodeIDString,
        //    TextColor = SkinStyle.Current.TextColor1,
        //    BackgroundColor = SkinStyle.Current.ViewColor,
        //    Enable = false
        //};
 
 
        public static FrameLayout UserMenuItem = new FrameLayout () {
            Y = Application.GetRealHeight (Application.DesignHeight - userMenuItemHeight),
            Height = Application.GetRealHeight (userMenuItemHeight+5),
            BackgroundColor = SkinStyle.Current.MainColor
        };
 
 
 
        static int curPageView = 0;
        public static List<System.Threading.Thread> updateSensorhreadList = new List<System.Threading.Thread> ();
 
 
        #region ---Bottom Button----
        public static Button btnFavorite = new Button () {
            Width = Application.GetRealWidth (160),
            Height = MainPage.GetDesignHeight (90),
            TextID = R.MyInternationalizationString.Favorite,
            TextColor = SkinStyle.Current.TextColor1,
            SelectedTextColor = SkinStyle.Current.SelectedColor,
            BackgroundColor = SkinStyle.Current.MainColor,
            SelectedBackgroundColor = SkinStyle.Current.UserMenuItemButton,
            UnSelectedImagePath = "Navigation/MenuFavorite.png",
            SelectedImagePath = "Navigation/MenuFavoriteOn.png",
            TextSize = 10,
            Padding = new Padding (Application.GetRealHeight (50), 0, 0, 0),
            IsSelected = true
        };
 
        public static Button btnDevice = new Button () {
            X = Application.GetRealWidth (160),
            Width = Application.GetRealWidth (160),
            Height = MainPage.GetDesignHeight (90),
            TextID = R.MyInternationalizationString.Category,
            SelectedTextColor = SkinStyle.Current.SelectedColor,
            TextColor = SkinStyle.Current.TextColor1,
            BackgroundColor = SkinStyle.Current.MainColor,
            SelectedBackgroundColor = SkinStyle.Current.UserMenuItemButton,
            UnSelectedImagePath = "Navigation/MenuCategory.png",
            SelectedImagePath = "Navigation/MenuCategoryOn.png",
            TextSize = 10,
            Padding = new Padding (Application.GetRealHeight (50), 0, 0, 0),
        };
        public static Button btnRoom = new Button () {
            X = Application.GetRealWidth (160 * 2),
            Width = Application.GetRealWidth (160),
            Height = MainPage.GetDesignHeight (90),
            TextID = R.MyInternationalizationString.Rooms,
            SelectedTextColor = SkinStyle.Current.SelectedColor,
            TextColor = SkinStyle.Current.TextColor1,
            BackgroundColor = SkinStyle.Current.MainColor,
            SelectedBackgroundColor = SkinStyle.Current.UserMenuItemButton,
            UnSelectedImagePath = "Navigation/MenuRoom.png",
            SelectedImagePath = "Navigation/MenuRoomOn.png",
            TextSize = 10,
            Padding = new Padding (Application.GetRealHeight (50), 0, 0, 0),
        };
        public static Button btnSetting = new Button () {
            X = Application.GetRealWidth (160 * 3),
            Width = Application.GetRealWidth (160),
            Height = MainPage.GetDesignHeight (90),
            TextID = R.MyInternationalizationString.Setting,
            SelectedTextColor = SkinStyle.Current.SelectedColor,
            TextColor = SkinStyle.Current.TextColor1,
            BackgroundColor = SkinStyle.Current.MainColor,
            SelectedBackgroundColor = SkinStyle.Current.UserMenuItemButton,
            UnSelectedImagePath = "Navigation/MenuSettings.png",
            SelectedImagePath = "Navigation/MenuSettingsOn.png",
            TextSize = 10,
            Padding = new Padding (Application.GetRealHeight (50), 0, 0, 0),
        };
 
        public static void SelectedBottomButton (Button btn)
        {
            btnFavorite.IsSelected = false;
            btnDevice.IsSelected = false;
            btnRoom.IsSelected = false;
            btnSetting.IsSelected = false;
            btn.IsSelected = true;
        }
        #endregion
 
        static void CleanPageView (FrameLayout BodyView)
        {
            UserMenuItem.RemoveAll ();
            FavoriteRoom.RemoveAll ();
            FavoriteBodyView.RemoveAll ();
            FavoritePageView.RemoveAll ();
            DeviceView.RemoveAll ();
            DeviceBodyView.RemoveAll ();
            DevicePageView.RemoveAll ();
            RoomBodyView.RemoveAll ();
            RoomPageView.RemoveAll ();
            SettingView.RemoveAll ();
            SettingBodyView.RemoveAll ();
            SettingPageView.RemoveAll ();
            UserPageView.RemoveAll ();
            BodyView.AddChidren (UserMenuItem);
 
            UserMenuItem.AddChidren (btnFavorite);
            UserMenuItem.AddChidren (btnDevice);
            UserMenuItem.AddChidren (btnRoom);
            UserMenuItem.AddChidren (btnSetting);
            foreach (var thread in UserMiddle.updateSensorhreadList) {
                thread.Abort ();
                //Console.WriteLine ("abortThread");
            }
            UserMiddle.updateSensorhreadList.Clear ();
        }
 
        public static void Init ()
        {
 
#if wallon
            InitHomePageView ();
            return;
#else
            if (MainPage.LoginUser == null)
                MainPage.LoginUser = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfo> (System.Text.Encoding.UTF8.GetString (Shared.IO.FileUtils.ReadFile (UserInfo.GlobalRegisterFile)));
            //判断需不需要登录,有没有登录,或者登录是否过期,
            if (MainPage.LoginUser == null || !MainPage.LoginUser.IsLogin) {
                if (MainPage.LoginUser != null)
                    new AccountLogin (MainPage.LoginUser.AccountString, "").Show ();
                else
                    new AccountLogin ().Show ();
 
                UserConfig.Instance.SaveUserConfig ();
            } else {
                InitHomePageView ();
                //Console.WriteLine ("TokenID : " + MainPage.LoginUser.LoginTokenString);
                //后台验证账号
                new System.Threading.Thread (() => {
                    try {
                        var requestObj = new LoginObj () { Account = MainPage.LoginUser.AccountString, Password = MainPage.LoginUser.Password };
                        var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject (requestObj);
                        var revertObj = MainPage.RequestHttps ("Login", requestJson, false);
                        if (revertObj != null) {
                            Application.RunOnMainThread (() => {
                                if (revertObj.StateCode == "SUCCESS") {
                                    var revertData = Newtonsoft.Json.JsonConvert.DeserializeObject<UserLoginRes> (revertObj.ResponseData.ToString ());
                                    MainPage.LoginUser.AllVisionRegisterDevUserNameGuid = revertData.AllVisionRegisterDevUserNameGuid;
                                    MainPage.LoginUser.LastTime = DateTime.Now;
                                    MainPage.LoginUser.SaveUserInfo ();
 
 
                                    string DeviceType = "android";
#if __IOS__
                                    DeviceType = "iphone";
#endif
                                    var mAddRegIDObj = new AddRegIDObj () {
                                        RegID = UserConfig.Instance.tokenID,
                                        Alias = UserConfig.Instance.phoneName,
                                        Account = MainPage.LoginUser.AccountString,
                                        UserMode = 2,
                                    };
                                    var mAddRegIDObjJson = Newtonsoft.Json.JsonConvert.SerializeObject (mAddRegIDObj);
                                    MainPage.RequestHttps (@"AddRegID", mAddRegIDObjJson, true, false);
 
                                    //string jsonString = "{" +
                                    //                  "\"RegID\":" + "\"" + UserConfig.Instance.tokenID + "\"" + "," +
                                    //                  "\"Alias\":" + "\"" + UserConfig.Instance.phoneName + "\"" + "," +
                                    //                  "\"Account\":" + "\"" + MainPage.LoginUser.AccountString + "\"" +
                                    //                       "}";
                                    //MainPage.RequestHttps (@"AddRegID", jsonString, true);
 
                                    if (!string.IsNullOrEmpty (MainPage.LoginUser.AllVisionRegisterDevUserNameGuid)) {
                                        //可视对讲
                                        Application.RunOnMainThread (() => {
#if Android
                                            (Application.Activity as BaseActivity).ReadWriteContact ((b) => {
                                                if (b) {
                                                    com.freeview.global.Video.Init (MainPage.LoginUser.LoginTokenString, MainPage.LoginUser.AllVisionRegisterDevUserNameGuid);
                                                }
                                            });
#else
                                            com.freeview.global.Video.Init (MainPage.LoginUser.LoginTokenString, MainPage.LoginUser.AllVisionRegisterDevUserNameGuid);
#endif
                                        });
                                    }
                                } else if (revertObj.StateCode != "Net_Error") {
                                    MainPage.LoginUser.LastTime = DateTime.Now.AddDays (-30);
                                    MainPage.LoginUser.SaveUserInfo ();
                                    new AccountLogin ().Show ();
                                }
                            });
                        }
#if Android
                        if (UserConfig.Instance.UpdateVersionType == 0)
                            UserSettingView.CheckVersionInfo ();
#endif
                    } catch { } finally {
                        UserConfig.Instance.SaveUserConfig ();
                    }
                }) { IsBackground = true}.Start();
            }
#endif
        }
 
 
        /// <summary>
        /// 加载用户界面
        /// </summary>
        static void InitHomePageView ()
        {
 
#if DEBUG
            //var tv = new InfraredMode () { SubnetID = 42, DeviceID = 1, LoopID = 1, InfraredType = InfraredType.TV, Name = "TV" };
            //IO.FileUtils.SaveEquipmentMessage (tv, "1");
            //var tv1 = new InfraredMode () { SubnetID = 42, DeviceID = 1, LoopID = 11, InfraredType = InfraredType.STB, Name = "stb" };
            //IO.FileUtils.SaveEquipmentMessage (tv1, "11");
            //var ac = new ACInfrared () { SubnetID = 42, DeviceID = 1, LoopID = 111,  Name = "ac" };
            //IO.FileUtils.SaveEquipmentMessage (ac, "111");
 
            var mHVAC = new HVAC () { SubnetID = 42, DeviceID = 12, LoopID = 11, Name = "ac" };
            IO.FileUtils.SaveEquipmentMessage (mHVAC, "11");
 
            var mThermostat = new Thermostat () { SubnetID = 42, DeviceID = 221, LoopID = 1, Name = "空调系统" };
            IO.FileUtils.SaveEquipmentMessage (mThermostat, "111");
 
            var mACMerrill = new ACMerrill () { SubnetID = 80, DeviceID = 0, LoopID = 1, Name = "美林空调系统", LoopCount = 17 };
            var mACMerrillLoopList = new List<ACMerrillLoop> ();
            for (int i = 0; i < mACMerrill.LoopCount; i++) {
                var id = i + 1;
                var ac = new ACMerrillLoop () {
 
                    SubnetID = 42,
                    DeviceID = 0,
                    LoopID = (byte)id,
                    Name = "空调" + id,
                  
                };
                if (i > 10) {
                    ac.Power = 1;
                    ac.IndoorTemperature = (byte)i;
                    ac.IndoorHumidity = (byte)(30 + i);
                }
                mACMerrillLoopList.Add (ac);
 
            }
            mACMerrill.mACMerrillLoopList = mACMerrillLoopList;
            //IO.FileUtils.SaveEquipmentMessage (mACMerrill, mACMerrill.LoopID.ToString ());
 
 
 
            //var mLightDoorLock = new LightDoorLock () { SubnetID = 42, DeviceID = 7, LoopID = 1, Name = "Door Lock", ReadStatusSubnetID = 42, ReadStatusDeviceID = 5, ReadStatusLoopID = 3 };
            //IO.FileUtils.SaveEquipmentMessage (mLightDoorLock, "1");
 
            //var mCurtainModel = new CurtainModel () { SubnetID = 111, DeviceID = 8, LoopID = 1, Name = "Curtain" };
            //IO.FileUtils.SaveEquipmentMessage (mCurtainModel, "1");
 
            //var s1 = new LightMixDimming () { SubnetID = 42,DeviceID = 2,LoopID = 1,Name = "Dimming 1",CurrentBrightness = 88};
            //IO.FileUtils.SaveEquipmentMessage (s1, "1");
 
            //var s2 = new LightMixDimming () { SubnetID = 42, DeviceID = 2, LoopID = 2, Name = "Dimming 2", CurrentBrightness = 100 };
            //IO.FileUtils.SaveEquipmentMessage (s1, "2");
            //var s3 = new LightMixDimming () { SubnetID = 42, DeviceID = 2, LoopID = 3, Name = "Dimming 3", CurrentBrightness = 0 };
            //IO.FileUtils.SaveEquipmentMessage (s1, "3");
            //var s4 = new LightMixDimming () { SubnetID = 42, DeviceID = 2, LoopID = 4, Name = "Dimming 4", CurrentBrightness = 88 };
            //IO.FileUtils.SaveEquipmentMessage (s1, "4");
 
 
 
            //var lii = new LightLogic () { Type = DeviceType.LightRGB, LoopID = 1, DeviceID = 4, SubnetID = 42, Name = "RGB" };
            //IO.FileUtils.SaveEquipmentMessage (lii, lii.LoopID.ToString ());
 
            var daliLoop = new LightDALI {
                Type = DeviceType.LightDALI, LoopID = 1, Name = "LightDALI1", CoolTones_High = 100, CoolTones_Low = 100, CoolTones_High_Modular = 100, CoolTones_Low_Modular = 100,
                WarmTones_High = 10, WarmTones_Low = 10, WarmTones_Low_Modular = 10, WarmTones_High_Modular = 10, CurrentBrightness = 0, CurTones_High = 20, CurTones_Low = 20, SubnetID = 205, DeviceID = 222
            };
            IO.FileUtils.SaveEquipmentMessage (daliLoop, daliLoop.LoopID.ToString ());
 
            var daliLoop2 = new LightDALI {
                Type = DeviceType.LightDALI, LoopID = 2, Name = "LightDALI2", CoolTones_High = 100, CoolTones_Low = 100, CoolTones_High_Modular = 100, CoolTones_Low_Modular = 100,
                WarmTones_High = 10, WarmTones_Low = 10, WarmTones_Low_Modular = 10, WarmTones_High_Modular = 10, CurrentBrightness = 0, CurTones_High = 20, CurTones_Low = 20, SubnetID = 205, DeviceID = 222
            };
            IO.FileUtils.SaveEquipmentMessage (daliLoop2, daliLoop2.LoopID.ToString ());
 
 
 
            //var tt = new CurtainTrietex () { LoopID = 1, DeviceID = 1, SubnetID = 42, Name = "开合帘" };
            //IO.FileUtils.SaveEquipmentMessage (tt, "1");
 
            //var fa = new FreshAir () { LoopID = 1, DeviceID = 112, SubnetID = 42, Name = "Fresh Air" };
            //IO.FileUtils.SaveEquipmentMessage (fa, fa.LoopID.ToString ());
            var se = new SensorPM25 () { LoopID = 1, DeviceID = 1, SubnetID = 11, Name = "PM2.5", CurrentPM25 = 22 };
            IO.FileUtils.SaveEquipmentMessage (se, "1");
            var se1 = new SensorCO2 () { LoopID = 1, DeviceID = 2, SubnetID = 11, Name = "CO2", CurrentCO2 = 338 };
            IO.FileUtils.SaveEquipmentMessage (se1, "2");
            var se2 = new SensorTVOC () { LoopID = 1, DeviceID = 3, SubnetID = 11, Name = "TVOC", CurrentTVOC = 197 };
            IO.FileUtils.SaveEquipmentMessage (se2, "3");
            var se3 = new SensorTemperature () { LoopID = 1, DeviceID = 4, SubnetID = 11, Name = "Temp.", CurrentTemperature = 19 };
            IO.FileUtils.SaveEquipmentMessage (se3, "4");
            var se4 = new SensorHumidity () { LoopID = 1, DeviceID = 5, SubnetID = 11, Name = "Humidity", CurrentHumidity = 43 };
            IO.FileUtils.SaveEquipmentMessage (se4, "5");
            var se5 = new SensorHumidity () { LoopID = 1, DeviceID = 6, SubnetID = 11, Name = "Humidity1", CurrentHumidity = 43 };
            IO.FileUtils.SaveEquipmentMessage (se5, "6");
            var se6 = new SensorHumidity () { LoopID = 1, DeviceID = 7, SubnetID = 11, Name = "Humidity2", CurrentHumidity = 43 };
            IO.FileUtils.SaveEquipmentMessage (se6, "7");
 
            //var infraredMode1 = new ACInfrared () { LoopID = 1, SubnetID = 42, DeviceID = 12, Name = "AC",SetTemperature = 26,IndoorTemperature  =28 };
            //IO.FileUtils.SaveEquipmentMessage (infraredMode1, "1");
 
            //var udo = new UniversalDevice () { LoopID = 1, SubnetID = 1, DeviceID = 6, ActionType = 2, Name = "Universal-1", obj1 = 1, TargetType = 0 };
            //udo.SendBytes = new List<byte> () { 1, 0 };
            //IO.FileUtils.SaveEquipmentMessage (udo, "1");
            //var ud12 = new UniversalDevice () { LoopID = 2, SubnetID = 1, DeviceID = 6, ActionType = 0, Name = "Universal-2", obj1 = 1, TargetType = 1 };
            //ud12.SendBytes = new List<byte> () { 2, 0 };
            //IO.FileUtils.SaveEquipmentMessage (ud12, "2");
            //var ud13 = new UniversalDevice () { ON_Text = "DAKAI", OFF_Text = "GUAN", LoopID = 3, SubnetID = 1, DeviceID = 6, ActionType = 1, Name = "Universal-3", obj1 = 1, TargetType = 2 };
            //ud13.SendBytes = new List<byte> () { 3, 0 };
            //IO.FileUtils.SaveEquipmentMessage (ud13, "3");
 
            //var ud8 = new UniversalDevice () { LoopID = 1, SubnetID = 42, DeviceID = 90, ActionType = 2, Name = "Universal-1", obj1 = 1, TargetType = 0, UniversalType = 0xE01C };
            //ud8.SendBytes = new List<byte> () { 1, 100 };
            //IO.FileUtils.SaveEquipmentMessage (ud8, "1");
            //var ud82 = new UniversalDevice () { LoopID = 1, SubnetID = 42, DeviceID = 90, ActionType = 2, Name = "Universal-2", obj1 = 1, TargetType = 0, UniversalType = 0xE01C };
            //ud82.SendBytes = new List<byte> () { 2, 100 };
            //IO.FileUtils.SaveEquipmentMessage (ud82, "2");
            //var ud83 = new UniversalDevice () { ON_Text = "DAKAI", OFF_Text = "GUAN", LoopID = 3, SubnetID = 2, DeviceID = 6, ActionType = 1, Name = "Universal-3", obj1 = 1, TargetType = 2 };
            //ud83.SendBytes = new List<byte> () { 3, 0 };
            //IO.FileUtils.SaveEquipmentMessage (ud83, "3");
 
 
            //SecurityModul sm0 = new SecurityModul () { Name = "SecurityModul-1", SubnetID = 42, DeviceID = 11, LoopID = 1, obj1 = 1 };
            //SecurityModul sm1 = new SecurityModul () { Name = "SecurityArea-1", SubnetID = 42, DeviceID = 11, LoopID = 1, obj1 = 1, AreaNumber = 1 };
            //SecurityModul sm2 = new SecurityModul () { Name = "SecurityArea-2", SubnetID = 42, DeviceID = 11, LoopID = 2, obj1 = 1, AreaNumber = 2 };
            //SecurityModul sm3 = new SecurityModul () { Name = "SecurityArea-3", SubnetID = 42, DeviceID = 11, LoopID = 3, obj1 = 1, AreaNumber = 3 };
            //SecurityModul sm4 = new SecurityModul () { Name = "SecurityArea-4", SubnetID = 42, DeviceID = 11, LoopID = 4, obj1 = 1, AreaNumber = 4 };
            //SecurityModul sm5 = new SecurityModul () { Name = "SecurityArea-5", SubnetID = 42, DeviceID = 11, LoopID = 5, obj1 = 1, AreaNumber = 5 };
            //SecurityModul sm6 = new SecurityModul () { Name = "SecurityArea-6", SubnetID = 42, DeviceID = 11, LoopID = 6, obj1 = 1, AreaNumber = 6 };
            //ScurityDryContact sdc = new ScurityDryContact () { Name = "window", SubnetID = 42, DeviceID = 10, LoopID = 1, obj1 = 1, AreaNumber = 1 };
            //ScurityDryContact sdc2 = new ScurityDryContact () { Name = "door", SubnetID = 42, DeviceID = 10, LoopID = 2, obj1 = 1, SensorType = 1, AreaNumber = 1 };
            //ScurityDryContact sdc3 = new ScurityDryContact () { Name = "door2", SubnetID = 42, DeviceID = 10, LoopID = 3, obj1 = 1, SensorType = 1, AreaNumber = 1 };
            //sm1.SensorList.Add (sdc);
            //sm1.SensorList.Add (sdc2);
            //sm2.SensorList.Add (sdc3);
            //IO.FileUtils.SaveEquipmentMessage (sm1, "1");
            //IO.FileUtils.SaveEquipmentMessage (sm2, "2");
            //IO.FileUtils.SaveEquipmentMessage (sm3, "3");
            //IO.FileUtils.SaveEquipmentMessage (sm4, "4");
            //IO.FileUtils.SaveEquipmentMessage (sm5, "5");
            //IO.FileUtils.SaveEquipmentMessage (sm6, "6");
#endif
 
#if wallon
            MainPage.LoginUser = new UserInfo ();
#endif
            if (null != UserPageView.Parent) {
                CleanPageView (FavoriteBodyView);
                UserPageView.AddChidren (FavoritePageView);
                FavoritePageView.AddChidren (FavoriteBodyView);
                FavoriteBodyView.AddChidren (FavoriteRoom);
                FavoriteRoom.InitRoomView (Room.FavoriteRoom);
                SelectedBottomButton (btnFavorite);
                curPageView = 0;
                btnFavorite.TextID = R.MyInternationalizationString.Favorite;
                btnDevice.TextID = R.MyInternationalizationString.Category;
                btnRoom.TextID = R.MyInternationalizationString.Rooms;
                btnSetting.TextID = R.MyInternationalizationString.Setting;
                FavoritePageView.PageIndex = 0;
                return;
            }
 
            UserHomePage.FrameLayoutMain.AddChidren (UserPageView);
            UserHomePage.FrameLayoutMain.AddChidren (LinkStatusTip);
 
 
            UserPageView.AddChidren (FavoritePageView);
            FavoritePageView.AddChidren (FavoriteBodyView);
            FavoriteBodyView.AddChidren (UserMenuItem);
            FavoriteBodyView.AddChidren (FavoriteRoom);
            FavoriteRoom.InitRoomView (Room.FavoriteRoom);
 
#region 底部导航栏
            UserMenuItem.AddChidren (btnFavorite);
            UserMenuItem.AddChidren (btnDevice);
            UserMenuItem.AddChidren (btnRoom);
            UserMenuItem.AddChidren (btnSetting);
            SelectedBottomButton (btnFavorite);
#if wallon
            btnFavorite.Height = Application.GetRealHeight (85);
            btnDevice.Height = Application.GetRealHeight (85);
            btnRoom.Height = Application.GetRealHeight (85);
            btnSetting.Height = Application.GetRealHeight (85);
            btnFavorite.Y = Application.GetRealHeight (5);
            btnDevice.Y = Application.GetRealHeight (5);
            btnRoom.Y = Application.GetRealHeight (5);
            btnSetting.Y = Application.GetRealHeight (5);
#endif
 
            btnFavorite.MouseUpEventHandler += (sender, e) => {
                CleanPageView (FavoriteBodyView);
                UserPageView.AddChidren (FavoritePageView);
                FavoritePageView.AddChidren (FavoriteBodyView);
                FavoriteBodyView.AddChidren (FavoriteRoom);
                FavoriteRoom.InitRoomView (Room.FavoriteRoom);
                curPageView = 0;
                SharedMethod.SharedMethod.CurPageLayout = FavoritePageView;
                SelectedBottomButton (btnFavorite);
            };
 
            btnDevice.MouseUpEventHandler += (sender, e) => {
                try {
                    CleanPageView (DeviceBodyView);
                    UserPageView.AddChidren (DevicePageView);
                    DevicePageView.AddChidren (DeviceBodyView);
                    DeviceBodyView.AddChidren (DeviceView);
                    UserDeviceView.DeviceMode ();
                    curPageView = 1;
                    SharedMethod.SharedMethod.CurPageLayout = DevicePageView;
                    DevicePageView.PageIndex = 0;
                    SelectedBottomButton (btnDevice);
                } catch (Exception ex) {
                    Console.WriteLine (ex.Message);
                } finally {
                }
            };
            btnRoom.MouseUpEventHandler += (sender, e) => {
                CleanPageView (RoomBodyView);
                UserPageView.AddChidren (RoomPageView);
                RoomPageView.AddChidren (RoomBodyView);
                UserRooms.ShowRoomList ();
                curPageView = 2;
                SharedMethod.SharedMethod.CurPageLayout = RoomPageView;
                RoomPageView.PageIndex = 0;
                SelectedBottomButton (btnRoom);
            };
 
            btnSetting.MouseUpEventHandler += (sender, e) => {
                CleanPageView (SettingBodyView);
                UserPageView.AddChidren (SettingPageView);
                SettingPageView.AddChidren (SettingBodyView);
                SettingBodyView.AddChidren (SettingView);
                //SettingBodyView.AddChidren (btnVersion);
                UserSettingView.InitUserSettingView ();
                curPageView = 3;
                SharedMethod.SharedMethod.CurPageLayout = SettingPageView;
                SettingPageView.PageIndex = 0;
                SelectedBottomButton (btnSetting);
            };
            FavoritePageView.PageChange += (sender, e) => {
                if (e < FavoritePageView.ChildrenCount - 1) {
                    FavoritePageView.GetChildren (FavoritePageView.ChildrenCount - 1).RemoveFromParent ();
                }
            };
            SettingPageView.PageChange += (sender, e) => {
                if (e < SettingPageView.ChildrenCount - 1) {
                    SettingPageView.GetChildren (SettingPageView.ChildrenCount - 1).RemoveFromParent ();
                }
            };
            RoomPageView.PageChange += (sender, e) => {
                if (e < RoomPageView.ChildrenCount - 1) {
                    RoomPageView.GetChildren (RoomPageView.ChildrenCount - 1).RemoveFromParent ();
                }
            };
            DevicePageView.PageChange += (sender, e) => {
                while (e < DevicePageView.ChildrenCount - 1) {
                    DevicePageView.GetChildren (DevicePageView.ChildrenCount - 1).RemoveFromParent ();
                }
                if (e == 0) {
                    DevicePageView.ScrollEnabled = true;
                }
            };
#endregion
 
        }
 
        public static void ShowSettingView ()
        {
                CleanPageView (SettingBodyView);
                UserPageView.AddChidren (SettingPageView);
                SettingPageView.AddChidren (SettingBodyView);
                SettingBodyView.AddChidren (SettingView);
                //SettingBodyView.AddChidren (btnVersion);
                UserSettingView.InitUserSettingView ();
                SettingPageView.PageIndex = 0;
                curPageView = 3;
                SharedMethod.SharedMethod.CurPageLayout = SettingPageView;
                Console.WriteLine (SharedMethod.SharedMethod.CurPageLayout);
            SelectedBottomButton (btnSetting);
        }
 
        public static void ShowRoomsView ()
        {
            CleanPageView (RoomBodyView);
            UserPageView.AddChidren (RoomPageView);
            RoomPageView.AddChidren (RoomBodyView);
            //UserMiddle.RoomBodyView.RemoveAll ();
            UserRooms.ShowRoomList ();
            curPageView = 2;
            SelectedBottomButton (btnRoom);
        }
 
        public static void ReadAllDeviceStatus ()
        {
            if (MainPage.LoginUser == null || !MainPage.LoginUser.IsLogin) {
                return;
            }
            UserDeviceToCurtains.readAllStatus (true);
            UserDeviceToLight.readAllStatus (true);
            UserDeviceToSocket.readAllStatus (true);
            UserDeviceToAC.readAllStatus (true);
            UserDeviceToFH.readAllStatus (true);
            UserFresAirList.readAllStatus (true);
        }
    }
}