private void txtNbPlaces_Validating(object sender, CancelEventArgs e) { string errMsg; if (!ModuleReservations.ValidChampNb(txtNbPlaces.Text, nbPlacesRest, out errMsg)) { e.Cancel = true; txtTelephone.Select(0, txtNbPlaces.Text.Length); errNom.SetError(txtNbPlaces, errMsg); } }
private void txtEmail_Validating(object sender, CancelEventArgs e) { string errMsg; if (!ModuleReservations.ValidChampEmail(txtEmail.Text, out errMsg)) { e.Cancel = true; txtEmail.Select(0, txtEmail.Text.Length); errNom.SetError(txtEmail, errMsg); } }
// Au click sur le bouton supprimer private void btnSupprimer_Click(object sender, EventArgs e) { if (dgvListeReservations.SelectedRows.Count <= 0) { MessageBox.Show("Veuillez sélectionner une réservation"); } else { var rep = MessageBox.Show("Êtes vous sûr de vouloir supprimmer cette réservation ?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (rep == DialogResult.Yes) { int indexRow = dgvListeReservations.CurrentRow.Index; Spectator laReserv = (Spectator)dgvListeReservations.Rows[indexRow].Cells[0].Value; string message = ModuleReservations.DeleteReservation(laReserv); MessageBox.Show(message); // On valorise chaque label avec une valeur vide lblLaPiece.Text = String.Empty; lblLeTheme.Text = String.Empty; lblLaDuree.Text = String.Empty; lblLeType.Text = String.Empty; lblLaRepresentation.Text = String.Empty; lblLaCompagnie.Text = String.Empty; lblLePrixFixe.Text = "€"; lblLeNom.Text = String.Empty; lblLePrenom.Text = String.Empty; lblLeNbPlaces.Text = String.Empty; lblLeEmail.Text = String.Empty; lblLeTelephone.Text = String.Empty; lblLePrixTotal.Text = "0 €"; LoadDataGridView(); } } }
// Validation de l'édition private void btnValiderEdition_Click(object sender, EventArgs e) { if (txtNom.Text == null || txtNom.Text == String.Empty || txtPrenom.Text == null || txtPrenom.Text == String.Empty || txtEmail.Text == null || txtEmail.Text == String.Empty || txtTelephone.Text == null || txtTelephone.Text == String.Empty || txtNbPlaces.Text == null || txtNbPlaces.Text == String.Empty) { errEmail.SetError(txtEmail, "Ce champ est requis !"); errNbPlaces.SetError(txtNbPlaces, "Ce champ est requis !"); errNom.SetError(txtNom, "Ce champ est requis !"); errPrenom.SetError(txtPrenom, "Ce champ est requis !"); errPhone.SetError(txtTelephone, "Ce champ est requis !"); } else { var rep = MessageBox.Show("Êtes vous sûr de vouloir éditer cette réservation ?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (rep == DialogResult.Yes) { editReserv.Spectator_lastname = txtNom.Text; editReserv.Spectator_firstname = txtPrenom.Text; editReserv.Spectator_email = txtEmail.Text; editReserv.Spectator_phone = txtTelephone.Text; editReserv.Spectator_show = laRepres; editReserv.Spectator_seatsBooked = int.Parse(txtNbPlaces.Text); ModuleReservations.EditionReservation(editReserv); grbDetails.Text = "Détails de la réservation"; cmbHeures.Items.Clear(); cmbDates.Items.Clear(); laRepresAvEdit = null; #region Affiche et cache les champs concernés btnValiderEdition.Visible = false; btnAnnulerEdition.Visible = false; cmbPiece.Visible = false; cmbDates.Visible = false; cmbHeures.Visible = false; txtNom.Visible = false; txtPrenom.Visible = false; txtNbPlaces.Visible = false; txtEmail.Visible = false; txtTelephone.Visible = false; lblHeure.Visible = false; lblPlacesRest.Visible = false; lblLesPlacesRest.Visible = false; lblLesPlacesRest.Text = ""; lblPrixReel.Visible = false; lblLePrixReel.Visible = false; btnModifier.Visible = true; btnSupprimer.Visible = true; lblLaPiece.Visible = true; lblLaRepresentation.Visible = true; lblLeNom.Visible = true; lblLePrenom.Visible = true; lblLeNbPlaces.Visible = true; lblLeEmail.Visible = true; lblLeTelephone.Visible = true; dgvListeReservations.Enabled = true; btnAjouter.Enabled = true; #endregion Affiche et cache les champs concernés lblReprésentation.Text = "Représentation :"; lblLeTheme.Text = String.Empty; lblLaDuree.Text = String.Empty; lblLeType.Text = String.Empty; lblLaCompagnie.Text = String.Empty; lblLePrixFixe.Text = "€"; lblLePrixTotal.Text = "0 €"; LoadDataGridView(); dgvListeReservations.Refresh(); } } }
// Chargement du datagridview private void LoadDataGridView() { // récupération de la liste des réservations List <Spectator> lesReservations = ModuleReservations.GetSpectators(); // Structure de la dgv DataTable table = new DataTable(); dgvListeReservations.DataSource = table; // Ajout des colonnes de la table table.Columns.Add(new DataColumn("reservation", typeof(Spectator))); table.Columns.Add(new DataColumn("piece", typeof(string))); dgvListeReservations.Columns["piece"].HeaderText = "Pièce"; table.Columns.Add(new DataColumn("representation", typeof(string))); dgvListeReservations.Columns["representation"].HeaderText = "Représentation"; table.Columns.Add(new DataColumn("duree", typeof(string))); dgvListeReservations.Columns["duree"].HeaderText = "Durée"; table.Columns.Add(new DataColumn("theme", typeof(string))); dgvListeReservations.Columns["theme"].HeaderText = "Thème"; table.Columns.Add(new DataColumn("public", typeof(string))); dgvListeReservations.Columns["public"].HeaderText = "Public"; table.Columns.Add(new DataColumn("nom", typeof(string))); dgvListeReservations.Columns["nom"].HeaderText = "Nom"; table.Columns.Add(new DataColumn("places", typeof(string))); dgvListeReservations.Columns["places"].HeaderText = "Places"; table.Columns.Add(new DataColumn("total", typeof(string))); dgvListeReservations.Columns["total"].HeaderText = "Total"; dgvListeReservations.ReadOnly = true; // Valorisation de la DGV avec les réservations foreach (Spectator uneReservation in lesReservations) { // Nom de la pièce string piece = uneReservation.Spectator_show.Show_theaterPiece.TheaterPiece_name; // Date et heure de la représentation string representation = uneReservation.Spectator_show.Show_dateTime.ToString("dd/MM/yyyy à H:mm"); // Durée de la pièce double doubleConvertDuree = double.Parse(uneReservation.Spectator_show.Show_theaterPiece.TheaterPiece_duration.ToString()); TimeSpan convertDuree = TimeSpan.FromHours(doubleConvertDuree); string duree = convertDuree.ToString(); // Thème de la pièce string theme = uneReservation.Spectator_show.Show_theaterPiece.TheaterPiece_theme.Theme_name; // Type de public de la pièce string typePublic = uneReservation.Spectator_show.Show_theaterPiece.TheaterPiece_publicType.PublicType_name; // Nom et prénom de la réservation string nom = uneReservation.Spectator_lastname; int places = uneReservation.Spectator_seatsBooked; // Calcul du prix total float taux = uneReservation.Spectator_show.Show_priceRate.PriceRate_rate; float prixHT = uneReservation.Spectator_show.Show_theaterPiece.TheaterPiece_seatsPrice * places; float total = prixHT + (prixHT * taux); // Ajout de la ligne à la table table.Rows.Add(uneReservation, piece, representation, duree, theme, typePublic, nom, places, total); } // La première colonne contenant l'objet ne sera pas visible dgvListeReservations.Columns["reservation"].Visible = false; }
// Fonction changement places restantes dynamique private void ChangementPlacesRest(Show repAvEdit) { TheaterPiece laPiece; if (cmbPiece.SelectedItem != null) { laPiece = cmbPiece.SelectedItem as TheaterPiece; } else { laPiece = editReserv.Spectator_show.Show_theaterPiece; } lesRepresentations = ModuleRepresentations.GetFilterShows(laPiece.TheaterPiece_id); Show uneRep = laRepres; if (uneRep == null) { foreach (var rep in lesRepresentations) { if (cmbDates.SelectedItem != null && cmbHeures.SelectedItem != null && cmbPiece.SelectedItem != null) { if (rep.Show_dateTime.ToString("dd/MM/yyyy") == cmbDates.SelectedItem.ToString() && rep.Show_dateTime.ToString("HH:mm") == cmbHeures.SelectedItem.ToString() && rep.Show_theaterPiece.TheaterPiece_id == laPiece.TheaterPiece_id) { uneRep = rep; } } else { if (rep.Show_dateTime.ToString("dd/MM/yyyy") == editReserv.Spectator_show.Show_dateTime.ToString("dd/MM/yyyy") && rep.Show_dateTime.ToString("HH:mm") == editReserv.Spectator_show.Show_dateTime.ToString("HH:mm") && rep.Show_theaterPiece.TheaterPiece_id == editReserv.Spectator_show.Show_theaterPiece.TheaterPiece_id) { uneRep = rep; } } } } int repPlacesRes = ModuleReservations.GetNbPlacesReservees(laRepres); int bookedPlaces = 0; if (repPlacesRes == -1) { repPlacesRes = 0; } if (txtNbPlaces.Text != String.Empty) { int test; if (int.TryParse(txtNbPlaces.Text, out test)) { bookedPlaces = Int32.Parse(txtNbPlaces.Text); } else { txtNbPlaces.Text = string.Empty; errNbPlaces.SetError(txtNbPlaces, "Veuillez saisir un nombre !"); } } if (isEdit && uneRep.Show_id == repAvEdit.Show_id) { nbPlacesRest = uneRep.Show_seats - (repPlacesRes - nbPlacesAvEdit) - bookedPlaces; } else { nbPlacesRest = uneRep.Show_seats - repPlacesRes - bookedPlaces; } if (nbPlacesRest < 0) { lblLesPlacesRest.Text = "0"; } else { lblLesPlacesRest.Text = nbPlacesRest.ToString(); } }
// Validation de l'ajout private void btnValiderAjout_Click(object sender, EventArgs e) { if (txtNom.Text == null || txtNom.Text == String.Empty || txtPrenom.Text == null || txtPrenom.Text == String.Empty || txtEmail.Text == null || txtEmail.Text == String.Empty || txtTelephone.Text == null || txtTelephone.Text == String.Empty || txtNbPlaces.Text == null || txtNbPlaces.Text == String.Empty) { errEmail.SetError(txtEmail, "Ce champ est requis !"); errNbPlaces.SetError(txtNbPlaces, "Ce champ est requis !"); errNom.SetError(txtNom, "Ce champ est requis !"); errPrenom.SetError(txtPrenom, "Ce champ est requis !"); errPhone.SetError(txtTelephone, "Ce champ est requis !"); } else { Spectator uneReservation = new Spectator(txtNom.Text, txtPrenom.Text, txtEmail.Text, txtTelephone.Text, laRepres, int.Parse(txtNbPlaces.Text)); ModuleReservations.AddSpectator(uneReservation); grbDetails.Text = "Détails de la réservation"; cmbHeures.Items.Clear(); cmbDates.Items.Clear(); #region Affiche et cache les champs concernés btnValiderAjout.Visible = false; btnAnnulerAjout.Visible = false; cmbPiece.Visible = false; cmbDates.Visible = false; cmbHeures.Visible = false; txtNom.Visible = false; txtPrenom.Visible = false; txtNbPlaces.Visible = false; txtEmail.Visible = false; txtTelephone.Visible = false; lblHeure.Visible = false; lblPlacesRest.Visible = false; lblLesPlacesRest.Visible = false; lblLesPlacesRest.Text = ""; lblPrixReel.Visible = false; lblLePrixReel.Visible = false; btnModifier.Visible = true; btnSupprimer.Visible = true; lblLaPiece.Visible = true; lblLaRepresentation.Visible = true; lblLeNom.Visible = true; lblLePrenom.Visible = true; lblLeNbPlaces.Visible = true; lblLeEmail.Visible = true; lblLeTelephone.Visible = true; dgvListeReservations.Enabled = true; #endregion Affiche et cache les champs concernés lblReprésentation.Text = "Représentation :"; lblLeTheme.Text = String.Empty; lblLaDuree.Text = String.Empty; lblLeType.Text = String.Empty; lblLaCompagnie.Text = String.Empty; lblLePrixFixe.Text = "€"; lblLePrixTotal.Text = "0 €"; LoadDataGridView(); dgvListeReservations.Refresh(); } }