Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @FXML
- void submitUser(ActionEvent event) throws SQLException {
- if(errorChecking() == true){//puts data through error checking before doing anything with it - avoids/handles exceptions
- //create user object
- newUser user = new newUser();
- //---Begin Anna 1---------------------------------------------------------------------------------------------
- //create string to concat the createdby and createdby ID number together
- String createdIDandName = "";
- //---End Anna 1-----------------------------------------------------------------------------------------------
- //set values from the GUI
- user.setName(tfName.getText());
- user.setRole(((Labeled) roleGroup.getSelectedToggle()).getText().toString());
- user.setPassword(tfPass.getText());
- user.setCreateDate(today);
- //---Begin Anna 2---------------------------------------------------------------------------------------------
- //concatenates the logged on user's ID and name togther and sets this for the createdBY in the database- Anna
- createdIDandName = loginController.loggedOnUser.getName() + ", " + loginController.loggedOnUser.getID();
- user.setCreatedBy(createdIDandName);
- //---End Anna 2-----------------------------------------------------------------------------------------------
- try {
- //get the unique ID
- user.setID(createUserID(roleGroup.getSelectedToggle().getUserData().toString()));
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- //print out the user created
- System.out.println("User: " + user);
- //send into database
- //create query to send appt in db
- String newUserQuery = "INSERT INTO `Users`(`idNum`, `password`, `role`, `FullName`, `CreatedBy`, `CreatedDate`) VALUES (?,?,?,?,?,?)";
- //try to connect to db
- try (
- PreparedStatement createUser = conn.prepareStatement(newUserQuery,Statement.RETURN_GENERATED_KEYS);)
- {
- //set info into the query
- createUser.setString(1, user.getID());
- createUser.setString(2, user.getPassword());
- createUser.setString(3, user.getRole());
- createUser.setString(4, user.getName());
- createUser.setString(5, user.getCreatedBy());
- createUser.setString(6, user.getCreateDate());
- //print query
- System.out.println("Query Sent " + createUser.toString());
- //pass the query in
- createUser.executeUpdate();
- }catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }//end catch
- /* ================================================================================================
- * @author Danni
- * ==============================================================================================*/
- try{
- //creates alert of the information type - default: OK button and i image
- Alert idNum = new Alert(AlertType.INFORMATION);
- //needed in order to add css to the box
- DialogPane dialogPane = idNum.getDialogPane();
- //css for ID number alert box
- //--Anna, made sure it works with the new style sheets
- dialogPane.getStylesheets().add(
- getClass().getResource("/application/application.css").toExternalForm());
- //--Anna
- idNum.setTitle("Auto-Generated ID Number");
- //in box itself
- idNum.setHeaderText("ID Number: " + user.getID() + "\n" + "Password: " + user.getPassword());
- idNum.setContentText("New user created! " + user.getName() + " now has access to the Mentcare system.");
- //displays the alert box
- Optional<ButtonType> result = idNum.showAndWait();
- if(result.get() == ButtonType.OK){
- //clears current data so the user can create more new users without having to leave the page
- stage = (Stage) ((Button) event.getSource()).getScene().getWindow();
- root = FXMLLoader.load(getClass().getResource("/view/addUserView.fxml"));
- scene = new Scene(root);
- stage.setScene(scene);
- }
- }catch(Exception e){
- e.getMessage();
- }
- //=================================================================================================
- }else{
- System.out.println("Failed error checking.");
- }
- }//end method
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement