using System; using System.Collections.Generic; using HDL_ON.Common; using HDL_ON.DAL.Server; using HDL_ON.DriverLayer; using HDL_ON.Entity; using HDL_ON.UI.CSS; using Shared; namespace HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock { /// /// 视频门锁用户管理界面 /// public class VideoDoorlockUserManagerPage : FrameLayout { FrameLayout bodyView; VerticalScrolViewLayout contentView; FrameLayout userPermissionsView; //Button btnUserName; Function device; VideoDoorlockUser doorlockUser; public Action delCallBackAction; public Action updataUserNameAction; Loading waitPage; public VideoDoorlockUserManagerPage(Function function,VideoDoorlockUser user) { bodyView = this; device = function; doorlockUser = user; BackgroundColor = CSS_Color.BackgroundColor; waitPage = new Loading(); } public override void RemoveFromParent() { base.RemoveFromParent(); bodyView = null; if (waitPage != null) { waitPage.RemoveFromParent(); waitPage = null; } } public void LoadPage() { bodyView.AddChidren(waitPage); new TopViewDiv(bodyView, Language.StringByID(StringId.UserManagement)).LoadTopView(); contentView = new VerticalScrolViewLayout() { Y = Application.GetRealHeight(64), Height = Application.GetRealHeight(667 - 70), }; bodyView.AddChidren(contentView); #region 用户名称 var userNameView = new FrameLayout() { Height = Application.GetRealHeight(50), BackgroundColor = CSS_Color.MainBackgroundColor, }; contentView.AddChidren(userNameView); var btnUserNameTitle = new Button() { X = Application.GetRealWidth(16), Width = Application.GetRealWidth(120), TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.SubheadingFontSize, TextID = StringId.User, }; userNameView.AddChidren(btnUserNameTitle); var btnEditUserNameIcon = new Button() { X = Application.GetRealWidth(333), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(28), Height = Application.GetMinRealAverage(28), UnSelectedImagePath = "Public/EditIcon.png", }; userNameView.AddChidren(btnEditUserNameIcon); var btnUserName = new Button() { X = Application.GetRealWidth(100), Width = Application.GetRealWidth(230), TextAlignment = TextAlignment.CenterRight, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.TextFontSize, Text = doorlockUser.lockUserName }; userNameView.AddChidren(btnUserName); btnUserName.MouseUpEventHandler = (sender, e) => { LoadEvent_EditUserName(); }; #endregion contentView.AddChidren(new Button() { Height = Application.GetRealHeight(8) }); initOptionView(false); EventHandler eventHandler = (sender, e) => { Action callBack = (str) => { if (string.IsNullOrEmpty(str)) { new Tip() { CloseTime = 1, Text = Language.StringByID(StringId.UesrNameCannotBeEmpty), Direction = AMPopTipDirection.None, }.Show(bodyView); return; } if (str == UserInfo.Current.userName) { return; } if (System.Text.Encoding.Unicode.GetBytes(str).Length > 20) { new Tip() { CloseTime = 1, Text = Language.StringByID(StringId.LengthOutOfRange), Direction = AMPopTipDirection.None, }.Show(bodyView); return; } new System.Threading.Thread(() => { try { Application.RunOnMainThread(() => { waitPage.Start(Language.StringByID(StringId.PleaseWait)); }); var pack = ApiUtlis.Ins.HttpRequest.EditDoorlockUserName(device.deviceId, doorlockUser.extUserId, str); if (pack.Code == StateCode.SUCCESS) { Application.RunOnMainThread(() => { btnUserName.Text = str; updataUserNameAction?.Invoke(str); }); } else { //失败提示 Application.RunOnMainThread(() => { if (string.IsNullOrEmpty(pack.message)) { pack.message = Language.StringByID(StringId.OperationFailed); } { var tip = new Tip() { MaxWidth = Application.GetRealWidth(300), Text = $"{pack.message}({pack.Code})", CloseTime = 3, Direction = AMPopTipDirection.None }; tip.Show(MainPage.BaseView); } }); } } catch (Exception ex) { MainPage.Log($"update user name error : {ex.Message}"); } finally { Application.RunOnMainThread(() => { waitPage.Hide(); }); } }) { IsBackground = true }.Start(); }; var pa = new PublicAssmebly(); pa.entryMaxLength = 20; pa.LoadDialog_EditParater(StringId.ChangeName, "", callBack, StringId.UesrNameCannotBeEmpty, 0, new List()); }; btnUserName.MouseUpEventHandler = eventHandler; btnEditUserNameIcon.MouseUpEventHandler = eventHandler; userNameView.MouseUpEventHandler = eventHandler; } void initOptionView(bool isEdit) { if(doorlockUser.faceCount == 0&& doorlockUser.fingerCount == 0 && doorlockUser.pwdCount == 0 && doorlockUser.cardCount == 0) { new PublicAssmebly().TipMsg(StringId.Tip, StringId.VideoDoorlockDelDataTip, () => { delCallBackAction?.Invoke(); this.RemoveFromParent(); }); return; } int childrenViewHeight = Application.GetRealWidth(116); int permissionsViewHeight = Application.GetRealHeight(291 + 92 + 100); if (userPermissionsView!= null) { userPermissionsView.RemoveAll(); if (isEdit) { permissionsViewHeight = Application.GetRealHeight(391 + 50 + 100); childrenViewHeight = Application.GetRealWidth(156); } userPermissionsView.Height = permissionsViewHeight ; } else { userPermissionsView = new FrameLayout() { Height = permissionsViewHeight, BackgroundColor = CSS_Color.MainBackgroundColor, }; contentView.AddChidren(userPermissionsView); } #region 门锁用户开锁方式管理 var userPermissionsTitleView = new FrameLayout() { Height = Application.GetRealHeight(63), BackgroundColor = CSS_Color.MainBackgroundColor, }; userPermissionsView.AddChidren(userPermissionsTitleView); var btnUserPermissionsTitle = new Button() { X = Application.GetRealWidth(16), TextAlignment = TextAlignment.CenterLeft, TextSize = CSS_FontSize.SubheadingFontSize, TextColor = CSS_Color.FirstLevelTitleColor, TextID = StringId.UnlockMethod }; userPermissionsTitleView.AddChidren(btnUserPermissionsTitle); var btnEditUserPermissions = new Button() { X = Application.GetRealWidth(267), Width = Application.GetRealWidth(80), TextAlignment = TextAlignment.CenterRight, TextSize = CSS_FontSize.TextFontSize, TextColor = CSS_Color.MainColor, TextID = !isEdit? StringId.Edit: StringId.Complete, }; userPermissionsTitleView.AddChidren(btnEditUserPermissions); btnEditUserPermissions.MouseUpEventHandler = (sender, e) => { if(!isEdit) { initOptionView(true); } else { initOptionView(false); } }; #region 开锁选项 var unlockOptionView = new FrameLayout() { Y = userPermissionsTitleView.Bottom, Height =2 * childrenViewHeight +Application.GetRealHeight(20), BackgroundColor = CSS_Color.MainBackgroundColor, }; userPermissionsView.AddChidren(unlockOptionView); #region 指纹 var fingerprintView = new FrameLayout() { X = Application.GetRealWidth(16), Width = Application.GetRealWidth(64 + 32), Height = childrenViewHeight }; unlockOptionView.AddChidren(fingerprintView); var btnFingerprintIcon = new Button() { Width = Application.GetRealWidth(64), Height = Application.GetRealWidth(64), UnSelectedImagePath = "FunctionIcon/DoorLock/UserRightsManagement/FingerprintIcon.png", X = Application.GetRealWidth(16), }; fingerprintView.AddChidren(btnFingerprintIcon); var btnFingerprintText = new Button() { Y = btnFingerprintIcon.Bottom, Height = Application.GetRealHeight(44), TextAlignment = TextAlignment.Center, TextSize = CSS_FontSize.TextFontSize, TextColor = CSS_Color.PromptingColor1, TextID = StringId.Fingerprints, }; fingerprintView.AddChidren(btnFingerprintText); if (doorlockUser.fingerCount > 0) { btnFingerprintIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/UserRightsManagement/FingerprintOnIcon.png"; btnFingerprintText.TextColor = CSS_Color.FirstLevelTitleColor; if (Language.CurrentLanguage == "Chinese") { btnFingerprintText.Text = doorlockUser.fingerCount + "组" + Language.StringByID(StringId.Fingerprints); } else { btnFingerprintText.Text = doorlockUser.fingerCount + " " + Language.StringByID(StringId.Fingerprints); } if (isEdit) { var btnClearFingerprints = new Button() { X = Application.GetRealWidth(18), Y = btnFingerprintText.Bottom, Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(28), BorderWidth = 1, BorderColor = CSS_Color.MainColor, Radius = (uint)Application.GetRealWidth(4), TextID = StringId.Clear, TextColor = CSS_Color.MainColor, }; fingerprintView.AddChidren(btnClearFingerprints); btnClearFingerprints.MouseUpEventHandler = (sender, e) => { new System.Threading.Thread(() => { try { Application.RunOnMainThread(() => { waitPage.Start(Language.StringByID(StringId.PleaseWait)); }); var pack = ApiUtlis.Ins.HttpRequest.DeleteDoorlockUserFingerPassword(device.deviceId, doorlockUser.lockUserIndex); if (pack != null && pack.Code == StateCode.SUCCESS) { Application.RunOnMainThread(() => { doorlockUser.fingerCount = 0; //更新界面 initOptionView(true); }); } else { //失败提示 Application.RunOnMainThread(() => { //失败提示 var tip = new Tip() { MaxWidth = Application.GetRealWidth(300), Text = pack.message, CloseTime = 3, Direction = AMPopTipDirection.None }; tip.Show(MainPage.BaseView); }); } } catch (Exception ex) { MainPage.Log($"delete finger error : {ex.Message}"); } finally { Application.RunOnMainThread(() => { waitPage.Hide(); }); } }) { IsBackground = true }.Start(); }; } } #endregion #region 数字密码 var digitalPasswordView = new FrameLayout() { Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(64 + 32), Height = childrenViewHeight }; unlockOptionView.AddChidren(digitalPasswordView); var btnDigitalPasswordIcon = new Button() { Width = Application.GetRealWidth(64), Height = Application.GetRealWidth(64), UnSelectedImagePath = "FunctionIcon/DoorLock/UserRightsManagement/DigitalPasswordIcon.png", X = Application.GetRealWidth(16), }; digitalPasswordView.AddChidren(btnDigitalPasswordIcon); var btnDigitalPasswordText = new Button() { Y = btnDigitalPasswordIcon.Bottom, Height = Application.GetRealHeight(44), TextAlignment = TextAlignment.Center, TextSize = CSS_FontSize.TextFontSize, TextColor = CSS_Color.PromptingColor1, TextID = StringId.DigitalPassword, }; digitalPasswordView.AddChidren(btnDigitalPasswordText); if (doorlockUser.pwdCount > 0) { btnDigitalPasswordIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/UserRightsManagement/DigitalPasswordOnIcon.png"; btnDigitalPasswordText.TextColor = CSS_Color.FirstLevelTitleColor; if (Language.CurrentLanguage == "Chinese") { btnDigitalPasswordText.Text = doorlockUser.pwdCount + "组" + Language.StringByID(StringId.DigitalPassword); } else { btnDigitalPasswordText.Text = doorlockUser.pwdCount + " " + Language.StringByID(StringId.DigitalPassword); } if (isEdit) { var btnClearDigitalPassword = new Button() { X = Application.GetRealWidth(18), Y = btnDigitalPasswordText.Bottom, Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(28), BorderWidth = 1, BorderColor = CSS_Color.MainColor, Radius = (uint)Application.GetRealWidth(4), TextID = StringId.Clear, TextColor = CSS_Color.MainColor, }; digitalPasswordView.AddChidren(btnClearDigitalPassword); btnClearDigitalPassword.MouseUpEventHandler = (sender, e) => { new System.Threading.Thread(() => { try { Application.RunOnMainThread(() => { waitPage.Start(Language.StringByID(StringId.PleaseWait)); }); var pack = ApiUtlis.Ins.HttpRequest.DeleteDoorlockUserNumberPassword(device.deviceId, doorlockUser.lockUserIndex); if (pack != null && pack.Code == StateCode.SUCCESS) { Application.RunOnMainThread(() => { doorlockUser.pwdCount = 0; //更新界面 initOptionView(true); }); } else { //失败提示 Application.RunOnMainThread(() => { //失败提示 var tip = new Tip() { MaxWidth = Application.GetRealWidth(300), Text = pack.message, CloseTime = 3, Direction = AMPopTipDirection.None }; tip.Show(MainPage.BaseView); }); } } catch (Exception ex) { MainPage.Log($"delete number password error : {ex.Message}"); } finally { Application.RunOnMainThread(() => { waitPage.Hide(); }); } }) { IsBackground = true }.Start(); }; } } #endregion #region NFC var nfcView = new FrameLayout() { X = Application.GetRealWidth(263), Width = Application.GetRealWidth(64 + 32), Height = childrenViewHeight }; unlockOptionView.AddChidren(nfcView); var btnNfcIcon = new Button() { Width = Application.GetRealWidth(64), Height = Application.GetRealWidth(64), UnSelectedImagePath = "FunctionIcon/DoorLock/UserRightsManagement/NfcIcon.png", X = Application.GetRealWidth(16), }; nfcView.AddChidren(btnNfcIcon); var btnNfcText = new Button() { Y = btnNfcIcon.Bottom, Height = Application.GetRealHeight(44), TextAlignment = TextAlignment.Center, TextSize = CSS_FontSize.TextFontSize, TextColor = CSS_Color.PromptingColor1, TextID = StringId.NfcKey, }; nfcView.AddChidren(btnNfcText); if (doorlockUser.cardCount > 0) { btnNfcIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/UserRightsManagement/NfcOnIcon.png"; btnNfcText.TextColor = CSS_Color.FirstLevelTitleColor; if (Language.CurrentLanguage == "Chinese") { btnNfcText.Text = doorlockUser.cardCount + "组" + Language.StringByID(StringId.NfcKey); } else { btnNfcText.Text = doorlockUser.cardCount + " " + Language.StringByID(StringId.NfcKey); } if (isEdit) { var btnClearNfc = new Button() { X = Application.GetRealWidth(18), Y = btnNfcText.Bottom, Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(28), BorderWidth = 1, BorderColor = CSS_Color.MainColor, Radius = (uint)Application.GetRealWidth(4), TextID = StringId.Clear, TextColor = CSS_Color.MainColor, }; nfcView.AddChidren(btnClearNfc); btnClearNfc.MouseUpEventHandler = (sender, e) => { new System.Threading.Thread(() => { try { Application.RunOnMainThread(() => { waitPage.Start(Language.StringByID(StringId.PleaseWait)); }); var pack = ApiUtlis.Ins.HttpRequest.DeleteDoorlockUserCardPassword(device.deviceId, doorlockUser.lockUserIndex); if (pack != null && pack.Code == StateCode.SUCCESS) { Application.RunOnMainThread(() => { doorlockUser.cardCount = 0; //更新界面 initOptionView(true); }); } else { Application.RunOnMainThread(() => { //失败提示 var tip = new Tip() { MaxWidth = Application.GetRealWidth(300), Text = pack.message, CloseTime = 3, Direction = AMPopTipDirection.None }; tip.Show(MainPage.BaseView); }); } } catch (Exception ex) { MainPage.Log($"delete face error : {ex.Message}"); } finally { Application.RunOnMainThread(() => { waitPage.Hide(); }); } }) { IsBackground = true }.Start(); }; } } #endregion #region 人脸 var faceView = new FrameLayout() { X = Application.GetRealWidth(16), Y = fingerprintView.Bottom+ Application.GetRealHeight(20), Width = Application.GetRealWidth(64 + 32), Height = childrenViewHeight }; unlockOptionView.AddChidren(faceView); var btnFaceIcon = new Button() { Width = Application.GetRealWidth(64), Height = Application.GetRealWidth(64), UnSelectedImagePath = "FunctionIcon/DoorLock/UserRightsManagement/FaceIcon.png", X = Application.GetRealWidth(16), }; faceView.AddChidren(btnFaceIcon); var btnFaceText = new Button() { Y = btnFaceIcon.Bottom, Height = Application.GetRealHeight(44), TextAlignment = TextAlignment.Center, TextSize = CSS_FontSize.TextFontSize, TextColor = CSS_Color.PromptingColor1, TextID = StringId.FaceKey, }; faceView.AddChidren(btnFaceText); if (doorlockUser.faceCount > 0) { btnFaceIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/UserRightsManagement/FaceOnIcon.png"; btnFaceText.TextColor = CSS_Color.FirstLevelTitleColor; if (Language.CurrentLanguage == "Chinese") { btnFaceText.Text = doorlockUser.faceCount + "组" + Language.StringByID(StringId.FaceKey); } else { btnFaceText.Text = doorlockUser.faceCount + " " + Language.StringByID(StringId.FaceKey); } if (isEdit) { var btnClearFace = new Button() { X = Application.GetRealWidth(18), Y = btnFaceText.Bottom, Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(28), BorderWidth = 1, BorderColor = CSS_Color.MainColor, Radius = (uint)Application.GetRealWidth(4), TextID = StringId.Clear, TextColor = CSS_Color.MainColor, }; faceView.AddChidren(btnClearFace); btnClearFace.MouseUpEventHandler = (sender, e) => { new System.Threading.Thread(() => { try { Application.RunOnMainThread(() => { waitPage.Start(Language.StringByID(StringId.PleaseWait)); }); var pack = ApiUtlis.Ins.HttpRequest.DeleteDoorlockUserFacePassword(device.deviceId, doorlockUser.lockUserIndex); if (pack != null && pack.Code == StateCode.SUCCESS) { Application.RunOnMainThread(() => { doorlockUser.faceCount = 0; //更新界面 initOptionView(true); }); } else { Application.RunOnMainThread(() => { //失败提示 var tip = new Tip() { MaxWidth = Application.GetRealWidth(300), Text = pack.message, CloseTime = 3, Direction = AMPopTipDirection.None }; tip.Show(MainPage.BaseView); }); } } catch (Exception ex) { MainPage.Log($"delete face error : {ex.Message}"); } finally { Application.RunOnMainThread(() => { waitPage.Hide(); }); } }) { IsBackground = true }.Start(); }; } } #endregion #endregion #endregion var delUserView = new FrameLayout() { Y = unlockOptionView.Bottom, Height = Application.GetRealHeight(310), BackgroundColor = CSS_Color.BackgroundColor, }; userPermissionsView.AddChidren(delUserView); Button btnDelUser = new Button() { Y = Application.GetRealHeight(40), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(220), Height = Application.GetRealWidth(44), BackgroundColor = CSS_Color.MainBackgroundColor, TextColor = CSS_Color.WarningColor, Radius = (uint)Application.GetRealWidth(22), TextID = StringId.DeleteUser, TextSize = CSS_FontSize.SubheadingFontSize, }; delUserView.AddChidren(btnDelUser); btnDelUser.MouseUpEventHandler = (sender, e) => { new PublicAssmebly().TipOptionMsg(StringId.Tip, StringId.DeleteDoorlockUserTip, () => { new System.Threading.Thread(() => { try { Application.RunOnMainThread(() => { waitPage.Start(Language.StringByID(StringId.PleaseWait)); }); var pack = ApiUtlis.Ins.HttpRequest.DeleteDoorlockUser(device.deviceId, doorlockUser.lockUserIndex); if (pack != null && pack.Code == StateCode.SUCCESS) { Application.RunOnMainThread(() => { //更新界面 new PublicAssmebly().TipMsg(StringId.Tip, StringId.DeleteSuccess, () => { this.RemoveFromParent(); delCallBackAction?.Invoke(); }); }); } else { Application.RunOnMainThread(() => { if (string.IsNullOrEmpty(pack.message)) { pack.message = Language.StringByID(StringId.OperationFailed); } //失败提示 var tip = new Tip() { MaxWidth = Application.GetRealWidth(300), Text = pack.message, CloseTime = 3, Direction = AMPopTipDirection.None }; tip.Show(MainPage.BaseView); }); } } catch (Exception ex) { MainPage.Log($"delete face error : {ex.Message}"); } finally { Application.RunOnMainThread(() => { waitPage.Hide(); }); } }) { IsBackground = true }.Start(); }); }; } /// /// 加载修改用户名称事件 /// void LoadEvent_EditUserName() { //btnUserName.MouseUpEventHandler = eventHandler; } } }