Example #1
0
 private void tickevent(object sender, EventArgs e)
 {
     try
     {
         using (KinoContext db = new KinoContext())
             filmrating.Text = ($"{db.Films.First(x => x.Id == selectedfilm.Id).PremierDate.ToString("d")}  ({days} : {hours.ToString("00")} : {minutes.ToString("00")} : {seconds.ToString("00")})");
     }
     catch { }
     if (seconds - 1 >= 0)
     {
         seconds--;
     }
     else if (minutes - 1 >= 0)
     {
         seconds = 59;
         minutes--;
     }
     else if (hours - 1 >= 0)
     {
         minutes = 59;
         seconds = 59;
         hours--;
     }
     else
     {
         hours = 23;
         days--;
     }
 }
        private void datesList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                using (KinoContext db = new KinoContext())
                {
                    var seldate = DateTime.Parse(datesList.SelectedValue.ToString());
                    date     = db.Dates.First(x => x.Title == seldate);
                    filmdate = db.FilmsDates.First(x => x.FilmId == film.Id && x.DateId == date.Id);

                    var seances   = db.FilmsDatesSeances.Where(x => x.FilmsDatesId == filmdate.Id).Select(x => x.SeanceId).ToArray();
                    var seancess  = db.Seances.Where(x => seances.Contains(x.Id)).Select(x => x.Title).ToList();
                    var seancesss = new List <string>();

                    foreach (var x in seancess)
                    {
                        var temp = ((DateTime)x).ToString("t");
                        seancesss.Add(temp);
                    }

                    seancesList.ItemsSource = seancesss;
                }
            }
            catch (Exception) { }
        }
Example #3
0
        public void FilmRefresh()
        {
            time2 = films.First(x => x.Id == selectedfilm.Id).PremierDate;

            timer.Stop();
            timer = new DispatcherTimer();
            StartClock();

            try
            {
                using (KinoContext db = new KinoContext())
                {
                    filmname.Text        = films.First(x => x.Id == selectedfilm.Id).Name;
                    filmcountry.Text     = films.First(x => x.Id == selectedfilm.Id).Country;
                    filmdescription.Text = films.First(x => x.Id == selectedfilm.Id).Description;
                    filmslogan.Text      = films.First(x => x.Id == selectedfilm.Id).Slogan;
                    filmcountry.Text     = films.First(x => x.Id == selectedfilm.Id).Country;
                    filmcountry.Text     = films.First(x => x.Id == selectedfilm.Id).Country;
                    poster.Source        = ToImage(films.First(x => x.Id == selectedfilm.Id).PosterByte);
                    var           genres  = db.FilmsGenres.Where(x => x.FilmId == selectedfilm.Id).Select(x => x.GenreId).ToArray();
                    var           genress = db.Genres.Where(x => genres.Contains(x.Id)).Select(x => x.Name);
                    StringBuilder s       = new StringBuilder();

                    foreach (var x in genress)
                    {
                        s.Append(x + ", ");
                    }
                    s.Remove(s.Length - 2, 2);

                    filmgenres.Text = s.ToString();
                }
            }
            catch { }
        }
 private void WatchTrailer(object sender, RoutedEventArgs e)
 {
     using (KinoContext db = new KinoContext())
     {
         Process.Start(db.Films.First(x => x.Id == film.Id).Trailer);
     }
 }
Example #5
0
        public int Registration(string FirstName, string LastName, string Login, string Password, string Email)
        {
            using (KinoContext db = new KinoContext())
            {
                Random rnd = new Random();
                number = rnd.Next(1000, 9999);

                if (db.Users.Where(x => x.Email == Email).Count() != 0)
                {
                    return(2);
                }

                else if (db.Users.Where(x => x.Login == Login).Count() != 0 || db.Admins.Where(x => x.Login == Login).Count() != 0)
                {
                    return(1);
                }

                else
                {
                    user = new User {
                        FirstName = FirstName, LastName = LastName, Login = Login, Password = Password, Email = Email
                    };
                    SendMail("Код подтверждения регистрации: " + number, Email);
                    return(number);
                }
            }
        }
Example #6
0
        private void DeleteOrder(object sender, RoutedEventArgs e)
        {
            Booking selectedbooking = (Booking)bookingsGrid.SelectedItem;

            using (KinoContext db = new KinoContext())
            {
                var film = db.Films.First(x => x.Name == selectedbooking.Film);
                db.ReservationPlaces.RemoveRange(db.ReservationPlaces.Where(x => x.CodeId == selectedbooking.Code));
                db.ReservationCodes.Remove(db.ReservationCodes.First(x => x.Code == selectedbooking.Code));
                db.Notifications.Add(new Notification {
                    Message = $"Привет, {user.FirstName}!\nВы отменили бронирование №{selectedbooking.Code} на сумму {selectedbooking.TotalCost} грн.\n\nФильм: {film.Name}\nДата: {selectedbooking.Date}\nСеанс:  {selectedbooking.Time}", Time = $"{DateTime.Now.Day.ToString("00")}.{DateTime.Now.Month.ToString("00")}\n{DateTime.Now.Hour.ToString("00")}:{DateTime.Now.Minute.ToString("00")}", UserId = user.Id
                });

                db.SaveChanges();
                MessageBox.Show("Бронирование успешно удалено.");
            }

            try
            {
                bookingsGrid.SelectedItem = bookings.ElementAt(0);
            }
            catch { }

            BookingsGridRefresh();
        }
Example #7
0
 private void Clear(object sender, RoutedEventArgs e)
 {
     using (KinoContext db = new KinoContext())
     {
         db.Notifications.RemoveRange(db.Notifications.Where(x => x.UserId == main.user.Id));
         db.SaveChanges();
         UpdateList();
     }
 }
Example #8
0
 private void ChangeLogin(object sender, RoutedEventArgs e)
 {
     using (KinoContext db = new KinoContext())
     {
         db.Users.First(x => x.Id == user.Id).Login = login.Text;
         db.SaveChanges();
         MessageBox.Show("Логин успешно изменен.");
     }
 }
 public void filmsGridRefresh()
 {
     using (KinoContext db = new KinoContext())
     {
         db.Films.Where(x => x.IsPremiere == false).Load();
         filmsGrid.ItemsSource = db.Films.Local.ToBindingList();
     }
     back.Visibility = Visibility.Collapsed;
 }
Example #10
0
 private void ChangeLastName(object sender, RoutedEventArgs e)
 {
     using (KinoContext db = new KinoContext())
     {
         db.Users.First(x => x.Id == user.Id).LastName = lastname.Text;
         db.SaveChanges();
         MessageBox.Show("Фамилия успешно изменена.");
     }
 }
        public DateSeancesControl(MainWindow main, Seancess seancess, Film film)
        {
            InitializeComponent();
            genres        = new List <Genre>();
            this.main     = main;
            this.seancess = seancess;
            this.film     = film;
            datesname     = new List <DateMy>();
            seancesname   = new List <SeanceMy>();
            currentdate   = new List <SeanceMy>();

            using (KinoContext db = new KinoContext())
            {
                List <int> datesids  = new List <int>();
                var        filmdates = db.FilmsDates.Where(x => x.FilmId == film.Id);

                foreach (var x in filmdates.ToList())
                {
                    datesids.Add((int)x.DateId);
                }

                foreach (var x in datesids.ToList())
                {
                    var newdate = db.Dates.First(d => d.Id == x).Title;
                    datesname.Add(new DateMy {
                        Title = newdate.ToString("d"), InFormat = newdate
                    });
                    datesGrid.ItemsSource = null;
                    datesGrid.ItemsSource = datesname;
                }


                foreach (var x in filmdates.ToList())
                {
                    int dateid   = (int)x.DateId;
                    var currdate = (DateTime)(db.Dates.Find(dateid).Title);

                    List <int> seancesids       = new List <int>();
                    var        filmdatesseances = db.FilmsDatesSeances.Where(f => f.FilmsDatesId == x.Id);

                    foreach (var f in filmdatesseances)
                    {
                        seancesids.Add((int)f.SeanceId);
                    }

                    foreach (var s in seancesids.ToList())
                    {
                        var newseance = db.Seances.First(d => d.Id == s).Title;
                        seancesname.Add(new SeanceMy {
                            Title = newseance.ToString("t"), InFormat = currdate, SeanceInFormat = newseance
                        });
                    }
                }
            }
        }
        public void Update(object ob)
        {
            Film film = (Film)ob;

            using (KinoContext db = new KinoContext())
            {
                db.Notifications.Add(new Notification {
                    Message = $"Привет, {this.FirstName}!\nФильм {film.Name} уже в прокате, проверьте вкладку \"Сеансы\".\nУспейте забронировать билет!", Time = $"{DateTime.Now.Day.ToString("00")}.{DateTime.Now.Month.ToString("00")}\n{DateTime.Now.Hour.ToString("00")}:{DateTime.Now.Minute.ToString("00")}", UserId = this.Id
                });
                db.SaveChanges();
            }
        }
 public void DeleteOrder(Booking booking)
 {
     using (KinoContext db = new KinoContext())
     {
         var reserv = db.ReservationCodes.First(x => x.Code == booking.Code);
         db.ReservationPlaces.RemoveRange(db.ReservationPlaces.Where(x => x.CodeId == booking.Code));
         db.ReservationCodes.Remove(db.ReservationCodes.Find(reserv.Id));
         db.SaveChanges();
     }
     main.RefreshBookings();
     BookingsGridRefresh();
 }
Example #14
0
        public ZalControl(Seancess seancess)
        {
            InitializeComponent();

            panels        = main.Children.OfType <StackPanel>();
            this.seancess = seancess;

            if (seancess.main.user == null)
            {
                order.Content = "Сохранить";
            }

            using (KinoContext db = new KinoContext())
            {
                if (seancess.main.user != null)
                {
                    firstf.IsReadOnly   = true;
                    secondf.IsReadOnly  = true;
                    thirdf.IsReadOnly   = true;
                    fourthf.IsReadOnly  = true;
                    fifthf.IsReadOnly   = true;
                    sixf.IsReadOnly     = true;
                    seventhf.IsReadOnly = true;
                    eighthf.IsReadOnly  = true;
                }

                firstf.Text   = db.Prices.First(x => x.Range == 1).Cost.ToString();
                secondf.Text  = db.Prices.First(x => x.Range == 2).Cost.ToString();
                thirdf.Text   = db.Prices.First(x => x.Range == 3).Cost.ToString();
                fourthf.Text  = db.Prices.First(x => x.Range == 4).Cost.ToString();
                fifthf.Text   = db.Prices.First(x => x.Range == 5).Cost.ToString();
                sixf.Text     = db.Prices.First(x => x.Range == 6).Cost.ToString();
                seventhf.Text = db.Prices.First(x => x.Range == 7).Cost.ToString();
                eighthf.Text  = db.Prices.First(x => x.Range == 8).Cost.ToString();
            }


            foreach (var x in panels)
            {
                var grids = x.Children.OfType <Grid>();

                foreach (var y in grids)
                {
                    var buttons = y.Children.OfType <Button>();

                    foreach (var z in buttons)
                    {
                        z.Style = (Style)FindResource("RoundCorner");
                    }
                }
            }
        }
Example #15
0
        private void save_Click(object sender, RoutedEventArgs e)
        {
            using (KinoContext db = new KinoContext())
            {
                db.Films.First(x => x.Id == selectedfilm.Id).IsPremiere = false;
                db.SaveChanges();
                selectedfilm.ChangeState();
            }

            main.GridPrincipal.Children.Clear();
            main.GridPrincipal.Children.Add(new NewFilmControl(main, new Seancess(main), selectedfilm, true));
            main.title.Text = "Добавление фильма в сеансы";
        }
Example #16
0
        private void DeleteFilm(object sender, RoutedEventArgs e)
        {
            using (KinoContext db = new KinoContext())
            {
                db.Subscriptions.RemoveRange(db.Subscriptions.Where(x => x.FilmId == selectedfilm.Id));
                db.FilmsGenres.RemoveRange(db.FilmsGenres.Where(x => x.FilmId == selectedfilm.Id));
                db.Films.Remove(db.Films.First(x => x.Id == selectedfilm.Id));
                db.SaveChanges();
                films        = db.Films.Where(x => x.IsPremiere == true).ToList();
                selectedfilm = db.Films.First(x => x.IsPremiere == true);
            }

            FilmRefresh();
        }
Example #17
0
 private void code_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (code.Text == randcode.ToString())
     {
         using (KinoContext db = new KinoContext())
         {
             db.Users.First(x => x.Id == user.Id).Email = email.Text;
             db.SaveChanges();
         }
         MessageBox.Show("E-mail успешно изменен.");
         code.Visibility   = Visibility.Collapsed;
         submit.Visibility = Visibility.Collapsed;
     }
 }
        private void filmsGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            datesList.SelectedItem   = null;
            datesList.ItemsSource    = null;
            seancesList.SelectedItem = null;
            seancesList.ItemsSource  = null;
            film = (Film)filmsGrid.SelectedItem;

            try
            {
                using (KinoContext db = new KinoContext())
                {
                    film                 = (Film)filmsGrid.SelectedItem;
                    filmslogan.Text      = film.Slogan;
                    poster.Source        = ToImage(db.Films.First(x => x.Id == film.Id).PosterByte);
                    filmname.Text        = film.Name;
                    filmcountry.Text     = film.Country;
                    filmrating.Text      = $"IMDb: {film.RatingIMDb}   Кинопоиск: {film.RatingKinopoisk}";
                    filmdescription.Text = film.Description;

                    var           genres  = db.FilmsGenres.Where(x => x.FilmId == film.Id).Select(x => x.GenreId).ToArray();
                    var           genress = db.Genres.Where(x => genres.Contains(x.Id)).Select(x => x.Name);
                    StringBuilder s       = new StringBuilder();

                    foreach (var x in genress)
                    {
                        s.Append(x + ", ");
                    }
                    s.Remove(s.Length - 2, 2);


                    filmgenres.Text = s.ToString();

                    var dates   = db.FilmsDates.Where(x => x.FilmId == film.Id).Select(x => x.DateId).ToArray();
                    var datess  = db.Dates.Where(x => dates.Contains(x.Id)).Select(x => x.Title).ToList();
                    var datesss = new List <string>();

                    foreach (var x in datess)
                    {
                        var temp = ((DateTime)x).ToString("d");
                        datesss.Add(temp);
                    }

                    datesList.ItemsSource = datesss;
                }
            }
            catch (Exception) { }
        }
Example #19
0
        public void Update()
        {
            using (KinoContext db = new KinoContext())
            {
                allfilms = db.Films.ToList();

                foreach (var x in allfilms.ToList())
                {
                    var subs = db.Subscriptions.Where(s => s.FilmId == x.Id);
                    foreach (var s in subs.ToList())
                    {
                        x.RegisterObserver(db.Users.First(u => u.Id == s.UserId));
                    }
                }
            }
        }
Example #20
0
 public bool FinalRegistration(int number)
 {
     if (this.number == number)
     {
         using (KinoContext db = new KinoContext())
         {
             db.Users.Add(user);
             db.SaveChanges();
             return(true);
         }
     }
     else
     {
         return(false);
     }
 }
Example #21
0
 private void ChangePassword(object sender, RoutedEventArgs e)
 {
     using (KinoContext db = new KinoContext())
     {
         if (db.Users.First(x => x.Id == user.Id).Password == oldpass.Password && newpass.Password == newpass2.Password)
         {
             db.Users.First(x => x.Id == user.Id).Password = newpass.Password;
             db.SaveChanges();
             MessageBox.Show("Пароль успешно изменен.");
         }
         else
         {
             MessageBox.Show("Что-то пошло не так.");
         }
     }
 }
        public void Start(Film film, MainWindow main)
        {
            genres    = new List <Genre>();
            this.main = main;
            this.film = film;

            if (edit)
            {
                filmtitle.Text       = film.Name;
                filmdescription.Text = film.Description;
                filmcountry.Text     = film.Country;
                filmIMDb.Text        = film.RatingIMDb.ToString();
                filmKinopoisk.Text   = film.RatingKinopoisk.ToString();

                filmslogan.Text = film.Slogan;
                trailer.Text    = film.Trailer;

                using (KinoContext db = new KinoContext())
                {
                    try
                    {
                        filmpremier.Text  = db.Films.First(x => x.Id == film.Id).PremierDate.ToString("d");
                        filmposter.Source = ToImage(db.Films.First(x => x.Id == film.Id).PosterByte);
                    }
                    catch { }

                    var        filmgenres = db.FilmsGenres;
                    List <int> genresids  = new List <int>();

                    foreach (var x in filmgenres)
                    {
                        if (x.FilmId == film.Id)
                        {
                            genresids.Add((int)x.GenreId);
                        }
                    }

                    foreach (var x in genresids)
                    {
                        genres.Add(db.Genres.Find(x));
                    }

                    genresGrid.ItemsSource = null;
                    genresGrid.ItemsSource = genres;
                }
            }
        }
