Wenn ein Benutzer gelöscht wird, wird nun vorher geprüft, ob dieser
Benutzer mit Ausleihen verknüpft ist. Ist dies der Fall, kann über einen Auswahldialog ein Benutzer ausgewählt werden, auf den die Ausleihen übertragen werden sollen. closes issue #2
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
import de.katho.kBorrow.data.KLending;
|
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.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;
|
||||||
@@ -43,7 +44,7 @@ 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();
|
||||||
|
|
||||||
boolean isOccupied = false;
|
boolean isOccupied = false;
|
||||||
@@ -56,18 +57,26 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(isOccupied){
|
if(isOccupied){
|
||||||
//select und rewrite
|
RewriteToNewUserDialog dialog = new RewriteToNewUserDialog(id, dbCon);
|
||||||
return deleteUser(pRow);
|
if(dialog.getResult() == 0){
|
||||||
|
lendingTableModel.updateModel();
|
||||||
|
userTableModel.updateModel();
|
||||||
|
userListModel.updateModel();
|
||||||
|
|
||||||
|
return deleteUser(pRow);
|
||||||
|
}
|
||||||
|
else return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(dbCon.deleteUser(id)){
|
if(dbCon.deleteUser(id)){
|
||||||
userTableModel.updateModel();
|
userTableModel.updateModel();
|
||||||
userListModel.updateModel();
|
userListModel.updateModel();
|
||||||
|
lendingTableModel.updateModel();
|
||||||
|
|
||||||
return true;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,42 +7,99 @@ import javax.swing.JButton;
|
|||||||
import javax.swing.JDialog;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
|
||||||
public class RewriteToNewUserDialog extends JDialog {
|
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 static final long serialVersionUID = -6002073589194176368L;
|
||||||
private final JPanel contentPanel = new JPanel();
|
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.
|
* Create the dialog.
|
||||||
*/
|
*/
|
||||||
public RewriteToNewUserDialog() {
|
public RewriteToNewUserDialog(int pOldId, DbConnector pDbCon) {
|
||||||
setBounds(100, 100, 450, 300);
|
setTitle("Ausleihe umschreiben");
|
||||||
|
setModal(true);
|
||||||
|
setModalityType(ModalityType.APPLICATION_MODAL);
|
||||||
|
setResizable(false);
|
||||||
|
setBounds(100, 100, 229, 156);
|
||||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
getContentPane().setLayout(new BorderLayout());
|
JPanel contentPane = new JPanel();
|
||||||
setVisible(true);
|
setContentPane(contentPane);
|
||||||
contentPanel.setLayout(new FlowLayout());
|
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.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
contentPanel.setLayout(null);
|
||||||
{
|
|
||||||
JPanel buttonPane = new JPanel();
|
JComboBox<String> comboBox = new JComboBox<String>(rwusermodel);
|
||||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
comboBox.setBounds(11, 52, 200, 30);
|
||||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
|
||||||
{
|
contentPanel.add(comboBox);
|
||||||
JButton okButton = new JButton("OK");
|
|
||||||
okButton.setActionCommand("OK");
|
// Button Panel
|
||||||
buttonPane.add(okButton);
|
JPanel buttonPane = new JPanel();
|
||||||
getRootPane().setDefaultButton(okButton);
|
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||||
}
|
|
||||||
{
|
okButton = new JButton("OK");
|
||||||
JButton cancelButton = new JButton("Cancel");
|
cancelButton = new JButton("Cancel");
|
||||||
cancelButton.setActionCommand("Cancel");
|
okButton.addActionListener(this);
|
||||||
buttonPane.add(cancelButton);
|
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();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
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