//-------------------------------------------------------------------------
        // Le premier paramètre est l'élément pricipal pour l'édition des tranches horaires
        // Le deuxième paramètre est l'élement secondaire pour l'édition du Type d'occupation Horaire
        // Le deuxième paramètre peut être égal au premier
        public CResultAErreur InitChamps(IElementATrancheHoraire elementATranche)
        {
            CResultAErreur result = CResultAErreur.True;

            m_elementEdite = elementATranche;

            m_panelEditionTranche.Visible = false;

            m_gestionnaireEditionTranches.ObjetEdite = m_elementEdite.TranchesHorairesListe;

            // Init combo sélection type d'occcupation horaire
            CListeObjetsDonnees listeOccupations = new CListeObjetsDonnees(m_elementEdite.ContexteDonnee, typeof(CTypeOccupationHoraire));

            listeOccupations.Filtre = new CFiltreData(CTypeOccupationHoraire.c_champSurCalendrier + "=@1", true);
            m_cmbxSelectTypeOccupationH.Init(listeOccupations, "Libelle", true);
            m_cmbxSelectTypeOccupationH.NullAutorise       = true;
            m_cmbxSelectTypeOccupationH.TextNull           = "Default";
            m_cmbxSelectTypeOccupationH.ElementSelectionne = m_elementEdite.TypeOccupationHoraire;

            m_cmbxSelectTypeOccupationHpourTranche.Init(listeOccupations, "Libelle", true);
            m_cmbxSelectTypeOccupationHpourTranche.NullAutorise = true;
            m_cmbxSelectTypeOccupationHpourTranche.TextNull     = "Default";


            // Init la liste des tranches
            m_listViewTranches.Items.Clear();
            foreach (CHoraireJournalier_Tranche tranche in m_elementEdite.TranchesHorairesListe)
            {
                ListViewItem item = new ListViewItem();
                m_listViewTranches.Items.Add(item);
                m_listViewTranches.UpdateItemWithObject(item, tranche);
            }
            foreach (ListViewItem itemSel in m_listViewTranches.Items)
            {
                itemSel.Selected = false;
            }



            return(result);
        }
Exemple #2
0
        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());
        }