Exemple #1
0
        public void Return()
        {
            try
            {
                Int32.Parse(_id);
            }
            catch (Exception e)
            {
                Thread errorParsing = new Thread(() => MessageBox.Show("Nie można przekonwertować ID. Wprowadź poprawne dane!"));
                errorParsing.Start();
                return;
            }
            int ID = Int32.Parse(_id);

            using (filmyEntities entities = new filmyEntities())
            {
                var movie_instance = entities.Movie_Instance.Find(ID);
                if (movie_instance.Is_Rented == false)
                {
                    Thread notRented = new Thread(() => MessageBox.Show("Film nie jest wypożyczony"));
                    notRented.Start();
                    return;
                }
                movie_instance.Is_Rented = false;
                entities.SaveChanges();
                Thread returned = new Thread(() => MessageBox.Show("Film został zwrócony"));
                returned.Start();
                return;
            }
        }
Exemple #2
0
        public void Calculate()
        {
            try
            {
                Int32.Parse(_id);
            }
            catch (Exception e)
            {
                Thread errorParsing = new Thread(() => MessageBox.Show("Nie można przekonwertować ID. Wprowadź poprawne dane!"));
                errorParsing.Start();
                return;
            }
            int ID = Int32.Parse(_id);

            using (filmyEntities entities = new filmyEntities())
            {
                var transaction = entities.Transactions.OrderByDescending(e => e.rental_date)
                                  .FirstOrDefault(e => e.FK_ID_Movie_Instance == ID);
                if (transaction == null)
                {
                    Thread errorNoTransaciton = new Thread(() => MessageBox.Show("Transakcja nie została znaleziona!"));
                    errorNoTransaciton.Start();
                    return;
                }
                DateTime rentedTime = transaction.rental_date.Value;
                if (rentedTime == DateTime.MinValue)
                {
                    Thread errorNotRented = new Thread(() => MessageBox.Show("Film nie jest wypożyczony!"));
                    errorNotRented.Start();
                    return;
                }
                var instance = entities.Movie_Instance.Find(ID);
                if (instance.Is_Rented.Value == false)
                {
                    Thread notRented = new Thread(() => MessageBox.Show("Film nie jest wypożyczony!"));
                    notRented.Start();
                    return;
                }
                int movieID        = instance.FK_ID_Movie.Value;
                var movie          = entities.Movie.Find(movieID);
                var rentedTimeDiff = DateTime.Now - rentedTime;
                int overTime       = (int)rentedTimeDiff.TotalMinutes - 60 * 24 * 7;
                if (overTime <= 0)
                {
                    MessageBox.Show("Film: " + movie.Title + "\nDo zapłaty: " + movie.Price + "zł");
                    return;
                }
                else
                {
                    int penalty = movie.Penalty.Value * (overTime / 60 * 24 * 7 + 1);
                    MessageBox.Show("Film: " + movie.Title + "\nDo zapłaty: " + movie.Price + "zł\n" + "Kara za przetrzymanie: " + penalty);
                    return;
                }
            }
        }
Exemple #3
0
 public void RentMovie()
 {
     try
     {
         Int32.Parse(_userId);
         Int32.Parse(_movieId);
     }
     catch (Exception e)
     {
         Thread badData = new Thread(() => MessageBox.Show("Wprowadzono niepoprawne dane!"));
         badData.Start();
         return;
     }
     using (filmyEntities entities = new filmyEntities())
     {
         int userID   = Int32.Parse(_userId);
         int movieID  = Int32.Parse(_movieId);
         var instance = entities.Movie_Instance.Find(movieID);
         var user     = entities.Client.Find(userID);
         if (user == null)
         {
             Thread badData2 = new Thread(() => MessageBox.Show("Użytkownik o podanym ID nie istnieje!"));
             badData2.Start();
             return;
         }
         if (instance == null)
         {
             Thread badData21 = new Thread(() => MessageBox.Show("Płyta o podanym ID nie istnieje!"));
             badData21.Start();
             return;
         }
         if (instance.Is_Rented == true)
         {
             Thread badData3 = new Thread(() => MessageBox.Show("Ta kopia filmu jest już wypożyczona!"));
             badData3.Start();
             return;
         }
         Transactions newTransaction = new Transactions();
         newTransaction.FK_ID_Movie_Instance = instance.ID_Movie_Instance;
         newTransaction.FK_ID_Clients        = user.ID_client;
         newTransaction.rental_date          = DateTime.Now;
         instance.Is_Rented = true;
         //entities.Movie_Instance.
         //entities.Movie_Instance.AddOrUpdate(instance);
         entities.Transactions.Add(newTransaction);
         entities.SaveChanges();
         Thread badData4 = new Thread(() => MessageBox.Show("Film został wypożyczony!"));
         badData4.Start();
     }
 }
Exemple #4
0
 private void LoadStatistics()
 {
     using (filmyEntities entities = new filmyEntities())
     {
         var x = entities.TopFilm().ToList();
         if (x == null)
         {
             MessageBox.Show("Brak statystyk do wyświetlenia");
             this.Close();
         }
         stats  = "Najczęściej wypożyczany film: " + x[0].Title;
         stats += "\r\nZostał wypożyczony " + x[0].Count.ToString() + " razy";
     }
     textBoxStats.Text = stats;
 }
Exemple #5
0
        public AddNewUser(string name, string surname, string PESEL, string Street, string City, string PostNumber, int HouseNum, int FlatNum)
        {
            Client client = new Client();

            client.Name         = name;
            client.Surname      = surname;
            client.PESEL        = PESEL;
            client.street       = Street;
            client.city         = City;
            client.post_number  = PostNumber;
            client.house_number = HouseNum;
            client.flat_number  = FlatNum;
            using (filmyEntities f = new filmyEntities())
            {
                if (f.Client.FirstOrDefault(c => c.PESEL == client.PESEL) != null)
                {
                    MessageBox.Show("Klient z numerem PESEL " + client.PESEL + " jest już zarejestrowany", "Klient istnieje");
                    return;
                }
                f.Client.Add(client);
                f.SaveChanges();
                MessageBox.Show("Klient " + client.Name + " " + client.Surname + " dodany.\nNumer ID klienta: " + client.ID_client, "Klient dodany");
            }
        }