📄 loginfrm.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 中小型酒店管理信息系统
{
/// <summary>
/// LoginFrm 的摘要说明。
/// </summary>
public class LoginFrm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txt_ID;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txt_Name;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txt_Pwd;
private System.Windows.Forms.Button btn_Login;
private System.Windows.Forms.Button btn_Cancel;
private System.Windows.Forms.StatusBar statusBar1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public static bool blCanLogin = false; //记录能否检验是否通过
public static string strUser = ""; //记录用户名
public static string strDepartment = "";//记录通过者所属部门
private DataSet ds = new DataSet(); //全局数据集类型
private DataTable myTable; //数据表类型
private DataRow myRow; //数据行类型
private string sendStrSQL = "SELECT * from jud_rymx";//yhqd为存储用户相关信息的表
public LoginFrm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
LinkDataBase link = new LinkDataBase();
string sendTableName = "jud_rymx";
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()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(LoginFrm));
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.txt_ID = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.txt_Name = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.txt_Pwd = new System.Windows.Forms.TextBox();
this.btn_Login = new System.Windows.Forms.Button();
this.btn_Cancel = new System.Windows.Forms.Button();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.SuspendLayout();
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 14.25F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.ForeColor = System.Drawing.SystemColors.Desktop;
this.label1.Location = new System.Drawing.Point(40, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(208, 24);
this.label1.TabIndex = 0;
this.label1.Text = "XX 酒店管理信息系统";
//
// label2
//
this.label2.Location = new System.Drawing.Point(24, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 23);
this.label2.TabIndex = 3;
this.label2.Text = "编号:";
//
// txt_ID
//
this.txt_ID.Location = new System.Drawing.Point(80, 56);
this.txt_ID.Name = "txt_ID";
this.txt_ID.Size = new System.Drawing.Size(128, 21);
this.txt_ID.TabIndex = 4;
this.txt_ID.Text = "";
this.txt_ID.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_ID_KeyPress);
this.txt_ID.Leave += new System.EventHandler(this.txt_ID_Leave);
//
// label3
//
this.label3.Location = new System.Drawing.Point(24, 88);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(56, 23);
this.label3.TabIndex = 5;
this.label3.Text = "姓名:";
//
// txt_Name
//
this.txt_Name.Enabled = false;
this.txt_Name.Location = new System.Drawing.Point(80, 88);
this.txt_Name.Name = "txt_Name";
this.txt_Name.Size = new System.Drawing.Size(128, 21);
this.txt_Name.TabIndex = 6;
this.txt_Name.Text = "";
this.txt_Name.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_Name_KeyPress);
//
// label4
//
this.label4.Location = new System.Drawing.Point(24, 120);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(56, 23);
this.label4.TabIndex = 7;
this.label4.Text = "密码:";
//
// txt_Pwd
//
this.txt_Pwd.Location = new System.Drawing.Point(80, 120);
this.txt_Pwd.Name = "txt_Pwd";
this.txt_Pwd.PasswordChar = '*';
this.txt_Pwd.Size = new System.Drawing.Size(128, 21);
this.txt_Pwd.TabIndex = 8;
this.txt_Pwd.Text = "";
this.txt_Pwd.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txt_Pwd_KeyPress);
//
// btn_Login
//
this.btn_Login.Location = new System.Drawing.Point(48, 152);
this.btn_Login.Name = "btn_Login";
this.btn_Login.TabIndex = 9;
this.btn_Login.Text = "登录";
this.btn_Login.Click += new System.EventHandler(this.btn_Login_Click);
//
// btn_Cancel
//
this.btn_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btn_Cancel.Location = new System.Drawing.Point(160, 152);
this.btn_Cancel.Name = "btn_Cancel";
this.btn_Cancel.TabIndex = 10;
this.btn_Cancel.Text = "取消";
this.btn_Cancel.Click += new System.EventHandler(this.btn_Cancel_Click);
//
// statusBar1
//
this.statusBar1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.statusBar1.Location = new System.Drawing.Point(0, 185);
this.statusBar1.Name = "statusBar1";
this.statusBar1.Size = new System.Drawing.Size(282, 22);
this.statusBar1.TabIndex = 11;
this.statusBar1.Text = "上海东华大学——徐诚";
//
// LoginFrm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(282, 207);
this.Controls.Add(this.statusBar1);
this.Controls.Add(this.btn_Cancel);
this.Controls.Add(this.btn_Login);
this.Controls.Add(this.txt_Pwd);
this.Controls.Add(this.txt_Name);
this.Controls.Add(this.txt_ID);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.KeyPreview = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "LoginFrm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "用户登录";
this.ResumeLayout(false);
}
#endregion
private void btn_Login_Click(object sender, System.EventArgs e)
{
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() && myRow[4].ToString().Trim()==this.txt_Pwd.Text.ToString().Trim())
{
blCanLogin = true;
strUser = myRow[2].ToString().Trim();//保存用户名
strDepartment = myRow[1].ToString().Trim();//保存部门名称
this.Close();//关闭窗体
return;
}
}
MessageBox.Show( "您输入的用户号或密码不正确!");
return;
}
private void btn_Cancel_Click(object sender, System.EventArgs e)
{
blCanLogin = false;
this.Close();
}
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();
}
}
}
private void txt_ID_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==13)
{
this.txt_Pwd.Focus();
}
}
private void txt_Name_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
}
private void txt_Pwd_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==13)
{
this.btn_Login.Focus();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -