wxr
2023-06-05 a2572dfd5f01df2f8c6980e53ff01d1100fbb5c8
HDL_ON/UI/UI2/FuntionControlView/DoorLock/DoorLockPage.cs
@@ -6,6 +6,7 @@
using HDL_ON.UI.CSS;
using HDL_ON.Entity;
using HDL_ON.DriverLayer;
using HDL_ON.DAL.Server;
namespace HDL_ON.UI
{
@@ -73,6 +74,8 @@
        /// </summary>
        private Dictionary<string, string> dicText = new Dictionary<string, string>();
        #endregion
        #region ■ 初始化_____________________________
@@ -117,6 +120,47 @@
            this.RefreshFormStatu();
            //读取设备状态
            Control.Ins.SendReadCommand(device);
            // 获取临时密码
            GetTempPwd();
        }
        /// <summary>
        /// 获取临时密码
        /// </summary>
        private void GetTempPwd()
        {
            new System.Threading.Thread(() =>
            {
                try
                {
                    var pack = Common.ApiUtlis.Ins.HttpRequest.GetDoorTempPassword(device.deviceId);
                    if (pack != null)
                    {
                        Application.RunOnMainThread(() =>
                        {
                            if (pack.Code == StateCode.SUCCESS)
                            {
                                var tempPasswrodObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DoorTempPassword>>(pack.Data.ToString());
                                if (tempPasswrodObj.Count > 0)
                                {
                                    doorLockData.TempPassword = tempPasswrodObj[0].pwd;
                                    doorLockData.StartTimeTick = tempPasswrodObj[0].beginTime;
                                    doorLockData.EndTimeTick = tempPasswrodObj[0].endTime;
                                    doorLockData.PwdId = tempPasswrodObj[0].pwdId;
                                    this.InitTempPasswordControl();
                                }
                            }
                        });
                    }
                }
                catch (Exception ex)
                {
                    MainPage.Log($"获取临时密码异常:{ex.Message}");
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
@@ -170,7 +214,7 @@
            this.picLockControl = new PicViewControl(256, 260);
            picLockControl.Y = Application.GetRealHeight(129);
            picLockControl.Gravity = Gravity.CenterHorizontal;
            picLockControl.UnSelectedImagePath = "FunctionIcon/DoorLock/LockPictrue1.png";
            picLockControl.UnSelectedImagePath = "FunctionIcon/DoorLock/LockPictrue1.png";
            FrameWhiteCentet1.AddChidren(picLockControl);
            picLockControl.ButtonClickEvent += (sender, e) =>
            {
@@ -185,37 +229,43 @@
            frameTempPsw.Visible = false;
            FrameWhiteCentet1.AddChidren(frameTempPsw);
            ////声音
            //this.btnVoice = new IconViewControl(24);
            //btnVoice.UnSelectedImagePath = "FunctionIcon/DoorLock/Voice.png";
            //btnVoice.X = Application.GetRealWidth(23);
            //btnVoice.Y = Application.GetRealHeight(410);
            //FrameWhiteCentet1.AddChidren(btnVoice);
            //声音
            this.btnVoice = new IconViewControl(24);
            btnVoice.UnSelectedImagePath = "FunctionIcon/DoorLock/Voice.png";
            btnVoice.X = Application.GetRealWidth(23);
            btnVoice.Y = Application.GetRealHeight(410);
            FrameWhiteCentet1.AddChidren(btnVoice);
            ////声音的滑动条
            //this.seekBarVoiceControl = new SeekBarImageControl(215);
            //seekBarVoiceControl.Gravity = Gravity.CenterHorizontal;
            //FrameWhiteCentet1.AddChidren(seekBarVoiceControl);
            //seekBarVoiceControl.Y = btnVoice.Y - (seekBarVoiceControl.Height - btnVoice.Height) / 2;
            ////绑定PageLayout控件
            //seekBarVoiceControl.BindPageLayout();
            //声音的滑动条
            this.seekBarVoiceControl = new SeekBarImageControl(215);
            seekBarVoiceControl.Gravity = Gravity.CenterHorizontal;
            FrameWhiteCentet1.AddChidren(seekBarVoiceControl);
            seekBarVoiceControl.Y = btnVoice.Y - (seekBarVoiceControl.Height - btnVoice.Height) / 2;
            //绑定PageLayout控件
            seekBarVoiceControl.BindPageLayout();
            ////声音百分比
            //this.btnVoicePersent = new NormalViewControl(Application.GetRealWidth(50), btnVoice.Height, false);
            //btnVoicePersent.X = seekBarVoiceControl.Right + Application.GetRealWidth(8) - seekBarVoiceControl.SeekBarPadding;
            //btnVoicePersent.Y = btnVoice.Y;
            //btnVoicePersent.TextColor = CSS_Color.PromptingColor1;
            //btnVoicePersent.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            //btnVoicePersent.Text = "100%";
            //FrameWhiteCentet1.AddChidren(btnVoicePersent);
            //声音百分比
            this.btnVoicePersent = new NormalViewControl(Application.GetRealWidth(50), btnVoice.Height, false);
            btnVoicePersent.X = seekBarVoiceControl.Right + Application.GetRealWidth(8) - seekBarVoiceControl.SeekBarPadding;
            btnVoicePersent.Y = btnVoice.Y;
            btnVoicePersent.TextColor = CSS_Color.PromptingColor1;
            btnVoicePersent.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnVoicePersent.Text = "100%";
            FrameWhiteCentet1.AddChidren(btnVoicePersent);
            //seekBarVoiceControl.ProgressChangedEvent += (div, value) =>
            //{
            //    btnVoicePersent.Text = value + "%";
            //    if (div == 1)
            //    {
            //    }
            //};
            seekBarVoiceControl.ProgressChangedEvent += (div, value) =>
            {
                btnVoicePersent.Text = value + "%";
                //if (div == 1)
                //{
                //}
            };
            seekBarVoiceControl.OnStopTrackingTouchEvent = (sender, e) => {
                var dic = new Dictionary<string, string>();
                dic.Add("door_volume", e.ToString());
                Control.Ins.SendWriteCommand(this.device, dic);
            };
            //初始化开锁菜单(一键开锁,临时密码开锁)
            this.InitUnLockMenuControl();
@@ -229,7 +279,7 @@
        private void InitUnLockMenuControl()
        {
            //如果是成员,则只有一键开锁
            if (true)// DB_ResidenceData.Instance.CurrentRegion.isOtherShare == true)
            if ( DB_ResidenceData.Instance.CurrentRegion.isOtherShare == true)
            {
                //一键开锁
                var btnOneKey = new NormalViewControl(100, 25, true);
@@ -556,32 +606,34 @@
                this.frameTempPsw.AddChidren(btnDelete);
                btnDelete.ButtonClickEvent += (sender, e) =>
                {
                    //清除当前临时密码?
                    HdlMessageLogic.Current.ShowMassage(ShowMsgType.Confirm, Language.StringByID(StringId.ClearTempPsswordMsg), () =>
                    if (Convert.ToInt64(this.doorLockData.EndTimeTick) < DateTime.Now.Ticks)
                    {
                        //清空临时密码
                        this.doorLockData.TempPassword = string.Empty;
                        this.doorLockData.StatrtTime = string.Empty;
                        this.doorLockData.EndTime = string.Empty;
                        //重新初始化临时密码控件
                        this.InitTempPasswordControl();
                    });
                        DelTempPwd();
                    }
                    else
                    {
                        //清除当前临时密码?
                        HdlMessageLogic.Current.ShowMassage(ShowMsgType.Confirm, Language.StringByID(StringId.ClearTempPsswordMsg), () =>
                        {
                            DelTempPwd();
                        });
                    }
                };
                //复制临时密码图标
                var btnCopy = new IconViewControl(28);
                btnCopy.UnSelectedImagePath = "FunctionIcon/DoorLock/Shard.png";
                btnCopy.X = this.frameTempPsw.Width - btnCopy.IconSize - btnDelete.X;
                btnCopy.Y = btnDelete.Y;
                this.frameTempPsw.AddChidren(btnCopy);
                btnCopy.ButtonClickEvent += (sender, e) =>
                {
                    //临时密码已经复制
                    HdlCommonLogic.Current.SetTextToShearPlate(this.doorLockData.TempPassword, Language.StringByID(StringId.TempPsswordHasBeenCopy));
                };
                ////复制临时密码图标
                //var btnCopy = new IconViewControl(28);
                //btnCopy.UnSelectedImagePath = "FunctionIcon/DoorLock/Shard.png";
                //btnCopy.X = this.frameTempPsw.Width - btnCopy.IconSize - btnDelete.X;
                //btnCopy.Y = btnDelete.Y;
                //this.frameTempPsw.AddChidren(btnCopy);
                //btnCopy.ButtonClickEvent += (sender, e) =>
                //{
                //    //临时密码已经复制
                //    HdlCommonLogic.Current.SetTextToShearPlate(this.doorLockData.TempPassword, Language.StringByID(StringId.TempPsswordHasBeenCopy));
                //};
                //生效时间
                var frameEffective = this.CreatEffectiveTimeControl(this.frameTempPsw, Language.StringByID(StringId.EffectiveTime), this.doorLockData.StatrtTime);
                var frameEffective = this.CreatEffectiveTimeControl(this.frameTempPsw, Language.StringByID(StringId.EffectiveTime), this.doorLockData.StartTime);
                frameEffective.X = Application.GetRealWidth(24);
                frameEffective.Y = Application.GetRealHeight(180);
@@ -600,6 +652,61 @@
                btnLine.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
                this.frameTempPsw.AddChidren(btnLine);
            }
        }
        /// <summary>
        /// 删除临时密码
        /// </summary>
        private void DelTempPwd()
        {
            var waitPage = new Loading();
            this.AddChidren(waitPage);
            waitPage.Start("");
            new System.Threading.Thread(() =>
            {
                try
                {
                    var pack = Common.ApiUtlis.Ins.HttpRequest.DelDoorTempPassword(device.deviceId, doorLockData.PwdId);
                    if (pack != null)
                    {
                        Application.RunOnMainThread(() =>
                        {
                            if (pack.Code == StateCode.SUCCESS)
                            {
                                //清空临时密码
                                this.doorLockData.TempPassword = string.Empty;
                                this.doorLockData.StartTimeTick = string.Empty;
                                this.doorLockData.EndTimeTick = string.Empty;
                                this.doorLockData.PwdId = string.Empty;
                                //重新初始化临时密码控件
                                this.InitTempPasswordControl();
                            }
                            else
                            {
                                IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
                            }
                        });
                    }
                }
                catch (Exception ex)
                {
                    MainPage.Log($"删除门锁临时密码异常: {ex.Message}");
                }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        try
                        {
                            waitPage.Hide();
                            waitPage.RemoveFromParent();
                            waitPage = null;
                        }
                        catch { }
                    });
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
@@ -657,12 +764,13 @@
            //生效时间
            var effectiveTime = Language.StringByID(StringId.EffectiveTime);
            contr.AddRowMenu(effectiveTime, startTime.ToString("yyyy.MM.dd HH:mm"), (btnView, btnValue) =>
            contr.AddRowMenu(effectiveTime + ": " + startTime.ToString("yyyy.MM.dd HH:mm"),"", (btnView, btnValue) =>
            {
                //关掉界面,然后重新调起来
                contr.Close();
                var form = new DoorLockSelectTimePage();
                form.TimeCheck = true;
                form.AddForm(startTime);
                form.SelectFinshEvent += (selectTime) =>
                {
@@ -673,12 +781,13 @@
            //失效时间
            var failTime = Language.StringByID(StringId.FailureTime);
            contr.AddRowMenu(failTime, endTime.ToString("yyyy.MM.dd HH:mm"), (btnView, btnValue) =>
            contr.AddRowMenu(failTime+": "+ endTime.ToString("yyyy.MM.dd HH:mm"),"", (btnView, btnValue) =>
            {
                //关掉界面,然后重新调起来
                contr.Close();
                var form = new DoorLockSelectTimePage();
                form.TimeCheck = true;
                form.AddForm(endTime);
                form.SelectFinshEvent += (selectTime) =>
                {
@@ -698,12 +807,32 @@
                    //关掉界面
                    contr.Close();
                    //生成临时密码
                    this.doorLockData.TempPassword = "987654";
                    this.doorLockData.StatrtTime = startTime.ToString("yyyy.MM.dd HH:mm");
                    this.doorLockData.EndTime = endTime.ToString("yyyy.MM.dd HH:mm");
                    //重新初始化临时密码控件
                    this.InitTempPasswordControl();
                    new System.Threading.Thread(() =>
                    {
                        var pack = Common.ApiUtlis.Ins.HttpRequest.CreateDoorTempPassword(device.deviceId,
                            Utlis.DateTimeToUnix(startTime).ToString(), Utlis.DateTimeToUnix(endTime).ToString());
                        if (pack != null)
                        {
                            if (pack.Code == StateCode.SUCCESS)
                            {
                                // 获取临时密码
                                GetTempPwd();
                            }
                            else
                            {
                                Application.RunOnMainThread(() => {
                                    IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
                                });
                            }
                        }
                    })
                    { IsBackground = true }.Start();
                    ////生成临时密码
                    //this.doorLockData.TempPassword = "987654";
                    //this.doorLockData.StatrtTime = startTime.ToString("yyyy.MM.dd HH:mm");
                    //this.doorLockData.EndTime = endTime.ToString("yyyy.MM.dd HH:mm");
                    ////重新初始化临时密码控件
                    //this.InitTempPasswordControl();
                }
            };
@@ -725,6 +854,12 @@
            {
                //生效时间必须大于失效时间
                HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, Language.StringByID(StringId.EffectiveTimeMustBeOverFailureTime));
                return false;
            }
            if ((endTime - startTime).TotalHours>=24)
            {
                //临时密码有效期不能大于24小时
                HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, Language.StringByID(StringId.TempPwdValidityTip));
                return false;
            }
            return true;
@@ -758,34 +893,43 @@
        /// </summary>
        private void RefreshFormStatu()
        {
            //如果不在线
            if (this.doorLockData.IsOnline == false)
            try
            {
                //开锁图片
                this.picLockControl.UnSelectedImagePath = "FunctionIcon/DoorLock/LockPictrue2.png";
                //连接状态
                this.btnOnlineIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/UnConnect.png";
                this.btnOnlineView.Text = this.dicText["未连接"];
                this.btnOnlineView.TextColor = CSS_Color.AuxiliaryColor2;
                //常开模式图标
                if (this.btnNormallyOpenIcon != null)
                //如果不在线
                if (this.doorLockData.IsOnline == false)
                {
                    this.btnNormallyOpenIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/NormallyOpenIcon2.png";
                    //开锁图片
                    this.picLockControl.UnSelectedImagePath = "FunctionIcon/DoorLock/LockPictrue2.png";
                    //连接状态
                    this.btnOnlineIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/UnConnect.png";
                    this.btnOnlineView.Text = this.dicText["未连接"];
                    this.btnOnlineView.TextColor = CSS_Color.AuxiliaryColor2;
                    //常开模式图标
                    if (this.btnNormallyOpenIcon != null)
                    {
                        this.btnNormallyOpenIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/NormallyOpenIcon2.png";
                    }
                }
                else
                {
                    //开锁图片
                    this.picLockControl.UnSelectedImagePath = this.doorLockData.Open == true ? "FunctionIcon/DoorLock/UnLockPictrue3.png" : "FunctionIcon/DoorLock/LockPictrue1.png";
                    //连接状态
                    this.btnOnlineIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/Connect.png";
                    this.btnOnlineView.Text = this.dicText["已连接"];
                    this.btnOnlineView.TextColor = CSS_Color.PromptingColor1;
                    //常开模式图标
                    if (this.btnNormallyOpenIcon != null)
                    {
                        this.btnNormallyOpenIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/NormallyOpenIcon1.png";
                    }
                }
                this.seekBarVoiceControl.Progress = this.doorLockData.Voice;
                this.btnVoicePersent.Text = this.doorLockData.Voice.ToString();
            }
            else
            catch (Exception ex)
            {
                //开锁图片
                this.picLockControl.UnSelectedImagePath = this.doorLockData.Open == true ? "FunctionIcon/DoorLock/UnLockPictrue3.png" : "FunctionIcon/DoorLock/LockPictrue1.png";
                //连接状态
                this.btnOnlineIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/Connect.png";
                this.btnOnlineView.Text = this.dicText["已连接"];
                this.btnOnlineView.TextColor = CSS_Color.PromptingColor1;
                //常开模式图标
                if (this.btnNormallyOpenIcon != null)
                {
                    this.btnNormallyOpenIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/NormallyOpenIcon1.png";
                }
                MainPage.Log($"界面更新异常,门锁:{ex.Message}");
            }
        }
@@ -1001,7 +1145,7 @@
                    }
                }
                //音量
                else if (data.key == "volume")
                else if (data.key == "door_volume")
                {
                    var value = data.state;
                    if (value != string.Empty)
@@ -1065,13 +1209,62 @@
            /// <summary>
            /// 临时密码生效时间(2020.03.17 13:27)
            /// </summary>
            public string StatrtTime = string.Empty;
            public string StartTime {
                get
                {
                    try
                    {
                        if(string.IsNullOrEmpty(StartTimeTick))
                        {
                            return string.Empty;
                        }
                        return Utlis.UnixToDateTime(Convert.ToInt64(StartTimeTick)).ToString("yyyy.MM.dd HH:mm");
                    }catch(Exception ex)
                    {
                        MainPage.Log($"临时密码生效时间转换异常: {ex.Message}");
                        return string.Empty;
                    }
                }
            }
            public string StartTimeTick = string.Empty;
            /// <summary>
            /// 临时密码失效时间(2020.03.17 13:27)
            /// </summary>
            public string EndTime = string.Empty;
            public string EndTime {
                get
                {
                    try
                    {
                        if (string.IsNullOrEmpty(EndTimeTick))
                        {
                            return string.Empty;
                        }
                        return Utlis.UnixToDateTime(Convert.ToInt64(EndTimeTick)).ToString("yyyy.MM.dd HH:mm");
                    }
                    catch (Exception ex)
                    {
                        MainPage.Log($"临时密码生效时间转换异常: {ex.Message}");
                        return string.Empty;
                    }
                }
            }
            public string EndTimeTick = string.Empty;
            /// <summary>
            /// 临时密码id
            /// </summary>
            public string PwdId = string.Empty;
        }
        /// <summary>
        /// 门锁临时密码
        /// </summary>
        private class DoorTempPassword
        {
            public string pwdId = string.Empty;
            public string pwd = string.Empty;
            public string beginTime = string.Empty;
            public string endTime = string.Empty;
        }
        #endregion
    }
}