using System; using System.Collections.Generic; using System.Windows.Forms; using Xylem.Common.Utils.UserAccessCtrl.Properties; namespace Xylem.Common.Utils.UserAccessCtrl { public partial class ChangePassword : UserControl, IIdentityForm { private readonly Action closeOnSuccessOrCancel; private readonly IDictionary fields; public ChangePassword() { InitializeComponent(); Dock = DockStyle.Fill; } public ChangePassword(Action closeOnSuccess) : this() { closeOnSuccessOrCancel = closeOnSuccess; fields = new Dictionary { { "OldPassword", tbxOldPassword }, { "NewPassword", newPassword }, { "ConfirmPassword", confirmPassword }, }; lblOldPassword.Text = Resources.StrLblOldPassword; lblNewPassword.Text = Resources.StrLblNewPassword; lblConfirmPassword.Text = Resources.StrLblConfirmPasswort; btnCHangePassword.Text = Resources.StrLblChangePassword; btnCancel.Text = Resources.StrLblCancel; } private void OnCancellationClick(Object sender, EventArgs args) { closeOnSuccessOrCancel?.Invoke(this); } private void OnFormSubmittedClick(Object sender, EventArgs args) { ChangePasswordErrorProvider.Clear(); errorLbl.Text = default(String); if (!Software.ChangePassword(tbxOldPassword.Text, newPassword.Text, confirmPassword.Text, out var errors)) { errorLbl.Text = Resources.StrMsgFailedPasswordChange; foreach (var kvp in errors) { if (fields.TryGetValue(kvp.Key, out var control)) { ChangePasswordErrorProvider.SetError(control, kvp.Value); } } } else { closeOnSuccessOrCancel?.Invoke(this); } } private void btnCHangePassword_KeyDown(Object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) OnFormSubmittedClick(this, null); } private void btnCancel_KeyDown(Object sender, KeyEventArgs e) { OnCancellationClick(this, null); } } }