📄 userloginform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using StudentsMIS.Security;
namespace StudentsMIS.WinForm
{
/// <summary>
/// UserLoginForm 的摘要说明。
/// </summary>
public class UserLoginForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtUserID;
private System.Windows.Forms.TextBox txtUserPwd;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Button btnOK;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public UserLoginForm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <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.btnCancel = new System.Windows.Forms.Button();
this.btnOK = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.txtUserID = new System.Windows.Forms.TextBox();
this.txtUserPwd = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// btnCancel
//
this.btnCancel.BackColor = System.Drawing.SystemColors.Control;
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(136, 104);
this.btnCancel.Name = "btnCancel";
this.btnCancel.TabIndex = 0;
this.btnCancel.Text = "关闭";
this.btnCancel.Click += new System.EventHandler(this.button1_Click);
//
// btnOK
//
this.btnOK.BackColor = System.Drawing.SystemColors.Control;
this.btnOK.Location = new System.Drawing.Point(48, 104);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 1;
this.btnOK.Text = "确定";
this.btnOK.Click += new System.EventHandler(this.button2_Click);
//
// label1
//
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Location = new System.Drawing.Point(28, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 23);
this.label1.TabIndex = 2;
this.label1.Text = "用户名:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label2
//
this.label2.BackColor = System.Drawing.Color.Transparent;
this.label2.Location = new System.Drawing.Point(28, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 23);
this.label2.TabIndex = 3;
this.label2.Text = "密 码:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtUserID
//
this.txtUserID.Location = new System.Drawing.Point(104, 32);
this.txtUserID.MaxLength = 20;
this.txtUserID.Name = "txtUserID";
this.txtUserID.Size = new System.Drawing.Size(120, 21);
this.txtUserID.TabIndex = 4;
this.txtUserID.Text = "";
//
// txtUserPwd
//
this.txtUserPwd.Location = new System.Drawing.Point(104, 64);
this.txtUserPwd.MaxLength = 20;
this.txtUserPwd.Name = "txtUserPwd";
this.txtUserPwd.PasswordChar = '*';
this.txtUserPwd.Size = new System.Drawing.Size(120, 21);
this.txtUserPwd.TabIndex = 5;
this.txtUserPwd.Text = "";
//
// UserLoginForm
//
this.AcceptButton = this.btnOK;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.Control;
this.CancelButton = this.btnCancel;
this.ClientSize = new System.Drawing.Size(266, 160);
this.Controls.Add(this.txtUserPwd);
this.Controls.Add(this.txtUserID);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnOK);
this.Controls.Add(this.btnCancel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.HelpButton = true;
this.MaximizeBox = false;
this.Name = "UserLoginForm";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "用户登录";
this.TopMost = true;
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
private void button2_Click(object sender, System.EventArgs e)
{
if(txtUserID.Text.Trim() == "")
{
MessageBox.Show("请先输入用户名!");
return;
}
else if(txtUserPwd.Text.Trim() == "")
{
MessageBox.Show("请先输入用户密码!");
return;
}
else
{
User user = new User(txtUserID.Text.Trim(),txtUserPwd.Text.Trim());
switch(user.Valid)
{
case 0 : MessageBox.Show("对不起,不存在此用户!");break;
case 1 : MessageBox.Show("对不起,密码不正确!");break;
case 2 :
{
CommonValue.userID = user.UserID;
CommonValue.userLevel = user.UserLevel;
this.DialogResult = DialogResult.OK;
this.Close();
break;
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -