wjc
2023-03-28 a9d1161b1df96e7ddad566335989a1444e433ef5
HDL_ON/UI/UI2/4-PersonalCenter/Visitor/VisitorQRCodePage.cs
@@ -1,10 +1,12 @@
using System;
#if __Android__
using System;
using HDL_ON.UI.CSS;
using Shared;
using Com.Hdl.Hdllinphonesdk.Dialog;
using HDL_ON.DAL.Server;
using System.Collections.Generic;
using Com.Hdl.Hdllinphonesdk.Utils;
using Com.Hdl.Hdllinphonesdk.Dialog;
namespace HDL_ON.UI.UI2.PersonalCenter.Visitor
{
@@ -17,46 +19,61 @@
        private Button randomBtn;//随机密码Btn
        private FrameLayout codeLayout;
        private ImageView codeIV;// 二维码
        private Button codeSaveTipBtn;
        private Button codeTip;//二维码有效期提示
        private Button visitorVoucherBtn;
        private VisitorTempPassword tempPassword;
        Action backAction;// 后退按键,刷新UI
        public VisitorQRCodePage()
        {
            bodyView = this;
        }
        public VisitorQRCodePage(VisitorTempPassword pwd)
        public VisitorQRCodePage(Action action,VisitorTempPassword pwd)
        {
            bodyView = this;
            this.tempPassword = pwd;
            backAction = action;
        }
        public override void RemoveFromParent()
        {
            this.tempPassword = null;
            backAction?.Invoke();
            base.RemoveFromParent();
        }
        public void LoadPage()
        {
            #region 顶部导航栏
            if (tempPassword == null)
#region 顶部导航栏
            if (tempPassword == null || tempPassword.id == null)
            {
                tempPassword = new VisitorTempPassword();
                Action click = () =>
                {
                    VisitorHistoryPage page = new VisitorHistoryPage();
                    Action action = () =>
                    {
                        LoadPage();
                    };
                    VisitorHistoryPage page = new VisitorHistoryPage(action);
                    MainPage.BasePageView.AddChidren(page);
                    page.LoadPage();
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                };
                bodyView.BackgroundColor = CSS_Color.BackgroundColor;
                new TopViewDiv(bodyView, "访客邀请").LoadTopView_SettingText(click, "测试记录");
                new TopViewDiv(bodyView, Language.StringByID(StringId.VisitorInvitation))
                    .LoadTopView_SettingText(click, Language.StringByID(StringId.VisitorRecord));
            }
            else
            {
                bodyView.BackgroundColor = CSS_Color.BackgroundColor;
                new TopViewDiv(bodyView, "访客邀请").LoadTopView();
                new TopViewDiv(bodyView, Language.StringByID(StringId.VisitorInvitation)).LoadTopView();
            }
            #endregion
#endregion
            bodyScrolView = new VerticalScrolViewLayout()
            {
@@ -69,7 +86,7 @@
            // 提示文字
            bodyScrolView.AddChidren(new Button()
            {
                Text = "*您发起访客二维码后,该二维码将在您设置的有效期内,可自由刷码进行进出,请谨慎分享该二维码。",
                Text = Language.StringByID(StringId.VisitorTip),
                IsMoreLines = true,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextColor = CSS_Color.PromptingColor1,
@@ -78,10 +95,10 @@
                Height = Application.GetRealHeight(60),
            });
            #region 手机号
#region 手机号
            bodyScrolView.AddChidren(new Button()
            {
                Text = "手机号",
                Text = Language.StringByID(StringId.PhoneNumber),
                Y = Application.GetRealWidth(10),
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextColor = CSS_Color.FirstLevelTitleColor,
@@ -97,12 +114,15 @@
                Width = Application.GetRealWidth(335),
                TextSize = CSS_FontSize.TextFontSize,
                TextColor = CSS_Color.FirstLevelTitleColor,
                PlaceholderText = "输入访客手机号",
                PlaceholderText = Language.StringByID(StringId.InputPhoneNumberOfTheVisitor),
                Text = tempPassword.phone,
                IsNumberKeyboardType = true,
                PlaceholderTextColor = CSS_Color.PromptingColor1,
            };
            bodyScrolView.AddChidren(phoneNumberEditText);
            //phoneNumberEditText.Foucs = true;
            // 分割线
            bodyScrolView.AddChidren(new Button()
            {
@@ -111,13 +131,13 @@
                Height = Application.GetRealHeight(1),
                BackgroundColor = CSS_Color.DividingLineColor,
            });
            #endregion
#endregion
            #region 动态密码
#region 动态密码
            bodyScrolView.AddChidren(new Button() { Height = Application.GetRealWidth(10), });
            bodyScrolView.AddChidren(new Button()
            {
                Text = "动态密码",
                Text = Language.StringByID(StringId.linshimima),
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextColor = CSS_Color.FirstLevelTitleColor,
                Height = Application.GetRealHeight(20),
@@ -137,8 +157,8 @@
                TextSize = CSS_FontSize.TextFontSize,
                TextColor = CSS_Color.FirstLevelTitleColor,
                Width = Application.GetRealWidth(335),
                PlaceholderText = "输入访6位密码",
                Text = tempPassword.tempPwd,
                PlaceholderText = Language.StringByID(StringId.Input6_DigitsTemporaryPassword),
                IsNumberKeyboardType = true,
                PlaceholderTextColor = CSS_Color.PromptingColor1,
            };
            pwdLayout.AddChidren(pwdEditText);
@@ -148,18 +168,13 @@
            {
                X = Application.GetRealWidth(275),
                Width = Application.GetRealWidth(80),
                Text = "随机生成",
                Text = Language.StringByID(StringId.RandomGeneration),
                TextAlignment = TextAlignment.CenterRight,
                TextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.TextFontSize,
            };
            pwdLayout.AddChidren(randomBtn);
            bodyScrolView.AddChidren(pwdLayout);
            randomBtn.MouseUpEventHandler += (sender, e) =>
            {
                string tPwd = getRandomPwd();
                pwdEditText.Text = tPwd;
            };
            // 分割线
            bodyScrolView.AddChidren(new Button()
@@ -169,19 +184,18 @@
                Height = Application.GetRealHeight(1),
                BackgroundColor = CSS_Color.DividingLineColor,
            });
            #endregion
#endregion
            #region 二维码生效时间
#region 二维码生效时间
            FrameLayout startLayout = new FrameLayout()
            {
                Height = Application.GetRealHeight(40),
                Y = Application.GetRealWidth(10),
                BackgroundColor = CSS_Color.BackgroundColor,
            };
            startLayout.AddChidren(new Button()
            {
                Text = "二维码生效时间",
                Text = Language.StringByID(StringId.EffectiveTime),
                X = Application.GetRealWidth(20),
                Width = Application.GetRealWidth(130),
                TextSize = CSS_FontSize.SubheadingFontSize,
@@ -199,7 +213,7 @@
            };
            if (tempPassword.tempPwd == null || tempPassword.tempPwd == "")
            {
                startTimeText.Text = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                startTimeText.Text = "";// System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            }
            else
            {
@@ -221,7 +235,7 @@
            // dialog回调
            Action<string> startTimeAction = (str) =>
            {
                startTimeText.Text = str +":00";
                startTimeText.Text = str + ":00";
            };
            startTimeBtn.MouseUpEventHandler += (sender, e) =>
            {
@@ -244,9 +258,9 @@
                BackgroundColor = CSS_Color.DividingLineColor,
            });
            #endregion
#endregion
            #region 二维码失效时间
#region 二维码失效时间
            FrameLayout endLayout = new FrameLayout()
            {
                Height = Application.GetRealHeight(40),
@@ -255,7 +269,7 @@
            endLayout.AddChidren(new Button()
            {
                Text = "二维码失效时间",
                Text = Language.StringByID(StringId.FailureTime),
                X = Application.GetRealWidth(20),
                Width = Application.GetRealWidth(130),
                TextSize = CSS_FontSize.SubheadingFontSize,
@@ -274,7 +288,7 @@
            };
            if (tempPassword.tempPwd == null || tempPassword.tempPwd == "")
            {
                endTimeText.Text = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                endTimeText.Text = "";// System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            }
            else
            {
@@ -317,9 +331,9 @@
                    string error = ex.Message;
                }
            };
            #endregion
#endregion
            #region 二维码
#region 二维码
            bodyScrolView.AddChidren(new Button() { Height = Application.GetRealWidth(33), });
            codeLayout = new FrameLayout()
            {
@@ -337,16 +351,18 @@
            codeLayout.AddChidren(codeIV);
            bodyScrolView.AddChidren(new Button() { Height = Application.GetRealWidth(20), });
            bodyScrolView.AddChidren(new Button()
            codeSaveTipBtn = new Button()
            {
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(343),
                Height = Application.GetRealWidth(20),
                Text = "长按可以把二维码保存到相册",
                Text = Language.StringByID(StringId.LongPressQRCodeSave),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.FirstLevelTitleColor,
            });
            #endregion
                Visible = false,
            };
            bodyScrolView.AddChidren(codeSaveTipBtn);
#endregion
            bodyScrolView.AddChidren(new Button() { Height = Application.GetRealWidth(28), });
            visitorVoucherBtn = new Button()
@@ -362,7 +378,6 @@
            };
            bodyScrolView.AddChidren(visitorVoucherBtn);
            //
            Action voucher_action = () =>
            {
                if (codeIV.ImageBytes == null)
@@ -384,21 +399,67 @@
            };
            visitorVoucherBtn.MouseUpEventHandler += (sender, e) =>
            {
                if (phoneNumberEditText.Text == "" || pwdEditText.Text == "")
                if (startTimeText.Text.Trim() == "")
                {
                    var tip_dialog = new Tip()
                    {
                        Text = Language.StringByID(StringId.VisitorStartTime),
                        CloseTime = 2,
                        Direction = AMPopTipDirection.None
                    };
                    tip_dialog.Show(MainPage.BaseView);
                    return;
                }
                if (endTimeText.Text.Trim() == "")
                {
                    var tip_dialog = new Tip()
                    {
                        Text = Language.StringByID(StringId.VisitorEndTime),
                        CloseTime = 2,
                        Direction = AMPopTipDirection.None
                    };
                    tip_dialog.Show(MainPage.BaseView);
                    return;
                }
                if (phoneNumberEditText.Text.Trim() == "" || phoneNumberEditText.Text.Trim().Length != 11)
                {
                    var tip_dialog = new Tip()
                    {
                        Text = Language.StringByID(StringId.PhoneNumberErrorTip),
                        CloseTime = 2,
                        Direction = AMPopTipDirection.None
                    };
                    tip_dialog.Show(MainPage.BaseView);
                    phoneNumberEditText.Foucs = true;
                    return;
                }
                if (pwdEditText.Text.Trim() == "" || pwdEditText.Text.Trim().Length != 6)
                {
                    var tip_dialog = new Tip()
                    {
                        Text = Language.StringByID(StringId.Input6_DigitsTemporaryPassword),
                        CloseTime = 2,
                        Direction = AMPopTipDirection.None
                    };
                    tip_dialog.Show(MainPage.BaseView);
                    pwdEditText.Foucs = true;
                    return;
                }
                string tip = "";
                string message = "";
                if (codeIV.ImageBytes == null)
                {
                    tip = "访客凭证";
                    message = "生成访客二维码并将临时密码发送至访客手机.";
                    tip = Language.StringByID(StringId.tip);
                    message = Language.StringByID(StringId.VisitorTipContent);
                }
                else
                {
                    tip = "访客凭证";
                    message = "确定删除访客凭证?";
                    tip = Language.StringByID(StringId.tip);
                    message = Language.StringByID(StringId.VisitorDelTipContent);
                }
                new LpTipDialog(Application.Activity, tip, message, new LpTipDialogCallBack(voucher_action)).Show();
            };
@@ -413,17 +474,74 @@
                string msg = "";
                if (bol)
                {
                    msg = "保存成功!";
                    msg = Language.StringByID(StringId.SavedSuccessfully);
                }
                else
                {
                    msg = "保存失败!";
                    msg = Language.StringByID(StringId.saveFail);
                }
                EmptyTipView tipView = new EmptyTipView(msg, 160);
                tipView.Gravity = Gravity.CenterHorizontal;
                bodyView.AddChidren(tipView);
                var tip_dialog = new Tip()
                {
                    Text = msg,
                    CloseTime = 2,
                    Direction = AMPopTipDirection.None
                };
                tip_dialog.Show(MainPage.BaseView);
#endif
            };
            if (tempPassword != null && tempPassword.id != null && tempPassword.id != "")
            {
                pwdEditText.Text = tempPassword.tempPwd;
                pwdEditText.PlaceholderText = Language.StringByID(StringId.TemporaryPasswordInvalid);
                pwdEditText.Enable = false;
                phoneNumberEditText.Enable = false;
                randomBtn.Visible = false;
                startTimeBtn.Enable = false;
                endTimeBtn.Enable = false;
            }
            else
            {
                pwdEditText.FoucsChanged = (sender, e) =>
                {
                    if (!pwdEditText.Foucs)
                    {
                        // 6位密码验证
                        var tip_dialog = new Tip()
                        {
                            Text = Language.StringByID(StringId.Input6_DigitsTemporaryPassword),
                            CloseTime = 2,
                            Direction = AMPopTipDirection.None
                        };
                        tip_dialog.Show(MainPage.BaseView);
                    }
                };
                randomBtn.MouseUpEventHandler += (sender, e) =>
                {
                    string tPwd = getRandomPwd();
                    pwdEditText.Text = tPwd;
                };
                phoneNumberEditText.FoucsChanged = (sender, e) =>
                {
                    if (!phoneNumberEditText.Foucs)
                    {
                        //手机号码错误提示
                        if (!Utlis.CheckPhoneNumber(phoneNumberEditText.Text.Trim(), "86"))
                        {
                            var tip_dialog = new Tip()
                            {
                                Text = Language.StringByID(StringId.PhoneNumberErrorTip),
                                CloseTime = 2,
                                Direction = AMPopTipDirection.None
                            };
                            tip_dialog.Show(MainPage.BaseView);
                        }
                    }
                };
            }
            RefreshVisitorVoucherBtn();
        }
@@ -433,9 +551,11 @@
        /// </summary>
        private void RefreshVisitorVoucherBtn()
        {
            if (tempPassword == null) return;
            if (tempPassword.tempPwd != null && tempPassword.tempPwd != "")
            {
                codeIV.ImageBytes = Scan.BytesFromText(pwdEditText.Text, codeIV.Width, codeIV.Height);
                codeIV.ImageBytes = Scan.BytesFromText(tempPassword.tempPwd, codeIV.Width, codeIV.Height);
                //判断二维码是否失效
                DateTime endTime = DateTime.Parse(tempPassword.validEndTime);
                DateTime currentTime = DateTime.Now;
@@ -447,15 +567,17 @@
                        TextAlignment = TextAlignment.Center,
                        TextColor = CSS_Color.textWhiteColor,
                        BackgroundColor = CSS_Color.DialogTransparentColor1,
                        Text = "二维码已失效",
                        Text = Language.StringByID(StringId.QRcodeIsInvalid),
                    };
                    codeLayout.AddChidren(codeTip);
                    visitorVoucherBtn.Visible = false;
                }
                visitorVoucherBtn.Text = "删除访客凭证";
                visitorVoucherBtn.Text = Language.StringByID(StringId.CancleVisitorCredentials);
            }
            else
            {
                visitorVoucherBtn.Text = "生成访客凭证";
                visitorVoucherBtn.Visible = true;
                visitorVoucherBtn.Text = Language.StringByID(StringId.GenerateVisitorCredentials);
            }
        }
@@ -488,9 +610,19 @@
                {
                    pwd.id = pack.Data.ToString();
                    codeIV.ImageBytes = Scan.BytesFromText(pwdEditText.Text, codeIV.Width, codeIV.Height);
                    codeSaveTipBtn.Visible = true;
                    RefreshVisitorVoucherBtn();
                }
                else {
                    var tip_dialog = new Tip()
                    {
                        Text = pack.message,
                        CloseTime = 2,
                        Direction = AMPopTipDirection.None
                    };
                    tip_dialog.Show(MainPage.BaseView);
                }
            }
            RefreshVisitorVoucherBtn();
            return result;
        }
@@ -534,4 +666,13 @@
            return pwd;
        }
    }
}
}
#else
using Shared;
namespace HDL_ON.UI.UI2.PersonalCenter.Visitor
{
    public class VisitorQRCodePage : FrameLayout
    { }
}
#endif