⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginfrm.cs

📁 用C#开发的教师签到系统 具有基本功能
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

namespace 教师签到系统
{
	/// <summary>
	/// LoginFrm 的摘要说明。
	/// </summary>
	public class LoginFrm : System.Windows.Forms.Form
	{
		public static bool blCanLogin = false;//记录能否检验是否通过
		public static string strUser = "";//记录用户名
		private DataSet ds = new DataSet();
		private System.Data.DataTable myTable;
		private DataRow myRow;
		private string sendStrSQL = "SELECT * from 管理员表";

		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.Button btnLonin;
		private System.Windows.Forms.Button btnCancel;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public LoginFrm()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
			LinkDataBase link = new LinkDataBase();
			string sendTableName = "管理员表";
			this.ds = link.SelectDataBAse(sendStrSQL,sendTableName);
			this.myTable = ds.Tables[0];
		}

		/// <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.label1 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.btnLonin = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 32);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "管理员编号";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(8, 72);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(64, 23);
			this.label3.TabIndex = 2;
			this.label3.Text = "密码";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(88, 32);
			this.textBox1.Name = "textBox1";
			this.textBox1.TabIndex = 3;
			this.textBox1.Text = "";
			this.textBox1.Leave += new System.EventHandler(this.textBox1_Leave);
			// 
			// textBox2
			// 
			this.textBox2.Location = new System.Drawing.Point(88, 72);
			this.textBox2.Name = "textBox2";
			this.textBox2.PasswordChar = '*';
			this.textBox2.TabIndex = 4;
			this.textBox2.Text = "";
			// 
			// btnLonin
			// 
			this.btnLonin.Location = new System.Drawing.Point(40, 128);
			this.btnLonin.Name = "btnLonin";
			this.btnLonin.Size = new System.Drawing.Size(56, 23);
			this.btnLonin.TabIndex = 5;
			this.btnLonin.Text = "登陆";
			this.btnLonin.Click += new System.EventHandler(this.btnLonin_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(128, 128);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(56, 23);
			this.btnCancel.TabIndex = 6;
			this.btnCancel.Text = "取消";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// LoginFrm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(224, 174);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnLonin);
			this.Controls.Add(this.textBox2);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "LoginFrm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "登陆";
			this.ResumeLayout(false);

		}
		#endregion

		private void btnLonin_Click(object sender, System.EventArgs e)
		{
			if(this.textBox1.Text=="")
			{
				MessageBox.Show("用户名不能为空");
				return;
			}
			if(this.textBox2.Text=="")
			{
				MessageBox.Show("密码不能为空");
                return;
			}
			for(int i=0;i< this.myTable.Rows.Count;i++)
			{
				this.myRow = myTable.Rows[i];
				//只有当输入的用户名和密码同时对应数据库中记录时,才能通过校验
				if(myRow[0].ToString().Trim()==this.textBox1.Text.ToString().Trim()&&
					myRow[2].ToString().Trim()==this.textBox2.Text.ToString().Trim())
				{
					blCanLogin = true;
					strUser = myRow[0].ToString().Trim();//保存用户名
					MessageBox.Show("登陆成功");
					this.Close();
					return;
				}
			}
			MessageBox.Show("你输入的用户号或密码不正确!");
			this.textBox1.Clear();
			this.textBox2.Clear();
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			blCanLogin = false;
			this.Close();
		}

		private void textBox1_Leave(object sender, System.EventArgs e)
		{
			this.textBox2.Text = "";
			for(int i=0;i<myTable.Rows.Count;i++)
			{
				this.myRow = myTable.Rows[i];
				if(myRow[0].ToString().Trim()==this.textBox1.Text.ToString ().Trim())
				{
					this.textBox2.Focus();
				}
			}
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -