魔獸登陸系統
阿新 • • 發佈:2018-04-21
bre 信息驗證 RM message png AR new 功能實現 int32
public class LoginInfo { /// <summary> /// 用戶信息類 /// </summary> private string email; public string Email { get { return email; } set { email = value; } } private int id; public int Id {get { return id; } set { id = value; } } private string name; public string Name { get { return name; } set { name = value; } } private string password; public string Password { get { returnpassword; } set { password = value; } } }
1 /// <summary> 2 /// 用戶信息驗證及登陸功能實現 3 /// </summary> 4 /// <param name="sender"></param> 5 /// <param name="e"></param> 6 private void btnLogin_Click(object sender, EventArgs e)7 { 8 9 if (txtEmail.Text.Trim() == "" || txtPwd.Text.Trim() == "") 10 { 11 MessageBox.Show("用戶名和密碼不允許為空!"); 12 13 14 } 15 else 16 { 17 string username = txtEmail.Text; 18 string pwd = txtPwd.Text; 19 bool isOk = false; 20 foreach (LoginInfo item in array) 21 { 22 if (item != null) 23 { 24 if (item.Email == username && item.Password == pwd) 25 { 26 isOk = true; 27 FrmMain frm = new FrmMain(); 28 29 frm.lblNames.Text = "歡迎," + item.Name; 30 frm.Show(); 31 break; 32 33 } 34 } 35 } 36 if (isOk == false) 37 { 38 txtPwd.Text = ""; 39 txtEmail.Focus(); 40 } 41 } 42 43 } 44 45 private void label2_Click(object sender, EventArgs e) 46 { 47 //創建註冊窗體對象 48 FrmRegist frm = new FrmRegist(); 49 frm.fl = this; 50 frm.Show(); 51 this.Hide();//登陸隱藏窗體 52 } 53 54 private void pictureBox2_Click(object sender, EventArgs e) 55 { 56 this.Close(); 57 } 58 public LoginInfo[] array;//存儲登錄用戶信息的對象數組 59 private void FrmLogin_Load(object sender, EventArgs e) 60 { 61 //初始用戶信息 62 array = new LoginInfo[10]; 63 64 65 }
1 /// <summary> 2 /// 登陸窗體對象 3 /// </summary> 4 /// <param name="sender"></param> 5 /// <param name="e"></param> 6 private void btnMian_Click(object sender, EventArgs e) 7 { 8 LoginInfo info = new LoginInfo(); 9 info.Name = txtName.Text; 10 info.Id = Convert.ToInt32(txtMa.Text); 11 info.Email = txtEmail.Text; 12 info.Email = txtEmails.Text; 13 info.Password = txtPwd.Text; 14 info.Password = txtPwds.Text; 15 if (this.txtName.Text.Trim()=="") 16 { 17 MessageBox.Show("信息不能為空!"); 18 this.txtName.Focus(); 19 20 } 21 else if (this.txtMa.Text.Trim() == "") 22 { 23 MessageBox.Show("信息不能為空!"); 24 this.txtMa.Focus(); 25 26 } 27 else if (this.txtEmail.Text.Trim() == "") 28 { 29 MessageBox.Show("信息不能為空!"); 30 this.txtEmail.Focus(); 31 32 } 33 else if (this.txtEmails.Text.Trim() == "") 34 { 35 MessageBox.Show("信息不能為空!"); 36 this.txtEmails.Focus(); 37 38 } 39 else if (this.txtPwd.Text.Trim() == "") 40 { 41 MessageBox.Show("信息不能為空!"); 42 this.txtPwd.Focus(); 43 44 } 45 else if (this.txtPwds.Text.Trim() == "") 46 { 47 MessageBox.Show("信息不能為空!"); 48 this.txtPwd.Focus(); 49 50 } 51 else 52 { 53 MessageBox.Show("註冊成功!"); 54 for (int i = 0; i < fl.array.Length; i++) 55 { 56 if(fl.array[i]==null) 57 { 58 fl.array[i] = info; 59 break; 60 } 61 } 62 63 fl.Visible = true; 64 this.Close(); 65 } 66 67 68 }
魔獸登陸系統