gxc
2020-02-28 66a9965c44ecc32a6696abca876ab9d1cd091584
ZigbeeApp/Shared/Phone/UserCenter/DoorLock/FunctionSetting.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Shared.Common;
using ZigBee.Device;
@@ -19,6 +20,27 @@
        #region ◆ 变量申明__________________________
        ZigBee.Device.DoorLock doorLock;
        /// <summary>
        /// 设备需要保存的设备名字
        /// </summary>
        private Dictionary<int, string> dicDeviceSaveName = new Dictionary<int, string>();
        /// <summary>
        /// 当前选择的设备
        /// </summary>
        private CommonDevice nowSelectDevice = null;
        /// <summary>
        /// 设备备注的控件
        /// </summary>
        private FrameCaptionInputControl btnDeviceName = null;
        /// <summary>
        /// 设备的某一回路
        /// </summary>
        private CommonDevice deviceObj = null;
        Action action;
        Action actionNone;
        string modifyDeviceName = "";
        bool IsModifyName = true;
        public Action<string> devicNameAction;
        #endregion
        /// <summary>
@@ -26,7 +48,7 @@
        /// </summary>
        public void Show()
        {
            this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.FunctionSetting));
            this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.DoorLockFunctionSetting));
            EventHandler<MouseEventArgs> eHandlerBack = (sender, e) =>
            {
@@ -42,7 +64,6 @@
        public void MidFrameLayoutContent()
        {
            var MidTopFrameLayout = new FrameLayout()
            {
                X = Application.GetRealWidth(449),
@@ -52,35 +73,49 @@
                BackgroundImagePath = "DoorLock/DoorlockPicture.png",
            };
            this.midFrameLayout.AddChidren(MidTopFrameLayout);
            var btnDeviceText = new Button()
            {
                Y = Application.GetRealHeight(288),
                Height = Application.GetRealHeight(60),
                Gravity = Gravity.CenterHorizontal,
                TextColor = ZigbeeColor.Current.XMBlack,
                TextSize = 15,
                Text = Common.LocalDevice.Current.GetDeviceMacName(doorLock),
            };
            this.midFrameLayout.AddChidren(btnDeviceText);
            BottomFrameLayout();
        }
        public void BottomFrameLayout()
        {
            #region  UI 
            //var bottomFrameLayout = new FrameLayout()
            //{
            //    Height = Application.GetRealHeight(100),
            //    Y = Application.GetRealHeight(418),
            //    Radius = 17,
            //    BackgroundColor = ZigbeeColor.Current.XMWhite,
            //};
            //this.midFrameLayout.AddChidren(bottomFrameLayout);
            //var bottomFrameLayout1 = new FrameLayout()
            //{
            //    Height = Application.GetRealHeight(1319 - 50),
            //    Y = Application.GetRealHeight(418 + 48),
            //    BackgroundColor = ZigbeeColor.Current.XMWhite,
            //};
            //this.midFrameLayout.AddChidren(bottomFrameLayout1);
            var bottomFrameLayout = new FrameLayout()
            {
                Height = Application.GetRealHeight(100),
                Y = Application.GetRealHeight(418),
                Radius = 17,
                BackgroundColor = ZigbeeColor.Current.XMWhite,
            };
            this.midFrameLayout.AddChidren(bottomFrameLayout);
            var bottomFrameLayout1 = new FrameLayout()
            {
                Height = Application.GetRealHeight(1319 - 50),
                Y = Application.GetRealHeight(418 + 48),
                BackgroundColor = ZigbeeColor.Current.XMWhite,
            };
            this.midFrameLayout.AddChidren(bottomFrameLayout1);
            var bottomFrameLayout2 = new FrameLayout()
            {
                Height = Application.GetRealHeight(1319),
                Y = Application.GetRealHeight(418),
                BackgroundColor = ZigbeeColor.Current.XMWhite,
            };
            this.midFrameLayout.AddChidren(bottomFrameLayout2);
            this.midFrameLayout.AddChidren(bottomFrameLayout);
            bottomFrameLayout.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
            var informationEdit = new Button()
            {
@@ -90,26 +125,26 @@
                Text = Language.StringByID(R.MyInternationalizationString.InformationEdit),
                TextColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 12,
                TextSize = 15,
            };
            bottomFrameLayout2.AddChidren(informationEdit);
            bottomFrameLayout.AddChidren(informationEdit);
            for (int i = 0; i < 7; i++)
            for (int i = 0; i < 6; i++)
            {
                var bottomRowLayout = new FrameLayout()
                {
                    Height = Application.GetRealHeight(58),
                };
                bottomFrameLayout2.AddChidren(bottomRowLayout);
                bottomFrameLayout.AddChidren(bottomRowLayout);
                var btnName = new Button()
                {
                    Width = Application.GetRealWidth(233),
                    Height = Application.GetRealHeight(58),
                    X = Application.GetRealWidth(58),
                    TextColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                    TextColor = Shared.Common.ZigbeeColor.Current.XMTopTitleText,
                    TextAlignment = TextAlignment.CenterLeft,
                    TextSize = 12,
                    TextSize = 14,
                };
                bottomRowLayout.AddChidren(btnName);
@@ -125,64 +160,108 @@
                {
                    Width = Application.GetRealWidth(58),
                    Height = Application.GetRealHeight(58),
                    X = Application.GetRealWidth(46)
                };
                btnNextFrameLayout.AddChidren(btnNext);
                var btnLine = new FrameLayout()
                {
                    Width = Application.GetRealWidth(965),
                    Height = Application.GetRealHeight(5),
                    Height = 1,
                    X = Application.GetRealWidth(58),
                    BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine,
                    Visible = false,
                };
                bottomFrameLayout2.AddChidren(btnLine);
                bottomFrameLayout.AddChidren(btnLine);
                if (i == 0)
                {
                    bottomRowLayout.Y = Application.GetRealHeight(204);
                    bottomRowLayout.Y = Application.GetRealHeight(220);
                    btnName.Text = Language.StringByID(R.MyInternationalizationString.DeviceRemarkXm) + ":";
                    btnNextFrameLayout.Width = btnNext.Width = Application.GetRealWidth(789 - 58);
                    btnNextFrameLayout.X = btnName.Right;
                    btnNext.TextAlignment = TextAlignment.CenterLeft;
                    btnNext.TextColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                    btnNext.Text = doorLock.DeviceName;
                    btnNextFrameLayout.Width = btnNext.Width = Application.GetRealWidth(789 - 58 - 20);
                    btnNextFrameLayout.X = Application.GetRealWidth(233 + 20);
                    var btnDeviceNameEditText = new EditText()
                    {
                        X = Application.GetRealWidth(46),
                        Width = Application.GetRealWidth(731),
                        Height = Application.GetRealHeight(58),
                        TextColor = ZigbeeColor.Current.XMGray3,
                        TextSize = 14,
                        PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor2,
                        TextAlignment = TextAlignment.CenterLeft,
                        Text = string.IsNullOrEmpty(doorLock.DeviceName) ? Language.StringByID(R.MyInternationalizationString.UNKnown) : doorLock.DeviceName,
                    };
                    btnNextFrameLayout.AddChidren(btnDeviceNameEditText);
                    btnDeviceNameEditText.TextChangeEventHandler += (sender, e) =>
                    {
                        modifyDeviceName = btnDeviceNameEditText.Text;
                    };
                    Action<Shared.View> actionEdit = async (obj) =>
                     {
                         try
                         {
                             Application.RunOnMainThread(() => { CommonPage.Loading.Start("Loading..."); });
                             var doorLockDeviceList = new List<CommonDevice> { };
                             doorLockDeviceList.Add(doorLock);
                             var result = await Common.LocalDevice.Current.ReMacName(doorLockDeviceList, btnDeviceNameEditText.Text);
                             if (result)
                             {
                                 IsModifyName = false;
                             }
                             else
                             {
                                 IsModifyName = true;
                             }
                         }
                         catch { }
                         finally
                         {
                             Application.RunOnMainThread(() =>
                             {
                                 CommonPage.Loading.Hide();
                             });
                         }
                     };
                    btnDeviceNameEditText.EditorEnterAction += actionEdit;
                    btnLine.Visible = true;
                    btnLine.Y = Application.GetRealHeight(308);
                    btnLine.Y = Application.GetRealHeight(303);
                }
                else if (i == 1)
                {
                    bottomRowLayout.Y = Application.GetRealHeight(343);
                    btnName.Text = Language.StringByID(R.MyInternationalizationString.BelongZone) + ":";
                    var btnArea = new Button()
                    bottomRowLayout.Y = Application.GetRealHeight(312);
                    bottomRowLayout.Height = Application.GetRealHeight(127);
                    btnName.Width = Application.GetRealWidth(0);
                    btnNextFrameLayout.Width = Application.GetRealWidth(0);
                    //所属区域
                    var rowBeloneArea = new BelongAreaControl(0);
                    bottomRowLayout.AddChidren(rowBeloneArea);
                    rowBeloneArea.InitControl(Language.StringByID(R.MyInternationalizationString.uBelongArea), doorLock);
                    //底线
                    rowBeloneArea.AddBottomLine();
                    rowBeloneArea.SelectRoomEvent += (roomKeys) =>
                    {
                        Width = Application.GetRealWidth(789 - 109 - 58),
                        Height = Application.GetRealHeight(58),
                        X = btnName.Right,
                        Y = btnName.Y,
                        TextColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                        Text = "一楼,客厅",
                        TextAlignment = TextAlignment.CenterLeft,
                        //变更房间
                        Common.Room.CurrentRoom.ChangedRoom(doorLock, roomKeys);
                    };
                    bottomRowLayout.AddChidren(btnArea);
                    btnNext.UnSelectedImagePath = "DoorLock/RightIcon.png";
                    btnLine.Visible = true;
                    btnLine.Y = Application.GetRealHeight(446);
                    btnLine.Visible = false;
                }
                else if (i == 2)
                {
                    bottomRowLayout.Y = Application.GetRealHeight(481);
                    btnName.Text = Language.StringByID(R.MyInternationalizationString.BelongModel) + ":";
                    btnNextFrameLayout.Width = btnNext.Width = Application.GetRealWidth(789 - 58);
                    btnNextFrameLayout.X = btnName.Right;
                    btnNextFrameLayout.Width = btnNext.Width = Application.GetRealWidth(789 - 58 - 20);
                    btnNextFrameLayout.X = Application.GetRealWidth(253);
                    btnNext.TextAlignment = TextAlignment.CenterLeft;
                    btnNext.Height = Application.GetRealHeight(58);
                    btnNext.Text = "HDL-Doorlock";
                    btnNext.TextColor = Shared.Common.ZigbeeColor.Current.XMBlack;
                    btnNext.Text = doorLock.DeviceName;
                    btnNext.TextColor = Shared.Common.ZigbeeColor.Current.XMGray3;
                    btnNext.TextSize = 14;
                    btnLine.Visible = true;
                    btnLine.Y = Application.GetRealHeight(1025 - 449);
                    btnLine.Y = Application.GetRealHeight(575);
                }
                else if (i == 3)
                {
@@ -192,19 +271,20 @@
                    btnNext.UnSelectedImagePath = "DoorLock/RightIcon.png";
                    btnLine.Visible = true;
                    btnLine.Y = Application.GetRealHeight(619 + 58 + 35);
                    btnLine.Y = Application.GetRealHeight(714);
                }
                else if (i == 4)
                {
                    bottomRowLayout.Y = Application.GetRealHeight(723 + 35);
                    btnNext.X = Application.GetRealWidth(0);
                    btnName.Text = Language.StringByID(R.MyInternationalizationString.RemotelyUnlock);
                    btnNext.Width = Application.GetRealWidth(104);
                    btnNext.Height = Application.GetRealHeight(63);
                    btnNext.UnSelectedImagePath = "DoorLock/Switch.png";
                    btnNext.SelectedImagePath = "DoorLock/SwitchOn.png";
                    btnLine.Visible = true;
                    btnLine.Y = Application.GetRealHeight(723 + 127);
                    if (ZigBee.Device.DoorLock.RemoteUnlockPassword == "")
                    btnLine.Y = Application.GetRealHeight(853);
                    if (string.IsNullOrEmpty(doorLock.RemoteUnlockPassword))
                    {
                        btnNext.IsSelected = false;
                    }
@@ -220,61 +300,150 @@
                    btnNextFrameLayout.Y = btnName.Y;
                    btnNext.UnSelectedImagePath = "DoorLock/RightIcon.png";
                    btnLine.Visible = true;
                    btnLine.Y = Application.GetRealHeight(861 + 127);
                }
                else if (i == 6)
                {
                    bottomRowLayout.Y = Application.GetRealHeight(999 + 35);
                    btnName.Text = Language.StringByID(R.MyInternationalizationString.Shared);
                    btnNext.UnSelectedImagePath = "DoorLock/RightIcon.png";
                    btnLine.Visible = true;
                    btnLine.Y = Application.GetRealHeight(999 + 127);
                    btnLine.Y = Application.GetRealHeight(992);
                }
                int currentIndex = i;
                EventHandler<MouseEventArgs> eHandler = (sender, e) =>
                {
                    if (currentIndex == 1)
                    {
                    }
                    else if (currentIndex == 3)
                    {
                        var temporaryPassword = new Shared.Phone.UserCenter.DoorLock.TemporaryPassword(doorLock);
                        Shared.Phone.UserView.HomePage.Instance.AddChidren(temporaryPassword);
                        Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                        temporaryPassword.Show();
                    }
                    else if (currentIndex == 4)
                    {
                        btnNext.IsSelected = !btnNext.IsSelected;
                        if (btnNext.IsSelected)
                        {
                            if (ZigBee.Device.DoorLock.RemoteUnlockPassword == "")
                            {
                                RemotePasswordDialog(doorLock, btnNext);
                            }
                        }
                        else
                        {
                            ZigBee.Device.DoorLock.RemoteUnlockPassword = "";
                        }
                    }
                    else if (currentIndex == 5)
                    {
                        var tempPage = new Shared.Phone.UserCenter.DoorLock.TimeSettignPage(doorLock, "DoorLockTime");
                        Shared.Phone.UserView.HomePage.Instance.AddChidren(tempPage);
                        Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                        tempPage.Show();
                    }
                    else if (currentIndex == 6)
                    {
                    }
                };
                bottomRowLayout.MouseDownEventHandler += eHandler;
                EventHandler<MouseEventArgs> eHandler = async (sender, e) =>
                 {
                     if (currentIndex == 3)
                     {
                         action = async () =>
                         {
                             var temporaryPassword = new Shared.Phone.UserCenter.DoorLock.TemporaryPassword(doorLock);
                             Shared.Phone.UserView.HomePage.Instance.AddChidren(temporaryPassword);
                             Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                             temporaryPassword.Show();
                         };
                         actionNone = async () =>
                         {
                             Shared.Phone.UserCenter.DoorLock.DoorLockCommonLayout.SecurityRequest(doorLock, action);
                         };
                         HdlCheckLogic.Current.CheckSecondarySecurity(action, actionNone);
                     }
                     else if (currentIndex == 4)
                     {
                         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)
                                 {
                                     btnNext.IsSelected = !btnNext.IsSelected;
                                     if (btnNext.IsSelected)
                                     {
                                         if (string.IsNullOrEmpty(doorLock.RemoteUnlockPassword))
                                         {
                                             RemotePasswordDialog(doorLock, btnNext);
                                         }
                                     }
                                     else
                                     {
                                         doorLock.RemoteUnlockPassword = "";
                                     }
                                 }
                                 else
                                 {
                                     new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.NoAccess), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                                 }
                             }
                             else
                             {
                                 new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.AccountIsFreezed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                             }
                         }
                         else
                         {
                             btnNext.IsSelected = !btnNext.IsSelected;
                             if (btnNext.IsSelected)
                             {
                                 if (string.IsNullOrEmpty(doorLock.RemoteUnlockPassword))
                                 {
                                     RemotePasswordDialog(doorLock, btnNext);
                                 }
                             }
                             else
                             {
                                 doorLock.RemoteUnlockPassword = "";
                             }
                         }
                     }
                     else if (currentIndex == 5)
                     {
                         var result = await Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetDoorLockOperateAccess(doorLock, Shared.Common.Config.Instance.Guid);
                         if (result == false)
                         {
                             var tempPage = new Shared.Phone.UserCenter.DoorLock.TimeSettignPage(doorLock, "DoorLockTime");
                             Shared.Phone.UserView.HomePage.Instance.AddChidren(tempPage);
                             Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                             tempPage.Show();
                         }
                         else
                         {
                             new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.AccountIsFreezed), Direction = AMPopTipDirection.None, CloseTime = 1 }.Show(Common.CommonPage.Instance);
                         }
                     }
                 };
                btnNext.MouseDownEventHandler += eHandler;
                btnName.MouseDownEventHandler += eHandler;
                btnNextFrameLayout.MouseDownEventHandler += eHandler;
                if (i != 4)
                {
                    bottomRowLayout.MouseDownEventHandler += eHandler;
                    btnName.MouseDownEventHandler += eHandler;
                    btnNextFrameLayout.MouseDownEventHandler += eHandler;
                }
                #endregion
            }
            //保存
            var btnFinifh = new Button()
            {
                Width = Application.GetRealWidth(907),
                Height = Application.GetRealHeight(127),
                Y = Application.GetRealHeight(1472),
                Gravity = Gravity.CenterHorizontal,
                Radius = (uint)Application.GetRealHeight(127) / 2,
                TextID = R.MyInternationalizationString.Save,
                BackgroundColor = Shared.Common.ZigbeeColor.Current.XMBlack,
                TextColor = Shared.Common.ZigbeeColor.Current.XMWhite,
                TextSize = 16,
                IsBold = true,
            };
            this.midFrameLayout.AddChidren(btnFinifh);
            btnFinifh.MouseUpEventHandler += (sender, e) =>
            {
                System.Threading.Tasks.Task.Run(async () =>
                {
                    Application.RunOnMainThread(() => { CommonPage.Loading.Start("Loading..."); });
                    try
                    {
                        if (IsModifyName)
                        {
                            var doorLockDeviceList = new List<CommonDevice> { };
                            doorLockDeviceList.Add(doorLock);
                            var result = await Common.LocalDevice.Current.ReMacName(doorLockDeviceList, modifyDeviceName);
                            if (result)
                            {
                                if (devicNameAction != null)
                                {
                                    devicNameAction(modifyDeviceName);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        var mess = ex.Message;
                    }
                    finally
                    {
                        Application.RunOnMainThread(() =>
                        {
                            CommonPage.Loading.Hide();
                        });
                    }
                });
            };
        }
        #region ◆ 接口实现__________________________