namespace ReadFileFromWindownForm1
{
public partial class Form1 : Form
{
List<Student> students;
public Form1()
{
students = new List<Student>();
InitializeComponent();
}
DataTable table = new DataTable();
private void Form1_Load(object sender, EventArgs e)
{
[Link] = 0;
}
private void btOpenfile_Click(object sender, EventArgs e)
{
loadFile();
}
private void loadFile()
{
[Link]();
String filename = @"D:\[Link]";
string[] lines = [Link](filename);
if([Link] > 0)
{
[Link] = filename;
string[] values;
for (int i = 0; i < [Link]; i++)
{
values = lines[i].ToString().Split('|');
string[] row = new string[[Link]];
for (int j = 0; j < [Link]; j++)
{
row[j] = values[j].Trim();
}
[Link](row);
Student student = new Student(row[0], row[1],
[Link](row[2]), row[3]);
[Link](student);
}
[Link] = false;
}
}
private void btAdd_Click(object sender, EventArgs e)
{
String filename = @"D:\[Link]";
String studentID = [Link];
if (studentID == null || [Link]().Length== 0)
{
[Link]("StudentID must not empty!");
}
else
{
String studentName = [Link];
Boolean male;
if ([Link] == true)
{
male = false;
}
else
{
male = true;
}
String major = [Link];
Student newStudent = new Student(studentID, studentName, male,
major);
[Link](newStudent);
try
{
StreamWriter streamWriter = new StreamWriter(filename);
using (streamWriter)
{
foreach (Student s in students)
{
[Link]([Link] + '|' +
[Link] + '|' + [Link] + '|' + [Link]);
}
}
loadFile();
[Link]("Add successful!");
}
catch (Exception ex)
{
}
}
}
}