?? changepassword.cs
字號:
this.sqltxtUser.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = "DELETE FROM 用戶清單 WHERE (用戶編號 = @Original_用戶編號) AND (姓名 = @Original_姓名) AND (密碼 = " +
"@Original_密碼 OR @Original_密碼 IS NULL AND 密碼 IS NULL) AND (性別 = @Original_性別) AND" +
" (部門 = @Original_部門)";
this.sqlDeleteCommand1.Connection = this.conn;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_用戶編號", System.Data.SqlDbType.VarChar, 6, 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));
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, 2, 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, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "部門", System.Data.DataRowVersion.Original, null));
//
// conn
//
this.conn.ConnectionString = "workstation id=ZHANGWENXU;packet size=4096;integrated security=SSPI;data source=\"" +
".\";persist security info=False;initial catalog=DBApp";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO 用戶清單(用戶編號, 部門, 姓名, 性別, 密碼) VALUES (@用戶編號, @部門, @姓名, @性別, @密碼); SELECT" +
" 用戶編號, 部門, 姓名, 性別, 密碼 FROM 用戶清單 WHERE (用戶編號 = @用戶編號)";
this.sqlInsertCommand1.Connection = this.conn;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@用戶編號", System.Data.SqlDbType.VarChar, 6, "用戶編號"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@部門", System.Data.SqlDbType.VarChar, 20, "部門"));
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, 2, "性別"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@密碼", System.Data.SqlDbType.VarChar, 50, "密碼"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 用戶編號, 部門, 姓名, 性別, 密碼 FROM 用戶清單";
this.sqlSelectCommand1.Connection = this.conn;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE 用戶清單 SET 用戶編號 = @用戶編號, 部門 = @部門, 姓名 = @姓名, 性別 = @性別, 密碼 = @密碼 WHERE (用戶編號 = @Original_用戶編號) AND (姓名 = @Original_姓名) AND (密碼 = @Original_密碼 OR @Original_密碼 IS NULL AND 密碼 IS NULL) AND (性別 = @Original_性別) AND (部門 = @Original_部門); SELECT 用戶編號, 部門, 姓名, 性別, 密碼 FROM 用戶清單 WHERE (用戶編號 = @用戶編號)";
this.sqlUpdateCommand1.Connection = this.conn;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@用戶編號", System.Data.SqlDbType.VarChar, 6, "用戶編號"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@部門", System.Data.SqlDbType.VarChar, 20, "部門"));
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, 2, "性別"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@密碼", System.Data.SqlDbType.VarChar, 50, "密碼"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_用戶編號", System.Data.SqlDbType.VarChar, 6, 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("@Original_性別", System.Data.SqlDbType.VarChar, 2, 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, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "部門", System.Data.DataRowVersion.Original, null));
//
// imageList1
//
this.imageList1.ImageSize = new System.Drawing.Size(32, 32);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// pictureBox2
//
this.pictureBox2.BackColor = System.Drawing.Color.Transparent;
this.pictureBox2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox2.BackgroundImage")));
this.pictureBox2.Location = new System.Drawing.Point(24, 64);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(32, 32);
this.pictureBox2.TabIndex = 21;
this.pictureBox2.TabStop = false;
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.Transparent;
this.pictureBox1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("pictureBox1.BackgroundImage")));
this.pictureBox1.Location = new System.Drawing.Point(32, 16);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(16, 32);
this.pictureBox1.TabIndex = 20;
this.pictureBox1.TabStop = false;
//
// changePassword
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(312, 213);
this.Controls.Add(this.pictureBox2);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnSubmit);
this.Controls.Add(this.newPassword2);
this.Controls.Add(this.newPassword);
this.Controls.Add(this.oldPassword);
this.Controls.Add(this.txtName);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "changePassword";
this.Text = "口令更改";
this.Load += new System.EventHandler(this.changePassword_Load);
this.ResumeLayout(false);
}
#endregion
private void btnSubmit_Click(object sender, System.EventArgs e)
{
string name=this.txtName .Text ;
string op=this.oldPassword .Text ;
string np=this.newPassword .Text ;
string np2=this.newPassword2 .Text;
int i;
if(name!=""&& op!=""&& np!=""&& np2!="")
{
SqlCommand cmd=new SqlCommand ("select count(*) from 用戶清單 where 姓名='"+name+"' AND 密碼='"+op+"'",conn);
this.conn .Open ();
i=Convert.ToInt32(cmd.ExecuteScalar());
this.conn .Close ();
if(i>0)
{
if(np==np2)
{SqlCommand cmd1=new SqlCommand ("update 用戶清單 set 密碼='"+np+"' where 用戶編號=2",conn);
this.conn .Open ();
cmd1.ExecuteNonQuery ();
this.conn .Close();
MessageBox.Show ("密碼更改成功!!!!");
this.Close ();
}
else
MessageBox.Show ("兩次輸入密碼不一致,請重新輸入!!");
}
else
MessageBox.Show ("該用戶不存在!!!!");
}
// string Name1,Name2;
// string Password1,chNewPassword;
// Name1 = txtName.Text;
//// Name2 =frmLogin.para @userName;
//
// conn.Open();
// cmd.CommandText = "select Password from 用戶清單 where Name =@userName";
// Password1=Convert.ToString(cmd.ExecuteScalar());
//
// conn.Close();
//
//
// chNewPassword = newPassword.Text.ToString();
// if(Password1==oldPassword.Text)
// {
// // newPassword.ReadOnly = false;
// // newPassword2.ReadOnly = false;
//
// // MessageBox.Show(Convert.ToString(Password1==oldPassword.Text));
// if(newPassword2.Text==chNewPassword)
// {
// conn.Open();
// cmd.CommandText = "Update 用戶清單 set 密碼='"+chNewPassword+"' where Name =@userName";
//
// cmd.ExecuteNonQuery();
// cmd.ExecuteScalar();
//
// conn.Close();
// }
// else
// {
//
// MessageBox.Show("你輸入的新密碼有錯誤!!!");
// return;
// }
// }
}
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void changePassword_Load(object sender, System.EventArgs e)
{
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -