Beispiel #1
0
        private void calculateButton_Click(object sender, EventArgs e)
        {
            //Agent newJuniorAgent;
            try
            {
                //Check validation
                if (FormValidation.IsEmpty(lNameTextBox.Text) && FormValidation.IsEmpty(fNameTextBox.Text) &&
                    FormValidation.IsEmpty(emailTextBox.Text) && FormValidation.IsEmpty(salesAmountTextBox.Text))
                {
                    MessageBox.Show("Validation failed", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    //disable textBox control
                    lNameTextBox.Enabled       = false;
                    fNameTextBox.Enabled       = false;
                    emailTextBox.Enabled       = false;
                    juniorRadioButton.Enabled  = false;
                    agentRadioButton.Enabled   = false;
                    seniorRadioButton.Enabled  = false;
                    salesAmountTextBox.Enabled = false;

                    //prepare result for displaying
                    richTextBox1.Visible = true;
                    if (juniorRadioButton.Checked == true)
                    {
                        JuniorAgent newJuniorAgent = new JuniorAgent(lNameTextBox.Text, fNameTextBox.Text, emailTextBox.Text,
                                                                     double.Parse(salesAmountTextBox.Text), true);
                        richTextBox1.Text = "";
                        richTextBox1.Text = "Junior Agent commission Income Details\n\nTotal commission: " + newJuniorAgent.CalculateCommission(true).ToString("C")
                                            + "\nCommission Rate: " + newJuniorAgent.GetCommissionRate()
                                            + "\nNote that Junior agent got 0.5% less commission than agent";
                    }
                    else if (agentRadioButton.Checked == true)
                    {
                        richTextBox1.Text = "";
                        Agent aAgent = new Agent(lNameTextBox.Text, fNameTextBox.Text, emailTextBox.Text,
                                                 double.Parse(salesAmountTextBox.Text));
                        richTextBox1.Text = "Agent commission Income Details\n\nTotal commission: " + aAgent.CalculateCommission(true).ToString("C")
                                            + "\nCommission Rate: " + aAgent.GetCommissionRate();
                    }
                    else
                    {
                        richTextBox1.Text = "";
                        SeniorAgent aSeniorAgent = new SeniorAgent(lNameTextBox.Text, fNameTextBox.Text, emailTextBox.Text,
                                                                   double.Parse(salesAmountTextBox.Text));
                        richTextBox1.Text = "Senior Agent commission Income Details\n\nTotal commission: " + aSeniorAgent.CalculateCommission(true).ToString("C")
                                            + "\nCommission Rate: " + aSeniorAgent.GetCommissionRate();
                    }
                    this.Width = 657;
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Validation failed", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        private void placeOrderToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //Declare local variables
            string mealType = "", firstName = "", lastName = "";
            int    hamQty = 0, subQty = 0, fishQty = 0;



            firstName = firstNameTextBox.Text;
            lastName  = lastNameTextBox.Text;
            try
            {
                if (hamCheckBox.Checked)
                {
                    mealType += "Hamburger";
                    hamQty    = int.Parse(hamQTextBox.Text);
                }

                if (subCheckBox.Checked)
                {
                    mealType += " Sub";
                    subQty    = int.Parse(subQTextBox.Text);
                }
                if (fishCheckBox.Checked)
                {
                    mealType += " Fish";
                    fishQty   = int.Parse(fishQTextBox.Text);
                }
                int comboOption = mealChoiceComboBox.SelectedIndex;

                //Check validation
                if (!FormValidation.IsEmpty(firstName) && !FormValidation.IsEmpty(lastName) &&
                    ((hamCheckBox.Checked && hamQty > 0) || (subCheckBox.Checked && subQty > 0) ||
                     (fishCheckBox.Checked && fishQty > 0)) && comboOption >= 0)
                {
                    //If Validation is passed then place the order
                    Order aOrder = new Order(firstName, lastName, comboOption, mealType, hamQty, subQty, fishQty);
                    MessageBox.Show("Your order is placed");
                }
                else
                {
                    MessageBox.Show("Validation failed");
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Invalid input");
            }
        }
Beispiel #3
0
        private void saveBtn_Click(object sender, EventArgs e)
        {
            string errorText         = "";
            bool   hasFormInputError = false;

            if (FormValidation.IsEmpty(accHolderNameTxtBox.Text, "Name"))
            {
                errorText        += FormValidation.ErrorText + "\n";
                hasFormInputError = true;
            }

            if (FormValidation.IsEmpty(locationTxtbox.Text, "Location"))
            {
                errorText        += FormValidation.ErrorText + "\n";
                hasFormInputError = true;
            }
            if (FormValidation.IsEmpty(checkingAccNoTxtBox.Text, "Checkin Account No"))
            {
                errorText        += FormValidation.ErrorText + "\n";
                hasFormInputError = true;
            }
            if (!FormValidation.IsPositiveValue(checkingAccNoTxtBox.Text))
            {
                errorText        += FormValidation.ErrorText + " for checking acc no!\n";
                hasFormInputError = true;
            }
            if (!FormValidation.IsDouble(checkingAccBalanceTxtBox.Text))
            {
                errorText        += FormValidation.ErrorText + " for chekcing balance\n";
                hasFormInputError = true;
            }
            if (FormValidation.IsEmpty(savingsAccNoTxtBox.Text, "Savings Account No"))
            {
                errorText        += FormValidation.ErrorText + "\n";
                hasFormInputError = true;
            }
            if (!FormValidation.IsPositiveValue(savingsAccNoTxtBox.Text))
            {
                errorText        += FormValidation.ErrorText + " for savings acc no!\n";
                hasFormInputError = true;
            }
            if (!FormValidation.IsDouble(savingAccBalanceTxtBox.Text))
            {
                errorText        += FormValidation.ErrorText + " for savings balance\n";
                hasFormInputError = true;
            }

            if (hasFormInputError)
            {
                showBtn.Visible = false;
                MessageBox.Show("Please fix the following error\n\n" + errorText, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                CheckingAcc aCheckingAcc = new CheckingAcc(Double.Parse(checkingAccBalanceTxtBox.Text), accHolderNameTxtBox.Text, locationTxtbox.Text, Int32.Parse(checkingAccNoTxtBox.Text));
                SavingsAcc  aSavingsAcc  = new SavingsAcc(Double.Parse(savingAccBalanceTxtBox.Text), accHolderNameTxtBox.Text, locationTxtbox.Text, Int32.Parse(savingsAccNoTxtBox.Text));
                accountSummary  = aCheckingAcc.ToString() + aSavingsAcc.ToString();
                showBtn.Visible = true;
                MessageBox.Show("Information saved successfully!", "", MessageBoxButtons.OK);
            }
        }