// Precondition: Edit, User selects Address item to edit // Postcondition: After user selects Address object, dialog is displayed to edit address information private void addressToolStripMenuItem1_Click(object sender, EventArgs e) { SelectAddress selectAddress = new SelectAddress(upv.AddressList); // The Select Address dialog box form DialogResult result = selectAddress.ShowDialog(); // Show form as dialog and store result if (result == DialogResult.OK) // If user clicks Select Address button - Open Address Form dialog { int editIndex = selectAddress.EditAddressIndex; // Index of selected Address in List Address editAddress = upv.AddressAt(editIndex); // Holds the Address object being updated AddressForm addressForm = new AddressForm(); // The address dialog box form // Assigns Address object attributes to form attributes 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 editingAddress = addressForm.ShowDialog(); // Show form as dialog and store result // If user accepts, attributes are updated if (editingAddress == 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); } } }
//event handler for address button click //precondition: Edit address button clicked //postconditions: interface to edit address shown private void addressToolStripMenuItem1_Click(object sender, EventArgs e) { SelectAddress selection = new SelectAddress(upv.AddressList); selection.ShowDialog(); if (selection.DialogResult == DialogResult.OK) { int index = selection.AddressIndex; //variable to store selected address Address selected = upv.AddressAt(index); AddressForm editForm = new AddressForm(); editForm.AddressName = selected.Name; editForm.Address1 = selected.Address1; if (!string.IsNullOrWhiteSpace(selected.Address2)) { editForm.Address2 = selected.Address2; } editForm.City = selected.City; editForm.State = selected.State; editForm.ZipText = selected.Zip.ToString("d5"); //show edit form editForm.ShowDialog(); if (editForm.DialogResult == DialogResult.OK) { selected.Name = editForm.AddressName; selected.Address1 = editForm.Address1; if (!string.IsNullOrWhiteSpace(editForm.Address2)) { selected.Address2 = editForm.Address2; } else { selected.Address2 = ""; } selected.City = editForm.City; selected.State = editForm.State; selected.Zip = int.Parse(editForm.ZipText); //no zip validation since already performed upv.addresses[index] = selected; } } }