📄 frmlogin.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using BusinessRule;
using DataAccess;
namespace Forms
{
/// <summary>
/// frmLogin 的摘要说明。
/// </summary>
public class frmLogin : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtPassWord;
private System.Windows.Forms.Button btnLog;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.TextBox txtUserName;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
//构造函数
public frmLogin()
{
InitializeComponent();
if(frmMain.UserID != 10000)
{
txtUserName.Text = frmMain.UserID.ToString();
txtUserName.SelectAll();
}
}
/// <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(frmLogin));
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.txtPassWord = new System.Windows.Forms.TextBox();
this.txtUserName = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.btnLog = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label3 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.txtPassWord);
this.groupBox1.Controls.Add(this.txtUserName);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.btnLog);
this.groupBox1.Controls.Add(this.btnExit);
this.groupBox1.Location = new System.Drawing.Point(16, 144);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(267, 144);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
//
// txtPassWord
//
this.txtPassWord.Location = new System.Drawing.Point(104, 64);
this.txtPassWord.Name = "txtPassWord";
this.txtPassWord.PasswordChar = '*';
this.txtPassWord.Size = new System.Drawing.Size(144, 21);
this.txtPassWord.TabIndex = 1;
this.txtPassWord.Text = "";
this.txtPassWord.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtPassWord_KeyPress);
//
// txtUserName
//
this.txtUserName.Location = new System.Drawing.Point(104, 24);
this.txtUserName.Name = "txtUserName";
this.txtUserName.Size = new System.Drawing.Size(144, 21);
this.txtUserName.TabIndex = 0;
this.txtUserName.Text = "";
this.txtUserName.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtUserName_KeyPress);
//
// label2
//
this.label2.Location = new System.Drawing.Point(24, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 23);
this.label2.TabIndex = 3;
this.label2.Text = "密码:";
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 23);
this.label1.TabIndex = 2;
this.label1.Text = "用户名:";
//
// btnLog
//
this.btnLog.Location = new System.Drawing.Point(56, 104);
this.btnLog.Name = "btnLog";
this.btnLog.Size = new System.Drawing.Size(72, 24);
this.btnLog.TabIndex = 10;
this.btnLog.Text = "登录(&L)";
this.btnLog.Click += new System.EventHandler(this.btnLog_Click);
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(144, 104);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(72, 24);
this.btnExit.TabIndex = 1;
this.btnExit.Text = "取消(&C)";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.pictureBox1.Location = new System.Drawing.Point(16, 8);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(267, 88);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.pictureBox1.TabIndex = 8;
this.pictureBox1.TabStop = false;
//
// label3
//
this.label3.BackColor = System.Drawing.Color.DarkSlateBlue;
this.label3.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.label3.Font = new System.Drawing.Font("黑体", 16.2F);
this.label3.ForeColor = System.Drawing.Color.Yellow;
this.label3.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.label3.Location = new System.Drawing.Point(16, 96);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(267, 37);
this.label3.TabIndex = 9;
this.label3.Text = "北大青鸟管理系统";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// frmLogin
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(304, 301);
this.ControlBox = false;
this.Controls.Add(this.label3);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.groupBox1);
this.MaximizeBox = false;
this.Name = "frmLogin";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "登录";
this.Load += new System.EventHandler(this.frmLogin_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
//单击“登录”按键
private void btnLog_Click(object sender, System.EventArgs e)
{
int teaID;
try
{
teaID = int.Parse(txtUserName.Text.Trim());
}
catch(Exception ex)
{
MessageBox.Show("用户名不可以包含非数字字符!","用户名错误",MessageBoxButtons.OK ,MessageBoxIcon.Error);
txtUserName.Focus();
txtUserName.SelectAll();
txtPassWord.Text = "";
return;
}
if(jimmy.CheckUp(teaID,txtPassWord.Text.Trim()))
{
frmMain.UserID = teaID;
this.Close();
}
else
{
MessageBox.Show("抱歉,用户名和密码不匹配!","登录不成功",MessageBoxButtons.OK,MessageBoxIcon.Error);
txtUserName.Focus();
txtUserName.SelectAll();
txtPassWord.Text = "";
}
}
//单击“取消”按键
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
//两个文本输入框都支持直接按回车键登录
private void txtUserName_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar == (char)13 )
{
btnLog_Click(sender,e);
}
}
private void txtPassWord_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar == (char)13 )
{
btnLog_Click(sender,e);
}
}
private void frmLogin_Load(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -