public void ReadStudentList() { Data = new List <StdInformation>(); if (File.Exists(FileN)) { BinaryReader binaryR = new BinaryReader(new FileStream(FileN, FileMode.Open)); int a = binaryR.ReadInt32(); for (int i = 0; i < a; i++) { StdInformation stdF = new StdInformation(); stdF.Load(binaryR); Data.Add(stdF); } binaryR.Close(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("The list of student had readed !!"); Console.ResetColor(); } else { Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("Have not student is this list !!!"); Console.ResetColor(); } Console.WriteLine("Press enter to continue =>."); Console.ReadLine(); }
public void EditStudentInf() { string mess = "Error invalid entry! Try again."; int stt; if (File.Exists(FileN)) { if (Data.Count == 0) { Console.WriteLine("\n Have not Student in the list !!!"); goto end; } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("\n The list have {0} student!", Data.Count); Console.ResetColor(); for (int i = 0; i < Data.Count; i++) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("{0}. {1}", i + 1, Data[i].stdName); Console.ResetColor(); } do { Console.Write("\n Choose the student to edit students' information: "); string stt2 = Console.ReadLine(); while (!int.TryParse(stt2, out stt)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(mess); Console.ResetColor(); Console.Write("Choose the Lecturer to edit Lecturers' information again: \t"); stt2 = Console.ReadLine(); } if (stt < 1 || stt > Data.Count) { Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine(mess); Console.ResetColor(); } } while (stt < 1 || stt > Data.Count); stt--; StdInformation sF = new StdInformation(); sF = editStdInf(stt); Data.RemoveAt(stt); Data.Insert(stt, sF); SaveList(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("\nThe information edit had saved!"); Console.ResetColor(); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("The list have not any student !!!"); Console.ResetColor(); } end: Console.ReadLine(); }
public void AddNewStudent() { string r; do { StdInformation stdF = new StdInformation(); stdF.AddNStd(); Data.Add(stdF); Console.ForegroundColor = ConsoleColor.Blue; Console.Write("Do you want to continue? (y: Yes / Enter: No): \t"); r = Console.ReadLine().ToLower(); Console.ResetColor(); } while (r.Equals("y")); }
public StdInformation editStdInf(int inf) { string mess = "Error invalid entry! Try again."; string id, name, DoB, address, phone, email, batch; StdInformation stdF = new StdInformation(); //edit ID inf of student Console.WriteLine("\n ID of student: {0}", Data[inf].stdId); Console.Write("Enter the new information (or ENTER to ignore): GT"); id = Console.ReadLine().ToUpper(); if (id != "") { stdF.stdId = "GT" + id; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Edit successful !"); Console.ResetColor(); } else { stdF.stdId = Data[inf].stdId; } //Edit name of student Console.WriteLine("\nTHe name of student: {0}", Data[inf].stdName); Console.Write("Enter the new information (or ENTER to ignore): "); name = Console.ReadLine().ToUpper(); if (name != "") { stdF.stdName = name; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Edit name successful !"); Console.ResetColor(); } else { stdF.stdName = Data[inf].stdName; } //Edit DoB information of student Console.WriteLine("\nDate of Birth: {0}", Data[inf].stdDoB.ToString("dd/MM/yyyy")); Console.Write("Enter the new information (yyyy/MM/dd) (or ENTER to ignore): "); DoB = Console.ReadLine(); if (DoB != "") { while (!DateTime.TryParse(DoB, out stdF.stdDoB)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(mess); Console.ResetColor(); Console.Write("Enter the new information (yyyy/MM/dd)"); DoB = Console.ReadLine(); } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Edit succesful !"); Console.ResetColor(); } else { stdF.stdDoB = Data[inf].stdDoB; } //Edit address information of student Console.WriteLine("\nAddress: {0}", Data[inf].stdAddress); Console.Write("Enter the new information (or ENTER to ignore):"); address = Console.ReadLine().ToUpper(); if (address != "") { stdF.stdAddress = address; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Edit successful !"); Console.ResetColor(); } else { stdF.stdAddress = Data[inf].stdAddress; } //Edit the phone number information of student Console.WriteLine("\nPhone number: {0}", Data[inf].stdPhone); Console.Write("Enter the new information (or ENTER to ignore):"); phone = Console.ReadLine(); if (phone != "") { while (!int.TryParse(phone, out stdF.stdPhone) || phone.Length != 10) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(mess); Console.ResetColor(); Console.Write("Enter the new information: "); phone = Console.ReadLine(); } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Edit successful !"); Console.ResetColor(); } else { stdF.stdPhone = Data[inf].stdPhone; } //edit Email inf of student Console.WriteLine("\n Email: {0}", Data[inf].stdEmail); Console.Write("Enter the new information (or ENTER to ignore): "); email = Console.ReadLine().ToUpper(); if (email != "") { stdF.stdEmail = email; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Edit successful !"); Console.ResetColor(); } else { stdF.stdEmail = Data[inf].stdEmail; } //edit the batch of student Console.WriteLine("\n The batch of student: {0}", Data[inf].stdBatch); Console.Write("Enter the new information (or ENTER to ignore): "); batch = Console.ReadLine().ToUpper(); if (batch != "") { stdF.stdBatch = batch; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Edit successful !"); Console.ResetColor(); } else { stdF.stdBatch = Data[inf].stdBatch; } return(stdF); }