csharp_ATM之找回密码篇


在这里插入图片描述
1.先添加一行命名空间,如果没有这一行代码,下面的代码绝对会出错

1
using System.Data.SqlClient;`
1
2
3
4
5
6
7
8
9
10
11
public Form2()
{
InitializeComponent();
}

Form1 f01;
public Form2(Form1 f1)//隐藏父窗体,然后通过but2 show出来
{
InitializeComponent();
f01 = f1;
}

2.为textBox3设置密码掩字符

1
2
3
4
private void textBox3_TextChanged(object sender, EventArgs e)
{
textBox3.PasswordChar = '*';
}

3.验证卡号与凭证是否匹配

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" & textBox2.Text == "" & textBox3.Text == "")
{
MessageBox.Show("不能留空哦");
}
else
{
string count = "SERVER=.;DATABASE=OX;USER=SA;PWD=1;";
//string sql= "update server set pwd='" + textBox3.Text.Trim() + "'where sno='"+textBox1.Text+"'where sfz='"+textBox2.Text+"'";
string sql = "update USERR set pwd='" + textBox3.Text + "'where ID='" + textBox1.Text.Trim() + "'AND ID IN(SELECT ID FROM DATA WHERE SFZ='"+textBox2.Text+"')";
//UPDATE USERR SET PWD='12' WHERE ID='123' AND ID IN(SELECT ID FROM DATA WHERE SFZ='9876')
SqlConnection con = new SqlConnection(count);//创建连接对象
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);//创建操作对象
if (cmd.ExecuteNonQuery()>0)
{
MessageBox.Show("修改成功");
Form1 f1 = new Form1();
this.button1.Visible = true;
//this.button2.Visible = true;
this.textBox1.Visible = true;
this.textBox2.Visible = true;
this.label1.Visible = true;
this.label2.Visible = true;
this.label3.Visible = true;
f01.Hide();
f1.Show();
}
else
{
MessageBox.Show("修改失败");
}
}
}

第一篇介绍 csharp_ATM之登录篇
在这里插入图片描述
最后一篇介绍:csharpATM之功能篇(存钱,取钱,转账,交易明细)完结篇
在这里插入图片描述

Evian Z wechat
打赏由马云爸爸买单,谢谢请我喝牛奶.