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

📄 loginfrm.cs

📁 进销存管理系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 进销存管理系统
{
	/// <summary>
	/// LoginFrm 的摘要说明。
	/// </summary>
	public class LoginFrm : System.Windows.Forms.Form
	{
		public static bool blCanLogin = false;  //记录能否检验是否通过
		public static string strUser = "";      //记录用户名
		public static string strDepartment = "";//记录通过者所属部门

		private DataSet ds = new DataSet();
		private DataTable myTable;
		private DataRow myRow;
		private string sendStrSQL = "SELECT * from 用户清单";
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button btn_Cancel;
		private System.Windows.Forms.Button btn_Login;
		private System.Windows.Forms.TextBox txt_ID;
		private System.Windows.Forms.TextBox txt_Name;
		private System.Windows.Forms.TextBox txt_Pwd;
		private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.Label LB_Warning;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

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

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
			//初始化窗体时,从数据库中的“用户清单”表中检索数据并保存在mytable中
			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()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LoginFrm));
            this.btn_Cancel = new System.Windows.Forms.Button();
            this.btn_Login = new System.Windows.Forms.Button();
            this.txt_ID = new System.Windows.Forms.TextBox();
            this.txt_Name = new System.Windows.Forms.TextBox();
            this.txt_Pwd = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.LB_Warning = new System.Windows.Forms.Label();
            this.groupBox1.SuspendLayout();
            this.SuspendLayout();
            // 
            // btn_Cancel
            // 
            this.btn_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btn_Cancel.Location = new System.Drawing.Point(158, 131);
            this.btn_Cancel.Name = "btn_Cancel";
            this.btn_Cancel.Size = new System.Drawing.Size(48, 24);
            this.btn_Cancel.TabIndex = 5;
            this.btn_Cancel.Text = "取消";
            this.btn_Cancel.Click += new System.EventHandler(this.btn_Cancel_Click);
            // 
            // btn_Login
            // 
            this.btn_Login.Location = new System.Drawing.Point(74, 131);
            this.btn_Login.Name = "btn_Login";
            this.btn_Login.Size = new System.Drawing.Size(48, 24);
            this.btn_Login.TabIndex = 4;
            this.btn_Login.Text = "登录";
            this.btn_Login.Click += new System.EventHandler(this.btn_Login_Click);
            // 
            // txt_ID
            // 
            this.txt_ID.Location = new System.Drawing.Point(104, 17);
            this.txt_ID.Name = "txt_ID";
            this.txt_ID.Size = new System.Drawing.Size(136, 21);
            this.txt_ID.TabIndex = 1;
            this.txt_ID.Leave += new System.EventHandler(this.txt_ID_Leave);
            // 
            // txt_Name
            // 
            this.txt_Name.Location = new System.Drawing.Point(104, 54);
            this.txt_Name.Name = "txt_Name";
            this.txt_Name.Size = new System.Drawing.Size(136, 21);
            this.txt_Name.TabIndex = 2;
            // 
            // txt_Pwd
            // 
            this.txt_Pwd.Location = new System.Drawing.Point(104, 94);
            this.txt_Pwd.Name = "txt_Pwd";
            this.txt_Pwd.PasswordChar = '*';
            this.txt_Pwd.Size = new System.Drawing.Size(136, 21);
            this.txt_Pwd.TabIndex = 3;
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(40, 17);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(48, 23);
            this.label1.TabIndex = 6;
            this.label1.Text = "用户号:";
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(40, 54);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(48, 23);
            this.label2.TabIndex = 7;
            this.label2.Text = "用户名:";
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(40, 94);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(40, 23);
            this.label3.TabIndex = 8;
            this.label3.Text = "密码:";
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.LB_Warning);
            this.groupBox1.Location = new System.Drawing.Point(0, 156);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(280, 32);
            this.groupBox1.TabIndex = 10;
            this.groupBox1.TabStop = false;
            // 
            // LB_Warning
            // 
            this.LB_Warning.Location = new System.Drawing.Point(54, 13);
            this.LB_Warning.Name = "LB_Warning";
            this.LB_Warning.Size = new System.Drawing.Size(172, 15);
            this.LB_Warning.TabIndex = 10;
            this.LB_Warning.Text = "初始用户号:1   密码:sys";
            this.LB_Warning.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            // 
            // LoginFrm
            // 
            this.AcceptButton = this.btn_Login;
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.CancelButton = this.btn_Cancel;
            this.ClientSize = new System.Drawing.Size(280, 189);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txt_Pwd);
            this.Controls.Add(this.txt_Name);
            this.Controls.Add(this.txt_ID);
            this.Controls.Add(this.btn_Login);
            this.Controls.Add(this.btn_Cancel);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "LoginFrm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "用户登录";
            this.groupBox1.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		//-------------根据输入的用户名和密码进行登录校验------------
		private void btn_Login_Click(object sender, System.EventArgs e)
		{
			for (int i=0;i<myTable.Rows.Count;i++)
			{
				this.myRow = myTable.Rows[i];
				//只有当输入的用户名和密码同时对应上数据库中记录时,才能通过校验
				if (myRow[0].ToString().Trim()==this.txt_ID.Text.ToString().Trim() && myRow[4].ToString().Trim()==this.txt_Pwd.Text.ToString().Trim())
				{					
					blCanLogin = true;
					strUser = myRow[0].ToString().Trim();//保存用户名
					strDepartment = myRow[1].ToString().Trim();//保存部门名称
					this.Close();//关闭窗体
					return;
				}
			}
			MessageBox.Show( "您输入的用户号或密码不正确!");
			return;
		}

		//-------关闭登录窗口,不进行任何操作-----------
		private void btn_Cancel_Click(object sender, System.EventArgs e)
		{
			blCanLogin = false;
			this.Close();
		}
        //----当鼠标离开用户号填写框,立即从数据库中检索出对于用户名称并显示----
		private void txt_ID_Leave(object sender, System.EventArgs e)
		{
			this.txt_Name.Text = "";
			for (int i=0;i<myTable.Rows.Count;i++)
			{
				this.myRow = myTable.Rows[i];
				if (myRow[0].ToString().Trim()==this.txt_ID.Text.ToString().Trim())
				{
					this.txt_Name.Text = myRow[2].ToString().Trim();
					this.txt_Pwd.Focus();
				}
			}
		}
	}
}

⌨️ 快捷键说明

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