?? 登錄.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 + -