接上面一篇:c#ATM之登录篇
1.先添加一行命名空间,如果没有这一行代码,下面的代码绝对会出错
using System.Data.SqlClient;`
public Form2()
{
InitializeComponent();
}
Form1 f01;
public Form2(Form1 f1)//隐藏父窗体,然后通过but2 show出来
{
InitializeComponent();
f01 = f1;
}
2.为textBox3设置密码掩字符
private void textBox3_TextChanged(object sender, EventArgs e)
{
textBox3.PasswordChar = '*';
}
3.验证卡号与凭证是否匹配
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("修改失败");
}
}
}
这是上篇c#ATM之登录篇 https://blog.csdn.net/I_TenKai/article/details/84558647