private void BtnFind_Click(object sender, RoutedEventArgs e) { // вызов селектора студентов SelectStudentWindow selectStudentWindow = new SelectStudentWindow(); selectStudentWindow.ShowDialog(); selectStudentWindow.Close(); if (selectStudentWindow.SelectedId >= 0) { SwitchToEditMode(selectStudentWindow.SelectedId); } }
private void Button_Click(object sender, RoutedEventArgs e) { int selectedIndex = grdRooms.SelectedIndex; if (selectedIndex >= 0) { if (grdRooms.Items[selectedIndex] is DataService.RoomRecord roomRecord && roomRecord.Free > 0) { // вызов селектора студентов SelectStudentWindow selectStudentWindow = new SelectStudentWindow(); selectStudentWindow.lblHeader.Content = "Заселение в: " + roomRecord.Hostel + " комната " + roomRecord.Number; selectStudentWindow.lblHeader.Visibility = Visibility.Visible; selectStudentWindow.ShowDialog(); selectStudentWindow.Close(); if (selectStudentWindow.SelectedId >= 0) { (Occupation previousOccupation, Occupation occupation) = DataService.SetOccupation(selectStudentWindow.SelectedId, roomRecord.Id); // обновление UI List <DataService.RoomRecord> records = new List <DataService.RoomRecord>(); foreach (DataService.RoomRecord r in grdRooms.ItemsSource) { records.Add(r); if (previousOccupation != null && r.Id == previousOccupation.Room.Id) { r.Occupied = r.Occupied - 1; r.Free = r.Free + 1; } } records[selectedIndex].Occupied = records[selectedIndex].Occupied + 1; records[selectedIndex].Free = records[selectedIndex].Free - 1; grdRooms.ItemsSource = records; UpdateStudentsGrid(); } } } }