From 4cbfec7090e76bdfe83497c38112ca41eb5fc5d0 Mon Sep 17 00:00:00 2001 From: esoe Date: Wed, 4 May 2022 14:01:58 +0300 Subject: [PATCH] curr --- doc/anyreport.puml | 41 +++++++++++++++-------- src/Access.java | 42 ++++++++++++++++++++++++ src/AccessPane.java | 75 +++++++++++++++++++++++++++++++++++++++++++ src/App.java | 11 ++++++- src/Base.java | 68 ++++++++++++++------------------------- src/BaseControls.java | 18 +++++++++++ src/Data.java | 3 ++ 7 files changed, 199 insertions(+), 59 deletions(-) create mode 100644 src/Access.java create mode 100644 src/AccessPane.java create mode 100644 src/BaseControls.java create mode 100644 src/Data.java diff --git a/doc/anyreport.puml b/doc/anyreport.puml index 9eccf38..24b4f32 100644 --- a/doc/anyreport.puml +++ b/doc/anyreport.puml @@ -10,6 +10,9 @@ package moodle-anyreport{ 'панель подключения к базе данных class AccessPane{} AccessPane --> App + 'панель просмотра базы данных (аналог phpmyadmin) + class BasePane{} + BasePane --> App 'панель управления тегами для формирования выборки пользователей class TagPane{} TagPane --> App @@ -20,7 +23,7 @@ package moodle-anyreport{ /'методы обработки действий пользователя клики мыши, нажатия клавишь, итд. '/ - class TagControls{ + class TagControls <>{ + enterPressed() : void + addTag() : void + removeTag() : void @@ -28,14 +31,9 @@ package moodle-anyreport{ } TagControls --> TagPane - class AccessControls{ - + connect(Base base, JPanel pane) : void - + disconnect(Base base, JPanel pane) : void - } - AccessControls --> AccessPane 'Пользователь попросил сохранить отчет в файл 'Указывает путь куда сохранить - class ReportControls{ + class ReportControls <>{ - path : String + getTableReport() : void + getXLSXReport() : void @@ -64,15 +62,24 @@ package moodle-anyreport{ class ReportTableModel{} ReportTableModel --> ReportControls + /'Общий инструментарий работы с базой данных + '/ + class BaseControls <>{ + + connectToServer() : void + + disconnectFromServer() : void + + showBaseList() : void + + selectCurrentBase() : void + + showTables() : void + } + BaseControls --> AccessPane + BaseControls --> BasePane /' получение данных из базы данных доступ к базе данных '/ class Base{ + - access : Access - connection : Connection - - login : String - - password : String - - link : String + setConnection(Connection connaction) : void + getConnaction() : Connaction + connect(Base b) : void @@ -82,7 +89,13 @@ package moodle-anyreport{ } Base --> Data - Base --> AccessControls + Base --> BaseControls + enum Access{ + - login : String + - password : String + - link : String + } + Access --> Base ' хранение и представление данных class Data{ @@ -106,14 +119,14 @@ package moodle-anyreport{ } UserListModel --> Data - class User{ + enum User{ - id : int - login : String - mail : String } User --> UserListModel - class Result{ + enum Result{ - id : int - quizid : int - userid : int @@ -122,7 +135,7 @@ package moodle-anyreport{ } Result --> Data - class Quiz{ + enum Quiz{ - id : int - name : String } diff --git a/src/Access.java b/src/Access.java new file mode 100644 index 0000000..d0b3819 --- /dev/null +++ b/src/Access.java @@ -0,0 +1,42 @@ +public class Access { + private String link; + private String login; + private String password; + /** + * @param link the link to set + */ + public void setLink(String link) { + this.link = link; + } + /** + * @return the link + */ + public String getLink() { + return link; + } + /** + * @param login the login to set + */ + public void setLogin(String login) { + this.login = login; + } + /** + * @return the login + */ + public String getLogin() { + return login; + } + /** + * @param password the password to set + */ + public void setPassword(String password) { + this.password = password; + } + /** + * @return the password + */ + public String getPassword() { + return password; + } + +} diff --git a/src/AccessPane.java b/src/AccessPane.java new file mode 100644 index 0000000..e1e7e5d --- /dev/null +++ b/src/AccessPane.java @@ -0,0 +1,75 @@ +import javax.swing.JPanel; +import java.awt.Color; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JPasswordField; +import javax.swing.JTextField; +import javax.swing.WindowConstants; +import javax.swing.border.LineBorder; +import javax.swing.border.TitledBorder; + +//import ru.egspt.moodle.events.ConnactionListener; +//import ru.egspt.moodle.events.DisconnectionListener; + +public class AccessPane extends JPanel { + private JLabel loginLabel = new JLabel("Имя пользователя: "); + private JTextField loginField = new JTextField(25); + private JLabel passLabel = new JLabel("Пароль: "); + private JPasswordField passField = new JPasswordField(25); + private JLabel linkLabel = new JLabel("Адрес сервера: "); + private JTextField linkField = new JTextField(25); + private JButton connButton = new JButton("Подключиться"); + private JButton DisconnButton = new JButton("Отключиться"); + + public AccessPane(Base base){ + loginField.setText("esoe");//значения по умолчанию + linkField.setText("www.egspt.ru");//значения по умолчанию + this.add(loginLabel); + this.add(loginField); + this.add(passLabel); + this.add(passField); + this.add(linkLabel); + this.add(linkField); + this.add(connButton); + //настройка кнопки connButton + connButton.addActionListener(e -> BaseControls.ConnectToServer(base, this)); + this.add(DisconnButton); + DisconnButton.addActionListener(e -> BaseControls.DisconnectFromServer(base)); + TitledBorder border = new TitledBorder(new LineBorder(Color.black), "connection to mysql", TitledBorder.CENTER, TitledBorder.CENTER); + this.setBorder(border); + //this.setBorder(BorderFactory.createTitledBorder("аккаунт сервера базы данных")); + this.setSize(320, 240); + this.setVisible(true); + } + /** + * @return the loginField + */ + public JTextField getLoginField() { + return loginField; + } + /** + * @return the passField + */ + public JPasswordField getPassField() { + return passField; + } + /** + * @return the urlField + */ + public JTextField getLinkField() { + return linkField; + } + public static void main( String[] args ){ + Base base = new Base(); + //Data data; + System.out.println( "Проверка работоспособности класса Account ..." ); + JFrame mainframe = new JFrame("connaction"); + AccessPane acc = new AccessPane(base); + mainframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); + mainframe.add(acc); + mainframe.setSize(320, 240); + mainframe.setVisible(true); + } + +} diff --git a/src/App.java b/src/App.java index 7d1e6b3..8d3484a 100644 --- a/src/App.java +++ b/src/App.java @@ -6,19 +6,28 @@ import javax.swing.WindowConstants; * Основной класс сборки приложения */ public class App extends JPanel{ + public Base base = new Base(); + public Data data; + public void init(){ + this.add(new AccessPane(base)); + this.setVisible(true); + } + public void initFrame(){ JFrame mainframe = new JFrame("mainframe"); mainframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); mainframe.add(this); mainframe.setSize(640, 480); mainframe.setVisible(true); - mainframe.setExtendedState(mainframe.MAXIMIZED_BOTH); + //mainframe.setExtendedState(mainframe.MAXIMIZED_BOTH); } public static void main( String[] args ) { System.out.println( "Работает подготовщик отчетов по результатам тестирования пользователей ..." ); App anyreport = new App(); + anyreport.initFrame(); anyreport.init(); + } } diff --git a/src/Base.java b/src/Base.java index 8b3ff50..f75abd4 100644 --- a/src/Base.java +++ b/src/Base.java @@ -2,71 +2,51 @@ import java.sql.Connection; import java.sql.DriverManager; public class Base { - private Connection connection; - private String link; - private String login; - private String password; + private Connection connection = null; + private Access access = new Access(); //request //response - Base(String link, String login, String password){ - setLink(link); - setLogin(login); - setPassword(password); - } - /** - * @param connection the connection to set - */ - public void setConnection(Connection connection) { - this.connection = connection; - } - /** - * @return the connection - */ - public Connection getConnection() { - return connection; + Base(){ + getAccess().setLink("link"); + getAccess().setLogin("login"); + getAccess().setPassword("password"); } - /** - * @param link the link to set - */ - public void setLink(String link) { - this.link = link; - } - /** - * @return the link - */ - public String getLink() { - return link; + Base(String link, String login, String password){ + getAccess().setLink(link); + getAccess().setLogin(login); + getAccess().setPassword(password); } /** - * @param login the login to set + * @param access the access to set */ - public void setLogin(String login) { - this.login = login; + public void setAccess(Access access) { + this.access = access; } /** - * @return the login + * @return the access */ - public String getLogin() { - return login; + public Access getAccess() { + return access; } /** - * @param password the password to set + * @param connection the connection to set */ - public void setPassword(String password) { - this.password = password; + public void setConnection(Connection connection) { + this.connection = connection; } /** - * @return the password + * @return the connection */ - public String getPassword() { - return password; + public Connection getConnection() { + return connection; } + //подключение к базе public void connect(){ System.out.println("Подключение к серверу баз данных ..."); Connection conn = null; try{ - conn = DriverManager.getConnection (getLink(), getLogin(), getPassword()); + conn = DriverManager.getConnection (getAccess().getLink(), getAccess().getLogin(), getAccess().getPassword()); System.out.println ("Подключение к серверу баз данных установлено ... "); } catch (Exception ex){ diff --git a/src/BaseControls.java b/src/BaseControls.java new file mode 100644 index 0000000..cf18da6 --- /dev/null +++ b/src/BaseControls.java @@ -0,0 +1,18 @@ + +public class BaseControls { + // + public static void ConnectToServer(Base base, AccessPane accessPane){ + System.out.println("Инициировано событие ConnectToServer ..."); + String link = accessPane.getLinkField().getText(); + base.getAccess().setLink(link); + String login = accessPane.getLoginField().getText(); + base.getAccess().setLogin(login); + String password = String.valueOf(accessPane.getPassField().getPassword()); + base.getAccess().setPassword(password); + base.connect();//подключиться к базе + } + public static void DisconnectFromServer(Base base){ + System.out.println("Инициировано событие DisconnectFromServer ..."); + base.disconnect(); + } +} diff --git a/src/Data.java b/src/Data.java new file mode 100644 index 0000000..b228498 --- /dev/null +++ b/src/Data.java @@ -0,0 +1,3 @@ +public class Data { + +}