コード例 #1
0
ファイル: Prog2Form.cs プロジェクト: meganbalcom/CIS-200
        // 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 (addressList.Count < 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(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 addressList
                    Letter newLetter = new Letter(addressList[letterForm.OriginAddressIndex],
                                                  addressList[letterForm.DestinationAddressIndex],
                                                  decimal.Parse(letterForm.FixedCostText)); // Letter to be inserted
                    parcelList.Add(newLetter);
                }
                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
        }
コード例 #2
0
        //event handler for Inserting a Letter
        private void letterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm   letterForm = new LetterForm(addresses);
            DialogResult result;              //used to store what is happened to the form

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

            if (result == DialogResult.OK)
            {
                Address originAddress = addresses[letterForm.OriginAddress]; //get origin address from the Letterorm
                Address destinAddress = addresses[letterForm.DestAddress];   //get destination address from the LetterForm

                decimal cost = decimal.Parse(letterForm.Cost);               //get the cost from the LetterForm

                //create letter with the data
                Letter newLetter = new Letter(originAddress, destinAddress, cost);

                //add the new address to the list
                parcels.Add(newLetter);
            }
            else
            {
                result = DialogResult.Cancel;
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: meganbalcom/CIS-200
        //Precondition: user clicked "insert letter" menu item
        //Postcondition: a new letter is added to the list
        private void letterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm   createdLetter    = new LetterForm(address);               //parameterized constructor
            DialogResult result           = createdLetter.ShowDialog();            //defines the dialog result
            int          originIndex      = createdLetter.originComboSelectedItem; //variable for what index position was selected in origin combo box
            int          destinationIndex = createdLetter.destComboSelectedItem;   //variable for what index position was selected in dest combo box

            if (result == DialogResult.OK)                                         //if "Ok" is the dialog result
            {
                Address originAddress      = address[originIndex];
                Address destinationAddress = address[destinationIndex];
                Letter  newLetter          = new Letter(originAddress, destinationAddress, createdLetter.FixedCost);
                //Creates a new letter object using the index positions of the two addresses and uses the fixed cost
                //entered in the letter form

                parcels.Add(newLetter); //adds a new letter object
            }
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: cphelps56/CIS200-Program2
        // Precondition: The Insert-Letter menu item was clicked.
        // Postcondition: A dialog box is displayed, prompting the user
        //                to select an origin address, a destination address,
        //                and a cost. If the user submits a new letter object
        //                is created and added to the parcels list.
        private void letterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm   letterForm = new LetterForm(addressList); // The dialog box form
            DialogResult result;                                   // result from dialog box
            Address      orAdr;                                    // variable to hold origin address
            Address      destAdr;                                  // variable to hold destination address
            decimal      cost;                                     // variable to hold the cost

            result = letterForm.ShowDialog();                      // shows modal dialog box, waits for OK/Cancel

            if (result == DialogResult.OK)                         // Only add if user chose OK
            {
                // gives variables values from dialog box
                orAdr   = addressList[letterForm.OrAddressIndex];
                destAdr = addressList[letterForm.DestAddressIndex];
                cost    = decimal.Parse(letterForm.FixedCost);

                Letter myLetter = new Letter(orAdr, destAdr, cost); // creates new letter object
                parcels.Add(myLetter);                              // adds new letter to the parcel list
            }
        }
コード例 #5
0
        // Preconditions: Insert Letter is clicked
        // Postconditions: Letter is created
        private void letterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LetterForm letterform = new LetterForm();

            DialogResult result = letterform.ShowDialog();

            string originAddress;
            string destinationAddress;

            if (result == DialogResult.OK)
            {
                originAddress = letterform.originIndex.ToString();
                destinationAddress = letterform.destinationIndex.ToString();
            }
            letterform.Dispose();
        }
コード例 #6
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 (addressList.Count < 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(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 addressList
                    Letter newLetter = new Letter(addressList[letterForm.OriginAddressIndex],
                        addressList[letterForm.DestinationAddressIndex],
                        decimal.Parse(letterForm.FixedCostText)); // Letter to be inserted
                    parcelList.Add(newLetter);
                }
                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
        }