From1 准备传值代码:
Password pa = new Password();
pa.MdiParent = this;//声明 PassWord的父窗体是本窗体( Form1)pa.NaVa = NaVa;
pa.PaVa = PaVa;
pa.Show();
PassWord:
public string NaVa = string.Empty;
public string PaVa = string.Empty;
点击修改密码:
private void button1_Click(object sender, EventArgs e)
{
if (this.txt_old.Text==PaVa)
{
if (this.txt_new.Text==this.txt_new2.Text)
{
string str = ConfigurationManager.ConnectionStrings["sqlcnn"].ConnectionString;
SqlConnection cnn = new SqlConnection(str);
SqlCommand cmm = new SqlCommand();
cmm.Connection = cnn;
cmm.CommandText = "update T_Login set Password=@password where UserName=@username";
cmm.Parameters.AddWithValue("@password", txt_new.Text);
cmm.Parameters.AddWithValue("@username", NaVa);
cnn.Open();
cmm.ExecuteNonQuery();
cnn.Close();
MessageBox.Show("密码修改成功!");
this.Close();
}
else
{
txt_old.Text = "";
txt_new.Text = "";
txt_new2.Text = "";
MessageBox.Show("两次输入的密码不一致,请重新输入!");
}
return;
}
else
{
txt_old.Text = "";
txt_new.Text = "";
txt_new2.Text = "";
MessageBox.Show("你输入的密码错误,请重新输入!");
}
//给子窗体定位,离顶部120px;
private void Password_Load(object sender, EventArgs e)
{
this.Top = 120;
}
//退出。结束整个进程
Application.Exit();