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.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.UserListModel;
|
||||
@@ -43,7 +44,7 @@ public class UserController {
|
||||
return status;
|
||||
}
|
||||
|
||||
public boolean deleteUser(int pRow){
|
||||
public boolean deleteUser(int pRow) {
|
||||
int id = userTableModel.getUserByRow(pRow).getId();
|
||||
|
||||
boolean isOccupied = false;
|
||||
@@ -56,18 +57,26 @@ public class UserController {
|
||||
}
|
||||
|
||||
if(isOccupied){
|
||||
//select und rewrite
|
||||
return deleteUser(pRow);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,4 +24,6 @@ public interface DbConnector {
|
||||
public ArrayList<KLending> getActiveLendingList();
|
||||
public int returnLending(int lendingId, int artId, String string);
|
||||
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
|
||||
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() {
|
||||
ArrayList<KArticle> artArr = new ArrayList<KArticle>();
|
||||
|
||||
@@ -432,19 +452,18 @@ public class SqliteConnector implements DbConnector {
|
||||
}
|
||||
}
|
||||
|
||||
public int createNewLender(String pLName, String pLSurname, String pLSN) {
|
||||
try{
|
||||
public boolean rewriteToNewUser(int pOldId, int pNewId) {
|
||||
try {
|
||||
Statement st = connection.createStatement();
|
||||
String query = "INSERT into lender (name, surname, student_number) "
|
||||
+ "VALUES ('"+pLName+"', '"+pLSurname+"', '"+pLSN+"')";
|
||||
String query = "UPDATE lending SET user_id = '"+pNewId+"' WHERE user_id = '"+pOldId+"'";
|
||||
|
||||
st.executeUpdate(query);
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
catch(SQLException e){
|
||||
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.JPanel;
|
||||
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 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() {
|
||||
setBounds(100, 100, 450, 300);
|
||||
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);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
setVisible(true);
|
||||
contentPanel.setLayout(new FlowLayout());
|
||||
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));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton okButton = new JButton("OK");
|
||||
okButton.setActionCommand("OK");
|
||||
buttonPane.add(okButton);
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
}
|
||||
{
|
||||
JButton cancelButton = new JButton("Cancel");
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
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
|
||||
public void keyPressed(KeyEvent pKeyPress) {
|
||||
if(pKeyPress.getKeyCode() == KeyEvent.VK_ENTER) saveButtonPressed();
|
||||
|
||||
@@ -30,7 +30,9 @@ public class UserDeleteTableButton extends TableButton {
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
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 DbConnector dbCon;
|
||||
private ArrayList<KUser> data;
|
||||
private String selectedItem = null;
|
||||
protected DbConnector dbCon;
|
||||
protected ArrayList<KUser> data;
|
||||
protected String selectedItem = null;
|
||||
|
||||
public UserListModel(DbConnector pDbCon){
|
||||
super();
|
||||
|
||||
Reference in New Issue
Block a user