Exemplo n.º 1
0
        //---------------------------------------------------
        protected override CResultAErreur GetDatasHorsCalculees(CListeQuerySource sources)
        {
            CResultAErreur result = CResultAErreur.True;

            if (TableSource != null)
            {
                result = TableSource.GetDatas(sources);
                if (!result)
                {
                    return(result);
                }
                DataTable table = result.Data as DataTable;
                if (table != null)
                {
                    result = TableauCroise.CreateTableCroisee(table);
                    if (Query != null && !Query.ModeCompatibilteTimos4_0_1_3)
                    {
                        DataTable tableResult = result.Data as DataTable;
                        if (tableResult != null)
                        {
                            tableResult.TableName = NomFinal;
                        }
                    }
                }
            }
            if (!(result.Data is DataTable))
            {
                result.EmpileErreur(I.T("Error in table @1|20002", NomFinal));
            }
            return(result);
        }
Exemplo n.º 2
0
        //-------------------------------------------------------
        public CResultAErreur GetDatas(CListeQuerySource sources)
        {
            CResultAErreur result = CResultAErreur.True;

            if (m_bUseCache && m_tableCache != null && Query != null && Query.UseRuntimeCache)
            {
                result.Data = m_tableCache;
                return(result);
            }

            result = GetDatasHorsCalculees(sources);
            DataTable table = result.Data as DataTable;

            if (result && table != null)
            {
                AddDonneesCalculees(table);
            }
            if (m_postFilter != null && table != null)
            {
                CResultAErreurType <DataTable> resTable = m_postFilter.FiltreData(table, Query, sources);
                if (!resTable)
                {
                    result.EmpileErreur(resTable.Erreur);
                    return(result);
                }
                table       = resTable.DataType;
                result.Data = table;
            }

            if (m_bUseCache && table != null)
            {
                m_tableCache = table;
            }
            return(result);
        }
Exemplo n.º 3
0
        //---------------------------------------------------
        protected override CResultAErreur GetDatasHorsCalculees(CListeQuerySource sources)
        {
            CResultAErreur result = CResultAErreur.True;

            if (TableSource != null)
            {
                result = TableSource.GetDatas(sources);
                if (!result)
                {
                    return(result);
                }
                DataTable source = result.Data as DataTable;
                DataTable table  = new DataTable();
                Dictionary <IColumnDeEasyQuery, DataColumn> mapCols = new Dictionary <IColumnDeEasyQuery, DataColumn>();
                foreach (IColumnDeEasyQuery colonne in m_listeColonnesCalculeesFromSource)
                {
                    Type tp = colonne.DataType;
                    if (tp.IsGenericType && tp.GetGenericTypeDefinition() == typeof(Nullable <>))
                    {
                        tp = tp.GetGenericArguments()[0];
                    }
                    DataColumn col = new DataColumn(colonne.ColumnName, tp);
                    table.Columns.Add(col);
                    mapCols[colonne] = col;
                }
                if (source != null)
                {
                    foreach (DataRow row in source.Rows)
                    {
                        CContexteEvaluationExpression ctx = new CContexteEvaluationExpression(row);
                        DataRow rowDest = table.NewRow();
                        foreach (IColumnDeEasyQuery col in m_listeColonnesCalculeesFromSource)
                        {
                            CColonneEQCalculee colCalc = col as CColonneEQCalculee;
                            if (colCalc != null && colCalc.Formule != null)
                            {
                                result = colCalc.Formule.Eval(ctx);
                                if (result)
                                {
                                    try
                                    {
                                        rowDest[mapCols[col]] = result.Data;
                                    }
                                    catch { }
                                }
                            }
                        }
                        table.Rows.Add(rowDest);
                    }
                    result.Data = table;
                }
            }
            if (!(result.Data is DataTable))
            {
                result.EmpileErreur(I.T("Error in table @1|20002", NomFinal));
            }
            return(result);
        }
Exemplo n.º 4
0
 //---------------------------------------------------
 public virtual DataTable GetTable(string strNomTable, CListeQuerySource sources)
 {
     foreach (I2iObjetGraphique objet in Childs)
     {
         IObjetDeEasyQuery ob = objet as IObjetDeEasyQuery;
         if (ob != null && ob.NomFinal == strNomTable)
         {
             CResultAErreur result = ob.GetDatas(sources);
             if (result)
             {
                 return(result.Data as DataTable);
             }
         }
     }
     return(null);
 }
