public CFormMain() { InitializeComponent(); if (CImportMyanmarConst.SessionClient != null) { CListeObjetDonneeGenerique <CProjet> lst = new CListeObjetDonneeGenerique <CProjet>(CImportMyanmarConst.ContexteDonnee); lst.Filtre = new CFiltreData( CTypeProjet.c_champId + "=@1", 4); CUtilElementAChamps.ReadChampsCustom(lst, 2567); foreach (CProjet projet in lst) { string strVal = projet.GetValeurChamp(2567) as string; if (strVal != null && strVal.Length > 0) { m_dicNominalCodeToProjet[strVal] = projet; } } } }
// ///////////////////////////////////////////////////////// /// <summary> /// Le data du result contient un IBaseGantt /// </summary> /// <returns></returns> public static CResultAErreur CreateGantt( CMetaProjet metaProjet, CParametreNiveauArbreGanttGroupe groupeRacine, CFiltreData filtreElements) { CResultAErreur result = CResultAErreur.True; if (metaProjet == null) return result; CElementDeGanttMetaProjet elementRacine = new CElementDeGanttMetaProjet(null, metaProjet); if (!result) return result; List<CProjet> lstProjets = new List<CProjet>(); bool bLectureDansContexteCourant = false; //S'il y a des éléments modifiés, ajoutés ou supprimés dans //les relations, charge manuellement DataTable table = metaProjet.ContexteDonnee.GetTableSafe(CRelationMetaProjet_Projet.c_nomTable); if ( table != null ) { if ( table.Select ( "", "", DataViewRowState.Added | DataViewRowState.Deleted | DataViewRowState.ModifiedCurrent ).Length > 0 ) { bLectureDansContexteCourant = true; //Il y a des modifs, on ne peut donc pas appliquer le filtre, //et on doit aller chercher les projets manuellement foreach ( CRelationMetaProjet_Projet rel in metaProjet.RelationsProjets ) { List<CProjet> lstTmp = new List<CProjet>(); lstTmp.Add ( rel.Projet ); while ( lstTmp.Count > 0 ) { List<CProjet> lstSuivante = new List<CProjet>(); foreach ( CProjet prj in lstTmp ) { lstProjets.Add ( prj ); lstSuivante.AddRange ( prj.ProjetsFils.ToList<CProjet>()); } lstTmp = lstSuivante; } } } } if (!bLectureDansContexteCourant) { CFiltreData filtre = result.Data as CFiltreData; filtre = CFiltreData.GetAndFiltre(filtreElements, new CFiltreDataAvance( CProjet.c_nomTable, CRelationMetaProjet_Projet.c_nomTable + "." + CMetaProjet.c_champId + "=@1", metaProjet.Id)); filtre.IntegrerFilsHierarchiques = !metaProjet.HideChildProjects; CListeObjetsDonnees lstObjetProjets = new CListeObjetsDonnees(metaProjet.ContexteDonnee, typeof(CProjet), filtre); lstObjetProjets.PreserveChanges = true; lstObjetProjets.ModeSansTri = true; lstProjets.AddRange(lstObjetProjets.ToList<CProjet>()); if ( metaProjet.HideChildProjects ) lstObjetProjets.ReadDependances("LiensEnTantQueProjetA.ProjetB", "LiensEnTantQueProjetB.ProjetA", "ContraintesPropres", "AnomaliesDuProjet"); else lstObjetProjets.ReadDependances("ProjetsFils", "LiensEnTantQueProjetA.ProjetB", "LiensEnTantQueProjetB.ProjetA", "ContraintesPropres", "AnomaliesDuProjet"); CUtilElementAChamps.ReadChampsCustom(lstObjetProjets); } CContexteDonnee contexteDeTravail = metaProjet.ContexteDonnee; return PrepareGantt(groupeRacine, result, elementRacine, lstProjets, contexteDeTravail); }
// ///////////////////////////////////////////////////////// /// <summary> /// Le data du result contient un IBaseGantt /// </summary> /// <returns></returns> public static CResultAErreur CreateGantt ( CProjet projet, CParametreNiveauArbreGanttGroupe groupeRacine, CFiltreData filtreElements ) { CResultAErreur result = CResultAErreur.True; if (projet == null) return result; CElementDeGanttProjet elementRacine = new CElementDeGanttProjet(null, projet); if (!result) return result; List<CProjet> lstProjets = new List<CProjet>(); if (!projet.IsNew())//Si le projet est nouveau, on ne peut pas filtrer //car les éléments ne sont pas encore en base { CFiltreData filtre = result.Data as CFiltreData; filtre = CFiltreData.GetAndFiltre(filtreElements, new CFiltreData(CProjet.c_champCodeSystemeComplet + " like @1 and " + CProjet.c_champId + "<>@2", projet.CodeSystemeComplet + "%", projet.Id)); CListeObjetsDonnees lstObjetProjets = new CListeObjetsDonnees(projet.ContexteDonnee, typeof(CProjet), filtre); lstObjetProjets.PreserveChanges = true; lstObjetProjets.ModeSansTri = true; lstProjets.AddRange(lstObjetProjets.ToList<CProjet>()); lstObjetProjets.ReadDependances("ProjetsFils","LiensEnTantQueProjetA", "LiensEnTantQueProjetB", "ContraintesPropres", "AnomaliesDuProjet"); CUtilElementAChamps.ReadChampsCustom(lstObjetProjets); } //Il faut ajouter les projets qui ne sont pas encore en base et qui n'ont donc pas de code system List<CProjet> lstALire = new List<CProjet>(); lstALire.Add(projet); DataRelation relation = null; foreach ( DataRelation rel in projet.ContexteDonnee.Tables[CProjet.c_nomTable].ChildRelations ) { if ( rel.ChildTable.TableName == CProjet.c_nomTable ) { relation = rel; break; } } while (lstALire.Count > 0 && relation != null) { List<CProjet> prochaineGeneration = new List<CProjet>(); foreach (CProjet test in lstALire) { DataRow[] rowsDeps = test.Row.Row.GetChildRows(relation); foreach (DataRow row in rowsDeps) { if (row.RowState != DataRowState.Deleted) { CProjet prj = new CProjet(row); if (prj.IsNew() && !lstProjets.Contains(prj) ) { lstProjets.Add(prj); } prochaineGeneration.Add(prj); } } } lstALire = prochaineGeneration; } //Comme on est passé par un filtre Avancé, les nouveaux éléments ne sont //pas dans la liste. On les ajoute donc ! //Vérifie qu'il y a des éléments dont l'id est négatif CListeObjetsDonnees lstTmp = new CListeObjetsDonnees(projet.ContexteDonnee, typeof(CProjet)); lstTmp.Filtre = new CFiltreData(CProjet.c_champId + "<@1", 0); lstTmp.InterditLectureInDB = true; if (lstTmp.Count > 0)//Il y a des projets tous neufs dans le contexte { foreach (CProjet projetTmp in new ArrayList(lstProjets)) { //N'utilise pas ProjetsFils pour ne pas lire dans la base CListeObjetsDonnees lstFils = new CListeObjetsDonnees(projet.ContexteDonnee, typeof(CProjet), new CFiltreData(CProjet.c_champIdParent + "=@1", projetTmp.Id)); lstFils.InterditLectureInDB = true; lstFils.Filtre = new CFiltreData(CProjet.c_champId + "<0"); foreach (CProjet projetFils in lstFils) if (!lstProjets.Contains(projetFils)) lstProjets.Add(projetFils); } //Les nouveaux sous projet du projet principal doivent également être ajoutés CListeObjetsDonnees lstFilsPrincipal = projet.ProjetsFils; lstFilsPrincipal.Filtre = new CFiltreData(CProjet.c_champId + "<0"); foreach (CProjet projetFils in lstFilsPrincipal) if (!lstProjets.Contains(projetFils)) lstProjets.Add(projetFils); } CContexteDonnee contexteDeTravail = projet.ContexteDonnee; return PrepareGantt(groupeRacine,result, elementRacine, lstProjets, contexteDeTravail); }
//------------------------------------------------------------- public CResultAErreur GenereItems(CMapDatabase database, CContexteDonnee ctxDonnee) { CResultAErreur result = CResultAErreur.True; //Calcule les éléments à générer if (Filtre == null || Filtre.TypeElements == null) { return(result); } if (FormuleLatitude == null || FormuleLongitude == null) { return(result); } result = Filtre.GetFiltreData(); if (!result) { return(result); } CFiltreData filtre = result.Data as CFiltreData; CListeObjetsDonnees lstObjets = new CListeObjetsDonnees(ctxDonnee, Filtre.TypeElements); lstObjets.Filtre = filtre; lstObjets.ModeSansTri = true; CMapLayer layer = null; if (lstObjets.Count > 0) { layer = database.GetLayer(Generator.LayerId, true); } else { return(result); } int?nIdChampLatitude = null; int?nIdChampLongitude = null; Dictionary <int, double> dicValeursLatitude = new Dictionary <int, double>(); Dictionary <int, double> dicValeursLongitude = new Dictionary <int, double>(); if (typeof(IObjetDonneeAChamps).IsAssignableFrom(lstObjets.TypeObjets)) { nIdChampLatitude = GetIdChampOptimFromFormule(FormuleLatitude); nIdChampLongitude = GetIdChampOptimFromFormule(FormuleLongitude); List <int> lst = new List <int>(); if (nIdChampLatitude != null) { lst.Add(nIdChampLatitude.Value); } if (nIdChampLongitude != null) { lst.Add(nIdChampLongitude.Value); } if (lst.Count > 0) { CUtilElementAChamps.ReadChampsCustom(lstObjets, lst.ToArray()); } DataTable table = ctxDonnee.Tables[((IObjetDonneeAChamps)lstObjets[0]).GetNomTableRelationToChamps()]; if (table != null && (nIdChampLatitude != null || nIdChampLatitude != null)) { string strCle = ((CObjetDonneeAIdNumerique)lstObjets[0]).GetChampId(); string strFiltre = ""; if (nIdChampLatitude != null) { strFiltre = CChampCustom.c_champId + "=" + nIdChampLatitude.Value; } if (nIdChampLongitude != null) { if (strFiltre.Length > 0) { strFiltre += " or "; } strFiltre += CChampCustom.c_champId + "=" + nIdChampLongitude.Value; } DataRow[] rows = table.Select(strFiltre); foreach (DataRow row in table.Rows) { if ((int)row[CChampCustom.c_champId] == nIdChampLatitude) { dicValeursLatitude[(int)row[strCle]] = (double)row[CRelationElementAChamp_ChampCustom.c_champValeurDouble]; } else if ((int)row[CChampCustom.c_champId] == nIdChampLongitude) { dicValeursLongitude[(int)row[strCle]] = (double)row[CRelationElementAChamp_ChampCustom.c_champValeurDouble]; } } } } else { nIdChampLatitude = null; nIdChampLongitude = null; } foreach (object obj in lstObjets) { DateTime dt = DateTime.Now; m_currentGeneratedItem = obj; CContexteEvaluationExpression ctxEval = new CContexteEvaluationExpression(obj); double?fLat = null; double?fLong = null; if (nIdChampLatitude != null) { double fTmp = 0; if (dicValeursLatitude.TryGetValue(((CObjetDonneeAIdNumerique)obj).Id, out fTmp)) { fLat = fTmp; } } else { result = FormuleLatitude.Eval(ctxEval); if (result) { try { fLat = Convert.ToDouble(result.Data); } catch { } } } if (fLat != null) { if (nIdChampLongitude != null) { double fTmp = 0; if (dicValeursLongitude.TryGetValue(((CObjetDonneeAIdNumerique)obj).Id, out fTmp)) { fLong = fTmp; } } else { result = FormuleLongitude.Eval(ctxEval); if (result) { try { fLong = Convert.ToDouble(result.Data); } catch { } } } } TimeSpan sp = DateTime.Now - dt; if (obj is CObjetDonnee) { //Console.WriteLine("Coord "+((CObjetDonnee)obj).DescriptionElement + " : " + sp.TotalMilliseconds); } if (fLong != null && fLat != null) { foreach (CMapItemDessin mapItemDessin in ItemsDessin) { if (mapItemDessin.GenereItem( obj, fLat.Value, fLong.Value, layer)) { break; } } } sp = DateTime.Now - dt; if (obj is CObjetDonnee) { //Console.WriteLine(((CObjetDonnee)obj).DescriptionElement + " : " + sp.TotalMilliseconds); } } return(result); }