Exemple #1
0
 public CEasyQuerySource GetSourceFromId(string strSourceId)
 {
     if (m_listeSources != null)
     {
         return(m_listeSources.GetSourceFromId(strSourceId));
     }
     return(null);
 }
Exemple #2
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);
        }