Exemple #1
0
        private void listBoxCountries_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                mediaPlayer.Close();
                comboBoxTranslatorInput.ItemsSource  = null;
                comboBoxTranslatorOutput.ItemsSource = null;
                comboBoxTranslatorOutput.Items.Clear();
                comboBoxConverterInput.ItemsSource  = null;
                comboBoxConverterOutput.ItemsSource = null;
                comboBoxConverterOutput.Items.Clear();
                if (txtBoxTranslatorInput.Text != "Insert the Text to Translate")
                {
                    txtBoxTranslatorInput.Text = "Insert the Text to Translate";
                }
                if (txtBoxTranslatorOutput.Text != "Translated Text")
                {
                    txtBoxTranslatorOutput.Text = "Translated Text";
                }
                comboBoxTranslatorInput.SelectedItem = "en - English";
                if (txtBoxConverterInput.Text != "Insert the Value to Convert")
                {
                    txtBoxConverterInput.Text = "Insert the Value to Convert";
                }
                if (txtBoxConverterOutput.Text != "Converted Value")
                {
                    txtBoxConverterOutput.Text = "Converted Value";
                }

                Country country = (Country)listBoxCountries.SelectedItem;

                if (country != null)
                {
                    if (country.Languages == null)
                    {
                        txtBoxTranslatorOutput.Text = "-- Translation Unavailable --";
                        txtBoxTranslatorInput.Text  = "-- Translation Unavailable --";
                    }

                    labelName.Content       = country.Name;
                    labelCapital.Content    = country.Capital;
                    labelRegion.Content     = country.Region;
                    labelSubRegion.Content  = country.SubRegion;
                    labelPopulation.Content = country.Population;
                    labelGini.Content       = country.Gini;

                    string fileNameFlags = Environment.CurrentDirectory + "/Flags" + $"/{country.Alpha3Code.ToLower()}.jpg";

                    BitmapImage img = new BitmapImage();
                    img.BeginInit();
                    if (File.Exists(fileNameFlags))
                    {
                        img.UriSource = new Uri(fileNameFlags);
                    }
                    else
                    {
                        img.UriSource      = new Uri(Environment.CurrentDirectory + "/ImageUnavailable.jpg");
                        imageFlag1.Stretch = Stretch.None;
                    }
                    img.EndInit();
                    imageFlag1.Source = img;

                    string fileNameMaps = Environment.CurrentDirectory + @"\Maps\" + $"{country.Alpha2Code.ToLower()}.gif";

                    BitmapImage img2 = new BitmapImage();
                    img2.BeginInit();
                    if (File.Exists(fileNameMaps))
                    {
                        img2.UriSource = new Uri(fileNameMaps);
                    }
                    else
                    {
                        img2.UriSource     = new Uri(Environment.CurrentDirectory + "/ImageUnavailable.jpg");
                        imageFlag1.Stretch = Stretch.None;
                    }
                    img2.EndInit();
                    imageMap.Source = img2;

                    List <string> LangDistinct = new List <string>();

                    if (country.Languages != null)
                    {
                        foreach (var ct in Countries)
                        {
                            foreach (var lg in ct.Languages)
                            {
                                if (!LangDistinct.Contains(lg.ToString()))
                                {
                                    LangDistinct.Add(lg.ToString());
                                }
                            }
                        }
                    }
                    comboBoxTranslatorInput.ItemsSource = LangDistinct;

                    if (country.Languages != null)
                    {
                        foreach (var lg in country.Languages)
                        {
                            comboBoxTranslatorOutput.Items.Add(lg.ToString());
                        }
                    }

                    comboBoxConverterInput.ItemsSource = Rates;

                    if (Rates != null)
                    {
                        foreach (var cr in country.Currencies)
                        {
                            foreach (var rate in Rates)
                            {
                                if (cr.code != null)
                                {
                                    if (cr.code.ToLower() == rate.Code.ToLower())
                                    {
                                        comboBoxConverterOutput.Items.Add(rate);
                                    }
                                }
                            }
                        }
                    }

                    if (comboBoxConverterOutput.Items.Count == 0)
                    {
                        comboBoxConverterOutput.Text = "Unable to Convert";
                    }

                    textBoxWiki.Text = dataService.LoadWikiText(country.Alpha2Code.ToLower());

                    LoadAudio(country.Alpha2Code.ToLower());
                }
            }
            catch (Exception ex)
            {
                dialogService.ShowMessage("An error occurred.\nPlease Update Info!", ex.Message);
            }
        }
        protected void gvCountries_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "AddNewCountry")
            {
                Control control = null;
                if (this.gvCountries.FooterRow != null)
                {
                    control = this.gvCountries.FooterRow;
                }
                else
                {
                    control = this.gvCountries.Controls[0].Controls[0];
                }

                try
                {
                    int continentId = Convert.ToInt32(this.lbContinents.SelectedValue);
                    string countryName = ((TextBox)control.FindControl("tbNewCountryName")).Text;
                    int countryPopulation = Convert.ToInt32(((TextBox)control.FindControl("tbNewCountryPopulation")).Text);
                    string countryLanguage = ((TextBox)control.FindControl("tbNewCountryLanguage")).Text;

                    Country newCountry = new Country
                    {
                        Name = countryName,
                        Population = countryPopulation,
                        Language = countryLanguage,
                        ContinentId = continentId
                    };

                    this.context.Countries.Add(newCountry);
                    this.context.SaveChanges();

                    ((TextBox)control.FindControl("tbNewCountryName")).Text = string.Empty;
                    ((TextBox)control.FindControl("tbNewCountryPopulation")).Text = string.Empty;
                    ((TextBox)control.FindControl("tbNewCountryLanguage")).Text = string.Empty;

                    this.successMessage.InnerText = "You successfully added country: " + countryName + "!";
                    this.successDiv.Visible = true;
                }
                catch (Exception ex)
                {
                    this.errorMessage.InnerText = ex.Message;
                    this.errorDiv.Visible = true;
                    return;
                }
            }
        }
Exemple #3
0
 public World(Country[] countries)
 {
     this.Countries = countries;
 }