Example #1
0
        // Precondition:  Insert, Letter menu item activated
        // Postcondition: The Letter dialog box is displayed. If data entered
        //                are OK, a Letter is created and added to the list
        //                of parcels
        private void letterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm   letterForm;                         // The letter dialog box form
            DialogResult result;                             // The result of showing form as dialog

            if (upv.AddressCount < LetterForm.MIN_ADDRESSES) // Make sure we have enough addresses
            {
                MessageBox.Show("Need " + LetterForm.MIN_ADDRESSES + " addresses to create letter!",
                                "Addresses Error");
                return;
            }

            letterForm = new LetterForm(upv.AddressList); // Send list of addresses
            result     = letterForm.ShowDialog();

            if (result == DialogResult.OK) // Only add if OK
            {
                try
                {
                    // For this to work, LetterForm's combo boxes need to be in same
                    // order as upv's AddressList
                    upv.AddLetter(upv.AddressAt(letterForm.OriginAddressIndex),
                                  upv.AddressAt(letterForm.DestinationAddressIndex),
                                  decimal.Parse(letterForm.FixedCostText)); // Letter to be inserted
                }
                catch (FormatException)                                     // This should never happen if form validation works!
                {
                    MessageBox.Show("Problem with Letter Validation!", "Validation Error");
                }
            }

            letterForm.Dispose(); // Best practice for dialog boxes
        }
Example #2
0
        // Precondition:  Insert, Letter menu item activated
        // Postcondition: The Letter dialog box is displayed. If data entered
        //                are OK, a Letter is created and added to the list
        //                of parcels
        private void letterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm   letterForm;                         // The letter dialog box form
            DialogResult result;                             // The result of showing form as dialog
            decimal      fixedCost;                          // The letter's cost

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

            letterForm = new LetterForm(upv.AddressList); // Send list of addresses
            result     = letterForm.ShowDialog();

            if (result == DialogResult.OK) // Only add if OK
            {
                if (decimal.TryParse(letterForm.FixedCostText, out fixedCost))
                {
                    // For this to work, LetterForm's combo boxes need to be in same
                    // order as upv's AddressList
                    upv.AddLetter(upv.AddressAt(letterForm.OriginAddressIndex),
                                  upv.AddressAt(letterForm.DestinationAddressIndex),
                                  fixedCost); // Letter to be inserted
                }
                else // This should never happen if form validation works!
                {
                    MessageBox.Show("Problem with Letter Validation!", "Validation Error");
                }
            }

            letterForm.Dispose(); // Best practice for dialog boxes
                                  // Alternatively, use with using clause as in Ch. 17
        }
Example #3
0
        //Preconditions: Letter menu button must be clicked
        //Postconditions: LetterForm appears for data input
        private void LetterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm letterForm = new LetterForm();

            DialogResult letterResult;

            letterResult = letterForm.ShowDialog();
        }
Example #4
0
        // Precondition:  None
        // Postcondition: Adds a handler to the Insert -> Letter
        private void letterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Create the letter form, giving it the UPV
            LetterForm letterForm = new LetterForm(UserParcelView);

            //Show the dialog wait for it to close
            letterForm.ShowDialog();

            //Lets rebuild the list, something might have been added
            outputAddressesAndLetters(true);
        }
Example #5
0
        // Precondition: Button must be clicked
        // postcondition: the letter form will be opened
        private void letterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm   letterForm = new LetterForm(upv);
            DialogResult letterResult;

            letterResult = letterForm.ShowDialog();

            if (letterResult == DialogResult.OK)
            {
                upv.AddLetter(letterForm.OriginAddress, letterForm.DestinationAddress, letterForm.FixedCost);
            }
        }
Example #6
0
        //Pre-Condition:The "Letter" menu item is clicked
        //Post-Condition: The LetterForm is displayed as a dialoge and if the
        //                result is OK a letter is added to parcels
        private void letterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm   letterForm = new LetterForm(userParcelView.addresses); //instance of the letter form is created
            DialogResult result;                                                //varibale to hold the result of the dialog

            result = letterForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                userParcelView.AddLetter(userParcelView.addresses[letterForm.OriginCombo], userParcelView.addresses[letterForm.DestCombo], int.Parse(letterForm.CostBox));
            }
        }
Example #7
0
        //Precondition: Origin address, destination address, and fixed cost must have values
        //Postconditon: Shows form and creates a letter
        private void letterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm lfrm = new LetterForm(upv.AddressList); //New LetterForm object

            DialogResult result = lfrm.ShowDialog();

            if (result == DialogResult.OK)
            {
                upv.AddLetter(upv.AddressAt(lfrm.OriginValue), upv.AddressAt(lfrm.DestValue),
                              decimal.Parse(lfrm.FixedCost));
            }
            lfrm.Dispose();
        }
Example #8
0
        /*
         * Preconditions: The insert letter button is clicked.
         * Postcondition: The letter form appears and address is added to the list if necessary.
         */

        private void insertParcelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm letterForm = new LetterForm(upv.AddressList);

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

            result = letterForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                upv.AddLetter(upv.AddressAt(letterForm.From), upv.AddressAt(letterForm.To), letterForm.Cost);
            }
        }
Example #9
0
        //Precondition: Insert, Letter menu item activated
        //Postcondition: Displays the LetterForm and passes the desired origin/destination Addresses into the affiliated UPV parcels list
        private void letterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm letterForm = new LetterForm(testa.AddressList);

            DialogResult result    = letterForm.ShowDialog();       //Pulls the dialog result
            decimal      fixedCost = letterForm.NewCost;            //Variable for the fixed cost

            //If statement that takes the inputs made on the LetterForm
            //  and passes it to the UPV AddLetter method
            if (result == DialogResult.OK)
            {
                testa.AddLetter(testa.AddressAt(letterForm.FromAddress), testa.AddressAt(letterForm.ToAddress), fixedCost);
            }
        }
Example #10
0
        //Precondition: Insert > Letter has been activated.
        //Postcondition: The letter object has been created.
        private void letterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm   letterForm = new LetterForm(upv.AddressList);
            DialogResult result     = letterForm.ShowDialog();

            Address oAddress;
            Address dAddress;
            decimal fixedCost;

            if (result == DialogResult.OK)
            {
                oAddress = letterForm.OriginAddressIndex;
                dAddress = letterForm.DestinationAddressIndex;
                decimal.TryParse(letterForm.FixedCost, out fixedCost);
                upv.AddLetter(oAddress, dAddress, fixedCost);
            }
        }
Example #11
0
        //precondition: click Insert/letter tab
        //postcondition: opens new form to take user input for the letter and return it, then stores it.
        private void letterSub_Click(object sender, EventArgs e)
        {
            DialogResult results;                                               // DialogResult variable declared
            LetterForm   newLetter = new LetterForm(formObject.AddressList);    // instance of letterForm instantiated

            results = newLetter.ShowDialog();

            //if statement that stores letter info if OK button was clicked.
            if (results == DialogResult.OK)
            {
                int     originAddIndex = newLetter.OriginAddIndex;              //int variable to store the index of address chosen
                int     destAddIndex   = newLetter.DestAddIndex;                //int variable to store the index of address chosen
                decimal cost           = newLetter.Cost;                        //decimal variable to store the cost input

                formObject.AddLetter(formObject.AddressAt(originAddIndex), formObject.AddressAt(destAddIndex), cost);
            }
        }
Example #12
0
        //Precondition: click, upv.address must be instantiated with more than 2 addresses
        //Postcondition: Show Letter Form, add letter to upv parcel list
        private void letterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm   LF = new LetterForm(upv.addresses); //create LetterForm object, pass upv.AddressList into the constructor
            DialogResult result;                             //holds dialog result OK/Cancel

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

            if (result == DialogResult.OK)                   //result == OK? add the selected indices and parsed fixed cost to the parcel list
            {
                //Precondition: origin address and destination address Indices cannot be Equal, fixed cost must be a decimal value
                //Postcondition: Add Letter to UserParcelView parcel list
                upv.AddLetter(LF.AddressList[LF.OriginIndex], LF.AddressList[LF.DestinationIndex], decimal.Parse(LF.FixedCost));
            }
            else
            if (result == DialogResult.Cancel)     //Dispose of resources if result == cancel
            {
                LF.Dispose();
            }
        }
Example #13
0
        //Precondition: Letter menu item is clicked
        //Postcondition: Input from letter form is stored and sent to UPV.
        private void letterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm   LetterForm = new LetterForm(upv.AddressList);
            DialogResult result;
            int          originIndex;
            int          destinationIndex;
            decimal      fixedCost;

            result = LetterForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                originIndex      = LetterForm.OriginIndex;
                destinationIndex = LetterForm.DestIndex;
                fixedCost        = decimal.Parse(LetterForm.LetterFixedCost);

                upv.AddLetter(upv.AddressAt(originIndex), upv.AddressAt(destinationIndex), fixedCost);
            }
        }
        // Click event for the Add Letter menu option
        private void letterMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm   letterForm = new LetterForm(upv.AddressList); // Creates a new instance of the LetterForm
            DialogResult result;                                       // Holds result of dialog box

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

            // Holds the various information entered on AddressForm
            string  originAddress;
            string  destinationAddress;
            decimal fixedCost;

            if (result == DialogResult.OK) // If the user clicks ok on address form, info is entered and stored in upv
            {
                // originAddress = letterForm.OriginAddress;
                //destinationAddress = letterForm.DestinationAddress;
                fixedCost = letterForm.FixedCost;

                //upv.AddLetter(originAddress, destinationAddress, fixedCost);
            }
        }
Example #15
0
        //Postcondition: file must be selected
        //Postcondition: Deserialize binary object and downcast it as a UPV object, pass it through to the LetterForm
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult result;   //store dialog result
            string       fileName; //store the file name

            using (var fileChooser = new OpenFileDialog())
            {
                result   = fileChooser.ShowDialog(); //Show OpenFileDialog Dialog box
                fileName = fileChooser.FileName;     //set the file name
            }
            if (result == DialogResult.OK)           //if OK clicked
            {
                if (string.IsNullOrEmpty(fileName))  //is fileName empty?
                {
                    MessageBox.Show("Invalid File Name", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error); // show error if user specified invalid file
                }
                else
                {
                    FileStream input = new FileStream(
                        fileName, FileMode.Open, FileAccess.Read);       //create FileStream with path name, Open Mode, and Read Access
                    try
                    {
                        fileReader = new StreamReader(input);                      // set file from where data is read
                        upv        = (UserParcelView)formatter.Deserialize(input); //Deserialize the input and set it to the upv
                        LetterForm LF = new LetterForm(upv.AddressList);           //create LetterForm object
                    }
                    catch (IOException)
                    {
                        MessageBox.Show("Error reading from file",
                                        "File Error", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    finally
                    {
                        input.Close(); //release the FileStream resources
                    }
                }
            }
        }