using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace FrmLogin
{
public partial class FrmLogin : Form
{
public FrmLogin()
{
InitializeComponent();
}
//存储登录用户信息的对象数组
public LoginInfo[] array = new LoginInfo[10];
private void FrmLogin_Load(object sender, EventArgs e)
{
}
public void show()
{
LoginInfo l = new LoginInfo();
l.Email = "lili@show.com";
l.ID = "111";
l.Name = "孙丽丽";
l.Password = "123";
array[0] = l;
//两种方式
//array[1] = new LoginInfo();
//array[1].Name = "王";
}
private void button1_Click(object sender, EventArgs e)
{
if (this.textBox1.Text.Trim()==""||this.textBox1.Text.Trim()=="")
{
MessageBox.Show("用户或密码不能为空");
}
else
{
string name = textBox1.Text;
string pwd = textBox2.Text;
foreach (LoginInfo item in array)
{
if (item.Email!=name||item.Password!=pwd)
{
MessageBox.Show("用户名或密码不正确请重新输入!");
//清空文本的方法
foreach (Control item1 in this.Controls)
{
if (item1 is TextBox)
{
item1.Text = "";
}
}
return;
}
else if (item.Email == name && item.Password == pwd)
{
// button1.Visible = false;
FrmMain fm = new FrmMain();
fm.textBox1.Text = "欢迎你" + item.Name;
fm.Show();
//窗体隐藏
this.Hide();
break;
}
}
}
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
FrmRegist fr = new FrmRegist();
fr.f1 = this;
fr.Show();
//登录窗体隐藏
this.Hide();
}
}
}
这是登录窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace FrmLogin
{
public partial class FrmRegist : Form
{
public FrmRegist()
{
InitializeComponent();
}
public FrmLogin f1;
private void FrmRegist_Load(object sender, EventArgs e)
{
}
private void NewMethod()
{
LoginInfo l = new LoginInfo();
if (this.textBox1.Text == "")
{
MessageBox.Show("姓名不能为空", "提示");
this.textBox1.Focus();
return;
}
else if (this.textBox2.Text == "")
{
MessageBox.Show("身份证号码不能为空", "提示");
this.textBox2.Focus();
return;
}
else if (this.textBox3.Text == ""||this.textBox5.Text=="")
{
MessageBox.Show("邮箱地址不能为空", "提示");
this.textBox3.Focus();
this.textBox5.Focus();
return;
}
else if (this.textBox4.Text == ""||this.textBox6.Text=="")
{
MessageBox.Show("密码不能为空", "提示");
this.textBox4.Focus();
this.textBox6.Focus();
return;
}
else
{
l.Name = this.textBox1.Text;
l.ID = this.textBox2.Text;
l.Email = this.textBox3.Text;
l.Password = this.textBox4.Text;
MessageBox.Show("恭喜,通过验证", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
for (int i = 0; i < f1.array.Length; i++)
{
if (f1.array[i] == null)
{
f1.array[i] = l;
break;
}
}
f1.Visible = true;
this.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
NewMethod();
}
private void button2_Click(object sender, EventArgs e)
{
foreach (Control item in this.Controls)
{
if (item is TextBox)
{
item.Text = "";
}
}
}
}
}