WJC
2020-03-17 f6e34a69f1d1e0b0b3a6252fe20acddca7fe56e5
ZigbeeApp/Shared/Phone/UserCenter/DoorLock/UserDoorLockPage.cs
@@ -6,22 +6,45 @@
{
    public class UserDoorLockPage : DoorLockCommonLayout, ZigBee.Common.IStatus
    {
        public UserDoorLockPage(Shared.Common.Room room ,DeviceUI doorLock)
        /// <summary>
        ///  构造函数
        /// </summary>
        /// <param name="room"></param>
        /// <param name="doorLock"></param>
        public UserDoorLockPage(Shared.Common.Room room, CommonDevice doorLock)
        {
            this.doorLock = doorLock.CommonDevice as ZigBee.Device.DoorLock;
            this.doorLock = doorLock as ZigBee.Device.DoorLock;
            currentRoom = room;
            deviceUI = doorLock;
             BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCTopViewBackgroundColor;
            BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCTopViewBackgroundColor;
            ZigBee.Device.ZbGateway.StatusList.Add(this);
        }
        #region ◆ 变量申明__________________________
        #region  变量申明
        /// <summary>
        /// 当前门锁
        /// </summary>
        ZigBee.Device.DoorLock doorLock;
        /// <summary>
        /// 底部布局
        /// </summary>
        FrameLayout bottomFrameLayout;
        /// <summary>
        /// 当前房间
        /// </summary>
        Shared.Common.Room currentRoom;
        DeviceUI deviceUI;
        /// <summary>
        /// 设备UI对象
        /// </summary>
        CommonDevice deviceUI;
        /// <summary>
        /// 设置二次验证Action
        /// </summary>
        Action action;
        /// <summary>
        /// 中部布局中门锁名称显示
        /// </summary>
        Button btnDoorLockTitle;
        #endregion
        /// <summary>
@@ -29,21 +52,20 @@
        /// </summary>
        public void Show()
        {
            this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.DoorLock));
            this.TopFrameLayout(this, "");
            EventHandler<MouseEventArgs> eHandlerBack = (sender, e) =>
            {
                RemoveFromParent();
            };
            this.btnBack.MouseUpEventHandler += eHandlerBack;
            this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack;
            this.MidFrameLayout(this);
            this.MidFrameLayout(this);
            var btnShare = new Button
            {
                X = Application.GetRealWidth(850 - 116),
                Height = Application.GetRealHeight(69),
                Width = Application.GetRealWidth(69),
                Width = Application.GetRealWidth(0),
            };
            this.titleFrameLayout.AddChidren(btnShare);
@@ -63,36 +85,31 @@
                UnSelectedImagePath = "DoorLock/SettingIcon.png",
            };
            btnFuncSetFrameLayout.AddChidren(btnFuncSet);
            btnFuncSet.MouseDownEventHandler += (sender, e) =>
            EventHandler<MouseEventArgs> btnFuncSetHander = (sender, e) =>
            {
                if (UserCenterResourse.UserInfo.AuthorityNo == 1)
                {
                    var userDoorLockPage = new Shared.Phone.UserCenter.DoorLock.FunctionSetting(doorLock);
                    Shared.Phone.UserView.HomePage.Instance.AddChidren(userDoorLockPage);
                    Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                    userDoorLockPage.Show();
                }
                else
                {
                    var userDoorLockPage = new Shared.Phone.UserCenter.DoorLock.FunctionSettingSub(doorLock);
                    Shared.Phone.UserView.HomePage.Instance.AddChidren(userDoorLockPage);
                    Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                    userDoorLockPage.Show();
                }
            };
            btnShare.MouseDownEventHandler += (sender, e) =>
            {
                var doorLock = new ZigBee.Device.DoorLock();
                var memberManagement = new Shared.Phone.UserCenter.DoorLock.MemberManagement(doorLock);
                Shared.Phone.UserView.HomePage.Instance.AddChidren(memberManagement);
                var functionSetting = new Shared.Phone.UserCenter.DoorLock.FunctionSetting(doorLock);
                Shared.Phone.UserView.HomePage.Instance.AddChidren(functionSetting);
                Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                memberManagement.Show();
                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();
        }
        /// <summary>
        /// 中部布局
        /// </summary>
        public void MidFrameLayoutContent()
        {
            #region UI
@@ -103,61 +120,90 @@
                Height = Application.GetRealHeight(1238),
                Width = Application.GetRealWidth(965),
                BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite,
                Radius = 6,
            };
            this.midFrameLayout.AddChidren(midTopFrameLayout);
            var btnDoorLockTitle = new Button()
            btnDoorLockTitle = new Button()
            {
                Width = Application.GetRealWidth(250),
                Height = Application.GetRealHeight(60),
                X = Application.GetRealWidth(372),
                Y = Application.GetRealHeight(46),
                TextColor = Shared.Common.ZigbeeColor.Current.XMGray3,
                Text = Language.StringByID(R.MyInternationalizationString.SmartDoorLock),
                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(752),
                X = Application.GetRealWidth(46),
                Y = Application.GetRealHeight(46),
                UnSelectedImagePath = "DoorLock/RecordIcon.png",
            };
            midTopFrameLayout.AddChidren(btnRecord);
            btnRecord.MouseDownEventHandler += (sender, e) =>
            btnRecordFrameLayout.AddChidren(btnRecord);
            EventHandler<MouseEventArgs> 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(850),
                X = Application.GetRealWidth(15),
                Y = Application.GetRealHeight(46),
                UnSelectedImagePath = "Item/Collection.png",
                SelectedImagePath = "Item/CollectionSelected.png"
            };
            midTopFrameLayout.AddChidren(btnCollect);
            btnCollect.MouseDownEventHandler += (sender, e) =>
            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)
                {
                    Shared.Common.Room.CurrentRoom.GetLoveRoom().DeleteDevice(deviceUI.FileName); //取消收藏
                    HdlRoomLogic.Current.AddLoveDevice(deviceUI);//收藏
                }
                else
                {
                    Shared.Common.Room.CurrentRoom.GetLoveRoom().AddDevice(deviceUI.FileName);//收藏
                {
                    HdlRoomLogic.Current.DeleteLoveDevice(deviceUI);//取消收藏
                }
            };
            btnCollectFrameLayout.MouseDownEventHandler += handerCollect;
            btnCollect.MouseDownEventHandler += handerCollect;
            var btnCurrentText = new Button()
            {
                Width = Application.GetRealWidth(100),
@@ -263,12 +309,22 @@
            };
            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);
