Example #1
0
        private void btnAddEmployee_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Do you wish to add a new employee?", "Add new employee?", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                string output = "";
                // Read inputs
                emp.FirstName = txtAddFName.Text;
                emp.LastName  = txtAddLName.Text;
                emp.Email     = txtAddEmail.Text;
                emp.DOB       = Convert.ToDateTime(txtAddDOB.Text);
                emp.Phone     = txtAddPhone.Text;

                // Call to DataHandler, then off to RegexCheck and finally StoredProcedure
                if (RegexCheck.Checker(emp) == "Pass")
                {
                    // Add employee to DB and store the result
                    int success = DataHandler.InsertEmployee(emp);

                    // Display the result
                    if (success == (int)SuccessEnum.Success)
                    {
                        output += "Added Employee to the DataBase!\n";
                        // Reset Fields
                        txtAddFName.Text = "";
                        txtAddLName.Text = "";
                        txtAddEmail.Text = "";
                        txtAddDOB.Text   = "";
                        txtAddPhone.Text = "";
                    }
                    else
                    {
                        output += "Failed to add Employee to the DataBase!\n";
                    }
                }
                // Display Regex fail message
                else
                {
                    output += RegexCheck.Checker(emp) + "\n";
                }

                MessageBox.Show(output, "Result");

                // Update List with new Employee
                FillListEmp();
            }
        }
Example #2
0
        private void btnUpdateHours_Click(object sender, EventArgs e)
        {
            string       output = "";
            DialogResult result = MessageBox.Show("Do you want update employee hours?", "Update hours?", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                // Read input
                emp.EmpID = int.Parse(lblUpdateEmpIDText.Text);
                // Create new EmpHours object
                EmpHours empHours = new EmpHours(emp);
                empHours.Date  = Convert.ToDateTime(txtUpdateWorkDate.Text);
                empHours.Hours = txtUpdateHours.Text;

                // Call to DataHandler, then off to RegexCheck and finally StoredProcedure
                if (RegexCheck.Checker(empHours) == "Pass")
                {
                    // Add employee to DB and store the result
                    int success = DataHandler.InsertHours(empHours);

                    // Display the result
                    if (success == (int)SuccessEnum.Success)
                    {
                        output += "Added Employee Hours to the DataBase!\n";
                    }
                    else
                    {
                        output += "Failed to add Employee Hours to the DataBase!\n";
                    }
                }
                // Regex fail message
                else
                {
                    output += RegexCheck.Checker(empHours) + "\n";
                }

                MessageBox.Show(output, "Result");

                txtUpdateHours.Text    = "";
                txtUpdateWorkDate.Text = monthCalendar.TodayDate.ToShortDateString();
            }
        }
Example #3
0
        private void btnUpdateEmployee_Click(object sender, EventArgs e)
        {
            string       output = "";
            DialogResult result = MessageBox.Show("Do you want to update employee information?", "Update employee?", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                // Remember which employee was selected
                int selected = listboxUpdate.SelectedIndex;

                // REALLY horrible solution..
                //-----------------------------------------
                IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true);
                DateTime        dt2     = new DateTime();
                try
                {
                    dt2 = DateTime.Parse(txtUpdateDOB.Text, culture, System.Globalization.DateTimeStyles.AssumeLocal);
                }
                catch (Exception)
                {
                    dt2 = new DateTime(0001, 01, 01);
                    // Had to change regex dateformat to not accept a year below 1000
                }
                //-----------------------------------------

                // Read inputs
                emp.EmpID     = int.Parse(lblUpdateEmpIDText.Text);
                emp.FirstName = txtUpdateFName.Text;
                emp.LastName  = txtUpdateLName.Text;
                emp.Email     = txtUpdateEmail.Text;
                //emp.DOB = Convert.ToDateTime(txtUpdateDOB.Text);
                emp.DOB   = dt2;
                emp.Phone = txtUpdatePhone.Text;

                // Call to DataHandler, then off to RegexCheck and finally StoredProcedure
                if (RegexCheck.Checker(emp) == "Pass")
                {
                    // Add employee to DB and store the result
                    int success = DataHandler.UpdateEmployee(emp);

                    // Display the result
                    if (success == (int)SuccessEnum.Success)
                    {
                        output += "Updated Employee Information!\n";
                    }
                    else
                    {
                        output += "Failed to update Employee Information!\n";
                    }
                }
                // Display Regex fail message
                else
                {
                    output += RegexCheck.Checker(emp);
                }

                MessageBox.Show(output, "Result");

                // Update List to include new Employee
                FillListEmp();
                // FillList resets the selected Employee
                // So we set it back using the index
                listboxUpdate.SelectedIndex = selected;
            }
        }