private void buttonDelete_Click(object sender, EventArgs e) {
   DialogResult result = MessageBox.Show("Êtes-vous sûr de vouloir supprimer la réservation " + CurrentReception.ReceptionName + "?", "Confirmation de suppression", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
   if(result == DialogResult.Yes) {
     try {
       using(ProjetSGBDEntities context = new ProjetSGBDEntities()) {
         context.DeleteReservation(CurrentReception.ReceptionId, CurrentClient.Id, CurrentReception.ModifiedAt);
       }
     } catch(Exception ex) {
       ModelError modelError = new ModelError(ex);
       MessageBox.Show(modelError.Message, "Erreur fatale!", MessageBoxButtons.OK, MessageBoxIcon.Error);
       DialogResult = DialogResult.None;
     }
   } else {
     DialogResult = DialogResult.None;
   }
 }
Example #2
0
 private void buttonDeleteReservations_Click(object sender, EventArgs e) {
   if(dataGridViewReservations.SelectedRows.Count == 1) {
     GetReservedReception_Result selected = (GetReservedReception_Result)dataGridViewReservations.SelectedRows[0].DataBoundItem;
     DialogResult result = MessageBox.Show("Êtes-vous sûr de vouloir supprimer la réservation " + selected.ReceptionName + "?", "Confirmation de suppression", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
     if(result == DialogResult.Yes) {
       try {
         using(ProjetSGBDEntities context = new ProjetSGBDEntities()) {
           context.DeleteReservation(selected.ReceptionId, CurrentClient.Id, selected.ModifiedAt);
         }
         PopulateReceptions();
       } catch(Exception ex) {
         ModelError modelError = new ModelError(ex);
         if(modelError.Number == ModelError.DATA_NOT_UP_TO_DATE) {
           MessageBox.Show(modelError.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
           PopulateReceptions();
         } else {
           MessageBox.Show(modelError.Message, "Erreur fatale!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
       }
     }
   }
 }