Пример #1
0
        //-----------------------------------
        public void FillStructureQuerySource(
            CEasyQuerySource source)
        {
            List <ITableDefinition> lstTables = ListeTables;

            if (lstTables != null && lstTables.Count > 0)
            {
                foreach (ITableDefinition table in lstTables)
                {
                    table.FolderId = source.RootFolder.Id;
                    table.SourceId = source.SourceId;
                    source.AddTableUniquementPourObjetConnexion(table);
                }
            }
        }
Пример #2
0
        //--------------------------------------------------------------------------------
        void m_menuProprietesConnexion_Click(object sender, EventArgs e)
        {
            TreeNode         node   = SelectedNode;
            CEasyQuerySource source = node != null ? node.Tag as CEasyQuerySource : null;

            if (source != null)
            {
                if (CFormProprietesQuerySource.EditeParametres(source))
                {
                    node.Text = source.SourceName;
                    source.ClearStructure();
                    RefreshTree();
                }
            }
        }
        //------------------------------------------------
        public string GetValue(CEasyQuerySource source)
        {
            CSnmpConnexionForEasyQuery filler = source.Connexion as CSnmpConnexionForEasyQuery;
            string strRetour = null;

            if (filler != null)
            {
                object val = filler.GetValue(m_strOID);
                if (val != null)
                {
                    strRetour = val.ToString();
                }
            }
            return(strRetour);
        }
Пример #4
0
        //----------------------------------------
        public override CResultAErreur GetDatas(CEasyQuerySource source, params string[] strIdsColonnesSource)
        {
            CResultAErreur          result = CResultAErreur.True;
            CStaticDataSetConnexion cnx    = source.Connexion as CStaticDataSetConnexion;

            if (cnx != null)
            {
                System.Data.DataTable table = cnx.GetData(this, strIdsColonnesSource);
                if (table != null)
                {
                    result.Data = table;
                }
            }
            return(result);
        }
Пример #5
0
        //------------------------------------------------
        public string GetValue(CEasyQuerySource source)
        {
            CSnmpTableFiller filler    = source.GetTableFiller(typeof(CSnmpTableFiller)) as CSnmpTableFiller;
            string           strRetour = null;

            if (filler != null)
            {
                object val = filler.GetValue(m_strOID);
                if (val != null)
                {
                    strRetour = val.ToString();
                }
            }
            return(strRetour);
        }
Пример #6
0
        private void CFormProprietesConnexion_Load(object sender, EventArgs e)
        {
            CEasyQuerySource    source = m_source;
            IEasyQueryConnexion cnx    = source.Connexion;
            IEnumerable <CEasyQueryConnexionProperty> props = cnx.ConnexionProperties;
            List <CCustomizableListItem> lst = new List <CCustomizableListItem>();

            m_txtNomSource.Text = source.SourceName;

            foreach (CEasyQueryConnexionProperty prop in props)
            {
                CCustomizableListItem item = new CCustomizableListItem();
                item.Tag = prop;
                lst.Add(item);
            }
            m_propertyGrid.Items = lst.ToArray();
            m_propertyGrid.Refill();
        }
Пример #7
0
        //--------------------------------------------------------------------------------
        void itemNewCnx_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem   item = sender as ToolStripMenuItem;
            IEasyQueryConnexion cnx  = item != null ? item.Tag as IEasyQueryConnexion : null;

            if (cnx != null)
            {
                cnx = (IEasyQueryConnexion)Activator.CreateInstance(cnx.GetType(), new object[0]);
                CEasyQuerySource src = new CEasyQuerySource();
                src.Connexion  = cnx;
                src.SourceName = cnx.ConnexionTypeName;
                if (CFormProprietesQuerySource.EditeParametres(src))
                {
                    m_sources.AddSource(src);
                    RefreshTree();
                }
            }
        }
