using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Web.Services; using System.Xml; /* Project / Add Web Reference http://www.webservicex.net/globalweather.asmx?op=GetWeather */ namespace WSPogoda { public partial class Form1 : Form { net.webservicex.www.GlobalWeather gw; XmlDocument miasta = new XmlDocument(); XmlDocument pogoda = new XmlDocument(); string panstwo; public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) // miasto { panstwo = (string)listBox1.SelectedItem; if (panstwo == null) { MessageBox.Show("Wybierz Państwo."); return; } listBox2.Items.Clear(); // lista miast string st; Cursor.Current = Cursors.WaitCursor; st = gw.GetCitiesByCountry(panstwo); Cursor.Current = Cursors.Default; try { miasta.LoadXml(st); } catch (XmlException er) { MessageBox.Show(er.Message); } ArrayList ar = new ArrayList(); XmlNodeList xlist = miasta.GetElementsByTagName("City"); foreach (XmlNode xn in xlist) { st = xn.FirstChild.Value; ar.Add(st); } ar.Sort(); listBox2.Items.AddRange(ar.ToArray()); } private void button3_Click(object sender, EventArgs e) // pogoda { string miasto = (string)listBox2.SelectedItem; if (miasto == null) { MessageBox.Show("Wybierz Miasto."); return; } string st; Cursor.Current = Cursors.WaitCursor; st = gw.GetWeather(miasto, panstwo); Cursor.Current = Cursors.Default; try { pogoda.LoadXml(st); } catch (XmlException er) { textBox1.Text = "Brak danych."; // opis pogody return; } ArrayList ar = new ArrayList(); try { XmlNodeList xlist = pogoda.GetElementsByTagName("Time"); ar.Add("Czas : "); ar.Add(xlist.Item(0).FirstChild.Value); xlist = pogoda.GetElementsByTagName("Temperature"); ar.Add("Temperatura : "); ar.Add(xlist.Item(0).FirstChild.Value); xlist = pogoda.GetElementsByTagName("DewPoint"); ar.Add("Punkt rosy : "); ar.Add(xlist.Item(0).FirstChild.Value); xlist = pogoda.GetElementsByTagName("RelativeHumidity"); ar.Add("Wilgotność : "); ar.Add(xlist.Item(0).FirstChild.Value); xlist = pogoda.GetElementsByTagName("Pressure"); ar.Add("Ciśnienie : "); ar.Add(xlist.Item(0).FirstChild.Value); xlist = pogoda.GetElementsByTagName("Wind"); ar.Add("Wiatr : "); ar.Add(xlist.Item(0).FirstChild.Value); xlist = pogoda.GetElementsByTagName("Visibility"); ar.Add("Widoczność : "); ar.Add(xlist.Item(0).FirstChild.Value); xlist = pogoda.GetElementsByTagName("SkyConditions"); ar.Add("Zachmurzenie : "); ar.Add(xlist.Item(0).FirstChild.Value); textBox1.Lines = (string[])ar.ToArray(typeof(string)); } catch { textBox1.Text = "Brak danych."; } } private void Form1_Load(object sender, EventArgs e) { gw = new net.webservicex.www.GlobalWeather(); listBox1.Items.AddRange(new object[] // wykaz państw { "Argentina", "Australia", "Burkina Faso", "Belgium", "Canada", "China", "Denmark", "Estonia", "France", "Germany", "Greece", "India", "Italy", "Japan", "Mexico", "Peru", "Poland", "Portugal", "Russia", "South Africa", "Spain", "Sweden", "Thailand", "Uganda", "United Kingdom", "United States"}); } } }