?? 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 + -