Ejemplo n.º 1
0
        public static void addTradePartner(AVLTree <Country> Countries, ComboBox cbAddTradePartner, ListBox listBoxCountries)
        {
            Country country       = Countries.GetItem(new Country((String)listBoxCountries.SelectedItem));
            String  countryAdding = (string)cbAddTradePartner.SelectedItem;

            Countries.updateItem(country.CountryName, addTradePartner(country, countryAdding));
            Countries.updateItem(countryAdding, addTradePartner(Countries.GetItem(new Country(countryAdding)), country.CountryName));
        }
Ejemplo n.º 2
0
        // Part 2
        public static void updateCountry(ref AVLTree <Country> Countries, string updating, ListBox listBoxCountries, TextBox txtName, TextBox txtGpdGrowth, TextBox txtInflation, TextBox txtTradeBalance, TextBox txtHdiRanking)
        {
            Country county  = Countries.GetItem(new Country((String)listBoxCountries.SelectedItem));
            string  oldName = county.CountryName;

            switch (updating)
            {
            case "Name": county.CountryName = txtName.Text; break;

            case "GPD": county.GpdGrowth = float.Parse(txtGpdGrowth.Text); break;

            case "Inflation": county.Inflation = float.Parse(txtInflation.Text); break;

            case "TradeBalance": county.TradeBalance = float.Parse(txtTradeBalance.Text); break;

            case "HdiRanking": county.HdiRanking = int.Parse(txtHdiRanking.Text); break;
            }
            Countries.updateItem(oldName, county);

            // Updates countries that previously traded with the changed countries old name, to its new name
            if ("Name".Equals(updating))
            {
                string[] countryText = Program.getCountries(Countries);
                foreach (string s in countryText)
                {
                    Boolean changed = false;
                    Country temp    = Countries.GetItem(new Country(s));
                    for (int i = 0; i < temp.MainTradePartners.Length; i++)
                    {
                        if (oldName.Equals(temp.MainTradePartners[i]))
                        {
                            temp.MainTradePartners[i] = txtName.Text;
                            changed = true;
                        }
                    }
                    if (changed)
                    {
                        Countries.updateItem(temp.CountryName, temp);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 // Part 4
 public static void deleteCountry(ref AVLTree <Country> Countries, ListBox listBoxCountries, Label lblInfo, TextBox txtSearch, CheckBox checkBoxTradingPartner)
 {
     if (listBoxCountries.SelectedIndex != -1)
     {
         String country = (String)listBoxCountries.SelectedItem;
         // simply removing the country from the AVL Tree
         Countries.RemoveItem(country);
         // removing all instances from other countries that traded with the removed country
         string[] countryNames = getCountries(Countries);
         foreach (string c in countryNames)
         {
             Countries.updateItem(c, removedCountryPartner(Countries.GetItem(new Country(c)), country));
         }
         // updates fields
         setAvlData(lblInfo, Countries);
         txtSearch.Text = "";
         showCountries(txtSearch.Text, listBoxCountries, Countries, checkBoxTradingPartner);
     }
 }