验证中...
Languages: C#
Categories: 数据库相关
Latest update 2019-06-12 21:09
注册(更新).txt
Raw Copy
using System;
using System.Data.SqlClient;
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.Windows;
namespace Nurse_Station
{
public partial class 注册 : System.Windows.Forms.Form
{
public 注册()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
}
private void btn_SignUp_Click(object sender, EventArgs e)
{
if (this.txb_UserNo.Text.Trim() == "")
{
MessageBox.Show("用户号不能为空!");
this.txb_UserNo.Focus();
return;
}
if (this.txb_Password.Text.Trim() == "")
{
MessageBox.Show("密码不能为空!");
this.txb_Password.Focus();
return;
}
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.ConnectionString =
sqlConnection.ConnectionString = @"Data Source=22WRRS7FHHMPW08\SQLEXPRESS;Initial Catalog=nurse;Integrated Security=True";
SqlCommand sqlCommand = sqlConnection.CreateCommand();
sqlCommand.CommandText =
"INSERT tb_User (No,Password) VALUES(@No,HASHBYTES('MD5',@Password));";
sqlCommand.Parameters.AddWithValue("@No", this.txb_UserNo.Text.Trim());
sqlCommand.Parameters.AddWithValue("@Password", this.txb_Password.Text.Trim());
sqlCommand.Parameters["@Password"].SqlDbType = SqlDbType.VarChar;
int rowAffected = 0;
try
{
sqlConnection.Open();
rowAffected = sqlCommand.ExecuteNonQuery();
}
catch (SqlException sqlEx)
{
if (sqlEx.Number == 2627)
{
MessageBox.Show("您注册的用户号已存在,请重新输入!\n");
}
}
finally
{
sqlConnection.Close();
}
if (rowAffected == 1)
{
MessageBox.Show("注册成功。");
}
else
{
MessageBox.Show("注册失败!");
}
}
private void btn_SignUp_Click_1(object sender, EventArgs e)
{
用户登录 Form = new 用户登录();
Form.Show();
this.Hide();
}
private void button1_Click(object sender, EventArgs e)
{
首页 Form = new 首页();
Form.Show();
this.Hide();
}
}
}

Comment list( 0 )

You need to Sign in for post a comment

Help Search

Gitee_you_jiang_zheng_wen Zheng_wen_close