protected void btnDelete_Click(object sender, EventArgs e) { try { CsEmployee objEmp = new CsEmployee(); Int32 _codeofEmp = Convert.ToInt32(txtcode.Text.Trim()); objEmp.deleteEmployee(_codeofEmp); txtcode.Text = ""; txtdept.Text = ""; txtdesi.Text = ""; txtname.Text = ""; txtyears.Text = ""; notFound.Text = "Information about " + _codeofEmp + " has been deleted"; notFound.Visible = true; btnDelete.Enabled = false; txtcode.Enabled = true; } catch { notFound.Text = "You must first enter a code in the code field and click find in order to delete"; txtcode.Focus(); } }
protected void btnSave_Click(object sender, EventArgs e) { Int32 cod; try { cod = Convert.ToInt32(txtcode.Text.Trim()); if (txtcode.Text.Trim().Length == 6) { Int16 val = Convert.ToInt16(dropDept.SelectedIndex); String _name = txtname.Text.Trim(); String _des = txtdesi.Text.Trim(); String dep_name = Convert.ToString(dropDept.Items[val]); CsEmployee test = new CsEmployee(); // call the function validate which is in the class CSemployee in order //to verify if the typed code already exist within the database if yes the the program //display a message error bool result = test.validateEmpCode(cod); if (!result) { errorDuplicate.Visible = false; CsEmployee obj = new CsEmployee(cod, _name, _des, dep_name); obj.AddEmployee(); txtcode.Text = ""; txtdesi.Text = ""; txtname.Text = ""; succes.Text = "Information has been succesfully saved"; succes.Visible = true; updateTimer(); populate_drp(); } else { errorDuplicate.Visible = true; errorDuplicate.Text = "Employee code already exists.Please re-enter employee code"; txtcode.Focus(); succes.Visible = false; } } else { errorDuplicate.Text = "Employee Code Must be 6 digits long without space and special characters."; txtcode.Focus(); succes.Visible = false; errorDuplicate.Visible = true; } } catch { errorDuplicate.Visible = true; errorDuplicate.Text = "Please Use only Numeric values without space and special characters for employee code"; txtcode.Focus(); succes.Visible = false; } }
protected void btnFind_Click(object sender, EventArgs e) { CsEmployee emp = new CsEmployee(); //The program find the previous information about the employee enable the update button //once the employee has been found the program display his/her information then allow //the user to make an update #region "Find previous information about the employee" try { Int32 needeedCd = Convert.ToInt32(txtcode.Text); if (txtcode.Text.Length == 6) { bool result = emp.validateEmpCode(needeedCd); if (!result) { succes.Text = "Employee code not found! "; btnUpdate.Enabled = false; errorDeptDuplicated.Visible = false; succes.Visible = true; } else { //call the the methode getEmployee with then class CsEmployee which retrieve information //about the employee whose the code correspond to the one typed in the textbox employee code errorDeptDuplicated.Visible = false; succes.Visible = false; emp.getEmployee(Convert.ToInt32(txtcode.Text)); txtname.Text = emp._Name; txtdesi.Text = emp._Designation; txtdept.Text = emp._deptName; btnUpdate.Enabled = true; txtcode.Enabled = false; } } else { //validate that the employee code typed by the user is 6 digits long //otherwise it displays an appropriate error message to the user. errorDeptDuplicated.Text = "Employee code should be 6 digits long without space and special characters."; txtcode.Focus(); errorDeptDuplicated.Visible = true; btnUpdate.Enabled = false; succes.Visible = false; } } catch { //verify that the user has typed only numeric values for thr employee code errorDeptDuplicated.Text = "Please Use only Numeric values without space and special characters for employee code"; txtcode.Focus(); errorDeptDuplicated.Visible = true; succes.Visible = false; } #endregion }
protected void btnFind_Click(object sender, EventArgs e) { txtdept.Text = ""; txtname.Text = ""; txtyears.Text = ""; txtdesi.Text = ""; CsEmployee objEmp = new CsEmployee(); try { if (txtcode.Text.Length == 6) { Int32 num = Convert.ToInt32(txtcode.Text.Trim()); bool result = objEmp.validateEmpCode(num); if (!result) { notFound.Visible = true; notFound.Text = "Employee code not found! "; } else { //After the Business logic has searched the datasource it retrieve information //for the corresponded employee code. notFound.Visible = false; objEmp.getEmployee(num); txtname.Text = objEmp._Name; txtdesi.Text = objEmp._Designation; txtdept.Text = objEmp._deptName; txtyears.Text = objEmp._yearsOfService.ToString(); } } else { //retrieves an error message when the user has typed an employee code less or greater than //6 digits long. notFound.Text = "Employee code should be 6 digits long without space and special characters."; notFound.Visible = true; } } catch { //retrieve an error message when a user has typed letter in the employee code textbox //while doing a search operation notFound.Text = "Incorrect Employee Code! Please Use only Numeric values without space and special characters for employee code"; txtcode.Focus(); } }
protected void btnFind_Click(object sender, EventArgs e) { CsEmployee objEmp = new CsEmployee(); bool flag; try { Int32 _codeofEmp=Convert.ToInt32(txtcode.Text.Trim()); flag = objEmp.validateEmpCode(_codeofEmp); if (flag) { btnDelete.Enabled = true; txtcode.Enabled = false; objEmp.getEmployee(_codeofEmp); notFound.Visible = false; txtdept.Text = objEmp._deptName; txtdesi.Text = objEmp._Designation; txtname.Text = objEmp._Name; txtyears.Text = objEmp._yearsOfService.ToString(); txtdept.Enabled = false; txtdesi.Enabled = false; txtname.Enabled = false; txtyears.Enabled = false; } else { notFound.Text = "Employee code not found!"; notFound.Visible = true; txtcode.Focus(); } } catch { notFound.Text = "Please Use only Numeric values without space and special characters for employee code"; txtcode.Focus(); } }
protected void btnFind_Click(object sender, EventArgs e) { CsEmployee objEmp = new CsEmployee(); bool flag; try { Int32 _codeofEmp = Convert.ToInt32(txtcode.Text.Trim()); flag = objEmp.validateEmpCode(_codeofEmp); if (flag) { btnDelete.Enabled = true; txtcode.Enabled = false; objEmp.getEmployee(_codeofEmp); notFound.Visible = false; txtdept.Text = objEmp._deptName; txtdesi.Text = objEmp._Designation; txtname.Text = objEmp._Name; txtyears.Text = objEmp._yearsOfService.ToString(); txtdept.Enabled = false; txtdesi.Enabled = false; txtname.Enabled = false; txtyears.Enabled = false; } else { notFound.Text = "Employee code not found!"; notFound.Visible = true; txtcode.Focus(); } } catch { notFound.Text = "Please Use only Numeric values without space and special characters for employee code"; txtcode.Focus(); } }
protected void btnUpdate_Click(object sender, EventArgs e) { //This button is enabled only if the find button has been clicked and the employee code typed by the user //has been found in the database other wise it will remain disabled. CsEmployee emp = new CsEmployee(); csDepartment test = new csDepartment(); #region "verify that all textboxes have been completed" if (txtname.Text.Trim().Length < 1) { errorDeptDuplicated.Text = "Please Enter Correct name"; errorDeptDuplicated.Visible = true; txtname.Focus(); return; } if (txtdesi.Text.Trim().Length < 1) { errorDeptDuplicated.Text = "Please Enter Correct designation"; errorDeptDuplicated.Visible = true; txtdesi.Focus(); return; } if (txtdept.Text.Trim().Length < 1) { errorDeptDuplicated.Text = "Please Enter Correct departement"; errorDeptDuplicated.Visible = true; txtdept.Focus(); return; } #endregion #region "Update employee information" //update information of the employee found when the button find was clicked try { Int32 emp_code = Convert.ToInt32(txtcode.Text); String xCodD = txtdept.Text.Trim().ToUpper(); bool validated = test.validateDept(xCodD); if (!validated) { errorDeptDuplicated.Visible = true; errorDeptDuplicated.Text = "Invalid Department.Please eneter valid Department name \n[SALES, IT, FINANCE, MARKETING, PURCHASING] "; succes.Visible = false; } else { String xName = txtname.Text.Trim(); String xDesi = txtdesi.Text.Trim(); errorDeptDuplicated.Visible = false; emp.Update(emp_code, xName, xDesi, xCodD); succes.Text = "Information has been succesfully updated"; succes.Visible = true; txtcode.Text = ""; txtdept.Text = ""; txtdesi.Text = ""; txtname.Text = ""; txtcode.Enabled = true; txtcode.Focus(); btnUpdate.Enabled = false; updateTimer(); } } catch { errorDeptDuplicated.Visible = true; errorDeptDuplicated.Text = "Incorrect Employee Number!"; } #endregion }