Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
428806c5b9 | ||
|
|
6dae70df05 | ||
|
|
0d02edec31 |
@@ -0,0 +1,16 @@
|
|||||||
|
package de.katho.kBorrow.controller;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.db.DbConnector;
|
||||||
|
|
||||||
|
public class RewriteToNewUserController {
|
||||||
|
|
||||||
|
private DbConnector dbCon;
|
||||||
|
|
||||||
|
public RewriteToNewUserController(DbConnector pDbCon){
|
||||||
|
dbCon = pDbCon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean rewriteToNewUser(int pOldId, int pNewId){
|
||||||
|
return dbCon.rewriteToNewUser(pOldId, pNewId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
package de.katho.kBorrow.controller;
|
package de.katho.kBorrow.controller;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.data.KLending;
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.db.DbConnector;
|
||||||
|
import de.katho.kBorrow.gui.RewriteToNewUserDialog;
|
||||||
|
import de.katho.kBorrow.models.LendingTableModel;
|
||||||
import de.katho.kBorrow.models.UserTableModel;
|
import de.katho.kBorrow.models.UserTableModel;
|
||||||
import de.katho.kBorrow.models.UserListModel;
|
import de.katho.kBorrow.models.UserListModel;
|
||||||
|
|
||||||
@@ -11,11 +15,13 @@ public class UserController {
|
|||||||
private DbConnector dbCon;
|
private DbConnector dbCon;
|
||||||
private UserTableModel userTableModel;
|
private UserTableModel userTableModel;
|
||||||
private UserListModel userListModel;
|
private UserListModel userListModel;
|
||||||
|
private LendingTableModel lendingTableModel;
|
||||||
|
|
||||||
public UserController(DbConnector pDbCon, HashMap<String, Object> pModels) {
|
public UserController(DbConnector pDbCon, HashMap<String, Object> pModels) {
|
||||||
dbCon = pDbCon;
|
dbCon = pDbCon;
|
||||||
userTableModel = (UserTableModel)pModels.get("usertablemodel");
|
userTableModel = (UserTableModel)pModels.get("usertablemodel");
|
||||||
userListModel = (UserListModel)pModels.get("userlistmodel");
|
userListModel = (UserListModel)pModels.get("userlistmodel");
|
||||||
|
lendingTableModel = (LendingTableModel)pModels.get("lendingtablemodel");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int createUser(String pName, String pSurname){
|
public int createUser(String pName, String pSurname){
|
||||||
@@ -38,16 +44,39 @@ public class UserController {
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean deleteUser(int pRow){
|
public boolean deleteUser(int pRow) {
|
||||||
int id = userTableModel.getUserByRow(pRow).getId();
|
int id = userTableModel.getUserByRow(pRow).getId();
|
||||||
|
|
||||||
if(dbCon.deleteUser(id)){
|
boolean isOccupied = false;
|
||||||
userTableModel.updateModel();
|
ArrayList<KLending> lendingList = lendingTableModel.getLendingList();
|
||||||
userListModel.updateModel();
|
for(KLending elem : lendingList){
|
||||||
|
if(elem.getUserId() == id){
|
||||||
return true;
|
isOccupied = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isOccupied){
|
||||||
|
RewriteToNewUserDialog dialog = new RewriteToNewUserDialog(id, dbCon);
|
||||||
|
if(dialog.getResult() == 0){
|
||||||
|
lendingTableModel.updateModel();
|
||||||
|
userTableModel.updateModel();
|
||||||
|
userListModel.updateModel();
|
||||||
|
|
||||||
|
return deleteUser(pRow);
|
||||||
|
}
|
||||||
|
else return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(dbCon.deleteUser(id)){
|
||||||
|
userTableModel.updateModel();
|
||||||
|
userListModel.updateModel();
|
||||||
|
lendingTableModel.updateModel();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,4 +24,6 @@ public interface DbConnector {
|
|||||||
public ArrayList<KLending> getActiveLendingList();
|
public ArrayList<KLending> getActiveLendingList();
|
||||||
public int returnLending(int lendingId, int artId, String string);
|
public int returnLending(int lendingId, int artId, String string);
|
||||||
public ArrayList<KLending> getLendingListForArticle(int pArtId);
|
public ArrayList<KLending> getLendingListForArticle(int pArtId);
|
||||||
|
public ArrayList<KUser> getRewriteUserList(int id);
|
||||||
|
public boolean rewriteToNewUser(int pOldId, int pNewId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,5 +104,17 @@ public class SqlConnector implements DbConnector{
|
|||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArrayList<KUser> getRewriteUserList(int id) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean rewriteToNewUser(int pOldId, int pNewId) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -206,6 +206,26 @@ public class SqliteConnector implements DbConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<KUser> getRewriteUserList(int id) {
|
||||||
|
ArrayList<KUser> userArr = new ArrayList<KUser>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Statement st = this.connection.createStatement();
|
||||||
|
String query = "SELECT id, name, surname FROM user WHERE id != "+id;
|
||||||
|
ResultSet rs = st.executeQuery(query);
|
||||||
|
|
||||||
|
while (rs.next()){
|
||||||
|
userArr.add(new KUser(rs.getInt("id"), rs.getString("name"), rs.getString("surname")));
|
||||||
|
}
|
||||||
|
|
||||||
|
return userArr;
|
||||||
|
}
|
||||||
|
catch (SQLException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<KArticle> getArticleList() {
|
public ArrayList<KArticle> getArticleList() {
|
||||||
ArrayList<KArticle> artArr = new ArrayList<KArticle>();
|
ArrayList<KArticle> artArr = new ArrayList<KArticle>();
|
||||||
|
|
||||||
@@ -432,19 +452,18 @@ public class SqliteConnector implements DbConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int createNewLender(String pLName, String pLSurname, String pLSN) {
|
public boolean rewriteToNewUser(int pOldId, int pNewId) {
|
||||||
try{
|
try {
|
||||||
Statement st = connection.createStatement();
|
Statement st = connection.createStatement();
|
||||||
String query = "INSERT into lender (name, surname, student_number) "
|
String query = "UPDATE lending SET user_id = '"+pNewId+"' WHERE user_id = '"+pOldId+"'";
|
||||||
+ "VALUES ('"+pLName+"', '"+pLSurname+"', '"+pLSN+"')";
|
|
||||||
|
|
||||||
st.executeUpdate(query);
|
st.executeUpdate(query);
|
||||||
|
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
catch(SQLException e){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return 1;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,5 +483,21 @@ public class SqliteConnector implements DbConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int createNewLender(String pLName, String pLSurname, String pLSN) {
|
||||||
|
try{
|
||||||
|
Statement st = connection.createStatement();
|
||||||
|
String query = "INSERT into lender (name, surname, student_number) "
|
||||||
|
+ "VALUES ('"+pLName+"', '"+pLSurname+"', '"+pLSN+"')";
|
||||||
|
|
||||||
|
st.executeUpdate(query);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch(SQLException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class ArticleInspectFrame extends JFrame {
|
|||||||
|
|
||||||
lblNewLabel_1.setBounds(10, 21, 100, 20);
|
lblNewLabel_1.setBounds(10, 21, 100, 20);
|
||||||
lblNewLabel_2.setBounds(10, 47, 100, 20);
|
lblNewLabel_2.setBounds(10, 47, 100, 20);
|
||||||
lblArticleName.setBounds(120, 21, 100, 20);
|
lblArticleName.setBounds(120, 21, 250, 20);
|
||||||
taArticleDesc.setBounds(120, 45, 250, 78);
|
taArticleDesc.setBounds(120, 45, 250, 78);
|
||||||
taArticleDesc.setEditable(false);
|
taArticleDesc.setEditable(false);
|
||||||
|
|
||||||
|
|||||||
105
src/de/katho/kBorrow/gui/RewriteToNewUserDialog.java
Normal file
105
src/de/katho/kBorrow/gui/RewriteToNewUserDialog.java
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
package de.katho.kBorrow.gui;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.controller.RewriteToNewUserController;
|
||||||
|
import de.katho.kBorrow.db.DbConnector;
|
||||||
|
import de.katho.kBorrow.models.RewriteUserModel;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
|
public class RewriteToNewUserDialog extends JDialog implements ActionListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -6002073589194176368L;
|
||||||
|
private final JPanel contentPanel = new JPanel();
|
||||||
|
|
||||||
|
private JButton okButton;
|
||||||
|
private JButton cancelButton;
|
||||||
|
private RewriteUserModel rwusermodel;
|
||||||
|
private RewriteToNewUserController rwcontroller;
|
||||||
|
|
||||||
|
private int result = 1;
|
||||||
|
private int oldId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the dialog.
|
||||||
|
*/
|
||||||
|
public RewriteToNewUserDialog(int pOldId, DbConnector pDbCon) {
|
||||||
|
setTitle("Ausleihe umschreiben");
|
||||||
|
setModal(true);
|
||||||
|
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||||
|
setResizable(false);
|
||||||
|
setBounds(100, 100, 229, 156);
|
||||||
|
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
|
JPanel contentPane = new JPanel();
|
||||||
|
setContentPane(contentPane);
|
||||||
|
contentPane.setLayout(new BorderLayout());
|
||||||
|
oldId = pOldId;
|
||||||
|
rwusermodel = new RewriteUserModel(pDbCon, oldId);
|
||||||
|
rwcontroller = new RewriteToNewUserController(pDbCon);
|
||||||
|
|
||||||
|
// Content Panel
|
||||||
|
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
|
contentPanel.setLayout(null);
|
||||||
|
|
||||||
|
JComboBox<String> comboBox = new JComboBox<String>(rwusermodel);
|
||||||
|
comboBox.setBounds(11, 52, 200, 30);
|
||||||
|
|
||||||
|
contentPanel.add(comboBox);
|
||||||
|
|
||||||
|
// Button Panel
|
||||||
|
JPanel buttonPane = new JPanel();
|
||||||
|
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||||
|
|
||||||
|
okButton = new JButton("OK");
|
||||||
|
cancelButton = new JButton("Cancel");
|
||||||
|
okButton.addActionListener(this);
|
||||||
|
cancelButton.addActionListener(this);
|
||||||
|
|
||||||
|
buttonPane.add(okButton);
|
||||||
|
buttonPane.add(cancelButton);
|
||||||
|
|
||||||
|
contentPane.add(buttonPane, BorderLayout.SOUTH);
|
||||||
|
contentPane.add(contentPanel, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
JLabel lblBenutzerAuswhlenAuf = new JLabel("<html>Benutzer ausw\u00E4hlen, auf den <br /> Ausleihen umgeschrieben werden sollen.</html>");
|
||||||
|
lblBenutzerAuswhlenAuf.setBounds(11, 11, 200, 30);
|
||||||
|
contentPanel.add(lblBenutzerAuswhlenAuf);
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
|
// OK Button pressed
|
||||||
|
if(e.getSource() == okButton ) {
|
||||||
|
int newId = rwusermodel.getIdByFullname(rwusermodel.getSelectedItem());
|
||||||
|
|
||||||
|
if(rwcontroller.rewriteToNewUser(oldId, newId)){
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel Button pressed
|
||||||
|
if(e.getSource() == cancelButton ) {
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getResult(){
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -205,6 +205,10 @@ public class UserPanel extends JPanel implements ActionListener, KeyListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setStatusLabel(String pText){
|
||||||
|
lblUserStatus.setText(pText);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent pKeyPress) {
|
public void keyPressed(KeyEvent pKeyPress) {
|
||||||
if(pKeyPress.getKeyCode() == KeyEvent.VK_ENTER) saveButtonPressed();
|
if(pKeyPress.getKeyCode() == KeyEvent.VK_ENTER) saveButtonPressed();
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ public class UserDeleteTableButton extends TableButton {
|
|||||||
|
|
||||||
int row = pTable.getSelectedRow();
|
int row = pTable.getSelectedRow();
|
||||||
|
|
||||||
pController.deleteUser(row);
|
if(pController.deleteUser(row)) pPanel.setStatusLabel("Benutzer erfolgreich gel<65>scht.");
|
||||||
|
else pPanel.setStatusLabel("Beuntzer konnte nicht gel<65>scht werden.");
|
||||||
|
|
||||||
pPanel.resetModeEditUser();
|
pPanel.resetModeEditUser();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -79,11 +79,10 @@ public class LendingTableModel extends AbstractTableModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Die Funktion muss differenzierter werden
|
public boolean isCellEditable(int row, int col){
|
||||||
public boolean isCellEditable(int row, int col){
|
if (col > 4) return true;
|
||||||
if (col > 4) return true;
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void updateModel(){
|
public void updateModel(){
|
||||||
data = dbCon.getActiveLendingList();
|
data = dbCon.getActiveLendingList();
|
||||||
@@ -100,5 +99,9 @@ public class LendingTableModel extends AbstractTableModel {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<KLending> getLendingList(){
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/de/katho/kBorrow/models/RewriteUserModel.java
Normal file
27
src/de/katho/kBorrow/models/RewriteUserModel.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package de.katho.kBorrow.models;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.db.DbConnector;
|
||||||
|
|
||||||
|
public class RewriteUserModel extends UserListModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -78927566018961799L;
|
||||||
|
private int id;
|
||||||
|
|
||||||
|
public RewriteUserModel(DbConnector pDbCon, int pId) {
|
||||||
|
super(pDbCon);
|
||||||
|
id = pId;
|
||||||
|
updateModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateModel(){
|
||||||
|
data = dbCon.getRewriteUserList(id);
|
||||||
|
|
||||||
|
if(data.size() > 0) setSelectedItem(data.get(0).getName()+" "+data.get(0).getSurname());
|
||||||
|
|
||||||
|
fireIntervalAdded(this, 0, data.size()-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -14,9 +14,9 @@ public class UserListModel extends AbstractListModel<String> implements ComboBox
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -8653066929273274524L;
|
private static final long serialVersionUID = -8653066929273274524L;
|
||||||
private DbConnector dbCon;
|
protected DbConnector dbCon;
|
||||||
private ArrayList<KUser> data;
|
protected ArrayList<KUser> data;
|
||||||
private String selectedItem = null;
|
protected String selectedItem = null;
|
||||||
|
|
||||||
public UserListModel(DbConnector pDbCon){
|
public UserListModel(DbConnector pDbCon){
|
||||||
super();
|
super();
|
||||||
|
|||||||
Reference in New Issue
Block a user