📄 login.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Model;
using Business_Logic;
namespace Railroad_Trip
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Login : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtUserName;
private System.Windows.Forms.TextBox txtPassWord;
private System.Windows.Forms.Label lblUpdatePass;
private System.Windows.Forms.Label lblRegister;
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.Label lblLogin;
private System.ComponentModel.IContainer components;
public Login()
{
//
// 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.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Login));
this.txtUserName = new System.Windows.Forms.TextBox();
this.txtPassWord = new System.Windows.Forms.TextBox();
this.lblUpdatePass = new System.Windows.Forms.Label();
this.lblRegister = new System.Windows.Forms.Label();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.lblLogin = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// txtUserName
//
this.txtUserName.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtUserName.Location = new System.Drawing.Point(118, 120);
this.txtUserName.Multiline = true;
this.txtUserName.Name = "txtUserName";
this.txtUserName.Size = new System.Drawing.Size(134, 18);
this.txtUserName.TabIndex = 1;
this.txtUserName.Text = "";
//
// txtPassWord
//
this.txtPassWord.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtPassWord.Location = new System.Drawing.Point(118, 146);
this.txtPassWord.Multiline = true;
this.txtPassWord.Name = "txtPassWord";
this.txtPassWord.PasswordChar = '*';
this.txtPassWord.Size = new System.Drawing.Size(134, 18);
this.txtPassWord.TabIndex = 3;
this.txtPassWord.Text = "";
this.txtPassWord.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtPassWord_KeyPress);
//
// lblUpdatePass
//
this.lblUpdatePass.BackColor = System.Drawing.Color.Transparent;
this.lblUpdatePass.Cursor = System.Windows.Forms.Cursors.Hand;
this.lblUpdatePass.Location = new System.Drawing.Point(84, 144);
this.lblUpdatePass.Name = "lblUpdatePass";
this.lblUpdatePass.Size = new System.Drawing.Size(22, 22);
this.lblUpdatePass.TabIndex = 4;
this.toolTip1.SetToolTip(this.lblUpdatePass, "点击修改密码");
this.lblUpdatePass.Click += new System.EventHandler(this.lblUpdatePass_Click_1);
//
// lblRegister
//
this.lblRegister.BackColor = System.Drawing.Color.Transparent;
this.lblRegister.Cursor = System.Windows.Forms.Cursors.Hand;
this.lblRegister.Location = new System.Drawing.Point(84, 116);
this.lblRegister.Name = "lblRegister";
this.lblRegister.Size = new System.Drawing.Size(22, 22);
this.lblRegister.TabIndex = 2;
this.toolTip1.SetToolTip(this.lblRegister, "点击注册帐号");
this.lblRegister.Click += new System.EventHandler(this.lblRegister_Click);
//
// lblLogin
//
this.lblLogin.BackColor = System.Drawing.Color.Transparent;
this.lblLogin.Cursor = System.Windows.Forms.Cursors.Hand;
this.lblLogin.Location = new System.Drawing.Point(270, 118);
this.lblLogin.Name = "lblLogin";
this.lblLogin.Size = new System.Drawing.Size(38, 52);
this.lblLogin.TabIndex = 6;
this.toolTip1.SetToolTip(this.lblLogin, "登 录");
this.lblLogin.Click += new System.EventHandler(this.lblLogin_Click);
//
// Login
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(380, 261);
this.Controls.Add(this.lblLogin);
this.Controls.Add(this.lblRegister);
this.Controls.Add(this.lblUpdatePass);
this.Controls.Add(this.txtPassWord);
this.Controls.Add(this.txtUserName);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Login";
this.Text = "铁路旅行时刻表查询系统";
this.Closing += new System.ComponentModel.CancelEventHandler(this.Login_Closing);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Login());
}
public string userName,passWord;
private void lblRegister_Click(object sender, System.EventArgs e)
{
//显示注册帐号的界面
RegisterAccount register=new RegisterAccount();
register.Show();
}
private void lblUpdatePass_Click_1(object sender, System.EventArgs e)
{
//显示修改密码的界面
ModifyPassword modeifypa=new ModifyPassword();
modeifypa.Show();
}
private void lblLogin_Click(object sender, System.EventArgs e)
{
//登录界面的登录事件
userName=txtUserName.Text;
passWord=txtPassWord.Text;
if(txtUserName.Text=="")
{
MessageBox.Show("用户名不能为空!","提示");
return;
}
else
{
if(txtPassWord.Text=="")
{
MessageBox.Show("密码不能为空!","提示");
return;
}
else
{}
}
LoginEntity data=new LoginEntity();
data._UserName=userName;
data._PassWord=passWord;
Handle panduan=new Handle();
if(panduan.ILogin(data))
{
MainView main=new MainView();
this.Visible=false;
main.Show();
}
else
{
MessageBox.Show("用户名或密码错误!","提示");
}
}
private void Login_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Application.Exit();
}
private void txtPassWord_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar==13)
{
//登录界面的登录事件
userName=txtUserName.Text;
passWord=txtPassWord.Text;
if(txtUserName.Text=="")
{
MessageBox.Show("用户名不能为空!","提示");
return;
}
else
{
if(txtPassWord.Text=="")
{
MessageBox.Show("密码不能为空!","提示");
return;
}
else
{}
}
LoginEntity data=new LoginEntity();
data._UserName=userName;
data._PassWord=passWord;
Handle panduan=new Handle();
if(panduan.ILogin(data))
{
MainView main=new MainView();
this.Visible=false;
main.Show();
}
else
{
MessageBox.Show("用户名或密码错误!","提示");
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -