Quantcast
Channel: Home Page http://blogs.dotnethell.it
Viewing all articles
Browse latest Browse all 24464

Import Exchange Rates from Central European Bank

$
0
0

CodeunitImport Exchange Rates

A very simply codeunit to import daily exchange rates directly from Central European Bank with XML Filestream IN


Documentation Section

//*** Import "New Change Rate" from  "ECB.EUROPA.EU"    --> FIX TIME >= 2.00 AM
//*** Import XML File "Change Rate" from "ECB.EUROPA.EU" --> "eurofxref-daily.xml"
//*** XmlTextReader Global Dim  DotNet  System.Xml.XmlTextReader.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
            
Global Variables
XmlTextReader DotNet  System.Xml.XmlTextReader.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 
codCurrency Code 20
decRate  Decimal  
datValueDate  Date  
intYear  Integer  
intMonth  Integer  
intDay  Integer  
intNodeCounter  Integer  
Currency Record  Currency 
CurrencyExchangeRate Record  Currency Exchange Rate 


OnRun() Section

//Direct XML Text Reader (XML Stream IN)
XmlTextReader := XmlTextReader.XmlTextReader('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml');
 
//LOOP XML STREAMING IN
WHILE XmlTextReader.Read DO BEGIN
  IF XmlTextReader.Name = 'Cube' THEN BEGIN
    IF XmlTextReader.AttributeCount = 1 THEN BEGIN
      XmlTextReader.MoveToAttribute('time');  //Time
      EVALUATE(intYear,COPYSTR(XmlTextReader.Value,1,4));   //Year
      EVALUATE(intMonth,COPYSTR(XmlTextReader.Value,6,2));  //Month
      EVALUATE(intDay,COPYSTR(XmlTextReader.Value,9,2));    //Day
      datValueDate := DMY2DATE(intDay,intMonth,intYear);    //Value Date
    END;
 
    IF XmlTextReader.AttributeCount = 2 THEN BEGIN
      XmlTextReader.MoveToAttribute('currency');  // Currency
      codCurrency := XmlTextReader.Value;     
      XmlTextReader.MoveToAttribute('rate');   // Rate
      EVALUATE(decRate,CONVERTSTR(XmlTextReader.Value,'.',',')); 

      //  MESSAGE('%1 - %2',codCurrency,decRate); > TEST MESSAGE
           
      // INSERT\MODIFY New Fix Exchange Rate
      IF Currency.GET(codCurrency) THEN BEGIN
        CurrencyExchangeRate."Currency Code" := codCurrency;
        CurrencyExchangeRate."Starting Date" := WORKDATE;
        CurrencyExchangeRate."Exchange Rate Amount" :=  decRate;
        CurrencyExchangeRate."Relational Exch. Rate Amount" :=1;
        CurrencyExchangeRate."Fix Exchange Rate Amount" := CurrencyExchangeRate."Fix Exchange Rate Amount"::"Relational Currency";
        IF NOT CurrencyExchangeRate.INSERT THEN
           CurrencyExchangeRate.MODIFY;
      END;    
    END;  
  END;
END;

Based and rivisited on original Mibuso solution.


Viewing all articles
Browse latest Browse all 24464

Trending Articles


Vimeo Create - Video Maker & Editor 1.5.2 by Vimeo Inc


From Male to Female


Pokemon para colorear


Sapos para colorear


Inggit Quotes and Taray Quotes


“Sayo lang ako sigurado”


RE: Mutton Pies (frankie241)


Ka longiing longsem kaba skhem bad kaba khlain ka pynlong kein ia ka...


Vimeo 10.7.0 by Vimeo.com, Inc.


FORECLOSURE OF REAL ESTATE MORTGAGE


UPDATE SC IDOL: TWO BECOME ONE


KASAMBAHAY BILL IN THE HOUSE


Girasoles para colorear


OFW quotes : Pinoy Tagalog Quotes


BARKADA TAGALOG QUOTES


Re:Mutton Pies (lleechef)


Re: lwIP PIC32 port - new title : CycloneTCP a new open source stack for...


Hato lada ym dei namar ka jingpyrshah jong U JJM Nichols Roy (Bah Joy) ngin...


Vimeo 10.7.1 by Vimeo.com, Inc.


Vimeo 11.8.1 by Vimeo.com, Inc.