黄学彪
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
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
using System;
using Shared;
using Shared.R;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using ZigBee.Device;
using Shared.Common;
namespace Shared.Phone.Device.Logic
{
    public class MemberList : FrameLayout
    {
        public MemberList()
        {
            Tag = "Logic";
        }
        Button selectedIcon = new Button();
        public static bool edit = false;
        VerticalRefreshLayout middle;
        CommonDevice common;
        Dictionary<string, string> editdeviceConditionsInfo;
        public void Show(CommonDevice commondevice, Dictionary<string, string> editdeviceConditions = null)
        {
            common = commondevice;
            editdeviceConditionsInfo = editdeviceConditions;
 
            #region  界面布局代码 
            UserView.HomePage.Instance.ScrollEnabled = false;
            this.BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor;
            TopView view = new TopView();
            this.AddChidren(view.TopRowView());
            view.toptitleNameBtn.TextID = MyInternationalizationString.userlist;
            view.clickBtn.MouseDownEventHandler += (sender, e) => { RemoveFromParent(); };
            middle = new VerticalRefreshLayout
            {
                Y = view.topRowLayout.Bottom,
                Height = Application.GetRealHeight(Method.H - 184),
                BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
            };
            this.AddChidren(middle);
            #endregion
 
            middle.BeginHeaderRefreshingAction += () =>
            {
                //重新刷新logic列表
                string macport = common.DeviceAddr + "_" + common.DeviceEpoint.ToString();
                for (int i = 0; i < Send.LockList.Count; i++)
                {
                    if (Send.LockList[i].DoorLockMacPort == macport)
                    {
                        ///从列表移除当前门锁全部的旧数据;
                        Send.LockList.Remove(Send.LockList[i]);
                        i--;
                    }
                }
                Read();
                //关闭刷新View;
                middle.EndHeaderRefreshing();
            };
            Read();
        }
        /// <summary>
        /// 读取当前门锁的云端数据;
        /// </summary>
        public void Read()
        {
 
            bool d = false;
            string macport = common.DeviceAddr + "_" + common.DeviceEpoint.ToString();
            for (int i = 0; i < Send.LockList.Count; i++)
            {
                if (Send.LockList[i].DoorLockMacPort == macport)
                {
                    ///已经存在该门锁信息
                    d = true;
                    break;
                }
 
            }
 
            CommonPage.Loading.Start();
            middle.RemoveAll();
            System.Threading.Tasks.Task.Run(async () =>
           {
               try
               {
                   if (!d)
                   {
                       var allMemberslist = await Send.AllMembers(macport);
                       Send.LockList.AddRange(allMemberslist);
                   }
               }
               catch { }
               finally
               {
                   Application.RunOnMainThread(() =>
                   {
                       CommonPage.Loading.Hide();
                       UserList(macport);
                   });
               }
           });
        }
        /// <summary>
        /// 成员列表的方法
        /// </summary>
        /// <param name="macport"></param>
        public void UserList(string macport)
        {
            for (int i=0;i<Send.LockList.Count;i++)
            {
                var user = Send.LockList[i];
                if (user.DoorLockMacPort != macport)
                {
                    continue;
                }
 
                FunView userView = new FunView();
                userView.iconBtn.Visible = false;
                userView.funnameBtn.X = Application.GetRealWidth(81);
                userView.funnameBtn.Text = user.UserName;
                userView.funnextBtn.X = Application.GetRealWidth(1080 - 81 - 58);
                userView.lineBtn.X = Application.GetRealWidth(81);
                userView.lineBtn.Width = Application.GetRealWidth(1080 - 81 - 58);
                if (Send.LockList.Count - 1 == i)
                {
                    userView.funFrameLayout.Height = Application.GetRealHeight(160 + 20);//最后一行增加20高度;
                    userView.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor;
                }
                middle.AddChidren(userView.FunFrameView());
                userView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
                 {
                     User(user);
                 };
 
            }
 
 
        }
        /// <summary>
        /// 当前成员信息的方法
        /// </summary>
        /// <param name="user"></param>
        public void User(Send.MembershipIfon user)
        {
 
 
            int count = user.UserIdMode.Count;
            #region  -------取消   完成
            var flMain = new FrameLayout { BackgroundColor = ZigbeeColor.Current.LogicTranslucentColor };
            this.AddChidren(flMain);
            CompleteView completeView = new CompleteView();
            flMain.AddChidren(completeView.Show(count));
            completeView.Btntitle.Text = user.UserName;
            EventHandler<MouseEventArgs> clickcancel = (sender, e) =>
            {
                UserView.HomePage.Instance.ScrollEnabled = true;
                flMain.RemoveFromParent();
            };
            flMain.MouseUpEventHandler += clickcancel;
            completeView.Btncancel.MouseUpEventHandler += clickcancel;
            //元素超出9个就用上下滑动控件;
            VerticalScrolViewLayout vV = null;
            if (count > 9)
            {
                ///元素超出9个;
                count = 6;
                //元素超出9个就用上下滑动控件;
                vV = new VerticalScrolViewLayout
                {
                    Y = Application.GetRealHeight(140 + 20),
                    Height = Application.GetRealHeight(160 * count),
                };
                //元素超出9个就用上下滑动控件;
                completeView.Show(count).AddChidren(vV);
                //清除之前的控件;
                vV.RemoveAll();
            }
            #endregion
            ///定两个变量记录之前的只值;
            string userId = "";
            string openMode = "";
            string accountName = "";
            string SelectedDeviceStatuscondition = "";
            for (int i = 0; i < user.UserIdMode.Count; i++)
            {
                var userifon = user.UserIdMode[i];
 
                mFunView lockView = new mFunView();
                if (user.UserIdMode.Count > 9)
                {
                  
                    vV.AddChidren(lockView.Show());
                }
                else
                {
                    lockView.frameLayout.Y = Application.GetRealHeight(140 + 20 + 160 * i);
                    completeView.Show(count).AddChidren(lockView.Show());
                }
                lockView.titleBtn.Text = userifon.ModeName;
 
                if ((user.UserIdMode.Count - 1) == i)
                {
                    lockView.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor;
                }
                lockView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
                 {
                     SelectedDeviceStatuscondition = "DoorLock";
                     selectedIcon.Visible = false;
                     selectedIcon = lockView.selectedIconBtn;
                     lockView.selectedIconBtn.Visible = true;
                     userId = userifon.UserId;
                     openMode = userifon.OpenMode.ToString();
                     accountName = completeView.Btntitle.Text + lockView.titleBtn.Text;
                 };
 
 
                if (string.IsNullOrEmpty(lockView.titleBtn.Text))
                {
                    string strname = "";
                    switch (userifon.OpenMode)
                    {
                        case 0:
                            {
                                strname = Language.StringByID(MyInternationalizationString.lockpassword);
                            }
                            break;
                        case 3:
                            {
                                strname = Language.StringByID(MyInternationalizationString.ic);
                            }
                            break;
                        case 15:
                            {
                                strname = Language.StringByID(MyInternationalizationString.fingerprint);
                            }
                            break;
                    }
                    lockView.titleBtn.Text = userifon.UserId + strname;
                }
 
                if (edit && editdeviceConditionsInfo != null)
                {
 
                    if (editdeviceConditionsInfo["AttriButeData2"] == userifon.UserId.ToString())
                    {
                        selectedIcon.Visible = false;
                        selectedIcon = lockView.selectedIconBtn;
                        lockView.selectedIconBtn.Visible = true;
                    }
 
                }
 
            }
    
            completeView.Btncomplete.MouseUpEventHandler += (sender, e) =>
            {
 
                string userIdstr = "", openModestr = "";
                var deviceConditionsInfo = new Dictionary<string, string>();
                var userdictionary = new Dictionary<string, string>();
                deviceConditionsInfo.Add("Type", "1");
                deviceConditionsInfo.Add("IsValid", "1");
                deviceConditionsInfo.Add("MacAddr", common.DeviceAddr);
                deviceConditionsInfo.Add("Epoint", common.DeviceEpoint.ToString());
                deviceConditionsInfo.Add("Cluster_ID", "64529");
                deviceConditionsInfo.Add("AttriButeData1", "2");
                deviceConditionsInfo.Add("Range", "0");
                deviceConditionsInfo.Add("AttriButeId", openMode);
                deviceConditionsInfo.Add("AttriButeData2", userId);
                userdictionary.Add("Account", Config.Instance.Guid);
                userdictionary.Add("AccountName", accountName);
                userdictionary.Add("Type", "1");
                userdictionary.Add("UserId", userId);
                if (edit)
                {
                    openModestr = editdeviceConditionsInfo["AttriButeId"];
                    userIdstr = editdeviceConditionsInfo["AttriButeData2"];
                }
                else
                {
                    openModestr = deviceConditionsInfo["AttriButeId"];
                    userIdstr = deviceConditionsInfo["AttriButeData2"];
                }
                if (SelectedDeviceStatuscondition != "")
                {
                    bool addConditions = false;
                    bool addAccounts = false;
                    for (int i = 0; i < Common.Logic.CurrentLogic.Conditions.Count; i++)
                    {
                        if (Common.Logic.CurrentLogic.Conditions[i]["Type"] == "1")
                        {
                            if ((Common.Logic.CurrentLogic.Conditions[i]["MacAddr"] == common.DeviceAddr) && (Common.Logic.CurrentLogic.Conditions[i]["Epoint"] == common.DeviceEpoint.ToString()))
                            {
                                if (Common.Logic.CurrentLogic.Conditions[i]["AttriButeId"] == openModestr && Common.Logic.CurrentLogic.Conditions[i]["AttriButeData2"] == userIdstr)
                                {
                                    Common.Logic.CurrentLogic.Conditions.RemoveAt(i);
                                    Common.Logic.CurrentLogic.Conditions.Insert(i, deviceConditionsInfo);
                                    addConditions = true;
                                    break;
                                }
                            }
                        }
                    }
                    for (int j = 0; j < Common.Logic.CurrentLogic.Accounts.Count; j++)
                    {
                        if (Common.Logic.CurrentLogic.Accounts[j]["Type"] == "1")
                        {
                            if (Common.Logic.CurrentLogic.Accounts[j]["UserId"] == userIdstr)
                            {
                                Common.Logic.CurrentLogic.Accounts.RemoveAt(j);
                                Common.Logic.CurrentLogic.Accounts.Insert(j, userdictionary);
                                addAccounts = true;
                                break;
                            }
                        }
                    }
                    if (!addConditions)
                    {//没有存在数据新加
                        Common.Logic.CurrentLogic.Conditions.Add(deviceConditionsInfo);
                    }
                    if (!addAccounts)
                    {//没有存在数据新加
                        Common.Logic.CurrentLogic.Accounts.Add(userdictionary);
                    }
                }
                else
                {
                    if (!edit)
                    {
                        var alert = new ShowMsgControl(ShowMsgType.Normal,
                         Language.StringByID(MyInternationalizationString.selectdevicestatuscondition),
                         Language.StringByID(MyInternationalizationString.confrim));
                        alert.Show();
                        return;
                    }
 
                }
                flMain.RemoveFromParent();
                var logicCommunalPage = new LogicCommunalPage();
                UserView.HomePage.Instance.AddChidren(logicCommunalPage);
                UserView.HomePage.Instance.PageIndex += 1;
                logicCommunalPage.Show(() => { });
 
            };
 
        }
        
    }
}