using System; using Shared.Common; using ZigBee.Device; namespace Shared.Phone.UserCenter.DoorLock { public class UserDoorLockPage : DoorLockCommonLayout, ZigBee.Common.IStatus { /// /// 构造函数 /// /// /// public UserDoorLockPage(Shared.Common.Room room, CommonDevice doorLock) { this.doorLock = doorLock as ZigBee.Device.DoorLock; currentRoom = room; deviceUI = doorLock; BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCTopViewBackgroundColor; ZigBee.Device.ZbGateway.StatusList.Add(this); } #region 变量申明 /// /// 当前门锁 /// ZigBee.Device.DoorLock doorLock; /// /// 底部布局 /// FrameLayout bottomFrameLayout; /// /// 当前房间 /// Shared.Common.Room currentRoom; /// /// 设备UI对象 /// CommonDevice deviceUI; /// /// 设置二次验证Action /// Action action; /// /// 中部布局中门锁名称显示 /// Button btnDoorLockTitle; #endregion /// /// UI显示 /// public void Show() { this.TopFrameLayout(this, ""); EventHandler eHandlerBack = (sender, e) => { RemoveFromParent(); }; this.btnBack.MouseUpEventHandler += eHandlerBack; this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack; this.MidFrameLayout(this); var btnShare = new Button { X = Application.GetRealWidth(850 - 116), Height = Application.GetRealHeight(69), Width = Application.GetRealWidth(0), }; this.titleFrameLayout.AddChidren(btnShare); var btnFuncSetFrameLayout = new FrameLayout { X = Application.GetRealWidth(850 - 116), Height = Application.GetRealHeight(69), Width = Application.GetRealWidth(69 * 2 + 58), }; this.titleFrameLayout.AddChidren(btnFuncSetFrameLayout); var btnFuncSet = new Button { X = Application.GetRealWidth(103), Height = Application.GetRealHeight(69), Width = Application.GetRealWidth(69), UnSelectedImagePath = "DoorLock/SettingIcon.png", }; btnFuncSetFrameLayout.AddChidren(btnFuncSet); EventHandler btnFuncSetHander = (sender, e) => { var functionSetting = new Shared.Phone.UserCenter.DoorLock.FunctionSetting(doorLock); Shared.Phone.UserView.HomePage.Instance.AddChidren(functionSetting); Shared.Phone.UserView.HomePage.Instance.PageIndex += 1; functionSetting.Show(); functionSetting.devicNameAction += (deviceRename) => { if (!string.IsNullOrEmpty(deviceRename)) { btnDoorLockTitle.Text = deviceRename; //改房间 HdlRoomLogic.Current.ChangedRoom(deviceUI, currentRoom.Id); deviceUI.ReSave(); } }; }; btnFuncSetFrameLayout.MouseDownEventHandler += btnFuncSetHander; btnFuncSet.MouseDownEventHandler += btnFuncSetHander; MidFrameLayoutContent(); } /// /// 中部布局 /// public void MidFrameLayoutContent() { #region UI var midTopFrameLayout = new FrameLayout() { X = Application.GetRealWidth(58), Y = Application.GetRealHeight(115), Height = Application.GetRealHeight(1238), Width = Application.GetRealWidth(965), BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite, Radius = 6, }; this.midFrameLayout.AddChidren(midTopFrameLayout); btnDoorLockTitle = new Button() { Width = Application.GetRealWidth(250), Height = Application.GetRealHeight(60), X = Application.GetRealWidth(372), Y = Application.GetRealHeight(46), TextColor = Shared.Common.ZigbeeColor.Current.XMBlack, TextSize = 15, TextAlignment = TextAlignment.Center, IsBold = true, }; midTopFrameLayout.AddChidren(btnDoorLockTitle); //获取Mac名字 btnDoorLockTitle.Text = Common.LocalDevice.Current.GetDeviceMacName(doorLock); var btnRecordFrameLayout = new FrameLayout() { Width = Application.GetRealWidth(69+15+46), Height = Application.GetRealHeight(69+46 * 2), X = Application.GetRealWidth(752-46), }; midTopFrameLayout.AddChidren(btnRecordFrameLayout); var btnRecord = new Button() { Width = Application.GetRealWidth(69), Height = Application.GetRealHeight(69), X = Application.GetRealWidth(46), Y = Application.GetRealHeight(46), UnSelectedImagePath = "DoorLock/RecordIcon.png", }; btnRecordFrameLayout.AddChidren(btnRecord); EventHandler handerRecord = (sender, e) => { //历史记录 ---- stan var form = new DeviceDoorLock.DoorLockHistoryLogForm(); form.AddForm(this.doorLock.DeviceAddr); }; btnRecordFrameLayout.MouseDownEventHandler += handerRecord; btnRecord.MouseDownEventHandler += handerRecord; var btnCollectFrameLayout = new FrameLayout() { Width = Application.GetRealWidth(69+15+46), Height = Application.GetRealHeight(69+46*2), X = Application.GetRealWidth(850-15), }; midTopFrameLayout.AddChidren(btnCollectFrameLayout); var btnCollect = new Button() { Width = Application.GetRealWidth(69), Height = Application.GetRealHeight(69), X = Application.GetRealWidth(15), Y = Application.GetRealHeight(46), UnSelectedImagePath = "Item/Collection.png", SelectedImagePath = "Item/CollectionSelected.png" }; btnCollectFrameLayout.AddChidren(btnCollect); if (HdlRoomLogic.Current.IsCollectInRoom(deviceUI) == false) { btnCollect.IsSelected = false; } else { btnCollect.IsSelected = true; } EventHandler < MouseEventArgs > handerCollect = (sender, e) => { btnCollect.IsSelected = !btnCollect.IsSelected; if (btnCollect.IsSelected) { HdlRoomLogic.Current.AddLoveDevice(deviceUI);//收藏 } else { HdlRoomLogic.Current.DeleteLoveDevice(deviceUI);//取消收藏 } }; btnCollectFrameLayout.MouseDownEventHandler += handerCollect; btnCollect.MouseDownEventHandler += handerCollect; var btnCurrentText = new Button() { Width = Application.GetRealWidth(100), Height = Application.GetRealHeight(40), X = Application.GetRealWidth(415), Y = Application.GetRealHeight(118), Text = Language.StringByID(R.MyInternationalizationString.Current), TextColor = Shared.Common.ZigbeeColor.Current.XMGray3, TextSize = 10, TextAlignment = TextAlignment.CenterLeft, }; midTopFrameLayout.AddChidren(btnCurrentText); var btnStatus = new Button() { Width = Application.GetRealWidth(200), Height = Application.GetRealHeight(40), X = btnCurrentText.Right, Y = Application.GetRealHeight(118), TextColor = Shared.Common.ZigbeeColor.Current.XMGray3, Text = Language.StringByID(R.MyInternationalizationString.CLose), TextSize = 10, TextAlignment = TextAlignment.CenterLeft, }; midTopFrameLayout.AddChidren(btnStatus); var btnDoorLockPic = new Button() { Width = Application.GetRealWidth(383), Height = Application.GetRealHeight(343), X = Application.GetRealWidth(161), Y = Application.GetRealHeight(415), UnSelectedImagePath = "DoorLock/DoorLockPicClose.png", SelectedImagePath = "DoorLock/DooorLockPicOpen.png", }; midTopFrameLayout.AddChidren(btnDoorLockPic); var btnFrameLayout = new FrameLayout() { Width = Application.GetRealWidth(420 - 46), Height = Application.GetRealHeight(446), X = btnDoorLockPic.Right, Y = Application.GetRealHeight(354), BackgroundColor = ZigbeeColor.Current.XMWhite, }; midTopFrameLayout.AddChidren(btnFrameLayout); var openFrameLayout = new FrameLayout() { Width = Application.GetRealWidth(420),//639-35 Height = Application.GetRealHeight(446 / 2), BackgroundColor = ZigbeeColor.Current.XMWhite, }; btnFrameLayout.AddChidren(openFrameLayout); var closeFrameLayout = new FrameLayout() { Width = Application.GetRealWidth(420),//639-35 Height = Application.GetRealHeight(446 / 2), Y = Application.GetRealHeight(446 / 2), BackgroundColor = ZigbeeColor.Current.XMWhite, }; btnFrameLayout.AddChidren(closeFrameLayout); var progressFrameLayout = new FrameLayout() { Width = Application.GetRealWidth(9),//639-35 Height = Application.GetRealHeight(446), X = Application.GetRealWidth(95), Y = Application.GetRealHeight(0), BackgroundColor = ZigbeeColor.Current.XMVerticalSeekBar, }; btnFrameLayout.AddChidren(progressFrameLayout); var progressButton = new Button() { Width = Application.GetRealWidth(81),//639-35 Height = Application.GetRealHeight(89), X = Application.GetRealWidth(58), Y = Application.GetRealHeight(347), UnSelectedImagePath = "DoorLock/UnLockButton.png", SelectedImagePath = "DoorLock/UnLockButton.png", }; btnFrameLayout.AddChidren(progressButton); var btnDoorOpenPic = new Button() { Width = Application.GetRealWidth(81), Height = Application.GetRealHeight(81), X = Application.GetRealWidth(164), Y = Application.GetRealHeight(6), UnSelectedImagePath = "DoorLock/DoorLockOpen.png", }; openFrameLayout.AddChidren(btnDoorOpenPic); var btnDoorClosePic = new Button() { Width = Application.GetRealWidth(81), Height = Application.GetRealHeight(81), X = Application.GetRealWidth(164), Y = Application.GetRealHeight(117), UnSelectedImagePath = "DoorLock/DoorLockClose.png", }; closeFrameLayout.AddChidren(btnDoorClosePic); var btnCurrentTopFrameLayout = new FrameLayout() { Height = Application.GetRealHeight(50), Width = Application.GetRealWidth(965), BackgroundColor = ZigbeeColor.Current.XMBlack, Y = Application.GetRealHeight(1100), }; midTopFrameLayout.AddChidren(btnCurrentTopFrameLayout); var btnCurrentFrameLayout = new FrameLayout() { Width = Application.GetRealWidth(965), Height = Application.GetRealHeight(138), Y = Application.GetRealHeight(1100), BackgroundColor = ZigbeeColor.Current.XMBlack, Radius = 6, }; midTopFrameLayout.AddChidren(btnCurrentFrameLayout); var btnCurrentRoomPic = new Button() { Width = Application.GetRealWidth(81), Height = Application.GetRealHeight(81), X = Application.GetRealWidth(58), Y = Application.GetRealHeight(29), UnSelectedImagePath = "DoorLock/RoomPic.png", }; btnCurrentFrameLayout.AddChidren(btnCurrentRoomPic); var btnCurrentRoomName = new Button() { Width = Application.GetRealWidth(172), Height = Application.GetRealHeight(49), X = Application.GetRealWidth(150), Y = Application.GetRealHeight(46), Text = currentRoom.Name, TextColor = Shared.Common.ZigbeeColor.Current.XMWhite, TextSize = 12, TextAlignment = TextAlignment.CenterLeft, }; btnCurrentFrameLayout.AddChidren(btnCurrentRoomName); #endregion #region 数据处理 EventHandler hander1 = async (sender, e) => { openFrameLayout.Enable = false; btnDoorOpenPic.Enable = false; if (UserCenterResourse.UserInfo.AuthorityNo != 1) { var result = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockOperateAccess(doorLock, Shared.Common.Config.Instance.Guid); if (result == false) { var result1 = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockUnlockAccess(doorLock, Shared.Common.Config.Instance.Guid); if (result1 == true) { RemoteUnlockRequest(doorLock, action, progressButton, btnDoorLockPic, btnStatus, btnDoorLockTitle); devicNameSecAction += (deviceRename) => { if (!string.IsNullOrEmpty(deviceRename)) { btnDoorLockTitle.Text = deviceRename; //改房间 HdlRoomLogic.Current.ChangedRoom(deviceUI, currentRoom.Id); deviceUI.ReSave(); } }; openFrameLayout.Enable = true; btnDoorOpenPic.Enable = true; } else { this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.NoAccess)); openFrameLayout.Enable = true; btnDoorOpenPic.Enable = true; } } else { this.ShowMassage(ShowMsgType.Tip, Language.StringByID(R.MyInternationalizationString.AccountIsFreezed)); openFrameLayout.Enable = true; btnDoorOpenPic.Enable = true; } } else { RemoteUnlockRequest(doorLock, action, progressButton, btnDoorLockPic, btnStatus, btnDoorLockTitle); devicNameSecAction += (deviceRename) => { if (!string.IsNullOrEmpty(deviceRename)) { btnDoorLockTitle.Text = deviceRename; //改房间 HdlRoomLogic.Current.ChangedRoom(deviceUI, currentRoom.Id); deviceUI.ReSave(); } }; openFrameLayout.Enable = true; btnDoorOpenPic.Enable = true; } }; openFrameLayout.MouseUpEventHandler += hander1; btnDoorOpenPic.MouseUpEventHandler += hander1; EventHandler hander2 = (sender, e) => { btnDoorLockPic.IsSelected = false; progressButton.Y = Application.GetRealHeight(347); }; closeFrameLayout.MouseUpEventHandler += hander2; btnDoorClosePic.MouseUpEventHandler += hander2; #endregion } #region 接口实现 /// /// 处理变化事件 --将弃用 改用DeviceInfoChange() /// /// The changed. /// Common. public void Changed(CommonDevice common) { } /// /// 处理变化事件 /// /// /// public void DeviceInfoChange(CommonDevice common, string typeTag) { } /// /// Changeds the IL ogic status. /// /// Logic. public void ChangedILogicStatus(ZigBee.Device.Logic logic) { } /// /// Changeds the IS cene status. /// /// Scene. public void ChangedISceneStatus(Scene scene) { } #endregion } }