📄 修改密码.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace 教师网上录入成绩
{
/// <summary>
/// 修改密码 的摘要说明。
/// </summary>
public class 修改密码 : System.Windows.Forms.Form
{
private CurrencyManager cmOrders;//用于数据导航控制
private System.Windows.Forms.DataGrid dataGrid1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private 教师网上录入成绩.DataSet9 dataSet91;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public 修改密码()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataSet91 = new 教师网上录入成绩.DataSet9();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button3 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.textBox3 = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet91)).BeginInit();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "教师基本信息";
this.dataGrid1.DataSource = this.dataSet91;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(16, 24);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(272, 96);
this.dataGrid1.TabIndex = 0;
//
// dataSet91
//
this.dataSet91.DataSetName = "DataSet9";
this.dataSet91.Locale = new System.Globalization.CultureInfo("zh-CN");
//
// 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("教师号", "教师号"),
new System.Data.Common.DataColumnMapping("姓名", "姓名"),
new System.Data.Common.DataColumnMapping("密码", "密码")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = "DELETE FROM 教师基本信息 WHERE (教师号 = @Original_教师号) AND (姓名 = @Original_姓名) AND (密码 = " +
"@Original_密码 OR @Original_密码 IS NULL AND 密码 IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_教师号", System.Data.SqlDbType.VarChar, 16, 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));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_密码", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "密码", System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation id=3366359E777E4EE;packet size=4096;integrated security=SSPI;data sou" +
"rce=3366359E777E4EE;persist security info=False;initial catalog=jiaoshi";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO 教师基本信息(教师号, 姓名, 密码) VALUES (@教师号, @姓名, @密码); SELECT 教师号, 姓名, 密码 FROM " +
"教师基本信息 WHERE (教师号 = @教师号)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@教师号", System.Data.SqlDbType.VarChar, 16, "教师号"));
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, 10, "密码"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT 教师号, 姓名, 密码 FROM 教师基本信息 WHERE (教师号 LIKE @Param2) AND (密码 LIKE @Param3)";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param2", System.Data.SqlDbType.VarChar, 16, "教师号"));
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param3", System.Data.SqlDbType.VarChar, 10, "密码"));
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = "UPDATE 教师基本信息 SET 教师号 = @教师号, 姓名 = @姓名, 密码 = @密码 WHERE (教师号 = @Original_教师号) AND " +
"(姓名 = @Original_姓名) AND (密码 = @Original_密码 OR @Original_密码 IS NULL AND 密码 IS NUL" +
"L); SELECT 教师号, 姓名, 密码 FROM 教师基本信息 WHERE (教师号 = @教师号)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@教师号", System.Data.SqlDbType.VarChar, 16, "教师号"));
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, 10, "密码"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_教师号", System.Data.SqlDbType.VarChar, 16, 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));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_密码", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "密码", System.Data.DataRowVersion.Original, null));
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 128);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 32);
this.label1.TabIndex = 1;
this.label1.Text = "教师号";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(128, 128);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(112, 21);
this.textBox1.TabIndex = 2;
this.textBox1.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(24, 40);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 32);
this.label2.TabIndex = 3;
this.label2.Text = "新密码";
//
// textBox2
//
this.textBox2.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet91, "教师基本信息.密码"));
this.textBox2.Location = new System.Drawing.Point(128, 40);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(96, 21);
this.textBox2.TabIndex = 4;
this.textBox2.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(280, 144);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(64, 40);
this.button1.TabIndex = 5;
this.button1.Text = "查找";
this.button1.Click += new System.EventHandler(this.button1_Click_1);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.button3);
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.textBox2);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Location = new System.Drawing.Point(24, 216);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(352, 176);
this.groupBox1.TabIndex = 6;
this.groupBox1.TabStop = false;
this.groupBox1.Text = " 修改密码";
//
// button3
//
this.button3.Location = new System.Drawing.Point(136, 88);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(88, 32);
this.button3.TabIndex = 6;
this.button3.Text = "提交";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(24, 88);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(72, 32);
this.button2.TabIndex = 5;
this.button2.Text = "修改";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label3
//
this.label3.Location = new System.Drawing.Point(24, 168);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(56, 24);
this.label3.TabIndex = 7;
this.label3.Text = "密码";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(128, 168);
this.textBox3.Name = "textBox3";
this.textBox3.PasswordChar = '*';
this.textBox3.Size = new System.Drawing.Size(112, 21);
this.textBox3.TabIndex = 8;
this.textBox3.Text = "";
//
// 修改密码
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(448, 405);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.label3);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.dataGrid1);
this.Name = "修改密码";
this.Text = "修改密码";
this.Load += new System.EventHandler(this.修改密码_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet91)).EndInit();
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void 修改密码_Load(object sender, System.EventArgs e)
{
this.dataGrid1.Enabled = false;
this.textBox2.Enabled = false;
this.cmOrders=(CurrencyManager) BindingContext[dataSet91,"教师基本信息"];
}
private void button1_Click_1(object sender, System.EventArgs e)
{
if(this.textBox1.Text != "" )
{
this.sqlDataAdapter1.SelectCommand.Parameters[0].Value = this.textBox1.Text;
this.sqlDataAdapter1.SelectCommand.Parameters[1].Value = this.textBox3.Text;
this.textBox2.Enabled = true;
}
this.dataSet91.Clear();
try
{
this.sqlDataAdapter1.Fill(this.dataSet91);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, System.EventArgs e)
{
this.textBox2.Clear();
this.textBox2.Focus();
}
private void button3_Click(object sender, System.EventArgs e)
{
bool canSubmit;
canSubmit=this.CheckNotNull();
if(canSubmit==false)//有非空值字段为空,不允许提交
{
return;
}
cmOrders.EndCurrentEdit();
if(dataSet91.GetChanges()!=null)
{
try
{
this.sqlDataAdapter1.Update(dataSet91);
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
dataSet91.RejectChanges();
}
}
// this.Close();
}
protected virtual bool CheckNotNull()
{
return(true);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -