コード例 #1
0
ファイル: CBlocWorkflowProjet.cs プロジェクト: ykebaili/Timos
        //---------------------------------------------------
        //S'assure que le projet est bien créé
        internal CResultAErreurType <CProjet> GetOrCreateProjetInCurrentContexte(CEtapeWorkflow etape, CProjet projetParent, IEnumerable <CProjet> predecesseurs)
        {
            CResultAErreurType <CProjet> resProjet = new CResultAErreurType <CProjet>();
            CWorkflow workflow = GetOrCreateWorkflowInCurrentContexte(etape);

            if (workflow == null)
            {
                resProjet.EmpileErreur(I.T("Can not create workflow for step @1|20143", etape.Libelle));
                return(resProjet);
            }
            if (m_nIdChampProjet == null)
            {
                resProjet.EmpileErreur(I.T("Workflow step @1 doesn't define a field to store associated project|20142", etape.Libelle));
                return(resProjet);
            }
            CProjet projet = workflow.GetValeurChamp(m_nIdChampProjet.Value) as CProjet;

            //SC 8/5/2013 : s'assure que le projet a le bon parent !
            if (projetParent != null && projet != null &&
                projetParent != projet.Projet)
            {
                projet = null;
            }
            string strGanttId = GetGanttId(etape);

            if (projet == null)
            {
                //Création du projet
                projet = new CProjet(etape.ContexteDonnee);
                CTypeProjet typeProjet = null;
                if (m_dbKeyTypeProjet != null) //s'il est null, pas d'erreur ça peut être les formules d'initialisation qui le remplissent
                {
                    typeProjet = new CTypeProjet(etape.ContexteDonnee);
                    if (!typeProjet.ReadIfExists(m_dbKeyTypeProjet))
                    {
                        resProjet.EmpileErreur(I.T("Project type @1 for step @2 doesn't exists|20144", m_dbKeyTypeProjet.StringValue, etape.Libelle));
                        return(resProjet);
                    }
                }
                projet.CreateNewInCurrentContexte();
                projet.TypeProjet = typeProjet;
                projet.GanttId    = strGanttId;
                DateTime?dateDebut = null;
                foreach (CProjet pred in predecesseurs)
                {
                    if (dateDebut == null || pred.DateFinGantt > dateDebut.Value)
                    {
                        dateDebut = pred.DateFinGantt;
                    }
                }
                if (dateDebut == null)
                {
                    dateDebut = DateTime.Now;
                }
                projet.DateDebutPlanifiee = dateDebut;
                if (typeProjet != null)
                {
                    projet.DateFinPlanifiee = projet.DateDebutPlanifiee.Value.AddHours(typeProjet.DureeDefautHeures);
                }
                projet.Projet  = projetParent;
                projet.Libelle = etape.Libelle;
                CContexteEvaluationExpression ctxEval = new CContexteEvaluationExpression(etape);
                foreach (CAffectationsProprietes affectation in 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(projet, etape, new CFournisseurPropDynStd());
                    }
                }
                foreach (CProjet predecesseur in predecesseurs)
                {
                    projet.AddPredecessor(predecesseur);
                }
                CResultAErreur result = workflow.SetValeurChamp(m_nIdChampProjet.Value, projet);
                if (!result)
                {
                    resProjet.EmpileErreur(result.MessageErreur);
                    return(resProjet);
                }
            }
            resProjet.DataType = projet;
            return(resProjet);
        }
コード例 #2
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);
        }