Exemplo n.º 1
0
        //-------------------------------------------------------------------------------------
        public CResultAErreurType <CDataTableFastSerialize> GetDataDirect(CDataHotelQuery query)
        {
            CResultAErreurType <CDataTableFastSerialize> res = new CResultAErreurType <CDataTableFastSerialize>();

            res.DataType = CDataRoomManager.Instance.GetData(query);
            return(res);
        }
Exemplo n.º 2
0
        //----------------------------------------------------------
        public DataTable GetData(ITableDefinition tableDefinition, params string[] strIdsColonnesSource)
        {
            CTableDefinitionDataHotel tableHotel = tableDefinition as CTableDefinitionDataHotel;

            if (tableHotel == null)
            {
                return(GetTableEntitiesVide(tableDefinition, strIdsColonnesSource));
            }
            CDataHotelQuery query = new CDataHotelQuery();

            query.DateDebut = DateTime.Now;
            query.DateFin   = DateTime.Now;
            query.TableId   = tableHotel.Id;
            query.EntitiesId.Add("DUMMYTEST");
            if (strIdsColonnesSource == null || strIdsColonnesSource.Count() == 0)
            {
                List <string> lstCols = new List <string>();
                foreach (IColumnDefinition col in tableDefinition.Columns)
                {
                    if (col is CColonneDefinitionDataHotel)
                    {
                        lstCols.Add(((CColonneDefinitionDataHotel)col).Id);
                    }
                }
                query.ChampsId = lstCols;
            }
            else
            {
                query.ChampsId = strIdsColonnesSource;
            }
            return(GetData(tableHotel, query));
        }
