加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

WebServices/Weather/

发布时间:2020-12-16 21:57:17 所属栏目:安全 来源:网络整理
导读:源码地址:http://download.csdn.net/detail/ericwuhk/9719157 ?/// ? summary ?? ?/// ? 调用webservice接口获取城市天气情况 ? ? ? ?/// ? /summary ? ?? using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;u

源码地址:http://download.csdn.net/detail/ericwuhk/9719157


?/// ? <summary> ??
?/// ? 调用webservice接口获取城市天气情况 ? ? ?
?/// ? </summary> ? ??

 


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;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public WeatherWS.WeatherWS ws;
        public Form1()
        {
            InitializeComponent();
            ws = new WeatherWS.WeatherWS();
        }

        private void button1_Click(object sender,EventArgs e)
        {            
            DataSet ds = ws.getRegionDataset();          
            DataTable  dt=ds.Tables[0];
            String str_temp;
            this.comboBox1.Items.Clear();
            //for (int i = dt.Rows.Count-1; i >=0; i--)
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                str_temp=dt.Rows[i][0].ToString() + dt.Rows[i][1].ToString();
                this.comboBox1.Items.Add(str_temp);                
            }
            this.comboBox1.SelectedIndex=0;             
        }

        private void comboBox1_SelectedIndexChanged(object sender,EventArgs e)
        {
            String provinceCode=GetNumbers(this.comboBox1.Text);
            DataSet ds = ws.getSupportCityDataset(provinceCode);
            DataTable dt = ds.Tables[0];
            String str_temp;
            this.comboBox2.Items.Clear();
            this.listBox1.Items.Clear();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                str_temp = dt.Rows[i][0].ToString() + dt.Rows[i][1].ToString();
                //listBox1.Items.Insert(0,str_temp);
                listBox1.Items.Add(str_temp);
                this.comboBox2.Items.Add(str_temp);               
            }

            this.comboBox2.SelectedIndex = 0;
            //this.comboBox2.SelectedIndex = dt.Rows.Count-1;

        }


        private void comboBox2_SelectedIndexChanged(object sender,EventArgs e)
        {
            String theCityID = GetNumbers(this.comboBox2.Text);
            string[] str;
            string str_temp;
            str = ws.getWeather(theCityID,"");
            listBox2.Items.Clear();
            //for (int i = 0; i < str.Length; i++)
            for (int i = str.Length - 1; i >= 0; i--)
            {
                str_temp = str[i];
                listBox2.Items.Insert(0,str_temp);
            }
        }


        ///   <summary>   
        ///   从字符串中提取所有数字   
        ///     Returns:所有数字   
        ///   </summary>     
        ///   <param   name   =   "p_str">   需要提取的字符串   </param>   
        ///   <returns>   所有数字   </returns>  
        ///   
        public static string GetNumbers(string p_str)
        {
            string strReturn = string.Empty;
            if (p_str == null || p_str.Trim() == "")
            {
                strReturn = "";
            }

            foreach (char chrTemp in p_str)
            {
                if (!Char.IsNumber(chrTemp))
                {
                    strReturn += chrTemp.ToString();
                }
            }
            return strReturn;
        }

        private void listBox1_SelectedIndexChanged(object sender,EventArgs e)
        {
            this.comboBox2.SelectedIndex=this.listBox1.SelectedIndex;
        }

    }
}

参考网址:http://ws.webxml.com.cn/WebServices/WeatherWS.asmx

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读