/// //////////////////////////////////////////////////////////////// public static CFiltreDataAvance ConvertFiltreToFiltreAvance(string strTable, CFiltreData filtre) { if (filtre is CFiltreDataAvance) { return((CFiltreDataAvance)filtre.GetClone()); } string strFiltre = filtre.Filtre; if (!filtre.HasFiltre) { return(new CFiltreDataAvance(strTable, "")); } //Remplace is null et is not null par has et hasno string strUpper = strFiltre.ToUpper(); if (strUpper.Contains("IS NULL") || strUpper.Contains("IS NOT NULL")) { Regex expReg = new Regex("[( ]*(?<P1>[^ ]+)[) ]*(?<OP>is null|is not null)", RegexOptions.IgnoreCase); strFiltre = expReg.Replace(strFiltre, new MatchEvaluator(RemplaceIsNullForAvance)); } CResultAErreur result = CAnalyseurSyntaxiqueFiltre.AnalyseFormule(strFiltre, strTable); if (!result) { result.EmpileErreur(I.T("Error while analyzing filter @1|134", strFiltre)); throw new CExceptionErreur(result.Erreur); } CFiltreDataAvance retour = new CFiltreDataAvance(strTable, (CComposantFiltre)result.Data); foreach (object parametre in filtre.Parametres) { retour.Parametres.Add(parametre); } return(retour); }
////////////////////////////////////////////////// public override CFiltreData GetClone() { CFiltreDataAvance filtre = new CFiltreDataAvance(m_strTablePrincipale, ""); CopyTo(filtre); return(filtre); }
////////////////////////////////////////////////// protected void CopyTo(CFiltreDataAvance filtre) { base.CopyTo(filtre); filtre.m_strTablePrincipale = m_strTablePrincipale; if (m_composantPrincipal != null) { m_composantPrincipal = (CComposantFiltre)CCloner2iSerializable.Clone(m_composantPrincipal); } }
//-------------------------------------------------------- public void InitComposant(CComposantFiltreChamp champTeste, string strNomTableSousFiltre, CComposantFiltreChamp champDeSousFiltre, CFiltreDataAvance filtre) { m_champTeste = champTeste; m_strTableSousFiltre = strNomTableSousFiltre; m_champSousFiltre = champDeSousFiltre; m_filtre = filtre; m_bIsInterprete = true; }
//////////////////////////////////////////////////////// public string GetStringAvance(CFiltreDataAvance filtre) { CComposantFiltre composant = filtre.ComposantPrincipal; if (composant == null) { return(""); } //remplace chaque champ par sa valeur for (int nParametre = 1; nParametre <= filtre.Parametres.Count; nParametre++) { (composant).RemplaceVariableParConstante("@" + nParametre, filtre.Parametres[nParametre - 1]); } return(GetStringExpression(composant, filtre)); }
//--------------------------------------------- /// <summary> /// Retourne un dictionnaire contenant tous les champs modifiés pour /// des versions données et des objets donnés /// </summary> /// <returns></returns> public Dictionary <int, Dictionary <int, Dictionary <CReferenceChampPourVersion, bool> > > GetDictionnaireChampsModifies( int nIdSession, string strIdsVersionsConcernees, Type typeElements, DataRow[] rows) { CResultAErreur result = CResultAErreur.True; if (rows.Length == 0) { return(new Dictionary <int, Dictionary <int, Dictionary <CReferenceChampPourVersion, bool> > >()); } //Crée la liste des ids string strPrimKey = rows[0].Table.PrimaryKey[0].ColumnName; StringBuilder blIds = new StringBuilder(); foreach (DataRow row in rows) { //Les modifications portent toujours sur l'élément le plus proche du référentiel, //Donc sur l'original Id ou l'id s'il n'y a pas d'original if (row[CSc2iDataConst.c_champOriginalId] == DBNull.Value) { blIds.Append(row[strPrimKey].ToString()); } else { blIds.Append(row[CSc2iDataConst.c_champOriginalId].ToString()); } blIds.Append(","); } blIds.Remove(blIds.Length - 1, 1); C2iRequeteAvancee requete = new C2iRequeteAvancee(-1); requete.TableInterrogee = CVersionDonneesObjetOperation.c_nomTable; requete.ListeChamps.Add(new C2iChampDeRequete("Id", new CSourceDeChampDeRequete(CVersionDonneesObjet.c_nomTable + "." + CVersionDonneesObjet.c_champIdElement), typeof(int), OperationsAgregation.None, true)); requete.ListeChamps.Add(new C2iChampDeRequete("IdVersion", new CSourceDeChampDeRequete(CVersionDonneesObjet.c_nomTable + "." + CVersionDonnees.c_champId), typeof(int), OperationsAgregation.None, true)); requete.ListeChamps.Add(new C2iChampDeRequete("Field", new CSourceDeChampDeRequete(CVersionDonneesObjetOperation.c_champChamp), typeof(string), OperationsAgregation.None, true)); requete.ListeChamps.Add(new C2iChampDeRequete("FieldType", new CSourceDeChampDeRequete(CVersionDonneesObjetOperation.c_champTypeChamp), typeof(string), OperationsAgregation.None, true)); CFiltreData filtre = new CFiltreDataAvance(CVersionDonneesObjetOperation.c_nomTable, CVersionDonneesObjet.c_nomTable + "." + CVersionDonnees.c_champId + " in (" + strIdsVersionsConcernees + ") and " + CVersionDonneesObjet.c_nomTable + "." + CVersionDonneesObjet.c_champIdElement + " in (" + blIds.ToString() + ") and " + CVersionDonneesObjet.c_nomTable + "." + CVersionDonneesObjet.c_champTypeElement + "=@1 and " + CVersionDonneesObjetOperation.c_champTypeChamp + "=@2", typeElements.ToString(), CChampPourVersionInDb.c_TypeChamp); filtre.IgnorerVersionDeContexte = true; requete.FiltreAAppliquer = filtre; Dictionary <int, Dictionary <int, Dictionary <CReferenceChampPourVersion, bool> > > dicoChampsModifies = new Dictionary <int, Dictionary <int, Dictionary <CReferenceChampPourVersion, bool> > >(); result = requete.ExecuteRequete(nIdSession); if (!result) { return(dicoChampsModifies); } foreach (DataRow rowModif in ((DataTable)result.Data).Rows) { int nIdVersion = (int)rowModif["IdVersion"]; Dictionary <int, Dictionary <CReferenceChampPourVersion, bool> > dicoChampsDeVersion = null; if (!dicoChampsModifies.TryGetValue(nIdVersion, out dicoChampsDeVersion)) { dicoChampsDeVersion = new Dictionary <int, Dictionary <CReferenceChampPourVersion, bool> >(); dicoChampsModifies[nIdVersion] = dicoChampsDeVersion; } Dictionary <CReferenceChampPourVersion, bool> dicoChampsDeId = null; if (!dicoChampsDeVersion.TryGetValue((int)rowModif["Id"], out dicoChampsDeId)) { dicoChampsDeId = new Dictionary <CReferenceChampPourVersion, bool>(); dicoChampsDeVersion[(int)rowModif["Id"]] = dicoChampsDeId; } dicoChampsDeId[ new CReferenceChampPourVersion((string)rowModif["FieldType"], (string)rowModif["Field"])] = true; } return(dicoChampsModifies); }
/*/////////////////////////////////////////////////// * public void AddAndFiltre ( CFiltreData filtre ) * { * if ( filtre == null || !filtre.HasFiltre ) * return; * if ( m_strFiltre.Trim() != "" ) * m_strFiltre = "("+m_strFiltre+") and "; * string strNewFiltre = filtre.Filtre+" "; * int nNumNewParam = Parametres.Count +1; * for ( int nParam = 0; nParam < filtre.Parametres.Count; nParam++ ) * { * strNewFiltre = strNewFiltre.Replace("@"+(nParam+1).ToString()+" ", "@"+nNumNewParam.ToString()+" "); * Parametres.Add ( filtre.Parametres[nParam] ); * nNumNewParam++; * } * m_strFiltre += strNewFiltre; * }*/ /////////////////////////////////////////////////// protected static CFiltreData CombineFiltres(CFiltreData filtre1, CFiltreData filtre2, string strOperateur) { if ((filtre1 == null || !filtre1.HasFiltre) && (filtre2 == null || !filtre2.HasFiltre)) { return(null); } if (filtre1 == null || !filtre1.HasFiltre) { return(filtre2.GetClone()); } if (filtre2 == null || !filtre2.HasFiltre) { return(filtre1.GetClone()); } if (filtre1 is CFiltreDataImpossible || filtre2 is CFiltreDataImpossible) { return(new CFiltreDataImpossible()); } CFiltreData filtreResult = null; if (filtre1 is CFiltreDataAvance || filtre2 is CFiltreDataAvance) { string strTable; if (filtre1 is CFiltreDataAvance) { strTable = ((CFiltreDataAvance)filtre1).TablePrincipale; if (filtre2 is CFiltreDataAvance && ((CFiltreDataAvance)filtre2).TablePrincipale != strTable) { throw new Exception(I.T("Cannot combine @1 filter on different tables|133", strOperateur)); } } else { strTable = ((CFiltreDataAvance)filtre2).TablePrincipale; } filtreResult = new CFiltreDataAvance(strTable, ""); if (!(filtre1 is CFiltreDataAvance)) { filtre1 = CFiltreDataAvance.ConvertFiltreToFiltreAvance(strTable, filtre1); } if (!(filtre2 is CFiltreDataAvance)) { filtre2 = CFiltreDataAvance.ConvertFiltreToFiltreAvance(strTable, filtre2); } CResultAErreur result = CResultAErreur.True; CFiltreDataAvance filtre1Avance = filtre1 as CFiltreDataAvance; CComposantFiltre composant1 = filtre1Avance.ComposantPrincipal; if (composant1 == null) { result = CAnalyseurSyntaxiqueFiltre.AnalyseFormule(filtre1.Filtre, strTable); if (!result) { result.EmpileErreur(I.T("Error while analyzing filter @1|134", filtre1.Filtre)); throw new CExceptionErreur(result.Erreur); } composant1 = result.Data as CComposantFiltre; } CFiltreDataAvance copie = filtre2.GetClone() as CFiltreDataAvance; copie.RenumerotteParameters(filtre1.Parametres.Count + 1); CComposantFiltre composant2 = copie.ComposantPrincipal; if (composant2 == null) { result = CAnalyseurSyntaxiqueFiltre.AnalyseFormule(copie.Filtre, strTable); if (!result) { result.EmpileErreur(I.T("Error while analyzing filter @1|134", copie.Filtre)); throw new CExceptionErreur(result.Erreur); } composant2 = result.Data as CComposantFiltre; } CComposantFiltre composantPrincipal = null; if (strOperateur.ToUpper() == "OR") { composantPrincipal = new CComposantFiltreOperateur(CComposantFiltreOperateur.c_IdOperateurOu); } if (strOperateur.ToUpper() == "AND") { composantPrincipal = new CComposantFiltreOperateur(CComposantFiltreOperateur.c_IdOperateurEt); } if (composantPrincipal != null) { composantPrincipal.Parametres.Add(composant1); composantPrincipal.Parametres.Add(composant2); filtreResult = new CFiltreDataAvance(strTable, composantPrincipal); } else { filtreResult.Filtre = "(" + composant1.GetString() + ") " + strOperateur + " (" + composant2.GetString() + ")"; } } else { filtreResult = new CFiltreData(); filtreResult.Filtre = "(" + filtre1.Filtre + ")"; CFiltreData copie = filtre2.GetClone(); copie.RenumerotteParameters(filtre1.Parametres.Count + 1); filtreResult.Filtre += " " + strOperateur + " (" + copie.Filtre + ")"; } foreach (object parametre in filtre1.Parametres) { filtreResult.Parametres.Add(parametre); } foreach (object parametre in filtre2.Parametres) { filtreResult.Parametres.Add(parametre); } if (filtre1 != null && filtre1.SortOrder != "") { filtreResult.SortOrder = filtre1.SortOrder; } if (filtre2 != null && filtre2.SortOrder != "") { if (filtreResult.SortOrder != "") { filtreResult.SortOrder += ","; } filtreResult.SortOrder += filtre2.SortOrder; } if (filtre1 != null) { filtreResult.IntegrerLesElementsSupprimes |= filtre1.IntegrerLesElementsSupprimes; filtreResult.IgnorerVersionDeContexte |= filtre1.IgnorerVersionDeContexte; filtreResult.IdsDeVersionsALire = filtre1.IdsDeVersionsALire; filtreResult.IntergerParentsHierarchiques |= filtre1.IntergerParentsHierarchiques; filtreResult.IntegrerFilsHierarchiques |= filtre1.IntegrerFilsHierarchiques; filtreResult.NeConserverQueLesRacines |= filtre1.NeConserverQueLesRacines; } if (filtre2 != null) { filtreResult.IntegrerLesElementsSupprimes |= filtre2.IntegrerLesElementsSupprimes; filtreResult.IgnorerVersionDeContexte |= filtre2.IgnorerVersionDeContexte; filtreResult.IntergerParentsHierarchiques |= filtre2.IntergerParentsHierarchiques; filtreResult.IntegrerFilsHierarchiques |= filtre2.IntegrerFilsHierarchiques; filtreResult.NeConserverQueLesRacines |= filtre2.NeConserverQueLesRacines; if (filtre2.IdsDeVersionsALire != null) { if (filtreResult.IdsDeVersionsALire != null) { Hashtable tblIds = new Hashtable(); foreach (int nId in filtreResult.IdsDeVersionsALire) { tblIds[nId] = true; } foreach (int nId in filtre2.IdsDeVersionsALire) { tblIds[nId] = true; } ArrayList lst = new ArrayList(); foreach (int nId in tblIds.Keys) { lst.Add(nId); } filtreResult.IdsDeVersionsALire = (int[])lst.ToArray(typeof(int)); } else { filtreResult.IdsDeVersionsALire = filtre2.IdsDeVersionsALire; } } } return(filtreResult); }
//-------------------------------------------------------- public CResultAErreur InterpreteParametres() { CResultAErreur result = CResultAErreur.True; if (m_bIsInterprete) { return(result); } //Paramètre 1 : champ //Paramètre 2 : sous type //Parametre 3 : champ de sous type retourné //Paramètre 4 : Filtre if (Parametres.Count < 4) { result.EmpileErreur(GetOperateurSousFiltre() + " " + I.T("Require 4 parameters : field, type, source field, sub filter|20008")); return(result); } m_champTeste = Parametres[0] as CComposantFiltreChamp; if (m_champTeste == null) { result.EmpileErreur(GetOperateurSousFiltre() + " : " + I.T("First parameter is invalid (field requiered|20070")); } Type tp = null; m_strTableSousFiltre = null; CComposantFiltreConstante compoCst = Parametres[1] as CComposantFiltreConstante; if (compoCst != null && compoCst.Valeur != null) { tp = CActivatorSurChaine.GetType(compoCst.Valeur.ToString(), true); if (tp != null) { m_strTableSousFiltre = CContexteDonnee.GetNomTableForType(tp); } if (m_strTableSousFiltre == null) { result.EmpileErreur(I.T("Invalid type reference (@1)|20009", compoCst.Valeur.ToString())); } } else { result.EmpileErreur(GetOperateurSousFiltre() + " : " + I.T("Second parameter is invalid (type requiered)|20010")); } if (result) { CComposantFiltreConstante compoFiltre = Parametres[3] as CComposantFiltreConstante; if (compoFiltre == null || compoFiltre.Valeur == null) { result.EmpileErreur(GetOperateurSousFiltre() + " : " + I.T("4th parameter is invalid (filtre requiered)|20012")); return(result); } m_filtre = new CFiltreDataAvance(m_strTableSousFiltre, compoFiltre.Valeur.ToString()); if (m_filtre.ComposantPrincipal == null) { result.EmpileErreur(I.T("Sub filter is invalide|20014")); return(result); } } if (result) { CComposantFiltreConstante compoSousChamp = Parametres[2] as CComposantFiltreConstante; if (compoSousChamp == null || compoSousChamp.Valeur == null) { result.EmpileErreur(GetOperateur() + " : " + I.T("3rd parameter is invalide (field requiered)|20013")); return(result); } m_champSousFiltre = new CComposantFiltreChamp(compoSousChamp.Valeur.ToString(), m_strTableSousFiltre); } m_bIsInterprete = result.Result; return(result); }