?? loginfrm.cs
字號(hào):
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 進(jìn)銷存管理系統(tǒng)
{
/// <summary>
/// LoginFrm 的摘要說(shuō)明。
/// </summary>
public class LoginFrm : System.Windows.Forms.Form
{
public static bool blCanLogin = false; //記錄能否檢驗(yàn)是否通過(guò)
public static string strUser = ""; //記錄用戶名
public static string strDepartment = "";//記錄通過(guò)者所屬部門
private DataSet ds = new DataSet();
private DataTable myTable;
private DataRow myRow;
private string sendStrSQL = "SELECT * from 用戶清單";
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button btn_Cancel;
private System.Windows.Forms.Button btn_Login;
private System.Windows.Forms.TextBox txt_ID;
private System.Windows.Forms.TextBox txt_Name;
private System.Windows.Forms.TextBox txt_Pwd;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label LB_Warning;
/// <summary>
/// 必需的設(shè)計(jì)器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public LoginFrm()
{
//
// Windows 窗體設(shè)計(jì)器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼
//
//初始化窗體時(shí),從數(shù)據(jù)庫(kù)中的“用戶清單”表中檢索數(shù)據(jù)并保存在mytable中
LinkDataBase link = new LinkDataBase();
string sendTableName = "用戶清單";
this.ds = link.SelectDataBase(sendStrSQL,sendTableName);
this.myTable = ds.Tables[0];
}
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗體設(shè)計(jì)器生成的代碼
/// <summary>
/// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(LoginFrm));
this.btn_Cancel = new System.Windows.Forms.Button();
this.btn_Login = new System.Windows.Forms.Button();
this.txt_ID = new System.Windows.Forms.TextBox();
this.txt_Name = new System.Windows.Forms.TextBox();
this.txt_Pwd = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.LB_Warning = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// btn_Cancel
//
this.btn_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btn_Cancel.Location = new System.Drawing.Point(158, 131);
this.btn_Cancel.Name = "btn_Cancel";
this.btn_Cancel.Size = new System.Drawing.Size(48, 24);
this.btn_Cancel.TabIndex = 5;
this.btn_Cancel.Text = "取消";
this.btn_Cancel.Click += new System.EventHandler(this.btn_Cancel_Click);
//
// btn_Login
//
this.btn_Login.Location = new System.Drawing.Point(74, 131);
this.btn_Login.Name = "btn_Login";
this.btn_Login.Size = new System.Drawing.Size(48, 24);
this.btn_Login.TabIndex = 4;
this.btn_Login.Text = "登錄";
this.btn_Login.Click += new System.EventHandler(this.btn_Login_Click);
//
// txt_ID
//
this.txt_ID.Location = new System.Drawing.Point(104, 17);
this.txt_ID.Name = "txt_ID";
this.txt_ID.Size = new System.Drawing.Size(136, 21);
this.txt_ID.TabIndex = 1;
this.txt_ID.Text = "";
this.txt_ID.Leave += new System.EventHandler(this.txt_ID_Leave);
//
// txt_Name
//
this.txt_Name.Location = new System.Drawing.Point(104, 54);
this.txt_Name.Name = "txt_Name";
this.txt_Name.Size = new System.Drawing.Size(136, 21);
this.txt_Name.TabIndex = 2;
this.txt_Name.Text = "";
//
// txt_Pwd
//
this.txt_Pwd.Location = new System.Drawing.Point(104, 94);
this.txt_Pwd.Name = "txt_Pwd";
this.txt_Pwd.PasswordChar = '*';
this.txt_Pwd.Size = new System.Drawing.Size(136, 21);
this.txt_Pwd.TabIndex = 3;
this.txt_Pwd.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(40, 17);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 23);
this.label1.TabIndex = 6;
this.label1.Text = "用戶號(hào):";
//
// label2
//
this.label2.Location = new System.Drawing.Point(40, 54);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(48, 23);
this.label2.TabIndex = 7;
this.label2.Text = "用戶名:";
//
// label3
//
this.label3.Location = new System.Drawing.Point(40, 94);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(40, 23);
this.label3.TabIndex = 8;
this.label3.Text = "密碼:";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.LB_Warning);
this.groupBox1.Location = new System.Drawing.Point(0, 156);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(280, 32);
this.groupBox1.TabIndex = 10;
this.groupBox1.TabStop = false;
//
// LB_Warning
//
this.LB_Warning.Location = new System.Drawing.Point(54, 13);
this.LB_Warning.Name = "LB_Warning";
this.LB_Warning.Size = new System.Drawing.Size(172, 15);
this.LB_Warning.TabIndex = 10;
this.LB_Warning.Text = "初始用戶號(hào):1 密碼:sys";
this.LB_Warning.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// LoginFrm
//
this.AcceptButton = this.btn_Login;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.CancelButton = this.btn_Cancel;
this.ClientSize = new System.Drawing.Size(280, 189);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.txt_Pwd);
this.Controls.Add(this.txt_Name);
this.Controls.Add(this.txt_ID);
this.Controls.Add(this.btn_Login);
this.Controls.Add(this.btn_Cancel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "LoginFrm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "用戶登錄";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
//-------------根據(jù)輸入的用戶名和密碼進(jìn)行登錄校驗(yàn)------------
private void btn_Login_Click(object sender, System.EventArgs e)
{
for (int i=0;i<myTable.Rows.Count;i++)
{
this.myRow = myTable.Rows[i];
//只有當(dāng)輸入的用戶名和密碼同時(shí)對(duì)應(yīng)上數(shù)據(jù)庫(kù)中記錄時(shí),才能通過(guò)校驗(yàn)
if (myRow[0].ToString().Trim()==this.txt_ID.Text.ToString().Trim() && myRow[4].ToString().Trim()==this.txt_Pwd.Text.ToString().Trim())
{
blCanLogin = true;
strUser = myRow[0].ToString().Trim();//保存用戶名
strDepartment = myRow[1].ToString().Trim();//保存部門名稱
this.Close();//關(guān)閉窗體
return;
}
}
MessageBox.Show( "您輸入的用戶號(hào)或密碼不正確!");
return;
}
//-------關(guān)閉登錄窗口,不進(jìn)行任何操作-----------
private void btn_Cancel_Click(object sender, System.EventArgs e)
{
blCanLogin = false;
this.Close();
}
//----當(dāng)鼠標(biāo)離開(kāi)用戶號(hào)填寫(xiě)框,立即從數(shù)據(jù)庫(kù)中檢索出對(duì)于用戶名稱并顯示----
private void txt_ID_Leave(object sender, System.EventArgs e)
{
this.txt_Name.Text = "";
for (int i=0;i<myTable.Rows.Count;i++)
{
this.myRow = myTable.Rows[i];
if (myRow[0].ToString().Trim()==this.txt_ID.Text.ToString().Trim())
{
this.txt_Name.Text = myRow[2].ToString().Trim();
this.txt_Pwd.Focus();
}
}
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -