📄 frmlogin.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace OES
{
public class frmLogin : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblUsername;
public System.Windows.Forms.TextBox txtUsername;
public System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.Label lblPassword;
private System.Windows.Forms.Button btnLogin;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Label lblUserLogin;
private System.ComponentModel.Container components = null;
public static int ctr=1;
public System.Windows.Forms.Label lblLogin;
private System.Windows.Forms.Label label1;
public static string userid;
public frmLogin()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmLogin));
this.lblUsername = new System.Windows.Forms.Label();
this.txtUsername = new System.Windows.Forms.TextBox();
this.txtPassword = new System.Windows.Forms.TextBox();
this.lblPassword = new System.Windows.Forms.Label();
this.btnLogin = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.lblUserLogin = new System.Windows.Forms.Label();
this.lblLogin = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lblUsername
//
this.lblUsername.AutoSize = true;
this.lblUsername.BackColor = System.Drawing.Color.Transparent;
this.lblUsername.Font = new System.Drawing.Font("Century Gothic", 9F);
this.lblUsername.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.lblUsername.Location = new System.Drawing.Point(152, 136);
this.lblUsername.Name = "lblUsername";
this.lblUsername.Size = new System.Drawing.Size(45, 18);
this.lblUsername.TabIndex = 0;
this.lblUsername.Text = "用户名";
//
// txtUsername
//
this.txtUsername.BackColor = System.Drawing.SystemColors.Info;
this.txtUsername.Location = new System.Drawing.Point(224, 136);
this.txtUsername.Name = "txtUsername";
this.txtUsername.Size = new System.Drawing.Size(104, 21);
this.txtUsername.TabIndex = 1;
this.txtUsername.Text = "";
//
// txtPassword
//
this.txtPassword.BackColor = System.Drawing.SystemColors.Info;
this.txtPassword.Location = new System.Drawing.Point(224, 168);
this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(104, 21);
this.txtPassword.TabIndex = 3;
this.txtPassword.Text = "";
this.txtPassword.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtPassword_KeyPress);
//
// lblPassword
//
this.lblPassword.AutoSize = true;
this.lblPassword.BackColor = System.Drawing.Color.Transparent;
this.lblPassword.Font = new System.Drawing.Font("Century Gothic", 9F);
this.lblPassword.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.lblPassword.Location = new System.Drawing.Point(152, 168);
this.lblPassword.Name = "lblPassword";
this.lblPassword.Size = new System.Drawing.Size(32, 18);
this.lblPassword.TabIndex = 2;
this.lblPassword.Text = "密码";
//
// btnLogin
//
this.btnLogin.BackColor = System.Drawing.Color.Transparent;
this.btnLogin.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnLogin.Font = new System.Drawing.Font("Verdana", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnLogin.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.btnLogin.Location = new System.Drawing.Point(152, 208);
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(80, 24);
this.btnLogin.TabIndex = 4;
this.btnLogin.Text = "登录(&L)";
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
//
// btnExit
//
this.btnExit.BackColor = System.Drawing.Color.Transparent;
this.btnExit.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnExit.Font = new System.Drawing.Font("Verdana", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnExit.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.btnExit.Location = new System.Drawing.Point(248, 208);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(80, 24);
this.btnExit.TabIndex = 6;
this.btnExit.Text = "退出(&E)";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// lblUserLogin
//
this.lblUserLogin.AutoSize = true;
this.lblUserLogin.BackColor = System.Drawing.Color.Transparent;
this.lblUserLogin.Font = new System.Drawing.Font("Century Gothic", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblUserLogin.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
this.lblUserLogin.Location = new System.Drawing.Point(160, 24);
this.lblUserLogin.Name = "lblUserLogin";
this.lblUserLogin.Size = new System.Drawing.Size(191, 39);
this.lblUserLogin.TabIndex = 21;
this.lblUserLogin.Text = "用 户 登 录";
//
// lblLogin
//
this.lblLogin.BackColor = System.Drawing.Color.Transparent;
this.lblLogin.Font = new System.Drawing.Font("Century Gothic", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblLogin.ForeColor = System.Drawing.Color.Red;
this.lblLogin.Location = new System.Drawing.Point(144, 72);
this.lblLogin.Name = "lblLogin";
this.lblLogin.Size = new System.Drawing.Size(272, 48);
this.lblLogin.TabIndex = 22;
this.lblLogin.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label1
//
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Font = new System.Drawing.Font("Century Gothic", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.label1.Location = new System.Drawing.Point(8, 304);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(432, 16);
this.label1.TabIndex = 23;
this.label1.Text = "建议在 800x600 (真彩 32 位) 模式下浏览";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// frmLogin
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(448, 327);
this.ControlBox = false;
this.Controls.Add(this.label1);
this.Controls.Add(this.lblLogin);
this.Controls.Add(this.lblUserLogin);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.txtUsername);
this.Controls.Add(this.lblPassword);
this.Controls.Add(this.lblUsername);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnLogin);
this.Font = new System.Drawing.Font("Times New Roman", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "frmLogin";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Login";
this.ResumeLayout(false);
}
#endregion
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
Application.Exit();
}
//add by dongping 2004-12-26
private bool syntaxCheck()
{
if (this.txtUsername.Text.Trim().Length == 0)
{
MessageBox.Show("用户名不能为空!");
this.txtUsername.Focus();
return false;
}
if (this.txtPassword.Text.Trim().Length == 0)
{
MessageBox.Show("密码不能为空!");
this.txtPassword.Focus();
return false;
}
return true;
}
private void btnLogin_Click(object sender, System.EventArgs e)
{
if(syntaxCheck()==true)
{
DataAccess objDA = DataAccess.GetInstance();
this.Hide();//hide the current instance of the form frmLogin
User user = new User();
userid=this.txtUsername.Text;
string result= user.ValidateUser(this.txtUsername.Text,this.txtPassword.Text);
//add by dong ping 2004-12-25
if (result.CompareTo("USER_ACCOUNT_INACTIVE")==0)
{
MessageBox.Show("帐户处于非活动状态,请和管理员联系!");
this.Show();
}
if (result.CompareTo("USER_NOT_EXISTS")==0)
{
MessageBox.Show("用户名或密码无效!");
this.Show();
}
//checking whether the user is a Administrator, teacher or a student and appropriate Welcome form is loaded
if(result.CompareTo("Student")==0)
{
frmStudentWelcome stud=new frmStudentWelcome(this,this.txtUsername .Text .Trim ());
stud.ShowDialog();//displays a modal dialog
}
else if(result.CompareTo("Teacher")==0)
{
//pass the current instance of the form to frmTeacherWelcome
frmTeacherWelcome objTeacher=new frmTeacherWelcome(this);
objTeacher.ShowDialog(); //displays a modal form
}
else if (result.CompareTo("Admin")==0)
{
//pass the current instance of the form to frmAdminWelcome
frmAdminWelcome objAdmin=new frmAdminWelcome(this);
objAdmin.ShowDialog();//displays a modal form
}
//else
//{
//checking the number of attempts and displaying an appropriate message
// string str;
// str="You are allowed only 3 attempts\nInvalid Username or Password\nAttempt Number : ";
// ctr++;
// this.lblLogin.Text=str+ctr;
// if(ctr <=3)
// {
// this.Show();
// this.txtUsername.Text="";
// this.txtPassword.Text="";
// this.txtUsername.Focus();
// }
// else
// {
// Application.Exit();
// }
}
}
private void txtPassword_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar ==13)
this.btnLogin_Click(sender,e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -