Développer une base de données de lecteurs multimédias pour organiser la musique comme iTunes

Description du domaine



Le sujet est un lecteur multimédia similaire à iTunes. Les principales entités de cette base de données sont l'utilisateur et la collection de compositions.



Chaque chanson appartient à un seul artiste et à un seul album, mais de nombreux utilisateurs peuvent les ajouter. Chaque utilisateur peut ajouter un nombre illimité de chansons.



Chaque utilisateur doit disposer d'un mail et d'un mot de passe uniques qui peuvent être répétés, grâce à ces informations, l'utilisateur peut se connecter à son compte. De plus, les champs suivants sont obligatoires pour les utilisateurs lors de l'inscription: nom, numéro de téléphone, pays de résidence, date de début d'abonnement et date de fin d'abonnement. Après une connexion correcte ou une inscription réussie, l'utilisateur est dirigé vers la page principale, où l'utilisateur est présenté avec une sélection de morceaux de différents artistes, parmi lesquels il peut choisir ceux qu'il aime et les ajouter à sa playlist. Le nombre de pistes ajoutées n'est pas limité. Chaque utilisateur a son propre compte personnel, dans lequel il peut voir la musique ajoutée, la supprimer, et il existe également une option pour afficher les données personnelles de l'utilisateur saisies par lui lors de son inscription.L'utilisateur peut à tout moment supprimer son compte ainsi que tout son contenu et ses données du système.



Construire un modèle logique



En utilisant la description du domaine, nous avons construit un modèle logique



image



Remarque
-- «USERS» «TRACK LIST» «SUBSCRIPTION VALIDITY», .



.





Construire un modèle relationnel



Le modèle logique a été converti en modèle relationnel à l'aide d'Oracle SQL Developer Data Modeler



image



Conformité aux formes normales



Toutes les tables de ce modèle correspondent à 1NF, car tous les attributs n'ont qu'une seule valeur pour chaque enregistrement, ce qui exclut la multiplicité.



Toutes les tables sont dans la deuxième forme normale, puisque chaque attribut non clé dépend de manière irréductible d'une clé primaire.



Toutes les tables sont sous la troisième forme normale, car chaque attribut non clé dépend de manière non transitoire de la clé primaire. Il n'y a aucune dépendance d'un attribut non clé à un autre attribut non clé.



Toutes les tables correspondent à NFBC, car les déterminants de toutes les dépendances fonctionnelles sont des clés potentielles.



Explication des dépendances fonctionnelles
image





Création de bases de données et d'applications



La base de données est créée sur le serveur phpMyAdmin local. Le résultat du programme est présenté ci-dessous:



image



Pages disponibles
/



image







image







image







image







image





Tester le programme



Test de la réaction de l'application aux entrées attendues et test de la santé des boutons



Vérifions l'exactitude de la réaction de l'application aux données d'entrée attendues + l'opérabilité de tous les champs, boutons et listes déroulantes.



Vérification de l'exactitude de l'enregistrement des utilisateurs
image







image



Vérifiez que le bouton Ajouter de la musique à la bibliothèque utilisateur fonctionne correctement
«FALSE ALARM by THE WEEKND»



image



«FALSE ALARM by THE WEEKND»



image



«FALSE ALARM by THE WEEKND» «TRACK LIST» 32



image



«MY MUSIC», 32



image



Vérifier si le bouton pour supprimer la musique de la bibliothèque de l'utilisateur fonctionne correctement
«FALSE ALARM by THE WEEKND»



image



«FALSE ALARM by THE WEEKND»



image



«MY MUSIC», 32



image



32 «TRACK LIST»



image



Vérifier si le bouton de tri de la musique par artiste fonctionne correctement
«MUSE»



image



«KASABIAN»



image



Vérification du bon fonctionnement du bouton de suppression d'un compte utilisateur du système
«ivanivanov@mail.ru»



image







image



«Delete user from system»



image



«USERS», 18





Test de la réponse de l'application à une entrée erronée



Lors de la saisie de données incorrectes, le programme en informe l'utilisateur



Erreur de saisie de nom incorrecte
image



Erreur de saisie d'e-mail non valide
image



Erreur de saisie de numéro de téléphone incorrect
image



Une erreur qui se produit lors de la tentative de duplication des informations d'identification d'un utilisateur existant
image



Une erreur qui se produit lors de la tentative de saisie des informations d'identification d'un utilisateur inexistant
image





Tout fonctionne pour la saisie de données attendue. Pour l'absence d'entrée et pour une entrée incorrecte, le programme émet un avertissement



Applications



Annexe 1 - code de création de tableaux



Code de création de tables dans Oracle Data Modeler
-- Generated by Oracle SQL Developer Data Modeler 19.4.0.350.1424
--   at:        2020-06-01 16:18:08 MSK
--   site:      Oracle Database 11g
--   type:      Oracle Database 11g

CREATE TABLE albums (
    id            VARCHAR2(5) NOT NULL,
    album_name    VARCHAR2(20) NOT NULL,
    release_year  DATE NOT NULL,
    genre         VARCHAR2(20) NOT NULL
);

ALTER TABLE albums ADD CONSTRAINT albums_pk PRIMARY KEY ( id );

CREATE TABLE my_music (
    user_id    VARCHAR2(5) NOT NULL,
    my_msc_id  NUMBER NOT NULL
);

CREATE UNIQUE INDEX my_music__idx ON
    my_music (
        user_id
    ASC );

ALTER TABLE my_music ADD CONSTRAINT my_msc_pk PRIMARY KEY ( my_msc_id );

CREATE TABLE performers (
    id              VARCHAR2(5) NOT NULL,
    performer_name  VARCHAR2(30) NOT NULL
);

ALTER TABLE performers ADD CONSTRAINT performers_pk PRIMARY KEY ( id );

CREATE TABLE subscription_validity (
    "Start_Date/_Start_Time"  DATE NOT NULL,
    "End_Date/_End_Time"      DATE NOT NULL,
    user_id                   VARCHAR2(5) NOT NULL,
    track_list_id             VARCHAR2(5) NOT NULL
);

ALTER TABLE subscription_validity ADD CONSTRAINT subscription_validity_pk PRIMARY KEY ( user_id,
                                                                                        track_list_id );

CREATE TABLE songs (
    id                  VARCHAR2(5) NOT NULL,
    track_name          VARCHAR2(50) NOT NULL,
    genre               VARCHAR2(20) NOT NULL,
    duration            TIMESTAMP NOT NULL,
    albums_id           VARCHAR2(5) NOT NULL,
    performers_id       VARCHAR2(5) NOT NULL,
    my_music_my_msc_id  NUMBER NOT NULL
);

ALTER TABLE track_list ADD CONSTRAINT track_list_pk PRIMARY KEY ( id );

CREATE TABLE "USER" (
    id                  VARCHAR2(5) NOT NULL,
    password            VARCHAR2(20) NOT NULL,
    name                VARCHAR2(30) NOT NULL,
    email               VARCHAR2(30) NOT NULL,
    phone_number        VARCHAR2(12) NOT NULL,
    country             VARCHAR2(20) NOT NULL,
    balance             NUMBER(7, 2),
    my_music_my_msc_id  NUMBER NOT NULL
);

CREATE UNIQUE INDEX user__idx ON
    "USER" (
        my_music_my_msc_id
    ASC );

ALTER TABLE "USER" ADD CONSTRAINT user_pk PRIMARY KEY ( id );

ALTER TABLE my_music
    ADD CONSTRAINT my_music_user_fk FOREIGN KEY ( user_id )
        REFERENCES "USER" ( id );

ALTER TABLE subscription_validity
    ADD CONSTRAINT subs_val_track_list_fk FOREIGN KEY ( track_list_id )
        REFERENCES track_list ( id );

ALTER TABLE subscription_validity
    ADD CONSTRAINT subs_val_user_fk FOREIGN KEY ( user_id )
        REFERENCES "USER" ( id );

