add: create worker account on first launch

This commit is contained in:
Johannes Kantz 2023-02-04 18:49:22 +01:00
parent b37cd2ad38
commit cd8e4c9b3d
4 changed files with 42 additions and 13 deletions

View File

@ -4,21 +4,30 @@ import java.util.ArrayList;
import java.util.List;
/**
* one constructor is used to create new parents the other is used to create existing parents from database
* one constructor is used to create new parents the other is used to create
* existing parents from database
*
* @author Malte Schulze Hobeling
*/
public class Parent extends User{
public class Parent extends User {
List<Child> children;
public Parent(long id, String name, String firstname, String password, String email, Address address, List<Child> children) {
public Parent(long id, String name, String firstname, String password, String email, Address address,
List<Child> children) {
super(id, name, firstname, password, email, address);
this.children = children;
}
public Parent(String name, String firstname, String password, String email, Address address) {
super(name, firstname, password, email, address);
this.children = new ArrayList<>();
}
public Parent(User user) {
super(user.getId(), user.getName(), user.getFirstname(), user.getPassword(), user.getEmail(), user.getAddress());
this.children = new ArrayList<>();
}
public List<Child> getChildren() {
return children;
}

View File

@ -4,14 +4,11 @@
package com.bib.essensbestellungsverwaltung;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import java.io.IOException;
import java.util.HashMap;
public class SingUpController {
@FXML
@ -74,9 +71,24 @@ public class SingUpController {
}else {
Address newAdresse = new Address(strasse,hausnummer,plz,stadt);
User newUser = new User(name,vorname,passwort,email,newAdresse);
long creatNewUser = AccountMgr.createUser(newUser);
if (creatNewUser > 0){
alert = new Alert(Alert.AlertType.CONFIRMATION,"Ihrer Daten wurde gespeichert.");
if(StartViewApplication.firstLaunch){
long id = AccountMgr.createWorker(new Worker(newUser));
if(id < 1) {
Alert a = new Alert(Alert.AlertType.ERROR,"Es ist ein Fehler bei der Erstellung Ihres Accounts aufgetreten.");
a.showAndWait();
return;
}
alert = new Alert(Alert.AlertType.CONFIRMATION,"Mitarbeiter Account erfolgreich erstellt");
alert.showAndWait();
StartViewApplication.firstLaunch = false;
}else {
long id = AccountMgr.createParent(new Parent(newUser));
if(id < 1) {
Alert a = new Alert(Alert.AlertType.ERROR,"Es ist ein Fehler bei der Erstellung Ihres Accounts aufgetreten.");
a.showAndWait();
return;
}
alert = new Alert(Alert.AlertType.CONFIRMATION,"Eltern Account erfolgreich erstellt");
alert.showAndWait();
}
tfName.setText("");

View File

@ -15,10 +15,11 @@ import java.io.IOException;
public class StartViewApplication extends Application {
public static Stage primary;
public static boolean firstLaunch;
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(StartViewApplication.class.getResource("login-view.fxml"));
FXMLLoader fxmlLoader = new FXMLLoader(StartViewApplication.class.getResource((firstLaunch) ? "signUp-view.fxml" : "login-view.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 1300, 750);
primary = stage;
stage.setTitle("Essen Bestellung im Kindergarten");
@ -29,7 +30,7 @@ public class StartViewApplication extends Application {
}
public static void main(String[] args) {
Database.init();
firstLaunch = Database.init();
Database.createDb();
Database.fillDb();
//Database.printSampleQuery();

View File

@ -1,14 +1,21 @@
package com.bib.essensbestellungsverwaltung;
/**
* one constructor is used to create new worker the other is used to create existing worker from database
* one constructor is used to create new worker the other is used to create
* existing worker from database
*
* @author Malte Schulze Hobeling
*/
public class Worker extends User{
public class Worker extends User {
public Worker(long id, String name, String firstname, String password, String email, Address address) {
super(id, name, firstname, password, email, address);
}
public Worker(String name, String firstname, String password, String email, Address address) {
super(name, firstname, password, email, address);
}
public Worker(User user) {
super(user.getId(), user.getName(), user.getFirstname(), user.getPassword(), user.getEmail(), user.getAddress());
}
}