資源簡介
獲取中行匯率數據,需要的同事可以下載,保證沒有問題
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Text.Regularexpressions;
using?System.Windows.Forms;
using?System.IO;
using?System.Net;
using?System.xml;
namespace?GetWebContent
{
????public?partial?class?Form1?:?Form
????{
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
???????????
????????????tb_html.Text?=?GetWebContent(tb_url.Text.Trim()).Trim();
????????????GetRate(tb_html.Text);
????????????MessageBox.Show(“OK“?“Notice“?MessageBoxButtons.OK?MessageBoxIcon.Information);
????????}
????????///?實時匯率換算(人民幣to外匯)? ???
????????///?外匯名稱如:英鎊、港幣、美元、日元、歐元????
????????///?人民幣價格???
????????///?返回實際外匯價格 ????
????????//public?Decimal?GetRMB(string?name?decimal?money)
????????//{
????????//????if?(name?!=?“人民幣“)???
????????//????{???
????????//????????string?wsrcString?=?GetWebContent(“http://www.boc.cn/cn/common/whpj.html“);//遠程獲取中行最新匯率???
????????//????????wsrcString?=?wsrcString.Substring(wsrcString.IndexOf(name)?wsrcString.Length?-?wsrcString.IndexOf(name));???
????????//????????string?regexStr?=?“yle=“\“?mce_style=“\“border-bottom:?#bcbbbb?1px?dashed;\“>(?.*?) “;???
????????//????????Regex?r?=?new?Regex(regexStr?RegexOptions.None);???
????????//????????Match?mc?=?r.Match(wsrcString);???
????????//????????money?=?100?/?decimal.Parse(mc.Groups[“key“].Value)?*?money;???
????????//????????return?Math.Round(Convert.ToDecimal(money)?2);???
????????//????}???
????????//????else??
????????//????{???
????????//????????return?money;???
????????//????}???
????????//}
????????///??獲取遠程HTML內容 ???
????????///?遠程網頁地址URL???
????????///?成功返回遠程HTML的代碼內容 ???
????????private?string?GetWebContent(string?strUrl)
????????{
????????????string?str?=?““;
????????????try
????????????{
????????????????WebClient?wc?=?new?WebClient();
????????????????wc.Credentials?=?CredentialCache.DefaultCredentials;
????????????????Encoding?enc?=?Encoding.GetEncoding(“UTF-8“);//?如果是亂碼就改成?UTF-8?/?GB2312????????????
????????????????//方法一:
????????????????//Byte[]?buffer?=?wc.DownloadData(strUrl);//?從資源下載數據并返回字節數組
????????????????//str?=?enc.GetString(buffer);//?輸出字符串(HTML代碼)
????????????????//方法二:
????????????????Stream?res?=?wc.OpenRead(strUrl);//以流的形式打開URL
????????????????//Stream?res?=?new?FileStream(@“E:\ExchangeRate\enindex.html“?FileMode.Open?FileAccess.Read);
????????????????StreamReader?sr?=?new?StreamReader(res?enc);//以指定的編碼方式讀取數據流
????????????????str?=?sr.ReadToEnd();//輸出(HTML代碼)
????????????????res.Close();
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????..A..H.?????16384??2013-07-18?13:57??GetWebContent.suo
?????文件??????13312??2013-07-18?13:57??GetWebContent\bin\Debug\GetWebContent.exe
?????文件??????32256??2013-07-18?13:57??GetWebContent\bin\Debug\GetWebContent.pdb
?????文件??????11592??2013-07-18?13:56??GetWebContent\bin\Debug\GetWebContent.vshost.exe
?????文件????????490??2007-07-21?02:33??GetWebContent\bin\Debug\GetWebContent.vshost.exe.manifest
?????文件?????134144??2012-08-06?21:30??GetWebContent\bin\Debug\HtmlAgilityPack.dll
?????文件???????9426??2013-07-18?13:57??GetWebContent\Form1.cs
?????文件???????8493??2013-07-16?18:45??GetWebContent\Form1.Designer.cs
?????文件???????6014??2013-07-16?18:45??GetWebContent\Form1.resx
?????文件???????4026??2013-07-16?16:23??GetWebContent\GetWebContent.csproj
?????文件????????168??2011-03-23?23:08??GetWebContent\GetWebContent.csproj.user
?????文件?????134144??2012-08-06?21:30??GetWebContent\HtmlAgilityPack.dll
?????文件???????1487??2013-07-18?13:56??GetWebContent\obj\Debug\GetWebContent.csproj.FileListAbsolute.txt
?????文件????????847??2013-07-16?18:45??GetWebContent\obj\Debug\GetWebContent.csproj.GenerateResource.Cache
?????文件??????13312??2013-07-18?13:57??GetWebContent\obj\Debug\GetWebContent.exe
?????文件????????180??2013-07-16?18:45??GetWebContent\obj\Debug\GetWebContent.Form1.resources
?????文件??????32256??2013-07-18?13:57??GetWebContent\obj\Debug\GetWebContent.pdb
?????文件????????180??2013-07-16?16:23??GetWebContent\obj\Debug\GetWebContent.Properties.Resources.resources
?????文件???????3943??2013-07-16?16:23??GetWebContent\obj\Debug\ResolveAssemblyReference.cache
?????文件????????494??2011-03-23?21:55??GetWebContent\Program.cs
?????文件???????1376??2011-03-23?21:55??GetWebContent\Properties\AssemblyInfo.cs
?????文件???????2876??2011-03-23?21:55??GetWebContent\Properties\Resources.Designer.cs
?????文件???????5612??2011-03-23?21:55??GetWebContent\Properties\Resources.resx
?????文件???????1098??2011-03-23?21:55??GetWebContent\Properties\Settings.Designer.cs
?????文件????????249??2011-03-23?21:55??GetWebContent\Properties\Settings.settings
?????文件????????929??2013-07-18?13:57??GetWebContent.sln
?????目錄??????????0??2011-03-23?22:28??GetWebContent\obj\Debug\Refactor
?????目錄??????????0??2011-03-23?21:55??GetWebContent\obj\Debug\TempPE
?????目錄??????????0??2013-07-16?16:23??GetWebContent\bin\Debug
?????目錄??????????0??2013-07-18?13:57??GetWebContent\obj\Debug
............此處省略7個文件信息
評論
共有 條評論