From f71e74b5f0d2716fbf05da016cdaa18d64e09f80 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期四, 31 十二月 2020 17:01:18 +0800
Subject: [PATCH] 又换完成最新门锁。空气质量传感器完成数据和基本配置功能。开发图表和自动化的同事可下载此代码

---
 ZigbeeApp/Shared/Phone/UserCenter/DoorLock/MemberFrozenPage.cs |  791 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 791 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/DoorLock/MemberFrozenPage.cs b/ZigbeeApp/Shared/Phone/UserCenter/DoorLock/MemberFrozenPage.cs
new file mode 100644
index 0000000..4ef606f
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/UserCenter/DoorLock/MemberFrozenPage.cs
@@ -0,0 +1,791 @@
+锘縰sing System;
+using System.Collections.Generic;
+using Shared.Common;
+using Shared.Phone.UserCenter.Device;
+using ZigBee.Device;
+namespace Shared.Phone.UserCenter.DoorLock
+{
+  public class MemberFrozenPage : DoorLockCommonLayout
+  {
+    /// <summary>
+    /// 鏋勯�犲嚱鏁�
+    /// </summary>
+    /// <param name="doorLock"></param>
+    public MemberFrozenPage(ZigBee.Device.DoorLock doorLock, Shared.Phone.UserCenter.MemberInfoRes accountObj)
+    {
+      this.doorLock = doorLock;
+      this.curAccountObj = accountObj;
+      BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCTopViewBackgroundColor;
+    }
+
+    #region  鍙橀噺鐢虫槑 
+    /// <summary>
+    /// 褰撳墠闂ㄩ攣
+    /// </summary>
+    ZigBee.Device.DoorLock doorLock;
+    /// <summary>
+    /// 褰撳墠鎴愬憳瀵硅薄v
+    /// </summary>
+    Shared.Phone.UserCenter.MemberInfoRes curAccountObj;
+    /// <summary>
+    /// 鍒锋柊View
+    /// </summary>
+    VerticalRefreshLayout bodyView;
+    #endregion
+
+    /// <summary>
+    /// 鍒濆鍖栨暟鎹俊鎭�
+    /// </summary>
+    void ReadDoorLockUserInfo()
+    {
+      System.Threading.Tasks.Task.Run(async () =>
+      {
+        try
+        {
+          var list = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockAllAcountUserlist(doorLock);
+          var result = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockOperateAccess(doorLock, curAccountObj.SubAccountDistributedMark);
+          var result1 = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockUnlockAccess(doorLock, curAccountObj.SubAccountDistributedMark);
+          var result2 = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockOperateAccess(doorLock, curAccountObj?.SubAccountDistributedMark);
+          if (result2 == true)
+          {
+            doorLock.IsFreezeAccount[curAccountObj.SubAccountDistributedMark] = true;
+          }
+          else
+          {
+            doorLock.IsFreezeAccount[curAccountObj.SubAccountDistributedMark] = false;
+          }
+          var result3 = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockUnlockAccess(doorLock, curAccountObj.SubAccountDistributedMark);
+          if (result3 == true)
+          {
+            doorLock.HasRemoteUnlockAccess[curAccountObj.SubAccountDistributedMark] = true;
+          }
+          else
+          {
+            doorLock.HasRemoteUnlockAccess[curAccountObj.SubAccountDistributedMark] = false;
+          }
+        }
+        catch { }
+        finally
+        {
+          Application.RunOnMainThread(() =>
+                {
+                MidRefresh();
+                bodyView.EndHeaderRefreshing();
+              });
+        }
+      });
+    }
+
+    /// <summary>
+    /// UI鏄剧ず 
+    /// </summary>
+    public void Show()
+    {
+      string accountTitle = "";
+      if (curAccountObj.UserName != null)
+      {
+        accountTitle = curAccountObj.UserName;
+      }
+      else
+      {
+        accountTitle = curAccountObj.Account;
+      }
+      this.TopFrameLayout(this, accountTitle);
+
+      EventHandler<MouseEventArgs> eHandlerBack = (sender, e) =>
+      {
+        RemoveFromParent();
+      };
+      this.btnBack.MouseUpEventHandler += eHandlerBack;
+      this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
+      this.MidFrameLayout(this);
+
+      bodyView = new VerticalRefreshLayout()
+      {
+      };
+      this.midFrameLayout.AddChidren(bodyView);
+      MidRefresh();
+
+      bodyView.BeginHeaderRefreshingAction += () =>
+      {
+        bodyView.BeginHeaderRefreshing();
+        ReadDoorLockUserInfo();
+      };
+    }
+    /// <summary>
+    /// 涓儴甯冨眬
+    /// </summary>
+    public async void MidRefresh()
+    {
+      bodyView.RemoveAll();
+
+      for (int i = 0; i < 3; i++)
+      {
+        var RowView = new FrameLayout()
+        {
+          Height = Application.GetRealHeight(127 + 23),
+          BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite,
+        };
+        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()
+        {
+          Width = Application.GetRealWidth(204),
+          X = Application.GetRealWidth(919 - 58),
+          Y = Application.GetRealHeight(25),
+        };
+        RowView.AddChidren(btnRightFrameLayout);
+
+        var btnRight = new Button()
+        {
+          Height = Application.GetMinRealAverage(60),
+          Width = Application.GetMinRealAverage(60),
+          X = Application.GetRealWidth(72),
+          Y = Application.GetRealHeight(32),
+          UnSelectedImagePath = "DoorLock/RightIcon.png",
+        };
+        btnRightFrameLayout.AddChidren(btnRight);
+
+        var line2 = new Button()
+        {
+          Y = RowView.Height - 1,
+          X = Application.GetRealWidth(58),
+          Width = Application.GetRealWidth(962),
+          Height = 1,
+          BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
+        };
+        RowView.AddChidren(line2);
+
+        if (i == 0)
+        {
+          btnText.Text = Language.StringByID(R.MyInternationalizationString.LockMethod);
+        }
+        else if (i == 1)
+        {
+          btnText.Text = Language.StringByID(R.MyInternationalizationString.FrozenUser);
+          btnRight.X = Application.GetRealWidth(50);
+          btnRight.Y = Application.GetRealHeight(32);
+          btnRight.Height = Application.GetMinRealAverage(63);
+          btnRight.Width = Application.GetMinRealAverage(104);
+          btnRight.UnSelectedImagePath = "DoorLock/Switch.png";
+          btnRight.SelectedImagePath = "DoorLock/SwitchOn.png";
+          var result = doorLock.IsFreezeAccount[curAccountObj.SubAccountDistributedMark];
+          if (result == true)
+          {
+            btnRight.IsSelected = true;
+          }
+          else
+          {
+            btnRight.IsSelected = false;
+          }
+        }
+        else if (i == 2)
+        {
+          if (doorLock.IsFreezeAccount[curAccountObj.SubAccountDistributedMark] == false)
+          {
+            btnText.Text = Language.StringByID(R.MyInternationalizationString.TempUnlockPermission);
+            btnRight.X = Application.GetRealWidth(50);
+            btnRight.Y = Application.GetRealHeight(32);
+            btnRight.Height = Application.GetMinRealAverage(63);
+            btnRight.Width = Application.GetMinRealAverage(104);
+            btnRight.UnSelectedImagePath = "DoorLock/Switch.png";
+            btnRight.SelectedImagePath = "DoorLock/SwitchOn.png";
+            line2.Visible = false;
+
+            var result1 = doorLock.HasRemoteUnlockAccess[curAccountObj.SubAccountDistributedMark];
+            if (result1 == true)
+            {
+              btnRight.IsSelected = true;
+            }
+            else
+            {
+              btnRight.IsSelected = false;
+            }
+          }
+          else
+          {
+            btnText.Width = 0;
+            btnRight.Width = 0;
+            line2.Width = 0;
+            RowView.BackgroundColor = Shared.Common.ZigbeeColor.Current.XMMidFrameLayout;
+          }
+        }
+
+        int currentIndex = i;
+        EventHandler<MouseEventArgs> eHandler = (sender, e) =>
+        {
+          if (currentIndex == 0)
+          {
+            var unLockMethod = new Shared.Phone.UserCenter.DoorLock.UnLockMethod(doorLock, curAccountObj);
+            Shared.Phone.UserView.HomePage.Instance.AddChidren(unLockMethod);
+            Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
+            unLockMethod.Show();
+          }
+          else if (currentIndex == 1)
+          {
+            if (!btnRight.IsSelected)
+            {
+              FreezeUser(true);
+            }
+            else
+            {
+              FreezeUser(false);
+            }
+          }
+          else if (currentIndex == 2)
+          {
+            if (!btnRight.IsSelected)
+            {
+              HasRemoteUnlockAccessMethod(true);
+            }
+            else
+            {
+              HasRemoteUnlockAccessMethod(false);
+            }
+          }
+        };
+        if (i == 0)
+        {
+          btnRightFrameLayout.MouseUpEventHandler += eHandler;
+          btnRight.MouseUpEventHandler += eHandler;
+          RowView.MouseUpEventHandler += eHandler;
+          btnText.MouseUpEventHandler += eHandler;
+        }
+        else if (i == 1)
+        {
+          btnRightFrameLayout.MouseUpEventHandler += eHandler;
+          btnRight.MouseUpEventHandler += eHandler;
+        }
+        else if (i == 2)
+        {
+          btnRightFrameLayout.MouseUpEventHandler += eHandler;
+          btnRight.MouseUpEventHandler += eHandler;
+        }
+      }
+    }
+
+    /// <summary>
+    /// 鍐荤粨璐︽埛
+    /// </summary>
+    /// <param name="isFreeze"></param>
+    void FreezeUser(bool isFreeze)
+    {
+      var dialog = new Dialog { };
+      string textFreeze = "";
+      if (isFreeze)
+      {
+        textFreeze = Language.StringByID(R.MyInternationalizationString.SureToFreezeAccount);
+      }
+      else
+      {
+        textFreeze = Language.StringByID(R.MyInternationalizationString.SureToUnFreeze);
+      }
+
+      string msg = Language.StringByID(R.MyInternationalizationString.GoPersonalCenter);
+      var alert = new Shared.Phone.UserCenter.ShowMsgControl(ShowMsgType.Confirm, textFreeze, Language.StringByID(R.MyInternationalizationString.DoorlockConfirm));
+      alert.Show();
+      //浣跨敤纭鍨嬪脊妗嗘椂,鐨勫洖璋冨嚱鏁�
+      alert.ConfirmClickEvent += () =>
+      {
+        System.Threading.Tasks.Task.Run(async () =>
+              {
+            int successConunt = 0;
+            int operateConunt = -1;
+            Application.RunOnMainThread(() => { CommonPage.Loading.Start(""); });
+            try
+            {
+              var doorLockId = doorLock.DeviceAddr + "_" + doorLock.DeviceEpoint;
+              var curAccountDoorLockUserList = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetAccountDoorLockUserList(doorLock, curAccountObj.SubAccountDistributedMark);
+              if (curAccountDoorLockUserList.Count != 0)
+              {
+                      //淇敼浜戠瀛樺偍淇℃伅
+                      operateConunt = curAccountDoorLockUserList.Count;
+                var tempGroupId = new List<List<int>>();
+                var tempUserIdList = new List<int> { };
+                foreach (var curDoorLockUser in curAccountDoorLockUserList)
+                {
+                        // 璐︽埛涓病鏈夐棬閿佺敤鎴�
+                        if (string.IsNullOrEmpty(curDoorLockUser.DoorLockLocalUserId))
+                  {
+                  }
+                  else
+                  {
+                    if (tempUserIdList.Count == 9)
+                    {
+                      tempGroupId.Add(tempUserIdList);
+                      tempUserIdList = new List<int>();
+                    }
+                    tempUserIdList.Add(int.Parse(curDoorLockUser.DoorLockLocalUserId));
+                  }
+                }
+                tempGroupId.Add(tempUserIdList);
+                      //鎵归噺鍐荤粨闂ㄩ攣涓殑璐︽埛
+                      ZigBee.Device.DoorLock.AccessType accessType;
+                if (isFreeze)
+                {
+                  accessType = ZigBee.Device.DoorLock.AccessType.DisEnableMoreUsers;
+                }
+                else
+                {
+                  accessType = ZigBee.Device.DoorLock.AccessType.EnableMoreUsers;
+                }
+                      //鍐荤粨/瑙e喕鐢ㄦ埛
+                      int count1 = tempGroupId.Count;
+                if (tempGroupId.Count == 1)
+                {
+                  foreach (var a in tempGroupId)
+                  {
+                    if (a.Count == 0)
+                    {
+                      count1 = 0;
+                      break;
+                    }
+                  }
+                }
+                int count2 = 0;
+
+                int tempCount = 0;
+                for (int i = 0; i < tempGroupId.Count; i++)
+                {
+                  var tempUserIdList1 = tempGroupId[i];
+                  if (tempUserIdList1.Count == 0)
+                  {
+                    break;
+                  }
+                  var passData = doorLock.FreezeAccountData(tempUserIdList1, accessType);
+                  var resultData = await doorLock.DefaultControlAsync(passData);
+                  if (resultData != null && resultData.defaultControlResponseData != null)
+                  {
+                    if (resultData.defaultControlResponseData.status == 32)
+                    {
+                      count2++;
+                    }
+                    else if (resultData.defaultControlResponseData.status == 33)
+                    {
+                      count2++;
+                    }
+                    System.Threading.Thread.Sleep(1000);
+                  }
+                  else
+                  {
+                    Application.RunOnMainThread(() =>
+                          {
+                                new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(Common.CommonPage.Instance);
+                              });
+                    return;
+                  }
+                  tempCount++;
+                }
+
+                      // 鎵归噺鍐荤粨闂ㄩ攣涓殑璐︽埛鍚庯紝鍑嗗鍐荤粨浜戠璐︽埛
+                      if (count2 == count1)
+                {
+                  foreach (var curDoorLockUser in curAccountDoorLockUserList)
+                  {
+                    if (isFreeze)
+                    {
+                      var refreshDoorLockData = new ZigBee.Device.DoorLock.RefreshDoorLockData();
+                      if (UserCenterResourse.UserInfo.AuthorityNo != 1)
+                      {
+                        refreshDoorLockData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+                        refreshDoorLockData.IsOtherAccountCtrl = true;
+                      }
+                      if (doorLock.DeviceAddr != null)
+                      {
+                        refreshDoorLockData.DoorLockId = doorLock.DeviceAddr + "_" + doorLock.DeviceEpoint;
+                      }
+
+                      refreshDoorLockData.OpenLockMode = curDoorLockUser.OpenLockMode;
+                      refreshDoorLockData.DoorLockLocalUserId = curDoorLockUser.DoorLockLocalUserId;
+                      refreshDoorLockData.PrimaryId = curDoorLockUser.Id;
+                      refreshDoorLockData.IsFreezeUser = true;
+                      refreshDoorLockData.IsTempUnlockAuthority = doorLock.HasRemoteUnlockAccess[curAccountObj.SubAccountDistributedMark];
+                            //鍐荤粨浜戠
+                            var result = await ZigBee.Device.DoorLock.SendDoorLockToServer("DoorLock/UpdateDoorLock", refreshDoorLockData);
+                      if (result != null)
+                      {
+                        if (result.StateCode == "Success")
+                        {
+                          successConunt++;
+                        }
+                        else
+                        {
+                          Application.RunOnMainThread(() =>
+                                {
+                                            if (isFreeze)
+                                            {
+                                              new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.FreezeFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                                            }
+                                            else
+                                            {
+                                              new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.UnFreezeFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                                            }
+                                            return;
+                                          });
+                        }
+                      }
+                      else
+                      {
+                        Application.RunOnMainThread(() =>
+                              {
+                                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.CloudServerResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(Common.CommonPage.Instance);
+                                      });
+                      }
+                    }
+                    else
+                    {
+                      var refreshDoorLockData = new ZigBee.Device.DoorLock.RefreshDoorLockData();
+                      if (UserCenterResourse.UserInfo.AuthorityNo != 1)
+                      {
+                        refreshDoorLockData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+                        refreshDoorLockData.IsOtherAccountCtrl = true;
+                      }
+                      if (doorLock.DeviceAddr != null)
+                      {
+                        refreshDoorLockData.DoorLockId = doorLock.DeviceAddr + "_" + doorLock.DeviceEpoint;
+                      }
+
+                      refreshDoorLockData.OpenLockMode = curDoorLockUser.OpenLockMode;
+                      refreshDoorLockData.DoorLockLocalUserId = curDoorLockUser.DoorLockLocalUserId;
+                      refreshDoorLockData.PrimaryId = curDoorLockUser.Id;
+                      refreshDoorLockData.IsFreezeUser = false;
+                      refreshDoorLockData.IsTempUnlockAuthority = doorLock.HasRemoteUnlockAccess[curAccountObj.SubAccountDistributedMark];
+                            //瑙e喕浜戠
+                            var result = await ZigBee.Device.DoorLock.SendDoorLockToServer("DoorLock/UpdateDoorLock", refreshDoorLockData);
+                      if (result != null)
+                      {
+                        if (result.StateCode == "Success")
+                        {
+                          successConunt++;
+                        }
+                        else
+                        {
+                          Application.RunOnMainThread(() =>
+                                {
+                                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.FreezeFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                                          });
+                        }
+                      }
+                      else
+                      {
+                        Application.RunOnMainThread(() =>
+                              {
+                                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.CloudServerResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(Common.CommonPage.Instance);
+                                      });
+                      }
+                    }
+                  }
+                }
+                else
+                {
+                  Application.RunOnMainThread(() =>
+                        {
+                            if (isFreeze)
+                            {
+                              new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.FreezeFailed) + ".", Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(Common.CommonPage.Instance);
+                            }
+                            else
+                            {
+                              new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.UnFreezeFailed) + ".", Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(Common.CommonPage.Instance);
+                            }
+                          });
+                }
+              }
+              else
+              {
+                      //娣诲姞浜戠瀛樺偍淇℃伅
+                      //鍐荤粨/瑙e喕浜戠
+                      var addLockInfo = new ZigBee.Device.DoorLock.AddDoorLockData();
+                if (UserCenterResourse.UserInfo.AuthorityNo != 1)
+                {
+                  addLockInfo.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+                  addLockInfo.IsOtherAccountCtrl = true;
+                }
+                addLockInfo.CloudAccountId = curAccountObj.SubAccountDistributedMark;
+                if (doorLock.DeviceAddr != null)
+                {
+                  addLockInfo.DoorLockId = doorLock.DeviceAddr + "_" + doorLock.DeviceEpoint;
+                }
+                addLockInfo.EntryTime = System.DateTime.Now;
+                if (isFreeze)
+                {
+                  addLockInfo.IsFreezeUser = true;
+                }
+                else
+                {
+                  addLockInfo.IsFreezeUser = false;
+                }
+                addLockInfo.IsTempUnlockAuthority = doorLock.HasRemoteUnlockAccess[curAccountObj.SubAccountDistributedMark];
+                var result = await ZigBee.Device.DoorLock.SendDoorLockToServer("DoorLock/AddDoorLock", addLockInfo);
+                if (result != null)
+                {
+                  if (result.StateCode == "Success")
+                  {
+                    operateConunt = 0;
+                  }
+                  else
+                  {
+                    Application.RunOnMainThread(() =>
+                          {
+                                if (isFreeze)
+                                {
+                                  new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.FreezeFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                                }
+                                else
+                                {
+                                  new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.UnFreezeFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                                }
+                                return;
+                              });
+                  }
+                }
+                else
+                {
+                  Application.RunOnMainThread(() =>
+                        {
+                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.CloudServerResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+
+                          });
+                }
+              }
+            }
+            catch { }
+            finally
+            {
+              if (operateConunt == successConunt)
+              {
+                if (isFreeze)
+                {
+                  doorLock.IsFreezeAccount[curAccountObj.SubAccountDistributedMark] = true;
+                }
+                else
+                {
+                  doorLock.IsFreezeAccount[curAccountObj.SubAccountDistributedMark] = false;
+                }
+                doorLock.ReSave();
+              }
+              Application.RunOnMainThread(() =>
+                    {
+                    MidRefresh();
+                    CommonPage.Loading.Hide();
+                  });
+            }
+          });
+      };
+    }
+
+    /// <summary>
+    /// 鏄惁缁欏瓙璐︽埛鎷ユ湁杩滅▼寮�閿佺殑鏉′欢
+    /// </summary>
+    /// <param name="hasAccess"></param>
+    void HasRemoteUnlockAccessMethod(bool hasAccess)
+    {
+      string msg = Language.StringByID(R.MyInternationalizationString.SureGiveAccessToSubaccount);
+      if (!hasAccess)
+      {
+        msg = Language.StringByID(R.MyInternationalizationString.SureCancelAccessToSubaccount);
+      }
+      var alert = new Shared.Phone.UserCenter.ShowMsgControl(ShowMsgType.Confirm, msg, Language.StringByID(R.MyInternationalizationString.DoorlockConfirm));
+      alert.Show();
+      //浣跨敤纭鍨嬪脊妗嗘椂,鐨勫洖璋冨嚱鏁�
+      alert.ConfirmClickEvent += () =>
+      {
+        System.Threading.Tasks.Task.Run(async () =>
+              {
+            int successConunt = 0;
+            int operateConunt = -1;
+            Application.RunOnMainThread(() => { CommonPage.Loading.Start("Loading..."); });
+            try
+            {
+              var resultList = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetAccountDoorLockUserList(doorLock, curAccountObj.SubAccountDistributedMark);
+              var uList = new List<string> { };
+              if (resultList != null)
+              {
+                foreach (var a in resultList)
+                {
+                  uList.Add(a.CloudAccountId);
+                }
+              }
+              var d = uList.Find((value) => { return value == curAccountObj.SubAccountDistributedMark; });
+              if (d != null)
+              {
+                      //淇敼浜戠瀛樺偍淇℃伅
+                      var curAccountDoorLockUserList = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetAccountDoorLockUserList(doorLock, curAccountObj.SubAccountDistributedMark);
+
+                foreach (var curDoorLockUser in curAccountDoorLockUserList)
+                {
+                  operateConunt = curAccountDoorLockUserList.Count;
+                  if (hasAccess)
+                  {
+                    var refreshDoorLockData = new ZigBee.Device.DoorLock.RefreshDoorLockData();
+                    if (UserCenterResourse.UserInfo.AuthorityNo != 1)
+                    {
+                      refreshDoorLockData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+                      refreshDoorLockData.IsOtherAccountCtrl = true;
+                    }
+                    if (doorLock.DeviceAddr != null)
+                    {
+                      refreshDoorLockData.DoorLockId = doorLock.DeviceAddr + "_" + doorLock.DeviceEpoint;
+                    }
+                    refreshDoorLockData.PrimaryId = curDoorLockUser.Id;
+                    refreshDoorLockData.IsFreezeUser = false;
+                    refreshDoorLockData.IsTempUnlockAuthority = true;
+                          // 鎺堟潈
+                          var result = await ZigBee.Device.DoorLock.SendDoorLockToServer("DoorLock/UpdateDoorLock", refreshDoorLockData);
+                    if (result != null)
+                    {
+                      if (result.StateCode == "Success")
+                      {
+                        successConunt++;
+                      }
+                      else
+                      {
+                        Application.RunOnMainThread(() =>
+                              {
+                                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GiveAccessToSubaccountFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                                      });
+                      }
+                    }
+                    else
+                    {
+                      Application.RunOnMainThread(() =>
+                            {
+                                    new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.CloudServerResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                                  });
+                    }
+                  }
+                  else
+                  {
+                    var refreshDoorLockData = new ZigBee.Device.DoorLock.RefreshDoorLockData();
+                    if (UserCenterResourse.UserInfo.AuthorityNo != 1)
+                    {
+                      refreshDoorLockData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+                      refreshDoorLockData.IsOtherAccountCtrl = true;
+                    }
+                    if (doorLock.DeviceAddr != null)
+                    {
+                      refreshDoorLockData.DoorLockId = doorLock.DeviceAddr + "_" + doorLock.DeviceEpoint;
+                    }
+                    refreshDoorLockData.PrimaryId = curDoorLockUser.Id;
+                    refreshDoorLockData.IsFreezeUser = false;
+                    refreshDoorLockData.IsTempUnlockAuthority = false;
+                          //鍙栨秷鏉冮檺
+                          var result = await ZigBee.Device.DoorLock.SendDoorLockToServer("DoorLock/UpdateDoorLock", refreshDoorLockData);
+                    if (result != null)
+                    {
+                      if (result.StateCode == "Success")
+                      {
+                        successConunt++;
+                      }
+                      else
+                      {
+                        Application.RunOnMainThread(() =>
+                              {
+                                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.CancelAccessToSubaccountFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                                      });
+                      }
+                    }
+                    else
+                    {
+                      Application.RunOnMainThread(() =>
+                            {
+                                    new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.CloudServerResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                                  });
+                    }
+                  }
+                }
+              }
+              else
+              {
+                      //鏂板锛屼笖涓嶅喕缁� 
+                      var addLockInfo = new ZigBee.Device.DoorLock.AddDoorLockData();
+                if (UserCenterResourse.UserInfo.AuthorityNo != 1)
+                {
+                  addLockInfo.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
+                  addLockInfo.IsOtherAccountCtrl = true;
+                }
+                addLockInfo.CloudAccountId = curAccountObj.SubAccountDistributedMark;
+                if (doorLock.DeviceAddr != null)
+                {
+                  addLockInfo.DoorLockId = doorLock.DeviceAddr + "_" + doorLock.DeviceEpoint;
+                }
+                addLockInfo.EntryTime = System.DateTime.Now;
+                addLockInfo.IsFreezeUser = false;
+                if (hasAccess)
+                {
+                  addLockInfo.IsTempUnlockAuthority = true;
+                }
+                else
+                {
+                  addLockInfo.IsTempUnlockAuthority = false;
+                }
+                var result = await ZigBee.Device.DoorLock.SendDoorLockToServer("DoorLock/AddDoorLock", addLockInfo);
+                if (result != null)
+                {
+                  if (result.StateCode == "Success")
+                  {
+                    operateConunt = 0;
+                  }
+                  else
+                  {
+                    Application.RunOnMainThread(() =>
+                          {
+                                if (hasAccess)
+                                {
+                                  new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GiveAccessToSubaccountFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                                }
+                                else
+                                {
+                                  new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.CancelAccessToSubaccountFailed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                                }
+                                return;
+                              });
+                  }
+                }
+                else
+                {
+                  Application.RunOnMainThread(() =>
+                        {
+                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.CloudServerResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
+                          });
+                }
+              }
+
+            }
+            catch { }
+            finally
+            {
+              if (operateConunt == successConunt)
+              {
+                if (hasAccess)
+                {
+                  doorLock.HasRemoteUnlockAccess[curAccountObj.SubAccountDistributedMark] = true;
+                }
+                else
+                {
+                  doorLock.HasRemoteUnlockAccess[curAccountObj.SubAccountDistributedMark] = false;
+                }
+                doorLock.ReSave();
+              }
+              Application.RunOnMainThread(() =>
+                    {
+                    MidRefresh();
+                    CommonPage.Loading.Hide();
+                  });
+            }
+          });
+      };
+    }
+  }
+}

--
Gitblit v1.8.0