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