?? loginfrm.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace 教師簽到系統
{
/// <summary>
/// LoginFrm 的摘要說明。
/// </summary>
public class LoginFrm : System.Windows.Forms.Form
{
public static bool blCanLogin = false;//記錄能否檢驗是否通過
public static string strUser = "";//記錄用戶名
private DataSet ds = new DataSet();
private System.Data.DataTable myTable;
private DataRow myRow;
private string sendStrSQL = "SELECT * from 管理員表";
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button btnLonin;
private System.Windows.Forms.Button btnCancel;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public LoginFrm()
{
//
// Windows 窗體設計器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 調用后添加任何構造函數代碼
//
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 窗體設計器生成的代碼
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.btnLonin = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 23);
this.label1.TabIndex = 0;
this.label1.Text = "管理員編號";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label3
//
this.label3.Location = new System.Drawing.Point(8, 72);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(64, 23);
this.label3.TabIndex = 2;
this.label3.Text = "密碼";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(88, 32);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 3;
this.textBox1.Text = "";
this.textBox1.Leave += new System.EventHandler(this.textBox1_Leave);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(88, 72);
this.textBox2.Name = "textBox2";
this.textBox2.PasswordChar = '*';
this.textBox2.TabIndex = 4;
this.textBox2.Text = "";
//
// btnLonin
//
this.btnLonin.Location = new System.Drawing.Point(40, 128);
this.btnLonin.Name = "btnLonin";
this.btnLonin.Size = new System.Drawing.Size(56, 23);
this.btnLonin.TabIndex = 5;
this.btnLonin.Text = "登陸";
this.btnLonin.Click += new System.EventHandler(this.btnLonin_Click);
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(128, 128);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(56, 23);
this.btnCancel.TabIndex = 6;
this.btnCancel.Text = "取消";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// LoginFrm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(224, 174);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnLonin);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label3);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "LoginFrm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "登陸";
this.ResumeLayout(false);
}
#endregion
private void btnLonin_Click(object sender, System.EventArgs e)
{
if(this.textBox1.Text=="")
{
MessageBox.Show("用戶名不能為空");
return;
}
if(this.textBox2.Text=="")
{
MessageBox.Show("密碼不能為空");
return;
}
for(int i=0;i< this.myTable.Rows.Count;i++)
{
this.myRow = myTable.Rows[i];
//只有當輸入的用戶名和密碼同時對應數據庫中記錄時,才能通過校驗
if(myRow[0].ToString().Trim()==this.textBox1.Text.ToString().Trim()&&
myRow[2].ToString().Trim()==this.textBox2.Text.ToString().Trim())
{
blCanLogin = true;
strUser = myRow[0].ToString().Trim();//保存用戶名
MessageBox.Show("登陸成功");
this.Close();
return;
}
}
MessageBox.Show("你輸入的用戶號或密碼不正確!");
this.textBox1.Clear();
this.textBox2.Clear();
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
blCanLogin = false;
this.Close();
}
private void textBox1_Leave(object sender, System.EventArgs e)
{
this.textBox2.Text = "";
for(int i=0;i<myTable.Rows.Count;i++)
{
this.myRow = myTable.Rows[i];
if(myRow[0].ToString().Trim()==this.textBox1.Text.ToString ().Trim())
{
this.textBox2.Focus();
}
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -