コード例 #1
0
        //TODO : pour les ajouts penser à l'objet en plus de la foreign key

        private void BtValiderReservation_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (CbChambres.SelectedValue == null)
                {
                    MessageBox.Show("Veuillez choisir un hotel puis une chambre");
                    return;
                }

                using (var db = new ModelBooking())
                {
                    bool           isNewReservation;
                    ReservationSet reservation;

                    if ((string)this.LbIdReservation.Content != "" && this.LbIdReservation.Content != null)
                    {
                        isNewReservation = false;
                        int idReservation = Convert.ToInt32(this.LbIdReservation.Content);

                        var resultQuery = (from reservations in db.ReservationsSet
                                           where reservations.Id == idReservation
                                           select reservations);

                        if (resultQuery.Any())
                        {
                            reservation = resultQuery.First();
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        isNewReservation = true;
                        reservation      = new ReservationSet();
                    }
                    reservation.dateDebut  = (DateTime)this.DtDebutReservation.SelectedDate;
                    reservation.dateFin    = (DateTime)this.DtFinReservation.SelectedDate;
                    reservation.keyClient  = Convert.ToInt32(this.CbClient.SelectedValue);
                    reservation.keyChambre = Convert.ToInt32(this.CbChambres.SelectedValue);

                    if (isNewReservation)
                    {
                        db.ReservationsSet.Add(reservation);
                    }
                    db.SaveChanges();
                }
                MessageBox.Show("Enregistré !");

                LoadReservations();
                ActiverDesactiverControlesReservations(false);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #2
0
        private void BtValiderChambre_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (CbHotels_TabChambres.SelectedValue == null)
                {
                    MessageBox.Show("Veuillez choisir un hotel");
                    return;
                }

                using (var db = new ModelBooking())
                {
                    bool        isNewChambre;
                    ChambresSet chambre;

                    if ((string)this.LbIdChambre.Content != "" && this.LbIdChambre.Content != null)
                    {
                        isNewChambre = false;
                        int idChambre = Convert.ToInt32(this.LbIdChambre.Content);

                        var resultQuery = (from chambres in db.ChambresSet
                                           where chambres.Id == idChambre
                                           select chambres);

                        if (resultQuery.Any())
                        {
                            chambre = resultQuery.First();
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        isNewChambre = true;
                        chambre      = new ChambresSet();
                    }
                    chambre.Nom           = this.TbNomChambre.Text;
                    chambre.Climatisation = (bool)this.RdHasClimO.IsChecked;
                    chambre.NbLits        = Convert.ToInt32(this.TbNbLits.Text);
                    chambre.keyHotel      = Convert.ToInt32(this.CbHotels_TabChambres.SelectedValue);

                    if (isNewChambre)
                    {
                        db.ChambresSet.Add(chambre);
                    }
                    db.SaveChanges();
                }
                MessageBox.Show("Enregistré !");

                LoadChambres();
                ActiverDesactiverControlesChambres(false);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #3
0
        private void BtValiderHotel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var db = new ModelBooking())
                {
                    bool      isNewHotel;
                    HotelsSet hotel;

                    if ((string)this.LbIdHotel.Content != "" && this.LbIdHotel.Content != null)
                    {
                        isNewHotel = false;
                        int idHotel = Convert.ToInt32(this.LbIdHotel.Content);

                        var resultQuery = (from hotels in db.HotelsSet
                                           where hotels.Id == idHotel
                                           select hotels);

                        if (resultQuery.Any())
                        {
                            hotel = resultQuery.First();
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        isNewHotel = true;
                        hotel      = new HotelsSet();
                    }
                    hotel.Nom          = this.TbNomHotel.Text;
                    hotel.Capacite     = Convert.ToInt32(this.TbCapacite.Text);
                    hotel.Localisation = this.TbLocalisation.Text;
                    hotel.Pays         = this.TbPays.Text;

                    if (isNewHotel)
                    {
                        db.HotelsSet.Add(hotel);
                    }
                    db.SaveChanges();
                }
                MessageBox.Show("Enregistré !");

                LoadHotels();
                ActiverDesactiverControlesHotels(false);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #4
0
        private void BtValiderClient_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var db = new ModelBooking())
                {
                    bool       isNewClient;
                    ClientsSet client;

                    if ((string)this.LbIdClient.Content != "" && this.LbIdClient.Content != null)
                    {
                        isNewClient = false;
                        int idClient = Convert.ToInt32(this.LbIdClient.Content);

                        var resultQuery = (from clients in db.ClientsSet
                                           where clients.Id == idClient
                                           select clients);

                        if (resultQuery.Any())
                        {
                            client = resultQuery.First();
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        isNewClient = true;
                        client      = new ClientsSet();
                    }
                    client.Nom           = this.TbNomClient.Text;
                    client.Prenom        = this.TbPrenomClient.Text;
                    client.DateNaissance = (DateTime)this.DtDateNaissance.SelectedDate;

                    if (isNewClient)
                    {
                        db.ClientsSet.Add(client);
                    }
                    db.SaveChanges();
                }
                MessageBox.Show("Enregistré !");

                LoadClients();
                ActiverDesactiverControlesClients(false);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #5
0
        private void BtSupprimerReservation_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                this.BtSupprimerReservation.IsEnabled = false;

                int idReservation;
                if (this.ReservationDataGrid.SelectedItem == null)
                {
                    return;
                }
                else
                {
                    idReservation = Convert.ToInt32(((ReservationSet)this.ReservationDataGrid.SelectedItem).Id);
                }

                using (var db = new ModelBooking())
                {
                    var resultQuery = (from reservation in db.ReservationsSet
                                       where reservation.Id == idReservation
                                       select reservation);

                    if (resultQuery.Any())
                    {
                        db.ReservationsSet.Remove(resultQuery.First());
                        db.SaveChanges();
                    }
                }
                MessageBox.Show("Suppression effectuée !");
                LoadReservations();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }