程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#調用WebService制作天氣預報

C#調用WebService制作天氣預報

編輯:C#入門知識

添加Web引用:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 天氣助手
{
    public partial class Weather : Form
    {
        public Weather()
        {
            InitializeComponent();
        }

        public string[] GetWeather(string xCity)
        {
            cn.com.webxml.www.WeatherWebService mWeatherWebService = new cn.com.webxml.www.WeatherWebService();
            string[] WeatherOfCity = mWeatherWebService.getWeatherbyCityName(xCity);
            return WeatherOfCity;
        }

        private void Weather_Load(object sender, EventArgs e)
        {


        }

        public void Weather_Shown(object sender, EventArgs e)
        {
            try
            {
                cn.com.webxml.www.WeatherWebService mWeatherWebService = new cn.com.webxml.www.WeatherWebService();
                string[] mArea = mWeatherWebService.getSupportProvince();

                int mCount = mArea.Length - 1;

                comboBox01.Items.Clear();
                for (int mI = 0; mI <= mCount; mI++)
                {
                    comboBox01.Items.Add(mArea[mI].ToString());

                }
                comboBox01.SelectedIndex = 0;

                              
            }
            catch
            {

            }
        }

        public void comboBox01_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                cn.com.webxml.www.WeatherWebService mWeatherWebService = new cn.com.webxml.www.WeatherWebService();
                string[] mCity = mWeatherWebService.getSupportCity(comboBox01.Text);

                int mCount = mCity.Length - 1;

                comboBox02.Items.Clear();
                for (int mI = 0; mI <= mCount; mI++)
                {
                    comboBox02.Items.Add(mCity[mI].Remove(mCity[mI].IndexOf("(")));

                }
                comboBox02.SelectedIndex = 0;
            }
            catch
            {

            }

        }

        public void comboBox02_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string[] WeatherOfCity = GetWeather(comboBox02.Items[comboBox02.SelectedIndex].ToString());

                label03.Text = WeatherOfCity[0].ToString();
                label05.Text = WeatherOfCity[1].ToString();

                label06.Text = WeatherOfCity[10].ToString();

                //今天
                pictureBox01.ImageLocation = @"images/weather/" + WeatherOfCity[8].ToString();
                pictureBox02.ImageLocation = @"images/weather/" + WeatherOfCity[9].ToString();
                label07.Text = WeatherOfCity[6].ToString() + WeatherOfCity[5].ToString() + WeatherOfCity[7].ToString();
                label08.Text = WeatherOfCity[11].ToString();               

                //明天
                pictureBox03.ImageLocation = @"images/weather/" + WeatherOfCity[15].ToString();
                pictureBox04.ImageLocat

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved