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

📄 loginform.cs

📁 C#的图书管理系统,用ASP自己开发的系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

using System.IO;
using System.Text;
using System.Net;
using System.Diagnostics;
namespace bookmanager
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class LoginForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.TextBox password;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.TextBox username;
private string connStr = "";
		public LoginForm()
		{
			this.connStr = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + Application.StartupPath + "\\" + "DB2006.mdb";
			bookmanager.Public.connStr = this.connStr;

			Public.NewConn();
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.username = new System.Windows.Forms.TextBox();
			this.password = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(40, 32);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "登录名:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(40, 72);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(72, 16);
			this.label2.TabIndex = 1;
			this.label2.Text = "登录密码:";
			// 
			// username
			// 
			this.username.Location = new System.Drawing.Point(128, 24);
			this.username.Name = "username";
			this.username.Size = new System.Drawing.Size(88, 21);
			this.username.TabIndex = 2;
			this.username.Text = "001";
			this.username.KeyDown += new System.Windows.Forms.KeyEventHandler(this.username_KeyDown);
			this.username.Enter += new System.EventHandler(this.username_Enter);
			// 
			// password
			// 
			this.password.Location = new System.Drawing.Point(128, 64);
			this.password.Name = "password";
			this.password.PasswordChar = '*';
			this.password.Size = new System.Drawing.Size(88, 21);
			this.password.TabIndex = 3;
			this.password.Text = "8888";
			this.password.KeyDown += new System.Windows.Forms.KeyEventHandler(this.password_KeyDown);
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(72, 112);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(80, 24);
			this.button1.TabIndex = 4;
			this.button1.Text = "登录";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(176, 112);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(72, 24);
			this.button2.TabIndex = 5;
			this.button2.Text = "关闭";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// LoginForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.SystemColors.Control;
			this.ClientSize = new System.Drawing.Size(292, 150);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.password);
			this.Controls.Add(this.username);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.MaximizeBox = false;
			this.Name = "LoginForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "图书管理系统--用户登录";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new LoginForm());
		}
		/// <summary>
		/// 关闭系统
		/// </summary>
		public void ExitApp()
		{
			if(MessageBox.Show("确定关闭系统吗?","关闭确认",MessageBoxButtons.OKCancel,MessageBoxIcon.Question)  == DialogResult.OK)
			{
				Application.Exit();
			}
		}
		private void button2_Click(object sender, System.EventArgs e)
		{
			this.ExitApp();
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			if(this.username.Text.Trim() != "" && this.password.Text.Trim() != "")
			{
				try
				{
					 string sql = "select * from SInfo where username='"+ this.username.Text +"' and pwd='"+ this.password.Text +"'";
					OleDbDataAdapter adp = new OleDbDataAdapter(sql,Public.conn);
					DataSet ds           = new DataSet();
					adp.Fill(ds,"user");
					if(ds.Tables[0].Rows.Count == 1)
					{
						Public.userID = ds.Tables[0].Rows[0]["username"].ToString();
						Public.cuUser = ds.Tables[0].Rows[0]["username"].ToString();
						Public.passCH = ds.Tables[0].Rows[0]["pwd"].ToString();
					}
					else
					{
						MessageBox.Show("登录用户名或密码有误!");
						return;
					}
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.Message.ToString());
					return;
				}
			}
			else
			{
				MessageBox.Show("请输入用户名和密码!");
				return;
			}

			MainForm main =  new MainForm();
			main.Show();
			this.Visible  = false;	
		}


		private void username_Enter(object sender, System.EventArgs e)
		{
		
//		this.password.Focus();
		}

		private void username_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Enter)
			{
				SendKeys.SendWait("{TAB}");
		     }

		}

		private void password_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(e.KeyCode==Keys.Enter)
			{
				SendKeys.SendWait("{TAB}");
			}
		}
	}
}

⌨️ 快捷键说明

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