我正在尝试验证用户名复选框以查看输入的值是否存在于 XML 文件中。
单击按钮时,它应检查输入的名称是否存在于 XML 文件中,然后继续,如果不存在,则应出现消息框。
当前代码显示 txt_Username.Text = Pupil.forename 由于其保护级别而无法访问。
单击按钮时:
private void btnNext_Click(object sender, RoutedEventArgs e, Pupil p)
{
if (txt_Username.Text = Pupil.forename)
{
this.Hide();
Display nw = new Display(theClass);
nw.ShowDialog();
this.Show();
}
MessageBox.Show("Cannot Find username");
}
学生班级:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PassingData
{
public class Pupil
{
private string forename;
private int score;
public Pupil(string forename, int score)
{
this.forename = forename;
this.score = score;
}
public Pupil()
{
this.forename = "Unknown";
}
public string Forename
{
get { return forename; }
set { forename = value; }
}
public int Score
{
get { return score; }
set { score = value; }
}
override public string ToString()
{
string output = forename + "\t" + score;
return output;
}
}
}
XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfPupil xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Pupil>
<Forename>Andy</Forename>
<Score>0</Score>
</Pupil>
<Pupil>
<Forename>Bob</Forename>
<Score>10</Score>
</Pupil>
<Pupil>
<Forename>Carl</Forename>
<Score>20</Score>
</Pupil>
<Pupil>
<Forename>Dave</Forename>
<Score>30</Score>
</Pupil>
<Pupil>
<Forename>Eric</Forename>
<Score>40</Score>
</Pupil>
<Pupil>
<Forename>Frank</Forename>
<Score>50</Score>
</Pupil>
</ArrayOfPupil>