HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-10-12 c6b35c3138b944830b5336bf610f918154dd47c7
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
using System;
using System.Collections.Generic;
using Shared.Common;
using Shared.Phone.UserCenter.Device;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.DoorLock
{
    /// <summary>
    /// 门锁管理
    /// </summary>
    public class UserManagement : DoorLockCommonLayout, ZigBee.Common.IStatus
    {
        /// <summary>
        /// 按键模式接收
        /// </summary>
        /// <param name="common">Common.</param>
        public void Changed(CommonDevice common)
        {
            //if (common.Type != ZigBee.Device.DeviceType.OnOffSwitch)
            //{
            //    return;
            //}
 
            Shared.Application.RunOnMainThread(() =>
            {
                //var dev = common as Panel;
            });
        }
        //从门锁读信息
        void ReadDoorLockDeviceUserInfo()
        {
            System.Threading.Tasks.Task.Run(async () =>
            {
                Application.RunOnMainThread(() => { CommonPage.Loading.Start("Loading..."); });
                try
                {
                    var getDoorLockInfo = await doorLock.GetDoorlockUserInfoAsync();
                    if (getDoorLockInfo != null && getDoorLockInfo.doorLockUserDetailData != null)
                    {
                        var dataList = getDoorLockInfo.doorLockUserDetailData.UserObjList;
                        foreach (var doorData in dataList)
                        {
                            var localDoorLockObj1 = new ZigBee.Device.DoorLock.LocaDoorLockObj()
                            {
                                UserID = doorData.UserId,
                                UnlockType = doorData.UserType
                            };
                            if ((doorLock.localDoorLockUserList.ContainsKey(localDoorLockObj1.UserID)) == false)
                            {
                                doorLock.localDoorLockUserList.Add(localDoorLockObj1.UserID, localDoorLockObj1);
                            }
                        }
                    }
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        CommonPage.Loading.Hide();
                    });
                }
            });
        }
        //从服务器读信息
        void ReadDoorLockServerUserInfo(Shared.Phone.UserCenter.MemberInfoRes curAccountObj)
        {
            System.Threading.Tasks.Task.Run(async () =>
            {
                Application.RunOnMainThread(() => { CommonPage.Loading.Start("Loading..."); });
                try
                {
                    //  读取云端门锁设备中的信息
                    var localDoorLockObj = new ZigBee.Device.DoorLock.GetDoorLockData() { };
 
                    localDoorLockObj.CloudAccountId = curAccountObj.SubAccountDistributedMark;
                    if (doorLock.DeviceAddr != null)
                    {
                        localDoorLockObj.DoorLockId = doorLock.DeviceAddr + "_" + doorLock.DeviceEpoint;
                    }
 
                    var getDoorLockInfoList = await ZigBee.Device.DoorLock.GetDoorLockInfoFromServer("App/GetDoorLockPager", localDoorLockObj);
                    if (getDoorLockInfoList != null)
                    {
                        foreach (var curDoorLockUser in getDoorLockInfoList.PageData)
                        {
                            if (doorLock.localDoorLockUserList.ContainsKey(int.Parse(curDoorLockUser.DoorLockLocalUserId)))
                            {
                                doorLock.localDoorLockUserList.Remove(int.Parse(curDoorLockUser.DoorLockLocalUserId));
                            }
                            var doorLockObj = new ZigBee.Device.DoorLock.LocaDoorLockObj() { };
                            doorLockObj.UserID = int.Parse(curDoorLockUser.DoorLockLocalUserId);
                            doorLockObj.UnlockType = curDoorLockUser.OpenLockMode;
                            doorLockObj.PrimaryId = curDoorLockUser.Id;
                            doorLockObj.EntryTime = curDoorLockUser.EntryTime;
                            doorLockObj.UserName = curDoorLockUser.UserIdRemarks;
                            doorLockObj.ConnectedAccount = curDoorLockUser.CloudAccountId;
                            doorLock.localDoorLockUserList.Add(int.Parse(curDoorLockUser.DoorLockLocalUserId), doorLockObj);
                        }
                    }
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        CommonPage.Loading.Hide();
                    });
                }
            });
        }
 
 
        /// 构造函数
        /// </summary>
        /// <param name="doorLock"></param>
        public UserManagement(ZigBee.Device.DoorLock doorLock)
        {
            this.doorLock = doorLock;
        }
 
        #region ◆ 变量申明__________________________
        ZigBee.Device.DoorLock doorLock;
        List<Shared.Phone.UserCenter.MemberInfoRes> localAccountList = new List<Shared.Phone.UserCenter.MemberInfoRes> { };
        #endregion
 
        public void Show()
        {
            this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.UserManagement));
 
            EventHandler<MouseEventArgs> eHandlerBack = (sender, e) =>
            {
                RemoveFromParent();
            };
            this.btnBack.MouseUpEventHandler += eHandlerBack;
            this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
            this.MidFrameLayout(this);
 
            var btnAddFrameLayout = new FrameLayout
            {
                X = Application.GetRealWidth(829),
                Height = Application.GetRealHeight(72),
                Width = Application.GetRealWidth(190),
            };
            this.titleFrameLayout.AddChidren(btnAddFrameLayout);
 
            var btnUndistributeIcon = new Button
            {
                Height = Application.GetRealHeight(69),
                Width = Application.GetRealWidth(69),
                UnSelectedImagePath = "DoorLock/UndistributeIcon.png",
            };
            btnAddFrameLayout.AddChidren(btnUndistributeIcon);
 
            var btnUndistributeText = new Button
            {
                Height = Application.GetRealHeight(72),
                Width = Application.GetRealWidth(121),
                TextID = R.MyInternationalizationString.Undistributed,
                TextColor = Shared.Common.ZigbeeColor.Current.XMTopTitleText,
                X = btnUndistributeIcon.Right,
                TextAlignment = TextAlignment.CenterLeft,
            };
            btnAddFrameLayout.AddChidren(btnUndistributeText);
 
            EventHandler<MouseEventArgs> eHandler = (sender, e) =>
            {
                var undistributeDoorlockUserPage = new Shared.Phone.UserCenter.DoorLock.UndistributeDoorlockUserPage(doorLock, localAccountList);
                Shared.Phone.UserView.HomePage.Instance.AddChidren(undistributeDoorlockUserPage);
                Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                undistributeDoorlockUserPage.Show();
            };
            btnAddFrameLayout.MouseDownEventHandler += eHandler;
            btnUndistributeText.MouseDownEventHandler += eHandler;
            btnUndistributeIcon.MouseDownEventHandler += eHandler;
 
            MidFrameLayoutContent();
        }
 
        async void MidFrameLayoutContent()
        {
            var SubAccounList = await ZigBee.Device.DoorLock.GetSubAccountByDistributedMark();
            var masterAccount = new Shared.Phone.UserCenter.MemberInfoRes();
            masterAccount.Account = Shared.Common.Config.Instance.Account;
            masterAccount.AccountType = Shared.Common.Config.Instance.AccountType;
            masterAccount.SubAccountDistributedMark = Shared.Common.Config.Instance.Guid;
            masterAccount.UserName = UserCenterResourse.UserInfo.UserName;
            localAccountList.Add(masterAccount);
            localAccountList.AddRange(SubAccounList);
            var bodyView = new VerticalScrolViewLayout()
            {
            };
            this.midFrameLayout.AddChidren(bodyView);
 
            doorLock.localAllAccountList = localAccountList;
            for (int i = 0; i < localAccountList.Count; i++)
            {
                var currentAccount = localAccountList[i];
                var RowView = new FrameLayout()
                {
                    Height = Application.GetRealHeight(161),
                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMTopFrameLayout,
                };
                bodyView.AddChidren(RowView);
 
                var btnText = new Button()
                {
                    X = Application.GetRealWidth(58),
                    Width = Application.GetRealWidth(300),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = Shared.Common.ZigbeeColor.Current.XMTopTitleText,
                    Gravity = Gravity.CenterVertical,
                    TextSize = 14,
                };
                RowView.AddChidren(btnText);
 
                var btnRightFrameLayout = new FrameLayout()
                {
                    Height = Application.GetRealHeight(110),
                    Width = Application.GetRealWidth(110),
                    X = Application.CurrentWidth - Application.GetRealWidth(150),
                    Y = Application.GetRealHeight(25),
                };
                RowView.AddChidren(btnRightFrameLayout);
 
                var btnRight = new Button()
                {
                    Height = Application.GetRealHeight(58),
                    Width = Application.GetRealWidth(58),
                    UnSelectedImagePath = "DoorLock/RightIcon.png",
                    Gravity = Gravity.Center,
                };
                btnRightFrameLayout.AddChidren(btnRight);
 
                var line2 = new Button()
                {
                    Y = RowView.Height - 1,
                    X = Application.GetRealWidth(58),
                    Width = Application.GetRealWidth(965),
                    Height = 1,
                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
                };
                RowView.AddChidren(line2);
                int currentIndex = i;
                if (currentIndex == localAccountList.Count - 1)
                {
                    line2.Visible = false;
                }
 
                if (currentAccount.UserName != null)
                {
                    btnText.Text = currentAccount.UserName;
                }
                else
                {
                    btnText.Text = currentAccount.Account;
                }
 
                EventHandler<MouseEventArgs> eHandler = (sender, e) =>
                {
                    if (currentIndex == 0)
                    {
                        var masterManagementPage = new Shared.Phone.UserCenter.DoorLock.MasterManagementPage(doorLock, currentAccount);
                        Shared.Phone.UserView.HomePage.Instance.AddChidren(masterManagementPage);
                        Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                        masterManagementPage.Show();
                    }
                    else if (currentIndex == 1)
                    {
                        var userDoorLockPage = new UserDoorLockPage(doorLock, currentAccount);
                        Shared.Phone.UserView.HomePage.Instance.AddChidren(userDoorLockPage);
                        Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                        userDoorLockPage.Show();
                    }
                    else
                    {
                        var memberFrozenPage = new Shared.Phone.UserCenter.DoorLock.MemberFrozenPage(doorLock, currentAccount);
                        Shared.Phone.UserView.HomePage.Instance.AddChidren(memberFrozenPage);
                        Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                        memberFrozenPage.Show();
                    }
                };
                btnRight.MouseUpEventHandler += eHandler;
                RowView.MouseUpEventHandler += eHandler;
                btnText.MouseUpEventHandler += eHandler;
            }
        }
 
        public void DeviceInfoChange(CommonDevice common, string typeTag)
        {
        }
 
        public void ChangedILogicStatus(ZigBee.Device.Logic logic)
        {
        }
 
        public void ChangedISceneStatus(Scene scene)
        {
        }
    }
}