黄学彪
2019-11-18 16604a593202f2f87adf71abd57d036fe7da3b52
ZigbeeApp/Shared/Phone/UserCenter/DoorLock/UndistributeDoorlockUserPage.cs
@@ -54,32 +54,76 @@
                        foreach (var curAccountObj in doorLock.localAllAccountList)
                        {
                            if (UserCenterResourse.UserInfo.AuthorityNo != 1)
                            {
                                localDoorLockObj.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
                                localDoorLockObj.IsOtherAccountCtrl = true;
                            }
                            localDoorLockObj.CloudAccountId = curAccountObj.SubAccountDistributedMark;
                            if (doorLock.DeviceAddr != null)
                            {
                                localDoorLockObj.DoorLockId = doorLock.DeviceAddr + "_" + doorLock.DeviceEpoint;
                            }
                            var getDoorLockInfoList = await ZigBee.Device.DoorLock.GetDoorLockInfoFromServer("DoorLock/GetDoorLockPager", localDoorLockObj);
                            if (getDoorLockInfoList != null)
                            {
                                foreach (var curDoorLockUser in getDoorLockInfoList.PageData)
                                {
                                    if (curDoorLockUser.DoorLockLocalUserId == null || curDoorLockUser.DoorLockLocalUserId == "")
                                    {
                                        continue;
                                    }
                                    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[int.Parse(curDoorLockUser.DoorLockLocalUserId)] = doorLockObj;
                                    }
                                    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);
                                    else
                                    {
                                        if (curDoorLockUser.DoorLockLocalUserId != null)
                                        {
                                            //门锁中没有,云端有用户ID,后台删除云端这些ID
                                            var deleteDoorLockData = new ZigBee.Device.DoorLock.DeleteDoorLockData();
                                            if (UserCenterResourse.UserInfo.AuthorityNo != 1)
                                            {
                                                deleteDoorLockData.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
                                                deleteDoorLockData.IsOtherAccountCtrl = true;
                                            }
                                            if (doorLock.DeviceAddr != null)
                                            {
                                                deleteDoorLockData.DoorLockId = doorLock.DeviceAddr + "_" + doorLock.DeviceEpoint;
                                            }
                                            deleteDoorLockData.DoorLockLocalUserId = curDoorLockUser.DoorLockLocalUserId;
                                            deleteDoorLockData.PrimaryId = curDoorLockUser.Id;
                                            deleteDoorLockData.DelDoorLockDelType = 2;
                                            var result = await ZigBee.Device.DoorLock.SendDoorLockToServer("DoorLock/DelDoorLock", deleteDoorLockData);
                                            int i = 0;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Application.RunOnMainThread(() =>
                                {
                                    new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.CloudServerResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                                    return;
                                });
                            }
                        }
                    }
                    else
                    {
                        Application.RunOnMainThread(() =>
                        {
                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                        });
                    }
                }
                catch { }
@@ -87,7 +131,7 @@
                {
                    Application.RunOnMainThread(() =>
                    {
                        RefreshList();
                        MidFrameLayoutContent();
                        CommonPage.Loading.Hide();
                    });
                }
@@ -104,119 +148,12 @@
            EventHandler<MouseEventArgs> eHandlerBack = (sender, e) =>
            {
                RemoveFromParent();
            };
             };
            this.btnBack.MouseUpEventHandler += eHandlerBack;
            this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
            this.MidFrameLayout(this);
            MidFrameLayoutContent();
            ReadDoorLockUserInfo();
        }
        public void RefreshList()
        {
            bodyView.RemoveAll();
            foreach (var curUserId in doorLock.localDoorLockUserList.Keys)
            {
                var curDoorLockUser = doorLock.localDoorLockUserList[curUserId];
                if (curDoorLockUser.ConnectedAccount != "")
                {
                    continue;
                }
                if (curDoorLockUser.UserID > 245)
                {
                    continue;
                }
                var RowView = new FrameLayout()
                {
                    Height = Application.GetRealHeight(161),
                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite,
                };
                bodyView.AddChidren(RowView);
                var btnDistributeUnlockIconFrameLayout = new FrameLayout()
                {
                    Height = Application.GetRealHeight(84),
                    Width = Application.GetRealWidth(84),
                    X = Application.GetRealWidth(58),
                    Y = Application.GetRealHeight(43),
                };
                RowView.AddChidren(btnDistributeUnlockIconFrameLayout);
                var btnDistributeUnlockIcon = new Button()
                {
                    Height = Application.GetRealHeight(84),
                    Width = Application.GetRealWidth(84),
                    UnSelectedImagePath = "DoorLock/DistributeUnlockIcon.png",
                };
                btnDistributeUnlockIconFrameLayout.AddChidren(btnDistributeUnlockIcon);
                var btnText = new Button()
                {
                    X = Application.GetRealWidth(176),
                    Width = Application.GetRealWidth(300),
                    Height = Application.GetRealHeight(300),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                    Gravity = Gravity.CenterVertical,
                };
                RowView.AddChidren(btnText);
                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);
                #region 数据处理
                switch (curDoorLockUser.UnlockType)
                {
                    case 0:
                        if (curDoorLockUser.UserName != "")
                        {
                            btnText.Text = curDoorLockUser.UserName;
                        }
                        else
                        {
                            btnText.Text = Language.StringByID(R.MyInternationalizationString.Password) + "ID" + curDoorLockUser.UserID;
                        }
                        break;
                    case 3:
                        if (curDoorLockUser.UserName != "")
                        {
                            btnText.Text = curDoorLockUser.UserName;
                        }
                        else
                        {
                            btnText.Text = Language.StringByID(R.MyInternationalizationString.IcCard) + "ID" + curDoorLockUser.UserID;
                        }
                        break;
                    case 15:
                        if (curDoorLockUser.UserName != "")
                        {
                            btnText.Text = curDoorLockUser.UserName;
                        }
                        else
                        {
                            btnText.Text = Language.StringByID(R.MyInternationalizationString.Fingerprint) + "ID" + +curDoorLockUser.UserID;
                        }
                        break;
                }
                EventHandler<MouseEventArgs> eHandler = (sender, e) =>
                {
                    MatchUsersFrameLayout(curDoorLockUser);
                };
                btnDistributeUnlockIcon.MouseUpEventHandler += eHandler;
                btnDistributeUnlockIconFrameLayout.MouseUpEventHandler += eHandler;
                RowView.MouseUpEventHandler += eHandler;
                btnText.MouseUpEventHandler += eHandler;
                #endregion
            }
        }
        public void MidFrameLayoutContent()
@@ -234,8 +171,8 @@
                Width = Application.GetRealWidth(141 + 100),
                Y = Application.GetRealHeight(35),
                X = Application.GetRealWidth(812 - 100),
                TextAlignment = TextAlignment.Center,
                Text = Language.StringByID(R.MyInternationalizationString.LockMethod),
                TextAlignment = TextAlignment.CenterRight,
                Text = Language.StringByID(R.MyInternationalizationString.AllMethod),
                TextColor = Shared.Common.ZigbeeColor.Current.XMTopTitleText,
                TextSize = 12,
            };
@@ -256,17 +193,147 @@
                SideslipFramelayout();
            };
            var btnLine = new Button
            {
                Y = midTopFrameLayout.Bottom,
                Height = 1,
                BackgroundColor = Shared.Common.ZigbeeColor.Current.XMTitleLine,
            };
            this.midFrameLayout.AddChidren(btnLine);
            bodyView = new VerticalScrolViewLayout()
            {
                Y = midTopFrameLayout.Bottom,
                Height = Application.GetRealHeight(1921 - 184 - 115 - 1),
            };
            this.midFrameLayout.AddChidren(bodyView);
            RefreshList();
        }
        void RefreshList()
        {
            bodyView.RemoveAll();
            var curLocalDoorLockUserList = new Dictionary<int, DoorLockCommonInfo.LocaDoorLockObj>();
            foreach (var curUserId in doorLock.localDoorLockUserList.Keys)
            {
                var curDoorLockUser = doorLock.localDoorLockUserList[curUserId];
                if (curDoorLockUser.ConnectedAccount != "")
                {
                    continue;
                }
                if (curDoorLockUser.UserID > 245)
                {
                    continue;
                }
                curLocalDoorLockUserList.Add(curUserId, curDoorLockUser);
            }
            int i = 0;
            foreach (var curUserId in curLocalDoorLockUserList.Keys)
            {
                var curDoorLockUser = curLocalDoorLockUserList[curUserId];
                var rowFrameLayout = new FrameLayout()
                {
                    Height = Application.GetRealHeight(127 + 23),
                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite,
                };
                bodyView.AddChidren(rowFrameLayout);
                var btnDistributeUnlockIconFrameLayout = new FrameLayout()
                {
                    Height = Application.GetRealHeight(84),
                    Width = Application.GetRealWidth(84),
                    X = Application.GetRealWidth(58),
                    Y = Application.GetRealHeight(43),
                };
                rowFrameLayout.AddChidren(btnDistributeUnlockIconFrameLayout);
                var btnDistributeUnlockIcon = new Button()
                {
                    Height = Application.GetRealHeight(84),
                    Width = Application.GetRealWidth(84),
                    UnSelectedImagePath = "DoorLock/DistributeUnlockIcon.png",
                };
                btnDistributeUnlockIconFrameLayout.AddChidren(btnDistributeUnlockIcon);
                var btnText = new Button()
                {
                    X = Application.GetRealWidth(176),
                    Width = Application.GetRealWidth(300),
                    Height = Application.GetRealHeight(300),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                    Gravity = Gravity.CenterVertical,
                };
                rowFrameLayout.AddChidren(btnText);
                var line2 = new Button()
                {
                    Y = rowFrameLayout.Height - 1,
                    X = Application.GetRealWidth(58),
                    Width = Application.GetRealWidth(965),
                    Height = 1,
                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
                };
                rowFrameLayout.AddChidren(line2);
                #region 数据处理
                int currentIndex = i;
                if (currentIndex == curLocalDoorLockUserList.Keys.Count - 1)
                {
                    line2.Visible = false;
                }
                switch (curDoorLockUser.UnlockType)
                {
                    case 0:
                        if (curDoorLockUser.UserName != "" && curDoorLockUser.UserName != null)
                        {
                            btnText.Text = curDoorLockUser.UserName;
                        }
                        else
                        {
                            btnText.Text = Language.StringByID(R.MyInternationalizationString.Password) + "ID" + curDoorLockUser.UserID;
                        }
                        break;
                    case 3:
                        if (curDoorLockUser.UserName != "" && curDoorLockUser.UserName != null)
                        {
                            btnText.Text = curDoorLockUser.UserName;
                        }
                        else
                        {
                            btnText.Text = Language.StringByID(R.MyInternationalizationString.IcCard) + "ID" + curDoorLockUser.UserID;
                        }
                        break;
                    case 15:
                        if (curDoorLockUser.UserName != "" && curDoorLockUser.UserName != null)
                        {
                            btnText.Text = curDoorLockUser.UserName;
                        }
                        else
                        {
                            btnText.Text = Language.StringByID(R.MyInternationalizationString.Fingerprint) + "ID" + +curDoorLockUser.UserID;
                        }
                        break;
                }
                EventHandler<MouseEventArgs> eHandler = (sender, e) =>
                {
                    MatchUsersFrameLayout(curDoorLockUser);
                };
                btnDistributeUnlockIcon.MouseUpEventHandler += eHandler;
                btnDistributeUnlockIconFrameLayout.MouseUpEventHandler += eHandler;
                rowFrameLayout.MouseUpEventHandler += eHandler;
                btnText.MouseUpEventHandler += eHandler;
                #endregion
                i++;
            }
        }
        //本地账户
        public void MatchUsersFrameLayout(ZigBee.Device.DoorLock.LocaDoorLockObj curDoorLockUser)
        void MatchUsersFrameLayout(ZigBee.Device.DoorLock.LocaDoorLockObj curDoorLockUser)
        {
            #region  UI
            FrameLayout flMain = new FrameLayout { BackgroundColor = 0x0f000000 };
@@ -420,6 +487,13 @@
                EventHandler<MouseEventArgs> eHandler = (sender, e) =>
                {
                    if (doorLock.IsFreezeAccount[currentAccount.SubAccountDistributedMark] == true)
                    {
                        new Tip() { MaxWidth = 150, Text = btnUserName.Text + Language.StringByID(R.MyInternationalizationString.AccountIsFreezed), Direction = AMPopTipDirection.Down, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                        return;
                    }
                    if (!btnChoose.IsSelected)
                    {
                        if (oldbuttonChoose != null)
@@ -463,6 +537,11 @@
                else
                {
                    var addLockInfo = new ZigBee.Device.DoorLock.AddDoorLockData();
                    if (UserCenterResourse.UserInfo.AuthorityNo != 1)
                    {
                        addLockInfo.LoginAccessToken = UserCenterLogic.GetConnectMainToken();
                        addLockInfo.IsOtherAccountCtrl = true;
                    }
                    addLockInfo.CloudAccountId = curAccountId;
                    if (doorLock.DeviceAddr != null)
                    {
@@ -474,7 +553,7 @@
                    switch (curDoorLockUser.UnlockType)
                    {
                        case 0:
                            if (curDoorLockUser.UserName != "")
                            if (curDoorLockUser.UserName != "" && curDoorLockUser.UserName != null)
                            {
                                addLockInfo.UserIdRemarks = curDoorLockUser.UserName;
                            }
@@ -484,7 +563,7 @@
                            }
                            break;
                        case 3:
                            if (curDoorLockUser.UserName != "")
                            if (curDoorLockUser.UserName != "" && curDoorLockUser.UserName != null)
                            {
                                addLockInfo.UserIdRemarks = curDoorLockUser.UserName;
                            }
@@ -494,7 +573,7 @@
                            }
                            break;
                        case 15:
                            if (curDoorLockUser.UserName != "")
                            if (curDoorLockUser.UserName != "" && curDoorLockUser.UserName != null)
                            {
                                addLockInfo.UserIdRemarks = curDoorLockUser.UserName;
                            }
@@ -507,26 +586,42 @@
                    addLockInfo.EntryTime = curDoorLockUser.EntryTime;
                    var result = await ZigBee.Device.DoorLock.SendDoorLockToServer("DoorLock/AddDoorLock", addLockInfo);
                    if (result != null && result.StateCode == "Success")
                    if (result != null)
                    {
                        if (doorLock.localDoorLockUserList.ContainsKey(curDoorLockUser.UserID))
                        if (result.StateCode == "Success")
                        {
                            doorLock.localDoorLockUserList.Remove(curDoorLockUser.UserID);
                            var localDoorLockObj = new ZigBee.Device.DoorLock.LocaDoorLockObj() { };
                            localDoorLockObj.UserID = curDoorLockUser.UserID;
                            localDoorLockObj.UnlockType = curDoorLockUser.UnlockType;
                            localDoorLockObj.EntryTime = curDoorLockUser.EntryTime;
                            localDoorLockObj.UserName = curDoorLockUser.UserName;
                            localDoorLockObj.ConnectedAccount = curAccountId;
                            doorLock.localDoorLockUserList.Add(curDoorLockUser.UserID, localDoorLockObj);
                            RefreshList();
                            //存门锁信息
                            var resultList = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetCloudLocalDoorLocklist(doorLock, curAccountId);
                            var uList = new List<int> { };
                            if (resultList != null)
                            {
                                foreach (var a in resultList.Keys)
                                {
                                    uList.Add(a);
                                }
                            }
                            var d = uList.Find((value) => { return value == curDoorLockUser.UserID; });
                            if (d != null)
                            {
                                RefreshList();
                                flMain.RemoveFromParent();
                                bottomFrameLayout.RemoveAll();
                            }
                            else
                            {
                                new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.CloudServerResponseOvertime), Direction = AMPopTipDirection.Down, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                            }
                        }
                        else
                        {
                            new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Down, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                            flMain.RemoveFromParent();
                            bottomFrameLayout.RemoveAll();
                        }
                    }
                    else
                    {
                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.BindFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinish);
                        new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.CloudServerResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinish);
                        flMain.RemoveFromParent();
                        bottomFrameLayout.RemoveAll();
                    }
@@ -697,6 +792,9 @@
        void DisplayByType(int unlockMethod)
        {
            bodyView.RemoveAll();
            var curLocalDoorLockUserList = new Dictionary<int, DoorLockCommonInfo.LocaDoorLockObj>();
            foreach (var curUserId in doorLock.localDoorLockUserList.Keys)
            {
                var curDoorLockUser = doorLock.localDoorLockUserList[curUserId];
@@ -704,12 +802,20 @@
                {
                    continue;
                }
                var RowView = new FrameLayout()
                curLocalDoorLockUserList.Add(curUserId, curDoorLockUser);
            }
            int i = 0;
            foreach (var curUserId in curLocalDoorLockUserList.Keys)
            {
                var curDoorLockUser = curLocalDoorLockUserList[curUserId];
                var rowFrameLayout = new FrameLayout()
                {
                    Height = Application.GetRealHeight(161),
                    Height = Application.GetRealHeight(150),
                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite,
                };
                bodyView.AddChidren(RowView);
                bodyView.AddChidren(rowFrameLayout);
                var btnDistributeUnlockIconFrameLayout = new FrameLayout()
                {
@@ -718,7 +824,7 @@
                    X = Application.GetRealWidth(58),
                    Y = Application.GetRealHeight(43),
                };
                RowView.AddChidren(btnDistributeUnlockIconFrameLayout);
                rowFrameLayout.AddChidren(btnDistributeUnlockIconFrameLayout);
                var btnDistributeUnlockIcon = new Button()
                {
@@ -737,19 +843,25 @@
                    TextColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                    Gravity = Gravity.CenterVertical,
                };
                RowView.AddChidren(btnText);
                rowFrameLayout.AddChidren(btnText);
                var line2 = new Button()
                {
                    Y = RowView.Height - 1,
                    Y = rowFrameLayout.Height - 1,
                    X = Application.GetRealWidth(58),
                    Width = Application.GetRealWidth(965),
                    Height = 1,
                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
                };
                RowView.AddChidren(line2);
                rowFrameLayout.AddChidren(line2);
                #region 数据处理
                int currentIndex = i;
                if (currentIndex == curLocalDoorLockUserList.Keys.Count - 1)
                {
                    line2.Visible = false;
                }
                switch (curDoorLockUser.UnlockType)
                {
                    case 0:
@@ -790,9 +902,10 @@
                };
                btnDistributeUnlockIcon.MouseUpEventHandler += eHandler;
                btnDistributeUnlockIconFrameLayout.MouseUpEventHandler += eHandler;
                RowView.MouseUpEventHandler += eHandler;
                rowFrameLayout.MouseUpEventHandler += eHandler;
                btnText.MouseUpEventHandler += eHandler;
                #endregion
                i++;
            }
        }
        #region ◆ 接口实现__________________________