//--------------------------------------------------- //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); }