Exemple #1
0
 public List <Film> wijzigDb(List <Film> filmList, int klantNr)
 {
     using (var entities = new VideoVerhuurEntities())
     {
         List <Film> gewijzigdeFilms = new List <Film>();
         foreach (var item in filmList)
         {
             Film film = entities.Films.Find(item.BandNr);
             if (film.InVoorraad > 0)
             {
                 film.InVoorraad  -= 1;
                 film.UitVoorraad += 1;
                 Verhuur verhuur = new Verhuur
                 {
                     KlantNr = klantNr,
                     BandNr  = item.BandNr
                 };
                 gewijzigdeFilms.Add(film);
                 entities.Verhuur.Add(verhuur);
             }
         }
         entities.SaveChanges();
         return(gewijzigdeFilms);
     }
 }
        public bool InsertVerhuur(Verhuur verhuur)
        {
            using (SqlConnection connection = Database.Connection)
            {
                string query = "INSERT INTO VERHUUR (AccountID, ExemplaarID, DatumBegin, DatumEind) VALUES (@accountid, @exemplaarid, @datumbegin, @datumeind)";

                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    command.Parameters.AddWithValue("@exemplaarid", verhuur.Exemplaar.ExemplaarID);
                    command.Parameters.AddWithValue("@accountid", verhuur.Account.ID);
                    command.Parameters.AddWithValue("@datumbegin", verhuur.DatumBegin);
                    command.Parameters.AddWithValue("@datumeind", verhuur.DatumEind);

                    try
                    {
                        command.ExecuteNonQuery();
                    }
                    catch (SqlException)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
        public bool Update(Verhuur verhuur)
        {
            using (SqlConnection connection = Connection.SQLconnection)
            {
                string query = "UPDATE Verhuur SET productexemplaar_id = @productExempID, res_pb_id = @respbid, datumIn = @datumIn, datumUit = @datumUit, prijs = @prijs, betaald = @betaald WHERE id = @ID";

                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    command.Parameters.AddWithValue("@ID", verhuur.Id);
                    command.Parameters.AddWithValue("@productExempID", verhuur.ProdcutExemplaar_id);
                    command.Parameters.AddWithValue("@respbid", verhuur.Res_pb_id);
                    command.Parameters.AddWithValue("@datumIn", verhuur.DatumIn);
                    command.Parameters.AddWithValue("@datumUit", verhuur.DatumUit);
                    command.Parameters.AddWithValue("@prijs", verhuur.Prijs);
                    command.Parameters.AddWithValue("@betaald", verhuur.Betaald);


                    try
                    {
                        command.ExecuteNonQuery();
                        return(true);
                    }
                    catch
                    {
                    }
                }
            }

            return(false);
        }
        public void Insert(Verhuur verhuur)
        {
            try
            {
                using (SqlConnection connection = Connection.SQLconnection)
                {
                    string query = "INSERT INTO Reservering (productexemplaar_id, res_pb_id, datumIn, datumUit, prijs, betaald) VALUES (@productExempID, @respbid, @datumIn,@datumUit,@prijs,@betaald)";



                    using (SqlCommand command = new SqlCommand(query, connection))
                    {
                        command.Parameters.AddWithValue("@productExempID", verhuur.ProdcutExemplaar_id);
                        command.Parameters.AddWithValue("@respbid", verhuur.Res_pb_id);
                        command.Parameters.AddWithValue("@datumIn", verhuur.DatumIn);
                        command.Parameters.AddWithValue("@datumUit", verhuur.DatumUit);
                        command.Parameters.AddWithValue("@prijs", verhuur.Prijs);
                        command.Parameters.AddWithValue("@betaald", verhuur.Betaald);

                        command.ExecuteNonQuery();
                    }
                }
            }

            catch
            {
            }
        }
        private void BtnBewaren_Click(object sender, RoutedEventArgs e)
        {
            if (cmbHuurder.SelectedIndex == -1)
            {
                cmbHuurder.Focus();
                return;
            }
            if (situatie == "new")
            {
                verhuur = new Verhuur();
            }
            verhuur.DeHuurder        = (Huurder)cmbHuurder.SelectedItem;
            verhuur.Vakantieverblijf = verblijf;
            verhuur.DatumVan         = (DateTime)dtpDatumVan.SelectedDate;
            verhuur.DatumTot         = (DateTime)dtpDatumTot.SelectedDate;
            verhuur.WaarborgGestort  = (bool)chkWaarborgGestort.IsChecked;


            TimeSpan ts = (TimeSpan)(dtpDatumTot.SelectedDate - dtpDatumVan.SelectedDate);
            int      aantalOvernachtingen = (int)ts.TotalDays;

            lblAantalOvernachtingen.Content = aantalOvernachtingen.ToString();

            verhuur.Tebetalen = TeBetalen();
            decimal.TryParse(txtBetaald.Text, out decimal betaald);
            verhuur.Betaald = betaald;
            if (situatie == "new")
            {
                Verhuringen.AlleVerhuringen.Add(verhuur);
            }
            this.Close();
        }
 private void lstVerhuur_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     VerhuurControlsLeegmaken();
     if (lstVerhuur.SelectedItem != null)
     {
         Verhuur verhuur = (Verhuur)lstVerhuur.SelectedItem;
         VulVerhuurContent(verhuur);
     }
 }
 public void MaakRecord(Verhuur verhuur, Klant klant)
 {
     using (var db = new VideoVerhuurEntities())
     {
         db.Klants.Find(klant.KlantNr).HuurAantal += 1;
         db.Verhuurs.Add(verhuur);
         db.SaveChanges();
     }
 }
        private void VulVerhuurContent(Verhuur verhuur)
        {
            Vakantiehuis vakantiehuis = (Vakantiehuis)lstVakantiehuizen.SelectedItem;

            txtKlant.Text = verhuur.Klant;
            dtpVerhuurVanaf.SelectedDate = verhuur.Vanaf;
            dtpVerhuurTot.SelectedDate   = verhuur.Tot;
            lblHuurprijs.Content         = vakantiehuis.PrijsPerNacht * verhuur.AantalDagen;
            lblVerhuurError.Visibility   = Visibility.Hidden;
        }
