コード例 #1
0
        static void GetCountryExchangeRates_BackgroundEventHandler(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker backgroundWorker = sender as BackgroundWorker;

            try
            {
                List <ExchangeRate> exRates   = new List <ExchangeRate>();
                List <Country>      countries = CountryAdministrator.GetCountries();
                for (int i = 0; i < countries.Count; ++i)
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        e.Result = null; e.Cancel = true; return;
                    }

                    CountryConfigFacade ccf = countries[i].GetCountryConfigFacade(); if (ccf == null)
                    {
                        continue;
                    }
                    Dictionary <double, string> sysRates = new Dictionary <double, string>();
                    foreach (CountryConfig.SystemRow system in ccf.GetSystemRows())
                    {
                        if (system.IsExchangeRateEuroNull())
                        {
                            continue;                                  // rather unlikely
                        }
                        double rate; if (!double.TryParse(system.ExchangeRateEuro, out rate))
                        {
                            continue;                                                                   // also rather unlikely
                        }
                        if (sysRates.ContainsKey(rate))
                        {
                            sysRates[rate] = ExchangeRate.AddToValidFor(sysRates[rate], system.Name);
                        }
                        else
                        {
                            sysRates.Add(rate, system.Name.ToLower());
                        }
                    }
                    foreach (var sr in sysRates)
                    {
                        ExchangeRate exRatesCY = new ExchangeRate()
                        {
                            Country = countries[i]._shortName, June30 = sr.Key, ValidFor = sr.Value
                        };
                        exRates.Add(exRatesCY);
                    }
                    backgroundWorker.ReportProgress(Convert.ToInt32((i + 1.0) / (countries.Count * 1.0) * 100.0));
                }
                e.Result = exRates;
            }
            catch (Exception exception) { e.Result = exception.Message; backgroundWorker.ReportProgress(100); }
        }
コード例 #2
0
        private void menuItemAddSys_Click(object sender, EventArgs e = null)
        {
            string system; DataGridViewRow clickedRow; if (!menuItem_GetActionInfo(sender, out system, out clickedRow))

            {
                return;
            }

            try
            {
                string systems = clickedRow.Cells[colValidFor.Name].Value == null ? string.Empty : clickedRow.Cells[colValidFor.Name].Value.ToString();
                if (!dgvRates.SetCellValue(clickedRow, colValidFor.Name, ExchangeRate.AddToValidFor(systems, system)))
                {
                    ShowGridLastError();
                }
            }
            catch (Exception exception) { UserInfoHandler.ShowException(exception); }
        }