Exemplo n.º 5
0
        //---------------------------------------------------
        protected override CResultAErreur GetDatasHorsCalculees(CListeQuerySource sources)
        {
            CResultAErreur result = CResultAErreur.True;

            if (TableSource != null)
            {
                result = TableSource.GetDatas(sources);
                if (!result)
                {
                    return(result);
                }
                DataTable table = result.Data as DataTable;
                if (table != null)
                {
                    DataTable      tableFiltre = table.Clone() as DataTable;
                    List <DataRow> lstRows     = new List <DataRow>();
                    string         strFiltre   = m_queryCAML != null?m_queryCAML.GetRowFilter(Parent as CEasyQuery) : "";

                    if (strFiltre.Length > 0)
                    {
                        foreach (DataRow row in table.Select(strFiltre))
                        {
                            lstRows.Add(row);
                        }
                    }
                    else
                    {
                        foreach (DataRow row in table.Rows)
                        {
                            lstRows.Add(row);
                        }
                    }

                    foreach (DataRow row in lstRows)
                    {
                        tableFiltre.ImportRow(row);
                    }
                    result.Data = tableFiltre;
                }
            }
            if (!(result.Data is DataTable))
            {
                result.EmpileErreur(I.T("Error in table @1|20002", NomFinal));
            }
            return(result);
        }
Exemplo n.º 6
0
        //---------------------------------------------------
        protected override CResultAErreur GetDatasHorsCalculees(CListeQuerySource sources)
        {
            DateTime       dtChrono = DateTime.Now;
            CResultAErreur result   = CResultAErreur.True;

            if (Table1 == null)
            {
                result.EmpileErreur(I.T("No source @1|20006", "1"));
                return(result);
            }
            if (Table2 == null)
            {
                result.EmpileErreur(I.T("No source @2|20006", "2"));
                return(result);
            }
            result = Table1.GetDatas(sources);
            if (!result || !(result.Data is DataTable))
            {
                result.EmpileErreur(I.T("Error in table @1 datas|20007", Table1.NomFinal));
                return(result);
            }
            DataTable t1 = result.Data as DataTable;

            result = Table2.GetDatas(sources);
            if (!result || !(result.Data is DataTable))
            {
                result.EmpileErreur(I.T("Error in table @1 datas|20007", Table2.NomFinal));
                return(result);
            }
            DataTable t2 = result.Data as DataTable;

            //Trouve toutes les lignes des la table 2 correspondant à la table 1
            List <CMapRows> maps1To2 = new List <CMapRows>();

            if (ParametresJointure.Count() == 0)
            {
            }
            else
            {
                CParametreJointure param0 = m_listeParametresJointure[0];
                Dictionary <object, List <DataRow> > dicValeursToRow1 = null;
                //Première passe : on évalue toutes les expression sur tous les enregistrement de t1 et t2
                List <DataRow> lst1 = new List <DataRow>();
                foreach (DataRow row in t1.Rows)
                {
                    lst1.Add(row);
                }
                result = CParametreJointure.GetDicValeurs(lst1, param0.FormuleTable1, ref dicValeursToRow1);
                if (!result)
                {
                    return(result);
                }
                Dictionary <object, List <DataRow> > dicValeursToRow2 = null;
                List <DataRow> lst2 = new List <DataRow>();
                foreach (DataRow row in t2.Rows)
                {
                    lst2.Add(row);
                }
                result   = CParametreJointure.GetDicValeurs(lst2, param0.FormuleTable2, ref dicValeursToRow2);
                maps1To2 = GetMatches(dicValeursToRow1, dicValeursToRow2, param0.Operateur);

                //Passe suivantes : on évalue pour chaque paire ce ceux qui matchent
                for (int n = 1; n < m_listeParametresJointure.Count; n++)
                {
                    CParametreJointure parametre = m_listeParametresJointure[n];
                    List <CMapRows>    lstMaps   = new List <CMapRows>();
                    foreach (CMapRows maps in maps1To2)
                    {
                        dicValeursToRow1 = null;
                        result           = CParametreJointure.GetDicValeurs(maps.Rows1, parametre.FormuleTable1, ref dicValeursToRow1);
                        if (!result)
                        {
                            return(result);
                        }
                        dicValeursToRow2 = null;
                        result           = CParametreJointure.GetDicValeurs(maps.Rows2, parametre.FormuleTable2, ref dicValeursToRow2);
                        lstMaps.AddRange(GetMatches(dicValeursToRow1, dicValeursToRow2, parametre.Operateur));
                    }
                    maps1To2 = lstMaps;
                }
                DataTable tableResult = new DataTable(NomFinal);
                Dictionary <IColumnDeEasyQuery, IColumnDeEasyQuery> colsFromTable1 = new Dictionary <IColumnDeEasyQuery, IColumnDeEasyQuery>();
                Dictionary <IColumnDeEasyQuery, IColumnDeEasyQuery> colsFromTable2 = new Dictionary <IColumnDeEasyQuery, IColumnDeEasyQuery>();
                foreach (IColumnDeEasyQuery col in m_listeColonnes)
                {
                    CColumnEQFromSource colFromSource = col as CColumnEQFromSource;
                    if (colFromSource != null)
                    {
                        IColumnDeEasyQuery colSource = Table1.Columns.FirstOrDefault(c => c.Id == colFromSource.IdColumnSource);
                        if (colSource != null)
                        {
                            colsFromTable1[col] = colSource;
                            IColumnDeEasyQuery colSource2 = Table2.Columns.FirstOrDefault(c => c.Id == colFromSource.IdColumnSource);
                            if (colSource2 != null)
                            {
                                colsFromTable2[col] = colSource2;
                            }
                        }
                        else
                        {
                            colSource = Table2.Columns.FirstOrDefault(c => c.Id == colFromSource.IdColumnSource);
                            if (colSource != null)
                            {
                                colsFromTable2[col] = colSource;
                            }
                        }
                        if (colSource != null && !tableResult.Columns.Contains(col.ColumnName))
                        {
                            Type tp = col.DataType;
                            if (tp.IsGenericType && tp.GetGenericTypeDefinition() == typeof(Nullable <>))
                            {
                                tp = tp.GetGenericArguments()[0];
                            }
                            DataColumn dtCol = new DataColumn(col.ColumnName, tp);
                            dtCol.ExtendedProperties[CODEQBase.c_extPropColonneId] = col.Id;
                            tableResult.Columns.Add(dtCol);
                        }
                    }
                }
                foreach (CMapRows map in maps1To2)
                {
                    lst1 = map.Rows1;
                    if (lst1.Count == 0)
                    {
                        lst1.Add(null);
                    }
                    lst2 = map.Rows2;
                    if (lst2.Count == 0)
                    {
                        lst2.Add(null);
                    }
                    foreach (DataRow row1 in lst1)
                    {
                        foreach (DataRow row2 in lst2)
                        {
                            if (row1 != null || row2 != null)
                            {
                                DataRow row = tableResult.NewRow();
                                if (row1 != null)
                                {
                                    foreach (KeyValuePair <IColumnDeEasyQuery, IColumnDeEasyQuery> kv in colsFromTable1)
                                    {
                                        try
                                        {
                                            row[kv.Key.ColumnName] = row1[kv.Value.ColumnName];
                                        }
                                        catch { }
                                    }
                                }
                                if (row2 != null)
                                {
                                    foreach (KeyValuePair <IColumnDeEasyQuery, IColumnDeEasyQuery> kv in colsFromTable2)
                                    {
                                        try
                                        {
                                            row[kv.Key.ColumnName] = row2[kv.Value.ColumnName];
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                                tableResult.Rows.Add(row);
                            }
                        }
                    }
                }
                tableResult.AcceptChanges();
                result.Data = tableResult;
            }
            TimeSpan sp = DateTime.Now - dtChrono;

            Console.WriteLine("Join " + NomFinal + " : " + sp.TotalMilliseconds.ToString());

            return(result);
        }
Exemplo n.º 7
0
 //-------------------------------------------------------
 protected abstract CResultAErreur GetDatasHorsCalculees(CListeQuerySource sources);
Exemplo n.º 8
0
        //---------------------------------------------------
        protected override CResultAErreur GetDatasHorsCalculees(CListeQuerySource sources)
        {
            CResultAErreur result = CResultAErreur.True;

            if (TableSource != null)
            {
                result = TableSource.GetDatas(sources);
                if (!result)
                {
                    return(result);
                }
                DataTable table = result.Data as DataTable;
                if (table != null)
                {
                    DataTable tableFinale = new DataTable(NomFinal);
                    Dictionary <string, string> dicIdColToNameCol = new Dictionary <string, string>();
                    foreach (IColumnDeEasyQuery col in ColonnesOrdonnees)
                    {
                        DataColumn dCol = table.Columns[col.ColumnName];
                        if (dCol != null)
                        {
                            DataColumn newCol = new DataColumn(dCol.ColumnName, dCol.DataType);
                            newCol.AllowDBNull = true;
                            tableFinale.Columns.Add(newCol);
                            dicIdColToNameCol[col.Id] = col.ColumnName;
                        }
                    }
                    foreach (DataColumn col in table.Columns)
                    {
                        if (tableFinale.Columns[col.ColumnName] == null)
                        {
                            DataColumn newCol = new DataColumn(col.ColumnName, col.DataType);
                            newCol.AllowDBNull = true;
                            tableFinale.Columns.Add(newCol);
                            //dicIdColToNameCol[col.Id] = col.ColumnName;
                        }
                    }
                    //Applique le tri
                    StringBuilder bl = new StringBuilder();
                    foreach (CSortColonne sort in ColonnesDeTri)
                    {
                        string strCol = "";
                        if (dicIdColToNameCol.TryGetValue(sort.IdColonne, out strCol))
                        {
                            bl.Append(strCol);
                            if (!sort.Croissant)
                            {
                                bl.Append(" desc");
                            }
                            bl.Append(",");
                        }
                    }
                    if (bl.Length > 0)
                    {
                        bl.Remove(bl.Length - 1, 1);
                        table.DefaultView.Sort = bl.ToString();
                    }
                    //Importe les lignes
                    foreach (DataRowView rowView in table.DefaultView)
                    {
                        DataRow row = rowView.Row;
                        tableFinale.ImportRow(row);
                    }


                    result.Data = tableFinale;
                }
            }
            if (!(result.Data is DataTable))
            {
                result.EmpileErreur(I.T("Error in table @1|20002", NomFinal));
            }
            return(result);
        }
Exemplo n.º 9
0
        //---------------------------------------------------
        protected override CResultAErreur GetDatasHorsCalculees(CListeQuerySource sources)
        {
            CResultAErreur result = CResultAErreur.True;

            if (TableSource != null)
            {
                result = TableSource.GetDatas(sources);
                if (!result)
                {
                    return(result);
                }
                DataTable table = result.Data as DataTable;
                if (table != null)
                {
                    DataTable tableFiltre = null;
                    Dictionary <IColumnDeEasyQuery, DataColumn> mapColonnes = new Dictionary <IColumnDeEasyQuery, DataColumn>();
                    Dictionary <string, string> mapIdSourceToNomSource      = new Dictionary <string, string>();
                    foreach (IColumnDeEasyQuery col in TableSource.Columns)
                    {
                        mapIdSourceToNomSource[col.Id] = col.ColumnName;
                    }

                    if (InclureToutesLesColonnesSource)
                    {
                        tableFiltre = table.Clone() as DataTable;
                    }
                    else
                    {
                        tableFiltre = new DataTable(NomFinal);


                        foreach (CColumnEQFromSource colFromSource in ColonnesFromSource)
                        {
                            Type tp = colFromSource.DataType;
                            if (tp.IsGenericType && tp.GetGenericTypeDefinition() == typeof(Nullable <>))
                            {
                                tp = tp.GetGenericArguments()[0];
                            }
                            DataColumn colToAdd = new DataColumn(colFromSource.ColumnName, tp);
                            tableFiltre.Columns.Add(colToAdd);
                            mapColonnes[colFromSource] = colToAdd;
                        }
                    }
                    foreach (CColonneEQCalculee colCalc in ColonnesCalculeesFromSource)
                    {
                        Type tp = colCalc.DataType;
                        if (tp.IsGenericType && tp.GetGenericTypeDefinition() == typeof(Nullable <>))
                        {
                            tp = tp.GetGenericArguments()[0];
                        }
                        DataColumn colToAdd = new DataColumn(colCalc.ColumnName, tp);
                        tableFiltre.Columns.Add(colToAdd);
                        mapColonnes[colCalc] = colToAdd;
                    }
                    HashSet <IColumnDeEasyQuery> colsSourceCopiables = new HashSet <IColumnDeEasyQuery>();
                    foreach (IColumnDeEasyQuery col in TableSource.Columns)
                    {
                        if (tableFiltre.Columns[col.ColumnName] != null)
                        {
                            colsSourceCopiables.Add(col);
                        }
                    }

                    DataRow previousRow = null;
                    foreach (DataRow row in table.Rows)
                    {
                        CContexteEvaluationExpression ctx = new CContexteEvaluationExpression(new CDataRowForChampCalculeODEQ(row, previousRow, Query));
                        if (Formule is C2iExpressionVrai)
                        {
                            result.Data = true;
                        }
                        else
                        {
                            result = Formule.Eval(ctx);
                        }
                        previousRow = row;
                        if (result && result.Data is bool && (bool)result.Data)
                        {
                            DataRow rowDest = tableFiltre.NewRow();
                            if (InclureToutesLesColonnesSource)
                            {
                                foreach (IColumnDeEasyQuery col in colsSourceCopiables)
                                {
                                    rowDest[col.ColumnName] = row[col.ColumnName];
                                }
                            }
                            else
                            {
                                foreach (CColumnEQFromSource colFromSource in ColonnesFromSource)
                                {
                                    rowDest[mapColonnes[colFromSource]] = row[mapIdSourceToNomSource[colFromSource.IdColumnSource]];
                                }
                            }
                            //Ajout des données calculées
                            foreach (CColonneEQCalculee colCalc in ColonnesCalculeesFromSource)
                            {
                                if (colCalc != null && colCalc.Formule != null)
                                {
                                    result = colCalc.Formule.Eval(ctx);
                                    if (result)
                                    {
                                        try
                                        {
                                            if (result.Data == null)
                                            {
                                                rowDest[mapColonnes[colCalc]] = DBNull.Value;
                                            }
                                            else
                                            {
                                                rowDest[mapColonnes[colCalc]] = result.Data;
                                            }
                                        }
                                        catch { }
                                    }
                                }
                            }
                            tableFiltre.Rows.Add(rowDest);
                        }
                    }
                    result.Data = tableFiltre;
                }
            }
            if (!(result.Data is DataTable))
            {
                result.EmpileErreur(I.T("Error in table @1|20002", NomFinal));
            }
            return(result);
        }
Exemplo n.º 10
0
        //-------------------------------------------------------
        protected override CResultAErreur GetDatasHorsCalculees(CListeQuerySource sources)
        {
            CEasyQuery     query  = Query;
            CResultAErreur result = CResultAErreur.True;

            if (result && TableDefinition == null)
            {
                result.EmpileErreur(I.T("Table object must be specified |20001"));
            }
            if (query == null || sources == null)
            {
                result.EmpileErreur(I.T("Query needs a source to provide datas|20000"));
            }
            CEasyQuerySource source = sources.GetSourceFromId(TableDefinition.SourceId);

            if (source == null)
            {
                result.EmpileErreur(I.T("Query needs a source to provide datas|20000"));
            }


            if (result)
            {
                IEnumerable <string> lstCols = new List <string>();

                if (m_definitionTable != null && m_listeColonnes != null && m_listeColonnes.Count() != m_definitionTable.Columns.Count())
                {
                    lstCols = from c in m_listeColonnes where c is CColumnEQFromSource select((CColumnEQFromSource)c).IdColumnSource;
                }


                ITableDefinitionRequetableCAML tblCAML = TableDefinition as ITableDefinitionRequetableCAML;
                if (tblCAML != null && m_CAMLQuery != null)
                {
                    result = tblCAML.GetDatasWithCAML(source, Parent as CEasyQuery, m_CAMLQuery, lstCols.ToArray());
                }
                else
                {
                    result = TableDefinition.GetDatas(source, lstCols.ToArray());
                }

                if (result && result.Data is DataTable)
                {
                    DataTable table = result.Data as DataTable;
                    foreach (DataColumn col in new ArrayList(table.Columns))
                    {
                        IColumnDefinition  def   = TableDefinition.Columns.FirstOrDefault(c => c.ColumnName.ToUpper() == col.ColumnName.ToUpper());
                        IColumnDeEasyQuery laCol = null;
                        if (def == null || (laCol = GetColonneFor(def)) == null)
                        {
                            table.Columns.Remove(col);
                        }
                        else
                        {
                            col.ColumnName = laCol.ColumnName;
                            col.ExtendedProperties[CODEQBase.c_extPropColonneId] = laCol.Id;
                        }
                    }
                    if (tblCAML == null && m_CAMLQuery != null)
                    {
                        string strRowFilter = m_CAMLQuery.GetRowFilter(Parent as CEasyQuery);
                        if (strRowFilter.Length > 0)
                        {
                            HashSet <DataRow> rows = new HashSet <DataRow>();
                            foreach (DataRow row in table.Select(strRowFilter))
                            {
                                rows.Add(row);
                            }
                            foreach (DataRow row in new ArrayList(table.Rows))
                            {
                                if (!rows.Contains(row))
                                {
                                    table.Rows.Remove(row);
                                }
                            }
                            table.AcceptChanges();
                        }
                    }
                    //Vérifie et corrige le type des colonnes
                    foreach (CColumnEQFromSource col in Columns)
                    {
                        DataColumn colDeTable = table.Columns[col.ColumnName];
                        if (colDeTable != null && col.DataType != colDeTable.DataType)
                        {
                            col.DataType = colDeTable.DataType;
                        }
                    }
                }
            }
            if (!result)
            {
                result.EmpileErreur(I.T("Error on table @1|20002"));
            }
            return(result);
        }