/// <summary> /// This event function runs when the add user button is pressed on the UI screen. It collects the data the user has inputted into the fields /// and then creates an SQL statement from that data. It then checks if the user already exitst and then runs the SQL function to /// add it to the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void addMemberSubmitButton_Click(object sender, EventArgs e) { //Get all employee details string firstName = firstNameTextBox.Text; string lastName = lastNameTextBox.Text; string DOB = dateOfBirthTextBox.Text; string salary = salaryTextBox.Text; string gender = genderDDL.Text; //Create the appropriate SQL statements string sqlInsert = createInsertString(firstName, lastName, DOB, salary, gender); string selectString = createSelectString(firstName, lastName); bool doesEmployeeExists = SQLAdapter.checkIfRecordExists(selectString); //If employee already exists in our database let user know if (doesEmployeeExists) { ((Label)Master.FindControl("validationLablel")).Text = "This user already exists in our Database"; } else { try { //Try insert data into the database and provide a message to let the user know SQLAdapter.ChangeDBData(sqlInsert); ((Label)Master.FindControl("validationLablel")).Text = "Member added successfully"; UpdateMembershipClass.updateMembershipClass(); firstNameTextBox.Text = ""; lastNameTextBox.Text = ""; dateOfBirthTextBox.Text = ""; salaryTextBox.Text = ""; genderDDL.Text = ""; } catch (SqlException ex) { ((Label)Master.FindControl("validationLablel")).Text = ex.Errors.ToString(); } catch (Exception) { ((Label)Master.FindControl("validationLablel")).Text = "An Unexpected error has occured adding a member"; } finally { } } }
/// <summary> /// Run the migration of 500 emplopyees /// </summary> /// <param name="sender"></param> /// <param name="e"></param> //protected void migrate(object sender, EventArgs e) //{ // //First Add the first 500 employee // csv.readEmployee(); //} /// <summary> /// This will update the membership details for every employee. Only used when initially migrating the 500 employees /// </summary> /// <param name="sender"></param> /// <param name="e"></param> //protected void test(object sender, EventArgs e) //{ // UpdateMembershipClass.updateMembershipClass(); //} /// <summary> /// Used to migrate members to our databse from engineering db using ID /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void migrate_employee(object sender, EventArgs e) { string id = memberShipIDTextBox.Text; try { string[] employeeDeatils = csv.getEmployeebyID(id); string selectString = createSelectString(employeeDeatils[2], employeeDeatils[3]); bool doesEmployeeExists = SQLAdapter.checkIfRecordExists(selectString); //If employee already exists in our database let user know if (doesEmployeeExists) { ((Label)Master.FindControl("validationLablel")).Text = "This user already exists in our Database"; } else { //Get salary of employee by ID string salary = csv.FindSalaryByID(employeeDeatils[0]); //Create string to insert string sqlInsert = createInsertString(employeeDeatils[2], employeeDeatils[3], employeeDeatils[1], salary, employeeDeatils[4]); try { SQLAdapter.ChangeDBData(sqlInsert); ((Label)Master.FindControl("validationLablel")).Text = "User successfully added"; } catch (Exception exception) { ((Label)Master.FindControl("validationLablel")).Text = exception.Message.ToString(); } } } catch (ArgumentOutOfRangeException exception) { ((Label)Master.FindControl("validationLablel")).Text = exception.Message.ToString(); } }