Example #1
0
        private void przyciskDodajKategorie_Click(object sender, RoutedEventArgs e)
        {
            using (var ctx = new bazaEntities())
            {
                bool czyPoprawna = true;
                var nazwa = inputDodajKategorie.Text;

                if (nazwa == "")
                {
                    czyPoprawna = false;
                    MessageBox.Show("Nie podano nazwy");
                }

                if (czyPoprawna)
                {
                    ctx.Category.Add(new Category
                    {
                        Name = nazwa,
                    });

                    ctx.SaveChanges();
                    MessageBox.Show("Dodano kategorię");
                }
            }
        }
Example #2
0
        private void ZaladujFilmy()
        {
            using (var ctx = new bazaEntities())
            {
                foreach (var item in ctx.Film)
                {
                    var nazwaKategoria = ctx.Category.Single(x => x.ID == item.CategoryID);
                    var nazwaAktor     = ctx.Actor.Single(x => x.ID == item.ActorID);
                    var nazwaRezyser   = ctx.Director.Single(x => x.ID == item.DirectorID);

                    listaFilmow.AppendText(
                        $"{item.Title} == {item.ProductionYear.ToShortDateString()} == {item.Prizes} == " +
                        $"{nazwaKategoria.Name} == {nazwaAktor.FirstName} {nazwaAktor.LastName} == {nazwaRezyser.FirstName} " +
                        $"{nazwaRezyser.LastName}\n");
                }
            }
        }
Example #3
0
        private void przyciskDodajReżysera_Click(object sender, RoutedEventArgs e)
        {
            using (var ctx = new bazaEntities())
            {
                bool czyPoprawne = true;
                var daneRezysera = inputDodajRezysera.Text;
                var dane = daneRezysera.Split(' ');
                if(dane.Length != 3)
                {
                    czyPoprawne = false;
                    MessageBox.Show("Niewłaściwe dane reżyser");
                }
                    string imie = "";
                string nazwisko = "";
                string rodzaj = "";

                imie = dane[0];
                nazwisko = dane[1];
                rodzaj = "Rezyser " + dane[2];

                if (imie == "" || nazwisko == "" || rodzaj == "")
                {
                    czyPoprawne = false;
                    MessageBox.Show("Niewłaściwe dane reżyser");
                }

                if (czyPoprawne)
                {
                    ctx.Director.Add(new Director
                    {
                        FirstName = imie,
                        LastName = nazwisko,
                        DirectorType = rodzaj,
                    });

                    ctx.SaveChanges();
                    MessageBox.Show("Dodano reżysera");
                }
            }
        }
Example #4
0
        private void przyciskDodajAktora_Click(object sender, RoutedEventArgs e)
        {
            using (var ctx = new bazaEntities())
            {
                bool czyPoprawne = true;
                var nazwaAktora = inputDodajAktora.Text;
                var dane = nazwaAktora.Split(' ');

                string imie = "";
                string nazwisko = "";

                if (dane.Length != 2 )
                {
                    MessageBox.Show("Niewłaściwe dane aktor");
                    czyPoprawne = false;
                }
                else
                {
                    imie = dane[0];
                    nazwisko = dane[1];
                }
                if (imie == "" || nazwisko == "")
                {
                    MessageBox.Show("Niewłaściwe dane aktor");
                    czyPoprawne = false;
                }

                if (czyPoprawne)
                {
                    ctx.Actor.Add(new Actor
                    {
                        FirstName = imie,
                        LastName = nazwisko,
                    });

                    ctx.SaveChanges();
                    MessageBox.Show("Dodano aktora");
                }
            }
        }
Example #5
0
        private void przyciskDodajFilm_Click(object sender, RoutedEventArgs e)
        {
            bool czyPoprawny = true;
            string tytulFilmu = inputFilmTytul.Text;
            string dataFilmu = inputFilmRokProduckji.SelectedDate.Value.ToShortDateString();
            string nagrodyFilmu = inputFilmNagrody.Text;
            string kategoriaFilmu = inputFilmKategoria.Text;
            string glownyAktorFilmu = inputFilmAktor.Text;
            string rezyserFilmu = inputFilmRezyser.Text;

            if (tytulFilmu == "" || dataFilmu == "" || nagrodyFilmu == "" || kategoriaFilmu == "" ||
                glownyAktorFilmu == "" || rezyserFilmu == "")
            {
                czyPoprawny = false;
                MessageBox.Show("Nie wypełniono wszystkich wymaganych pól");
            }

            string imieAktor = "";
            string nazwiskoAktor = "";

            string[] daneAktora = glownyAktorFilmu.Split(' ');
            if (daneAktora.Length == 2)
            {
                imieAktor = daneAktora[0];
                nazwiskoAktor = daneAktora[1];
            }
            else
            {
                MessageBox.Show("Nieprawidłowy aktor");
            }

            string imieRezyser = "";
            string nazwiskoRezyser = "";
            string rodzajRezyser = "";

            string[] daneRezysera = rezyserFilmu.Split(' ');
            if (daneRezysera.Length == 3)
            {
                imieRezyser = daneRezysera[0];
                nazwiskoRezyser = daneRezysera[1];
                rodzajRezyser = "Rezyser " + daneRezysera[2];
            }

            if (czyPoprawny)
            {
                using (var ctx = new bazaEntities())
                {
                    bool czyJestPowiazanie = true;

                    var kategoria = ctx.Category.SingleOrDefault(x => x.Name == kategoriaFilmu);
                    var aktor = ctx.Actor.SingleOrDefault(x => x.FirstName == imieAktor && x.LastName == nazwiskoAktor);
                    var rezyser = ctx.Director.SingleOrDefault(x => x.FirstName == imieRezyser && x.LastName == nazwiskoRezyser &&
                    x.DirectorType == rodzajRezyser);

                    if (kategoria == null || aktor == null || rezyser == null) czyJestPowiazanie = false;

                    if (czyJestPowiazanie)
                    {
                        ctx.Film.Add(new Film
                        {
                            Title = tytulFilmu,
                            ProductionYear = Convert.ToDateTime(dataFilmu),
                            Prizes = nagrodyFilmu,
                            CategoryID = kategoria.ID,
                            ActorID = aktor.ID,
                            DirectorID = rezyser.ID,
                        });

                        ctx.SaveChanges();
                        MessageBox.Show("Dodano nowy film do bazy");
                    }

                }
            }
        }