Пример #8
0
 //--------------------------------------------------------------------------------
 private void CTreeListeTables_BeforeExpand(object sender, TreeViewCancelEventArgs e)
 {
     if (e.Node.Tag is CEasyQuerySource)
     {
         if (e.Node.Nodes.Count == 1 && e.Node.Nodes[0].Tag == null)
         {
             using (CWaitCursor waiter = new CWaitCursor())
             {
                 e.Node.Nodes.Clear();
                 CEasyQuerySource source = e.Node.Tag as CEasyQuerySource;
                 FillNodes(e.Node.Nodes, source, source.RootFolder);
             }
         }
     }
     else if (e.Node.Tag is ITableDefinition)
     {
         if (e.Node.Nodes.Count == 1 && e.Node.Nodes[0].Tag == null)
         {
             e.Node.Nodes.Clear();
             ITableDefinition table = e.Node.Tag as ITableDefinition;
             foreach (IColumnDefinition col in table.Columns)
             {
                 TreeNode node = new TreeNode(col.ColumnName);
                 node.Tag                = col;
                 node.ImageIndex         = GetImageNum(col.ImageKey);
                 node.SelectedImageIndex = node.ImageIndex;
                 e.Node.Nodes.Add(node);
             }
         }
     }
     else if (e.Node.Tag is CEasyQuerySourceFolder)
     {
         if (e.Node.Nodes.Count == 1 && e.Node.Nodes[0].Tag == null)
         {
             CEasyQuerySourceFolder folder = e.Node.Tag as CEasyQuerySourceFolder;
             e.Node.Nodes.Clear();
             FillNodes(e.Node.Nodes, folder.Source, folder);
             if (Nodes.Count == 1)
             {
                 Nodes[0].Expand();
             }
         }
     }
 }
Пример #9
0
 //-----------------------------------------------------
 public void FillStructureQuerySource(CEasyQuerySource source)
 {
     if (m_dataset != null)
     {
         foreach (DataTable table in m_dataset.Tables)
         {
             CTableDefinitionStaticDataSet def = new CTableDefinitionStaticDataSet(source);
             def.TableName = table.TableName;
             def.SetId(table.ExtendedProperties[c_strTableId] as string);
             foreach (DataColumn col in table.Columns)
             {
                 CColonneTableStaticDataset c = CColonneTableStaticDataset.GetForDataCol(col);
                 c.Table = def;
                 def.AddColumn(c);
             }
             source.AddTableUniquementPourObjetConnexion(def);
         }
         source.AddTableUniquementPourObjetConnexion(new CTableDefinitionManualTable());
     }
 }
Пример #10
0
        //-----------------------------------
        public static IEnumerable <ITableDefinition> FromMib(
            CEasyQuerySource laBase,
            ObjectRegistryBase mibBase,
            CEasyQuerySourceFolder folderRacine)
        {
            List <ITableDefinition> lst = new List <ITableDefinition>();

            if (laBase.Tables.FirstOrDefault(t => t.GetType() == typeof(CTableDefinitionStructureSNMP)) == null)
            {
                CTableDefinitionStructureSNMP table = new CTableDefinitionStructureSNMP();
                if (folderRacine != null)
                {
                    table.FolderId = folderRacine.Id;
                }
                lst.Add(table);
                table.Fill(mibBase);
                laBase.AddTable(table);
            }
            FillListeTables(laBase, mibBase.Tree.Root, lst, folderRacine);
            return(lst.AsReadOnly());
        }
Пример #11
0
        //-----------------------------------
        public override CResultAErreur GetDatas(CEasyQuerySource source, params string[] strIdsColonnesSources)
        {
            CResultAErreur result  = CResultAErreur.True;
            List <string>  strCols = new List <string>();

            foreach (IColumnDefinition col in Columns)
            {
                CColumnDefinitionSNMP colSnmp = col as CColumnDefinitionSNMP;
                if (colSnmp != null)
                {
                    if (strIdsColonnesSources.Contains(colSnmp.Id))
                    {
                        strCols.Add(colSnmp.OIDString);
                    }
                }
            }
            DataTable table = source.GetTable(this, strCols.ToArray());

            result.Data = table;
            return(result);
        }
Пример #12
0
        //-----------------------------------
        public static IEnumerable <ITableDefinition> FromMib(
            CEasyQuerySource laBase,
            IDefinition rootDefinition,
            CEasyQuerySourceFolder folderRacine)
        {
            List <ITableDefinition> lst = new List <ITableDefinition>();

            if (laBase.Tables.FirstOrDefault(t => t.GetType() == typeof(CTableDefinitionStructureSNMP)) == null)
            {
                CTableDefinitionStructureSNMP table = new CTableDefinitionStructureSNMP();
                if (folderRacine != null)
                {
                    table.FolderId = folderRacine.Id;
                }
                lst.Add(table);
                table.Fill(rootDefinition);
                laBase.AddTableUniquementPourObjetConnexion(table);
            }
            FillListeTables(laBase, rootDefinition, lst, folderRacine);
            return(lst.AsReadOnly());
        }
