📄 checkpasswordframe.cs
字号:
#region 命名空间
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
#endregion
namespace WindowsApplication
{
#region 检查密码类CheckPassword
/// <summary>
/// CheckPasswordFrame 的摘要说明。
/// </summary>
public class CheckPasswordFrame : System.Windows.Forms.Form
{
#region 控件集合...
private System.Windows.Forms.Label label1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.TextBox textUserName;
private System.Windows.Forms.TextBox textPassword;
#endregion
#region 变量定义...
public static bool blpassword=false;
private ConnectionData conn=new ConnectionData();
private string searchStr="select 用户名称,密码 from System_UserTable";
private DataTable tempTable=new DataTable();
#endregion
#region 类构造函数
public CheckPasswordFrame()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(CheckPasswordFrame));
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textUserName = new System.Windows.Forms.TextBox();
this.textPassword = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.btnOK = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(128)), ((System.Byte)(128)), ((System.Byte)(255)));
this.label1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(0, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(278, 32);
this.label1.TabIndex = 0;
this.label1.Text = "检查密码";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.ForeColor = System.Drawing.SystemColors.ControlText;
this.label2.Location = new System.Drawing.Point(24, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 24);
this.label2.TabIndex = 1;
this.label2.Text = "用户名称:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// textUserName
//
this.textUserName.Location = new System.Drawing.Point(104, 56);
this.textUserName.Name = "textUserName";
this.textUserName.Size = new System.Drawing.Size(144, 21);
this.textUserName.TabIndex = 2;
this.textUserName.Text = "";
//
// textPassword
//
this.textPassword.Location = new System.Drawing.Point(104, 96);
this.textPassword.Name = "textPassword";
this.textPassword.PasswordChar = '%';
this.textPassword.Size = new System.Drawing.Size(144, 21);
this.textPassword.TabIndex = 4;
this.textPassword.Text = "";
//
// label3
//
this.label3.ForeColor = System.Drawing.SystemColors.ControlText;
this.label3.Location = new System.Drawing.Point(24, 96);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(64, 24);
this.label3.TabIndex = 3;
this.label3.Text = "密码:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// btnOK
//
this.btnOK.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnOK.ForeColor = System.Drawing.SystemColors.ControlText;
this.btnOK.Location = new System.Drawing.Point(64, 144);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 5;
this.btnOK.Text = "确定(&C)";
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// button2
//
this.button2.Cursor = System.Windows.Forms.Cursors.Hand;
this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button2.ForeColor = System.Drawing.SystemColors.ControlText;
this.button2.Location = new System.Drawing.Point(168, 144);
this.button2.Name = "button2";
this.button2.TabIndex = 6;
this.button2.Text = "取消(&C)";
//
// CheckPasswordFrame
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.CancelButton = this.button2;
this.ClientSize = new System.Drawing.Size(274, 191);
this.Controls.Add(this.button2);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.textPassword);
this.Controls.Add(this.textUserName);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "CheckPasswordFrame";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "CheckPasswordFrame";
this.Load += new System.EventHandler(this.CheckPasswordFrame_Load);
this.ResumeLayout(false);
}
#endregion
#region 初始化事件...
private void CheckPasswordFrame_Load(object sender, System.EventArgs e)
{
#region 初始化变量
this.textPassword.Focus();
try
{
this.textUserName.Text=landFrame.strUserName;
tempTable=this.ExcuteSql(searchStr,"System_UserTable");
}
catch(Exception ele)
{
MessageBox.Show(this,ele.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
#endregion
}
#endregion
#region 检查非空函数
private bool CheckNull()
{
if(this.textUserName.Text.Equals(""))
{
MessageBox.Show(this,"用户名称不能为空!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.textUserName.Focus();
return false;
}
else if(this.textPassword.Text.Equals(""))
{
MessageBox.Show(this,"密码不能为空!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.textPassword.Focus();
return false;
}
return true;
}
#endregion
#region 清空函数
private void ClearText()
{
this.textPassword.Text="";
this.textUserName.Text="";
}
#endregion
#region 数据库处理函数
private DataTable ExcuteSql(string strSql,string tableName)
{
DataSet dsSet=new DataSet();
DataTable dsTable=new DataTable();
try
{
dsSet=conn.ExcuteDataSetResult(strSql,tableName);
dsTable=dsSet.Tables[0];
}
catch(Exception eles)
{
MessageBox.Show(this,eles.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
return dsTable;
}
#endregion
#region 确定事件...
private void btnOK_Click(object sender, System.EventArgs e)
{
try
{
if(this.CheckNull().Equals(false))
{
return;
}
CheckPasswordFrame.blpassword=ConfireFunction(tempTable);
}
catch(Exception ele)
{
MessageBox.Show(this,ele.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Question);
}
}
#endregion
#region 确定函数...
private bool ConfireFunction(DataTable tableName)
{
bool f=false;
try
{
for(int i=0;i<tableName.Rows.Count;i++)
{
if(tableName.Rows[i][0].ToString().Equals(this.textUserName.Text.ToString()) && tableName.Rows[i][1].ToString().Equals(MD4.EncryptString(this.textPassword.Text.ToString())))
{
MessageBox.Show(this,"密码正确啦!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
f=true;
return f;
}
f=false;
}
if(f.Equals(false))
{
MessageBox.Show(this,"密码不正确啦!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.textPassword.Text="";
this.textPassword.Focus();
return f ;
}
}
catch(Exception ese)
{
MessageBox.Show(this,ese.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
return f;
}
#endregion
}
#endregion
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -