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

📄 login.cs

📁 学生管理系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace chaxun
{
	/// <summary>
	/// login 的摘要说明。
	/// </summary>
	public class login : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.Button btnCN;

		string Scon=@"Integrated Security=SSPI;Initial Catalog=xxgcx;Data Source=.";
		//,Connection Timeout = 120,Max Pool Size = 5
		/// <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()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.btnOK = new System.Windows.Forms.Button();
			this.btnCN = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("楷体_GB2312", 13.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.ForeColor = System.Drawing.SystemColors.InfoText;
			this.label1.Location = new System.Drawing.Point(90, 124);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(102, 32);
			this.label1.TabIndex = 0;
			this.label1.Text = "用户名:";
			// 
			// label2
			// 
			this.label2.Font = new System.Drawing.Font("楷体_GB2312", 13.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label2.ForeColor = System.Drawing.SystemColors.InfoText;
			this.label2.Location = new System.Drawing.Point(90, 174);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(84, 31);
			this.label2.TabIndex = 1;
			this.label2.Text = "密  码:";
			// 
			// textBox1
			// 
			this.textBox1.BackColor = System.Drawing.Color.White;
			this.textBox1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.textBox1.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.textBox1.Location = new System.Drawing.Point(222, 131);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(90, 26);
			this.textBox1.TabIndex = 2;
			this.textBox1.Text = "";
			// 
			// textBox2
			// 
			this.textBox2.BackColor = System.Drawing.Color.White;
			this.textBox2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.textBox2.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.textBox2.Location = new System.Drawing.Point(222, 180);
			this.textBox2.Name = "textBox2";
			this.textBox2.PasswordChar = '*';
			this.textBox2.Size = new System.Drawing.Size(90, 26);
			this.textBox2.TabIndex = 3;
			this.textBox2.Text = "";
			// 
			// btnOK
			// 
			this.btnOK.Font = new System.Drawing.Font("楷体_GB2312", 13.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnOK.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.btnOK.Location = new System.Drawing.Point(108, 218);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new System.Drawing.Size(72, 37);
			this.btnOK.TabIndex = 4;
			this.btnOK.Text = "确定";
			this.btnOK.Click += new System.EventHandler(this.button1_Click);
			// 
			// btnCN
			// 
			this.btnCN.Font = new System.Drawing.Font("楷体_GB2312", 13.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnCN.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
			this.btnCN.Location = new System.Drawing.Point(222, 218);
			this.btnCN.Name = "btnCN";
			this.btnCN.Size = new System.Drawing.Size(72, 37);
			this.btnCN.TabIndex = 5;
			this.btnCN.Text = "退出";
			this.btnCN.Click += new System.EventHandler(this.btnCN_Click);
			// 
			// login
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.Gainsboro;
			this.ClientSize = new System.Drawing.Size(424, 304);
			this.ControlBox = false;
			this.Controls.Add(this.btnCN);
			this.Controls.Add(this.btnOK);
			this.Controls.Add(this.textBox2);
			this.Controls.Add(this.textBox1);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
			this.MaximizeBox = false;
			this.Name = "login";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Load += new System.EventHandler(this.login_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		/// 
		
		public static string user_name,user_level;
		[STAThread]
		static void Main() 
		{
			Application.Run(new login());
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			if(this.textBox1.Text=="")
			{
				MessageBox.Show("用户名不能为空");
				this.textBox1.Focus();
				return;
			}
			else if(this.textBox2.Text=="")
			{
				MessageBox.Show("密码不能为空");
				this.textBox2.Focus();
				return;
			}
			else
			{
				string commandstring=@"select * from student where xh = '"+this.textBox1.Text.Trim()+"' and mm = '"+this.textBox2.Text.Trim()+"' ";
				SqlDataAdapter sql=new SqlDataAdapter(commandstring,Scon);
				DataSet ds=new DataSet();
				try
				{
					sql.Fill(ds,"operator");

				}
				catch(Exception e1)
				{
				MessageBox.Show(e1.Message);
				}
				int h = ds.Tables[0].Rows.Count;
				if(h==0)
				{
					MessageBox.Show("用户名和密码错误,请重新输入");
					textBox1.Text=this.textBox2.Text="";
					textBox1.Focus();
					return;
				}
				else
				{
					user_name = ds.Tables[0].Rows[0][2].ToString();
					user_level = ds.Tables[0].Rows[0][11].ToString();
				    Main_info mi = new Main_info();
					this.Hide();
					mi.Show();

				}
	        }
		
		}

		private void btnCN_Click(object sender, System.EventArgs e)
		{
			Application.Exit();
		}

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

⌨️ 快捷键说明

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