1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Xml;
using System.Collections;
namespace Annuaire
{
public partial class Form1 : Form
{
private List<cAnnuaireResult> m_ListAnnuaireResult = new List<cAnnuaireResult>();
private List<String> m_strId = new List<String>();
private List<String> m_strQtePhones = new List<String>();
private List<ArrayList> m_strPhone = new List<ArrayList>();
public Form1()
{
InitializeComponent();
nbOfResults.Text = "10";
}
private void button1_Click(object sender, EventArgs e)
{
string strUrl = @"http://webservice118000.fr/distribution/android?apikey=dcf36f9fd6ddb3fe9fdb582b29971eb1fe43015fc03c8607";
strUrl = strUrl + "&qs=" + QuiQuoi.Text + "&dv=" + Localite.Text + "&mr=" + nbOfResults.Text;
string address = string.Format(strUrl, Uri.EscapeDataString("escape me"), Uri.EscapeDataString("& me !!"));
string xmlString;
using (WebClient client = new WebClient())
{
client.Encoding = System.Text.Encoding.UTF8;
xmlString = client.DownloadString(address);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlString);
xmlDoc.Save(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\result_118218.xml");
XmlNodeList Nom = xmlDoc.GetElementsByTagName("name");
foreach (XmlNode node in Nom)
{
XmlElement NameElement = (XmlElement)node;
if (NameElement.HasAttributes)
{
m_strId.Add(NameElement.Attributes["cc"].InnerText);
}
}
ArrayList list = new ArrayList();
XmlNodeList QtePhone = xmlDoc.GetElementsByTagName("phone");
foreach (XmlNode node in QtePhone)
{
XmlElement NameElement = (XmlElement)node;
if (NameElement.HasAttributes)
{
m_strQtePhones.Add(NameElement.Attributes["qty"].InnerText);
}
}
XmlNodeList PhoneNumber = xmlDoc.GetElementsByTagName("line");
int k = 0;
int qte = 0;
foreach (XmlNode nodeBis in PhoneNumber)
{
qte = Int32.Parse(m_strQtePhones[k].ToString());
XmlElement NameElementBis = (XmlElement)nodeBis;
if (NameElementBis.HasAttributes)
{
string[] tab;
tab = new string[2];
tab[0] = NameElementBis.Attributes["t"].InnerText;
tab[1] = NameElementBis.Attributes["n"].InnerText;
list.Add(tab);
m_strPhone.Add(list);
}
qte++;
k++;
if (qte>k)
{
list.Clear();
k = 0;
}
}
XmlNodeList FirstName = xmlDoc.GetElementsByTagName("firstname");
XmlNodeList Ville = xmlDoc.GetElementsByTagName("city");
XmlNodeList CPostal = xmlDoc.GetElementsByTagName("post");
XmlNodeList Mail = xmlDoc.GetElementsByTagName("em");
XmlNodeList Rue = xmlDoc.GetElementsByTagName("addr");
m_ListAnnuaireResult.Clear();
for (int i = 0; i <= m_strId.Count() - 1; i++)
{
m_ListAnnuaireResult.Add(new cAnnuaireResult(Nom[i].InnerXml, FirstName[i].InnerXml, m_strPhone[i], "", Rue[i].InnerXml, Ville[i].InnerXml, CPostal[i].InnerXml));
}
m_strId.Clear();
m_strPhone.Clear();
dataGridView1.DataSource = m_ListAnnuaireResult;
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
if (column.HeaderText.Trim().ToUpper()=="STRTEL")
{
column.HeaderText = "Téléphone";
}
if (column.HeaderText.Trim().ToUpper() == "STRVILLE")
{
column.HeaderText = "Ville";
}
if (column.HeaderText.Trim().ToUpper() == "STRCPOSTAL")
{
column.HeaderText = "Code Postal";
}
if (column.HeaderText.Trim().ToUpper() == "STRNOM")
{
column.HeaderText = "Nom";
}
if (column.HeaderText.Trim().ToUpper() == "STRPRENOM")
{
column.HeaderText = "Prenom";
}
if (column.HeaderText.Trim().ToUpper() == "STRMAIL")
{
column.HeaderText = "Adresse e-mail";
}
if (column.HeaderText.Trim().ToUpper() == "STRRUE")
{
column.HeaderText = "Rue";
}
}
}
}
}
} |
Partager