Beispiel #1
0
        public bool Delete()
        {
            TA_TRX.Fill(DS_Master.TRX);
            TA_ARRIVE.Fill(DS_Master.ARRIVE);
            TA_DEPART.Fill(DS_Master.DEPART);

            DTR_RESERV = DS_Master.Tables["RESERVATION"].Rows[BS_RESERVATION.Position];
            int i = DTR_RESERV.GetChildRows("ARRIVE_FK_IdReser").Length;
            int j = DTR_RESERV.GetChildRows("DEPART_FK_IdReser").Length;

            // Pré-conditions
            if (i != 0 && j != i)
            {
                MessageBox.Show("Le nombre d'arrivés n'est pas compatible avec le nombre de départs associés à cette réservation", "Impossible de suprimer");
                return(false);
            }

            if (ir_Reserv.DTP_Fin.Value.AddDays(2) < DateTime.Today)
            {
                MessageBox.Show("Une réservation doit rester dans la base de donnée au moins 2 jours après sa date de fin.", "Impossible de suprimer");
                return(false);
            }

            // Post-conditions
            foreach (DataRow DTR in DTR_RESERV.GetChildRows("TRX_FK_IdReser"))
            {
                DTR["IdReser"] = DBNull.Value;
            }

            foreach (DataRow DTR in DTR_RESERV.GetChildRows("DE_FK_IdReser"))
            {
                DTR.Delete();
            }

            foreach (DataRow DTR in DTR_RESERV.GetChildRows("DEPART_FK_IdReser"))
            {
                DTR.Delete();
            }

            foreach (DataRow DTR in DTR_RESERV.GetChildRows("ARRIVE_FK_IdReser"))
            {
                DTR.Delete();
            }

            DTR_RESERV.Delete();

            try
            {
                TA_TRX.Update(DS_Master.TRX);
                TA_DE.Update(DS_Master.DE);
                TA_ARRIVE.Update(DS_Master.ARRIVE);
                TA_DEPART.Update(DS_Master.DEPART);
                TA_RESERVATION.Update(DS_Master.RESERVATION);

                Sync_ForeignTables();

                MessageBox.Show("Reservation supprimé avec succès.", "Succès");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            return(false);
        }