Пример #1
0
        // Precondition:  OK button is cliked
        // Postcondition: The address form is shown with the address selected from combo box loaded. The
        //                user can change the data and save it to the file, which will update the address.
        private void okBttn_Click_1(object sender, EventArgs e)
        {
            Address     address     = addressList[AddressIndex]; //holds index of address list
            AddressForm addressForm = new AddressForm();         // The address dialog box form

            addressForm.AddressName = address.Name;              //changes the address form name to the address chosen's address name
            addressForm.Address1    = address.Address1;          //changes the address form address 1 to the address chosen's address 1
            addressForm.Address2    = address.Address2;          //changes the address form address 2 to the address chosen's address 2
            addressForm.City        = address.City;              //changes the address form city to the address chosen's city
            addressForm.State       = address.State;             //changes the address form state to the address chosen's state
            addressForm.ZipText     = address.Zip.ToString();    //changes the zip form name to the address chosen's zip

            DialogResult result = addressForm.ShowDialog();      // Show form as dialog and store result

            if (result == DialogResult.OK)                       //if the result is okay
            {
                int zip;                                         //holds value of zip code
                address.Name     = addressForm.AddressName;      //changes the address object's name to name on address form
                address.Address1 = addressForm.Address1;         //changes the address object's address1 to address1 on address form
                address.Address2 = addressForm.Address2;         //changes the address address2 to the address form address2
                address.City     = addressForm.City;             //changes the address city to the address form city
                address.State    = addressForm.State;            //changes the address state to the address form state
                int.TryParse(addressForm.ZipText, out zip);      //changes the address zip to the address form zip
                address.Zip = zip;                               //changes the address name to the address form name
                Close();                                         //close address form
            }
        }
        //Click event for the Add Address menu option
        protected void addressMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm  addressForm = new AddressForm(); // Creates a new instance of the AddressForm
            DialogResult result;                          // Holds result of dialog box

            result = addressForm.ShowDialog();            // Sets result = what was input

            // Holds the various information entered on AddressForm
            string addressName;
            string address1;
            string address2;
            string city;
            string state;
            int    zip;

            if (result == DialogResult.OK) // If the user clicks ok on address form, info is entered and stored in upv
            {
                addressName = addressForm.AddressName;
                address1    = addressForm.Address1;
                address2    = addressForm.Address2;
                city        = addressForm.City;
                state       = addressForm.State;
                zip         = addressForm.Zip;

                upv.AddAddress(addressName, address1, address2, city, state, zip);
            }
        }
Пример #3
0
        //Precondition: User clicks Edit > Address
        //Postcondition: ChooseAddressForm is displayed
        private void addressToolStripMenuItemOne_Click(object sender, EventArgs e)
        {
            ChooseAddressForm chooseForm = new ChooseAddressForm(upv.AddressList); //Send list of addresses
            DialogResult      result     = chooseForm.ShowDialog();                //Result is shown
            int addressIndex;                                                      //Used for index position

            if (result == DialogResult.OK)
            {
                addressIndex = chooseForm.chosenIndex;       //Inherit index from ChooseAddressForm
                AddressForm addressEdit = new AddressForm(); // Opens new address form to edit selected address

                //Fill in form with selected address
                addressEdit.AddressName = upv.AddressList[addressIndex].Name;
                addressEdit.Address1    = upv.AddressList[addressIndex].Address1;
                addressEdit.Address2    = upv.AddressList[addressIndex].Address2;
                addressEdit.City        = upv.AddressList[addressIndex].City;
                addressEdit.State       = upv.AddressList[addressIndex].State;
                addressEdit.ZipText     = upv.AddressList[addressIndex].Zip.ToString();

                DialogResult editResult = addressEdit.ShowDialog(); //Stores result from addressEdit

                //Fill in form with selected address
                if (editResult == DialogResult.OK)
                {
                    upv.AddressList[addressIndex].Name     = addressEdit.AddressName;
                    upv.AddressList[addressIndex].Address1 = addressEdit.Address1;
                    upv.AddressList[addressIndex].Address2 = addressEdit.Address2;
                    upv.AddressList[addressIndex].City     = addressEdit.City;
                    upv.AddressList[addressIndex].State    = addressEdit.State;
                    upv.AddressList[addressIndex].Zip      = Convert.ToInt32(addressEdit.ZipText);
                }
            }
        }
Пример #4
0
        //Precondition: user clicks on addresses under the edit menu.
        //Postcondition: new window will appear allowing user to edit address.
        private void addressToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            EditAddressForm editAddress = new EditAddressForm(upv.addresses); // send addresses to new form
            DialogResult    result      = editAddress.ShowDialog();           // The result of showing form as dialog
            int             addressIndex;                                     //used to hold the position of the addresses

            if (result == DialogResult.OK)
            {
                addressIndex = editAddress.index;           //inherit the selected address index
                AddressForm editAdress = new AddressForm(); //Create a new Address form

                //fills text boxes with information from the addresses
                editAdress.Address1    = upv.addresses[addressIndex].Address1;
                editAdress.Address2    = upv.addresses[addressIndex].Address2;
                editAdress.AddressName = upv.addresses[addressIndex].Name;
                editAdress.City        = upv.addresses[addressIndex].City;
                editAdress.State       = upv.addresses[addressIndex].State;
                editAdress.ZipText     = upv.addresses[addressIndex].Zip.ToString();

                DialogResult editResult = editAdress.ShowDialog();//Stores the dialog result from editAddress

                if (editResult == DialogResult.OK)
                {
                    //puts the information back into the address list that the user edited.
                    upv.addresses[addressIndex].Address1 = editAdress.Address1;
                    upv.addresses[addressIndex].Address2 = editAdress.Address2;
                    upv.addresses[addressIndex].Name     = editAdress.AddressName;
                    upv.addresses[addressIndex].City     = editAdress.City;
                    upv.addresses[addressIndex].State    = editAdress.State;
                    upv.addresses[addressIndex].Zip      = Convert.ToInt32(editAdress.ZipText);
                }
            }
        }
Пример #5
0
        //Precondition: Address menu item is clicked.
        //Postcondition: Input from address form is stored and sent to UPV.
        private void addressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm  AddressForm = new AddressForm();
            DialogResult result;
            string       name;                 //Variable to hold name
            string       address1;             //Variable to hold address line 1
            string       address2;             //Variable to hold address line 2
            string       city;                 //Variable to hold city
            string       state;                //Variable to hold state
            int          zip;                  //Variable to hold zip

            result = AddressForm.ShowDialog(); //Show Address form on top of main form

            if (result == DialogResult.OK)     //If the dialog result is okay
            {
                name     = AddressForm.AddressName;
                address1 = AddressForm.AddressLine1;
                address2 = AddressForm.AddressLine2;
                city     = AddressForm.AddressCity;
                state    = AddressForm.AddressState;
                zip      = int.Parse(AddressForm.AddressZip);

                upv.AddAddress(name, address1, address2, city, state, zip); //Use add address method to add address input to UPV.
            }
        }
Пример #6
0
        // 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);
                }
            }
        }
Пример #7
0
        // Precondition: Edit, Addresses menu item selected
        // Postcondition: edits existing address object
        private void addressToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            EditAddressForm editAddress = new EditAddressForm(upv.AddressList); // creates a new Edit Address Form
            DialogResult    result      = editAddress.ShowDialog();             // displays the edit form as a dialog box and stores the results

            if (result == DialogResult.OK)                                      // if everything is valid it opens the addressform(empty) need to have the data alrdy included into the new form!
            {
                AddressForm addressForm = new AddressForm();                    //creates a new Address Form

                // sets all of the address information(Name, Address 1 & 2, City, State, and ZipCode)
                // on the Address Form for the person who was selected in the Edit Address Dialog Box
                addressForm.AddressName = upv.AddressAt(editAddress.NameAddress).Name.ToString();
                addressForm.Address1    = upv.AddressAt(editAddress.NameAddress).Address1.ToString();
                addressForm.Address2    = upv.AddressAt(editAddress.NameAddress).Address2.ToString();
                addressForm.City        = upv.AddressAt(editAddress.NameAddress).City.ToString();
                addressForm.State       = upv.AddressAt(editAddress.NameAddress).State.ToString();
                addressForm.ZipText     = upv.AddressAt(editAddress.NameAddress).Zip.ToString();

                DialogResult editResult = addressForm.ShowDialog(); // displays all of the information that was has been set onto the dialog box

                if (editResult == DialogResult.OK)                  // if all of the text boxes contain valid information
                {
                    // edits the previous Address information to their new (if changed) values
                    upv.AddressAt(editAddress.NameAddress).Name     = addressForm.AddressName;
                    upv.AddressAt(editAddress.NameAddress).Address1 = addressForm.Address1;
                    upv.AddressAt(editAddress.NameAddress).Address2 = addressForm.Address2;
                    upv.AddressAt(editAddress.NameAddress).City     = addressForm.City;
                    upv.AddressAt(editAddress.NameAddress).State    = addressForm.State;
                    upv.AddressAt(editAddress.NameAddress).Zip      = Convert.ToInt32(addressForm.ZipText);
                }
            }
        }
Пример #8
0
        // Precondition: Edit, Address menu item activated
        // Postcondition: EditAddressForm shows
        private void editAddressButton_Click(object sender, EventArgs e)
        {
            EditAddressForm editAddressForm;                        // The edit address dialog box form
            DialogResult    result1;                                // Result of showing form as dialog

            editAddressForm = new EditAddressForm(upv.AddressList); // Send list of addresses
            result1         = editAddressForm.ShowDialog();

            if (result1 == DialogResult.OK)                             // Add if OK
            {
                int         addIndex    = editAddressForm.AddressIndex; // Address index
                Address     add         = upv.AddressAt(addIndex);      // Add address at index
                AddressForm addressForm = new AddressForm();            // The address dialog box form

                //Sets AddressFrom properties to Address properties
                addressForm.AddressName = add.Name;
                addressForm.Address1    = add.Address1;
                addressForm.Address2    = add.Address2;
                addressForm.City        = add.City;
                addressForm.State       = add.State;
                addressForm.ZipText     = add.Zip.ToString();

                DialogResult result2 = addressForm.ShowDialog(); // Result of showing form as dialog
                if (result2 == DialogResult.OK)                  // Add if OK
                {
                    // Sets Address properties to AddressForm properties
                    add.Name     = addressForm.AddressName;
                    add.Address1 = addressForm.Address1;
                    add.Address2 = addressForm.Address2;
                    add.City     = addressForm.City;
                    add.State    = addressForm.State;
                    add.Zip      = int.Parse(addressForm.ZipText);
                }
            }
        }
Пример #9
0
        //Preconditions: Address menu button must be clicked
        //Postconditions: AddressForm appears for data input
        private void AddressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm addressForm = new AddressForm();

            DialogResult addressResult;

            addressResult = addressForm.ShowDialog();
        }
        private void addressToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ChooseAddressForm chooseAddressForm;                    // The chooseAddress dialog box form
            DialogResult      result;                               // The result of showing form as dialog

            if (upv.AddressCount < ChooseAddressForm.MIN_ADDRESSES) // Make sure we have enough addresses
            {
                MessageBox.Show("Need " + ChooseAddressForm.MIN_ADDRESSES + " address to edit address!",
                                "Addresses Error");
                return; // Exit now since can't edit valid address
            }

            chooseAddressForm = new ChooseAddressForm(upv.AddressList); // Send list of addresses
            int index;                                                  // Creates index to hold index place as int

            result = chooseAddressForm.ShowDialog();                    // Sets result = dialog box of chooseAddressForm
            Address address;                                            // Creates object address of type Address

            if (result == DialogResult.OK)                              // Only add if OK
            {
                index = chooseAddressForm.AddressIndex;                 // Address to be inserted

                address = upv.AddressAt(index);                         // gives address object the address at specified index

                AddressForm  addressForm;                               // Creates addressForm of type AddressForm
                DialogResult dialogResult;                              // creates dialogResult of type DialogResult

                addressForm = new AddressForm();                        // Create a new instance of the AddressForm

                //Loads in the various address properties
                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 = addressForm.ShowDialog(); // Sets dialogResult = to loaded properties
                if (dialogResult == DialogResult.OK)     //OK dialog result dpes the same load but now in reverse
                {
                    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);
                }
            }

            else // This should never happen if form validation works!
            {
                MessageBox.Show("Problem with Address Validation!", "Validation Error");
            }

            chooseAddressForm.Dispose(); // Best practice for dialog boxes
                                         // Alternatively, use with using clause as in Ch. 17
        }
Пример #11
0
        //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
            }
        }
        //Pre: user clicks on address tab
        //Post: AddressForm should appear and allow data to be selected/entered
        private void addressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm  addressForm = new AddressForm();
            DialogResult result;

            result = addressForm.ShowDialog();

            //not sure how to get the info on to the main form?
        }
Пример #13
0
        // Precondition:  None
        // Postcondition: Adds a handler to the Insert -> Address
        private void addressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Create the address from, giving it the UPV
            AddressForm addressEntry = new AddressForm(UserParcelView);

            //Show the dialog and wait for user response
            addressEntry.ShowDialog();

            //Lets rebuild the list, something might have been added
            outputAddressesAndLetters(true);
        }
Пример #14
0
        // Precondition:  Edit, Address menu item activated
        // Postcondition: The address selected from the list has been edited
        //                with the new information replacing the existing object's
        //                properties
        private void addressToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (upv.AddressList.Count > 0)                                                // Only edit if there are addresses!
            {
                ChooseAddressForm chooseAddForm = new ChooseAddressForm(upv.AddressList); // The choose address dialog box form
                DialogResult      result        = chooseAddForm.ShowDialog();             // Show form as dialog and store result

                if (result == DialogResult.OK)                                            // Only edit if OK
                {
                    int editIndex;                                                        // Index of address to edit
                    editIndex = chooseAddForm.AddressIndex;

                    if (editIndex >= 0)                                     // -1 if didn't select item from combo box
                    {
                        Address     editAddress = upv.AddressAt(editIndex); // The address being edited
                        AddressForm addressForm = new AddressForm();        // The address dialog box form

                        // Populate form fields from selected address
                        addressForm.AddressName = editAddress.Name;
                        addressForm.Address1    = editAddress.Address1;
                        addressForm.Address2    = editAddress.Address2;
                        addressForm.City        = editAddress.City;
                        addressForm.State       = editAddress.State;
                        addressForm.ZipText     = $"{editAddress.Zip:D5}";

                        result = addressForm.ShowDialog(); // Show form as dialog and store result

                        if (result == DialogResult.OK)     // Only edit if OK
                        {
                            // Edit address properties using form fields
                            editAddress.Name     = addressForm.AddressName;
                            editAddress.Address1 = addressForm.Address1;
                            editAddress.Address2 = addressForm.Address2;
                            editAddress.City     = addressForm.City;
                            editAddress.State    = addressForm.State;
                            if (int.TryParse(addressForm.ZipText, out int zip))
                            {
                                editAddress.Zip = zip;
                            }
                            else
                            {
                                MessageBox.Show("Problem with Zip Validation!", "Validation Error");
                            }
                        }
                        addressForm.Dispose(); // Best practice for dialog boxes
                    }
                }
                chooseAddForm.Dispose(); // Best practice for dialog boxes
            }
            else
            {
                MessageBox.Show("No addresses to edit!", "No Addresses");
            }
        }
Пример #15
0
        //Precondition: Insert > Address has been activated.
        //Postcondition: The address object has been created.
        private void addressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm  addressForm = new AddressForm();
            DialogResult result      = addressForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                upv.AddAddress(addressForm.AddName, addressForm.Address1, addressForm.Address2, addressForm.City,
                               addressForm.State, int.Parse(addressForm.Zip));
            }
        }