Пример #13
0
        //-----------------------------------
        public override CResultAErreur GetDatas(CEasyQuerySource source, params string[] strIdsColonnesSources)
        {
            CResultAErreur result  = CResultAErreur.True;
            List <string>  strCols = new List <string>();

            foreach (IColumnDefinition col in Columns)
            {
                CColumnDefinitionSNMP colSnmp = col as CColumnDefinitionSNMP;
                if (colSnmp != null)
                {
                    if (strIdsColonnesSources.Contains(colSnmp.Id))
                    {
                        strCols.Add(colSnmp.OIDString);
                    }
                }
            }
            DataTable table = source.GetTable(this, strCols.ToArray());

            if (table != null)
            {
                //Vérifie les types de colonnes, pour éviter les pbs de déclaration dans la mib (merci assentria)
                foreach (IColumnDefinition col in Columns)
                {
                    CColumnDefinitionSNMP colSnmp = col as CColumnDefinitionSNMP;
                    if (colSnmp != null)
                    {
                        DataColumn colDeTable = table.Columns[colSnmp.ColumnName];
                        if (colDeTable != null && colDeTable.DataType != col.DataType)
                        {
                            colSnmp.SnmpType = null;
                            colSnmp.DataType = colDeTable.DataType;
                        }
                    }
                }
            }
            object a = Columns;

            result.Data = table;
            return(result);
        }
Пример #14
0
        //-----------------------------------
        public static CTableDefinitionSNMP FromDefinition(
            CEasyQuerySource laBase,
            IDefinition def,
            CEasyQuerySourceFolder folder

            )
        {
            CTableDefinitionSNMP table = null;

            if (def.Type == DefinitionType.Table)
            {
                table           = new CTableDefinitionSNMP(laBase);
                table.TableName = def.Name;
                table.OID       = def.GetNumericalForm();

                if (folder != null)
                {
                    table.FolderId = folder.Id;
                }

                if (def.Children.Count() == 1)
                {
                    CColumnDefinitionSimple colIndex = new CColumnDefinitionSimple("Index", typeof(string));
                    table.AddColumn(colIndex);
                    IDefinition entry = def.Children.ElementAt(0);
                    foreach (IDefinition col in entry.Children)
                    {
                        if (col.Type == DefinitionType.Column)
                        {
                            CColumnDefinitionSNMP newCol = new CColumnDefinitionSNMP();
                            newCol.ColumnName = col.Name;
                            newCol.OID        = col.GetNumericalForm();
                            newCol.DataType   = typeof(string);
                            table.AddColumn(newCol);
                        }
                    }
                }
            }
            return(table);
        }
Пример #15
0
        //----------------------------------------------
        public override CResultAErreur GetDatas(CEasyQuerySource source, params string[] strIdsColonnesSource)
        {
            CResultAErreur result = CResultAErreur.True;

            CDataHotelConnexion filler = source.Connexion as CDataHotelConnexion;

            if (filler != null)
            {
                List <string> strColsHotel = new List <string>();
                foreach (IColumnDefinition col in Columns)
                {
                    if (strIdsColonnesSource.Contains(col.Id))
                    {
                        CColonneDefinitionDataHotel colHotel = col as CColonneDefinitionDataHotel;
                        if (colHotel != null)
                        {
                            strColsHotel.Add(colHotel.Id);
                        }
                    }
                }
            }
            return(result);
        }
        //----------------------------------------------
        public CResultAErreur GetDatasWithCAML(
            CEasyQuerySource source,
            CEasyQuery easyQuery,
            CCAMLQuery camlquery,
            params string[] strIdsColonnesSource)
        {
            CResultAErreur result = CResultAErreur.True;

            CSharepointConnexion filler = source.Connexion as CSharepointConnexion;

            if (filler != null)
            {
                List <string> strColsShp = new List <string>();
                foreach (IColumnDefinition col in Columns)
                {
                    if (strIdsColonnesSource.Contains(col.Id))
                    {
                        CColonneDefinitionSharepoint colShp = col as CColonneDefinitionSharepoint;
                        if (colShp != null)
                        {
                            strColsShp.Add(colShp.SharepointId);
                        }
                    }
                }
                string strCAMLQuery = "";
                if (camlquery != null && easyQuery != null)
                {
                    strCAMLQuery = camlquery.GetXmlText(easyQuery);
                }
                System.Data.DataTable table = filler.GetDataWithCAML(
                    this,
                    strCAMLQuery,
                    strColsShp.ToArray());
                result.Data = table;
            }
            return(result);
        }
Пример #17
0
 //-----------------------------------
 public CTableDefinitionSNMP(CEasyQuerySource laBase)
     : base(laBase)
 {
 }
Пример #18
0
        //-----------------------------------
        private static void FillListeTables(
            CEasyQuerySource laBase,
            IDefinition definition,
            List <ITableDefinition> lstToFill,
            CEasyQuerySourceFolder folderRacine)
        {
            CTableDefinitionSnmpOfScalar tableScalars = null;

            if (definition.Entity != null)
            {
                tableScalars           = new CTableDefinitionSnmpOfScalar();
                tableScalars.OIDRacine = definition.GetNumericalForm();
                tableScalars.TableName = folderRacine.Name + "_Scalars";
                tableScalars.FolderId  = folderRacine.Id;
            }
            foreach (IDefinition children in definition.Children)
            {
                if (children.Type == DefinitionType.Table)
                {
                    CTableDefinitionSNMP table = FromDefinition(laBase, children, folderRacine);
                    if (table != null)
                    {
                        lstToFill.Add(table);
                        laBase.AddTableUniquementPourObjetConnexion(table);
                    }
                }
                else if (children.Type == DefinitionType.OidValueAssignment)
                {
                    CEasyQuerySourceFolder folder = folderRacine.GetSubFolderWithCreate(children.Name);
                    FillListeTables(laBase, children, lstToFill, folder);
                }
                else if (children.Type == DefinitionType.Scalar)
                {
                    if (children.Type == DefinitionType.Scalar && tableScalars != null)
                    {
                        CColumnDefinitionSNMP colSnmp = new CColumnDefinitionSNMP();
                        colSnmp.ColumnName = children.Name;
                        colSnmp.OID        = children.GetNumericalForm();
                        Type       tp      = typeof(string);
                        ObjectType objType = children.Entity as ObjectType;
                        if (objType != null)
                        {
                            TextualConvention conv = objType.Syntax as TextualConvention;
                            if (conv != null)
                            {
                                tp = ((AbstractTypeAssignment)conv.Syntax).GetTypeDotNet();
                            }
                            else
                            {
                                AbstractTypeAssignment abs = objType.Syntax as AbstractTypeAssignment;
                                if (abs != null)
                                {
                                    tp = abs.GetTypeDotNet();
                                }
                            }
                        }
                        switch (objType.Access)
                        {
                        case MaxAccess.accessibleForNotify:
                        case MaxAccess.readOnly:
                            colSnmp.IsReadOnly = true;
                            break;

                        case MaxAccess.readWrite:
                        case MaxAccess.readCreate:
                            colSnmp.IsReadOnly = false;
                            break;
                        }
                        colSnmp.DataType = tp;
                        tableScalars.AddColumn(colSnmp);
                    }
                }
            }
            if (tableScalars != null && tableScalars.Columns.Count() > 0)
            {
                laBase.AddTableUniquementPourObjetConnexion(tableScalars);
                tableScalars.Base = laBase;
            }
        }
Пример #19
0
        //-----------------------------------
        public static CTableDefinitionSNMP FromDefinition(
            CEasyQuerySource laBase,
            IDefinition def,
            CEasyQuerySourceFolder folder

            )
        {
            CTableDefinitionSNMP table = null;

            if (def.Type == DefinitionType.Table)
            {
                table           = new CTableDefinitionSNMP(laBase);
                table.TableName = def.Name;
                table.OID       = def.GetNumericalForm();

                if (folder != null)
                {
                    table.FolderId = folder.Id;
                }

                if (def.Children.Count() == 1)
                {
                    CColumnDefinitionSimple colIndex = new CColumnDefinitionSimple("Index", typeof(string));
                    table.AddColumn(colIndex);
                    IDefinition entry = def.Children.ElementAt(0);
                    foreach (IDefinition col in entry.Children)
                    {
                        if (col.Type == DefinitionType.Column)
                        {
                            ObjectType objType = col.Entity as ObjectType;
                            if (objType != null && objType.Access != MaxAccess.notAccessible)
                            {
                                CColumnDefinitionSNMP newCol = new CColumnDefinitionSNMP();
                                newCol.ColumnName  = col.Name;
                                newCol.Description = col.Description;
                                newCol.OID         = col.GetNumericalForm();
                                TextualConvention conv = objType.Syntax as TextualConvention;
                                if (conv != null)
                                {
                                    newCol.SnmpType = conv.Syntax as AbstractTypeAssignment;
                                }
                                else
                                {
                                    newCol.SnmpType = objType.Syntax as AbstractTypeAssignment;
                                }
                                if (newCol.SnmpType == null)
                                {
                                    newCol.DataType   = typeof(string);
                                    newCol.IsReadOnly = true;
                                }
                                switch (objType.Access)
                                {
                                case MaxAccess.accessibleForNotify:
                                case MaxAccess.readOnly:
                                    newCol.IsReadOnly = true;
                                    break;

                                case MaxAccess.readWrite:
                                case MaxAccess.readCreate:
                                    newCol.IsReadOnly = false;
                                    break;
                                }
                                table.AddColumn(newCol);
                            }
                        }
                    }
                }
            }
            return(table);
        }
Пример #20
0
        //-------------------------------------
        public CResultAErreur FillFromSNMP(CInterrogateurSnmp agent)
        {
            CResultAErreur result = CResultAErreur.True;

            try
            {
                agent.Connexion.Version  = SnmpVersion;
                agent.ConnexionIp        = Ip;
                agent.ConnexionPort      = SnmpPort;
                agent.ConnexionCommunity = Communaute;
                CEasyQuerySource source = new CEasyQuerySource();
                source.Connexion = new CSnmpConnexionForEasyQuery(agent);
                if (TypeAgent != null)
                {
                    foreach (CTypeEntiteSnmpPourSupervision typeEntite in TypeAgent.TypesEntites)
                    {
                        //Repere tous les existants
                        Dictionary <string, CEntiteSnmpPourSupervision> dicEntites = new Dictionary <string, CEntiteSnmpPourSupervision>();
                        foreach (CEntiteSnmpPourSupervision entite in GetEntites(typeEntite))
                        {
                            string strIndex = entite.Index;
                            if (strIndex != null)
                            {
                                dicEntites[strIndex] = entite;
                            }
                        }
                        //récupère les données de la table
                        CODEQBase objetDeQuery = typeEntite.GetObjetDeQuery(TypeAgent);
                        if (objetDeQuery != null)
                        {
                            CEasyQueryFromEasyQueryASourcesSpecifique query = new CEasyQueryFromEasyQueryASourcesSpecifique(objetDeQuery.Query, source);
                            DataTable table = query.GetTable(objetDeQuery.NomFinal);
                            if (table != null)
                            {
                                foreach (DataRow row in table.Rows)
                                {
                                    CEntiteSnmpPourSupervision entite = new CEntiteSnmpPourSupervision(Database);
                                    entite.CreateNew();
                                    entite.AgentSnmp  = this;
                                    entite.TypeEntite = typeEntite;
                                    entite.FillFromSource(row);
                                    entite.UpdateIndexEtLibelle();
                                    string strIndex = entite.Index;
                                    //Si l'entité existe déjà
                                    CEntiteSnmpPourSupervision oldEntite = Entites.FirstOrDefault(
                                        e => e.Index == strIndex &&
                                        e.TypeEntite.Id == typeEntite.Id &&
                                        e.Id != entite.Id);
                                    if (oldEntite != null)
                                    {
                                        oldEntite.FillFromSource(row);
                                        entite.Delete();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                result.EmpileErreur(new CErreurException(e));
            }
            return(result);
        }
 //----------------------------------------------
 public override CResultAErreur GetDatas(CEasyQuerySource source, params string[] strIdsColonnesSource)
 {
     return(GetDatasWithCAML(source, null, null, strIdsColonnesSource));
 }
 //------------------------------------------------
 public static void Autoexec()
 {
     CEasyQuerySource.RegisterImageForFolder(c_strImageScalar, Resources.number16);
 }
Пример #23
0
 //--------------------------------------------------------
 public override CResultAErreur GetDatas(CEasyQuerySource source, params string[] strIdsColonnesSource)
 {
     return(CResultAErreur.True);
 }
Пример #24
0
 //-----------------------------------
 public CTableDefinitionSnmpOfScalar(CEasyQuerySource laBase)
     : base(laBase)
 {
 }
Пример #25
0
        //-------------------------------------------------------
        protected override CResultAErreur GetDatasHorsCalculees(CListeQuerySource sources)
        {
            CResultAErreur result = CResultAErreur.True;



            if (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);
            }


            CTableDefinitionEntitiesDataHotel tableHotel = m_definitionTable as CTableDefinitionEntitiesDataHotel;

            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);
            }



            DataTable tableResult = hotelConnexion.GetData(tableHotel, dateDebut.Value, dateFin.Value);

            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);
        }
Пример #26
0
 //-----------------------------------------------------
 public void FillStructureQuerySource(CEasyQuerySource source)
 {
 }
Пример #27
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);
        }
Пример #28
0
 //---------------------------------------------------
 public CTableDefinitionStaticDataSet(CEasyQuerySource laBase)
     : base(laBase)
 {
     m_strId = Guid.NewGuid().ToString();
 }