コード例 #1
0
        //--------------------------------------------------------------------------
        /// <summary>
        /// Retourne un projet pouvant être executé pour l'étape demandée<BR>
        /// </BR>
        /// Cette fonction se charge de la mise à jour de toutes la structure du projet
        /// </summary>
        /// <param name="etape"></param>
        /// <returns></returns>
        public static CResultAErreurType <CProjet> AssureProjetRunnable(CEtapeWorkflow etape, CBlocWorkflowProjet blocProjet)
        {
            CResultAErreurType <CProjet> resProjet = new CResultAErreurType <CProjet>();
            CProjet projet = GetProjetDirectementAssocie(etape);

            int nNumLastIteration = 0;

            if (projet != null)
            {
                nNumLastIteration = projet.NumeroIteration;
                if (projet.GanttId == "")
                {
                    projet.GanttId = blocProjet.GetGanttId(etape);
                }
            }

            CProjet projetParent = FindProjetParent(etape);

            if (projetParent != null && projet != null &&
                projetParent != projet.Projet)
            {
                projet = null;
            }

            if (projet == null)
            {
                resProjet = blocProjet.GetOrCreateProjetInCurrentContexte(etape,
                                                                          FindProjetParent(etape),
                                                                          FindPredecesseurs(etape));
                return(resProjet);
            }

            if (
                projet.DateFinRelle == null ||
                !blocProjet.GererIteration ||
                projet.HasOptionLienEtape(EOptionLienProjetEtape.NoIteration))
            {
                if ((!blocProjet.GererIteration || projet.HasOptionLienEtape(EOptionLienProjetEtape.NoIteration)) &&
                    !projet.HasOptionLienEtape(EOptionLienProjetEtape.StepKeepDates))
                {
                    projet.DateFinRelle = null;
                }
                resProjet.DataType = projet;
                return(resProjet);
            }

            //Il faut créer une ittération pour ce projet
            IEnumerable <CProjet> predecesseurs = FindPredecesseurs(etape);

            CProjet newProjet = projet.Clone(false) as CProjet;

            //Remet les dates à null
            newProjet.DateDebutReel = null;
            newProjet.DateFinRelle  = null;

            //Met les deux projets sur la même barre de gantt
            if (projet.GanttId.Length == 0)
            {
                projet.GanttId = blocProjet.GetGanttId(etape);
            }
            newProjet.GanttId = projet.GanttId;

            DateTime?dateDebut = null;

            foreach (CProjet pred in predecesseurs)
            {
                if (dateDebut == null || pred.DateFinGantt > dateDebut.Value)
                {
                    dateDebut = pred.DateFinGantt;
                }
            }
            if (dateDebut == null)
            {
                dateDebut = DateTime.Now;
            }
            if (dateDebut != null)
            {
                newProjet.DateDebutPlanifiee = dateDebut.Value;
                newProjet.DateFinPlanifiee   = dateDebut.Value.AddHours(projet.DureeEnHeure.Value);
            }
            newProjet.DateDebutAuto   = true;
            newProjet.NumeroIteration = nNumLastIteration + 1;

            //Supprime toutes les dépendances du nouveau projet
            CObjetDonneeAIdNumerique.Delete(newProjet.LiensDeProjetAttaches, true);

            //Change le workflow lancé
            etape.WorkflowLancé.SetValeurChamp(blocProjet.IdChampProjet.Value, newProjet);

            //Crée les liens vers les prédécesseurs
            foreach (CProjet pred in predecesseurs)
            {
                newProjet.AddPredecessor(pred);
            }

            //Met à jour les successeurs
            foreach (CTypeEtapeWorkflow typeSucc in FindTypesSuccesseurs(etape.TypeEtape))
            {
                CEtapeWorkflow succ = etape.Workflow.GetEtapeForType(typeSucc);
                if (succ != null)
                {
                    resProjet = AssureProjetRunnable(succ, succ.TypeEtape.Bloc as CBlocWorkflowProjet);
                    CProjet prjSucc = resProjet.DataType;
                    if (prjSucc != null)
                    {
                        //Si le projet est lié à l'ancien, on déplace le lien
                        CLienDeProjet lien = prjSucc.GetLienToPredecesseur(projet);
                        if (lien != null)
                        {
                            lien.ProjetA = newProjet;
                        }
                    }
                }
            }
            newProjet.AutoMoveDependancies();

            CContexteEvaluationExpression ctxEval = new CContexteEvaluationExpression(etape);

            foreach (CAffectationsProprietes affectation in blocProjet.AffectationsCreationEtDemarrage)
            {
                bool bAppliquer = affectation.FormuleCondition == null || affectation.FormuleCondition is C2iExpressionVrai;
                if (affectation.FormuleCondition != null)
                {
                    CResultAErreur res = affectation.FormuleCondition.Eval(ctxEval);
                    if (res && res.Data != null && CUtilBool.BoolFromString(res.Data.ToString()) == true)
                    {
                        bAppliquer = true;
                    }
                }
                if (bAppliquer)
                {
                    affectation.AffecteProprietes(newProjet, etape, new CFournisseurPropDynStd());
                }
            }

            resProjet.DataType = newProjet;
            return(resProjet);
        }