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 LoginInfo[] array;
public FrmLogin()
{
InitializeComponent();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
FrmRegist fr = new FrmRegist();
fr.Show();
}
private void FrmLogin_Load(object sender, EventArgs e)
{
array=new LoginInfo[10];
LoginInfo info1 = new LoginInfo();
info1.Name = "孙丽丽";
info1.Id = "120185198005088521";
info1.Email = "lili@;
info1.Password="lili1980";
array[0] = info1;
LoginInfo info2 = new LoginInfo();
info2.Name = "郑福疆";
info2.Id = "120185198005088522";
info2.Email = "fujiang@;
info2.Password = "fujiang1997";
array[1] = info2;
LoginInfo info3 = new LoginInfo();
info3.Name = "罗鹏";
info3.Id ="120185199601068522";
info3.Email = "luopeng@;
info3.Password = "luopeng1996";
array[2] = info3;
}
private void btnLogin_Click(object sender, EventArgs e)
{
if (txtEmail.Text.Trim() == "" || txtpwd.Text.Trim() == "")
{
MessageBox.Show("用户名或密码不能为空!", "提示");
}
else
{
string pwd = this.txtpwd.Text;
string UserName = this.txtEmail.Text;
bool isOK = false;
foreach (LoginInfo item in array)
{
if (item != null)
{
if(item.Email==UserName && item.Password==pwd)
{
isOK = true;
FrmMain FM = new FrmMain();
FM.lblName.Text = "欢迎" + item.Name;
FM.Show();
break;
}
}
}
if (isOK == false)
{
txtpwd.Text = "";
txtpwd.Focus();
}
}
}
}
}
====================================
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();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
public FrmLogin f1;
private void button1_Click(object sender, EventArgs e)
{
string Name= this.txtName.Text;
string ID = this.txtId.Text;
string Email = this.txtEmail.Text;
string password = this.txtpassword.Text;
string Pow =this.txtpow.Text;
string EM = this.txtEm.Text;
if(txtName.Text.Trim()=="" || txtId.Text.Trim()==""
|| txtEmail.Text.Trim()=="" ||txtpassword.Text.Trim()==""
||txtEm.Text.Trim()==""||txtpow.Text.Trim()=="")
{
MessageBox.Show("注册各项信息不得为空","提示");
}
else if (txtEmail.Text.Trim() != txtEm.Text.Trim()
|| txtpassword.Text.Trim() != txtpow.Text.Trim())
{
MessageBox.Show("两次输入邮箱地址及密码必须相同", "提示");
}
else
{
MessageBox.Show("恭喜,通过验证!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
LoginInfo info=new LoginInfo();
info.Name=Name;
info.Id=ID;
info.Email=Email;
info.Password=password;
for (int i = 0; i < f1.array.Length;i++ )
{
if (f1.array[i] == null)
{
f1.array[1] = info;
break;
}
}
f1.Visible = true;
this.Close();
}
}
}
我是新手,运行不了,错误信息显示:可访问性不一致 我好想两边都用的public啊 就是想把二段代码中的数据放入到 第一段中的数组中去 求大神指点