@@ -296,33 +352,64 @@
            btnCurrentFrameLayout.AddChidren(btnCurrentRoomName);
            #endregion
            #region 数据处理
            EventHandler<MouseEventArgs> hander1 = async (sender, e) =>
             {
                 if (UserCenterResourse.UserInfo.AuthorityNo != 1)
                 {
                     var result = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockOperateAccess(doorLock, Shared.Common.Config.Instance.Guid);
                     if (result == false)
            {
                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) =>
                     {
                         var result1 = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockUnlockAccess(doorLock, Shared.Common.Config.Instance.Guid);
                         if (result1 == true)
                         if (!string.IsNullOrEmpty(deviceRename))
                         {
                             RemoteUnlockRequest(doorLock, action, progressButton, btnDoorLockPic, btnStatus);
                             btnDoorLockTitle.Text = deviceRename;
                             //改房间
                             HdlRoomLogic.Current.ChangedRoom(deviceUI, currentRoom.Id);
                             deviceUI.ReSave();
                         }
                         else
                         {
                             new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.NoAccess), Direction = AMPopTipDirection.Down, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                         }
                     }
                     else
                     {
                         new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.AccountIsFreezed), Direction = AMPopTipDirection.Down, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                     }
                 }
                 else
                 {
                     RemoteUnlockRequest(doorLock, action, progressButton, btnDoorLockPic, btnStatus);
                 }
             };
                     };
                    openFrameLayout.Enable = true;
                    btnDoorOpenPic.Enable = true;
                }
            };
            openFrameLayout.MouseUpEventHandler += hander1;
            btnDoorOpenPic.MouseUpEventHandler += hander1;
            EventHandler<MouseEventArgs> hander2 = (sender, e) =>
@@ -332,9 +419,10 @@
            };
            closeFrameLayout.MouseUpEventHandler += hander2;
            btnDoorClosePic.MouseUpEventHandler += hander2;
            #endregion
        }
        #region ◆ 接口实现__________________________
        #region  接口实现
        /// <summary>
        /// 处理变化事件 --将弃用 改用DeviceInfoChange()
        /// </summary>