public StudentViewModel(Semester selectedSemester, Course selectedCourse) { modify = false; _student = new Student(); Name = ""; Neptun = ""; Semester = selectedSemester; Course = selectedCourse; insertStudentWindow = new InsertStudentWindow(); insertStudentWindow.DataContext = this; insertStudentWindow.ShowDialog(); }
public StudentViewModel(Student selectedStudent, Semester selectedSemester, Course selectedCourse) { modify = true; ModifyableStudent = selectedStudent; _student = new Student(); _student.clone(selectedStudent); Semester = selectedSemester; Course = selectedCourse; insertStudentWindow = new InsertStudentWindow(); insertStudentWindow.DataContext = this; insertStudentWindow.ShowDialog(); }
private void FixupSemester(Semester previousValue) { if (IsDeserializing) { return; } if (previousValue != null && previousValue.Course.Contains(this)) { previousValue.Course.Remove(this); } if (Semester != null) { if (!Semester.Course.Contains(this)) { Semester.Course.Add(this); } } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("Semester") && (ChangeTracker.OriginalValues["Semester"] == Semester)) { ChangeTracker.OriginalValues.Remove("Semester"); } else { ChangeTracker.RecordOriginalValue("Semester", previousValue); } if (Semester != null && !Semester.ChangeTracker.ChangeTrackingEnabled) { Semester.StartTracking(); } FixupSemesterKeys(); } }
public static IEnumerable<Student> ImportFromExcel(string filename, Semester semester) { const String nameColumnName = "név"; const String neptunColumnName = "neptun kód"; int? nameColumnIndex = null; int? neptunColumnIndex = null; // open an Excel application Excel.Application excelApp = new Excel.Application(); excelApp.Visible = false; // open the workbook in read-only mode Excel.Workbook workbook = excelApp.Workbooks.Open(filename, Type.Missing, true); Excel.Worksheet worksheet = excelApp.ActiveSheet; Excel.Range usedRange = worksheet.UsedRange; // scan through the first row to get the column indices for (int j = 1; j <= worksheet.UsedRange.Columns.Count; j++) { Excel.Range cell = usedRange.Cells[1, j]; if (cell.Value != null) { String cellValue = cell.Value.ToString(); if (cellValue.ToLower() == nameColumnName.ToLower()) { nameColumnIndex = j; } if (cellValue.ToLower() == neptunColumnName.ToLower()) { neptunColumnIndex = j; } } } // throw exception if a required a column does not exist if (nameColumnIndex == null || neptunColumnIndex == null) { throw new BUTEClassAdministrationException("Nem találhatók a szükséges oszlopok."); } // use List as an IEnumerable implementation List<Student> students = new List<Student>(); // scan through the rows from the second row // instantiate new student entities for (int i = 2; i <= usedRange.Rows.Count; i++) { string name = usedRange.Cells[i, nameColumnIndex].Value.ToString(); string neptun = usedRange.Cells[i, neptunColumnIndex].Value.ToString(); Student student = new Student(); student.Name = name; student.Neptun = neptun; student.Semester = semester; students.Add(student); } excelApp.Quit(); return students; }