Posted on Saturday, May 22, 2010 3:39:23 PM and it has been read 2648 times since then.
Indicative Exchange Rates Announced by the Central Bank of Turkey For Daily Basis
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
DataTable result = getCurrencyRates();
if (result != null)
{
if (result.Rows.Count > 0)
{
GridView grid = new GridView();
grid.DataSource = result;
grid.DataBind();
divCurrency.Controls.Add(grid);
}
}
}
catch
{
divCurrency.InnerHtml = @"An error occurred while trying to get exchange rates.";
}
}
}
public DataTable getCurrencyRates()
{
string dateValue = XDocument.Load("http://www.tcmb.gov.tr/kurlar/today.xml").Element("Tarih_Date").Attribute("Tarih").Value;
var resultSet = from result in XDocument.Load("http://www.tcmb.gov.tr/kurlar/today.xml").Descendants("Currency")
.Where(result => result.Descendants("Isim").Any())
.Where(result => result.Descendants("CurrencyName").Any())
.Where(result => result.Descendants("ForexBuying").Any())
.Where(result => result.Descendants("ForexSelling").Any())
.Where(result => result.Descendants("BanknoteBuying").Any())
.Where(result => result.Descendants("BanknoteSelling").Any())
select new
{
Adi = result.Element("Isim").Value,
Kod = result.Element("CurrencyName").Value,
DovizAlis = result.Element("ForexBuying").Value,
DovizSatis = result.Element("ForexSelling").Value,
EfektifAlis = result.Element("BanknoteBuying").Value,
EfektifSatis = result.Element("BanknoteSelling").Value
};
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("Tarih", typeof(string))); //Date
dt.Columns.Add(new DataColumn("Döviz Adı", typeof(string))); //CurrencyName
dt.Columns.Add(new DataColumn("Kod", typeof(string))); //CurrencyCode
dt.Columns.Add(new DataColumn("Doviz Alış", typeof(string))); //ForexBuying
dt.Columns.Add(new DataColumn("Döviz Satış", typeof(string))); //ForexSelling
dt.Columns.Add(new DataColumn("Efektif Alış", typeof(string))); //BanknoteBuying
dt.Columns.Add(new DataColumn("Efektif Satış", typeof(string))); //BanknoteSelling
foreach (var currency in resultSet)
{
dr = dt.NewRow();
dr[0] = dateValue;
dr[1] = currency.Adi;
dr[2] = currency.Kod;
dr[3] = currency.DovizAlis;
dr[4] = currency.DovizSatis;
dr[5] = currency.EfektifAlis;
dr[6] = currency.EfektifSatis;
dt.Rows.Add(dr);
}
return dt;
}
}
- Downloadable File/s - |
|||
---|---|---|---|
File Name | File Size | Description | |
exchangeratescentralbankofturkey.zip | 28.392 KB | Exchange Rates Announced by the Central Bank of Turkey For Daily Basis | Download |