コード例 #1
0
ファイル: Form1.cs プロジェクト: homyakoid/CurrencyConverter
 // method checks the ComboBoxCurrencies to return the correctly set currency ID
 private void CheckComboBoxCurrencies(out string currency)
 {
     if (comboBoxCurrencies.Text == "All")
     {
         currency = null;
         return;
     }
     else
     {
         bool exists = false;
         ServiceReference1.ObjectsList currencyIDs = new ServiceReference1.ObjectsList();
         currencyIDs = client.GetCurrencyCodes();
         foreach (var id in currencyIDs.Objects)
         {
             if (comboBoxCurrencies.Text == id)
             {
                 exists = true;
                 break;
             }
         }
         if (exists)
         {
             currency = comboBoxCurrencies.Text;
             return;
         }
         else
             throw new KeyNotFoundException("There is no such currency code listed!");
     }
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: homyakoid/CurrencyConverter
        // method that is called when the form load event is initiated
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                ServiceReference1.ObjectsList ObjectsList = new ServiceReference1.ObjectsList();
                // get all currencies IDs
                ObjectsList = client.GetCurrencyCodes();
                // get the last listed date
                string lastDateStr = client.GetLastDate();
                DateTime lastDate = DateTime.Parse(lastDateStr);
                // set the last listed date for both start and end date
                dateTimePicker2.Value = lastDate;
                dateTimePicker3.Value = lastDate;
                // fill the combobox with all currencies IDs + "All" for all currencies IDs to be involved
                comboBoxCurrencies.Items.Add("All");
                foreach (string id in ObjectsList.Objects)
                {
                    comboBoxSource.Items.Add(id);
                    if (id != comboBoxSource.Items[0].ToString())
                        comboBoxTarget.Items.Add(id);
                    comboBoxCurrencies.Items.Add(id);
                }
                comboBoxSource.Text = comboBoxSource.Items[0].ToString();
                comboBoxTarget.Text = comboBoxTarget.Items[0].ToString();
                comboBoxCurrencies.Text = "All";
                // fill dates list with all dates for chosen period
                ShowRates();
                formIsLoaded = true;
            }
            catch (EndpointNotFoundException ex)
            {
                MessageBox.Show(ex.Message);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: homyakoid/CurrencyConverter
 // method checks if specified date is listed
 private bool IfDateListed(string date)
 {
     ServiceReference1.ObjectsList dates = new ServiceReference1.ObjectsList();
     dates = client.GetDates();
     foreach (var d in dates.Objects)
     {
         if (d == date)
         {
             return true;
         }
     }
     return false;
 }
コード例 #4
0
ファイル: Form1.cs プロジェクト: homyakoid/CurrencyConverter
 // method that is called when the data in comboBoxSource is changed
 private void comboBoxSource_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         ServiceReference1.ObjectsList ObjectsList = new ServiceReference1.ObjectsList();
         // get all currencies IDs
         ObjectsList = client.GetCurrencyCodes();
         comboBoxTarget.Items.Clear();
         // fill in comboBoxTarget with currencies IDs, except ID chosen in comboBoxSource to avoid the possibility
         // to choose the same currency ID so the conversion will have no sense
         foreach (string id in ObjectsList.Objects)
         {
             if (id != comboBoxSource.SelectedItem.ToString())
                 comboBoxTarget.Items.Add(id);
         }
         comboBoxTarget.Text = comboBoxTarget.Items[0].ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }