黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
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
    {
        /// 构造函数
        /// </summary>
        /// <param name="doorLock"></param>
        public UserManagement(ZigBee.Device.DoorLock doorLock)
        {
            this.doorLock = doorLock;
            localAllAccountListTemp = doorLock.localAllAccountList;
            localDoorLockUserListTemp = doorLock.localDoorLockUserList;
        }
 
        #region ◆ 变量申明__________________________
        ZigBee.Device.DoorLock doorLock;
        VerticalRefreshLayout midVerticalScrolViewLayout;
        public List<MemberInfoRes> localAllAccountListTemp = new List<MemberInfoRes> { };
        public Dictionary<int, DoorLockCommonInfo.LocaDoorLockObj> localDoorLockUserListTemp = new Dictionary<int, DoorLockCommonInfo.LocaDoorLockObj>();
 
 
        #endregion
 
        /// <summary>
        /// 数据刷新
        /// </summary>
        void ReadAccountDoorLockInfoList()
        {
            System.Threading.Tasks.Task.Run(async () =>
            {
                try
                {
                    var localAccountListTemp = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.LocalAccountList();
                    if (localAccountListTemp != null)
                    {
                        doorLock.localAllAccountList.Clear();
                        doorLock.localAllAccountList = localAccountListTemp;
                        localAllAccountListTemp = doorLock.localAllAccountList;
 
                        //初始化权限信息
                        foreach (var sub in localAccountListTemp)
                        {
                            //☆マーク☆
                            //if (doorLock.IsFreezeAccount.ContainsKey(sub.SubAccountDistributedMark) == false)
                            //{
                            //    doorLock.IsFreezeAccount.Add(sub.SubAccountDistributedMark, false);
                            //}
                            //if (doorLock.HasRemoteUnlockAccess.ContainsKey(sub.SubAccountDistributedMark) == false)
                            //{
                            //    doorLock.HasRemoteUnlockAccess.Add(sub.SubAccountDistributedMark, false);
                            //}
                            //if (doorLock.IsFailedToGetDoorLockInfo.ContainsKey(sub.SubAccountDistributedMark) == false)
                            //{
                            //    doorLock.IsFailedToGetDoorLockInfo.Add(sub.SubAccountDistributedMark, false);
                            //}
                        }
 
                        //获取本地门锁列表
                        if (localDoorLockUserListTemp.Count == 0)
                        {
                            var list = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockAllAcountUserlist(doorLock);
                            localDoorLockUserListTemp = doorLock.localDoorLockUserList;
                        }
                        doorLock.ReSave();
                    }
                    else
                    {
                        Application.RunOnMainThread(() =>
                        {
                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.CloudServerResponseOvertime), Direction = AMPopTipDirection.Down, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                        });
                    }
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        MidFrameLayoutContent();
                        CommonPage.Loading.Hide();
                        midVerticalScrolViewLayout.EndHeaderRefreshing();
                    });
                }
            });
        }
 
        /// <summary>
        /// 显示界面
        /// </summary>
        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 - 116),
                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(150),
                TextID = R.MyInternationalizationString.Undistributed,
                TextColor = Shared.Common.ZigbeeColor.Current.XMTopTitleText,
                X = btnUndistributeIcon.Right,
                IsBold = true,
                TextSize = 13,
                TextAlignment = TextAlignment.CenterLeft,
            };
            btnAddFrameLayout.AddChidren(btnUndistributeText);
            if (HdlUserCenterResourse.ResidenceOption.AuthorityNo != 1)
            {
                btnAddFrameLayout.Width = 0;
                btnUndistributeIcon.Width = 0;
                btnUndistributeText.Width = 0;
            }
            EventHandler<MouseEventArgs> eHandler = (sender, e) =>
            {
                var undistributeDoorlockUserPage = new Shared.Phone.UserCenter.DoorLock.UndistributeDoorlockUserPage(doorLock, doorLock.localAllAccountList);
                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;
            midVerticalScrolViewLayout = new VerticalRefreshLayout() {  };
            this.midFrameLayout.AddChidren(midVerticalScrolViewLayout);
 
            if (localAllAccountListTemp.Count == 0)
            {
                CommonPage.Loading.Start("Loading...");
                ReadAccountDoorLockInfoList();
            }
            else
            {
                MidFrameLayoutContent();
            }
 
            midVerticalScrolViewLayout.BeginHeaderRefreshingAction += () =>
            {
                midVerticalScrolViewLayout.BeginHeaderRefreshing();
                ReadAccountDoorLockInfoList();
            };
        }
 
        /// <summary>
        /// 中部布局显示
        /// </summary>
        async void MidFrameLayoutContent()
        {
            midVerticalScrolViewLayout.RemoveAll();
            for (int i = 0; i < doorLock.localAllAccountList.Count; i++)
            {
                var currentAccount = doorLock.localAllAccountList[i];
                var RowView = new FrameLayout()
                {
                    Height = Application.GetRealHeight(127 + 23),
                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite,
                };
                midVerticalScrolViewLayout.AddChidren(RowView);
 
                var btnText = new Button()
                {
                    X = Application.GetRealWidth(58),
                    Width = Application.GetRealWidth(300),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                    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 == doorLock.localAllAccountList.Count - 1)
                {
                    line2.Visible = false;
                }
 
                btnText.Text = currentAccount.ShowName;
 
                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
                    {
                        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;
            }
        }
    }
}