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> ?? 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; } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- angularjs – ng-repeat在编译html后没有加载数据
- angularjs – 使用Angular UI-Router更改URL,不执
- shell 1>&2 2>&1 &&
- twitter-bootstrap – 始终显示bootstrap-datepi
- angular – 将数据从html主体传递到根组件
- 【WebService】6.处理Map等CXF无法自动转换的值
- vim – 如何说服nerdtree在当前窗口中打开文件
- angular – Http获取404 Not URL for URL:null
- 信息系统项目管理系列之九:项目质量管理
- 在文件的某个位置(行和列)启动Vim
热点阅读