Exemple #1
0
        // Precondition: "Edit Address" menu item is activated
        // Postcondition: The EditAnAddressForm appears and allows the user to select the
        //                address they want to edit. Then, the AddressForm is populated
        //                with the respective data and can be edited.

        private void addressToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            EditAnAddressForm editAddress = new EditAnAddressForm(addressList); // Address that will be edited
            DialogResult      result1     = editAddress.ShowDialog();           // Result of OpenFileDialog


            if (result1 == DialogResult.OK)
            {
                int         index       = editAddress.EditAddressIndex; // holds the position selected
                Address     a           = addressList[index];           //the address the user chooses
                AddressForm addressForm = new AddressForm();            // create a new addressForm object

                // Assign the field values according to the address selected
                addressForm.AddressName           = a.Name;
                addressForm.Address1              = a.Address1;
                addressForm.Address2              = a.Address2;
                addressForm.City                  = a.City;
                addressForm.stateCbo.SelectedItem = a.State;
                addressForm.ZipText               = a.Zip.ToString();

                DialogResult result2 = addressForm.ShowDialog(); // Result of selecting an address to edit
                if (result2 == DialogResult.OK)
                {
                    // Populate the fields of the AddressForm with the data
                    a.Name     = addressForm.AddressName;
                    a.Address1 = addressForm.Address1;
                    a.Address2 = addressForm.Address2;
                    a.City     = addressForm.City;
                    a.State    = addressForm.stateCbo.SelectedItem.ToString();
                    a.Zip      = int.Parse(addressForm.ZipText);
                }
            }
        }
        List <Address> addressList = new List <Address>(); // field to hold list of addresses

        // Precondition: The Insert-Address menu button was clicked.
        // Postcondition: A dialog box is displayed propmting the user
        //                to fill in all the neccessary data to create
        //                an address object. If the user submits, a new
        //                address is added to the address list.
        private void addressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm  addressForm = new AddressForm(); // the dialog box form
            DialogResult result;                          // result from dialog
            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 modal dialog box, waits for OK/Cancel

            if (result == DialogResult.OK)                // Only add new address when user chose OK
            {
                // gives variables values from dialog box
                name     = addressForm.AddressName;
                address1 = addressForm.AddressLine1;
                address2 = addressForm.AddressLine2;
                city     = addressForm.AddressCity;
                state    = addressForm.AddressState.ToString();
                zip      = int.Parse(addressForm.AddressZip);

                Address myAddress = new Address(name, address1, address2, city, state, zip); // new address created from data from dialog box
                addressList.Add(myAddress);                                                  // adds new address to address list
            }
        }
        //event handler opening a new AddressForm
        private void mainMenuStrip_Click(object sender, EventArgs e)
        {
            AddressForm  addressForm = new AddressForm(states); //create new object of AddressForm
            DialogResult result;                                //used to store what is happened to the form


            result = addressForm.ShowDialog(); // form will be opened and will be modal

            //checking to see if anything was stored
            if (result == DialogResult.OK)
            {
                string name     = addressForm.NameValue;               //get the name from the AddressForm
                string address1 = addressForm.Addr1Value;              //get the address line 1 from the AddressForm
                string address2 = addressForm.Addr2Value;              //get the address line 2 from the AddressForm
                string city     = addressForm.CityValue;               //get the city from the AddressForm
                string state    = states[addressForm.StateValue];      //get the state from the AddressForm
                int    zipCode  = int.Parse(addressForm.ZipCodeValue); //get the zip code from the AddressForm

                //create address with new data
                Address newAddress = new Address(name, address1, address2, city, state, zipCode);

                //add the new address to the list
                addresses.Add(newAddress);
            }
        }
Exemple #4
0
        //PreConditions: User clicks edit button
        //PostConditions: Shows a Address Form
        private void editButton_Click(object sender, EventArgs e)
        {
            //Get the index of the selected value
            int selectedIndex = addressCBox.SelectedIndex;

            //If nothing is selected tell the user and return
            if (selectedIndex < 0)
            {
                MessageBox.Show("You must select an address to edit");
                return;
            }


            //The user selected a valid index lets create the form
            AddressForm addressForm = new AddressForm();

            //Get the address
            var address = _UPV.AddressAt(addressCBox.SelectedIndex);

            //Set the forms values based on the selected address
            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();

            //Lets hide the form to make it look cleaner
            this.Visible = false;

            //Show the address form and wait for a response
            var result = addressForm.ShowDialog();

            //The user closed the form, if they accepted the edit lets set the values, if not close the form
            if (result == DialogResult.OK)
            {
                //Set the values from the form to the address
                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);

                //Close the form with an OK status
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                //Closes the form
                cancelButton_Click(sender, e);
            }
        }
Exemple #5
0
        //Precondition: user clicked on "insert address" menu item
        //Postcondition: a new address is added to the list
        //This click event is adding any valid address object created in the address form
        private void addressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm  createdAddress = new AddressForm();           //Creating an AddressForm object so it can be accessed in this class
            DialogResult result         = createdAddress.ShowDialog(); //Defines the DialogResult

            if (result == DialogResult.OK)                             //Referencing the Add Address Button on Address Form
            //If the dialog result is "ok" create a new address object
            {
                Address newAddress = new Address(createdAddress.NameAddressForm, createdAddress.AddressLine1,
                                                 createdAddress.AddressLine2, createdAddress.City, createdAddress.State, createdAddress.Zip);

                address.Add(newAddress);
            }
        }
        // Precondition: Address list cannot be empty
        // Postcondition: An address object is selected and can be edited by the user
        private void addressesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChooseAddressForm chooseAddressForm; // the choose address dialog box form
            DialogResult      result1;           // holds the result from the dialog box

            if (addressList.Count < 1)           // ensures the address list is not empty
            {
                MessageBox.Show("There are no addresses to edit", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                chooseAddressForm = new ChooseAddressForm(addressList);// creates form and sends the address list
                result1           = chooseAddressForm.ShowDialog();

                if (result1 == DialogResult.OK)
                {
                    int     index = chooseAddressForm.AddressIndex; // holds selection index
                    Address a     = addressList[index];             // variable to hold selected address

                    AddressForm addressForm = new AddressForm();    // creates address form dialog box

                    // sets text boxes on form to the properties from the selected address
                    addressForm.AddressName = a.Name;
                    addressForm.Address1    = a.Address1;
                    addressForm.Address2    = a.Address2;
                    addressForm.City        = a.City;
                    addressForm.State       = a.State;
                    addressForm.ZipText     = a.Zip.ToString();

                    DialogResult result2 = addressForm.ShowDialog();

                    if (result2 == DialogResult.OK)
                    {
                        // sets the properties for the selected address to the edited values
                        a.Name     = addressForm.AddressName;
                        a.Address1 = addressForm.Address1;
                        a.Address2 = addressForm.Address2;
                        a.City     = addressForm.City;
                        a.State    = addressForm.State;
                        a.Zip      = int.Parse(addressForm.ZipText);
                    }
                    addressForm.Dispose();
                }
                chooseAddressForm.Dispose();
            }
        }
Exemple #7
0
        // Precondition:  Insert, Address menu item activated
        // Postcondition: The Address dialog box is displayed. If data entered
        //                are OK, an Address is created and added to the list
        //                of addresses
        private void addressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm  addressForm = new AddressForm();        // The address dialog box form
            DialogResult result      = addressForm.ShowDialog(); // Show form as dialog and store result

            if (result == DialogResult.OK)                       // Only add if OK
            {
                try
                {
                    Address newAddress = new Address(addressForm.AddressName, addressForm.Address1,
                                                     addressForm.Address2, addressForm.City, addressForm.State,
                                                     int.Parse(addressForm.ZipText)); // Use form's properties to create address
                    addressList.Add(newAddress);
                }
                catch (FormatException) // This should never happen if form validation works!
                {
                    MessageBox.Show("Problem with Address Validation!", "Validation Error");
                }
            }

            addressForm.Dispose(); // Best practice for dialog boxes
        }
Exemple #8
0
        //event handler for Edit > Address
        private void addressToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //create new EditAddress form
            EditAddress  editForm = new EditAddress(addressList);
            DialogResult editResult;

            editResult = editForm.ShowDialog(); //open editForm as modal

            //user has chosed an address to edit and has clicked "Edit"
            if (editResult == DialogResult.OK)
            {
                DialogResult addrResult;
                int          index = editForm.Edit;              //int for storing index of selected address
                Address      a     = addressList[index];         //this is the chosen address to edit

                AddressForm addressForm = new AddressForm();     //opens new AddressForm
                addressForm.AddressName = a.Name.ToString();     //set the name in the text box
                addressForm.Address1    = a.Address1.ToString(); //set the address 1 in the text box
                addressForm.Address2    = a.Address2.ToString(); //set the address 2 in the text box
                addressForm.City        = a.City.ToString();     //set the city in the text box
                addressForm.State       = a.State.ToString();    //set the state in the text box
                addressForm.ZipText     = a.Zip.ToString();      //set the zip code in the text box

                addrResult = addressForm.ShowDialog();           //open edit form with populated values

                //user has clicked ok to edit the address
                if (addrResult == DialogResult.OK)
                {
                    //now we do the reverse of what we just did previously by actually EDITING the
                    //values for the given address, not replacing the address with a new version
                    a.Name     = addressForm.AddressName;
                    a.Address1 = addressForm.Address1;
                    a.Address2 = addressForm.Address2;
                    a.City     = addressForm.City;
                    a.State    = addressForm.State;
                    a.Zip      = int.Parse(addressForm.ZipText);
                }
            }
        }
        // Preconditions: Insert address is clicked
        // Postconditions: Address is created
        private void addressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm addressForm = new AddressForm();

            DialogResult result = addressForm.ShowDialog();

            Address myAddress;

            if(result==DialogResult.OK)
            {

                addresses.Add(addressForm.name, addressForm.addressLine1, addressForm.addressLine2, addressForm.city, addressForm.stateIndex.ToString(), addressForm.zip);
            }
            addressForm.Dispose();
        }
        // Precondition:  Edit, Address menu item activated
        // Postcondition: The address selected  has been edited with the new information replacing
        //                the existing object's properties
        private void addressToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            List<Address> Addresses;

            Addresses = addressList;

            if ((Addresses.Count() == 0))
                MessageBox.Show("Must have address to edit", "Edit Error");
            else
            {
                SelectAddressForm saForm = new SelectAddressForm(Addresses);
                DialogResult result = saForm.ShowDialog();

                if (result == DialogResult.OK)
                {
                    int editIndex;

                    editIndex = saForm.addressIndex;

                    if (editIndex >= 0)
                    {
                        Address editAddress = Addresses[editIndex];

                        AddressForm addressForm = new AddressForm();

                        addressForm.AddressName = editAddress.Name;

                        DialogResult editResult = addressForm.ShowDialog();

                        if (editResult == DialogResult.OK)
                        {
                            editAddress.Name = addressForm.AddressName;
                        }
                        addressForm.Dispose();
                    }
                }
                saForm.Dispose();
            }
        }
        // Precondition:  Insert, Address menu item activated
        // Postcondition: The Address dialog box is displayed. If data entered
        //                are OK, an Address is created and added to the list
        //                of addresses
        private void addressToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddressForm addressForm = new AddressForm(); // The address dialog box form
            DialogResult result = addressForm.ShowDialog(); // Show form as dialog and store result

            if (result == DialogResult.OK) // Only add if OK
            {
                try
                {
                    Address newAddress = new Address(addressForm.AddressName, addressForm.Address1,
                        addressForm.Address2, addressForm.City, addressForm.State,
                        int.Parse(addressForm.ZipText)); // Use form's properties to create address
                    addressList.Add(newAddress);
                }
                catch (FormatException) // This should never happen if form validation works!
                {
                    MessageBox.Show("Problem with Address Validation!", "Validation Error");
                }
            }

            addressForm.Dispose(); // Best practice for dialog boxes
        }