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

📄 frmlogin.cs

📁 毕业生管理系统:分为六个模块:身份验证模块、毕业生资料模块,考试成绩录入模块、通信录及数据输出与系统设置模块、毕业生成绩统计模块、数据库维护模块。
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

namespace 毕业生信息管理系统
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class frmlogin : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label lblName;
		private System.Windows.Forms.Label lblPassword;
		private System.Windows.Forms.TextBox txtName;
		private System.Windows.Forms.TextBox txtPassword;
		private System.Windows.Forms.Button btnZhuce;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.Button btnClose;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private OleDbConnection objSqlConn;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ComboBox comboBox1;
		private OleDbCommand objSqlCommand;

		public frmlogin()
		{
			//
			// 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(frmlogin));
			this.lblName = new System.Windows.Forms.Label();
			this.lblPassword = new System.Windows.Forms.Label();
			this.txtName = new System.Windows.Forms.TextBox();
			this.txtPassword = new System.Windows.Forms.TextBox();
			this.btnZhuce = new System.Windows.Forms.Button();
			this.btnOK = new System.Windows.Forms.Button();
			this.btnClose = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.SuspendLayout();
			// 
			// lblName
			// 
			this.lblName.BackColor = System.Drawing.Color.Transparent;
			this.lblName.Font = new System.Drawing.Font("黑体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblName.ForeColor = System.Drawing.Color.DarkOrchid;
			this.lblName.Location = new System.Drawing.Point(72, 40);
			this.lblName.Name = "lblName";
			this.lblName.Size = new System.Drawing.Size(96, 32);
			this.lblName.TabIndex = 0;
			this.lblName.Text = "用户名:";
			// 
			// lblPassword
			// 
			this.lblPassword.BackColor = System.Drawing.Color.Transparent;
			this.lblPassword.Font = new System.Drawing.Font("黑体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblPassword.ForeColor = System.Drawing.Color.DarkOrchid;
			this.lblPassword.Location = new System.Drawing.Point(72, 96);
			this.lblPassword.Name = "lblPassword";
			this.lblPassword.Size = new System.Drawing.Size(96, 32);
			this.lblPassword.TabIndex = 1;
			this.lblPassword.Text = "密码:";
			// 
			// txtName
			// 
			this.txtName.Font = new System.Drawing.Font("黑体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtName.ForeColor = System.Drawing.Color.Blue;
			this.txtName.Location = new System.Drawing.Point(160, 40);
			this.txtName.Name = "txtName";
			this.txtName.Size = new System.Drawing.Size(160, 26);
			this.txtName.TabIndex = 2;
			this.txtName.Text = "";
			// 
			// txtPassword
			// 
			this.txtPassword.Font = new System.Drawing.Font("黑体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtPassword.ForeColor = System.Drawing.Color.Blue;
			this.txtPassword.Location = new System.Drawing.Point(160, 96);
			this.txtPassword.Name = "txtPassword";
			this.txtPassword.PasswordChar = '*';
			this.txtPassword.Size = new System.Drawing.Size(160, 26);
			this.txtPassword.TabIndex = 3;
			this.txtPassword.Text = "";
			// 
			// btnZhuce
			// 
			this.btnZhuce.BackColor = System.Drawing.Color.Transparent;
			this.btnZhuce.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnZhuce.ForeColor = System.Drawing.Color.Red;
			this.btnZhuce.Location = new System.Drawing.Point(152, 200);
			this.btnZhuce.Name = "btnZhuce";
			this.btnZhuce.Size = new System.Drawing.Size(88, 32);
			this.btnZhuce.TabIndex = 4;
			this.btnZhuce.Text = "新用户注册";
			this.btnZhuce.Click += new System.EventHandler(this.btnZhuce_Click);
			// 
			// btnOK
			// 
			this.btnOK.BackColor = System.Drawing.Color.Transparent;
			this.btnOK.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnOK.ForeColor = System.Drawing.Color.Red;
			this.btnOK.Location = new System.Drawing.Point(72, 200);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new System.Drawing.Size(72, 32);
			this.btnOK.TabIndex = 5;
			this.btnOK.Text = "确定";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// btnClose
			// 
			this.btnClose.BackColor = System.Drawing.Color.Transparent;
			this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnClose.Font = new System.Drawing.Font("黑体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnClose.ForeColor = System.Drawing.Color.Red;
			this.btnClose.Location = new System.Drawing.Point(248, 200);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new System.Drawing.Size(72, 32);
			this.btnClose.TabIndex = 6;
			this.btnClose.Text = "退出";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.Color.Transparent;
			this.label1.Font = new System.Drawing.Font("黑体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.ForeColor = System.Drawing.Color.DarkOrchid;
			this.label1.Location = new System.Drawing.Point(72, 152);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(96, 32);
			this.label1.TabIndex = 7;
			this.label1.Text = "登录方式:";
			// 
			// comboBox1
			// 
			this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.comboBox1.Font = new System.Drawing.Font("黑体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.comboBox1.ForeColor = System.Drawing.Color.Blue;
			this.comboBox1.Location = new System.Drawing.Point(160, 152);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(160, 24);
			this.comboBox1.TabIndex = 8;
			// 
			// frmlogin
			// 
			this.AcceptButton = this.btnOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.SystemColors.Control;
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.CancelButton = this.btnClose;
			this.ClientSize = new System.Drawing.Size(344, 256);
			this.Controls.Add(this.comboBox1);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.btnClose);
			this.Controls.Add(this.btnOK);
			this.Controls.Add(this.btnZhuce);
			this.Controls.Add(this.txtPassword);
			this.Controls.Add(this.txtName);
			this.Controls.Add(this.lblPassword);
			this.Controls.Add(this.lblName);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "frmlogin";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "毕业生信息管理系统";
			this.Load += new System.EventHandler(this.frmlogin_Load);
			this.ResumeLayout(false);

		}
		#endregion

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

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			MessageBox.Show("谢谢您的使用!!");
			Application.Exit();
		}

		private void btnZhuce_Click(object sender, System.EventArgs e)
		{
			frmReg objzhuce = new frmReg();
			objzhuce.Show();
		}

		private void btnOK_Click(object sender, System.EventArgs e)
		{   
			if(string.Compare(this.comboBox1.Text,"普通用户",true)==0)
			{
				user myUser = user.InitUser();
				myUser.isPublicUser = false;
				//MessageBox.Show("你是普通用户,您没有权限进行增删改查","温馨小提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				if(this.txtName.Text != "" && this.txtPassword.Text != "")
				{
					bool flag=false;
					string selCmd = "select userID,password from Users";
					objSqlCommand = new OleDbCommand(selCmd,objSqlConn);
					try
					{
						OleDbDataReader objSqlDataReader;
						objSqlConn.Open();
						objSqlDataReader =objSqlCommand.ExecuteReader();

						while (objSqlDataReader.Read())
						{
							if ((objSqlDataReader.GetValue(0).ToString()) == txtName.Text.ToString())
							{
								if (objSqlDataReader.GetValue(1).ToString() == txtPassword.Text.ToString())
								{
									flag = true;
								}
							}
						}
						objSqlConn.Close();
						if (flag)
						{
							frmMdiForm objfrmMdiForm=new frmMdiForm(this); 
							objfrmMdiForm.Show();
							this.Hide();
						}
						else
						{
							MessageBox.Show("你输入的帐号或密码不正确!");
							txtName.Text = "";
							txtPassword.Text = "";
							txtName.Focus();
						}
					}
					catch(Exception se)
					{
						MessageBox.Show(se.Message);
						objSqlConn.Close();
						this.Close();
					}
				}
				else
				{
					MessageBox.Show("请输入完整信息!");
				}
			}
			else 
			{
				if(this.txtName.Text.Equals("lican")&&this.txtPassword.Text.Equals("102245023"))
				{
					user myUser=user.InitUser();
					myUser.isPublicUser=true;
					frmMdiForm objfrmMdiForm=new frmMdiForm(this); 
					objfrmMdiForm.Show();
					this.Hide();
				}
				else
				{
					MessageBox.Show("您输入的管理员帐号或密码不正确!");
				}
			}
		} 
	
		private void frmlogin_Load(object sender, System.EventArgs e)
		{
			string strConnection="Provider=Microsoft.Jet.OLEDB.4.0;";
			strConnection+=@"Data Source=Student.mdb";
			objSqlConn=new OleDbConnection(strConnection);
			this.comboBox1.Items.Add("普通用户");
			this.comboBox1.Items.Add("超级用户");
			this.comboBox1.SelectedIndex=0;
		}
	}
}

⌨️ 快捷键说明

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