private void button3_Click(object sender, RoutedEventArgs e) { CinemaDataContext Context = new CinemaDataContext(); int i = 0; string[] Strs = File.ReadAllLines("Films.txt"); Context.ExecuteCommand("delete from tblMovie"); do { tblMovie Movie = new tblMovie(); Movie.MovieName = Strs[i++]; Movie.MovieDirector = Strs[i++]; Movie.MovieDuration = Convert.ToInt32(Strs[i++]); Movie.MovieYear = Convert.ToInt32(Strs[i++]); Movie.MinAge = Convert.ToInt32(Strs[i++]); Movie.MainActor = Strs[i++]; Context.tblMovies.InsertOnSubmit(Movie); Context.SubmitChanges(); int MovieID = (from M in Context.tblMovies where M.MovieName == Movie.MovieName select M.MovieID).First(); string[] GenresStrs = Strs[i++].Split(); foreach (string S in GenresStrs) { tblMovieGenre MovieGenre = new tblMovieGenre(); MovieGenre.MovieID = MovieID; MovieGenre.GenreID = (from G in Context.tblGenres where G.GenreName == S select G.GenreID).First(); Context.tblMovieGenres.InsertOnSubmit(MovieGenre); } string[] CountriesStrs = Strs[i++].Split(); foreach (string S in CountriesStrs) { tblMovieCountry MovieCountry = new tblMovieCountry(); MovieCountry.MovieID = MovieID; MovieCountry.CountryID = (from G in Context.tblCountries where G.CountryName == S select G.CountryID).First(); Context.tblMovieCountries.InsertOnSubmit(MovieCountry); } i++; }while (i < Strs.Length); Context.SubmitChanges(); }
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); } }
public void BuyTicket(Film film, Visitor visitor, Cashier cashier, string seat) { var dateTime = new DateTime(2012, 7, 5); var order = new Order { OrderID = Guid.NewGuid().ToString(), Visitor = visitor, VisitorID = visitor.VisitorID, Cashier = cashier, CashierID = cashier.CashierID, Film = film, FilmID = film.FilmID, DataSale = dateTime }; _cinema.Orders.InsertOnSubmit(order); //_cinema.Seats.InsertOnSubmit(new Seat { OrderID = order.OrderID, SeatNumber = seat }); _cinema.Visitors.InsertOnSubmit(visitor); _cinema.SubmitChanges(); }
private void btnLogin_Click(object sender, RoutedEventArgs e) { try { if (string.IsNullOrWhiteSpace(tbNickName.Text)) { throw new Exception("Пустое имя пользователя"); } if (string.IsNullOrWhiteSpace(passwordBox1.Password)) { throw new Exception("Пустой пароль"); } if (passwordBox1.Password != passwordBox2.Password) { throw new Exception("Пароли не совпадают"); } CinemaDataContext DatabaseContext = new CinemaDataContext(); var UserQueue = from U in DatabaseContext.tblUsers where U.Username == tbNickName.Text select U; if (UserQueue.Count() != 0) { throw new Exception(" Пользователь с таким именем уже существует"); } tblUser User = new tblUser(); User.Username = tbNickName.Text; User.Password = passwordBox1.Password; User.Rights = "E"; DatabaseContext.tblUsers.InsertOnSubmit(User); DatabaseContext.SubmitChanges(); MessageBox.Show("Вы успешно зарегестрированы"); Close(); } catch (Exception E) { MessageBox.Show("Ошибка: " + E.Message); } }
private void button2_Click(object sender, RoutedEventArgs e) { CinemaDataContext Context = new CinemaDataContext(); Context.ExecuteCommand("delete from tblSeat"); List <tblRoom> Rooms = Context.tblRooms.ToList(); int c = 0; foreach (tblRoom R in Rooms) { for (int i = 0; i < R.RowNumber; i++) { for (int j = 0; j < R.SeatsNumber; j++) { tblSeat Seat = new tblSeat(); Seat.RoomID = R.RoomID; Seat.Row = i + 1; Seat.Seat = j + 1; if (j > R.SeatsNumber / 5 && j < R.SeatsNumber * 4 / 5 && i > R.RowNumber / 3 && i < R.RowNumber * 4 / 5) { Seat.Vip = 0; } else { Seat.Vip = 1; } // Seat.Vip = 0; c++; Context.tblSeats.InsertOnSubmit(Seat); } } } Context.SubmitChanges(); }
private void btnOrder_Click(object sender, RoutedEventArgs e) { try { CinemaDataContext Context = new CinemaDataContext(); List <tblTicket> TempSeats = new List <tblTicket>(); int Sum = 0; for (int i = 0; i < Seats.GetLength(0); i++) { for (int j = 0; j < Seats.GetLength(1); j++) { if (Seats[i, j].IsSelected) { if ((from T in Context.tblTickets where T.ShowID == Show.ShowID && T.Row == i + 1 && T.Seat == j + 1 && T.Status == 1 select T).Count() != 0) { throw new Exception("Место " + (j + 1).ToString() + " в ряду " + (i + 1).ToString() + " уже занято" + Environment.NewLine + "Заказ будет отменен"); } tblTicket Ticket = (from T in Context.tblTickets where T.Row == i + 1 && T.Seat == j + 1 && T.ShowID == Show.ShowID select T).First(); TempSeats.Add(Ticket); if (Seats[i, j].IsVip) { Sum += Show.VipPrice; } else { Sum += Show.NotVipPrice; } } } } foreach (var T in TempSeats) { tblSoldTicket SoldTicket = new tblSoldTicket(); SoldTicket.UserID = (int)Settings.UserID; SoldTicket.TicketID = T.TicketID; T.Status = 1; Context.tblSoldTickets.InsertOnSubmit(SoldTicket); } try { Context.SubmitChanges(); MessageBox.Show("Вы заказали " + TempSeats.Count + " билет(а/ов)" + Environment.NewLine + "на сумму " + Sum + " руб."); foreach (var T in TempSeats) { Ticket TicketWindow = new Ticket(MovieName, Show.Date, Show.Session, Show.RoomID, (int)T.Row, (int)T.Seat, Seats[(int)T.Row - 1, (int)T.Seat - 1].IsVip ? Show.VipPrice : Show.NotVipPrice); TicketWindow.ShowDialog(); } } catch (Exception E) { MessageBox.Show("Невозможно сделать заказ: " + E.Message); } } catch (Exception E) { MessageBox.Show("Ошибка: " + E.Message); } button2_Click(sender, e); }
public DataTable buildAndPerformSelectDeleteQuery(string queryType, string tableName, string queryValue) { if (queryType == "select") { if (tableName == "administrator") { IEnumerable <CinemaContext.administrator> selectData = from administrator in dc.administrators select administrator; dt = LINQResultToDataTable(selectData); } if (tableName == "cashier") { IEnumerable <CinemaContext.cashier> selectData = from cashier in dc.cashiers select cashier; dt = LINQResultToDataTable(selectData); } if (tableName == "customer") { IEnumerable <CinemaContext.customer> selectData = from customer in dc.customers select customer; dt = LINQResultToDataTable(selectData); } if (tableName == "film") { IEnumerable <CinemaContext.film> selectData = from film in dc.films select film; dt = LINQResultToDataTable(selectData); } } if (queryType == "delete") { int idValue; var splitRes = queryValue.Split('='); idValue = Convert.ToInt32(splitRes[1]); if (tableName == "administrator") { administrator admin = (from r in dc.administrators where r.adminid == idValue select r).SingleOrDefault(); dc.administrators.DeleteOnSubmit(admin); dc.SubmitChanges(); IEnumerable <CinemaContext.administrator> selectData = from administrator in dc.administrators select administrator; dt = LINQResultToDataTable(selectData); } if (tableName == "cashier") { cashier cash = (from r in dc.cashiers where r.cashierid == idValue select r).SingleOrDefault(); dc.cashiers.DeleteOnSubmit(cash); dc.SubmitChanges(); IEnumerable <CinemaContext.cashier> selectData = from cashier in dc.cashiers select cashier; dt = LINQResultToDataTable(selectData); } if (tableName == "customer") { customer cust = (from r in dc.customers where r.customerid == idValue select r).SingleOrDefault(); dc.customers.DeleteOnSubmit(cust); dc.SubmitChanges(); IEnumerable <CinemaContext.customer> selectData = from customer in dc.customers select customer; dt = LINQResultToDataTable(selectData); } if (tableName == "film") { string filmTitle; var splitResult = queryValue.Split('='); filmTitle = splitRes[1]; film fil = (from r in dc.films where r.title == filmTitle select r).SingleOrDefault(); dc.films.DeleteOnSubmit(fil); dc.SubmitChanges(); IEnumerable <CinemaContext.film> selectData = from film in dc.films select film; dt = LINQResultToDataTable(selectData); } } return(dt); }
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); } }
private void button3_Click(object sender, RoutedEventArgs e) { try { tblMovie Movie = new tblMovie(); if (string.IsNullOrWhiteSpace(tbFilmName.Text)) { throw new Exception("Не введено название фильма"); } Movie.MovieName = tbFilmName.Text; if (string.IsNullOrWhiteSpace(tbDirector.Text)) { throw new Exception("Не введено имя режиссера"); } Movie.MovieDirector = tbDirector.Text; Movie.MovieDuration = Convert.ToInt32(udDuration.Value); Movie.MovieYear = Convert.ToInt32(udYear.Value); Movie.MinAge = Convert.ToInt32(udMinAge.Value); if (string.IsNullOrWhiteSpace(tbMainHero.Text)) { throw new Exception("Не введено имя главного актера"); } Movie.MainActor = tbMainHero.Text; if (string.IsNullOrWhiteSpace(tbGenres.Text)) { throw new Exception("Не выбран хотя бы один жанр"); } if (string.IsNullOrWhiteSpace(tbCountries.Text)) { throw new Exception("Не выбран хотя бы одна страна"); } CinemaDataContext Context = new CinemaDataContext(); Context.tblMovies.InsertOnSubmit(Movie); Context.SubmitChanges(); int MovieID = (from M in Context.tblMovies where M.MovieName == tbFilmName.Text select M.MovieID).ToArray()[0]; List <int> GenresID; List <int> CountriesID; GetID(tbGenres.Text, tbCountries.Text, out GenresID, out CountriesID); foreach (int ID in GenresID) { tblMovieGenre MovieGenre = new tblMovieGenre(); MovieGenre.MovieID = MovieID; MovieGenre.GenreID = ID; Context.tblMovieGenres.InsertOnSubmit(MovieGenre); } foreach (int ID in CountriesID) { tblMovieCountry MovieCountry = new tblMovieCountry(); MovieCountry.MovieID = MovieID; MovieCountry.CountryID = ID; Context.tblMovieCountries.InsertOnSubmit(MovieCountry); } Context.SubmitChanges(); ReloadFilmsRooms(); MessageBox.Show("Фильм " + Movie.MovieName + " успешно добавлен"); } catch (Exception Ex) { MessageBox.Show("Ошибка: " + Ex.Message); } }