From a879e5dac4fc7cee747e25a63002c40462cdaef7 Mon Sep 17 00:00:00 2001 From: lss <lsc@hdlchina.com.cn> Date: 星期四, 26 五月 2022 11:39:43 +0800 Subject: [PATCH] 兼容全视通可视对讲 --- HDL_ON/UI/UI2/4-PersonalCenter/Visitor/VisitorQRCodePage.cs | 530 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 518 insertions(+), 12 deletions(-) diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/Visitor/VisitorQRCodePage.cs b/HDL_ON/UI/UI2/4-PersonalCenter/Visitor/VisitorQRCodePage.cs index 01c9940..68285b6 100644 --- a/HDL_ON/UI/UI2/4-PersonalCenter/Visitor/VisitorQRCodePage.cs +++ b/HDL_ON/UI/UI2/4-PersonalCenter/Visitor/VisitorQRCodePage.cs @@ -1,31 +1,537 @@ 锘縰sing 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; namespace HDL_ON.UI.UI2.PersonalCenter.Visitor { public class VisitorQRCodePage : FrameLayout { - /// <summary> - /// 椤堕儴title - /// </summary> - FrameLayout topView; FrameLayout bodyView; + VerticalScrolViewLayout bodyScrolView; + private EditText phoneNumberEditText;// 鐢佃瘽鍙风爜EditText + private EditText pwdEditText;// 瀵嗙爜EditText + private Button randomBtn;//闅忔満瀵嗙爜Btn + private FrameLayout codeLayout; + private ImageView codeIV;// 浜岀淮鐮� + private Button codeTip;//浜岀淮鐮佹湁鏁堟湡鎻愮ず + private Button visitorVoucherBtn; + private VisitorTempPassword tempPassword; public VisitorQRCodePage() { - Action click = () => + bodyView = this; + } + + public VisitorQRCodePage(VisitorTempPassword pwd) + { + bodyView = this; + this.tempPassword = pwd; + } + + public void LoadPage() + { + #region 椤堕儴瀵艰埅鏍� + if (tempPassword == null) { - VisitorHistoryPage page = new VisitorHistoryPage(); - MainPage.BasePageView.AddChidren(page); - page.LoadPage(); - MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; + tempPassword = new VisitorTempPassword(); + + Action click = () => + { + VisitorHistoryPage page = new VisitorHistoryPage(); + MainPage.BasePageView.AddChidren(page); + page.LoadPage(); + MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; + }; + + bodyView.BackgroundColor = CSS_Color.BackgroundColor; + new TopViewDiv(bodyView, "璁垮閭�璇�").LoadTopView_SettingText(click, "娴嬭瘯璁板綍"); + + } + else + { + bodyView.BackgroundColor = CSS_Color.BackgroundColor; + new TopViewDiv(bodyView, "璁垮閭�璇�").LoadTopView(); + } + #endregion + + bodyScrolView = new VerticalScrolViewLayout() + { + Y = Application.GetRealHeight(64), + VerticalScrollBarEnabled = false, + BackgroundColor = CSS_Color.MainBackgroundColor, + }; + bodyView.AddChidren(bodyScrolView); + + // 鎻愮ず鏂囧瓧 + bodyScrolView.AddChidren(new Button() + { + Text = "*鎮ㄥ彂璧疯瀹簩缁寸爜鍚庯紝璇ヤ簩缁寸爜灏嗗湪鎮ㄨ缃殑鏈夋晥鏈熷唴锛屽彲鑷敱鍒风爜杩涜杩涘嚭锛岃璋ㄦ厧鍒嗕韩璇ヤ簩缁寸爜銆�", + IsMoreLines = true, + TextSize = CSS_FontSize.PromptFontSize_FirstLevel, + TextColor = CSS_Color.PromptingColor1, + TextAlignment = TextAlignment.Center, + Padding = new Padding(0, Application.GetRealWidth(20), 0, Application.GetRealWidth(20)), + Height = Application.GetRealHeight(60), + }); + + #region 鎵嬫満鍙� + bodyScrolView.AddChidren(new Button() + { + Text = "鎵嬫満鍙�", + Y = Application.GetRealWidth(10), + TextSize = CSS_FontSize.SubheadingFontSize, + TextColor = CSS_Color.FirstLevelTitleColor, + Height = Application.GetRealHeight(20), + Padding = new Padding(0, Application.GetRealWidth(20), 0, Application.GetRealWidth(20)), + TextAlignment = TextAlignment.CenterLeft, + }); + + phoneNumberEditText = new EditText() + { + Height = Application.GetRealHeight(45), + X = Application.GetRealWidth(20), + Width = Application.GetRealWidth(335), + TextSize = CSS_FontSize.TextFontSize, + TextColor = CSS_Color.FirstLevelTitleColor, + PlaceholderText = "杈撳叆璁垮鎵嬫満鍙�", + Text = tempPassword.phone, + IsNumberKeyboardType = true, + PlaceholderTextColor = CSS_Color.PromptingColor1, + }; + bodyScrolView.AddChidren(phoneNumberEditText); + // 鍒嗗壊绾� + bodyScrolView.AddChidren(new Button() + { + X = Application.GetRealWidth(20), + Width = Application.GetRealWidth(335), + Height = Application.GetRealHeight(1), + BackgroundColor = CSS_Color.DividingLineColor, + }); + #endregion + + #region 鍔ㄦ�佸瘑鐮� + bodyScrolView.AddChidren(new Button() { Height = Application.GetRealWidth(10), }); + bodyScrolView.AddChidren(new Button() + { + Text = "鍔ㄦ�佸瘑鐮�", + TextSize = CSS_FontSize.SubheadingFontSize, + TextColor = CSS_Color.FirstLevelTitleColor, + Height = Application.GetRealHeight(20), + Padding = new Padding(0, Application.GetRealWidth(20), 0, Application.GetRealWidth(20)), + TextAlignment = TextAlignment.CenterLeft, + }); + + FrameLayout pwdLayout = new FrameLayout() + { + Height = Application.GetRealHeight(40), }; - bodyView.BackgroundColor = CSS_Color.BackgroundColor; - new TopViewDiv(bodyView, Language.StringByID(StringId.MemberPermissionManagement)).LoadTopView_SettingText(click, ""); + // 瀵嗙爜杈撳叆妗� + pwdEditText = new EditText() + { + X = Application.GetRealWidth(20), + TextSize = CSS_FontSize.TextFontSize, + TextColor = CSS_Color.FirstLevelTitleColor, + Width = Application.GetRealWidth(335), + PlaceholderText = "杈撳叆璁�6浣嶅瘑鐮�", + Text = tempPassword.tempPwd, + PlaceholderTextColor = CSS_Color.PromptingColor1, + }; + pwdLayout.AddChidren(pwdEditText); + + //闅忔満瀵嗙爜Btn + randomBtn = new Button() + { + X = Application.GetRealWidth(275), + Width = Application.GetRealWidth(80), + Text = "闅忔満鐢熸垚", + 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() + { + X = Application.GetRealWidth(20), + Width = Application.GetRealWidth(335), + Height = Application.GetRealHeight(1), + BackgroundColor = CSS_Color.DividingLineColor, + }); + #endregion + + #region 浜岀淮鐮佺敓鏁堟椂闂� + FrameLayout startLayout = new FrameLayout() + { + Height = Application.GetRealHeight(40), + Y = Application.GetRealWidth(10), + BackgroundColor = CSS_Color.BackgroundColor, + }; + + startLayout.AddChidren(new Button() + { + Text = "浜岀淮鐮佺敓鏁堟椂闂�", + X = Application.GetRealWidth(20), + Width = Application.GetRealWidth(130), + TextSize = CSS_FontSize.SubheadingFontSize, + TextColor = CSS_Color.FirstLevelTitleColor, + TextAlignment = TextAlignment.CenterLeft, + Enable = false, + }); + Button startTimeText = new Button() + { + X = Application.GetRealWidth(159), + Width = Application.GetRealWidth(150), + TextAlignment = TextAlignment.CenterRight, + TextSize = CSS_FontSize.TextFontSize, + TextColor = CSS_Color.FirstLevelTitleColor, + }; + if (tempPassword.tempPwd == null || tempPassword.tempPwd == "") + { + startTimeText.Text = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + } + else + { + startTimeText.Text = tempPassword.validBeginTime; + } + + startLayout.AddChidren(startTimeText); + startLayout.AddChidren(new Button() + { + X = Application.GetRealWidth(339), + Gravity = Gravity.CenterVertical, + Width = Application.GetMinRealAverage(16), + Height = Application.GetMinRealAverage(16), + UnSelectedImagePath = "Public/Right.png", + Enable = false, + }); + Button startTimeBtn = new Button(); + startLayout.AddChidren(startTimeBtn); + // dialog鍥炶皟 + Action<string> startTimeAction = (str) => + { + startTimeText.Text = str +":00"; + }; + startTimeBtn.MouseUpEventHandler += (sender, e) => + { + try + { + new LpTimeDialog(Application.Activity, new LpTimeDialogCallBak(startTimeAction)).Show(); + } + catch (Exception ex) + { + string error = ex.Message; + } + }; + bodyScrolView.AddChidren(startLayout); + // 鍒嗗壊绾� + bodyScrolView.AddChidren(new Button() + { + X = Application.GetRealWidth(20), + Width = Application.GetRealWidth(335), + Height = Application.GetRealHeight(1), + BackgroundColor = CSS_Color.DividingLineColor, + }); + + #endregion + + #region 浜岀淮鐮佸け鏁堟椂闂� + FrameLayout endLayout = new FrameLayout() + { + Height = Application.GetRealHeight(40), + Y = Application.GetRealWidth(10), + }; + + endLayout.AddChidren(new Button() + { + Text = "浜岀淮鐮佸け鏁堟椂闂�", + X = Application.GetRealWidth(20), + Width = Application.GetRealWidth(130), + TextSize = CSS_FontSize.SubheadingFontSize, + TextColor = CSS_Color.FirstLevelTitleColor, + TextAlignment = TextAlignment.CenterLeft, + Enable = false, + }); + Button endTimeText = new Button() + { + X = Application.GetRealWidth(159), + Width = Application.GetRealWidth(150), + TextAlignment = TextAlignment.CenterRight, + TextSize = CSS_FontSize.TextFontSize, + TextColor = CSS_Color.FirstLevelTitleColor, + Enable = false, + }; + if (tempPassword.tempPwd == null || tempPassword.tempPwd == "") + { + endTimeText.Text = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + } + else + { + endTimeText.Text = tempPassword.validEndTime; + } + endLayout.AddChidren(endTimeText); + endLayout.AddChidren(new Button() + { + X = Application.GetRealWidth(339), + Gravity = Gravity.CenterVertical, + Width = Application.GetMinRealAverage(16), + Height = Application.GetMinRealAverage(16), + UnSelectedImagePath = "Public/Right.png", + Enable = false, + }); + Button endTimeBtn = new Button(); + endLayout.AddChidren(endTimeBtn); + bodyScrolView.AddChidren(endLayout); + // 鍒嗗壊绾� + bodyScrolView.AddChidren(new Button() + { + X = Application.GetRealWidth(20), + Width = Application.GetRealWidth(335), + Height = Application.GetRealHeight(1), + BackgroundColor = CSS_Color.DividingLineColor, + }); + // dialog鍥炶皟 + Action<string> endTimeAction = (str) => + { + endTimeText.Text = str + ":00"; + }; + endTimeBtn.MouseUpEventHandler += (sender, e) => + { + try + { + new LpTimeDialog(Application.Activity, new LpTimeDialogCallBak(endTimeAction)).Show(); + } + catch (Exception ex) + { + string error = ex.Message; + } + }; + #endregion + + #region 浜岀淮鐮� + bodyScrolView.AddChidren(new Button() { Height = Application.GetRealWidth(33), }); + codeLayout = new FrameLayout() + { + X = Application.GetRealWidth(117), + Width = Application.GetRealWidth(142), + Height = Application.GetRealWidth(142), + }; + bodyScrolView.AddChidren(codeLayout); + + // 浜岀淮鐮両magView + codeIV = new ImageView() + { + BackgroundColor = CSS_Color.BackgroundColor, + }; + codeLayout.AddChidren(codeIV); + + bodyScrolView.AddChidren(new Button() { Height = Application.GetRealWidth(20), }); + bodyScrolView.AddChidren(new Button() + { + X = Application.GetRealWidth(16), + Width = Application.GetRealWidth(343), + Height = Application.GetRealWidth(20), + Text = "闀挎寜鍙互鎶婁簩缁寸爜淇濆瓨鍒扮浉鍐�", + TextAlignment = TextAlignment.Center, + TextColor = CSS_Color.FirstLevelTitleColor, + }); + #endregion + + bodyScrolView.AddChidren(new Button() { Height = Application.GetRealWidth(28), }); + visitorVoucherBtn = new Button() + { + X = Application.GetRealWidth(78), + Width = Application.GetRealWidth(220), + Height = Application.GetRealWidth(44), + BackgroundColor = CSS_Color.MainColor, + Radius = (uint)Application.GetRealWidth(44), + TextSize = CSS_FontSize.SubheadingFontSize, + TextAlignment = TextAlignment.Center, + TextColor = CSS_Color.textWhiteColor, + }; + bodyScrolView.AddChidren(visitorVoucherBtn); // + Action voucher_action = () => + { + if (codeIV.ImageBytes == null) + { + // 璇锋眰鏈嶅姟绔紝鐢熸垚涓存椂瀵嗙爜 + tempPassword.homeId = Entity.DB_ResidenceData.Instance.CurrentRegion.id; + tempPassword.phone = phoneNumberEditText.Text; + tempPassword.tempPwd = pwdEditText.Text; + tempPassword.validBeginTime = startTimeText.Text; + tempPassword.validEndTime = endTimeText.Text; + tempPassword.useCount = 1000; + CreateVisitorPassword(tempPassword); + } + else + { + // 鍒犻櫎璁垮涓存椂瀵嗙爜 + DelVisitorPassword(tempPassword); + } + }; + visitorVoucherBtn.MouseUpEventHandler += (sender, e) => + { + if (phoneNumberEditText.Text == "" || pwdEditText.Text == "") + { + return; + } + string tip = ""; + string message = ""; + if (codeIV.ImageBytes == null) + { + tip = "璁垮鍑瘉"; + message = "鐢熸垚璁垮浜岀淮鐮佸苟灏嗕复鏃跺瘑鐮佸彂閫佽嚦璁垮鎵嬫満."; + } + else + { + tip = "璁垮鍑瘉"; + message = "纭畾鍒犻櫎璁垮鍑瘉锛�"; + } + new LpTipDialog(Application.Activity, tip, message, new LpTipDialogCallBack(voucher_action)).Show(); + }; + + //灏嗕簩缁寸爜淇濆瓨鍒版湰鍦扮浉鍐� + codeIV.MouseLongEventHandler += (sender, e) => + { +#if __Android__ + bool bol = HDLImageUtils.SaveImageToGallery(Application.Activity, + Scan.BytesFromText(tempPassword.tempPwd, codeIV.Width, codeIV.Height)); + + string msg = ""; + if (bol) + { + msg = "淇濆瓨鎴愬姛锛�"; + } + else + { + msg = "淇濆瓨澶辫触锛�"; + } + EmptyTipView tipView = new EmptyTipView(msg, 160); + tipView.Gravity = Gravity.CenterHorizontal; + bodyView.AddChidren(tipView); +#endif + }; + + RefreshVisitorVoucherBtn(); + } + + /// <summary> + /// 鍒锋柊VisitorVoucherBtn鐘舵�� + /// </summary> + private void RefreshVisitorVoucherBtn() + { + if (tempPassword.tempPwd != null && tempPassword.tempPwd != "") + { + codeIV.ImageBytes = Scan.BytesFromText(pwdEditText.Text, codeIV.Width, codeIV.Height); + //鍒ゆ柇浜岀淮鐮佹槸鍚﹀け鏁� + DateTime endTime = DateTime.Parse(tempPassword.validEndTime); + DateTime currentTime = DateTime.Now; + if (currentTime > endTime || !tempPassword.status) + { + // 浜岀淮鐮佹湁鏁堟湡鎻愮ず + codeTip = new Button() + { + TextAlignment = TextAlignment.Center, + TextColor = CSS_Color.textWhiteColor, + BackgroundColor = CSS_Color.DialogTransparentColor1, + Text = "浜岀淮鐮佸凡澶辨晥", + }; + codeLayout.AddChidren(codeTip); + } + visitorVoucherBtn.Text = "鍒犻櫎璁垮鍑瘉"; + } + else + { + visitorVoucherBtn.Text = "鐢熸垚璁垮鍑瘉"; + } + } + + /// <summary> + /// 娣诲姞涓存椂瀵嗙爜锛堣瀹㈠嚟璇侊級 + /// </summary> + /// <param name="homeId">浣忓畢id</param> + /// <param name="phone">璁垮鎵嬫満鍙�</param> + /// <param name="tempPwd">涓存椂瀵嗙爜</param> + /// <param name="validBeginTime">寮�濮嬫椂闂�</param> + /// <param name="validEndTime">缁撴潫鏃堕棿</param> + /// <param name="useCount">浣跨敤娆℃暟锛岄粯璁や竴涓暟鍊煎ぇ涓�浜涚殑</param> + /// <returns></returns> + private bool CreateVisitorPassword(VisitorTempPassword pwd) + { + var result = false; + Dictionary<string, object> dictionary = new Dictionary<string, object>(); + dictionary.Add("homeId", pwd.homeId); + dictionary.Add("phone", pwd.phone); + dictionary.Add("tempPwd", pwd.tempPwd); + dictionary.Add("validBeginTime", pwd.validBeginTime); + dictionary.Add("validEndTime", pwd.validEndTime); + dictionary.Add("useCount", pwd.useCount); + + var requestJson = HttpUtil.GetSignRequestJson(dictionary); + var pack = HttpUtil.RequestHttpsPost(NewAPI.API_POST_ADD_TEMP_PASSWORD, requestJson); + if (pack != null) + { + if (pack.Code == StateCode.SUCCESS) + { + pwd.id = pack.Data.ToString(); + codeIV.ImageBytes = Scan.BytesFromText(pwdEditText.Text, codeIV.Width, codeIV.Height); + } + } + RefreshVisitorVoucherBtn(); + return result; + } + + /// <summary> + /// 鍒犻櫎涓存椂瀵嗙爜(璁垮鍑瘉) + /// </summary> + /// <param name="home_id">浣忓畢id</param> + /// <param name="pwd_id">涓存椂瀵嗙爜id</param> + private bool DelVisitorPassword(VisitorTempPassword pwd) + { + Dictionary<string, object> dictionary = new Dictionary<string, object>(); + dictionary.Add("homeId", pwd.homeId); + dictionary.Add("id", pwd.id); + var result = false; + var requestJson = HttpUtil.GetSignRequestJson(dictionary); + var pack = HttpUtil.RequestHttpsPost(NewAPI.API_POST_DEL_TEMP_PASSWORD, requestJson); + if (pack != null) + { + if (pack.Code == StateCode.SUCCESS) + { + // 鍏抽棴褰撳墠鐣岄潰 + RemoveFromParent(); + } + } + RefreshVisitorVoucherBtn(); + return result; + } + + /// <summary> + /// 鐢熸垚6浣嶉殢鏈哄瘑鐮� + /// </summary> + /// <returns></returns> + private string getRandomPwd() + { + string pwd = ""; + for (int i = 0; i < 6; i++) + { + int math = new Random().Next(0, 9); + pwd += math; + } + return pwd; } } -} +} \ No newline at end of file -- Gitblit v1.8.0