Exemple #9
0
 public void BewaarVerhuurdeFilms(Verhuur verhuur)
 {
     using (var db = new VideoVerhuurEntities())
     {
         var film = db.Films.Find(verhuur.BandNr);
         film.InVoorraad  -= 1;
         film.UitVoorraad += 1;
         db.Verhuur.Add(verhuur);
         db.SaveChanges();
     }
 }
Exemple #10
0
        private void BtnVerhuurDelete(object sender, RoutedEventArgs e)
        {
            Button  btn     = (Button)sender;
            Verhuur verhuur = (Verhuur)btn.DataContext;

            if (MessageBox.Show("Deze verhuur annuleren?", "Verhuur verwijderen", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes)
            {
                Verhuringen.AlleVerhuringen.Remove(verhuur);
            }

            LstVerblijven_SelectionChanged(null, null);
        }
 private void btnVerwijderVerhuur_Click(object sender, RoutedEventArgs e)
 {
     if (lstVerhuur.SelectedItem != null)
     {
         if (MessageBox.Show("Ben je zeker?", "Verhuur wissen", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
         {
             Verhuur verhuur = (Verhuur)lstVerhuur.SelectedItem;
             verhuurService.VerwijderVerhuring(verhuur);
             Vakantiehuis vakantiehuis = (Vakantiehuis)lstVakantiehuizen.SelectedItem;
             VulVerhuurListbox(vakantiehuis.ID);
         }
     }
 }
Exemple #12
0
        private void BtnVerhuurEdit_Click(object sender, RoutedEventArgs e)
        {
            Button  btn     = (Button)sender;
            Verhuur verhuur = (Verhuur)btn.DataContext;

            winVerhuur venster = new winVerhuur();

            venster.situatie = "edit";
            venster.verblijf = verhuur.Vakantieverblijf;
            venster.verhuur  = verhuur;
            venster.ShowDialog();

            LstVerblijven_SelectionChanged(null, null);
        }
        public void Verhuring(int bandnr, int klantnr)
        {
            using (var db = new VideoVerhuurEntities())
            {
                var v = new Verhuur {
                    BandNr = bandnr, KlantNr = klantnr, VerhuurDatum = DateTime.Today
                };
                db.Verhuur.Add(v);

                var film = db.Films.Find(bandnr);
                film.InVoorraad  -= 1;
                film.UitVoorraad += 1;

                db.SaveChanges();
            }
        }
        public ActionResult Afrekenen()
        {
            decimal teBetalen     = 0;
            var     klantenNummer = int.Parse(@Session["klant"].ToString().Substring(@Session["klant"].ToString().LastIndexOf(" ") + 1));
            Klant   klant         = db.GetKlantOpNummer(klantenNummer);

            ViewBag.Voornaam = klant.Voornaam;
            ViewBag.Naam     = klant.Naam;
            ViewBag.Straat   = klant.Straat_Nr;
            ViewBag.Postcode = klant.PostCode;
            ViewBag.Gemeente = klant.Gemeente;

            List <WinkelmandItem> mandjeItems = new List <WinkelmandItem>();

            foreach (string nummer in Session)
            {
                int filmNr;
                if (int.TryParse(nummer, out filmNr))
                {
                    Film film = db.GetFilm(filmNr);
                    if (film != null)
                    {
                        WinkelmandItem mandjeItem = new WinkelmandItem(film.Titel, film.Prijs, Convert.ToInt16(Session[nummer]));
                        mandjeItems.Add(mandjeItem);
                        Verhuur verhuurItem = new Verhuur();
                        verhuurItem.KlantNr      = klant.KlantNr;
                        verhuurItem.BandNr       = film.BandNr;
                        verhuurItem.VerhuurDatum = DateTime.Today;
                        if (film.InVoorraad > 0)
                        {
                            teBetalen += film.Prijs;
                            db.BewaarVerhuurdeFilms(verhuurItem);
                        }
                        else
                        {
                            mandjeItems.Remove(mandjeItem);
                            System.Windows.Forms.MessageBox.Show("De laatste film van \"" + film.Titel + "\" is net verhuurd en kan niet meer uitgeleend worden.");
                        }
                    }
                }
            }
            Session.RemoveAll();
            ViewBag.teBetalen = teBetalen;
            return(View(mandjeItems));
        }
Exemple #15
0
        private Verhuur CreateVerhuurFromReader(SqlDataReader reader)
        {
            Verhuur verhuur;

            return(verhuur = new Verhuur
            {
                Account = new Account()
                {
                    ID = Convert.ToInt32(reader["AccountID"])
                },
                DatumBegin = Convert.ToDateTime(reader["DatumBegin"]),
                DatumEind = Convert.ToDateTime(reader["DatumEind"]),
                Exemplaar = new Exemplaar
                {
                    ExemplaarID = Convert.ToInt32(reader["ExemplaarID"])
                }
            });
        }
        public ActionResult Afrekening()
        {
            decimal totaleprijs = 0;

            winkelmand = (List <MandjeItem>)Session["FilmLijst"];
            foreach (var mandjeitem in winkelmand)
            {
                Verhuur verhuur = new Verhuur();
                verhuur.BandNr       = mandjeitem.film.BandNr;
                verhuur.VerhuurDatum = DateTime.Now;
                verhuur.KlantNr      = mandjeitem.klant.KlantNr;
                db.MaakRecord(verhuur, (Klant)Session["klant"]);

                totaleprijs += mandjeitem.film.Prijs;
            }
            Session["klant"] = null;
            db.UpdateAlleFilms(winkelmand);
            Session["TotalePrijs"] = totaleprijs;
            return(View(winkelmand));
        }
        public void PlaatsReservering(string voornaam, string tussenvoegsel, string achternaam, string straat, int huisnr,
                                      string woonplaats, DateTime start, DateTime eind, int evenementid, List <int> plekids, List <AccountViewModel> accounts, List <ProductExemplaar> producten)
        {
            int persoonID      = 0;
            int hoofdAccountId = 0;

            using (SqlConnection connection = Connection.SQLconnection)
            {
                //Insert into table PERSOON
                string queryPERSOON = "INSERT INTO PERSOON (voornaam, tussenvoegsel, achternaam, straat, huisnr, woonplaats, banknr) VALUES (@voornaam, @tussenvoegsel, @achternaam, @straat, @huisnr, @woonplaats, 'n.v.t.');";

                using (SqlCommand command = new SqlCommand(queryPERSOON, connection))
                {
                    command.Parameters.AddWithValue("@voornaam", voornaam);
                    command.Parameters.AddWithValue("@tussenvoegsel", tussenvoegsel);
                    command.Parameters.AddWithValue("@achternaam", achternaam);
                    command.Parameters.AddWithValue("@straat", straat);
                    command.Parameters.AddWithValue("@huisnr", huisnr);
                    command.Parameters.AddWithValue("@woonplaats", woonplaats);
                    try
                    {
                        command.ExecuteNonQuery();
                    }
                    catch (SqlException)
                    {
                        throw;
                    }
                }
                //End table PERSOON

                //Get id from PERSOON
                string queryPERSOONID = "SELECT MAX(ID) as id FROM PERSOON";

                using (SqlCommand command = new SqlCommand(queryPERSOONID, connection))
                {
                    try
                    {
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                persoonID = Convert.ToInt32(reader["id"]);
                            }
                        }
                    }
                    catch (SqlException)
                    {
                        throw;
                    }
                }
                //End get PersonID

                //Insert into table RESERVERING
                string queryRESERVERING = "INSERT INTO RESERVERING (persoon_id, datumStart, datumEinde, betaald, eventID) VALUES (@persoon_id, @datumStart, @datumEind, @betaald, @eventID)";

                using (SqlCommand command = new SqlCommand(queryRESERVERING, connection))
                {
                    command.Parameters.AddWithValue("@persoon_id", persoonID);
                    command.Parameters.AddWithValue("@datumStart", start);
                    command.Parameters.AddWithValue("@datumEind", eind);
                    command.Parameters.AddWithValue("@betaald", true);
                    command.Parameters.AddWithValue("@eventID", evenementid);

                    try
                    {
                        command.ExecuteNonQuery();
                    }
                    catch (SqlException)
                    {
                        throw;
                    }
                }
                //End insert into table RESERVERING

                //Insert into plek_reservering
                string queryPLEKRESERVERING = "INSERT INTO PLEK_RESERVERING (plek_id, reservering_id) VALUES (@plekID, (SELECT MAX(id) FROM RESERVERING))";

                foreach (int plekid in plekids)
                {
                    using (SqlCommand command = new SqlCommand(queryPLEKRESERVERING, connection))
                    {
                        command.Parameters.AddWithValue("@plekID", plekid);
                        try
                        {
                            command.ExecuteNonQuery();
                        }
                        catch (SqlException)
                        {
                            throw;
                        }
                    }
                }
                //End insert into plek_reservering

                foreach (AccountViewModel account in accounts)
                {
                    try
                    {
                        string query =
                            "INSERT INTO Account (gebruikersnaam, email, activatiehash, geactiveerd, wachtwoord, telefoonnummer, status) VALUES (@gebruikersnaam, @email, @activatiehash, @geactiveerd, @wachtwoord, @telefoonnummer, 0)";
                        using (SqlCommand command = new SqlCommand(query, connection))
                        {
                            command.Parameters.AddWithValue("@gebruikersnaam", account.Gebruikersnaam);
                            command.Parameters.AddWithValue("@email", account.Email);
                            command.Parameters.AddWithValue("@activatiehash", Guid.NewGuid());
                            command.Parameters.AddWithValue("@geactiveerd", false);
                            command.Parameters.AddWithValue("@wachtwoord", account.Wachtwoord);
                            command.Parameters.AddWithValue("@telefoonnummer", account.Telefoonnummer);
                            command.ExecuteNonQuery();
                        }
                    }
                    catch (Exception)
                    {
                        throw;
                    }

                    string idQuery =
                        "INSERT INTO RESERVERING_POLSBANDJE (reservering_id, polsbandje_id, account_id, aanwezig) VALUES ((SELECT MAX(id) FROM RESERVERING), 1, (SELECT MAX(id) FROM ACCOUNT), 0)";
                    using (SqlCommand command = new SqlCommand(idQuery, connection))
                    {
                        try
                        {
                            command.ExecuteNonQuery();
                        }
                        catch (SqlException)
                        {
                            throw;
                        }
                    }

                    if (hoofdAccountId == 0)
                    {
                        string hoofdQuery =
                            "SELECT MAX(id) as id FROM RESERVERING_POLSBANDJE";
                        using (SqlCommand command = new SqlCommand(hoofdQuery, connection))
                        {
                            try
                            {
                                using (SqlDataReader reader = command.ExecuteReader())
                                {
                                    while (reader.Read())
                                    {
                                        hoofdAccountId = Convert.ToInt32(reader["id"]);
                                    }
                                }
                            }
                            catch (SqlException)
                            {
                                throw;
                            }
                        }
                    }
                }

                foreach (ProductExemplaar product in producten)
                {
                    Verhuur v            = new Verhuur(product.Id, hoofdAccountId, eind, start, 0, true);
                    string  queryProduct = "INSERT INTO VERHUUR VALUES (@exemplaarid, @reserveringid, @datumin, @datumuit, 0, 1)";

                    using (SqlCommand command = new SqlCommand(queryProduct, connection))
                    {
                        command.Parameters.AddWithValue("@exemplaarid", product.Id);
                        command.Parameters.AddWithValue("@reserveringid", hoofdAccountId);
                        command.Parameters.AddWithValue("@datumin", eind);
                        command.Parameters.AddWithValue("@datumuit", start);
                        try
                        {
                            command.ExecuteNonQuery();
                        }
                        catch (SqlException)
                        {
                            throw;
                        }
                    }
                }
            }
        }
        private void btnBewaarVerhuur_Click(object sender, RoutedEventArgs e)
        {
            bool         fouten       = false;
            Vakantiehuis vakantiehuis = (Vakantiehuis)lstVakantiehuizen.SelectedItem;

            lblVerhuurError.Content = "";
            string   klant = txtKlant.Text.Trim();
            DateTime vanaf = DateTime.MinValue;
            DateTime tot   = DateTime.MinValue;

            if (klant.Length == 0)
            {
                fouten = true;
                lblVerhuurError.Content += "Klantnaam invoeren aub\n";
            }
            if (dtpVerhuurVanaf.SelectedDate == null)
            {
                fouten = true;
                lblVerhuurError.Content += "Startdatum selecteren aub\n";
            }
            if (dtpVerhuurTot.SelectedDate == null)
            {
                fouten = true;
                lblVerhuurError.Content += "Einddatum selecteren aub\n";
            }
            if (dtpVerhuurVanaf.SelectedDate != null && dtpVerhuurTot.SelectedDate != null)
            {
                vanaf = (DateTime)dtpVerhuurVanaf.SelectedDate;
                tot   = (DateTime)dtpVerhuurTot.SelectedDate;
                if (tot <= vanaf)
                {
                    fouten = true;
                    lblVerhuurError.Content = "Startdatum moet voor einddatum vallen\n";
                }
            }
            if (isVerhuurNew)
            {
                if (verhuurService.IsErOverlap(vakantiehuis.ID, vanaf, tot))
                {
                    fouten = true;
                    lblVerhuurError.Content = "Overlap in boeking !\n";
                }
            }
            else
            {
                if (verhuurService.IsErOverlap((Verhuur)lstVerhuur.SelectedItem, vakantiehuis.ID, vanaf, tot))
                {
                    fouten = true;
                    lblVerhuurError.Content = "Overlap in boeking !\n";
                }
            }
            if (fouten)
            {
                lblVerhuurError.Visibility = Visibility.Visible;
                return;
            }
            Verhuur verhuur;

            if (isVerhuurNew)
            {
                verhuur = new Verhuur(vakantiehuis.ID, klant, vanaf, tot);
                verhuurService.VoegVerhuurToe(verhuur);
            }
            else
            {
                verhuur       = (Verhuur)lstVerhuur.SelectedItem;
                verhuur.Klant = klant;
                verhuur.Vanaf = vanaf;
                verhuur.Tot   = tot;
            }
            VerhuurStandaardBeeld();
            VulVerhuurListbox(vakantiehuis.ID);
            lstVerhuur.SelectedItem = verhuur;
            lstVerhuur_SelectionChanged(null, null);
        }
 //Methodes
 public bool VoegToe(Verhuur verhuur)
 {
     Verhuringen.Add(verhuur);
     return true;
 }