private void btnLoadPersist_Click(object sender, System.EventArgs e) { FileStream fs = null; try { PersistedCountry pc = new PersistedCountry(string.Empty, 0); fs = File.Open(Application.StartupPath + COUNTRY_FILE, FileMode.Open); pc.Load(fs); this.mCountry = new ImprovedCountry(pc.Name, pc.Population); this.txtName.Text = this.mCountry.Name; this.txtPopulation.Text = this.mCountry.Population.ToString(); } finally { fs.Close(); } }
private void btnUpdate_Click(object sender, System.EventArgs e) { try { if (this.mCountry == null) { this.mCountry = new ImprovedCountry(this.txtName.Text, Int32.Parse(this.txtPopulation.Text)); } else { this.mCountry.Population = Int32.Parse(this.txtPopulation.Text); this.mCountry.Name = this.txtName.Text; } this.ShowCountry(); } catch (FormatException ex) { } }