//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."); }
//EmployeeForm - Handles tab and enter key presses for autocomplete purposes private void txt_EnterKeyUp(Object obj, KeyEventArgs e) { if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Tab) { if (txtFirstName.Text != "" && txtLastName.Text != "" ) { //Self auto-complete pattern Employee employee = EmployeeDatabase.GetEmployee(txtFirstName.Text, txtLastName.Text); //No employee record if (employee.EmployeeID == 0) { return; } UtilWinforms.AutoCompleteEmpties(ref allTextBoxControls, employee); } } }
//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!"); }