赞
踩
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
namespace 电影记录管理系统
{
public partial class FrmPwdChange : Form
{
public FrmPwdChange()
{
InitializeComponent();
}
//连接字符串 获取文件里的连接路径
static string connStr = ConfigurationManager.ConnectionStrings["str"].ConnectionString;
private void FrmPwdChange_Load(object sender, EventArgs e)
{
//获取变量uid
string currentUser = Form2.Uid;
//把获取的字符串赋给用户名文本框
txtUsername.Text = currentUser;
}
private void btnOk_Click(object sender, EventArgs e)
{
//连接字符串
SqlConnection conn = new SqlConnection();
//获取当前密码
string sql = "select MUserPwd from MovieAccount where MUserName ='" + txtUsername.Text + "'";
//创建一个cmd对象
SqlCommand cmd = new SqlCommand(sql,conn);
//打开conn连接
conn.Open();
//读取sql数据,获取读到的数据
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())//如果读到了数据,继续进行
{
string oldPwd = sdr.GetString(0).Trim();
//如果用户输入的密码等于旧密码
if (oldPwd == txtOldPwd.Text)
{
if (txtNewPwd.Text.Trim() == "" || txtNewPwdConfirm.Text.Trim() == "")
{
//如果新密码为空,则弹出提示
MessageBox.Show("新密码不能为空!");
return;
}
else if (txtNewPwd.Text.Trim() != txtNewPwd.Text.Trim())
{
//两次新密码不一样,弹出提示
MessageBox.Show("你输入的密码两次不一样,请重新输入!");
//a清空文本框
txtNewPwd.Text = "";
txtNewPwdConfirm.Text = "";
return;
}
else
{
sdr.Close();
string sqlUpdate = "update MovieAccount set MUserPwd ='" + txtNewPwdConfirm.Text +
"' where MUserName ='" + txtUsername.Text + "'";
SqlCommand cmdUp = new SqlCommand();
if (cmdUp.ExecuteNonQuery() == 0)
{
MessageBox.Show("未知错误!");
return;
}
else
{
MessageBox.Show("恭喜你,密码修改成功!");
}
}
}
else
{
MessageBox.Show("旧密码错误");
//清空文本框
txtNewPwd.Text = "";
txtOldPwd.Text = "";
return;
}
}
else
{
MessageBox.Show("用户名不存在,请重新输入!");
txtOldPwd.Text = "";
txtUsername.Text = "";
txtNewPwd.Text = "";
txtNewPwdConfirm.Text = "";
return;
}
//关闭数据库
conn.Close();
}
private void btnBack_Click(object sender, EventArgs e)
{
//返回主窗体
//new一个main窗体
FrmMain main = new FrmMain();
//出现密码修改主窗体
main.Show();
//隐藏当前的窗口
this.Hide();
}
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。