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

📄 frmreg.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>
	/// frmzhuce 的摘要说明。
	/// </summary>
	public class frmReg : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnClose;
		private System.Windows.Forms.Button btnOK;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Label lblName;
		private System.Windows.Forms.Label lblPassword;
		private System.Windows.Forms.Label lblPassword2;
		private System.Windows.Forms.Label lblEmail;
		private System.Windows.Forms.TextBox txtName;
		private System.Windows.Forms.TextBox txtPassword;
		private System.Windows.Forms.TextBox txtPassword2;
		private System.Windows.Forms.TextBox txtEmail;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private OleDbConnection objSqlConn;
		private System.Windows.Forms.Button btncheck;
		private OleDbCommand objSqlCommand;

		public frmReg()
		{
			//
			// 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(frmReg));
			this.btnClose = new System.Windows.Forms.Button();
			this.btnOK = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.lblName = new System.Windows.Forms.Label();
			this.lblPassword = new System.Windows.Forms.Label();
			this.lblPassword2 = new System.Windows.Forms.Label();
			this.lblEmail = new System.Windows.Forms.Label();
			this.txtName = new System.Windows.Forms.TextBox();
			this.txtPassword = new System.Windows.Forms.TextBox();
			this.txtPassword2 = new System.Windows.Forms.TextBox();
			this.txtEmail = new System.Windows.Forms.TextBox();
			this.btncheck = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// btnClose
			// 
			this.btnClose.BackColor = System.Drawing.Color.Transparent;
			this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnClose.Font = new System.Drawing.Font("黑体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnClose.ForeColor = System.Drawing.Color.Magenta;
			this.btnClose.Location = new System.Drawing.Point(256, 304);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new System.Drawing.Size(80, 32);
			this.btnClose.TabIndex = 0;
			this.btnClose.Text = "退出";
			this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
			// 
			// btnOK
			// 
			this.btnOK.BackColor = System.Drawing.Color.Transparent;
			this.btnOK.Font = new System.Drawing.Font("黑体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btnOK.ForeColor = System.Drawing.Color.Magenta;
			this.btnOK.Location = new System.Drawing.Point(16, 304);
			this.btnOK.Name = "btnOK";
			this.btnOK.Size = new System.Drawing.Size(80, 32);
			this.btnOK.TabIndex = 1;
			this.btnOK.Text = "确定";
			this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
			// 
			// button2
			// 
			this.button2.BackColor = System.Drawing.Color.Transparent;
			this.button2.Font = new System.Drawing.Font("黑体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.button2.ForeColor = System.Drawing.Color.Magenta;
			this.button2.Location = new System.Drawing.Point(136, 304);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(80, 32);
			this.button2.TabIndex = 2;
			this.button2.Text = "重置";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// 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.Blue;
			this.lblName.Location = new System.Drawing.Point(24, 80);
			this.lblName.Name = "lblName";
			this.lblName.Size = new System.Drawing.Size(96, 32);
			this.lblName.TabIndex = 3;
			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.Blue;
			this.lblPassword.Location = new System.Drawing.Point(24, 136);
			this.lblPassword.Name = "lblPassword";
			this.lblPassword.Size = new System.Drawing.Size(96, 32);
			this.lblPassword.TabIndex = 4;
			this.lblPassword.Text = "密码:";
			// 
			// lblPassword2
			// 
			this.lblPassword2.BackColor = System.Drawing.Color.Transparent;
			this.lblPassword2.Font = new System.Drawing.Font("华文中宋", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblPassword2.ForeColor = System.Drawing.Color.Blue;
			this.lblPassword2.Location = new System.Drawing.Point(24, 184);
			this.lblPassword2.Name = "lblPassword2";
			this.lblPassword2.Size = new System.Drawing.Size(96, 32);
			this.lblPassword2.TabIndex = 5;
			this.lblPassword2.Text = "再次输入:";
			// 
			// lblEmail
			// 
			this.lblEmail.BackColor = System.Drawing.Color.Transparent;
			this.lblEmail.Font = new System.Drawing.Font("华文中宋", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.lblEmail.ForeColor = System.Drawing.Color.Blue;
			this.lblEmail.Location = new System.Drawing.Point(24, 240);
			this.lblEmail.Name = "lblEmail";
			this.lblEmail.Size = new System.Drawing.Size(96, 32);
			this.lblEmail.TabIndex = 6;
			this.lblEmail.Text = "Email:";
			// 
			// txtName
			// 
			this.txtName.Font = new System.Drawing.Font("楷体_GB2312", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtName.Location = new System.Drawing.Point(120, 80);
			this.txtName.Name = "txtName";
			this.txtName.Size = new System.Drawing.Size(128, 26);
			this.txtName.TabIndex = 7;
			this.txtName.Text = "";
			// 
			// txtPassword
			// 
			this.txtPassword.Font = new System.Drawing.Font("楷体_GB2312", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtPassword.Location = new System.Drawing.Point(120, 133);
			this.txtPassword.Name = "txtPassword";
			this.txtPassword.PasswordChar = '*';
			this.txtPassword.Size = new System.Drawing.Size(224, 26);
			this.txtPassword.TabIndex = 8;
			this.txtPassword.Text = "";
			// 
			// txtPassword2
			// 
			this.txtPassword2.Font = new System.Drawing.Font("楷体_GB2312", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtPassword2.Location = new System.Drawing.Point(120, 186);
			this.txtPassword2.Name = "txtPassword2";
			this.txtPassword2.PasswordChar = '*';
			this.txtPassword2.Size = new System.Drawing.Size(224, 26);
			this.txtPassword2.TabIndex = 9;
			this.txtPassword2.Text = "";
			// 
			// txtEmail
			// 
			this.txtEmail.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.txtEmail.Location = new System.Drawing.Point(120, 239);
			this.txtEmail.Name = "txtEmail";
			this.txtEmail.Size = new System.Drawing.Size(224, 26);
			this.txtEmail.TabIndex = 10;
			this.txtEmail.Text = "";
			// 
			// btncheck
			// 
			this.btncheck.BackColor = System.Drawing.Color.Transparent;
			this.btncheck.Font = new System.Drawing.Font("楷体_GB2312", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.btncheck.ForeColor = System.Drawing.Color.Red;
			this.btncheck.Location = new System.Drawing.Point(264, 80);
			this.btncheck.Name = "btncheck";
			this.btncheck.Size = new System.Drawing.Size(80, 32);
			this.btncheck.TabIndex = 11;
			this.btncheck.Text = "检测用户";
			this.btncheck.Click += new System.EventHandler(this.btncheck_Click);
			// 
			// frmReg
			// 
			this.AcceptButton = this.btnOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.CancelButton = this.btnClose;
			this.ClientSize = new System.Drawing.Size(376, 380);
			this.Controls.Add(this.btncheck);
			this.Controls.Add(this.txtEmail);
			this.Controls.Add(this.txtPassword2);
			this.Controls.Add(this.txtPassword);
			this.Controls.Add(this.txtName);
			this.Controls.Add(this.lblEmail);
			this.Controls.Add(this.lblPassword2);
			this.Controls.Add(this.lblPassword);
			this.Controls.Add(this.lblName);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.btnOK);
			this.Controls.Add(this.btnClose);
			this.ForeColor = System.Drawing.SystemColors.ControlText;
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "frmReg";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "新用户注册";
			this.Load += new System.EventHandler(this.frmReg_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			MessageBox.Show("为保障用户的安全,请重新登陆!");
			frmlogin objlogin = new frmlogin();
			objlogin.Show();
			this.Close();
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			txtName.Clear();
			txtPassword.Clear();
			txtPassword2.Clear();
			txtEmail.Clear();
		}

		private void btnOK_Click(object sender, System.EventArgs e)
		{
			if(this.txtName.Text != "" && this.txtPassword.Text != "" && this.txtPassword2.Text != "")
			{
				bool flag=false;
				string selCmd = "select userID 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())
						{
							flag = true;
						}
					}
					objSqlConn.Close();
					if (flag)
					{
						MessageBox.Show("你输入的用户名已存在!");
						txtName.Text = "";
						txtPassword.Text = "";
						txtPassword2.Text = "";
						txtEmail.Text = "";
						txtName.Focus();
					}
					else
					{
						if(this.txtPassword.Text.ToString() == this.txtPassword2.Text.ToString())
						{
							if(txtEmail.Text == ""|| txtEmail.Text.IndexOf("@") < 0||txtEmail.Text.IndexOf("@")>txtEmail.Text.IndexOf("."))
							{
								MessageBox.Show("Email输入错误或者格式错误!");
							}
							else
							{
								string insCmd="insert into Users values ('"+this.txtName.Text+"','"+this.txtPassword.Text+"','"+this.txtEmail.Text+"')";
								objSqlCommand=new OleDbCommand(insCmd,objSqlConn);
								try
								{
									objSqlConn.Open();
									objSqlCommand.ExecuteNonQuery();
									MessageBox.Show("注册成功,请返回登录!");
									this.Close();
								}
								catch(OleDbException ex)
								{
									MessageBox.Show(ex.Message);
								}
								finally
								{
									objSqlConn.Close();
								}
							}
						}
						else
						{
							MessageBox.Show("密码跟确认密码不一致!");
						}
					}
				}
				catch(Exception se)
				{
					MessageBox.Show(se.Message);
					objSqlConn.Close();
					this.Close();
				}
			}
			else
			{
				MessageBox.Show("请输入完整信息!");
			}
		}

		private void frmReg_Load(object sender, System.EventArgs e)
		{
			string strConnection="Provider=Microsoft.Jet.OLEDB.4.0;";
			strConnection+=@"Data Source=Student.mdb";
			objSqlConn=new OleDbConnection(strConnection);
		}

		private void btncheck_Click(object sender, System.EventArgs e)
		{
			if(this.txtName.Text != "")
			{
				bool flag=false;
				string selCmd = "select userID 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())
						{
							flag = true;
						}
					}
					objSqlConn.Close();
					if (flag)
					{
						MessageBox.Show("你输入的用户名已存在!");
						txtName.Clear();
					}	
					else
					{
						MessageBox.Show("此用户名可以放心使用!");
					
					}
					try
					{
						objSqlConn.Open();
						objSqlCommand.ExecuteNonQuery();
						
						
					}
					catch(OleDbException ex)
					{
						MessageBox.Show(ex.Message);
					}
					finally
					{
						objSqlConn.Close();
					}
				}
				
				catch(Exception se)
				{
					MessageBox.Show(se.Message);
					objSqlConn.Close();
					this.Close();
				}
			}
		}
	}
}
					

⌨️ 快捷键说明

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