// Constructor // Reads the csv file and populates a Tree for the application to use // Also sets placeholders for the search and add trade partner textboxes // Populates the listview with country names public TradingDataForm() { csvRead.readCsvIn(); csvRead.FileContent.ForEach(item => CTree.InsertItem(item)); InitializeComponent(); SearchTB.Text = "Search countries..."; AddTradePartnerTB.Text = "Add Trade Partner..."; populateListView(""); }
public void init() { LinkedList <string> partners = null; CT = new CountryTree(); for (int i = 0; i < 15; i++) { Country country = new Country("demoCountry" + i, 0, 0, 0, 0, partners); CT.InsertItem(country); } }
//<<ADDED ERROR HANDLING (TRY/CATCH) FOR SUMMATIVE>> public static bool ParseCountriesIntoTree(string filePath, ref CountryTree tree) { try { String[] lines = new string[LINE_MAX]; lines = File.ReadAllLines(filePath); foreach (string line in lines) { if (line.StartsWith(COUNTRY)) //ignore header { if (line.Split(',').Length != 6) { return false; } } else { LinkedList<string> partnerNames = new LinkedList<string>(); string[] columns = line.Split(','); string[] partners = columns[PARTNERS_INDEX].Split(';', '[', ']'); foreach (string p in partners) { if (p.Length > 1) { partnerNames.AddLast(p); } } tree.InsertItem(new Country(columns[NAME_INDEX], Double.Parse(columns[GDP_INDEX]), Double.Parse(columns[INFLATION_INDEX]), Double.Parse(columns[TRADE_INDEX]), int.Parse(columns[HDI_INDEX]), partnerNames)); } } return true; } catch (Exception e) { Console.WriteLine(e.StackTrace); return false; } }