您的位置:首页 > 其它

天气预报的web服务的使用

2013-10-12 16:07 429 查看
添加Web引用:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx

重命名为:weather

public string[] GetWeather(string city)

{

weather.WeatherWebService webweather = new
cheshi.weather.WeatherWebService();//实例化天气的服务

string[] wcity = webweather.getWeatherbyCityName(city);

return wcity;

}

private void weathers_Shown(object sender, EventArgs e)

{

try

{

weather.WeatherWebService wweather = new
cheshi.weather.WeatherWebService();

string[] area = wweather.getSupportProvince();

int mount = area.Length - 1;

comboBox1.Items.Clear();

for (int im = 0; im < mount; im++)

{

comboBox1.Items.Add(area[im].ToString());

}

comboBox1.SelectedIndex = 0;

}

catch { }

}

private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)

{

try

{

weather.WeatherWebService weweather = new
cheshi.weather.WeatherWebService();

string[] mcity = weweather.getSupportCity(comboBox1.Text);

int mcount = mcity.Length - 1;

comboBox2.Items.Clear();

for (int i = 0; i < mcount; i++)

{

comboBox2.Items.Add(mcity[i].Remove(mcity[i].IndexOf("(")));

}

comboBox2.SelectedIndex = 0;

}

catch { }

}

private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)

{

try

{

string[] cityweather =
GetWeather(comboBox2.Items[comboBox2.SelectedIndex].ToString());

label1.Text = cityweather[0].ToString();

label2.Text = cityweather[1].ToString();

label3.Text = cityweather[10].ToString();

//今天

pictureBox1.ImageLocation =@"images/weather/"
+cityweather[8].ToString();

pictureBox2.ImageLocation = @"images/weather/" +
cityweather[9].ToString();

label4.Text = cityweather[6].ToString() + cityweather[5].ToString()
+ cityweather[7].ToString();

label5.Text = cityweather[11].ToString();

//明天

label6.Text = cityweather[13].ToString() +
cityweather[12].ToString() + cityweather[14].ToString();

//后天

label7.Text = cityweather[18].ToString() +
cityweather[17].ToString() + cityweather[19].ToString();

//城市说明及图片

pictureBox3.ImageLocation = @"http://www.cma.gov.cn/tqyb/img/city/"
+ cityweather[3].ToString();

label8.Text = cityweather[22].ToString();

//预计时间

label9.Text = "预报时间:" + cityweather[4].ToString();

}

catch { }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: