Ejemplo n.º 1
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            // Create instance of Employee class called temp
            Employee temp = new Employee();

            // Fill in from Form Data
            temp.FName      = txtFName.Text;
            temp.MName      = txtMName.Text;
            temp.LName      = txtLName.Text;
            temp.Street1    = txtStreet1.Text;
            temp.Street2    = txtStreet2.Text;
            temp.City       = txtCity.Text;
            temp.State      = txtState.Text;
            temp.Zipcode    = txtZipCode.Text;
            temp.Country    = txtCountry.Text;
            temp.Phone      = txtPhone.Text;
            temp.Email      = txtEmail.Text;
            temp.EmployeeID = txtEmployeeID.Text;
            temp.HourlyRate = double.Parse(txtHourlyRate.Text);

            if (temp.Feedback.Contains("ERROR:"))
            {
                lblFeedback.Text = temp.Feedback;
            }
            else if (chkEmployee.Checked == true)
            {
                // FillLabel(temp);
                lblFeedback.Text = temp.AddEmployee();
            }
            else
            {
                // FillLabel(temp);
                lblFeedback.Text = temp.AddPerson();
            }
        }
Ejemplo n.º 2
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            double hourlyrate = 10;

            // Make sure the feedback label is cleared from any previous attempts
            lblFeedback.Text = "";

            /************************* FORM VALIDATION *************************/
            bool isValid = true;

            // First Name Form Validation
            if (ValidationLibrary.IsItFilledIn(txtFName.Text, 1) == false)
            {
                lblFeedback.Text += "ERROR: Please fill in a First Name.\n";
                isValid           = false;
            }

            // Last Name Form Validation
            if (ValidationLibrary.IsItFilledIn(txtLName.Text, 1) == false)
            {
                lblFeedback.Text += "ERROR: Please fill in a Last Name.\n";
                isValid           = false;
            }

            // State Form Validation
            if (ValidationLibrary.IsItFilledIn(txtState.Text, 2) == false)
            {
                lblFeedback.Text += "ERROR: Please fill in a 2-digit State abbreviation.\n";
                isValid           = false;
            }
            else if (ValidationLibrary.IsValidLength(txtState.Text, 2) == false)
            {
                lblFeedback.Text += "ERROR: Please make sure State abbreviation is exactly 2-digits.\n";
                isValid           = false;
            }
            else if (txtState.Text.All(Char.IsLetter) == false)
            {
                lblFeedback.Text += "ERROR: Please make sure State abbreviation only contains letters.\n";
                isValid           = false;
            }

            // Zip Code Form Validation
            if (ValidationLibrary.IsItFilledIn(txtZipCode.Text, 5) == false)
            {
                lblFeedback.Text += "ERROR: Please fill in a 5-digit Zip Code.\n";
                isValid           = false;
            }
            else if (ValidationLibrary.IsAllDigits(txtZipCode.Text) == false)
            {
                lblFeedback.Text += "ERROR: Please make sure Zip Code contains numbers only.\n";
                isValid           = false;
            }

            // Email Form Validation
            if (ValidationLibrary.IsItFilledIn(txtEmail.Text) == false)
            {
                lblFeedback.Text += "ERROR: Please fill in a valid Email address.\n";
                isValid           = false;
            }
            else if (ValidationLibrary.IsValidEmail(txtEmail.Text) == false)
            {
                lblFeedback.Text += "ERROR: Please fill in a valid Email address.\n";
                isValid           = false;
            }

            if (chkEmployee.Checked == true)
            {
                // Employee ID Form Validation
                if (ValidationLibrary.IsItFilledIn(txtEmployeeID.Text, 1) == false)
                {
                    lblFeedback.Text += "ERROR: Please fill in an Employee ID...Numbers Only!\n";
                    isValid           = false;
                }
                else if (txtEmployeeID.Text.All(Char.IsNumber) == false)
                {
                    lblFeedback.Text += "ERROR: Please make sure Employee ID contains numbers only.\n";
                    isValid           = false;
                }

                // Hourly Rate Form Validation
                if (txtHourlyRate.Text.Length < 2)
                {
                    lblFeedback.Text += "ERROR: Please fill in an Hourly Wage greate than or equal to 10.\n";
                    isValid           = false;
                }
                else
                {
                    bool isNum = double.TryParse(txtHourlyRate.Text, out hourlyrate) == true;

                    if (isNum == true)
                    {
                    }
                    else
                    {
                        lblFeedback.Text += "ERROR: Please make sure that Hourly Wage is greater than or equal to 10.\n";
                        isValid           = false;
                    }
                }
            }

            if (isValid)
            {
                // Create instance of Employee class called temp
                Employee temp = new Employee();

                // Fill in from Form Data
                temp.FName      = txtFName.Text;
                temp.MName      = txtMName.Text;
                temp.LName      = txtLName.Text;
                temp.Street1    = txtStreet1.Text;
                temp.Street2    = txtStreet2.Text;
                temp.City       = txtCity.Text;
                temp.State      = txtState.Text;
                temp.Zipcode    = txtZipCode.Text;
                temp.Country    = txtCountry.Text;
                temp.Phone      = txtPhone.Text;
                temp.Email      = txtEmail.Text;
                temp.Employed   = workstatus;
                temp.EmployeeID = txtEmployeeID.Text;
                temp.HourlyRate = double.Parse(txtHourlyRate.Text);

                // Display Errors or Results in Feedback Label
                if (temp.Feedback.Contains("ERROR:"))
                {
                    lblFeedback.Text = temp.Feedback;
                }
                else if (chkEmployee.Checked == true)
                {
                    lblFeedback.Text = temp.AddEmployee();
                }
                else
                {
                    lblFeedback.Text = temp.AddPerson();
                }
            }
        }