public void AddStudentToRegister(StudentList aStudentList) { if (aStudentList.getCount() == 0) { Console.WriteLine("\n *********************************************************"); Console.WriteLine("\t No hay datos de estudiante."); Console.WriteLine("\n *********************************************************"); } else if (this.SubjectRegisterHeaderAtributes()) { Console.Write("\n Escriba el ID del registro de asignatura que desea editar: "); int id = Convert.ToInt32("0" + Console.ReadLine()); foreach (var subjectRegister in subjectRegisters) { if (subjectRegister.Id == id) { Console.WriteLine("\n Agregar estudiante a registro de asignatura \n"); Console.WriteLine("\t Estudiantes disponibles para agregar a registro de asignatura: \n"); aStudentList.PrintListIdNameCareer(); Console.Write("\n Escriba el ID del estudiante que desea agregar al registro de asignatura: "); int idEst = Convert.ToInt32("0" + Console.ReadLine()); if (aStudentList.GetIdList().Contains(idEst)) { subjectRegister.AddStudentToSubjectRegister(aStudentList.SearchAndReturn(idEst)); } break; } } } }
//Funciones nuevas para serializar/deserializar static void ClearRegisterObjects() //Limpia objetos y guarda los cambios { Students = new StudentList(); Subjects = new SubjectList(); SubjectsRegister = new SubjectRegisterList(); Serialize(); }
static void JsonImport() { var json = System.IO.File.ReadAllText("Files/Template.json"); Students = JsonConvert.DeserializeObject <StudentList>(json); Console.Clear(); Console.WriteLine("\n **************************************************"); Console.Write("\t Documeto Importado Exitosamente"); Console.WriteLine("\n **************************************************"); Console.WriteLine(" Presione Cualquier tecla para continuar "); Console.ReadKey(); ImportExportStudentMenu(); // SerializeStudents(); }
static void XmlImport() { var writer = new System.Xml.Serialization.XmlSerializer(typeof(StudentList)); StreamReader newtw = new StreamReader("Files/Template.xml"); Students = (StudentList)writer.Deserialize(newtw); Console.Clear(); Console.WriteLine("\n **************************************************"); Console.Write("\t Documeto Importado Exitosamente"); Console.WriteLine("\n **************************************************"); Console.WriteLine(" Presione Cualquier tecla para continuar "); Console.ReadKey(); ImportExportStudentMenu(); // SerializeStudents(); }
static void DeserializeStudents() //Deserializa el objeto Students { try { using (Stream stream = File.Open("studentsBinary.bin", FileMode.Open)) { BinaryFormatter bin = new BinaryFormatter(); Students = (StudentList)bin.Deserialize(stream); } } catch (IOException) { Students = new StudentList(); } }
public void ListStudentsFromSubjectRegister(StudentList aStudentList) { if (aStudentList.getCount() == 0) { Console.WriteLine("\n *********************************************************"); Console.WriteLine("\t No hay datos de estudiante."); Console.WriteLine("\n *********************************************************"); return; } else if (this.SubjectRegisterHeaderAtributes()) { Console.Write("\n Escriba el ID del registro de asignatura que desea editar: "); int id = Convert.ToInt32("0" + Console.ReadLine()); foreach (var subjectRegister in subjectRegisters) { if (subjectRegister.Id == id) { subjectRegister.ListStudentsFromRegister(); return; } } } }