ALTER TABLE track_list
    ADD CONSTRAINT track_list_albums_fk FOREIGN KEY ( albums_id )
        REFERENCES albums ( id );

ALTER TABLE track_list
    ADD CONSTRAINT track_list_my_music_fk FOREIGN KEY ( my_music_my_msc_id )
        REFERENCES my_music ( my_msc_id );

ALTER TABLE track_list
    ADD CONSTRAINT track_list_performers_fk FOREIGN KEY ( performers_id )
        REFERENCES performers ( id );

ALTER TABLE "USER"
    ADD CONSTRAINT user_my_music_fk FOREIGN KEY ( my_music_my_msc_id )
        REFERENCES my_music ( my_msc_id );

CREATE SEQUENCE my_msc_my_msc_id_seq START WITH 1 NOCACHE ORDER;

CREATE OR REPLACE TRIGGER my_msc_my_msc_id_trg BEFORE
    INSERT ON my_music
    FOR EACH ROW
    WHEN ( new.my_msc_id IS NULL )
BEGIN
    :new.my_msc_id := my_msc_my_msc_id_seq.nextval;
END;
/

-- Oracle SQL Developer Data Modeler Summary Report: 
-- 
-- CREATE TABLE                             6
-- CREATE INDEX                             2
-- ALTER TABLE                             13
-- CREATE VIEW                              0
-- ALTER VIEW                               0
-- CREATE PACKAGE                           0
-- CREATE PACKAGE BODY                      0
-- CREATE PROCEDURE                         0
-- CREATE FUNCTION                          0
-- CREATE TRIGGER                           1
-- ALTER TRIGGER                            0
-- CREATE COLLECTION TYPE                   0
-- CREATE STRUCTURED TYPE                   0
-- CREATE STRUCTURED TYPE BODY              0
-- CREATE CLUSTER                           0
-- CREATE CONTEXT                           0
-- CREATE DATABASE                          0
-- CREATE DIMENSION                         0
-- CREATE DIRECTORY                         0
-- CREATE DISK GROUP                        0
-- CREATE ROLE                              0
-- CREATE ROLLBACK SEGMENT                  0
-- CREATE SEQUENCE                          1
-- CREATE MATERIALIZED VIEW                 0
-- CREATE MATERIALIZED VIEW LOG             0
-- CREATE SYNONYM                           0
-- CREATE TABLESPACE                        0
-- CREATE USER                              0
-- 
-- DROP TABLESPACE                          0
-- DROP DATABASE                            0
-- 
-- REDACTION POLICY                         0
-- 
-- ORDS DROP SCHEMA                         0
-- ORDS ENABLE SCHEMA                       0
-- ORDS ENABLE OBJECT                       0
-- 
-- ERRORS                                   0
-- WARNINGS                                 0







Annexe 2 - code de programme



Classe DataBase
package sample.database;

import javafx.event.ActionEvent;
import sample.model.Performers;
import sample.model.TrackList;
import sample.model.User;

import java.sql.*;
import java.util.ArrayList;

public class DataBase {

    public static void main(String[] args) {
        DataBase dataBase = new DataBase();
        for (TrackList t:dataBase.allMusic()
             ) {
            System.out.println(t.toString());
        }
    }
    //
    public boolean loginIn(String email, String password) {
        try {
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
            Statement stmt = conn.createStatement();
            //       (   )
            ResultSet rset = stmt.executeQuery("SELECT * FROM users u INNER JOIN subscription_validity s ON u.id_users=s.id_users where email = '" + email + "'&& password ='" + password + "'");
            if (rset.next()) {
                User.setId(rset.getInt(1));
                User.setName(rset.getString(3));
                User.setEmail(rset.getString(4));
                User.setPhone(rset.getString(5));
                User.setCountry(rset.getString(6));
                User.setStartDate(rset.getString(8));
                User.setEndDate(rset.getString(9));
                return true;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }


    public boolean emailCheck(String email) {
        try {
        	//   db
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
            //   Statement
            Statement stmt = conn.createStatement();
            //        
            ResultSet rset = stmt.executeQuery("select * from users where email = '" + email + "'");
            return !rset.next();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return true;
    }

    public void registration(String name, String email, String phone, String password, String country, String startDate, String endDate) {
        try {
        	//   db
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
            //   Statement
            Statement stmt = conn.createStatement();
            //       users  
            stmt.executeUpdate("insert into users (email,password,name,phone_num,contry) value ('" + email + "','" + password + "','" + name + "','" + phone + "','" + country + "')");
            //       subscription_validity
            stmt.executeUpdate("insert into subscription_validity (Start_Date_Start_Time, End_Date_End_Time,id_users) value ('" + startDate + "','" + endDate + "', (select max(id_users) from users) )");
            stmt.close();
            conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    //   
    public ArrayList<TrackList> allMusic() {
        ArrayList<TrackList> arrayList = new ArrayList<>();
        try {
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");

            Statement stmt = conn.createStatement();
            //           
            ResultSet rset = stmt.executeQuery("SELECT * FROM track_list t INNER JOIN performers p  ON p.id_performers=t.id_performers INNER JOIN albums a ON a.id_albums=t.id_albums");
            while (rset.next()) {
                arrayList.add(new TrackList(rset.getInt(1), rset.getString(2), rset.getString(10), rset.getString(8), rset.getString(3), rset.getString(4)));
            }
            rset.close();
            stmt.close();
            conn.close();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return arrayList;
    }

    //   
    public ArrayList<TrackList> myMusic(int id) {
        ArrayList<TrackList> arrayList = new ArrayList<>();
        try {
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");

            Statement stmt = conn.createStatement();
            //           
            ResultSet rset = stmt.executeQuery("SELECT m.id_track_list, t.track_name, " +
                    "a.album_name, p.performer_name, t.genre, t.duration FROM my_music m INNER JOIN " +
                    "track_list t ON t.id_track_list=m.id_track_list INNER JOIN performers p ON " +
                    "p.id_performers=t.id_performers INNER JOIN albums a ON a.id_albums=t.id_albums WHERE m.id_users=" + id);
            while (rset.next()) {
                arrayList.add(new TrackList(rset.getInt(1), rset.getString(2), rset.getString(3), rset.getString(4), rset.getString(5), rset.getString(6)));
            }
            rset.close();
            stmt.close();
            conn.close();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return arrayList;
    }

    public void addMyMusic(int idUser, int idTrackList) {
        try {
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
            Statement stmt = conn.createStatement();
            ResultSet rset = stmt.executeQuery("SELECT * FROM my_music WHERE " +
                    "id_users = " + idUser + " && id_track_list = " + idTrackList);
            //   id user,    
            //       
            if (!rset.next())
                stmt.executeUpdate("INSERT INTO my_music (id_users, id_track_list) VALUE ("+ idUser +", "+  idTrackList +")");
            rset.close();
            stmt.close();
            conn.close();
            //         
        } catch (SQLException e){
            e.printStackTrace();
        }
    }

    public void deleteMyMusic(int idUser, int idTrackList) {
        try {
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
            Statement stmt = conn.createStatement();
            stmt.executeUpdate("DELETE FROM my_music WHERE id_users =" + idUser + "&& id_track_list =" + idTrackList);
            stmt.close();
            conn.close();
        } catch (SQLException e){
            e.printStackTrace();
        }
    }
    //     
    public ArrayList<Performers> performers(){
        ArrayList<Performers> arrayList = new ArrayList();
        try {
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
            Statement stmt = conn.createStatement();
            ResultSet rset = stmt.executeQuery("SELECT * FROM performers");
            while(rset.next()){
                arrayList.add(new Performers(rset.getInt(1),rset.getString(2)));
            }
            rset.close();
            stmt.close();
            conn.close();
        } catch (SQLException e){
            e.printStackTrace();
        }
        return arrayList;
    }
    //      
    public ArrayList<TrackList> performerMusic(int id) {
        ArrayList<TrackList> arrayList = new ArrayList<>();
        try {
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");

            Statement stmt = conn.createStatement();
            //           
            ResultSet rset = stmt.executeQuery("SELECT * FROM track_list t INNER JOIN performers p  ON p.id_performers=t.id_performers INNER JOIN albums a ON a.id_albums=t.id_albums WHERE p.id_performers = " + id);
            while (rset.next()) {
                arrayList.add(new TrackList(rset.getInt(1), rset.getString(2), rset.getString(10), rset.getString(8), rset.getString(3), rset.getString(4)));
            }
            rset.close();
            stmt.close();
            conn.close();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return arrayList;
    }
    //    
    public void deleteUser(int idUser) {
        try {
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my_tunes", "root", "root");
            Statement stmt = conn.createStatement();
            stmt.executeUpdate("DELETE FROM users WHERE id_users =" + idUser);
            stmt.close();
            conn.close();
        } catch (SQLException e){
            e.printStackTrace();
        }
    }
}




Classe principale

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Modality;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/login.fxml"));
        Stage newStage = new Stage();
        newStage.setScene(new Scene(root));
        newStage.initModality(Modality.NONE);
        newStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}




Cours de musique

package sample;

import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ListView;
import javafx.stage.Modality;
import javafx.stage.Stage;
import sample.database.DataBase;
import sample.model.Performers;
import sample.model.TrackList;
import sample.model.User;

import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;

public class Music implements Initializable {
    @FXML
    public ListView<TrackList> allMusic;
    @FXML
    public ComboBox comboBox;
    @FXML
    public Button myMusic;

    DataBase dataBase = new DataBase();
    ArrayList<TrackList> arrayList;

    TrackList trackList = null;

    public void addMyMusic(ActionEvent actionEvent) {
    	//    " "
        if(trackList != null)
            dataBase.addMyMusic(User.getId(),trackList.getId());
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        arrayList = dataBase.allMusic();
        ObservableList<TrackList> observableList = FXCollections.observableList(arrayList);

        allMusic.setItems(observableList);
        allMusic.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TrackList>(){

            @Override
            public void changed(ObservableValue<? extends TrackList> observable, TrackList oldValue, TrackList newValue) {
                trackList = newValue;
            }
        });

        for (Performers p:dataBase.performers()
        ) {
            comboBox.getItems().add(p);
        }

        comboBox.getItems().add(new Performers(0,"All"));
        comboBox.setValue(new Performers(0,"All"));
        comboBox.valueProperty().addListener(new ChangeListener<Performers>() {

            @Override
            public void changed(ObservableValue<? extends Performers> observable, Performers oldValue, Performers newValue) {
                if(newValue.getId() == 0) {
                    arrayList = dataBase.allMusic();
                    ObservableList<TrackList> observableList = FXCollections.observableList(arrayList);
                    allMusic.setItems(observableList);
                } else{
                    arrayList = dataBase.performerMusic(newValue.getId());
                    ObservableList<TrackList> observableList = FXCollections.observableList(arrayList);
                    allMusic.setItems(observableList);
                }
            }
        });
    }

    public void myMusic(ActionEvent actionEvent) {
        Stage stage = (Stage) myMusic.getScene().getWindow();
        stage.close();
        try {
            Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/mymusic.fxml"));
            Stage newStage = new Stage();
            newStage.setScene(new Scene(root));
            newStage.initModality(Modality.NONE);
            newStage.show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}




Classe MyMusic

package sample;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.stage.Modality;
import javafx.stage.Stage;
import sample.database.DataBase;
import sample.model.TrackList;
import sample.model.User;

import javax.jws.soap.SOAPBinding;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;

public class MyMusic implements Initializable {
    @FXML
    public ListView allMusic;
    @FXML
    public Button back;
    @FXML
    public Button userData;
    DataBase dataBase = new DataBase();
    ArrayList<TrackList> arrayList;
    TrackList trackList = null;

    public void deleteMyMusic(ActionEvent actionEvent) {
        if(trackList != null)
            dataBase.deleteMyMusic(User.getId(),trackList.getId());

        arrayList = dataBase.myMusic(User.getId());
        ObservableList<TrackList> observableList = FXCollections.observableList(arrayList);

        allMusic.setItems(observableList);
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        arrayList = dataBase.myMusic(User.getId());
        ObservableList<TrackList> observableList = FXCollections.observableList(arrayList);

        allMusic.setItems(observableList);
        allMusic.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<TrackList>(){

            @Override
            public void changed(ObservableValue<? extends TrackList> observable, TrackList oldValue, TrackList newValue) {
                trackList = newValue;
            }
        });
    }

    public void userData(ActionEvent actionEvent) {
        Stage stage = (Stage) userData.getScene().getWindow();
        stage.close();
        try {
            Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/userdata.fxml"));
            Stage newStage = new Stage();
            newStage.setScene(new Scene(root));
            newStage.initModality(Modality.NONE);
            newStage.show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void back(ActionEvent actionEvent) {
        Stage stage = (Stage) back.getScene().getWindow();
        stage.close();
        try {
            Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/music.fxml"));
            Stage newStage = new Stage();
            newStage.setScene(new Scene(root));
            newStage.initModality(Modality.NONE);
            newStage.show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}




Classe d'inscription

package sample;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import sample.database.DataBase;


public class Registration {
    @FXML
    public Label error;
    @FXML
    public Button reg;
    @FXML
    public TextField phone;
    @FXML
    public PasswordField password;
    @FXML
    public PasswordField repeatPassword;
    @FXML
    public TextField name;
    @FXML
    public TextField email;
    @FXML
    public TextField endDate;
    @FXML
    public TextField startDate;
    @FXML
    public TextField country;

    public void registration(ActionEvent actionEvent) {
        DataBase dataBase = new DataBase();
        // String name,String email,String phone, String password, String country, String startDate, String endDate
        if(name.getText().matches("[a-zA-Zђ-Ї°-Џ]{3,}")){
                if(email.getText().matches("[A-Za-z0-9]{3,}[@][A-Za-z0-9]{3,}[.][A-Za-z0-9]{2,}")){
                    if(phone.getText().matches("[+][7][0-9]{10}") || phone.getText().matches("[8][0-9]{10}")){
                        if(dataBase.emailCheck(email.getText())){
                            if(password.getText().equals(repeatPassword.getText())){
                                dataBase.registration(name.getText(),email.getText(),
                                        phone.getText(),password.getText(),country.getText(), startDate.getText(), endDate.getText());
                                Stage stage = (Stage)reg.getScene().getWindow();
                                stage.close();
                            }else{
                                error.setText("  ");
                            }
                        }else{
                            error.setText("  ");
                        }
                    }else{
                        error.setText("    +7**********  8**********");
                    }
                }else{
                    error.setText(" emeail   ***@***.**");
                }
        }else{
            error.setText("  ");
        }
    }
}




Classe Userdata

package sample;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.stage.Modality;
import javafx.stage.Stage;
import sample.database.DataBase;
import sample.model.User;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

public class Userdata implements Initializable {
    @FXML
    public Label name;
    @FXML
    public Label email;
    @FXML
    public Label phone;
    @FXML
    public Label contry;
    @FXML
    public Label startDate;
    @FXML
    public Label endDate;
    @FXML
    public Button back;
    @FXML
    public Button delete;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        name.setText(User.getName());
        email.setText(User.getEmail());
        phone.setText(User.getPhone());
        contry.setText(User.getCountry());
        startDate.setText(User.getStartDate());
        endDate.setText(User.getEndDate());
    }

    public void back(ActionEvent actionEvent) {
        Stage stage = (Stage) back.getScene().getWindow();
        stage.close();
        try {
            Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/mymusic.fxml"));
            Stage newStage = new Stage();
            newStage.setScene(new Scene(root));
            newStage.initModality(Modality.NONE);
            newStage.show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void delete(ActionEvent actionEvent) {
        DataBase dataBase = new DataBase();
        dataBase.deleteUser(User.getId());

        Stage stage = (Stage) delete.getScene().getWindow();
        stage.close();
        try {
            Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/login.fxml"));
            Stage newStage = new Stage();
            newStage.setScene(new Scene(root));
            newStage.initModality(Modality.NONE);
            newStage.show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}




Classe d'interprètes

package sample.model;

public class Performers {
    private int id;
    private String name;

    public Performers(int id, String name) {
        this.id = id;
        this.name = name;
    }

    @Override
    public String toString() {
        return name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}




Classe TrackList

package sample.model;

public class TrackList {
    private int id;
    private String trackName;
    private String albumName;
    private String performerName;
    private String genre;
    private String duration;

    public TrackList(int id, String trackName, String albumName, String performerName, String genre, String duration) {
        this.id = id;
        this.trackName = trackName;
        this.albumName = albumName;
        this.performerName = performerName;
        this.genre = genre;
        this.duration = duration;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTrackName() {
        return trackName;
    }

    public void setTrackName(String trackName) {
        this.trackName = trackName;
    }

    public String getAlbumName() {
        return albumName;
    }

    public void setAlbumName(String albumName) {
        this.albumName = albumName;
    }

    public String getPerformerName() {
        return performerName;
    }

    public void setPerformerName(String performerName) {
        this.performerName = performerName;
    }

    public String getGenre() {
        return genre;
    }

    public void setGenre(String genre) {
        this.genre = genre;
    }

    public String getDuration() {
        return duration;
    }

    public void setDuration(String duration) {
        this.duration = duration;
    }

    @Override
    public String toString() {
        return
                trackName +
                " by " + performerName  +
                " from album - " + albumName +
                " (" + genre + ") " +
                ", " + duration;
    }


}




Classe d'utilisateurs

package sample.model;

public class User {
    private static int id;
    private static String name;
    private static  String email;
    private static String phone;
    private static String country;

    private static String startDate;
    private static String endDate;

    public static int getId() {
        return id;
    }

    public static void setId(int id) {
        User.id = id;
    }

    public static String getName() {
        return name;
    }

    public static void setName(String name) {
        User.name = name;
    }

    public static String getEmail() {
        return email;
    }

    public static void setEmail(String email) {
        User.email = email;
    }

    public static String getPhone() {
        return phone;
    }

    public static void setPhone(String phone) {
        User.phone = phone;
    }

    public static String getCountry() {
        return country;
    }

    public static void setCountry(String country) {
        User.country = country;
    }

    public static String getStartDate() {
        return startDate;
    }

    public static void setStartDate(String startDate) {
        User.startDate = startDate;
    }

    public static String getEndDate() {
        return endDate;
    }

    public static void setEndDate(String endDate) {
        User.endDate = endDate;
    }
}




Classe de connexion

package sample;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.stage.Modality;
import javafx.stage.Stage;
import sample.database.DataBase;

import java.io.IOException;

public class Login {
    @FXML
    public Button loginIn;
    @FXML
    public Button registration;
    @FXML
    public TextField email;
    @FXML
    public PasswordField password;
    @FXML
    public Label error;

    public void loginIn(ActionEvent actionEvent) {
        DataBase dataBase = new DataBase();
        if(email.getText() != null ){
            if(password.getText() != null){
                if(dataBase.loginIn(email.getText(), password.getText())){
                    Stage stage = (Stage) loginIn.getScene().getWindow();
                    stage.close();
                    try {
                        Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/music.fxml"));
                        Stage newStage = new Stage();
                        newStage.setScene(new Scene(root));
                        newStage.initModality(Modality.NONE);
                        newStage.show();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                } else {
                    error.setText("This Login or Password does not exist");
                }
            } else {
                error.setText("Please, enter your Password: ");
            }
        } else {
            error.setText("Please, enter your Login: ");
        }
    }

    public void registration(ActionEvent actionEvent) {
        try {
            Parent root = FXMLLoader.load(getClass().getResource("/sample/fxml/registration.fxml"));
            Stage newStage = new Stage();
            newStage.setScene(new Scene(root));
            newStage.initModality(Modality.NONE);
            newStage.show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}





All Articles