📄 login.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Lib;
using System.IO;
using System.Data;
namespace AssetCheck
{
/// <summary>
/// Login 的摘要说明。
/// </summary>
public class Login : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnLogin;
private System.Windows.Forms.Label labID;
private System.Windows.Forms.TextBox txtID;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.Label labName;
private System.Windows.Forms.TextBox txtPass;
private System.Windows.Forms.Label labPass;
private System.Windows.Forms.Button btnExit;
public static string UserID="";
public static bool bl=false;
public Login()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.labID = new System.Windows.Forms.Label();
this.txtID = new System.Windows.Forms.TextBox();
this.txtName = new System.Windows.Forms.TextBox();
this.labName = new System.Windows.Forms.Label();
this.txtPass = new System.Windows.Forms.TextBox();
this.labPass = new System.Windows.Forms.Label();
this.btnLogin = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
//
// labID
//
this.labID.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold);
this.labID.Location = new System.Drawing.Point(16, 27);
this.labID.Size = new System.Drawing.Size(64, 20);
this.labID.Text = "编号:";
//
// txtID
//
this.txtID.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold);
this.txtID.Location = new System.Drawing.Point(72, 22);
this.txtID.Size = new System.Drawing.Size(155, 30);
this.txtID.Text = "";
this.txtID.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtID_KeyDown);
this.txtID.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtID_KeyPress);
//
// txtName
//
this.txtName.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold);
this.txtName.Location = new System.Drawing.Point(72, 59);
this.txtName.Size = new System.Drawing.Size(155, 30);
this.txtName.Text = "";
this.txtName.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtName_KeyDown);
this.txtName.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtName_KeyPress);
//
// labName
//
this.labName.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold);
this.labName.Location = new System.Drawing.Point(13, 65);
this.labName.Size = new System.Drawing.Size(64, 20);
this.labName.Text = "名称:";
//
// txtPass
//
this.txtPass.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold);
this.txtPass.Location = new System.Drawing.Point(73, 97);
this.txtPass.Size = new System.Drawing.Size(155, 30);
this.txtPass.Text = "";
this.txtPass.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtPass_KeyDown);
this.txtPass.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtPass_KeyPress);
//
// labPass
//
this.labPass.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold);
this.labPass.Location = new System.Drawing.Point(15, 102);
this.labPass.Size = new System.Drawing.Size(64, 20);
this.labPass.Text = "密码:";
//
// btnLogin
//
this.btnLogin.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold);
this.btnLogin.Location = new System.Drawing.Point(6, 148);
this.btnLogin.Size = new System.Drawing.Size(114, 40);
this.btnLogin.Text = "ENT.登陆";
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
//
// btnExit
//
this.btnExit.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold);
this.btnExit.Location = new System.Drawing.Point(124, 148);
this.btnExit.Size = new System.Drawing.Size(114, 40);
this.btnExit.Text = "<.退出";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// Login
//
this.ClientSize = new System.Drawing.Size(242, 197);
this.ControlBox = false;
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnLogin);
this.Controls.Add(this.txtPass);
this.Controls.Add(this.labPass);
this.Controls.Add(this.txtName);
this.Controls.Add(this.labName);
this.Controls.Add(this.txtID);
this.Controls.Add(this.labID);
this.Font = new System.Drawing.Font("宋体", 15.75F, System.Drawing.FontStyle.Bold);
this.Text = "登陆 F+F2重置";
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Login_KeyDown);
this.Load += new System.EventHandler(this.Login_Load);
}
#endregion
private void Login_Load(object sender, System.EventArgs e)
{
/*
a:
if (!Lib.E.BoolRegedit("00900"))
{
Regedit regedit=new Regedit();
try
{
regedit.ShowDialog();
if (regedit.DialogResult==DialogResult.OK)
{
goto a;
}
else
{
Application.Exit();
return ;
}
}
catch
{}
finally
{
regedit.Dispose();
}
}
*/
if (!File.Exists("Asset.sdf"))
{
if (E.conn.State==ConnectionState.Open)
{
E.conn.Close();
}
bl=true;
if (!Libs.DataBase.SetDataBase())
{
Application.Exit();
return;
}
}
Lib.E.ConnStr="Asset.sdf";
E.SetMyAudioController(0);
E.Focus(txtID);
}
private void txtID_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar==(char)13)
{
if (txtID.Text.Trim()!="")
{
txtName.Text=E.ExecStr("select Names from users where ID='"+txtID.Text.Trim()+"'",0);
if (txtName.Text!="")
{
E.Focus(txtPass);
}
else
{
E.Beep("",50,2670,2);
E.MessageShow(true,"编号不存在,请重新输入!");
txtID.Text="";
E.Focus(txtID);
}
}
return;
}
}
private void txtName_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar==(char)13)
{
if (txtName.Text.Trim()!="")
E.Focus(txtPass);
return;
}
}
private void txtPass_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar==(char)13)
{
btnLogin_Click(sender,e);
return;
}
}
private void btnLogin_Click(object sender, System.EventArgs e)
{
if (txtID.Text.Trim()=="")
{
E.Beep("",50,2670,2);
E.MessageShow(true,"编号不能为空,请扫输入!");
E.Focus(txtID);
return;
}
if (E.ExecSC("select Count(ID) from users where ID='"+txtID.Text.Trim()+"' and Pass='"+txtPass.Text.Trim()+"'")>0)
{
UserID=E.ExecStr("select ID from users where ID='"+txtID.Text.Trim()+"' and Pass='"+txtPass.Text.Trim()+"'",0);
DialogResult=DialogResult.OK;
Close();
/*if ((UserID!=""))
{
DialogResult=DialogResult.OK;
Close();
}
else
{
E.Beep("",50,2670,2);
E.MessageShow(true,"编号或密码不正确,请重新输入!");
E.Focus(txtID);
return;
}*/
}
else
{
E.Beep("",50,2670,2);
E.MessageShow(true,"密码不正确,请重新输入!");
E.Focus(txtPass);
return;
}
}
private void btnExit_Click(object sender, System.EventArgs e)
{
DialogResult=DialogResult.Cancel;
Close();
}
private void Login_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyData==Keys.F2)
{
txtClear();
E.Focus(txtID);
return;
}
if (e.KeyData==Keys.Left)
{
Close();
return;
}
}
public void txtClear()
{
txtID.Text="";
txtName.Text="";
txtPass.Text="";
}
private void txtID_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyData==Keys.Down)
{
if (txtID.Text.Trim()!="")
{
txtName.Text=E.ExecStr("select Names from users where ID='"+txtID.Text.Trim()+"'",0);
if (txtName.Text!="")
{
E.Focus(txtPass);
}
else
{
E.Beep("",50,2670,2);
E.MessageShow(true,"编号不存在,请重新输入!");
txtID.Text="";
E.Focus(txtID);
}
}
return;
}
if (e.KeyData==Keys.Left)
{
Close();
return;
}
}
private void txtName_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyData==Keys.Down)
{
E.Focus(txtPass);
return;
}
if (e.KeyData==Keys.Up)
{
E.Focus(txtID);
return;
}
if (e.KeyData==Keys.Left)
{
Close();
return;
}
}
private void txtPass_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyData==Keys.Up)
{
E.Focus(txtID);
return;
}
if (e.KeyData==Keys.Left)
{
Close();
return;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -