//precondition: the address toolstrip menu item is clicked. //postcondition: the selected upv address object is updated private void AddressToolStripMenuItem1_Click(object sender, EventArgs e) { const int MINIMUM_ADDRESSES = 0; //the minimum addresses required to be able to edit //checks if there is at least one address //If yes, opens an EditAddress form. If no, shows a messagebox with error. if (upv.AddressCount > MINIMUM_ADDRESSES) { EditAddress editAddress = new EditAddress(upv.AddressList); // Send list of addresses and open EditAddress form DialogResult result = editAddress.ShowDialog(); //the dialog result of the EditAddress form int selectedIndex; //keeps track of selected indoex in the editaddress form. if (result == DialogResult.OK) // Only add if OK { selectedIndex = editAddress.AddressBoxIndex; //sets selectedIndex to the selected one in the EditAddress form. //Populates the address form textboxes with the selected address' data AddressForm addressForm = new AddressForm { AddressName = upv.AddressList[selectedIndex].Name, Address1 = upv.AddressList[selectedIndex].Address1, Address2 = upv.AddressList[selectedIndex].Address2, City = upv.AddressList[selectedIndex].City, State = upv.AddressList[selectedIndex].State, ZipText = upv.AddressList[selectedIndex].Zip.ToString() }; DialogResult editResult = addressForm.ShowDialog(); //sets editResult depending on what was clicked //checks if the result was ok. //If so, tries to update the upv address with the new information if (editResult == DialogResult.OK) { //tries to parse the zipcode. If successful, updates the upv address. if (int.TryParse(addressForm.ZipText, out int zip)) { upv.AddressList[selectedIndex].Name = addressForm.AddressName; upv.AddressList[selectedIndex].Address1 = addressForm.Address1; upv.AddressList[selectedIndex].Address2 = addressForm.Address2; upv.AddressList[selectedIndex].City = addressForm.City; upv.AddressList[selectedIndex].State = addressForm.State; upv.AddressList[selectedIndex].Zip = zip; } else // If there was an error { MessageBox.Show("Problem with Address Validation!", "Validation Error"); } } addressForm.Dispose(); //disposes the form } editAddress.Dispose(); // Disposes the form } else { //shows if there is nothing to edit MessageBox.Show("No addresses to edit!", "Addresses Error"); this.DialogResult = DialogResult.Abort; // Dismiss immediately } }
private void editAddressesToolStripMenuItem_Click(object sender, EventArgs e) { List <Address> add = upv.addresses; //address list set to addresses in upv if (add.Count() == 0) //addresses must be loaded { MessageBox.Show("No Addresses Loaded"); } else { EditAddress ea = new EditAddress(add); //passes add to new EditAddress form DialogResult result = ea.ShowDialog(); //show and store dialog result if (result == DialogResult.OK) //is result ok? { if (ea.CmbBxIndex() != -1) //must select from combo box { Address eadd = add[ea.CmbBxIndex()]; //combo box index is used to identify address being edited AddressForm af = new AddressForm(); //new AddressForm to edit address identified above //each property from identified address is passed to new AddressForm af.AddressName = eadd.Name; af.Address1 = eadd.Address1; af.Address2 = eadd.Address2; af.City = eadd.City; af.State = eadd.State; af.ZipText = eadd.Zip.ToString(); DialogResult eres = af.ShowDialog(); //show and store dialog result if (eres == DialogResult.OK) //is result ok? { //user input replaces properties from identified address eadd.Name = af.AddressName; eadd.Address1 = af.Address1; eadd.Address2 = af.Address2; eadd.City = af.City; eadd.State = af.State; eadd.Zip = int.Parse(af.ZipText); } } } } }
private void addressToolStripMenuItem1_Click(object sender, EventArgs e) { DialogResult result; //Hold dialog result of the edit form. EditAddress editForm = new EditAddress(upv.AddressList); // The address dialog box form result = editForm.ShowDialog(); //show the edit form. if (result == DialogResult.OK) { int newZip; //temporary variable to hold the edited zip from the address form int.TryParse(editForm.addressForm.ZipText, out newZip); //Tries to parse the ziptext, does nothing if fails. upv.AddressList[editForm.SelectedIndex].Name = editForm.addressForm.AddressName; //set these to the selected address object from the upv list, get data from the editForm upv.AddressList[editForm.SelectedIndex].Address1 = editForm.addressForm.Address1; upv.AddressList[editForm.SelectedIndex].Address2 = editForm.addressForm.Address2; upv.AddressList[editForm.SelectedIndex].City = editForm.addressForm.City; upv.AddressList[editForm.SelectedIndex].State = editForm.addressForm.State; upv.AddressList[editForm.SelectedIndex].Zip = newZip; } }
// Precondition: Edit, Address menu item activated // Postcondition: Dialog to seect address is shown, if user selects address // and clicks OK address dialog is shown to edit address info private void addressToolStripMenuItem1_Click(object sender, EventArgs e) { EditAddress editAddress = new EditAddress(upv.addresses); //edit addrss form passes addresses DialogResult result = editAddress.ShowDialog(); //stores the result of the editaddress dialog if (result == DialogResult.OK) //if the user clicks ok { Address address = upv.AddressAt(editAddress.AddressIndex); //stores the address the user selected to be edited AddressForm addressForm = new AddressForm(); //new instance of the address form //Populate the address text boxes with the info to be edited addressForm.AddressName = address.Name; addressForm.Address1 = address.Address1; addressForm.Address2 = address.Address2; addressForm.City = address.City; addressForm.State = address.State; addressForm.ZipText = address.Zip.ToString(); DialogResult editresult = addressForm.ShowDialog(); //stores the result of the address dialog if (editresult == DialogResult.OK) //if user clicked ok { //reassigns the addresses properties to the contents of the address forms fields address.Name = addressForm.AddressName; address.Address1 = addressForm.Address1; address.Address2 = addressForm.Address2; address.City = addressForm.City; address.State = addressForm.State; address.Zip = int.Parse(addressForm.ZipText); } addressForm.Dispose(); //dispose of the address form } editAddress.Dispose(); //dispose of the edit address form }
// Precondition: upv item activated // Postcondition: The selected address info is replaced with modified info. private void addressToolStripMenuItem1_Click(object sender, EventArgs e) { DialogResult result1 = new DialogResult(); // The result of showing form as dialog DialogResult result2 = new DialogResult(); // The result of showing form as dialog EditAddress editForm = new EditAddress(upv.AddressList); // The edit address dialog box form AddressForm editAdd = new AddressForm(); // the address dialog box form result1 = editForm.ShowDialog(); if (result1 == DialogResult.OK) // Only add if OK { //loads information from address selected into form Address address = upv.AddressAt(editForm.SelectedIndex); editAdd.AddressName = address.Name; editAdd.Address1 = address.Address1; editAdd.Address2 = address.Address2; editAdd.City = address.City; editAdd.State = address.State; editAdd.ZipText = (address.Zip).ToString(); result2 = editAdd.ShowDialog(); if (result2 == DialogResult.OK) // Only change if OK { //replaces infomation in upv with those entered into form address.Name = editAdd.AddressName; address.Address1 = editAdd.Address1; address.Address2 = editAdd.Address2; address.City = editAdd.City; address.State = editAdd.State; address.Zip = int.Parse(editAdd.ZipText); reportTxt.Clear(); // clears info in report text box } } }