📄 登录.cs
字号:
//
this.sqlSelectCommand1.CommandText = "SELECT ID, 姓名, 密码, 权限 FROM 操作员表";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE 操作员表 SET 姓名 = @姓名, 密码 = @密码, 权限 = @权限 WHERE (ID = @Original_ID) AND (姓名 = @Original_姓名 OR @Original_姓名 IS NULL AND 姓名 IS NULL) AND (密码 = @Original_密码 OR @Original_密码 IS NULL AND 密码 IS NULL) AND (权限 = @Original_权限 OR @Original_权限 IS NULL AND 权限 IS NULL); SELECT ID, 姓名, 密码, 权限 FROM 操作员表 WHERE (ID = @ID)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@姓名", System.Data.SqlDbType.VarChar, 50, "姓名"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@密码", System.Data.SqlDbType.VarChar, 50, "密码"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@权限", System.Data.SqlDbType.VarChar, 50, "权限"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_姓名", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "姓名", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_密码", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "密码", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_权限", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "权限", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ID", System.Data.SqlDbType.Int, 4, "ID"));
//
// frmLogin
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(322, 144);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "frmLogin";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "用户登录";
this.Load += new System.EventHandler(this.登录_Load);
this.ResumeLayout(false);
}
#endregion
private void label2_Click(object sender, System.EventArgs e)
{
}
private void 登录_Load(object sender, System.EventArgs e)
{
DataSet dsTeacher=new DataSet();
this.sqlDataAdapter1.Fill(dsTeacher,"操作员表");
this.comboBox1.DataSource=dsTeacher.Tables["操作员表"];
this.comboBox1.DisplayMember="姓名";
}
private void label1_Click(object sender, System.EventArgs e)
{
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
}
private void textBox2_TextChanged(object sender, System.EventArgs e)
{
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
//Application.Exit();
}
private void button1_Click(object sender, System.EventArgs e)
{
sql="select * from 操作员表 where 姓名='"+ this.comboBox1.Text +"'";
SqlCommand cmdLogin=new SqlCommand(sql,this.sqlConnection1);
this.sqlConnection1.Open();
try
{
SqlDataReader rdLogin=cmdLogin.ExecuteReader();
if(rdLogin.Read())
{
string passWord=rdLogin.GetString(2);
if(passWord==this.textBox2.Text)
{
frmMain.strTeacher=this.comboBox1.Text;
frmMain.strTeacherPower=rdLogin.GetString(3);
frmMain.bolPass=true;
this.Close();
}
else
{
MessageBox.Show("密码不正确!","登录",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
}
else
{
MessageBox.Show("用户不存在!","登录",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox2.Clear();
}
rdLogin.Close();
}
catch(SqlException exe)
{
MessageBox.Show("用户不存在!","登录",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox2.Clear();
}
finally
{
this.sqlConnection1.Close();
}
}
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==(char)13)
this.textBox2.Focus();
}
private void textBox2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==(char)13)
{
sql="select * from 操作员表 where 姓名='"+ this.comboBox1.Text +"'";
SqlCommand cmdLogin=new SqlCommand(sql,this.sqlConnection1);
this.sqlConnection1.Open();
try
{
SqlDataReader rdLogin=cmdLogin.ExecuteReader();
if(rdLogin.Read())
{
string passWord=rdLogin.GetString(2);
if(passWord==this.textBox2.Text)
{
frmMain.strTeacher=this.comboBox1.Text;
frmMain.strTeacherPower=rdLogin.GetString(3);
frmMain.bolPass=true;
this.Close();
}
else
{
MessageBox.Show("密码不正确!","登录",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
}
else
{
MessageBox.Show("用户不存在!","登录",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox2.Clear();
}
rdLogin.Close();
}
catch(SqlException exe)
{
MessageBox.Show("用户不存在!","登录",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
this.textBox2.Clear();
}
finally
{
this.sqlConnection1.Close();
}
}
}
private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.textBox2.Clear();
this.textBox2.Focus();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -