/* ================================================================== * 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]; } }
//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!"); }