using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class FrmLogin : Form { public FrmLogin() { InitializeComponent(); } public LoginInfo[] array; //用于存储登录用户的信息 //定义长度为10的110数组 // public LoginInfo[] persons = new LoginInfo[10]; private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "") { MessageBox.Show("邮箱或密码不能为空!", "提示"); } else { string userName = textBox1.Text; string pwd = textBox2.Text; bool isOK = false; foreach (LoginInfo item in array) { if (item != null) { if (item.Email == userName && item.Password == pwd) { // lblValidation.Visible = false; isOK = true; FrmMain fm = new FrmMain(); // fm.lblName.Text = "欢迎," + item.Name;//将信息传递到主页面 fm.Show(); break; } } } if (isOK == false) { // lblValidation.Visible = true; textBox2.Text = ""; textBox2.Focus(); } } } private void FrmLogin_Load(object sender, EventArgs e) { //初始三个用户信息 array = new LoginInfo[10]; LoginInfo info1 = new LoginInfo(); info1.Name = "孙丽丽"; info1.Id = "120185198005088521"; info1.Email = "lili@sohu.com"; info1.Password = "lili1980"; array[0] = info1; LoginInfo info2 = new LoginInfo(); info2.Name = "范晶晶"; info2.Id = "110186198111088725"; info2.Email = "jingjing@sina.com"; info2.Password = "jingjing"; array[1] = info2; LoginInfo info3 = new LoginInfo(); info3.Name = "陈小坤"; info3.Id = "110125197905123571"; info3.Email = "xiaokun@sohu.com"; info3.Password = "chenkun"; array[2] = info3; // lblValidation.Visible = false;//初始时将验证提示信息隐藏 } private void label4_Click(object sender, EventArgs e) { FrmRegist fr = new FrmRegist(); fr.fl = this; fr.Show(); this.Hide();//登录窗体隐藏 } private void label3_Click(object sender, EventArgs e) { } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class FrmRegist : Form { public FrmRegist() { InitializeComponent(); } public FrmLogin fl;//登录窗体对象 private void label1_Click(object sender, EventArgs e) { } private void textBox1_TextChanged(object sender, EventArgs e) { } private void textBox2_TextChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { if (txtName.Text.Trim() == "" || txtId.Text.Trim() == "" || txtName.Text.Trim() == "" || txtReEmail.Text.Trim() == "" || txtId.Text.Trim() == "" || txtRePwd.Text.Trim() == "") { return; } bool isOK = true; LoginInfo info = new LoginInfo(); info.Name = txtName.Text; info.Id = txtId.Text; if (txtName.Text == txtReEmail.Text) { info.Email = txtName.Text; } else { isOK = false; } if (txtId.Text == txtRePwd.Text) { info.Password = txtId.Text; isOK = true; } else { isOK = false; // lblEqualPwd.Visible = true; } if (isOK) { MessageBox.Show("恭喜,通过验证!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //找到数组中空闲的位置,将注册成功的对象传入 for (int i = 0; i < fl.array.Length; i++) { if (fl.array[i] == null) { fl.array[i] = info; break; } } fl.Visible = true; this.Close(); } } private void FrmRegist_Load(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { } private void pictureBox1_Click(object sender, EventArgs e) { } } }