Exemplo n.º 1
0
 private void ConvertOnline()
 {
     if (Helpers.CheckTextBox(textBox1.Text))
     {
         textBox2.Text = "";
         if (comboBox1.Text == comboBox2.Text)
         {
             textBox2.AppendText(textBox1.Text);
         }
         else
         {
             if (Helpers.GetShortName(comboBox1.Text) == "PLN")
             {
                 double a = (1 / currentExchangeRates.GetCourse(Helpers.GetShortName(comboBox2.Text))) * Convert.ToDouble(textBox1.Text);
                 textBox2.AppendText((Math.Round(a, 2)).ToString());
             }
             if (Helpers.GetShortName(comboBox2.Text) == "PLN")
             {
                 double a = ((currentExchangeRates.GetCourse(Helpers.GetShortName(comboBox1.Text))) * (Convert.ToDouble(textBox1.Text)));
                 textBox2.AppendText((Math.Round(a, 2)).ToString());
             }
             if (Helpers.GetShortName(comboBox2.Text) != "PLN" && Helpers.GetShortName(comboBox1.Text) != "PLN")
             {
                 double a = (currentExchangeRates.GetCourse(Helpers.GetShortName(comboBox1.Text))) * (currentExchangeRates.GetCourse(Helpers.GetShortName(comboBox2.Text)));
                 textBox2.AppendText((Math.Round(a, 2)).ToString());
             }
         }
     }
     else
     {
         textBox1.Clear();
         textBox2.Clear();
         MessageBox.Show("Nie poprawny format ciągu wejściowego. Przykładowe formaty: 100 | 12,23 | 1245,54", "Błąd", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
Exemplo n.º 2
0
 private void CompletAll()
 {
     if (Helpers.CheckConnectInternet())
     {
         currentExchangeRates  = new CurrentExchangeRates(true);
         labeCourseUsd.Content = "USD = " + Math.Round(currentExchangeRates.GetCourse("USD"), 2) + "zł";
         labeCourseEur.Content = "EUR = " + Math.Round(currentExchangeRates.GetCourse("EUR"), 2) + "zł";
         labeCourseGbp.Content = "GBP = " + Math.Round(currentExchangeRates.GetCourse("GBP"), 2) + "zł";
         labeCourseChf.Content = "CHF = " + Math.Round(currentExchangeRates.GetCourse("CHF"), 2) + "zł";
         Helpers.FillComboBox(currentExchangeRates, ref comboBox1, true);
         Helpers.FillComboBox(currentExchangeRates, ref comboBox2, true);
         comboBox1.SelectedIndex     = 0;
         comboBox2.SelectedIndex     = 1;
         OfflineDataCurrency.Content = "";
         control.Fill = Brushes.Green;
         ReadAndWriteJson.WriteJson();
         OfflineMode = false;
     }
     else
     {
         currentExchangeRates  = new CurrentExchangeRates(false);
         labeCourseUsd.Content = "USD = " + Math.Round(currentExchangeRates.GetCourse("USD"), 2) + "zł";
         labeCourseEur.Content = "EUR = " + Math.Round(currentExchangeRates.GetCourse("EUR"), 2) + "zł";
         labeCourseGbp.Content = "GBP = " + Math.Round(currentExchangeRates.GetCourse("GBP"), 2) + "zł";
         labeCourseChf.Content = "CHF = " + Math.Round(currentExchangeRates.GetCourse("CHF"), 2) + "zł";
         Helpers.FillComboBox(currentExchangeRates, ref comboBox1, true);
         Helpers.FillComboBox(currentExchangeRates, ref comboBox2, true);
         comboBox1.SelectedIndex     = 0;
         comboBox2.SelectedIndex     = 1;
         OfflineDataCurrency.Content = "Kursy walut z dnia: " + currentExchangeRates.Data;
         control.Fill = Brushes.Red;
         OfflineMode  = true;
     }
 }