//---------------------------------------------------------- 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)); }
//---------------------------------------------------------- private void AssureListeTables() { if (m_listeTables == null) { CDataHotelClient client = new CDataHotelClient(m_strIp, m_nPort); try { DataSet ds = client.GetRoomServer().GetDataSetModele(); if (ds != null) { m_listeTables = new List <ITableDefinition>(); foreach (DataTable table in ds.Tables) { string strTableId = table.ExtendedProperties[CDataHotelTable.c_extPropTableId] as string; if (strTableId != null) { CTableDefinitionDataHotel tableDef = new CTableDefinitionDataHotel(strTableId, table.TableName); tableDef.AddColumn(new CColonneDefinitionHotelEntiteId("Data entity id")); tableDef.AddColumn(new CColonneDefinitionHotelDate("Data date")); foreach (DataColumn col in table.Columns) { string strColId = col.ExtendedProperties[CDataHotelField.c_extPropColumnId] as string; if (strColId != null) { CColonneDefinitionDataHotel colHotel = new CColonneDefinitionDataHotel(strColId, col.ColumnName); tableDef.AddColumn(colHotel); } } m_listeTables.Add(tableDef); CTableDefinitionEntitiesDataHotel tableE = new CTableDefinitionEntitiesDataHotel(strTableId, table.TableName); m_listeTables.Add(tableE); } } } } catch (Exception e) { } } }
//------------------------------------------------------- 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); }
//---------------------------------------------------------- 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); }