Ejemplo n.º 1
0
        private async void listView_ItemClick(object sender, ItemClickEventArgs e)
        {
            selectedCurrencyFile  = (CurrencyFile)e.ClickedItem;
            listView.SelectedItem = selectedCurrencyFile;
            string date     = selectedCurrencyFile.GetFileDate();
            Uri    uri      = new Uri("http://api.nbp.pl/api/exchangerates/tables/a/" + date + "?format=xml");
            string response = await client.GetStringAsync(uri);

            XDocument document = XDocument.Load(new StringReader(response));
            var       query    =
                from rate in document.Root.Descendants("Rate")
                let code = rate.Element("Code")
                           let currency                     = rate.Element("Currency")
                                                    let mid = rate.Element("Mid")
                                                              select new Currency()
            {
                Code = code.Value, Name = currency.Value, Mid = mid.Value, Date = date
            };

            currencyRatings = new ObservableCollection <Currency>(query);
            listViewCurrency.ItemsSource = currencyRatings;

            //Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
            roamingSettings.Values["currencyRatings"]      = JsonConvert.SerializeObject(currencyRatings);
            roamingSettings.Values["selectedCurrencyFile"] = JsonConvert.SerializeObject(selectedCurrencyFile);
        }
Ejemplo n.º 2
0
        private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            // Restore values stored in session state.
            //if (e.PageState != null && e.PageState.ContainsKey("years")) {
            //    comboBox.DataContext = e.PageState["greetingOutputText"].ToString();
            //}

            //Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
            if (roamingSettings.Values.ContainsKey("years"))
            {
                years = (ObservableCollection <string>)JsonConvert.DeserializeObject(roamingSettings.Values["years"].ToString());
                comboBox.DataContext = years;
            }
            if (roamingSettings.Values.ContainsKey("selectedYear"))
            {
                selectedYear          = (string)JsonConvert.DeserializeObject(roamingSettings.Values["selectedYear"].ToString());
                comboBox.SelectedItem = selectedYear;
            }
            if (roamingSettings.Values.ContainsKey("currencyFiles"))
            {
                currencyFiles        = (ObservableCollection <CurrencyFile>)JsonConvert.DeserializeObject(roamingSettings.Values["currencyFiles"].ToString());
                listView.ItemsSource = currencyFiles;
            }
            if (roamingSettings.Values.ContainsKey("selectedCurrencyFile"))
            {
                selectedCurrencyFile  = (CurrencyFile)JsonConvert.DeserializeObject(roamingSettings.Values["selectedCurrencyFile"].ToString());
                listView.SelectedItem = selectedCurrencyFile;
            }
            if (roamingSettings.Values.ContainsKey("currencyRatings"))
            {
                currencyRatings       = (ObservableCollection <Currency>)JsonConvert.DeserializeObject(roamingSettings.Values["currencyRatings"].ToString());
                listView.SelectedItem = selectedCurrencyFile;
            }
            if (roamingSettings.Values.ContainsKey("selectedCurrencyRating"))
            {
                selectedCurrencyRating        = (Currency)JsonConvert.DeserializeObject(roamingSettings.Values["selectedCurrencyRating"].ToString());
                listViewCurrency.SelectedItem = selectedCurrencyRating;
            }
        }
Ejemplo n.º 3
0
        private async void button_Click(object sender, RoutedEventArgs e)
        {
            this.currencyFiles   = new ObservableCollection <CurrencyFile>();
            listView.ItemsSource = currencyFiles;

            string generalPath = "http://www.nbp.pl/kursy/xml/";
            string yearFilePath;
            string selectedYear = (string)comboBox.SelectedItem;

            if (selectedYear.Equals(System.DateTime.Now.Year.ToString()))
            {
                yearFilePath = "dir.txt";
            }
            else
            {
                yearFilePath = "dir" + selectedYear + ".txt";
            }

            Uri    uriObj = new Uri(generalPath + yearFilePath);
            string result = await client.GetStringAsync(uriObj);

            foreach (string currencyFileCode in result.Split('\n'))
            {
                if (!currencyFileCode.StartsWith("a"))
                {
                    continue;
                }
                else
                {
                    CurrencyFile code = new CurrencyFile(currencyFileCode);
                    currencyFiles.Add(code);
                }
            }
            //Windows.Storage.ApplicationDataContainer roamingSettings = Windows.Storage.ApplicationData.Current.RoamingSettings;
            roamingSettings.Values["currencyFiles"] = JsonConvert.SerializeObject(currencyFiles);
        }