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

📄 login.cs

📁 c#和sql 图管理系统简单模式 老师做的给大家参考了
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
using Library.UserInterface;
namespace Library
{
	/// <summary>
	/// Login 的摘要说明。
	/// </summary>
	public class Login : System.Windows.Forms.Form
	{
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.Windows.Forms.PictureBox pictureBox2;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.TextBox textUserID;
		private System.Windows.Forms.TextBox textUserPassword;
		private System.Windows.Forms.Button btnOk;
		private System.Data.SqlClient.SqlConnection sqlConnection1;
		private System.Windows.Forms.Label lblUser;
		private System.Windows.Forms.Label lblPassword;
		private System.Windows.Forms.Label lbltitle;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Login()
		{
			//
			// 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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Login));
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.lblUser = new System.Windows.Forms.Label();
			this.lblPassword = new System.Windows.Forms.Label();
			this.btnCancel = new System.Windows.Forms.Button();
			this.textUserID = new System.Windows.Forms.TextBox();
			this.textUserPassword = new System.Windows.Forms.TextBox();
			this.btnOk = new System.Windows.Forms.Button();
			this.pictureBox2 = new System.Windows.Forms.PictureBox();
			this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
			this.lbltitle = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// pictureBox1
			// 
			this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
			this.pictureBox1.Location = new System.Drawing.Point(0, 88);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(56, 72);
			this.pictureBox1.TabIndex = 0;
			this.pictureBox1.TabStop = false;
			this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click);
			// 
			// lblUser
			// 
			this.lblUser.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblUser.Location = new System.Drawing.Point(72, 88);
			this.lblUser.Name = "lblUser";
			this.lblUser.Size = new System.Drawing.Size(56, 23);
			this.lblUser.TabIndex = 1;
			this.lblUser.Text = "用户";
			// 
			// lblPassword
			// 
			this.lblPassword.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblPassword.Location = new System.Drawing.Point(72, 136);
			this.lblPassword.Name = "lblPassword";
			this.lblPassword.Size = new System.Drawing.Size(56, 23);
			this.lblPassword.TabIndex = 2;
			this.lblPassword.Text = "密码";
			// 
			// btnCancel
			// 
			this.btnCancel.Image = ((System.Drawing.Image)(resources.GetObject("btnCancel.Image")));
			this.btnCancel.Location = new System.Drawing.Point(200, 192);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(64, 24);
			this.btnCancel.TabIndex = 3;
			this.btnCancel.Text = "取消";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// textUserID
			// 
			this.textUserID.Location = new System.Drawing.Point(136, 88);
			this.textUserID.Name = "textUserID";
			this.textUserID.Size = new System.Drawing.Size(96, 21);
			this.textUserID.TabIndex = 0;
			this.textUserID.Text = "";
			// 
			// textUserPassword
			// 
			this.textUserPassword.Location = new System.Drawing.Point(136, 136);
			this.textUserPassword.Name = "textUserPassword";
			this.textUserPassword.PasswordChar = '*';
			this.textUserPassword.Size = new System.Drawing.Size(96, 21);
			this.textUserPassword.TabIndex = 1;
			this.textUserPassword.Text = "";
			// 
			// btnOk
			// 
			this.btnOk.Image = ((System.Drawing.Image)(resources.GetObject("btnOk.Image")));
			this.btnOk.Location = new System.Drawing.Point(96, 192);
			this.btnOk.Name = "btnOk";
			this.btnOk.Size = new System.Drawing.Size(64, 24);
			this.btnOk.TabIndex = 6;
			this.btnOk.Text = "确定";
			this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
			// 
			// pictureBox2
			// 
			this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
			this.pictureBox2.Location = new System.Drawing.Point(0, 0);
			this.pictureBox2.Name = "pictureBox2";
			this.pictureBox2.Size = new System.Drawing.Size(400, 50);
			this.pictureBox2.TabIndex = 7;
			this.pictureBox2.TabStop = false;
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "workstation id=localhost;packet size=4096;integrated security=SSPI;data source=lo" +
				"calhost;persist security info=False;initial catalog=BookManager";
			// 
			// lbltitle
			// 
			this.lbltitle.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lbltitle.Location = new System.Drawing.Point(120, 48);
			this.lbltitle.Name = "lbltitle";
			this.lbltitle.Size = new System.Drawing.Size(96, 23);
			this.lbltitle.TabIndex = 8;
			this.lbltitle.Text = "登录系统";
			// 
			// Login
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(320, 253);
			this.Controls.Add(this.lbltitle);
			this.Controls.Add(this.pictureBox2);
			this.Controls.Add(this.btnOk);
			this.Controls.Add(this.textUserPassword);
			this.Controls.Add(this.textUserID);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.lblPassword);
			this.Controls.Add(this.lblUser);
			this.Controls.Add(this.pictureBox1);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "Login";
			this.Text = "图书馆管理系统";
			this.Load += new System.EventHandler(this.Login_Load);
			this.ResumeLayout(false);

		}
		#endregion

		static void Main() 
		{
			Application.Run(new Login());
		}
		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.textUserID.Text="";
			this.textUserPassword.Text="";
		}

		private void btnOk_Click(object sender, System.EventArgs e)
		{	
			if(UserCheck(this.textUserID.Text,this.textUserPassword.Text)=="system")
			{
				
				this.Visible=false;
				Form mainform=new MainForm(this.textUserID.Text,"system");
				mainform.ShowDialog();
				this.Close();
			}
			else if(UserCheck(this.textUserID.Text,this.textUserPassword.Text)=="user")
			{
				this.Visible=false;
				Form mainform=new MainForm(this.textUserID.Text,"user");
				mainform.ShowDialog();				
				this.Close();
				
			}
			else
			{
				if(MessageBox.Show("输入用户密码有误,是否重新登陆","输入有误",MessageBoxButtons.OKCancel,MessageBoxIcon.Question)==DialogResult.OK)
				{
					this.textUserID.Clear();
					this.textUserPassword.Clear();
					//this.textUserID.();
				}
				else
				{
					this.Close();
				}
			}
		}
		
		string UserCheck(string username,string userpassword)
		{
			string txtSql,usersort;	
			usersort="nobody";
			//txtSql = "select count(*) from User where UserID="+this.textUserID.Text+" and UserPassword="+this.textUserPassword.Text;
			txtSql = "SELECT * FROM [User]";
//			txtSql = "SELECT * FROM ManagerUser";
			SqlCommand checkuser=new SqlCommand(txtSql,this.sqlConnection1);
			try
			{
				this.sqlConnection1.Open();
				SqlDataReader sqlreader=checkuser.ExecuteReader();
				while(sqlreader.Read())
				{	
					if((sqlreader[0].ToString().Trim()==username)&&(sqlreader[1].ToString().Trim()==userpassword))
					{						
						usersort=sqlreader[2].ToString().Trim();
						//this.sqlConnection1.Close();
						break;						
					}
				}		
			}
			catch(Exception e)
			{
				//Console.WriteLine(e.ToString());
				MessageBox.Show(e.ToString());
			}			
			   sqlConnection1.Close();	
			   //return "nobody";	
			  return usersort;
		}

		private void Login_Load(object sender, System.EventArgs e)
		{
			//this.sqlConnection1.Open();
			//this.sqlDataAdapter1.Fill(this.dataSetUser1);
		}

		private void pictureBox1_Click(object sender, System.EventArgs e)
		{
		
		}


	}
}

⌨️ 快捷键说明

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