Beispiel #1
0
        //Updates Employee's information
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (!UtilDotNET.IsMatch(UtilDotNET.phonePattern1, txtPhone.Text))
            {
                MessageBox.Show("Error: not a valid phone format.");
                return;
            }


            if (!UtilDotNET.IsMatch(UtilDotNET.emailPattern, txtEmail.Text))
            {
                MessageBox.Show("Error: invalid email format.");
                return;
            }


            if (!UtilDotNET.ValidateDate(txtStartingDate.Text) && txtStartingDate.Text != "")
            {
                MessageBox.Show("Invalid date format");
                return;
            }

            EmployeeDatabase.UpdateEmployee(txtFirstName.Text, txtLastName.Text, txtDepartment.Text, txtPhone.Text, txtEmail.Text, txtStartingDate.Text);

            MessageBox.Show(string.Format("Updated: {0} {1}", txtFirstName.Text, txtLastName.Text));

            //Update listview display
            this.Form2_Load(this, null);
        }
Beispiel #2
0
        //Submit button event, add employee, update auto complete, and include employee in timesheet
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //Exit this function if there is any blank text leave out
            if (txtFirstName.Text == "" || txtLastName.Text == "" || txtDepartment.Text == "" || txtPhone.Text == "" || txtEmail.Text == "")
            {
                MessageBox.Show("Missing data; please fill in all fields.");
                return;
            }

            /* ==================================================================
             * Format invariants
             * - Phone: xxx-xxx-xxxx
             * - Department: enum match
             * - Email: _@_.com
             * - Date: MM/dd/yyyy (just tryparse)
             */
            if (!UtilDotNET.IsMatch(UtilDotNET.phonePattern1, txtPhone.Text))
            {
                MessageBox.Show("Error: not a valid phone format.");
                return;
            }


            if (!UtilDotNET.IsMatch(UtilDotNET.emailPattern, txtEmail.Text))
            {
                MessageBox.Show("Error: invalid email format.");
                return;
            }


            if (!UtilDotNET.ValidateDate(txtStartingDate.Text) && txtStartingDate.Text != "")
            {
                MessageBox.Show("Invalid date format");
                return;
            }



            //Exit if employee is already in list
            Employee solicitude = EmployeeDatabase.GetEmployee(txtFirstName.Text, txtLastName.Text);

            if (solicitude == null)
            {
                MessageBox.Show(string.Format("Employee {0} {1} already in records.", solicitude.FirstName, solicitude.LastName));
                return;
            }

            EmployeeDatabase.AddEmployee(txtFirstName.Text, txtLastName.Text, txtDepartment.Text, txtPhone.Text, txtEmail.Text, txtStartingDate.Text);
            //Load all employees
            allEmployees = EmployeeDatabase.GetAllEmployees();

            UtilWinforms.UpdateAutoComplete(ref allTextBoxControls, ref allEmployees);            //Update AutoComplete values

            //Some feedback on add employee
            MessageBox.Show("Added 1 employee to Employee table.");

            //Update timesheet table with new employee - name and employee id, the rest of the fields empty
            Employee employee = EmployeeDatabase.GetEmployee(txtFirstName.Text, txtLastName.Text);

            //Add to timsheet table
            TimeSheetDatabase.AddWeekWork(employee.EmployeeID.ToString(), employee.FirstName, employee.LastName, WorkWeek.zeroDummy, WorkWeek.zeroDummy, WorkWeek.zeroDummy, WorkWeek.zeroDummy, WorkWeek.ellipsisDummy, WorkWeek.dashDummy, WorkWeek.dashDummy, employee.StartingDate);

            //Clear out the form
            txtFirstName.Text    = "";
            txtLastName.Text     = "";
            txtDepartment.Text   = "";
            txtPhone.Text        = "";
            txtEmail.Text        = "";
            txtStartingDate.Text = "";

            this.Form2_Load(this, null);                                        //Update listview

            MessageBox.Show("Employee added to timesheet records.\nYou can start now updating employee's work days!");
        }