Files
FullAutoWaterCheck/全自动水压检测仪/Forms/ChangePasswordForm.cs
2026-01-26 18:47:27 +08:00

93 lines
3.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Windows.Forms;
using .DATA;
namespace
{
public partial class ChangePasswordForm : Form
{
private UserRepository _userRepository;
public ChangePasswordForm()
{
InitializeComponent();
_userRepository = new UserRepository();
}
/// <summary>
/// 确定按钮
/// </summary>
private void btnConfirm_Click(object sender, EventArgs e)
{
string oldPassword = txtOldPassword.Text;
string newPassword = txtNewPassword.Text;
string confirmPassword = txtConfirmPassword.Text;
// 验证
if (string.IsNullOrEmpty(oldPassword))
{
MessageBox.Show("请输入旧密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtOldPassword.Focus();
return;
}
if (string.IsNullOrEmpty(newPassword))
{
MessageBox.Show("请输入新密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtNewPassword.Focus();
return;
}
if (newPassword.Length < 6)
{
MessageBox.Show("新密码长度不能少于6位", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtNewPassword.Focus();
return;
}
if (string.IsNullOrEmpty(confirmPassword))
{
MessageBox.Show("请输入确认密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtConfirmPassword.Focus();
return;
}
if (newPassword != confirmPassword)
{
MessageBox.Show("两次输入的密码不一致!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtConfirmPassword.Focus();
return;
}
try
{
if (_userRepository.ChangePassword(LoginData.CurrentUserId, oldPassword, newPassword))
{
MessageBox.Show("密码修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.DialogResult = DialogResult.OK;
this.Close();
}
else
{
MessageBox.Show("旧密码错误,请重新输入!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtOldPassword.Clear();
txtOldPassword.Focus();
}
}
catch (Exception ex)
{
MessageBox.Show($"修改密码失败:{ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// 取消按钮
/// </summary>
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}
}