private void button2_Click(object sender, RoutedEventArgs e) { if (dataGrid1.SelectedItems.Count != 0 && MessageBox.Show("Вы действительно хотите удалить выбранные сеансы?", "", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { foreach (object Item in dataGrid1.SelectedItems) { try { int ShowID = (int)Item.GetType().GetProperty("ID").GetValue(Item, new object[0]); CinemaDataContext Context = new CinemaDataContext(); tblShow Show = ((from S in Context.tblShows where S.ShowID == ShowID select S).ToArray().First()); Context.tblShows.DeleteOnSubmit(Show); try { Context.SubmitChanges(); } catch { MessageBox.Show("Невозможно удалить сеанс с ID = " + ShowID.ToString() + ". На него уже куплены билеты"); } } catch (Exception E) { MessageBox.Show("Ошибка удаления: " + E.Message); } } comboBox1_SelectionChanged(sender, null); } }
private void cmbShow_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (cmbShow.SelectedIndex != -1) { try { gridBook.Visibility = System.Windows.Visibility.Visible; CinemaDataContext Context = new CinemaDataContext(); string MovieName = (string)cmbFilms.SelectedItem; DateTime Date = (DateTime)cmbDate.SelectedItem; var ShowQuery = (from S in Context.tblShows join M in Context.tblMovies on S.MovieID equals M.MovieID where M.MovieName == MovieName && S.Date == Date && S.Session == Times[cmbShow.SelectedIndex] select S).Distinct(); Show = ShowQuery.First(); lblNotVip.Content = " - Эконом (" + Show.NotVipPrice.ToString() + ")"; lblVip.Content = " - VIP (" + Show.VipPrice.ToString() + ")"; RedrawRoom((from R in Context.tblRooms where R.RoomID == Show.RoomID select R).First()); } catch (Exception E) { MessageBox.Show("Ошибка: " + E.Message); } } else { gridBook.Visibility = System.Windows.Visibility.Collapsed; } }
private void button7_Click(object sender, RoutedEventArgs e) { try { if (cmbFilm2.SelectedValue == null) { throw new Exception("Не выбран фильм"); } if (cmbRoom.SelectedValue == null) { throw new Exception("Не выбран зал"); } if (datePicker1.SelectedDate == null || datePicker2.SelectedDate == null) { throw new Exception("Не выбрана дата"); } DateTime DT1 = (DateTime)datePicker1.SelectedDate; DateTime DT2 = (DateTime)datePicker2.SelectedDate; if (DT2.DayOfYear - DT1.DayOfYear > 7) { throw new Exception("Максимальная количество дней - 7"); } CinemaDataContext Context = new CinemaDataContext(); int MovieID = (from M in Context.tblMovies where M.MovieName == (string)cmbFilm2.SelectedValue select M.MovieID).ToArray()[0]; int RoomID = (int)cmbRoom.SelectedValue; for (DateTime DT = DT1; DT <= DT2; DT = DT.Date.AddDays(1)) { DateTime NewSession = new DateTime(2011, 01, 01, Convert.ToInt32(udHour.Value), Convert.ToInt32(udMinute.Value), 0); int? S = Context.IsShowCorrect(RoomID, MovieID, DT, NewSession); if (DT <= DateTime.Now) { MessageBox.Show("Сеанс " + DT.ToShortDateString() + " " + NewSession.Hour.ToString() + ":" + NewSession.Minute.ToString() + " раньше текущего времени"); continue; } if (S == 0 || S == null) { tblShow Show = new tblShow(); Show.MovieID = (from M in Context.tblMovies where M.MovieName == (string)cmbFilm2.SelectedItem select M.MovieID).ToArray()[0]; Show.RoomID = (int)cmbRoom.SelectedItem; Show.Date = DT; Show.Session = NewSession; Show.VipPrice = 0; Show.NotVipPrice = 0; Context.tblShows.InsertOnSubmit(Show); Context.SubmitChanges(); } else { MessageBox.Show("Сеанс с ID = " + S.ToString() + " пересекается с уже имеющимся сеансом в этом зале"); } } MessageBox.Show("Сеансы успешно добавлены"); } catch (Exception E) { MessageBox.Show("Ошибка: " + E.Message); } }