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

📄 frmlogin.cs

📁 资产数据库设计
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace AdminGoods
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		public System.Windows.Forms.TextBox txtUsername;
		private System.Windows.Forms.TextBox txtPassword;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button btOK;
		private System.Windows.Forms.Button btExit;

		

		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1( )
		{
			//
			// 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.txtUsername = new System.Windows.Forms.TextBox();
			this.txtPassword = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.btOK = new System.Windows.Forms.Button();
			this.btExit = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// txtUsername
			// 
			this.txtUsername.Location = new System.Drawing.Point(112, 24);
			this.txtUsername.Name = "txtUsername";
			this.txtUsername.Size = new System.Drawing.Size(136, 21);
			this.txtUsername.TabIndex = 0;
			this.txtUsername.Text = "";
			// 
			// txtPassword
			// 
			this.txtPassword.Location = new System.Drawing.Point(112, 64);
			this.txtPassword.Name = "txtPassword";
			this.txtPassword.PasswordChar = '*';
			this.txtPassword.Size = new System.Drawing.Size(136, 21);
			this.txtPassword.TabIndex = 1;
			this.txtPassword.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 32);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(88, 16);
			this.label1.TabIndex = 2;
			this.label1.Text = "username";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(8, 64);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(88, 16);
			this.label2.TabIndex = 3;
			this.label2.Text = "password";
			// 
			// btOK
			// 
			this.btOK.Location = new System.Drawing.Point(64, 112);
			this.btOK.Name = "btOK";
			this.btOK.Size = new System.Drawing.Size(80, 24);
			this.btOK.TabIndex = 4;
			this.btOK.Text = "Login";
			this.btOK.Click += new System.EventHandler(this.btOK_Click);
			// 
			// btExit
			// 
			this.btExit.Location = new System.Drawing.Point(176, 112);
			this.btExit.Name = "btExit";
			this.btExit.Size = new System.Drawing.Size(80, 24);
			this.btExit.TabIndex = 5;
			this.btExit.Text = "Exit";
			this.btExit.Click += new System.EventHandler(this.btExit_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(292, 149);
			this.Controls.Add(this.btExit);
			this.Controls.Add(this.btOK);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.txtPassword);
			this.Controls.Add(this.txtUsername);
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		

		private void btOK_Click(object sender, System.EventArgs e)
		{
			string username = this.txtUsername.Text.Trim().ToString();
			string password = this.txtPassword.Text.Trim().ToString();

			if( this.LoginCheck(  username , password )  )
			{
				MessageBox.Show(this,"登陆成功!");

				
				
				this.Close();
			
			}
			else
			{
				MessageBox.Show(this,"登陆失败!");

				return;
			}
		}

		private bool LoginCheck(string username,string password)
		{
			

			bool login = false;
			Database db = new Database();
			try
			{
				
				System.Data.SqlClient.SqlConnection conn = db.openConn();

				System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
				cmd.CommandText = "select * from worker where username = '" + username + "' and password = '" + password + "' ";
				cmd.Connection = conn;

				System.Data.SqlClient.SqlDataReader rs = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

				while(rs.Read())
				{
					login =true;
				}
			}
			catch(Exception ex)
			{
				string msg = ex.Message ;
			}
			finally
			{
				db.closeConn ();

			}
			return login;

		}

		private void btExit_Click(object sender, System.EventArgs e)
		{
			this.txtUsername .Text = "null";

			this.Close();
		}

		
	}
}

⌨️ 快捷键说明

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