public CCalendrier_JourParticulier[] GetTousLesJoursParticuliers() { ArrayList exceptions = new ArrayList(this.JoursParticuliersListe); if (this.CalendrierDeBase != null) { exceptions.AddRange(CalendrierDeBase.GetTousLesJoursParticuliers()); } return((CCalendrier_JourParticulier[])exceptions.ToArray(typeof(CCalendrier_JourParticulier))); }
//---------------------------------------------------------------------------- public Dictionary <string, CCalendrier_JourParticulier> GetDicJoursParticuliers() { //S'assure de la lecture de tous les jours particuliers ReadAllJoursParts(); Dictionary <string, CCalendrier_JourParticulier> dic = null; if (CalendrierDeBase != null) { dic = CalendrierDeBase.GetDicJoursParticuliers(); } else { dic = new Dictionary <string, CCalendrier_JourParticulier>(); } foreach (CCalendrier_JourParticulier jp in JoursParticuliersListe) { dic[jp.GetKey()] = jp; } return(dic); }
public CTrancheHoraire[] GetHoraires(DateTime debut, DateTime fin) { Dictionary <string, CCalendrier_JourParticulier> dicJours = GetDicJoursParticuliers(); if ((debut == null) || (fin == null) || (fin < debut) || this.HoraireParDefaut == null) { return(new CTrancheHoraire[0]); } List <CTrancheHoraire> listeTranches = new List <CTrancheHoraire>(); // Recherche les EO planifiées de l'Acteur du calendrier s'il y en a un if (Acteur != null) { listeTranches.AddRange(Acteur.GetHorairesSansCalendrier(debut, fin)); } // Traitement du jour précedent la date de début IElementATrancheHoraire jourPrecedentDebut = (IElementATrancheHoraire)GetJourParticulierAvecHeritageOptim(debut.Date.AddDays(-1), dicJours); if (jourPrecedentDebut == null) { jourPrecedentDebut = (IElementATrancheHoraire)this.HoraireParDefaut; } foreach (CHoraireJournalier_Tranche tranche in jourPrecedentDebut.TranchesHorairesListe) { if (tranche.HeureFin < tranche.HeureDebut) { // La tranche est à cheval sur deux jours CTrancheHoraire newTranche = new CTrancheHoraire(); // Heure de début tronquée à 00:00:00 newTranche.DateHeureDebut = debut.Date.AddDays(-1); // La veille newTranche.DateHeureDebut = newTranche.DateHeureDebut.AddMinutes(tranche.HeureDebut); // Heure de fin le jour de début newTranche.DateHeureFin = debut.Date; newTranche.DateHeureFin = newTranche.DateHeureFin.AddMinutes(tranche.HeureFin); newTranche.TypeOccupationHoraire = tranche.TypeOccupationHoraireAppliquee; if (newTranche.TypeOccupationHoraire == null) { newTranche.TypeOccupationHoraire = this.TypeOccupationHoraireAppliquee; } //Ajout la tranche à la liste if (newTranche.DateHeureFin >= debut && newTranche.DateHeureDebut <= fin) { listeTranches.Add(newTranche); } } } // Pour chaque jour entre la date de début et de fin inclus for (DateTime date = debut.Date; date <= fin.Date; date = date.AddDays(1)) { // Traite les tranches horaires du Calendrier de l'Acteur IElementATrancheHoraire jour = (IElementATrancheHoraire)GetJourParticulierAvecHeritageOptim(date, dicJours); if (jour == null) { jour = (IElementATrancheHoraire)this.HoraireParDefaut; } if (jour != null) { jour = jour.ElementATrancheHoraireApplique; } if (jour != null) { if (jour.TranchesHorairesListe.Count == 0) { //Regle : si un jour particulier n'a pas d'horaires, alors, //il prend l'horaire de ce jour dans le calendrier de base List <CTrancheHoraire> tranches = new List <CTrancheHoraire>(); if (CalendrierDeBase != null) { tranches.AddRange(CalendrierDeBase.GetHoraires(date, date.AddDays(1))); } else { foreach (CHoraireJournalier_Tranche ht in HoraireParDefaut.TranchesHorairesListe) { CTrancheHoraire newTranche = new CTrancheHoraire(); newTranche.TypeOccupationHoraire = jour.TypeOccupationHoraire; newTranche.DateHeureDebut = date.Date; newTranche.DateHeureDebut = newTranche.DateHeureDebut.AddMinutes(ht.HeureDebut); // On ne prend que celles qui commencent ce jour là newTranche.DateHeureFin = (ht.HeureFin > ht.HeureDebut) ? date.Date : date.AddDays(1).Date; newTranche.DateHeureFin = newTranche.DateHeureFin.AddMinutes(ht.HeureFin); tranches.Add(newTranche); } } foreach (CTrancheHoraire tr in tranches) { if (tr.DateHeureDebut < fin && tr.DateHeureFin > debut) { CTrancheHoraire newTranche = new CTrancheHoraire(); newTranche.DateHeureDebut = tr.DateHeureDebut; newTranche.DateHeureFin = tr.DateHeureFin; newTranche.TypeOccupationHoraire = jour.TypeOccupationHoraire; if (newTranche.TypeOccupationHoraire == null) { newTranche.TypeOccupationHoraire = this.TypeOccupationHoraireAppliquee; } listeTranches.Add(newTranche); } } } else { foreach (CHoraireJournalier_Tranche tranche in jour.TranchesHorairesListe) { CTrancheHoraire newTranche = new CTrancheHoraire(); newTranche.DateHeureDebut = date.Date; newTranche.DateHeureDebut = newTranche.DateHeureDebut.AddMinutes(tranche.HeureDebut); // On ne prend que celles qui commencent ce jour là newTranche.DateHeureFin = (tranche.HeureFin > tranche.HeureDebut) ? date.Date : date.AddDays(1).Date; newTranche.DateHeureFin = newTranche.DateHeureFin.AddMinutes(tranche.HeureFin); newTranche.TypeOccupationHoraire = tranche.TypeOccupationHoraireAppliquee; if (newTranche.TypeOccupationHoraire == null) { newTranche.TypeOccupationHoraire = this.TypeOccupationHoraireAppliquee; } if (newTranche.DateHeureFin >= debut && newTranche.DateHeureDebut <= fin) { listeTranches.Add(newTranche); } } } } } // Traitement des priorités List <CTrancheHoraire> listeTraitee = TraitePrioritesTranches(listeTranches); listeTraitee.Sort(new CTrancheHoraire.PrioriteComparer()); return((CTrancheHoraire[])listeTraitee.ToArray()); }