📄 registeraccount.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Model;
using Business_Logic;
namespace Railroad_Trip
{
/// <summary>
/// RegisterAccount 的摘要说明。
/// </summary>
public class RegisterAccount : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtUserName;
private System.Windows.Forms.TextBox txtPassWord;
private System.Windows.Forms.TextBox txtAgPass;
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.RadioButton radMan;
private System.Windows.Forms.RadioButton radLady;
private System.Windows.Forms.TextBox txtAge;
private System.Windows.Forms.TextBox txtTel;
private System.Windows.Forms.TextBox txtAddress;
private int age=0; //年龄
private string userName,passWord,aPassWord,name,sex,tel,address;
private System.Windows.Forms.Label lblOK;
private System.Windows.Forms.Label lblCancel;//用户名,密码,确认密码,真实姓名,性别,联系电话,联系地址;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public RegisterAccount()
{
//
// 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(RegisterAccount));
this.txtUserName = new System.Windows.Forms.TextBox();
this.txtPassWord = new System.Windows.Forms.TextBox();
this.txtAgPass = new System.Windows.Forms.TextBox();
this.txtName = new System.Windows.Forms.TextBox();
this.radMan = new System.Windows.Forms.RadioButton();
this.radLady = new System.Windows.Forms.RadioButton();
this.txtAge = new System.Windows.Forms.TextBox();
this.txtTel = new System.Windows.Forms.TextBox();
this.txtAddress = new System.Windows.Forms.TextBox();
this.lblOK = new System.Windows.Forms.Label();
this.lblCancel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// txtUserName
//
this.txtUserName.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtUserName.Location = new System.Drawing.Point(212, 154);
this.txtUserName.Multiline = true;
this.txtUserName.Name = "txtUserName";
this.txtUserName.Size = new System.Drawing.Size(180, 18);
this.txtUserName.TabIndex = 0;
this.txtUserName.Text = "";
//
// txtPassWord
//
this.txtPassWord.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtPassWord.Location = new System.Drawing.Point(214, 206);
this.txtPassWord.Multiline = true;
this.txtPassWord.Name = "txtPassWord";
this.txtPassWord.PasswordChar = '*';
this.txtPassWord.Size = new System.Drawing.Size(168, 16);
this.txtPassWord.TabIndex = 1;
this.txtPassWord.Text = "";
//
// txtAgPass
//
this.txtAgPass.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtAgPass.Location = new System.Drawing.Point(212, 254);
this.txtAgPass.Multiline = true;
this.txtAgPass.Name = "txtAgPass";
this.txtAgPass.PasswordChar = '*';
this.txtAgPass.Size = new System.Drawing.Size(170, 18);
this.txtAgPass.TabIndex = 2;
this.txtAgPass.Text = "";
//
// txtName
//
this.txtName.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtName.Location = new System.Drawing.Point(210, 304);
this.txtName.Multiline = true;
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(130, 16);
this.txtName.TabIndex = 3;
this.txtName.Text = "";
//
// radMan
//
this.radMan.BackColor = System.Drawing.Color.Transparent;
this.radMan.Location = new System.Drawing.Point(240, 356);
this.radMan.Name = "radMan";
this.radMan.Size = new System.Drawing.Size(54, 24);
this.radMan.TabIndex = 4;
this.radMan.Text = " 男";
this.radMan.CheckedChanged += new System.EventHandler(this.radMan_CheckedChanged_1);
//
// radLady
//
this.radLady.BackColor = System.Drawing.Color.Transparent;
this.radLady.Location = new System.Drawing.Point(350, 356);
this.radLady.Name = "radLady";
this.radLady.Size = new System.Drawing.Size(58, 24);
this.radLady.TabIndex = 5;
this.radLady.Text = " 女";
this.radLady.CheckedChanged += new System.EventHandler(this.radLady_CheckedChanged_1);
//
// txtAge
//
this.txtAge.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtAge.Location = new System.Drawing.Point(212, 404);
this.txtAge.Multiline = true;
this.txtAge.Name = "txtAge";
this.txtAge.Size = new System.Drawing.Size(170, 18);
this.txtAge.TabIndex = 6;
this.txtAge.Text = "";
//
// txtTel
//
this.txtTel.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtTel.Location = new System.Drawing.Point(214, 454);
this.txtTel.Multiline = true;
this.txtTel.Name = "txtTel";
this.txtTel.Size = new System.Drawing.Size(168, 18);
this.txtTel.TabIndex = 7;
this.txtTel.Text = "";
//
// txtAddress
//
this.txtAddress.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.txtAddress.Location = new System.Drawing.Point(212, 504);
this.txtAddress.Multiline = true;
this.txtAddress.Name = "txtAddress";
this.txtAddress.Size = new System.Drawing.Size(330, 18);
this.txtAddress.TabIndex = 8;
this.txtAddress.Text = "";
//
// lblOK
//
this.lblOK.BackColor = System.Drawing.Color.Transparent;
this.lblOK.Location = new System.Drawing.Point(344, 560);
this.lblOK.Name = "lblOK";
this.lblOK.Size = new System.Drawing.Size(142, 22);
this.lblOK.TabIndex = 11;
this.lblOK.Click += new System.EventHandler(this.lblOK_Click);
//
// lblCancel
//
this.lblCancel.BackColor = System.Drawing.Color.Transparent;
this.lblCancel.Location = new System.Drawing.Point(110, 560);
this.lblCancel.Name = "lblCancel";
this.lblCancel.Size = new System.Drawing.Size(142, 22);
this.lblCancel.TabIndex = 12;
this.lblCancel.Click += new System.EventHandler(this.lblCancel_Click);
//
// RegisterAccount
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(596, 611);
this.Controls.Add(this.lblCancel);
this.Controls.Add(this.lblOK);
this.Controls.Add(this.txtAddress);
this.Controls.Add(this.txtTel);
this.Controls.Add(this.txtAge);
this.Controls.Add(this.txtName);
this.Controls.Add(this.txtAgPass);
this.Controls.Add(this.txtPassWord);
this.Controls.Add(this.txtUserName);
this.Controls.Add(this.radLady);
this.Controls.Add(this.radMan);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "RegisterAccount";
this.Text = "注册帐号";
this.ResumeLayout(false);
}
#endregion
private void radMan_CheckedChanged_1(object sender, System.EventArgs e)
{
sex="男";
}
private void radLady_CheckedChanged_1(object sender, System.EventArgs e)
{
sex="女";
}
private void lblCancel_Click(object sender, System.EventArgs e)
{
//注册取消事件
this.Dispose();
}
#region 注册提交事件
private void lblOK_Click(object sender, System.EventArgs e)
{
//注册提交事件
userName=txtUserName.Text;
passWord=txtPassWord.Text;
aPassWord=txtAgPass.Text;
name=txtName.Text;
tel=txtTel.Text;
address=txtAddress.Text;
//判断用户输入是否为空
if(userName.Length==0)
{
MessageBox.Show("用户名不能为空!","提示");
return;
}
else
{
if(userName.Length<6)
{
MessageBox.Show("用户名的长度至少为6位!只能是英文与数字!","提示");
return;
}
//判断密码输入否?
if(passWord.Length==0)
{
MessageBox.Show("密码不能为空!","提示");
return;
}
else
{
if(passWord.Length<6)
{
MessageBox.Show("密码的长度至少为6位!","提示");
return;
}
else
{}
//判断确认密码输入否?
if(aPassWord.Length==0)
{
MessageBox.Show("确认密码不能为空!","提示");
return;
}
else
{
if(aPassWord.Length<6)
{
MessageBox.Show("确认密码的长度至少为6位!","提示");
return;
}
else
{}
//判断输入的两次密码是否相同
if(passWord==aPassWord)
{
//判断真实姓名是否输入
if(name.Length==0)
{
MessageBox.Show("真实姓名不能为空!","提示");
return;
}
else
{
try
{
age=int.Parse(txtAge.Text);//要处理非数字异常
}
catch
{
MessageBox.Show("输入错误,请输入数字!","提示");
return;
}
//判断用户是否输入年龄
if(age<18)
{
MessageBox.Show("对不起,你的年龄太小无法注册!","提示");
return;
}
else
{
//判断是否输入电话
if(tel.Length==0)
{
MessageBox.Show("对不起,请输入你的联系电话!","提示");
return;
}
else
{
if(tel.Length>12||tel.Length<10)
{
MessageBox.Show("对不起,请输入电话的正确格式!\n 如 :027-5201314 或 13123456789","提示");
return;
}
else
{
//联系地址是否输入
if(address.Length==0)
{
MessageBox.Show("对不起,请输入你的联系地址!","提示");
return;
}
else
{
//传参
LoginEntity data3=new LoginEntity();
data3._UserName=userName;
data3._PassWord=aPassWord;
data3._Name=name;
data3._Sex=sex;
data3._Age=age;
data3._Tel=tel;
data3._Address=address;
Handle panduan=new Handle();
//判断用户名是否存在
if(panduan.UserNameLive(data3))
{
MessageBox.Show("该用户名已经存在,请重新注册!","提示");
//用户名存在,清空密码
txtUserName.Text="";
txtPassWord.Text="";
txtAgPass.Text="";
return;
}
else
{
//注册连到数据库
if(panduan.Registeruser(data3))
{
MessageBox.Show("注册成功!","提示");
this.Dispose();
}
else
{
MessageBox.Show("注册失败 !请稍后再试!","提示");
txtPassWord.Text="";
txtAgPass.Text="";
return;
}
}
}
}
}
}
}
}
else
{
MessageBox.Show("两次输入的密码不能相同!","提示");
return;
}
}
}
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -