public MainWindow() { InitializeComponent(); this.DataContext = this; StudentsList.Add(new Student("Paul", "LName1", "FName1")); StudentsList.Add(new Student("Alex", "LName2", "FName2")); StudentsList.Add(new Student("Steve", "LName3", "FName3")); }
public void CreateStudent(Student st1) { Console.WriteLine("Please insert Student First Name:"); string studentfirstName = Console.ReadLine(); Console.WriteLine("Please insert Student Last Name:"); ///Second aproach : insert datas in the console string studentlastName = Console.ReadLine(); Console.WriteLine("Please insert Student Grade:"); int studentgrade = Convert.ToInt32(Console.ReadLine()); st1.FirstName = studentfirstName; st1.LastName = studentlastName; st1.Grade = studentgrade; StudentsList.Add(st1); }
/// <summary> /// Reads the details text file from the App_Data directory and parses each row to an object. /// </summary> private void ParseDetailsFile() { StreamReader file = new StreamReader(System.Web.HttpContext.Current.Server.MapPath("~/App_Data/studInfo.txt")); var detailsLines = file.ReadLine(); //Loop through all the lines in the details file while (detailsLines != null) { var studentSplitedLine = detailsLines.Split(' '); StudentsList.Add(new Student { FirstName = studentSplitedLine[0], LastName = studentSplitedLine[1], Id = long.Parse(studentSplitedLine[2]) }); detailsLines = file.ReadLine(); } file.Close(); }
/// <summary> /// Выпоняет загрузку списка студентов из файла /// </summary> public void GetStudents() { if (ValidateFileName()) { try { using (var workbook = new XLWorkbook(FileName)) { var worksheet = workbook.Worksheets.Worksheet(1); for (int row = 2; ; row++) { if (string.IsNullOrEmpty(worksheet.Cell(row, 1).GetValue <string>())) { break; } else { var student = new StudentViewModel { StudentId = 0, Name = worksheet.Cell(row, 1).GetValue <string>(), Phone = worksheet.Cell(row, 2).GetValue <string>(), Description = worksheet.Cell(row, 3).GetValue <string>(), GroupName = worksheet.Cell(row, 4).GetValue <string>() }; StudentsList.Add(student); } } } OnPropertyChanged(nameof(StudentsList)); } catch (Exception) { ErrorMessage = "Неверный формат файла!"; } if (StudentsList.Count == 0) { ErrorMessage = "Неверный формат файла!"; } } }
public void SetStudent(Student student) { StudentsList.Add(student); }
public void AddStudent(Student x) { StudentsList.Add(x); }