Example #23
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            RenderTargetBitmap bmp = new RenderTargetBitmap(498, 424, 96, 96, PixelFormats.Pbgra32);

            bmp.Render(this);

            var encoder = new PngBitmapEncoder();

            encoder.Frames.Add(BitmapFrame.Create(bmp));

            using (KinoContext db = new KinoContext())
            {
                using (Stream stm = File.Create(path + "\\" + dir + "\\Билет №" + number + ".png"))
                    encoder.Save(stm);
            }
            this.Close();
        }
        private void SaveFilm(object sender, RoutedEventArgs e)
        {
            SaveFilm();
            using (KinoContext db = new KinoContext())
            {
                main.allfilms = db.Films.ToList();

                foreach (var x in main.allfilms.ToList())
                {
                    var subs = db.Subscriptions.Where(s => s.FilmId == x.Id);
                    foreach (var s in subs.ToList())
                    {
                        x.RegisterObserver(db.Users.First(u => u.Id == s.UserId));
                    }
                }
            }
        }
        public void PlacesGridRefresh()
        {
            try
            {
                Booking currbooking = (Booking)bookingsGrid.SelectedItem;
                placesGrid.ItemsSource = null;
                placesGrid.ItemsSource = currbooking.places;

                var filmname = currbooking.Film;
                Film film;

                using (KinoContext db = new KinoContext())
                {
                    film = db.Films.First(x => x.Name == filmname);
                }
                filmposter.Source = ToImage(film.PosterByte);
            }
            catch { }
        }
 private void seancesList_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         using (KinoContext db = new KinoContext())
         {
             seance = new Seance();
             foreach (var x in db.Seances)
             {
                 if (x.Title.ToString().Contains(seancesList.SelectedValue.ToString()) == true)
                 {
                     seance = x;
                     break;
                 }
             }
             filmdateseance = db.FilmsDatesSeances.First(x => x.FilmsDatesId == filmdate.Id && x.SeanceId == seance.Id);
         }
     }
     catch (Exception) { }
 }
Example #27
0
        private void bookingsGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                Booking currbooking = (Booking)bookingsGrid.SelectedItem;
                placesGrid.ItemsSource = null;
                placesGrid.ItemsSource = currbooking.places;

                var  filmname = currbooking.Film;
                Film film;

                using (KinoContext db = new KinoContext())
                {
                    film = db.Films.First(x => x.Name == filmname);
                }

                filmposter.Source = ToImage(film.PosterByte);
            }
            catch { }
        }
Example #28
0
        private void ChangePath(object sender, RoutedEventArgs e)
        {
            OpenFileDialog folderBrowser = new OpenFileDialog();

            folderBrowser.ValidateNames   = false;
            folderBrowser.CheckFileExists = false;
            folderBrowser.CheckPathExists = true;
            folderBrowser.FileName        = "Folder Selection.";

            if (folderBrowser.ShowDialog() == true)
            {
                string folderPath = System.IO.Path.GetDirectoryName(folderBrowser.FileName);
                path.Text = folderPath;

                using (KinoContext db = new KinoContext())
                {
                    db.Users.First(x => x.Id == user.Id).PathForTickets = path.Text;
                    db.SaveChanges();
                }
            }
        }
        private void TicketsSold(object sender, RoutedEventArgs e)
        {
            Booking booking = (Booking)bookingsGrid.SelectedItem;

            using (KinoContext db = new KinoContext())
            {
                var reserv = db.ReservationCodes.First(x => x.Code == booking.Code);

                var places = db.ReservationPlaces.Where(x => x.CodeId == reserv.Id);
                
                foreach (var x in places.ToList())
                {
                    db.SoldPlaces.Add(new SoldPlace { FilmDateSeanceId = booking.FDS, Place = x.Place, Range = x.Range });
                    db.SaveChanges();
                }

                DeleteOrder(booking);
            }
            main.RefreshBookings();
            BookingsGridRefresh();

            MessageBox.Show("Бронь успешно подтверждена.");
        }
Example #30
0
        public IPerson Auth(string login, string password)
        {
            using (KinoContext db = new KinoContext())
            {
                IPerson person;
                try
                {
                    person = db.Users.First(x => (x.Login == login || x.Email == login && x.Password == password));
                }
                catch (Exception) { person = null; };

                if (person == null)
                {
                    try
                    {
                        person = db.Admins.First(x => (x.Login == login && x.Password == password));
                    }
                    catch (Exception) { person = null; }
                }

                return(person);
            }
        }