Пример #16
0
        /*
         * Preconditions: The insert Address button is clicked.
         * Postcondition: The address form appears and address is added to the list if necessary.
         */

        private void insertAddressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm adf = new AddressForm();

            DialogResult result; // Result from dialog - OK/Cancel?

            result = adf.ShowDialog();

            if (result == DialogResult.OK)
            {
                upv.AddAddress(adf.AddressName, adf.Address1, adf.Address2, adf.City, adf.State, adf.Zip);
            }
        }
Пример #17
0
        //Precondition: None
        //Postcondition: Shows form for and creates address
        private void addressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm afrm = new AddressForm();

            DialogResult result = afrm.ShowDialog(); //Shows address dialog box

            if (result == DialogResult.OK)
            {
                upv.AddAddress(afrm.NameValue, afrm.AddressOne, afrm.AddressTwo, afrm.City, afrm.StateIndex, afrm.Zip);
            }

            afrm.Dispose(); //Resources are released
        }
Пример #18
0
        //Pre-Condition:The "Address" menu item is clicked
        //Post-Condition: The Address form is displayed as a dialog box
        //                and if the OK button was clicked,the contents
        //                are used to create a new address and added to addresses
        private void addressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm  addressForm = new AddressForm(); //The Address form instnace is created
            DialogResult result;                          //variable to hold the result of the dialog

            result = addressForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                userParcelView.AddAddress(addressForm.NameBox, addressForm.AddressBox1, addressForm.AddressBox2,
                                          addressForm.CityBox, addressForm.StateCombo, int.Parse(addressForm.ZipBox));
            }
        }
Пример #19
0
        //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();
            }
        }
Пример #20
0
        //Precondition: Address menu item is clicked
        //Postcondition: An address is added to the UPV object's list and the dialog box is disposed.
        private void AddressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm  addAddress = new AddressForm(); //new AddressForm object
            DialogResult dialogResult;                   //allows us to store a dialog result.

            dialogResult = addAddress.ShowDialog();      //displays the AddressForm.

            //checks to see if the dialogresult was set to ok. If it was, an address is added to the UPV object.
            if (dialogResult == DialogResult.OK)
            {
                upvObject.AddAddress(addAddress.NameValue, addAddress.Address1Value, addAddress.Address2Value, addAddress.CityValue, addAddress.StateValue, int.Parse(addAddress.ZipValue)); //passing the AddressForms results into the AddAddress method.
                addAddress.Dispose();                                                                                                                                                        //Gets rid of the form.
            }
        }
Пример #21
0
        //Precondition: None
        //Postcondition:takes info added in the Address form and uses it to create a new
        //              address object
        private void addressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm  addressForm = new AddressForm(); //adds a new address form object
            DialogResult result;

            result = addressForm.ShowDialog(); // shows the form as a modal dialog box

            if (result == DialogResult.OK)     //if all entered address info is valid
            {
                // adds the new address object to the list
                upv.AddAddress(addressForm.NameValue, addressForm.Address, addressForm.Address2,
                               addressForm.City, addressForm.State, Convert.ToInt32(addressForm.Zip));
            }
        }
Пример #22
0
        // Precondition: Button must be clicked
        // postcondition: the address form will be opened
        private void addressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm  addressForm = new AddressForm();
            DialogResult addressResult;

            addressResult = addressForm.ShowDialog();

            if (addressResult == DialogResult.OK)
            {
                int zip;
                int.TryParse(addressForm.zipText, out zip);
                upv.AddAddress(addressForm.nameText, addressForm.address1Text, addressForm.address2Text, addressForm.cityText, addressForm.stateText, zip);
            }
        }
Пример #23
0
        // 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
        }
Пример #24
0
        // ----------------------------------------------------------------------- EDIT --------->>

        // Precondition:  none
        // Postcondition: Specified address is resubmitted with the new details
        private void BtnEditAddress_Click(object sender, EventArgs e)
        {
            List <Address> addresses = upv.AddressList; // creates a list of addresses
            int            index;                       // used to identfy address

            if (upv.AddressCount <= 0)
            {
                MessageBox.Show("There must be atleast one address to edit.", "Error");
            }                                                                                                      //checks whether there is atleast one address
            else
            {
                EditAddressForm selectAddress = new EditAddressForm(addresses); // The address dialog box form
                DialogResult    result        = selectAddress.ShowDialog();     // Show form as dialog and store result

                if (result == DialogResult.OK)
                {
                    index = selectAddress.AddressIndex;              // keeps track of index

                    Address     selectedAddress = addresses[index];  // the index of the selcted address is kept
                    AddressForm editAddress     = new AddressForm(); // creates new dialogue to edit the address

                    // views the address details and presenets to user
                    editAddress.AddressName = selectedAddress.Name;
                    editAddress.Address1    = selectedAddress.Address1;
                    editAddress.Address2    = selectedAddress.Address2;
                    editAddress.City        = selectedAddress.City;
                    editAddress.State       = selectedAddress.State;
                    editAddress.ZipText     = selectedAddress.Zip.ToString();

                    DialogResult result_2 = editAddress.ShowDialog();

                    // edits the address details
                    if (result_2 == DialogResult.OK)
                    {
                        selectedAddress.Name     = editAddress.AddressName;
                        selectedAddress.Address1 = editAddress.Address1;
                        selectedAddress.Address2 = editAddress.Address2;
                        selectedAddress.City     = editAddress.City;
                        selectedAddress.State    = editAddress.State;
                        selectedAddress.Zip      = Convert.ToInt32(editAddress.ZipText);

                        reportTxt.Text = $"Address has been successfully edited."; //feedback
                    }
                }
            }
        }
Пример #25
0
        //Precondition: AddressList must be > 0
        //Postcondition: The address selected will be updated with newly specified values
        private void addressToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (upv.AddressCount < SelectorForm.MIN_ADDRESSES) //Count of Addresses in the upv must be greater than 0
            {
                MessageBox.Show("Need at least " + SelectorForm.MIN_ADDRESSES + " Address", "Address Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return; // Exit now since can't create valid letter
            }

            SelectorForm Selector = new SelectorForm(upv.AddressList); // The Selector dialog box form
            DialogResult result   = Selector.ShowDialog();             //Show Selector Form as dialog and store result

            AddressForm Editor   = new AddressForm();                  //The Editor dialog box form
            int         addIndex = Selector.Index;                     //local variable to store the index selected in the Editor Form

            Editor.AddressName = upv.AddressAt(addIndex).Name;         //Set Property to the Name of the AddressAt the SelectedIndex
            Editor.Address1    = upv.AddressAt(addIndex).Address1;     //Set Property to the Address1 of the AddressAt the SelectedIndex
            Editor.Address2    = upv.AddressAt(addIndex).Address2;     //Set Property to the Address2 of the AddressAt the SelectedIndex
            Editor.City        = upv.AddressAt(addIndex).City;         //Set Property to the City of the AddressAt the SelectedIndex
            Editor.State       = upv.AddressAt(addIndex).State;        //Set Property to the State of the AddressAt the SelectedIndex
            Editor.ZipText     = $"{upv.AddressAt(addIndex).Zip}";     //Set Property to the Zip of the AddressAt the SelectedIndex


            if (result == DialogResult.OK)                                 //if OK was clicked (Selector Form)
            {
                DialogResult result1 = Editor.ShowDialog();                //Show Editor form as a dialog box
                int          zipResult;                                    //integer holding TryParse result

                if (result1 == DialogResult.OK)                            //if OK was clicked (Editor Form)
                {
                    upv.AddressAt(addIndex).Name     = Editor.AddressName; //set upv Name property to the current value held in the Editor Forms TextBox
                    upv.AddressAt(addIndex).Address1 = Editor.Address1;    //set upv Address1 property to the current value held in the Editor Forms TextBox
                    upv.AddressAt(addIndex).Address2 = Editor.Address2;    //set upv Address2 property to the current value held in the Editor Forms TextBox
                    upv.AddressAt(addIndex).City     = Editor.City;        //set upv City property to the current value held in the Editor Forms TextBox
                    upv.AddressAt(addIndex).State    = Editor.State;       //set upv State property to the current value held in the Editor Forms TextBox

                    if (int.TryParse(Editor.ZipText, out zipResult))       //Try parsing the value in the TextBox, if successful, set the upv Zip property to that value
                    {
                        upv.AddressAt(addIndex).Zip = zipResult;
                    }
                }
                Editor.Dispose();     //dispose of resources
                Selector.Dispose();   //dispose of resources
            }
        }
Пример #26
0
        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);
                        }
                    }
                }
            }
        }
Пример #27
0
        //Precondition: click
        //Postcondition: Show Address Form, Add address to upv AddressList
        public void addressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm  AF = new AddressForm();                    //create an AddressForm object
            DialogResult result;                                    //holds result of the AddressForm button (OK/Cancel)

            result = AF.ShowDialog();                               //Shows the form as a modal dialog box

            if (result == DialogResult.OK && AF.ValidateChildren()) //if Result is OK, then Add an Address to the UserParcelView AddressList
            {
                //Precondition: ValidateChildren() must return true
                //Postcondition: Add Address to UserParcelView Address list
                upv.AddAddress(AF.NameValue, AF.AddressValue, AF.AddressValue1, AF.CityValue, AF.StateValue, AF.ZipValue);
            }
            else
            if (result == DialogResult.Cancel)    //Dispose of resources if result == cancel
            {
                AF.Dispose();
            }
        }
Пример #28
0
        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;
                        }
                    }
                }
            }
        }
Пример #29
0
        //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;
                }
            }
        }
Пример #30
0
        // Precondition: Edit, Addresses menu item activated
        // Postcondition: Allows you to edit an addresses opened from
        //                the upv object that you selected in ChooseAddressForm
        private void addressesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChooseAddressForm chooseForm;                        // new instnace of ChooseAddressForm
            DialogResult      result;                            // new dialogresult

            chooseForm = new ChooseAddressForm(upv.AddressList); // Send list of addresses
            result     = chooseForm.ShowDialog();                // show chooseform dialog box

            if (result == DialogResult.OK)                       // Only add if OK
            {
                try
                {
                    AddressForm  addressForm = new AddressForm();            // new instance of address
                    Address      myAddress;                                  // The address being added
                    DialogResult resultTwo;                                  // second dialog result

                    myAddress = upv.AddressAt(chooseForm.AddressIndex);      // get address from selected index and
                                                                             //assign it to variable myAddress
                    addressForm.AddressName = myAddress.Name;                // load address information into textbox

                    addressForm.Address1 = myAddress.Address1;               // load address information into textbox
                    addressForm.Address2 = myAddress.Address2;               // load address information into textbox
                    addressForm.City     = myAddress.City;                   // load address information into textbox
                    addressForm.State    = myAddress.State;                  // load address information into textbox
                    addressForm.ZipText  = myAddress.Zip.ToString("D5");     // load address information into textbox
                    resultTwo            = addressForm.ShowDialog();         // show form with preloaded address to edit
                    if (resultTwo == DialogResult.OK)                        // Only add if OK
                    {
                        myAddress.Name     = addressForm.AddressName;        // Change address at selected index with new information
                        myAddress.Address1 = addressForm.Address1;           // Change address at selected index with new information
                        myAddress.Address2 = addressForm.Address2;           // Change address at selected index with new information
                        myAddress.City     = addressForm.City;               // Change address at selected index with new information
                        myAddress.State    = addressForm.State;              // Change address at selected index with new information
                        myAddress.Zip      = int.Parse(addressForm.ZipText); // Change address at selected index with new information
                    }
                }
                catch (FormatException)                                                     // This should never happen if form validation works
                {
                    MessageBox.Show("Problem with Letter Validation!", "Validation Error"); // if something wrong, show error
                }
            }
        }