⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pwdupdate.cs

📁 物流行业的仓库库存管理系统DOTNET平台下的源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.sure_button.Name = "sure_button";
			this.sure_button.Size = new System.Drawing.Size(72, 24);
			this.sure_button.TabIndex = 1;
			this.sure_button.Text = "确定";
			this.sure_button.Click += new System.EventHandler(this.sure_button_Click);
			// 
			// esc_button
			// 
			this.esc_button.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.esc_button.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.esc_button.Location = new System.Drawing.Point(216, 216);
			this.esc_button.Name = "esc_button";
			this.esc_button.Size = new System.Drawing.Size(72, 24);
			this.esc_button.TabIndex = 2;
			this.esc_button.Text = "退出";
			this.esc_button.Click += new System.EventHandler(this.esc_button_Click);
			// 
			// PwdAdapter
			// 
			this.PwdAdapter.DeleteCommand = this.sqlDeleteCommand1;
			this.PwdAdapter.InsertCommand = this.sqlInsertCommand1;
			this.PwdAdapter.SelectCommand = this.sqlSelectCommand1;
			this.PwdAdapter.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																								 new System.Data.Common.DataTableMapping("Table", "LonInFrm", new System.Data.Common.DataColumnMapping[] {
																																																			 new System.Data.Common.DataColumnMapping("UserID", "UserID"),
																																																			 new System.Data.Common.DataColumnMapping("Password", "Password"),
																																																			 new System.Data.Common.DataColumnMapping("GroupID", "GroupID")})});
			this.PwdAdapter.UpdateCommand = this.sqlUpdateCommand1;
			// 
			// sqlDeleteCommand1
			// 
			this.sqlDeleteCommand1.CommandText = "DELETE FROM LonInFrm WHERE (UserID = @Original_UserID) AND (GroupID = @Original_G" +
				"roupID OR @Original_GroupID IS NULL AND GroupID IS NULL) AND (Password = @Origin" +
				"al_Password OR @Original_Password IS NULL AND Password IS NULL)";
			this.sqlDeleteCommand1.Connection = this.sqlConnection1;
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_UserID", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UserID", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_GroupID", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "GroupID", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Password", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Password", System.Data.DataRowVersion.Original, null));
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "workstation id=WKX;packet size=4096;user id=sa;data source=\".\";persist security i" +
				"nfo=False;initial catalog=storage";
			// 
			// sqlInsertCommand1
			// 
			this.sqlInsertCommand1.CommandText = "INSERT INTO LonInFrm(UserID, Password, GroupID) VALUES (@UserID, @Password, @Grou" +
				"pID); SELECT UserID, Password, GroupID FROM LonInFrm WHERE (UserID = @UserID)";
			this.sqlInsertCommand1.Connection = this.sqlConnection1;
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserID", System.Data.SqlDbType.VarChar, 10, "UserID"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Password", System.Data.SqlDbType.VarChar, 10, "Password"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@GroupID", System.Data.SqlDbType.VarChar, 10, "GroupID"));
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = "SELECT UserID, Password, GroupID FROM LonInFrm";
			this.sqlSelectCommand1.Connection = this.sqlConnection1;
			// 
			// sqlUpdateCommand1
			// 
			this.sqlUpdateCommand1.CommandText = @"UPDATE LonInFrm SET UserID = @UserID, Password = @Password, GroupID = @GroupID WHERE (UserID = @Original_UserID) AND (GroupID = @Original_GroupID OR @Original_GroupID IS NULL AND GroupID IS NULL) AND (Password = @Original_Password OR @Original_Password IS NULL AND Password IS NULL); SELECT UserID, Password, GroupID FROM LonInFrm WHERE (UserID = @UserID)";
			this.sqlUpdateCommand1.Connection = this.sqlConnection1;
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserID", System.Data.SqlDbType.VarChar, 10, "UserID"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Password", System.Data.SqlDbType.VarChar, 10, "Password"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@GroupID", System.Data.SqlDbType.VarChar, 10, "GroupID"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_UserID", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UserID", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_GroupID", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "GroupID", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Password", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Password", System.Data.DataRowVersion.Original, null));
			// 
			// PwdUpdate
			// 
			this.AcceptButton = this.sure_button;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.CancelButton = this.esc_button;
			this.ClientSize = new System.Drawing.Size(336, 262);
			this.Controls.Add(this.esc_button);
			this.Controls.Add(this.sure_button);
			this.Controls.Add(this.groupBox1);
			this.Name = "PwdUpdate";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "修改密码";
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void sure_button_Click(object sender, System.EventArgs e)
		{
			if(textID.Text.Trim()!=string.Empty)//判断是否输入了ID
			{
				userID=textID.Text.Trim();
			}
			else
			{
				MessageBox.Show("此字段不能为空!");
				return;
			}
			if(textPwdOld.Text.Trim()!=string.Empty)//判断是否输入了原有密码
			{
				passWord=textPwdOld.Text.Trim();
			}
			else
			{
				MessageBox.Show("此字段不能为空!");
				return;
	
			}
			if(textPwdNew1.Text.Trim()!=string.Empty)//判断是否输入了新密码
			{
				NewPassWord1=textPwdNew1.Text.Trim();
			}
			else
			{
				MessageBox.Show("此字段不能为空!");
				return;
			}
			if(textPwdNew2.Text.Trim()!=string.Empty)//判断是否再次输入了新密码
			{
				NewPassWord2=textPwdNew2.Text.Trim();
			}
			else
			{
				MessageBox.Show("此字段不能为空!");
				return;
			}
			SqlConnection myConn = null;
			SqlTransaction UserInsertTra = null;
			DataSet UserInfoSet = new DataSet();
			if(NewPassWord1==NewPassWord2)//强制两次输入新密码必须相同
			{
				try
				{
				    
					myConn = new SqlConnection("server=.;Trusted_Connection=yes;user=sa;pwd=1;database=storage");//连接字符串
					myConn.Open();    
					PwdAdapter.SelectCommand.CommandText = "SELECT * FROM LonInFrm  WHERE UserID = '" + userID +"'";
					PwdAdapter.SelectCommand.Connection = myConn;
					PwdAdapter.Fill(UserInfoSet,"UserInfoTab");
					if ( UserInfoSet.Tables["UserInfoTab"] == null || UserInfoSet.Tables["UserInfoTab"].Rows.Count == 0 )//判断用户是否存在
					{
						MessageBox.Show("User is not exist");
						this.textID.Focus();
						this.textID.Select(0,this.textID.Text.Length);
						return;
					}
					if( UserInfoSet.Tables["UserInfoTab"].Rows[0]["PassWord"].ToString().Trim() != passWord )//用户原有密码输入错误
					{
						MessageBox.Show("PassWord Error!");
						this.textPwdOld.Focus();
						this.textPwdOld.Select(0,this.textPwdOld.Text.Length);
						return;
					}
					UserInfoSet.Tables["UserInfoTab"].Rows[0]["PassWord"] = NewPassWord1;//更新密码
					UserInsertTra = myConn.BeginTransaction();
					PwdAdapter.UpdateCommand.Connection = myConn;
					PwdAdapter.UpdateCommand.Transaction = UserInsertTra;
					PwdAdapter.Update(UserInfoSet.Tables[0]);
					UserInsertTra.Commit();
					MessageBox.Show("OK");
				}
				catch( Exception ex )
				{
					UserInsertTra.Rollback();
					MessageBox.Show(ex.Message);
				}
				finally
				{
					if( myConn.State != ConnectionState.Closed )//关闭数据库
					{
						myConn.Close();
					}
				}
			}
		}

		private void esc_button_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -