Exemplo n.º 1
0
        /// <summary>
        /// Удалить сеанс
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteSessionButton_Click(object sender, RoutedEventArgs e)
        {
            Sessions ses = (Sessions)SessionsDataGrid.SelectedValue;

            using (var db = new CinemaEntities())
            {
                if ((db.IsTicketsOnSessionBought(ses.Session_id)).Count() != 0)
                {
                    MessageBox.Show("Нельзя удалить сеанс, когда на него уже куплены билеты");
                }
                else
                {
                    MessageBoxResult messageBoxResult = MessageBox.Show("Удалить выбранные сеанс?", "Внимание!", MessageBoxButton.YesNo);
                    if (messageBoxResult == MessageBoxResult.Yes)
                    {
                        var t = from f in db.Tickets where f.Session == ses.Session_id select f;
                        foreach (var ticket in t)
                        {
                            db.Tickets.Remove(ticket);
                        }
                        var      s        = from f in db.Sessions where f.Session_id == ses.Session_id select f;
                        Sessions sessions = new Sessions();
                        foreach (var s1 in s)
                        {
                            sessions = s1;
                        }
                        db.Sessions.Remove(sessions);
                        db.SaveChanges();
                        MessageBox.Show("Сеанс удален");
                        LoadSessions();
                        DatePicker_SelectedDateChanged(DateSessionDataPicker, null);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void DatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            DateTime?date = DateSessionDataPicker.SelectedDate;

            if (date == null)
            {
                FilmInformationSessionDataGrid.ItemsSource = null;
            }
            else
            {
                using (var db = new CinemaEntities())
                {
                    var s = from f in db.Sessions
                            where f.Film == film.Film_id && f.Session_time.Year == ((DateTime)date).Year && f.Session_time.Month == ((DateTime)date).Month && f.Session_time.Day == ((DateTime)date).Day
                            select new Session
                    {
                        Time      = f.Session_time.Hour.ToString() + ":" + f.Session_time.Minute.ToString(),
                        Price     = f.Price,
                        Hall      = f.Halls.Hall_number,
                        sessionId = f.Session_id
                    };
                    FilmInformationSessionDataGrid.ItemsSource = null;
                    FilmInformationSessionDataGrid.ItemsSource = s.ToList();
                }
            }
        }
Exemplo n.º 3
0
 private void AddSessionSeeFreeHallsButton_Click(object sender, RoutedEventArgs e)
 {
     if (!(Regex.IsMatch(AddSessionHourTextBox.Text, reg2) || Regex.IsMatch(AddSessionHourTextBox.Text, reg1)) ||
         !(Regex.IsMatch(AddSessionMinuteTextBox.Text, reg2) || Regex.IsMatch(AddSessionMinuteTextBox.Text, reg1)) ||
         int.Parse(AddSessionMinuteTextBox.Text) > 59 ||
         int.Parse(AddSessionHourTextBox.Text) >= 24)
     {
         MessageBox.Show("Неверное время", Error);
     }
     else
     {
         AddSessionHallComboBox.IsEnabled = true;
         dateTime = (DateTime)AddSessionDataPicker.SelectedDate;
         dateTime = dateTime.AddHours(double.Parse(AddSessionHourTextBox.Text));
         dateTime = dateTime.AddMinutes(double.Parse(AddSessionMinuteTextBox.Text));
         List <int> halls = new List <int>();
         using (var db = new CinemaEntities())
         {
             ListHalls = db.GetFreeHalls(Cinema.Cinema_id, film.Film_id, dateTime).ToList();
             foreach (var h in ListHalls)
             {
                 halls.Add(h.Hall_number);
             }
             AddSessionHallComboBox.ItemsSource = halls;
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Авторизироваться
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AuthButton_Click(object sender, RoutedEventArgs e)
        {
            string log = AuthLoginTextBox.Text;
            string pas = AuthPasswordPasswordBox.Password;

            if (log == "")
            {
                MessageBox.Show("Введите логин", Error);
            }
            else if (pas == "")
            {
                MessageBox.Show("Введите пароль", Error);
            }
            else
            {
                using (var db = new CinemaEntities())
                {
                    foreach (var u in from f in db.Users where f.Login == log || f.Password == pas select f)
                    {
                        user = u;
                    }
                    if (user == null)
                    {
                        MessageBox.Show("Такого пользователя не существует.", Error);
                    }
                    else
                    {
                        lastGrid.Visibility = Visibility.Visible;
                        AuthGrid.Visibility = Visibility.Hidden;
                        ChangeVisibilityUserButtons();
                    }
                }
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Вывести всех пользователей и их права
 /// </summary>
 private void LoadUsersRole()
 {
     using (var db = new CinemaEntities())
     {
         var k = from f in db.Users select new UserRole {
             Login = f.Login, Role = f.Role
         };
         UsersRoleDataGrid.ItemsSource = k.ToList();
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Добавить новый фильм
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void AddNewFilm(object sender, RoutedEventArgs e)
 {
     if (NewFilmNameTextBox.Text == "")
     {
         MessageBox.Show("Неверное название фильма", Error);
     }
     else if (NewFilmDateReleaseDatePicker.SelectedDate == null)
     {
         MessageBox.Show("Укажите дату релиза", Error);
     }
     else if (NewFilmDateEndDatePicker.SelectedDate == null)
     {
         MessageBox.Show("Укажите дату окончания проката", Error);
     }
     else if (NewFilmDateReleaseDatePicker.SelectedDate > NewFilmDateEndDatePicker.SelectedDate)
     {
         MessageBox.Show("Прокат фильма не может закончиться раньше, чем он начнется", Error);
     }
     else if (NewFilmDateEndDatePicker.SelectedDate < DateTime.Now)
     {
         MessageBox.Show("Фильм уже вышел из проката", Error);
     }
     else if (!(Regex.IsMatch(NewFilmDurationHourTextBox.Text, reg2) || Regex.IsMatch(NewFilmDurationHourTextBox.Text, reg1)) ||
              !(Regex.IsMatch(NewFilmDurationMinuteTextBox.Text, reg2) || Regex.IsMatch(NewFilmDurationMinuteTextBox.Text, reg1)) ||
              int.Parse(NewFilmDurationMinuteTextBox.Text) > 59 ||
              (int.Parse(NewFilmDurationMinuteTextBox.Text) == 0 &&
               int.Parse(NewFilmDurationHourTextBox.Text) == 0))
     {
         MessageBox.Show("Неверная длительность фильма", Error);
     }
     else if (NewFilmPosterLabel.Background == null)
     {
         MessageBox.Show("Ваберите постер", Error);
     }
     else
     {
         Films film = new Films()
         {
             Film_name    = NewFilmNameTextBox.Text,
             Date_release = (DateTime)NewFilmDateReleaseDatePicker.SelectedDate,
             Date_end     = NewFilmDateEndDatePicker.SelectedDate,
             Duration     = new TimeSpan(int.Parse(NewFilmDurationHourTextBox.Text), int.Parse(NewFilmDurationMinuteTextBox.Text), 0),
             Description  = NewFilmDescriptionTextBox.Text,
             Poster       = ImageWork.ImageToByteArray(System.Drawing.Image.FromFile(posterWay))
         };
         using (var db = new CinemaEntities())
         {
             db.Films.Add(film);
             db.SaveChanges();
             MessageBox.Show("Фильм добавлен");
         }
         LoadPosters();
         FromAddFilmToManu(null, null);
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// Перейти к окну пользователя
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void UserButton_Click(object sender, RoutedEventArgs e)
 {
     UserGrid.Visibility = Visibility.Visible;
     lastGrid            = ((Grid)((Button)sender).Parent);
     lastGrid.Visibility = Visibility.Hidden;
     using (var db = new CinemaEntities())
     {
         var p = db.GetPursheDetails(user.Login);
         PursheDetailsDataGrid.ItemsSource = p.ToList();
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Оплатить билеты
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PayTickets(object sender, RoutedEventArgs e)
        {
            string regNum  = @"\d\d\d\d";
            string regDate = @"\d\d";

            if (!Regex.IsMatch(PayNumberCardTextBox1.Text, regNum) ||
                !Regex.IsMatch(PayNumberCardTextBox2.Text, regNum) ||
                !Regex.IsMatch(PayNumberCardTextBox3.Text, regNum) ||
                !Regex.IsMatch(PayNumberCardTextBox4.Text, regNum))
            {
                MessageBox.Show("Неверный номер карты", Error);
            }
            else if (!Regex.IsMatch(PayMonthCardTextBox.Text, regDate) ||
                     !Regex.IsMatch(PayYearCardTextBox.Text, regDate) ||
                     int.Parse(PayMonthCardTextBox.Text) > 12 ||
                     int.Parse(PayMonthCardTextBox.Text) < 1)
            {
                MessageBox.Show("Неверная дата", Error);
            }
            else if (PayUserCardTextBox.Text == "")
            {
                MessageBox.Show("Укажите владельца карты", Error);
            }
            else if (!Regex.IsMatch(PayCVC2CardTextBox.Text, @"\d\d\d"))
            {
                MessageBox.Show("Неверный код CVC2", Error);
            }
            else
            {
                using (var db = new CinemaEntities())
                {
                    Purchases purchases = new Purchases()
                    {
                        Buyer         = user.Login,
                        Purchase_date = DateTime.Now
                    };
                    db.Purchases.Add(purchases);
                    foreach (var t in ListPlacesToBuy)
                    {
                        var o = from f in db.Tickets where f.Ticket_id == t.Ticket_id select f;
                        foreach (var p in o)
                        {
                            purchases.Tickets.Add(p);
                        }
                    }
                    db.SaveChanges();
                }
                MessageBox.Show("Билеты куплены");
                PayGrid.Visibility        = Visibility.Hidden;
                ListPosterGrid.Visibility = Visibility.Visible;
            }
        }
Exemplo n.º 9
0
 private Grid lastGrid;                                                           //чтобы возвразаться на последний грид
 public MainWindow()
 {
     InitializeComponent();
     LoadPosters();
     using (var db = new CinemaEntities())
     {
         var c = from f in db.Cinemas where f.Cinema_id == 1 select f;
         foreach (var c1 in c)
         {
             Cinema = c1;
         }
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// вывести сессии в окне настроек сессий
 /// </summary>
 private void LoadSessions()
 {
     ListSessions = new List <Sessions>();
     using (var db = new CinemaEntities())
     {
         var s = from f in db.Sessions where f.Film == film.Film_id select f;
         foreach (var ses in s)
         {
             ListSessions.Add(ses);
         }
     }
     SessionsDataGrid.ItemsSource = ListSessions;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Добавить сессию
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddSessionButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                decimal r    = decimal.Parse(AddSessionPriceTextBox.Text);
                int     hall = int.Parse(AddSessionHallComboBox.Text);
                foreach (var h in ListHalls)
                {
                    if (h.Hall_number == hall)
                    {
                        hall = h.Hall_id;
                    }
                    break;
                }
                Sessions sessions = new Sessions()
                {
                    Film         = film.Film_id,
                    Hall         = hall,
                    Price        = r,
                    Session_time = dateTime
                };

                ListSessions.Add(sessions);
                SessionsDataGrid.ItemsSource = null;
                SessionsDataGrid.ItemsSource = ListSessions;
                using (var db = new CinemaEntities())
                {
                    db.Sessions.Add(sessions);
                    db.SaveChanges();
                    var places = from f in db.Places where f.Hall == hall select f;
                    foreach (var place in places)
                    {
                        Tickets tickets = new Tickets()
                        {
                            Sessions = sessions,
                            Places   = place
                        };
                        db.Tickets.Add(tickets);
                    }
                    db.SaveChanges();
                }
                MessageBox.Show("Сеанс добавлен");
                AddSessionGrid.Visibility   = Visibility.Hidden;
                SessionSetupGrid.Visibility = Visibility.Visible;
            }
            catch (FormatException)
            {
                MessageBox.Show("Неверная цена", Error);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// изменение роли
        /// </summary>
        /// <param name="role"></param>
        private void ChangeUserRole(string role)
        {
            UserRole userRole = new UserRole();
            var      o        = UsersRoleDataGrid.SelectedCells;

            foreach (var l in o)
            {
                userRole = (UserRole)l.Item;
            }
            using (var db = new CinemaEntities())
            {
                var u = from f in db.Users where f.Login == userRole.Login select f;
                foreach (var u2 in u)
                {
                    u2.Role = role;
                    if (user.Login == u2.Login)
                    {
                        user.Role = role;
                    }
                }
                db.SaveChanges();
            }
        }
Exemplo n.º 13
0
 public SignIn()
 {
     InitializeComponent();
     db = new CinemaEntities();
 }
Exemplo n.º 14
0
        /// <summary>
        /// Регистрация нового посетителя
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RegistrationUserButton_Click(object sender, RoutedEventArgs e)
        {
            string login    = LoginRegistrationTextBox.Text.ToString();            //для более легкого обращения к введеному логину
            string password = PasswordRegistrationPasswordBox.Password.ToString(); //для более легкого обращения к введенному паролю

            if (login == "")
            {
                MessageBox.Show("Введите логин", Error);
            }
            else if (password == "")
            {
                MessageBox.Show("Введите пароль", Error);
            }
            else if (password.Length < 6)
            {
                MessageBox.Show("Пароль не должен быть короче 6 символов", Error);
            }
            else if (password != PasswordRegistration2PasswordBox.Password.ToString())
            {
                MessageBox.Show("Пароли не сопадают", Error);
            }
            else
            {
                using (var db = new CinemaEntities())
                {
                    bool enter = false; //существует ли логин в БД
                    foreach (var log in from f in db.Users select f)
                    {
                        if (log.Login.ToString() == login)
                        {
                            enter = true;
                            MessageBox.Show("Такой логин уже существует", Error);
                            break;
                        }
                    }
                    if (!enter)
                    {
                        user = new Users
                        {
                            Login    = login,
                            Password = password,
                            Role     = role.Visiter
                        };
                        if (LastNameRegistrationTextBox.Text.ToString() == "")
                        {
                            user.Last_name = null;
                        }
                        else
                        {
                            user.Last_name = LastNameRegistrationTextBox.Text.ToString();
                        }
                        if (FirstNameRegistrationTextBox.Text.ToString() == "")
                        {
                            user.First_name = null;
                        }
                        else
                        {
                            user.First_name = FirstNameRegistrationTextBox.Text.ToString();
                        }
                        db.Users.Add(user);
                        db.SaveChanges();
                        MessageBox.Show("Пользователь зарегистрирован.");

                        lastGrid.Visibility         = Visibility.Visible;
                        RegistrationGrid.Visibility = Visibility.Hidden;
                        ChangeVisibilityUserButtons();
                    }
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Переход на страницу выбора мест
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GoToChoosePlacesGrid(object sender, RoutedEventArgs e)
        {
            Button  button  = (Button)sender;
            Session session = (Session)button.DataContext;

            lastGrid = PlacesGrid;
            PlacesGrid.Visibility          = Visibility.Visible;
            FilmInformationGrid.Visibility = Visibility.Hidden;
            using (var db = new CinemaEntities())
            {
                var      ses      = from f in db.Sessions where f.Session_id == session.sessionId select f;
                Sessions sessions = new Sessions();
                foreach (var k in ses)
                {
                    sessions = k;
                    price    = k.Price;
                }
                AmountLabel.Content             = "0";
                AmountTickets                   = 0;
                ListChoosedPlacesTextBlock.Text = "";
                switch (sessions.Halls.Type_hall)
                {
                //одинаковые типы залы имеют одинаковую схему зала.
                case 1:
                {
                    listPlaces = new List <Place>();
                    foreach (var p in db.GetPlaces(session.sessionId))
                    {
                        Place place = new Place();
                        listPlaces.Add(place);
                        place.placeInfo = p;
                        place.label     = new Label()
                        {
                            Width  = 25,
                            Height = 25,
                            HorizontalAlignment        = HorizontalAlignment.Left,
                            VerticalAlignment          = VerticalAlignment.Top,
                            Foreground                 = Brushes.White,
                            Content                    = place.placeInfo.Place_number,
                            HorizontalContentAlignment = HorizontalAlignment.Center,
                            VerticalContentAlignment   = VerticalAlignment.Center,
                            Margin = new Thickness(50 + place.placeInfo.Place_number * 35, 325 - 35 * place.placeInfo.Row_number, 0, 0)
                        };
                        if (place.placeInfo.Ticket == null)
                        {
                            place.label.Background = Brushes.Green;
                        }
                        else
                        {
                            place.label.Background = Brushes.Red;
                        }
                        place.label.MouseLeftButtonUp += ChooseOnePlace;
                        PlacesGrid.Children.Add(place.label);
                    }
                    Label label = new Label()
                    {
                        Width                      = 25 * 8 + 70,
                        Height                     = 25,
                        Background                 = Brushes.LightGray,
                        HorizontalAlignment        = HorizontalAlignment.Left,
                        VerticalAlignment          = VerticalAlignment.Top,
                        HorizontalContentAlignment = HorizontalAlignment.Center,
                        VerticalContentAlignment   = VerticalAlignment.Center,
                        Content                    = "Экран",
                        Foreground                 = Brushes.Black,
                        Margin                     = new Thickness(85, 45 + 8 * 35, 0, 0)
                    };
                    PlacesGrid.Children.Add(label);
                    break;
                }
                }
            }
        }
Exemplo n.º 16
0
 public SignUp(Form mainForm)
 {
     InitializeComponent();
     MainForm = mainForm;
     db       = new CinemaEntities();
 }
Exemplo n.º 17
0
        /// <summary>
        /// Загрузка постеров фильмов на главный экран
        /// </summary>
        private void LoadPosters()
        {
            foreach (var p in PostersList)
            {
                PosterGrid.Children.Remove(p.Poster);
            }
            PostersList = new List <PosterClass>();
            using (var db = new CinemaEntities())
            {
                int i = -1;
                var q = from f in db.Films where f.Date_end > DateTime.Now select f;
                foreach (var v in q)
                {
                    i++;
                    System.Windows.Controls.Image image = new System.Windows.Controls.Image()
                    {
                        Width  = 150,
                        Height = 200,
                        Source = ImageWork.ByteArrayToImage(v.Poster),
                        Margin = new Thickness(0, 0, 0, 0),
                        HorizontalAlignment = HorizontalAlignment.Left,
                        VerticalAlignment   = VerticalAlignment.Top,
                        Stretch             = Stretch.Fill
                    };

                    TextBlock textBlock = new TextBlock()
                    {
                        Text                = v.Film_name,
                        FontSize            = 20,
                        Width               = 150,
                        HorizontalAlignment = HorizontalAlignment.Left,
                        VerticalAlignment   = VerticalAlignment.Top,
                        Margin              = new Thickness(0, 200, 0, 0),
                        TextWrapping        = TextWrapping.Wrap,
                        TextAlignment       = TextAlignment.Center
                    };

                    Grid grid = new Grid()
                    {
                        Width  = 150,
                        Height = 275,
                        HorizontalAlignment = HorizontalAlignment.Left,
                        VerticalAlignment   = VerticalAlignment.Top,
                        Margin = new Thickness(50 + 250 * (i % 3), 300 * (i / 3), 0, 0)
                    };
                    grid.MouseMove         += Poster_MouseMove;
                    grid.MouseLeave        += Poster_MouseLeave;
                    grid.MouseLeftButtonUp += Poster_MouseLeftButtonUp;

                    grid.Children.Add(image);
                    grid.Children.Add(textBlock);
                    PosterGrid.Children.Add(grid);
                    PosterClass pp = new PosterClass
                    {
                        film   = v,
                        Poster = grid
                    };
                    PostersList.Add(pp);
                }
            }
        }