Example #1
0
        /*
         * =============================================================
         * Save event
         *
         *
         * =============================================================
         */
        private void btnSave_Click(object sender, EventArgs e)
        {
            //Loops through allCells, storing e.Text in currentGridDisplay; uses dictionaries and ParseCellName
            UpdateGrid();

            //Display Hours
            double hrs = CalculateHours();

            lblTotal.Text = Math.Round(hrs, 1).ToString();

            if (CheckValidTransition())
            {
                //Updates workweek for specific tableid
                PrepareLongColumns();

                //Call TimeSheetDatabase Update function
                TimeSheetDatabase.UpdateTimeSheet(currentWorkWeek.TableID, LongColumns[0], LongColumns[1], LongColumns[2], LongColumns[3], LongColumns[4], LongColumns[5], LongColumns[6]);
            }
            else
            {
                //Correct the error - user change dropdown list selection but did not open
                txtFirstName.Text = currentWorkWeek.FirstName;
                txtLastName.Text  = currentWorkWeek.LastName;
            }
        }
Example #2
0
        /*
         * Open and Save events
         */
        //Display current week of data
        private void btnOpen_Click(object sender, EventArgs e)
        {
            if (txtFirstName.Text != "" || txtLastName.Text != "")
            {
                //Update for autocompletion...
                employeeWorkWeekList = TimeSheetDatabase.GetAllWorkWeekForSingleEmployee(txtFirstName.Text, txtLastName.Text);

                //Exit on empty list
                if (employeeWorkWeekList.Count == 0)
                {
                    return;
                }

                currentWorkWeek = WorkWeek.GetCurrentWorkWeek(employeeWorkWeekList);

                //Split the string array first, before putting them in cells
                Display(currentWorkWeek);
                UpdateWeekComboBox(currentWorkWeek);

                //Display Hours
                double hrs = CalculateHours();
                lblTotal.Text = Math.Round(hrs, 3).ToString();

                //Feedback
                MessageBox.Show(string.Format("WorkWeek for employee:\n{0} {1}.", currentWorkWeek.FirstName.Trim(), currentWorkWeek.LastName.Trim()));
            }
            else
            {
                MessageBox.Show("Missing data! Please enter employee's first and last name.");
            }
        }
Example #3
0
        //Remove button event
        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (txtFirstName.Text == "" || txtLastName.Text == "")
            {
                MessageBox.Show("Missing data; please enter first and last name.");
                return;
            }

            Employee employee = EmployeeDatabase.GetEmployee(txtFirstName.Text, txtLastName.Text);

            if (employee.EmployeeID == 0)
            {
                MessageBox.Show("No employee found with that reference.");
                return;
            }

            EmployeeDatabase.RemoveEmployee(txtFirstName.Text, txtLastName.Text);

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

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

            //Add to timsheet table
            TimeSheetDatabase.RemoveWorkWeekWithName(employee.EmployeeID.ToString(), employee.FirstName);


            //Some more feedback on remove employee
            MessageBox.Show("Removed 1 employee.");
        }
Example #4
0
        /*	==================================================================
         *	btnForth_click event
         *	*****************************************************************
         *	Description: Creates a new WorkWeek, only 1 above current date
         *	Notes:
         *	1. Create new WorkWeek with EmployeeID, FirstName, LastName,
         *	empty data cells (like when in EmployeeForm).
         *	2. Set Week to be +7 days from current date.
         *	3. Display (includes add to weekspan combobox)
         *	4. Only 1 week above current date allowed.
         *
         *	==================================================================
         */
        private void btnForth_Click(object sender, EventArgs e)
        {
            //Prevent logic error - user changes names but does not click 'open records'
            if (CheckValidTransition())
            {
                //Correct the error - user change dropdown list selection but did not open
                txtFirstName.Text = currentWorkWeek.FirstName;
                txtLastName.Text  = currentWorkWeek.LastName;
            }
            else
            {
                return;
            }


            //Move to next workWeek when not in last week
            int index = employeeWorkWeekList.IndexOf(currentWorkWeek);

            if (index == (employeeWorkWeekList.Count - 1))                                              //Last item
            {
                //Add new WorkWeek to table TimeSheet, with Week +7 of current week ()
                //--Update timesheet table with new employee - name and employee id, the rest of the fields empty
                DateTime dateNextWeek;
                if (DateTime.TryParse(currentWorkWeek.Week, out dateNextWeek))
                {
                    dateNextWeek = dateNextWeek.AddDays(7);
                }

                //Add to timesheet table
                TimeSheetDatabase.AddWeekWork(currentWorkWeek.EmployeeID.ToString(), currentWorkWeek.FirstName, currentWorkWeek.LastName, WorkWeek.zeroDummy, WorkWeek.zeroDummy, WorkWeek.zeroDummy, WorkWeek.zeroDummy, WorkWeek.ellipsisDummy, WorkWeek.dashDummy, WorkWeek.dashDummy, dateNextWeek.ToString());

                //Update employee WorkWeek list, and set currentWorkWeek
                employeeWorkWeekList = TimeSheetDatabase.GetAllWorkWeekForSingleEmployee(txtFirstName.Text, txtLastName.Text);
                currentWorkWeek      = employeeWorkWeekList.Last();
                //MessageBox.Show(currentWorkWeek.Week.ToString());

                //Display
                UpdateWeekComboBox(currentWorkWeek);
                Display(currentWorkWeek);

                //Display Hours
                double hrs = CalculateHours();
                lblTotal.Text = Math.Round(hrs, 1).ToString();

                //Feedback
                MessageBox.Show(string.Format("Added new Time Sheet for employee {0} {1}", currentWorkWeek.FirstName, currentWorkWeek.LastName));
            }
            else
            {
                //Change combobox
                cmbWeekSpan.SelectedItem = cmbWeekSpan.Items[index + 1];
            }
        }
Example #5
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!");
        }