Exemplo n.º 3
0
        //-------------------------------------------------------
        protected override CResultAErreur GetDatasHorsCalculees(CListeQuerySource sources)
        {
            CEasyQuery     query  = Query;
            CResultAErreur result = CResultAErreur.True;



            if (query == null || sources == null)
            {
                result.EmpileErreur(I.T("Table @1 needs a source to provide datas|20001", NomFinal));
                return(result);
            }

            CEasyQuerySource    source         = sources.GetSourceFromId(TableDefinition.SourceId);
            CDataHotelConnexion hotelConnexion = source != null ? source.Connexion as CDataHotelConnexion : null;

            if (hotelConnexion == null)
            {
                result.EmpileErreur(I.T("No connection for table @1|20006", NomFinal));
                return(result);
            }

            CTableDefinitionDataHotel tableHotel = m_definitionTable as CTableDefinitionDataHotel;

            if (tableHotel == null)
            {
                result.EmpileErreur(I.T("Table @1 can not be calculated. A DataHotel table should be used as source|20002", NomFinal));
                return(result);
            }

            DateTime?dateDebut = null;
            DateTime?dateFin   = null;
            CContexteEvaluationExpression ctxEval = new CContexteEvaluationExpression(Query);

            if (m_formuleDateDebut != null)
            {
                result = m_formuleDateDebut.Eval(ctxEval);
                if (!result)
                {
                    result.EmpileErreur(I.T("Error on start date formula in table @1|20003", NomFinal));
                }
                else
                {
                    dateDebut = result.Data as DateTime?;
                }
            }
            if (m_formuleDateFin != null)
            {
                result = m_formuleDateFin.Eval(ctxEval);
                if (!result)
                {
                    result.EmpileErreur(I.T("Error on end date formula in table @1|20004", NomFinal));
                }
                else
                {
                    dateFin = result.Data as DateTime?;
                }
            }
            if (dateDebut == null || dateFin == null)
            {
                result.EmpileErreur(I.T("Both start date and end date must be set for table  @1|20005", NomFinal));
            }
            if (!result)
            {
                return(result);
            }

            List <string> lstIdsEntites = new List <string>();

            if (SourceEntites != null)
            {
                lstIdsEntites.AddRange(SourceEntites.GetListeIdsEntites(Query));
            }

            ITestDataHotel test = null;

            //Calcule le filtre
            if (m_filtre != null)
            {
                test = m_filtre.GetTestFinal(Query);
            }

            CDataHotelQuery hotelQuery = new CDataHotelQuery();

            hotelQuery.TableId   = tableHotel.Id;
            hotelQuery.DateDebut = dateDebut.Value;
            hotelQuery.DateFin   = dateFin.Value;
            hotelQuery.EntitiesId.AddRange(lstIdsEntites);
            hotelQuery.Filtre = test;
            List <string>             lstIdsColonnes = new List <string>();
            List <IChampHotelCalcule> lstCalcs       = new List <IChampHotelCalcule>();

            foreach (IColumnDeEasyQuery col in m_listeColonnes)
            {
                CColumnEQFromSource colFromSource = col as CColumnEQFromSource;
                if (colFromSource != null)
                {
                    lstIdsColonnes.Add(colFromSource.IdColumnSource);
                }
                CColonneCalculeeDataHotel colCalc = col as CColonneCalculeeDataHotel;
                if (colCalc != null)
                {
                    if (colCalc.Calcul != null)
                    {
                        IChampHotelCalcule champHotelCalc = colCalc.Calcul.GetChampHotel(Query);
                        if (champHotelCalc != null)
                        {
                            champHotelCalc.NomChampFinal = colCalc.ColumnName;
                            lstCalcs.Add(champHotelCalc);
                        }
                    }
                }
            }
            hotelQuery.ChampsId       = lstIdsColonnes;
            hotelQuery.ChampsCalcules = lstCalcs;


            DataTable tableResult = hotelConnexion.GetData(tableHotel, hotelQuery);

            if (tableResult != null)
            {
                Dictionary <string, IColumnDeEasyQuery> colNameSourceToDestCol = new Dictionary <string, IColumnDeEasyQuery>();
                foreach (IColumnDeEasyQuery col in m_listeColonnes)
                {
                    CColumnEQFromSource cs = col as CColumnEQFromSource;
                    if (cs != null)
                    {
                        IColumnDefinition def = tableHotel.GetColumn(cs.IdColumnSource);
                        if (def != null)
                        {
                            colNameSourceToDestCol[def.ColumnName] = col;
                        }
                    }
                }

                foreach (DataColumn col in tableResult.Columns)
                {
                    IColumnDeEasyQuery colThis = null;
                    if (colNameSourceToDestCol.TryGetValue(col.ColumnName, out colThis))
                    {
                        col.ColumnName = colThis.ColumnName;
                    }
                }
            }

            result.Data = tableResult;



            return(result);
        }
Exemplo n.º 4
0
        //-------------------------------------------------------------------------------------------------------------------
        public DataTable GetData(
            CDataHotelQuery query)
        {
            DataTable table = new DataTable();

            table.Columns.Add(CDataHotelTable.c_nomChampTableEntiteId, typeof(string));
            table.Columns.Add(CDataHotelTable.c_nomChampTableDate, typeof(DateTime));

            //Sélectionne les champs nécéssaires au calcul
            //On utilise un Hashset et une liste pour conserver l'ordre
            HashSet <string> setChampsSource = new HashSet <string>();
            List <string>    lstChampsSource = new List <string>();

            foreach (string strIdChamp in query.ChampsId)
            {
                if (!setChampsSource.Contains(strIdChamp))
                {
                    lstChampsSource.Add(strIdChamp);
                    setChampsSource.Add(strIdChamp);
                }
            }
            foreach (IChampHotelCalcule champCalcule in query.ChampsCalcules)
            {
                if (champCalcule.IdsChampsSource.Count() > 0)
                {
                    foreach (string strIdChampSource in champCalcule.IdsChampsSource)
                    {
                        if (!setChampsSource.Contains(strIdChampSource))
                        {
                            lstChampsSource.Add(strIdChampSource);
                            setChampsSource.Add(strIdChampSource);
                        }
                    }
                }
            }

            foreach (string strIdChamp in lstChampsSource)
            {
                table.Columns.Add(strIdChamp, typeof(double));
            }

            //Récupère toutes les données
            foreach (string strIdEntite in query.EntitiesId)
            {
                Dictionary <DateTime, Dictionary <string, double> > dicValues = new Dictionary <DateTime, Dictionary <string, double> >();
                foreach (string strChamp in lstChampsSource)
                {
                    List <CDataRoomEntry> lst = GetData(query.TableId, strIdEntite, strChamp, query.DateDebut.Value, query.DateFin.Value);
                    foreach (CDataRoomEntry rec in lst)
                    {
                        if (query.Filtre == null || query.Filtre.IsInFilter(strChamp, rec))
                        {
                            Dictionary <string, double> vals = null;
                            if (!dicValues.TryGetValue(rec.Date, out vals))
                            {
                                vals = new Dictionary <string, double>();
                                dicValues[rec.Date] = vals;
                            }
                            vals[strChamp] = rec.Value;
                        }
                    }
                }
                foreach (KeyValuePair <DateTime, Dictionary <string, double> > kv in dicValues)
                {
                    DataRow row = table.NewRow();
                    row[CDataHotelTable.c_nomChampTableEntiteId] = strIdEntite;
                    row[CDataHotelTable.c_nomChampTableDate]     = kv.Key;
                    foreach (KeyValuePair <string, double> fv in kv.Value)
                    {
                        row[fv.Key] = fv.Value;
                    }
                    table.Rows.Add(row);
                }
            }
            return(table);
        }
Exemplo n.º 5
0
 //-----------------------------------------------------------
 public CResultAErreurType <CDataTableFastSerialize> GetDataDirect(CDataHotelQuery query)
 {
     return(m_server.GetDataDirect(query));
 }
Exemplo n.º 6
0
        //----------------------------------------------------------------
        public CResultAErreurType <CDataTableFastSerialize> GetData(CDataHotelQuery query)
        {
            //Explose la requête pour chaque serveur de destination
            Dictionary <CDataRoom, CDataHotelQuery> dicRoomToQuery = new Dictionary <CDataRoom, CDataHotelQuery>();
            CListeEntitesDeMemoryDb <CDataRoom>     allRooms       = new CListeEntitesDeMemoryDb <CDataRoom>(m_database);

            foreach (string strIdEntite in query.EntitiesId)
            {
                //Si le dispatch ne sait pas qui interroger, on interroge tout le monde !
                CDataRoom        room     = CDataDispatch.GetRoomFor(strIdEntite, m_database);
                List <CDataRoom> lstToAsk = new List <CDataRoom>();
                if (room != null)
                {
                    lstToAsk.Add(room);
                }
                else
                {
                    lstToAsk.AddRange(allRooms);
                }
                foreach (CDataRoom roomToAsk in lstToAsk)
                {
                    CDataHotelQuery specQuery = null;
                    if (!dicRoomToQuery.TryGetValue(roomToAsk, out specQuery))
                    {
                        specQuery = query.Clone(false);
                        dicRoomToQuery[roomToAsk] = specQuery;
                    }
                    specQuery.EntitiesId.Add(strIdEntite);
                }
            }
            CResultAErreurType <CDataTableFastSerialize> myResult = new CResultAErreurType <CDataTableFastSerialize>();
            DataTable tableResult = new DataTable();

            foreach (KeyValuePair <CDataRoom, CDataHotelQuery> kv in dicRoomToQuery)
            {
                CDataRoom room = kv.Key;
                CResultAErreurType <CDataTableFastSerialize> res = new CResultAErreurType <CDataTableFastSerialize>();
                IDataRoomServer srv = GetRoomServer(room);
                if (srv != null)
                {
                    res = srv.GetDataDirect(kv.Value);
                    if (res && res.DataType != null)
                    {
                        DataTable tableTmp = res.DataType;
                        tableResult.Merge(tableTmp);
                    }
                }
            }
            //S'assure que la table résultat contient bien toutes les colonnes demandées
            foreach (string strIdCol in query.ChampsId)
            {
                if (tableResult.Columns[strIdCol] == null)
                {
                    tableResult.Columns.Add(strIdCol, typeof(double));
                }
            }
            tableResult.DefaultView.Sort = CDataHotelTable.c_nomChampTableDate + "," + CDataHotelTable.c_nomChampTableEntiteId;
            DataTable tableFinale = tableResult.Clone();

            tableFinale.BeginLoadData();
            foreach (DataRowView rv in tableResult.DefaultView)
            {
                DataRow row = tableFinale.NewRow();

                foreach (DataColumn col in tableFinale.Columns)
                {
                    row[col.ColumnName] = rv[col.ColumnName];
                }
                tableFinale.Rows.Add(row);
            }
            tableFinale.EndLoadData();
            tableResult = tableFinale;
            foreach (IChampHotelCalcule champCalcule in query.ChampsCalcules)
            {
                champCalcule.FinaliseCalcul(
                    query.TableId,
                    tableResult,
                    this,
                    query.DateDebut,
                    query.DateFin);
            }

            myResult.DataType = tableResult;
            return(myResult);
        }
