//Precondition: Edit, Address menu item activated. //Postcondition: A dialog box to choose an address to edit appears. Then an address form //with the chosen adress information appears. private void addressToolStripMenuItem1_Click(object sender, EventArgs e) { List <Address> Addresses; Addresses = upv.AddressList; if ((Addresses.Count() == 0)) { MessageBox.Show("Must have address to edit", "Edit Error"); } else { SelectAddressForm saForm = new SelectAddressForm(upv.AddressList); DialogResult result = saForm.ShowDialog(); if (result == DialogResult.OK) { int editIndex; editIndex = saForm.EditAddressIndex; if (editIndex >= 0) { Address editAddress = Addresses[editIndex]; AddressForm addressForm = new AddressForm(); addressForm.AddressName = editAddress.Name; addressForm.Address1 = editAddress.Address1; addressForm.Address2 = editAddress.Address2; addressForm.City = editAddress.City; addressForm.State = editAddress.State; addressForm.ZipText = editAddress.Zip.ToString(); DialogResult editResult = addressForm.ShowDialog(); if (editResult == DialogResult.OK) { editAddress.Name = addressForm.AddressName; editAddress.Address1 = addressForm.Address1; editAddress.Address2 = addressForm.Address2; editAddress.City = addressForm.City; editAddress.State = addressForm.State; editAddress.Zip = int.Parse(addressForm.ZipText); } addressForm.Dispose(); } } saForm.Dispose(); } }
// Precondition: Edit menu item is activated // Postcondition: The address form is displayed. Data from the address list can be edited. private void editToolStripMenuItem_Click(object sender, EventArgs e) { SelectAddressForm selectAddressForm = new SelectAddressForm(upv.AddressList); // The select address dialog box form DialogResult result1 = selectAddressForm.ShowDialog(); // Show form as dialog and store result int addressIndex; //holds the value of the combo box index selected if (result1 == DialogResult.OK) // Only add if OK { addressIndex = selectAddressForm.AddressIndex; AddressForm af = new AddressForm(); //address form dialog box form DialogResult result2 = af.ShowDialog(); // shows form as dialog and store result } selectAddressForm.Dispose(); // Best practice for dialog boxes // Alternatively, use with using clause as in Ch. 17 }