0

I got a school project. I have to make a currency converter and I got stuck. I found something on the Code Project web site, but I am new at this and I do not really know how to implement it in my project.

I tried something like `

public sealed partial class MainPage : Page
{
    public MainPage()
    {

        this.InitializeComponent();

        this.NavigationCacheMode = NavigationCacheMode.Required;

    }


    protected override void OnNavigatedTo(NavigationEventArgs e)
    {


    }
    class WebClient
    {
        internal string DownloadString(string url)
        {

            throw new NotImplementedException();

            url = "https://openexchangerates.org/api/latest.json?app_id=ae11142304694b10a1dbf2d25933a333";
            var currencyRates = _download_serialized_json_data<App9.CurrencyRates>(url);
        }
    }
    public static T _download_serialized_json_data<T>(string url) where T : new()
    {
        var w = new WebClient();
        {
            //using (var w = new WebClient()) {
            var json_data = string.Empty;
            // attempt to download JSON data as a string
            try
            {
                json_data = w.DownloadString(url);
            }
            catch (Exception) { }
            // if string with JSON data is not empty, deserialize it to class and return its instance 
            return !string.IsNullOrEmpty(json_data) ? JsonConvert.DeserializeObject<T>(json_data) : new T();
        }
    }

    private void comboBoxTo_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {

    }

    private void convertButton_Click(object sender, RoutedEventArgs e)
    {
        if (amountTb.Text == string.Empty)
        {
            afisareTb.Text = "Scrieti o valoare";
        }
        else
        {

            var currencyRates = _download_serialized_json_data<CurrencyRates>("https://openexchangerates.org/api/latest.json?app_id=YOUR_APP_ID "); 
        }

    }
}

`

I do not have any errors, it is just that, when I press on converter button from my app, nothing happens.

Andrei Paul
  • 83
  • 1
  • 1
  • 9
  • Please try to create a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) example of a method or application (preferably a console or test method) that reproduces the problem, then include that in your question. As it is, you're asking us to try to re-derive your bug to tell you where you where you went wrong. – dbc May 14 '15 at 17:06
  • I got the designer,which does not matter how it looks like. Then i got the CurrencyRates.cs and in my MainPage.xaml.cs it's the code from pastebin. The real problem is that i do not know if "public static T _download_serialized_json_data(string url) where T : new()" is connecting to openexchangerates.org, from where i got the api key and bring the data i need to my app so when i press the button convert do to the conversion from the currency i selected to another one. I do not really know if my action in the button is very good written.As i said i am new and i can not figure a way out. – Andrei Paul May 14 '15 at 17:20
  • 1
    Try to extract your actual code out of the GUI into a separate class, including a method like `Convert(decimal value, string from, string to)`, that shows what you have done so far and indicates the problem you are having. Then please [edit your question](http://stackoverflow.com/help/editing) to show your code. You're much more likely to get help if we don't have to chase things down on separate sites. – dbc May 14 '15 at 17:25

0 Answers0