Exemplo 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));
        }
Exemplo n.º 2
0
 private void listBoxTradingPartners_KeyUp(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Delete)
     {
         // Storing needed country values
         Country mainCountry        = Countries.GetItem(new Country((String)listBoxCountries.SelectedItem));
         String  tradingCountryName = (String)listBoxTradingPartners.SelectedItem;
         Country tradingCountry     = Countries.GetItem(new Country(tradingCountryName));
         // Removing trading for both countries
         mainCountry.MainTradePartners    = Program.removedCountryPartner(mainCountry.MainTradePartners, tradingCountryName);
         tradingCountry.MainTradePartners = Program.removedCountryPartner(tradingCountry.MainTradePartners, mainCountry.CountryName);
         // Update Trading Partner Listview
         Program.updateTradePartnersList(mainCountry, listBoxTradingPartners);
         e.Handled = true;
     }
 }
Exemplo n.º 3
0
 public static void showCountries(string search, ListBox listBoxCountries, AVLTree <Country> Countries, CheckBox checkBox) // checkBoxTradingPartner
 {
     string[] CountriesText = getCountries(Countries);
     listBoxCountries.Items.Clear();
     if (checkBox.Checked)   //Part 6 & 7
     {
         foreach (string s in CountriesText)
         {
             if (Contains(Countries.GetItem(new Country(s)).MainTradePartners, search))
             {
                 listBoxCountries.Items.Add(s);
             }
         }
     }
     else
     {
         foreach (string s in CountriesText)
         {
             if (s.ToLower().Contains(search.ToLower()))
             {
                 listBoxCountries.Items.Add(s);
             }
         }
     }
 }
Exemplo n.º 4
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);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public static void updateCountryTextBoxes(ref AVLTree <Country> Countries, ListBox listBoxCountries, TextBox txtName, TextBox txtGpdGrowth, TextBox txtInflation, TextBox txtTradeBalance, TextBox txtHdiRanking, ListBox listBoxTradingPartners, ComboBox addTradePartner)
        {
            Country c = Countries.GetItem(new Country((String)listBoxCountries.SelectedItem));

            txtName.Text         = c.CountryName;
            txtGpdGrowth.Text    = c.GpdGrowth.ToString();
            txtInflation.Text    = c.Inflation.ToString();
            txtTradeBalance.Text = c.TradeBalance.ToString();
            txtHdiRanking.Text   = c.HdiRanking.ToString();
            listBoxTradingPartners.Items.Clear();
            foreach (string s in c.MainTradePartners)
            {
                listBoxTradingPartners.Items.Add(s);
            }
            updateAddTradePartners(Countries, addTradePartner, listBoxCountries);
        }
Exemplo n.º 6
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);
     }
 }
Exemplo n.º 7
0
 public static void updateAddTradePartners(AVLTree <Country> Countries, ComboBox addTradePartner, ListBox listBoxCountries)
 {
     if ((String)listBoxCountries.SelectedItem != "")
     {
         Country  county       = Countries.GetItem(new Country((String)listBoxCountries.SelectedItem));
         String[] countryTexts = getCountries(Countries);
         addTradePartner.Items.Clear();
         addTradePartner.SelectedItem  = "";
         addTradePartner.SelectedIndex = -1;
         addTradePartner.SelectedText  = "";
         addTradePartner.SelectedValue = "";
         foreach (string c in countryTexts)
         {
             if (!county.MainTradePartners.Contains(c) && !c.Equals(county.CountryName))
             {
                 addTradePartner.Items.Add(c);
             }
         }
     }
 }
Exemplo n.º 8
0
        // Part 8
        public static void setBiggestTradingPartner(ref AVLTree <Country> Countries, TextBox txtNameTrade, TextBox txtGpdTrade, TextBox txtGpdTradeSum, TextBox txtInflationTrade, TextBox txtTradeBalanceTrade, TextBox txtHdiTrade, ListBox listBoxTrade)
        {
            string[] CountriesText = getCountries(Countries);

            string countryWithBiggestTradePotential    = "";
            float  countryWithBiggestTradePotentialGPD = 0;

            foreach (string s in CountriesText)
            {
                Country x     = Countries.GetItem(new Country(s));
                float   total = 0;
                foreach (string countr in x.MainTradePartners)
                {
                    if (Countries.GetItem(new Country(countr)) != null)
                    {
                        total += Countries.GetItem(new Country(countr)).GpdGrowth;
                    }
                }
                if (total > countryWithBiggestTradePotentialGPD)
                {
                    countryWithBiggestTradePotentialGPD = total;
                    countryWithBiggestTradePotential    = x.CountryName;
                }
            }

            Country c = Countries.GetItem(new Country(countryWithBiggestTradePotential));

            txtNameTrade.Text = c.CountryName;
            txtGpdTrade.Text  = c.GpdGrowth.ToString();
            float gpdTemp = 0;

            foreach (string countr in c.MainTradePartners)
            {
                if (Countries.GetItem(new Country(countr)) != null)
                {
                    gpdTemp += Countries.GetItem(new Country(countr)).GpdGrowth;
                }
            }
            txtGpdTradeSum.Text       = gpdTemp.ToString();
            txtInflationTrade.Text    = c.Inflation.ToString();
            txtTradeBalanceTrade.Text = c.TradeBalance.ToString();
            txtHdiTrade.Text          = c.HdiRanking.ToString();
            listBoxTrade.Items.Clear();
            foreach (string s in c.MainTradePartners)
            {
                listBoxTrade.Items.Add(s);
            }
        }