Пример #1
0
        //----------------------------------------------------------
        private void FillStructureTable(futurocom.easyquery.Sharepoint30.Lists service,
                                        CTableDefinitionSharepoint table)
        {
            if (table == null)
            {
                return;
            }
            try
            {
                XmlNode             node    = service.GetList(table.TableName) as XmlNode;
                XmlNamespaceManager manager = new XmlNamespaceManager(node.OwnerDocument.NameTable);
                manager.AddNamespace("sp", node.NamespaceURI);
                XmlNodeList liste = node.SelectNodes("sp:Fields/sp:Field", manager);
                List <CColonneDefinitionSharepoint> lstCols = new List <CColonneDefinitionSharepoint>();

                foreach (XmlNode childNode in liste)
                {
                    string strNom         = "";
                    string strId          = "";
                    string strType        = "";
                    string strDescription = "";
                    foreach (XmlAttribute attr in childNode.Attributes)
                    {
                        if (attr.Name.ToUpper() == "NAME")
                        {
                            strId = attr.Value;
                        }
                        if (attr.Name.ToUpper() == "NAME")
                        {
                            strNom = XmlConvert.DecodeName(attr.Value);
                        }
                        if (attr.Name.ToUpper() == "TYPE")
                        {
                            strType = attr.Value;
                        }
                        if (attr.Name.ToUpper() == "DESCRIPTION")
                        {
                            strDescription = XmlConvert.DecodeName(attr.Value);
                        }
                        if (strId.Length > 0 && strNom.Length > 0 && strType.Length > 0 && strDescription.Length > 0)
                        {
                            break;
                        }
                    }
                    CColonneDefinitionSharepoint col = new CColonneDefinitionSharepoint();
                    col.SharepointId = strId;
                    col.ColumnName   = strNom;
                    col.DataType     = typeof(string);
                    lstCols.Add(col);
                }
                lstCols.Sort((x, y) => x.ColumnName.CompareTo(y.ColumnName));
                foreach (CColonneDefinitionSharepoint c in lstCols)
                {
                    table.AddColumn(c);
                }
            }
            catch
            {
            }
        }
        //----------------------------------------------
        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);
        }
Пример #3
0
        //----------------------------------------------------------
        public DataTable GetDataWithCAML(ITableDefinition tableDefinition, string strCAMLQuery, params string[] strIdsColonnesSource)
        {
            DataTable tableResult            = null;
            CTableDefinitionSharepoint table = tableDefinition as CTableDefinitionSharepoint;

            if (table == null)
            {
                return(tableResult);
            }

            futurocom.easyquery.Sharepoint30.Lists service = new futurocom.easyquery.Sharepoint30.Lists();
            if (m_strURL.Length > 0)
            {
                service.Url = m_strURL;
            }
            service.Credentials = new NetworkCredential(m_strUser, m_strPassword);

            //Création de la liste des colonnes attendues
            XmlDocument doc        = new XmlDocument();
            XmlElement  nodeFields = null;

            if (strIdsColonnesSource.Length > 0)
            {
                nodeFields = doc.CreateElement("ViewFields");
                foreach (string strIdColonne in strIdsColonnesSource)
                {
                    XmlElement nodeField = doc.CreateElement("FieldRef");
                    nodeFields.AppendChild(nodeField);
                    XmlAttribute att = doc.CreateAttribute("Name");
                    att.Value = strIdColonne;
                    nodeField.Attributes.Append(att);
                }
            }
            XmlElement nodeQuery = null;

            if (strCAMLQuery.Length > 0)
            {
                nodeQuery = doc.CreateElement("Query");
                XmlElement nodeWhere = doc.CreateElement("Where");
                nodeQuery.AppendChild(nodeWhere);
                nodeWhere.InnerXml = strCAMLQuery;
            }
            XmlElement nodeQueryOptions = doc.CreateElement("QueryOptions");

            nodeQueryOptions.InnerXml = "";
            XmlNode node = service.GetListItems(table.Id, null, nodeQuery, nodeFields, "", nodeQueryOptions, null);

            XmlNamespaceManager manager = new XmlNamespaceManager(node.OwnerDocument.NameTable);

            foreach (XmlAttribute att in node.Attributes)
            {
                if (att.Name.StartsWith("xmlns:"))
                {
                    string strAbrv = att.Name.Substring(att.Name.IndexOf(":") + 1);
                    manager.AddNamespace(strAbrv, att.Value);
                }
            }
            XmlNodeList liste = node.SelectNodes("/rs:data/z:row", manager);

            tableResult = new DataTable(tableDefinition.TableName);
            //Création de la structure de la table
            Dictionary <string, DataColumn> dicCols = new Dictionary <string, DataColumn>();

            foreach (IColumnDefinition col in table.Columns)
            {
                CColonneDefinitionSharepoint colShp = col as CColonneDefinitionSharepoint;
                if (colShp != null && (strIdsColonnesSource.Length == 0 || strIdsColonnesSource.Contains(colShp.SharepointId)))
                {
                    DataColumn newCol = new DataColumn(col.ColumnName, col.DataType);
                    tableResult.Columns.Add(newCol);

                    dicCols[colShp.SharepointId] = newCol;
                }
            }

            foreach (XmlNode xmlRow in liste)
            {
                DataRow row = tableResult.NewRow();
                foreach (XmlAttribute att in xmlRow.Attributes)
                {
                    if (att.Name.StartsWith("ows_"))
                    {
                        string     strNomCol  = att.Name.Substring(4);
                        DataColumn colDeTable = null;
                        if (dicCols.TryGetValue(strNomCol, out colDeTable))
                        {
                            row[colDeTable] = att.Value;
                        }
                    }
                }
                try{
                    tableResult.Rows.Add(row);
                }
                catch {}
            }
            return(tableResult);
        }