private void addressToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (upv.AddressList.Count > 1)
            {
                //This will show the Dialog Box form to edit a address
                NewAddressForm pickAddressForm = new NewAddressForm(upv.AddressList);
                //The results will be shown with a dialog box
                DialogResult result = pickAddressForm.ShowDialog();

                if (DialogResult.OK == result)
                {
                    //This is the index of the address that we have chosen to edit
                    int editTheAddressIndex;
                    editTheAddressIndex = pickAddressForm.ChosenAddress;

                    if (editTheAddressIndex >= 1)
                    {
                        Address     addressBeingEdited = upv.AddressAt(editTheAddressIndex);
                        AddressForm theNewAddressForm  = new AddressForm();

                        //The form for the addressses has been populated here
                        theNewAddressForm.AddressName = addressBeingEdited.Name;
                        theNewAddressForm.Address1    = addressBeingEdited.Address1;
                        theNewAddressForm.Address2    = addressBeingEdited.Address2;
                        theNewAddressForm.ZipText     = $"{ addressBeingEdited.Zip}";
                        theNewAddressForm.State       = addressBeingEdited.State;
                        theNewAddressForm.City        = addressBeingEdited.Name;

                        //Showing the Dialog Results from the previous information
                        result = theNewAddressForm.ShowDialog();

                        if (DialogResult.OK == result)
                        {
                            addressBeingEdited.Name     = theNewAddressForm.AddressName;
                            addressBeingEdited.Address1 = theNewAddressForm.Address1;
                            addressBeingEdited.Address2 = theNewAddressForm.Address2;
                            addressBeingEdited.State    = theNewAddressForm.State;
                            addressBeingEdited.City     = theNewAddressForm.City;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        //event handler for clicking of add address menu item
        //pre:buttomn clicked
        //post: launch form for creating new address
        private void addressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //create an instance of the form
            NewAddressForm inputForm = new NewAddressForm();

            //show the form as a dialogue box
            inputForm.ShowDialog();
            //if the dialogue is returned as successful
            if (inputForm.DialogResult == DialogResult.OK)
            {
                //checks if 2nd string was a valid value, if so has two address lines
                if (String.IsNullOrWhiteSpace(inputForm.AddressLineTwo))
                {
                    currentView.AddAddress(inputForm.AddressName, inputForm.AddressLineOne,
                                           inputForm.City, inputForm.State, inputForm.Zip);
                }
                //otherwise defaults to 1 address line
                else
                {
                    currentView.AddAddress(inputForm.AddressName, inputForm.AddressLineOne,
                                           inputForm.AddressLineTwo, inputForm.City, inputForm.State, inputForm.Zip);
                }
            }
        }