using System; using System.Collections.Generic; using Shared.Common; using Shared.Phone.UserCenter.Device; using ZigBee.Device; namespace Shared.Phone.UserCenter.DoorLock { /// /// 门锁管理 /// public class UserManagement : DoorLockCommonLayout, ZigBee.Common.IStatus { /// /// 按键模式接收 /// /// Common. 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(); }); } }); } /// 构造函数 /// /// public UserManagement(ZigBee.Device.DoorLock doorLock) { this.doorLock = doorLock; } #region ◆ 变量申明__________________________ ZigBee.Device.DoorLock doorLock; List localAccountList = new List { }; #endregion public void Show() { this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.UserManagement)); EventHandler 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 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 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) { } } }