zoukankan      html  css  js  c++  java
  • C# QQ weather (二)

        /// <summary>
        /// 2011-06-16 塗聚文
        /// </summary>
        public partial class QQweather : System.Web.UI.Page
        {
    
            public string selectcity = "1";
            string strUrl = "http://weather.qq.com/inc/ss1.htm";
            /// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void Page_Load(object sender, EventArgs e)
            {
                ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
                HttpWebRequest req = (HttpWebRequest)WebRequest.CreateDefault(new Uri("http://www.dupcit.com/QQweather.aspx"));
                req.Method = "GET";
                HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                selectcity = DropDownList1.SelectedValue.ToString();
                if (!IsPostBack)
                {
    
                    this.DropDownList1.DataSource = CreateDataSource();
                    DropDownList1.DataTextField = "WeatherTextField";
                    DropDownList1.DataValueField = "WeatherValueField";
    
                    // Bind the data to the control.
                    DropDownList1.DataBind();
    
                    // Set the default selected item, if desired.
                    DropDownList1.SelectedIndex = 0;
                    selectcity = @"1";               
                    strUrl = "http://weather.qq.com/inc/ss1.htm";
                    geovindu.InnerHtml = getHttpData(strUrl); 
                }
    
    
            }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void Button1_Click(object sender, EventArgs e)
            {
                ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
                HttpWebRequest req = (HttpWebRequest)WebRequest.CreateDefault(new Uri("http://www.dupcit.com/QQweather.aspx"));
                req.Method = "GET";
                HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                selectcity = DropDownList1.SelectedValue.ToString();
                strUrl = "http://weather.qq.com/inc/ss"+selectcity+".htm";
                geovindu.InnerHtml = getHttpData(strUrl); 
    
    
    
    
            }
            /// <summary>
            /// <%# selectcity%>
            /// </summary>
            /// <returns></returns>
            ICollection CreateDataSource()
            {
    
             
                DataTable dt = new DataTable();            
                dt.Columns.Add(new DataColumn("WeatherTextField", typeof(String)));
                dt.Columns.Add(new DataColumn("WeatherValueField", typeof(String)));
                dt.Rows.Add(CreateRow("香港", "1", dt));
                dt.Rows.Add(CreateRow("澳門", "2", dt));
                dt.Rows.Add(CreateRow("哈爾濱", "17", dt));
                dt.Rows.Add(CreateRow("烏魯木齊", "28", dt));
                dt.Rows.Add(CreateRow("西寧", "56", dt));
                dt.Rows.Add(CreateRow("蘭州", "57", dt));
                dt.Rows.Add(CreateRow("呼和浩特", "69", dt));
                dt.Rows.Add(CreateRow("銀川", "78", dt));
                dt.Rows.Add(CreateRow("石家莊", "82", dt));
                dt.Rows.Add(CreateRow("太原", "84", dt));
                dt.Rows.Add(CreateRow("長春 ", "103", dt));
                dt.Rows.Add(CreateRow("瀋陽 ", "115", dt));
                dt.Rows.Add(CreateRow("北京 ", "125", dt));
                dt.Rows.Add(CreateRow("天津 ", "127", dt));
                dt.Rows.Add(CreateRow("濟南 ", "140", dt));
                dt.Rows.Add(CreateRow("拉薩 ", "150", dt));
                dt.Rows.Add(CreateRow("成都 ", "166", dt));
                dt.Rows.Add(CreateRow("昆明 ", "179", dt));
                dt.Rows.Add(CreateRow("西安 ", "186", dt));
                dt.Rows.Add(CreateRow("鄭州 ", "189", dt));
                dt.Rows.Add(CreateRow("武漢 ", "211", dt));
                dt.Rows.Add(CreateRow("重慶 ", "212", dt));
                dt.Rows.Add(CreateRow("長沙 ", "218", dt));
                dt.Rows.Add(CreateRow("貴陽 ", "227", dt));
                dt.Rows.Add(CreateRow("桂林 ", "232", dt));
                dt.Rows.Add(CreateRow("南京 ", "244", dt));
                dt.Rows.Add(CreateRow("合肥 ", "248", dt));
                dt.Rows.Add(CreateRow("上海 ", "252", dt));
                dt.Rows.Add(CreateRow("杭州 ", "255", dt));
                dt.Rows.Add(CreateRow("南昌 ", "264", dt));
                dt.Rows.Add(CreateRow("福州 ", "276", dt));
                dt.Rows.Add(CreateRow("臺北 ", "280", dt));
                dt.Rows.Add(CreateRow("廈門 ", "287", dt));
                dt.Rows.Add(CreateRow("廣州 ", "292", dt));
                dt.Rows.Add(CreateRow("南寧 ", "295", dt));
                dt.Rows.Add(CreateRow("深圳 ", "296", dt));
                dt.Rows.Add(CreateRow("海口 ", "303", dt));
                DataView dv = new DataView(dt);
                return dv;
    
            }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="Text"></param>
            /// <param name="Value"></param>
            /// <param name="dt"></param>
            /// <returns></returns>
            DataRow CreateRow(String Text, String Value, DataTable dt)
            {
                DataRow dr = dt.NewRow();
                dr[0] = Text;
                dr[1] = Value;
                return dr;
    
            }
            public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
            {
                //直接确认,否则打不开
                return true;
            }
            /// <summary>
            /// 
            /// </summary>
            /// <param name="url"></param>
            /// <returns></returns>
            public string getHttpData(string url)
            {
                WebClient myWebClient = new WebClient();
                Stream myStream = myWebClient.OpenRead(url);
                WebHeaderCollection myHeader = myWebClient.ResponseHeaders;
                string myCharset = myHeader.Get("Content-Type");
                Match myMatch = Regex.Match(myCharset, "(?<=(charset=)).*$");
                StreamReader myReader = new StreamReader(myStream, Encoding.GetEncoding(myMatch.ToString()));
                return myReader.ReadToEnd();
            } 
    
    哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)成功.---Geovin Du(涂聚文)
  • 相关阅读:
    【SHOI2002】百事世界杯之旅
    【LGOJ 3384】树链剖分
    [20191006机房测试] 括号序列
    [20191006机房测试] 矿石
    【SHOI2012】回家的路
    [20191005机房测试] Seat
    [20191005机房测试] Silhouette
    每年六一儿童节,牛客都会准备一些小礼物去看望孤儿院的小朋友,今年亦是如此。HF作为牛客的资深元老,自然也准备了一些小游戏。其中,有个游戏是这样的:首先,让小朋友们围成一个大圈。然后,他随机指定一个数m,让编号为0的小朋友开始报数。每次喊到m-1的那个小朋友要出列唱首歌,然后可以在礼品箱中任意的挑选礼物,并且不再回到圈中,从他的下一个小朋友开始,继续0...m-1报数....这样
    fgets函数读取最后一行的时候为什么会重复
    c语言中返回的变量地址,其物理地址在?(刨根问底)
  • 原文地址:https://www.cnblogs.com/geovindu/p/2083010.html
Copyright © 2011-2022 走看看