/// <summary> /// Initialize edit form with country data /// </summary> /// <param name="c">The Country to be edited</param> public editForm(Country c) { InitializeComponent(); countrytb.Text = c.Name; gdptb.Text = c.GDP; inflationtb.Text = c.Inflation; tradeBaltb.Text = c.TradeBalance; hditb.Text = c.HDI; tradePartlv.HeaderStyle = ColumnHeaderStyle.None; foreach (String s in c.TradePartners) { tradePartlv.Items.Add(s); } }
/// <summary> /// Checks to see if all changes are acceptable, creates new country item with the new data /// </summary> private void saveButt_Click(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(countrytb.Text) && !string.IsNullOrWhiteSpace(gdptb.Text) && !string.IsNullOrWhiteSpace(inflationtb.Text) && !string.IsNullOrWhiteSpace(tradeBaltb.Text) && !string.IsNullOrWhiteSpace(hditb.Text)) { LinkedList<string> newTradePart = new LinkedList<string>(); foreach (ListViewItem lvi in tradePartlv.Items) { if (!string.IsNullOrWhiteSpace(lvi.SubItems[0].Text)) { newTradePart.AddLast(lvi.SubItems[0].Text); } } newCountry = new Country(countrytb.Text, gdptb.Text, inflationtb.Text, tradeBaltb.Text, hditb.Text, newTradePart); this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show("Some fields still require an entry", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
/// <summary> /// Load button click /// Reads csv file and creates country objects to be added to the tree /// </summary> private void button3_Click(object sender, EventArgs e) { const int MAX_LINES_FILE = 50000; string[] AllLines = new string[MAX_LINES_FILE]; tree = new AVLTree<Country>(); OpenFileDialog openFile = new OpenFileDialog(); openFile.Filter = "csv files (*.csv)|*.csv"; if (openFile.ShowDialog() == DialogResult.OK) { try { AllLines = File.ReadAllLines(openFile.FileName); foreach (string line in AllLines) { if (line.StartsWith("Country")) { headers = line.Split(','); } else { string[] columns = line.Split(','); string[] partners = columns[5].Split(';', '[', ']'); LinkedList<String> tPartners = new LinkedList<string>(); for (int i = 1; i < partners.Length - 1; i++) { tPartners.AddLast(partners[i]); } //Creates a new country object and adds to tree Country country = new Country(columns[0], columns[1], columns[2], columns[3], columns[4], tPartners); tree.InsertItem(country); } } populateListView(false); treeDepth(); } catch (Exception ex) { MessageBox.Show("Error: " + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }