📄 登录系统.cs
字号:
namespace 毕业设计
{
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 软件系统
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class 登录 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.LinkLabel NewUser;
private System.Windows.Forms.LinkLabel PassWord;
private System.Windows.Forms.Button btnLogin;
private System.Windows.Forms.TextBox txtUser_id;
private System.Windows.Forms.TextBox txtUserpwd;
private System.Windows.Forms.Timer timer;
private System.ComponentModel.IContainer components;
OprationCard.OprationCrad Machine;
int Step=0;
bool newcard=true;
public 登录()
{
//
// 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();
this.label1 = new System.Windows.Forms.Label();
this.txtUser_id = new System.Windows.Forms.TextBox();
this.txtUserpwd = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.NewUser = new System.Windows.Forms.LinkLabel();
this.PassWord = new System.Windows.Forms.LinkLabel();
this.btnLogin = new System.Windows.Forms.Button();
this.timer = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(64, 80);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 23);
this.label1.TabIndex = 0;
this.label1.Text = "用户名";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// txtUser_id
//
this.txtUser_id.Location = new System.Drawing.Point(112, 80);
this.txtUser_id.Name = "txtUser_id";
this.txtUser_id.TabIndex = 1;
this.txtUser_id.Text = "";
//
// txtUserpwd
//
this.txtUserpwd.Location = new System.Drawing.Point(112, 136);
this.txtUserpwd.Name = "txtUserpwd";
this.txtUserpwd.PasswordChar = '*';
this.txtUserpwd.TabIndex = 2;
this.txtUserpwd.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(80, 136);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(32, 23);
this.label2.TabIndex = 3;
this.label2.Text = "密码";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label3
//
this.label3.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label3.Location = new System.Drawing.Point(0, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(296, 64);
this.label3.TabIndex = 5;
this.label3.Text = "学生体育管理系统登录";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// NewUser
//
this.NewUser.LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline;
this.NewUser.Location = new System.Drawing.Point(56, 216);
this.NewUser.Name = "NewUser";
this.NewUser.Size = new System.Drawing.Size(72, 16);
this.NewUser.TabIndex = 6;
this.NewUser.TabStop = true;
this.NewUser.Text = "新用户注册";
this.NewUser.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.NewUser_LinkClicked);
//
// PassWord
//
this.PassWord.LinkBehavior = System.Windows.Forms.LinkBehavior.NeverUnderline;
this.PassWord.Location = new System.Drawing.Point(176, 216);
this.PassWord.Name = "PassWord";
this.PassWord.Size = new System.Drawing.Size(56, 16);
this.PassWord.TabIndex = 7;
this.PassWord.TabStop = true;
this.PassWord.Text = "忘记密码";
//
// btnLogin
//
this.btnLogin.Location = new System.Drawing.Point(104, 176);
this.btnLogin.Name = "btnLogin";
this.btnLogin.TabIndex = 8;
this.btnLogin.Text = "登录";
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
//
// timer
//
this.timer.Interval = 500;
this.timer.Tick += new System.EventHandler(this.timer_Tick);
//
// Login
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.btnLogin);
this.Controls.Add(this.PassWord);
this.Controls.Add(this.NewUser);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.txtUserpwd);
this.Controls.Add(this.txtUser_id);
this.Controls.Add(this.label1);
this.Name = "Login";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "系统登录";
this.Closing += new System.ComponentModel.CancelEventHandler(this.Login_Closing);
this.Load += new System.EventHandler(this.Login_Load);
this.ResumeLayout(false);
}
#endregion
private void btnLogin_Click(object sender, System.EventArgs e)
{
毕业设计.数据处理.数据处理 o=new 毕业设计.数据处理.数据处理();
string user_id=txtUser_id.Text;
string user_pwd=txtUserpwd.Text;
string result=o.Login(user_id,user_pwd);
if(result!=null)
{
毕业设计.软件系统.主界面 oo=new 毕业设计.软件系统.主界面();
this.Hide();
this.timer.Enabled=false;
oo.userid=result;
oo.ShowDialog(this);
this.timer.Enabled=true;
this.Show();
}
else
{
txtUser_id.Text="";
txtUserpwd.Text="";
}
}
private void Login_Load(object sender, System.EventArgs e)
{
Machine=new OprationCard.OprationCrad();
Machine.port=1;
Machine.HZ=115200;
DataSet o=new DataSet();
try
{
o.ReadXml("Machine.config");
if(o.Tables[0].Rows[0][0].ToString()=="COM1")
{
Machine.port=0;
}
if(o.Tables[0].Rows[0][0].ToString()=="COM2")
{
Machine.port=1;
}
if(o.Tables[0].Rows[0][0].ToString()=="COM3")
{
Machine.port=2;
}
if(o.Tables[0].Rows[0][0].ToString()=="COM4")
{
Machine.port=3;
}
if(o.Tables[0].Rows[0][0].ToString()=="COM5")
{
Machine.port=4;
}
if(o.Tables[0].Rows[0][0].ToString()=="COM6")
{
Machine.port=5;
}
if(o.Tables[0].Rows[0][0].ToString()=="COM7")
{
Machine.port=6;
}
if(o.Tables[0].Rows[0][0].ToString()=="COM8")
{
Machine.port=7;
}
Machine.HZ=System.Convert.ToInt32(o.Tables[0].Rows[0][1].ToString());
Machine.Mode=System.Convert.ToInt32(o.Tables[0].Rows[0][3].ToString());//模式0
Machine.SecNo=System.Convert.ToInt32(o.Tables[0].Rows[0][2].ToString());//第二扇区
Machine.HZ=Convert.ToInt32(o.Tables[0].Rows[0][1].ToString());
毕业设计.射频卡.初始化状态 status=new 毕业设计.射频卡.初始化状态();
if(Machine.Init_Machine()<=0)
{
status.lbStatus.Text="设备初始化失败,请检查电源和端口!";
}
else
{
status.lbStatus.Text="设备初始化成功!";
if(Machine.SetTime(GetTime())==0)
status.lbStatus.Text+="\r\n时间设置成功!";
if(Machine.LoadKey()!=0)
status.lbStatus.Text+="\r\n载入密码失败!";
else
{
status.lbStatus.Text+="\r\n装入密码成功!";
this.timer.Enabled=true;
}
}
status.Show();
}
catch
{
MessageBox.Show("配置文件丢失,请配置程序!");
this.Dispose(true);
毕业设计.射频卡.读卡器配置 oo=new 毕业设计.射频卡.读卡器配置();
this.timer.Enabled=false;
oo.ShowDialog(this.Parent);
this.Dispose(true);
}
}
private void NewUser_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
this.Hide();
this.timer.Enabled=false;
毕业设计.软件系统.注册用户 o=new 注册用户();
o.ShowDialog(this);
this.Show();
this.timer.Enabled=true;
}
private void timer_Tick(object sender, System.EventArgs e)
{
毕业设计.射频卡.读卡结果 o=new 毕业设计.射频卡.读卡结果();
o.Title="不能识别的卡";
if(this.Step==0)
{
if(Machine.FindCard()==0)
{
if(this.newcard)
{
this.newcard=false;
this.Step=1;
}
else
this.Step=0;
}
else
{
this.newcard=true;
this.Step=0;
}
}
if(this.Step==1)
{
if(Machine.LoadKey()==0)
{
this.Step=2;
}
else
{
this.Step=0;
}
}
if(this.Step==2)
{
if(Machine.Authentication()==0)
{
// this.Text="注册卡序列号--"+Machine.CardNo.ToString();
this.Step=3;
}
else
{
this.Step=0;
o.lbCardNo.Text="卡序列号:"+Machine.CardNo.ToString();
o.lbReason.Text="密码验证失败";
this.timer.Enabled=false;
o.ShowDialog();
this.timer.Enabled=true;
}
}
if(this.Step==3)
{
byte[] Datas={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
if(Machine.Read(Datas,8)!=0)
{
this.Step=0;
// MessageBox.Show("读卡错误!!请换卡");
}
else
{
this.Step=4;
string s="";
for(int i=0;i<Datas.Length;i++)
s+=Datas[i];
int cardno=0;
for(int i=0;i<Datas.Length;i++)
{
int t=System.Convert.ToInt32(Datas[15-i]);
t-=48;
if(t>=0)
cardno=cardno*10+t;
}
毕业设计.数据处理.数据处理 oo=new 毕业设计.数据处理.数据处理();
string result=oo.Login(cardno.ToString());
if(result!=null)
{
毕业设计.软件系统.主界面 ooo=new 毕业设计.软件系统.主界面();
this.Hide();
this.timer.Enabled=false;
ooo.userid=result;
ooo.ShowDialog(this);
this.timer.Enabled=true;
this.Show();
}
else
{
txtUser_id.Text="";
txtUserpwd.Text="";
}
}
}
if(this.Step==4)
{
if(Machine.FindCard()==0&&Machine.LoadKey()==0&&Machine.Authentication()==0)
{
this.Step=4;
}
else
{
this.Step=0;
}
}
}
private void Login_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Machine.Exit_Machine();
this.timer.Enabled=false;
this.Dispose(true);
}
private byte[] GetTime()
{
毕业设计.数据处理.数据处理 o=new 毕业设计.数据处理.数据处理();
return o.GetTime();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -