189 8069 5689

C#调用WebService制作天气预报-创新互联

添加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 = @"p_w_picpaths/weather/" + WeatherOfCity[8].ToString();
                pictureBox02.ImageLocation = @"p_w_picpaths/weather/" + WeatherOfCity[9].ToString();
                label07.Text = WeatherOfCity[6].ToString() + WeatherOfCity[5].ToString() + WeatherOfCity[7].ToString();
                label08.Text = WeatherOfCity[11].ToString();       

               //明天
                pictureBox03.ImageLocation = @"p_w_picpaths/weather/" + WeatherOfCity[15].ToString();
                pictureBox04.ImageLocation = @"p_w_picpaths/weather/" + WeatherOfCity[16].ToString();
                label16.Text = WeatherOfCity[13].ToString() + WeatherOfCity[12].ToString() + WeatherOfCity[14].ToString();

               //后天
                pictureBox05.ImageLocation = @"p_w_picpaths/weather/" + WeatherOfCity[20].ToString();
                pictureBox06.ImageLocation = @"p_w_picpaths/weather/" + WeatherOfCity[21].ToString();
                label17.Text = WeatherOfCity[18].ToString() + WeatherOfCity[17].ToString() + WeatherOfCity[19].ToString();

               //城市说明及图片
                pictureBox07.ImageLocation = @"http://www.cma.gov.cn/tqyb/img/city/" + WeatherOfCity[3].ToString();
                label18.Text = WeatherOfCity[22].ToString();

               //预计时间
                label19.Text = "预报时间:" + WeatherOfCity[4].ToString();

           }
            catch
            {

           }
        }

   }
}

创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。


网页题目:C#调用WebService制作天气预报-创新互联
分享链接:http://cdxtjz.com/article/ddcees.html

其他资讯