?? 用戶管理.cs
字號:
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(120, 32);
this.textBox3.Name = "textBox3";
this.textBox3.PasswordChar = '*';
this.textBox3.Size = new System.Drawing.Size(136, 26);
this.textBox3.TabIndex = 1;
this.textBox3.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(24, 32);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(56, 23);
this.label4.TabIndex = 0;
this.label4.Text = "舊密碼";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.dataGrid1);
this.groupBox2.Controls.Add(this.button10);
this.groupBox2.Font = new System.Drawing.Font("宋體", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.groupBox2.Location = new System.Drawing.Point(16, 32);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(368, 360);
this.groupBox2.TabIndex = 4;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "用戶列表";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "操作員表", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("ID", "ID"),
new System.Data.Common.DataColumnMapping("姓名", "姓名"),
new System.Data.Common.DataColumnMapping("權限", "權限")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = "DELETE FROM 操作員表 WHERE (ID = @Original_ID) AND (姓名 = @Original_姓名 OR @Original_姓名" +
" IS NULL AND 姓名 IS NULL) AND (權限 = @Original_權限 OR @Original_權限 IS NULL AND 權限 I" +
"S NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection2;
this.sqlDeleteCommand1.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.sqlDeleteCommand1.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.sqlDeleteCommand1.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));
//
// sqlConnection2
//
this.sqlConnection2.ConnectionString = "workstation id=XU;packet size=4096;integrated security=SSPI;data source=XU;persis" +
"t security info=False;initial catalog=jifei";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO 操作員表(姓名, 權限) VALUES (@姓名, @權限); SELECT ID, 姓名, 權限 FROM 操作員表 WHERE (ID" +
" = @@IDENTITY)";
this.sqlInsertCommand1.Connection = this.sqlConnection2;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@姓名", System.Data.SqlDbType.VarChar, 50, "姓名"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@權限", System.Data.SqlDbType.VarChar, 50, "權限"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT ID, 姓名, 權限 FROM 操作員表";
this.sqlSelectCommand1.Connection = this.sqlConnection2;
//
// 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); SELECT ID, 姓名, 權限 FROM 操作員表 WHERE (ID = @ID)";
this.sqlUpdateCommand1.Connection = this.sqlConnection2;
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("@ID", System.Data.SqlDbType.Int, 4, "ID"));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=XU;packet size=4096;integrated security=SSPI;data source=XU;persis" +
"t security info=False;initial catalog=jifei";
//
// 用戶管理
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(692, 416);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.添加新用戶);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.MaximizeBox = false;
this.Name = "用戶管理";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "用戶管理";
this.Load += new System.EventHandler(this.用戶管理_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.添加新用戶.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void 用戶管理_Load(object sender, System.EventArgs e)
{
this.comboBox1.SelectedIndex=0;
this.sqlDataAdapter1.Fill(this.sds,"操作員表");
this.dataGrid1.SetDataBinding(this.sds,"操作員表");
this.dataGrid1.Refresh();
if(frmMain.strTeacherPower=="操作員")
{
this.groupBox2.Enabled=false;
this.添加新用戶.Enabled=false;
this.dataGrid1.Visible=false;
}
}
private void groupBox5_Enter(object sender, System.EventArgs e)
{
}
private void button10_Click(object sender, System.EventArgs e)
{
try
{
this.sqlDataAdapter1.Update(sds,"操作員表");
MessageBox.Show("修改成功!","用戶管理",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(SqlException)
{
MessageBox.Show("修改無效,請檢查輸入!","用戶管理",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
//this.sqlConnection2.Close();
}
this.dataGrid1.Refresh();
}
private void button1_Click(object sender, System.EventArgs e)
{
if(this.textBox1.Text!="" & this.textBox2.Text!="")
{
string sql="insert into 操作員表 (姓名,密碼,權限) values ('"+ this.textBox1.Text +"','"+ this.textBox2.Text +"','"+ this.comboBox1.Text +"')";
SqlCommand cmdTjyh=new SqlCommand(sql,this.sqlConnection1);
try
{
this.sqlConnection1.Open();
cmdTjyh.ExecuteNonQuery();
MessageBox.Show("添加成功!","添加用戶",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(SqlException exe)
{
MessageBox.Show("添加失敗!","添加用戶",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
this.sqlConnection1.Close();
sds.Tables["操作員表"].Clear();
this.sqlDataAdapter1.Fill(sds,"操作員表");
this.dataGrid1.SetDataBinding(sds,"操作員表");
this.dataGrid1.Refresh();
this.textBox2.Clear();
this.textBox1.Clear();
}
}
else
{
MessageBox.Show("請輸入完整信息!","添加用戶",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
private void button2_Click(object sender, System.EventArgs e)
{
string strPass="";
string sql="select 密碼 from 操作員表 where 姓名='"+ frmMain.strTeacher +"'";
SqlCommand cmd=new SqlCommand(sql,this.sqlConnection1);
this.sqlConnection1.Open();
SqlDataReader reader=cmd.ExecuteReader();
try
{
reader.Read();
strPass=reader.GetString(0);
}
catch(SqlException exe)
{
reader.Close();
this.sqlConnection1.Close();
MessageBox.Show("數據庫錯誤!","修改密碼",MessageBoxButtons.OK,MessageBoxIcon.Error);
goto finish;
}
finally
{
reader.Close();
this.sqlConnection1.Close();
}
if(strPass==this.textBox3.Text & this.textBox4.Text!="")
{
sql="update 操作員表 set 密碼='"+ this.textBox4.Text +"' where 姓名='"+ frmMain.strTeacher +"'";
SqlCommand cmdXgmm=new SqlCommand(sql,this.sqlConnection1);
this.sqlConnection1.Open();
try
{
cmdXgmm.ExecuteNonQuery();
MessageBox.Show("密碼修改成功!","修改密碼",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(SqlException exe)
{
MessageBox.Show("數據庫錯誤,更新失敗!","修改密碼",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
this.sqlConnection1.Close();
}
}
else
{
MessageBox.Show("原始密碼錯誤或新密碼為空,密碼修改失敗!","修改密碼",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finish:
this.textBox3.Clear();
this.textBox4.Clear();
sds.Tables["操作員表"].Clear();
this.sqlDataAdapter1.Fill(sds,"操作員表");
this.dataGrid1.SetDataBinding(sds,"操作員表");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -