汇率 [英] Currency exchange rate

查看:105
本文介绍了汇率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi I'm new to dotnet platform...I want to know the code for currency exchange rate in asp.net..can any one help me?

< br $> b $ b

我尝试过:



这是我的代码



ASP.Net代码





What I have tried:

This is my code

ASP.Net code

<div>
    <table>
    <tr>
    <td>
        <asp:Label ID="lbl_Amount" runat="server" Text="Amount"></asp:Label></td>
        <td>
            <asp:TextBox ID="txt_amount" runat="server"></asp:TextBox>
            </td></tr>
            <tr>
            <td>
                <asp:Label ID="lbl_FromCurrency" runat="server" Text="From Currency"></asp:Label> </td>
                <td>
                    <asp:TextBox ID="txt_fromCurrency" runat="server"></asp:TextBox>
                    </td></tr>
                    <tr>
                    <td>
                        <asp:Label ID="lbl_toCurrency" runat="server" Text="To Currency"></asp:Label></td>
                   
                   <td>
                       <asp:TextBox ID="txt_ToCurrency" runat="server"></asp:TextBox></td> </tr>
                       <tr><td>
                           <asp:Label ID="lbl_value" runat="server" Text=""></asp:Label></td>
                       <td>
                           <asp:Button ID="Btn_Convert" runat="server" Text="Convert"  OnClick="CurrencyConversion"/></td></tr></table>
    </div>





C#代码





C# Code

public string CurrencyConversion(decimal amount, string fromCurrency, string toCurrency)
       {
           WebClient web = new WebClient();
           string url = string.Format("https://www.google.com/finance/converter?from={0}&to={1}&a={2}", fromCurrency.ToUpper(), toCurrency.ToUpper(), amount);
           string response = web.DownloadString(url);
           Regex regex = new Regex("<span class=bld>(.*?)</span>");

           var result = regex.Match(response).Groups[1].Value;
           return result;
       }

推荐答案

查看这些:

1. 使用API​​的ASP.NET实时货币转换器(谷歌,雅虎) ,Web服务和jQuery Ajax [ ^ ]

2. [ ^ ]
Check these out:
1. ASP.NET Real-time Currency Converter using API (Google, Yahoo), Web service, and jQuery Ajax[^]
2. Currency Conversion as per Exchange Rates using Google Finance API Web Service in ASP.Net[^]


EuropeanCentralBank有一些可能性。

欧元外汇参考汇率 [ ^ ]



The EuropeanCentralBank has some possibilyties.
Euro foreign exchange reference rates[^]

public static DataTable GetCurrencyListFromWeb1()
       {
           DataTable returnList = new DataTable();
           returnList.Columns.Add("currency", typeof(string));
           returnList.Columns.Add("rate", typeof(decimal));
           Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
           string date = string.Empty;
           using (XmlReader xmlr = XmlReader.Create(@"https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"))
           {
               xmlr.ReadToFollowing("Cube");
               while (xmlr.Read())
               {
                   if (xmlr.NodeType != XmlNodeType.Element) continue;
                   if (xmlr.GetAttribute("time") != null)
                   {
                       date = xmlr.GetAttribute("time");
                   }
                   else returnList.Rows.Add(xmlr.GetAttribute("currency"), decimal.Parse(xmlr.GetAttribute("rate"), CultureInfo.CurrentCulture));
               }
           }
           returnList.Rows.Add("EUR", 1);
           return returnList;
       }


这篇关于汇率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