private void ModifySelectedTimeTableSubject(object sender, ExecutedRoutedEventArgs e) { int selectedPairNumber = SubjectControl.GetSelectedPairNumber(); DaysOfWeek selectedDay = SubjectControl.GetSelectedDay(); SubjectScheduleItem selectedSubjectScheduleItem = SubjectControl.GetSelectedSubjectScheduleItem(); var modifyDialog = new Dialogs.ModifyTimeTableSubjectDialog(_subjectRepository.GetAllSubjects(), selectedSubjectScheduleItem, _pairTypeRepository.GetAllPairTypes().ToList()); modifyDialog.ShowDialog(); if (!modifyDialog.IsSeleted && modifyDialog.SelectedPairType == null && modifyDialog.SelectedSubject == null) { return; } SubjectScheduleItem modifiedScheduleItem = new SubjectScheduleItem() { PairType = modifyDialog.SelectedPairType, Subject = modifyDialog.SelectedSubject }; _displayedSchedule.ScheduleDayColumns.First(col => col.DayName == selectedDay).SubjectDayDict[ selectedPairNumber] = modifiedScheduleItem; SubjectControl.LoadSchedule(_displayedSchedule); _subjectRepository.AddModifyOneTimeTableSubject(_displayedSchedule.Year, _displayedSchedule.SemesterNumber, _displayedSchedule.WeekNumber, selectedDay, selectedPairNumber, modifiedScheduleItem.Subject, modifiedScheduleItem.PairType); }
public Dictionary <int, SubjectScheduleItem> GetAllSubjectItemsInCertainDay(string dayName, int year, int semesterNumber, int weekNumber) { var subjects = new Dictionary <int, SubjectScheduleItem>(); using (var databaseConnection = new SqlConnection(_connString)) { databaseConnection.Open(); using (var command = new SqlCommand(getSubjectsInCertainDay, databaseConnection)) { command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@dayName", dayName); command.Parameters.AddWithValue("@year", year); command.Parameters.AddWithValue("@semesterNumber", semesterNumber); command.Parameters.AddWithValue("@weekNumber", weekNumber); using (var reader = command.ExecuteReader()) { while (reader.Read()) { if (!reader.HasRows) { continue; } SubjectScheduleItem subjectItem = (reader["SubjectId"] != DBNull.Value && reader["TeacherId"] != DBNull.Value) ? new SubjectScheduleItem() { Subject = new Subject { SubjectId = (int)reader["SubjectId"], Name = (string)reader["Name"], SubjectDescription = (reader["Subjectdescription"] == DBNull.Value) ? "": (string)reader["Subjectdescription"], TeacherId = (int)reader["TeacherId"] }, PairType = new PairType() { TypeId = (int)reader["PairTypeId"], TypeName = (string)reader["TypeName"], TypeStringId = (string)reader["TypeStringId"] } } : null; subjects.Add((int)reader["PairNumber"], subjectItem); } } } if (subjects.Count != 0) { while (subjects.Count > 0 && subjects[subjects.Keys.Max()] == null) { subjects.Remove(subjects.Keys.Max()); } } } return(subjects); }
public ModifyTimeTableSubjectDialog(List <Subject> awailableSubjects, SubjectScheduleItem selectedSubjectScheduleItem, List <PairType> awailablePairTypes) { InitializeComponent(); AwailableSubjectsList.ItemsSource = awailableSubjects; AwailableSubjectsList.SelectedItem = selectedSubjectScheduleItem != null ? awailableSubjects.First(subject => subject.SubjectId == selectedSubjectScheduleItem.Subject.SubjectId) : awailableSubjects[0]; AwailablePairTypesList.ItemsSource = awailablePairTypes; AwailablePairTypesList.SelectedItem = selectedSubjectScheduleItem != null ? awailablePairTypes.First(p => p.TypeId == selectedSubjectScheduleItem.PairType.TypeId) : awailablePairTypes[0]; }