Exemplo n.º 7
0
        //----------------------------------------------------------
        public DataTable GetData(CTableDefinitionDataHotel tableHotel, CDataHotelQuery query)
        {
            DataTable tableResult = null;

            try
            {
                CDataHotelClient client = new CDataHotelClient(m_strIp, m_nPort);
                //Convertit les ids de colonne en id de colonne DataHotel;
                List <string> lstIds = new List <string>();
                Dictionary <string, IColumnDefinition> dicIdToColDef = new Dictionary <string, IColumnDefinition>();

                //remarque sur le code :
                //au début, les CColonneDefinitionDataHotel avaient un id qui leur était propre
                //au lieu de prendre l'id de la colonne de DataHotel, du coup,
                //il fallait faire une conversion des IdCol -> IdHotel.
                //Cette notion a été corrigée, mais pour compatiblité, on continue à
                //convertir.
                foreach (string strIdCol in query.ChampsId)
                {
                    IColumnDefinition           col    = tableHotel.GetColumn(strIdCol);
                    CColonneDefinitionDataHotel colHot = col as CColonneDefinitionDataHotel;
                    if (colHot != null)
                    {
                        lstIds.Add(colHot.HotelColumnId);
                        dicIdToColDef[colHot.HotelColumnId] = col;
                        if (query.Filtre != null)
                        {
                            query.Filtre.ReplaceColumnId(strIdCol, colHot.HotelColumnId);
                        }
                    }
                    if (col is CColonneDefinitionHotelDate)
                    {
                        dicIdToColDef[CDataHotelTable.c_nomChampTableDate] = col;
                    }
                    if (col is CColonneDefinitionHotelEntiteId)
                    {
                        dicIdToColDef[CDataHotelTable.c_nomChampTableEntiteId] = col;
                    }
                }
                query.ChampsId = lstIds;
                CResultAErreurType <CDataTableFastSerialize> res = client.GetRoomServer().GetData(query);
                if (res && res.Data != null)
                {
                    tableResult = res.DataType;
                    foreach (DataColumn col in tableResult.Columns)
                    {
                        IColumnDefinition colDef = null;
                        if (dicIdToColDef.TryGetValue(col.ColumnName, out colDef))
                        {
                            col.ExtendedProperties[CODEQBase.c_extPropColonneId] = col.ColumnName;
                            col.ColumnName = colDef.ColumnName;
                        }
                    }
                }

                return(tableResult);
            }
            catch (Exception ex)
            {
            }
            return(null);
        }