Exemplo n.º 1
0
        private void searchCountryTextBox_TextChanged(object sender, EventArgs e)
        {
            AVLCountry searchTree = new AVLCountry();
            string     userInput  = searchCountryTextBox.Text;
            var        source     = new AutoCompleteStringCollection();

            if (userInput == "")
            {
                //refresh comboBox
                countryComboBox.DataSource    = CountryAVLTree.GetAllCountries();
                countryComboBox.DisplayMember = "countryName";
                selectCountryLabel.Text       = "Select Country: " + CountryAVLTree.Count().ToString();
                //clear search results
                foreach (Country search in searchTree.GetAllCountries())
                {
                    searchTree.RemoveItem(search);
                }
            }
            else
            {
                //clear all user innput
                int countryCount = 0;
                currentCountry          = null;
                countryComboBox.Text    = "";
                selectCountryLabel.Text = "Select Country: 0";
                foreach (Country c in CountryAVLTree.GetAllCountries())
                {
                    if (c.CountryName.ToLower().StartsWith(userInput.ToLower().Trim()))
                    {
                        source.Add(c.CountryName);
                        countryCount++;
                        searchTree.InsertItem(c);
                    }
                }
                foreach (Country search in searchTree.GetAllCountries())
                {
                    if (!search.CountryName.ToLower().StartsWith(userInput.ToLower().Trim()))
                    {
                        source.Remove(search.CountryName);
                        countryCount--;
                        searchTree.RemoveItem(search);
                    }
                }
                countryComboBox.DataSource    = searchTree.GetAllCountries();
                countryComboBox.DisplayMember = "countryName";
                selectCountryLabel.Text       = "Select Country: " + countryCount;
                searchCountryTextBox.AutoCompleteCustomSource = source;
            }
        }
Exemplo n.º 2
0
        public AVLCountry fetchAllTradePartners(Country country)
        {
            AVLCountry tradePartners = new AVLCountry();

            foreach (string partnerName in country.TradePartners)
            {
                foreach (Country c in GetAllCountries())
                {
                    if (c.CountryName == partnerName)
                    {
                        tradePartners.InsertItem(c);
                    }
                }
            }
            return(tradePartners);
        }
Exemplo n.º 3
0
        private void openFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog()
            {
                Filter = "CSV Files|*.csv", ValidateNames = true
            })
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    string[]  headers        = new string[6]; //column headers
                    const int MAX_LINES_FILE = 50000;
                    string[]  AllLines       = new string[MAX_LINES_FILE];
                    AllLines = File.ReadAllLines(ofd.FileName); //name of file selected in dialog box
                    foreach (string line in AllLines)
                    {
                        if (line.StartsWith("Country")) //found first line - headers
                        {
                            headers = line.Split(',');
                        }
                        else
                        {
                            //split data using commas
                            string[]            columns = line.Split(',');
                            LinkedList <String> tradePartnersLinkedList = new LinkedList <string>();
                            string[]            partners = columns[5].Split(';', '[', ']');
                            foreach (string tradePartner in partners)
                            {
                                if (tradePartner != "")
                                {
                                    tradePartnersLinkedList.AddLast(tradePartner);
                                }
                            }
                            Country c = new Country(columns[0], Double.Parse(columns[1]), Double.Parse(columns[2]),
                                                    Double.Parse(columns[3]), int.Parse(columns[4]), tradePartnersLinkedList);

                            CountryAVLTree.InsertItem(c);
                            fetchMainForm();
                        }
                    }
                    MessageBox.Show("Operation Complete. Number of countries: " + CountryAVLTree.Count(), "Operation Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }