protected student GetFields(string record)
 {
     student std = new student();
     std.id = id.ReadField(ref record);
     std.name = name.ReadField(ref record);
     std.address = address.ReadField(ref record);
     return std;
 }
 public void Write(StreamWriter sw, student std)
 {
     string record = "";
     record += id.WriteField(std.id);
     record += name.WriteField(std.name);
     record += address.WriteField(std.address);
     string RecordToWrite = this.FormatRecord(record);
     sw.Write(RecordToWrite);
 }
 public void WriteWzKey(StreamWriter sw, student std)
 {
     string record = "";
     record += id.writeField(std.id, "ID=");
     record += name.writeField(std.name, "Name=");
     record += address.writeField(std.address, "Address=");
     string RecordToWrite = this.FormatRecord(record);
     sw.Write(RecordToWrite);
 }
Ejemplo n.º 4
0
 static void Main(string[] args)
 {
     recordStructure rd = GetRecordStructureFromUser();
     Console.WriteLine("What do you want to do");
     Console.WriteLine("1-Enter a new student");
     Console.WriteLine("2-Display File");
     Console.WriteLine("3-Exit");
     int choice = int.Parse(Console.ReadLine());
     switch (choice)
     {
         case 1:
             student std = new student();
             std.getData();
             Console.WriteLine("Enter file name");
             FileStream fs = new FileStream(Console.ReadLine(), FileMode.Append, FileAccess.Write);
             StreamWriter sw = new StreamWriter(fs);
             if (rd.keyval)
                 rd.WriteWzKey(sw, std);
             else
                 rd.Write(sw, std);
             sw.Close();
             fs.Close();
             break;
         case 2:
             Console.WriteLine("Enter file name");
             List<student> allStudents = rd.ReadAll(Console.ReadLine());
             for (int i = 0; i < allStudents.Count; i++)
             {
                 allStudents[i].display();
             }
             break;
         default:
             break;
     }
 }