Es können nun bestehende Ausleihen wieder zurückgebucht werden. Außerdem

einiges an Refactoring betrieben.
This commit is contained in:
Servicepoint
2014-11-25 18:12:26 +01:00
parent 932e18a725
commit 1289d2d58d
26 changed files with 476 additions and 199 deletions

BIN
assets/icons/edit-undo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1011 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@@ -182,100 +182,101 @@
</display>
</class>
<association id="21">
<bendpoint x="2798" y="639"/>
<end type="SOURCE" refId="10" navigable="false">
<attribute id="22" name="dbCon">
<end type="SOURCE" refId="17" navigable="false">
<attribute id="22" name="set">
<position height="0" width="0" x="0" y="0"/>
</attribute>
<multiplicity id="23" minimum="0" maximum="1">
<position height="0" width="0" x="0" y="0"/>
</multiplicity>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<end type="TARGET" refId="1" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="24">
<end type="SOURCE" refId="14" navigable="false">
<attribute id="25" name="data">
<bendpoint x="1017" y="639"/>
<end type="SOURCE" refId="4" navigable="false">
<attribute id="25" name="dbCon">
<position height="0" width="0" x="0" y="0"/>
</attribute>
<multiplicity id="26" minimum="0" maximum="2147483647">
<multiplicity id="26" minimum="0" maximum="1">
<position height="0" width="0" x="0" y="0"/>
</multiplicity>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="27">
<bendpoint x="2798" y="639"/>
<end type="SOURCE" refId="10" navigable="false">
<attribute id="28" name="dbCon">
<position height="0" width="0" x="0" y="0"/>
</attribute>
<multiplicity id="29" minimum="0" maximum="1">
<position height="0" width="0" x="0" y="0"/>
</multiplicity>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<generalization id="30">
<end type="SOURCE" refId="13"/>
<end type="TARGET" refId="12"/>
</generalization>
<realization id="31">
<end type="SOURCE" refId="18"/>
<end type="TARGET" refId="2"/>
</realization>
<realization id="32">
<end type="SOURCE" refId="9"/>
<end type="TARGET" refId="2"/>
</realization>
<association id="33">
<end type="SOURCE" refId="5" navigable="false">
<attribute id="34" name="data">
<position height="0" width="0" x="0" y="0"/>
</attribute>
<multiplicity id="35" minimum="0" maximum="2147483647">
<position height="0" width="0" x="0" y="0"/>
</multiplicity>
</end>
<end type="TARGET" refId="19" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<generalization id="36">
<end type="SOURCE" refId="6"/>
<end type="TARGET" refId="12"/>
</generalization>
<association id="37">
<end type="SOURCE" refId="14" navigable="false">
<attribute id="38" name="dbCon">
<position height="0" width="0" x="0" y="0"/>
</attribute>
<multiplicity id="39" minimum="0" maximum="1">
<position height="0" width="0" x="0" y="0"/>
</multiplicity>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="40">
<end type="SOURCE" refId="14" navigable="false">
<attribute id="41" name="data">
<position height="0" width="0" x="0" y="0"/>
</attribute>
<multiplicity id="42" minimum="0" maximum="2147483647">
<position height="0" width="0" x="0" y="0"/>
</multiplicity>
</end>
<end type="TARGET" refId="3" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<generalization id="27">
<end type="SOURCE" refId="6"/>
<end type="TARGET" refId="12"/>
</generalization>
<generalization id="28">
<generalization id="43">
<end type="SOURCE" refId="7"/>
<end type="TARGET" refId="12"/>
</generalization>
<association id="29">
<end type="SOURCE" refId="17" navigable="false">
<attribute id="30" name="set">
<position height="0" width="0" x="0" y="0"/>
</attribute>
<multiplicity id="31" minimum="0" maximum="1">
<position height="0" width="0" x="0" y="0"/>
</multiplicity>
</end>
<end type="TARGET" refId="1" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="32">
<end type="SOURCE" refId="10" navigable="false">
<attribute id="33" name="articleModel">
<position height="0" width="0" x="0" y="0"/>
</attribute>
<multiplicity id="34" minimum="0" maximum="1">
<position height="0" width="0" x="0" y="0"/>
</multiplicity>
</end>
<end type="TARGET" refId="5" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<realization id="35">
<end type="SOURCE" refId="9"/>
<end type="TARGET" refId="2"/>
</realization>
<generalization id="36">
<end type="SOURCE" refId="16"/>
<end type="TARGET" refId="12"/>
</generalization>
<realization id="37">
<end type="SOURCE" refId="18"/>
<end type="TARGET" refId="2"/>
</realization>
<association id="38">
<end type="SOURCE" refId="14" navigable="false">
<attribute id="39" name="dbCon">
<position height="0" width="0" x="0" y="0"/>
</attribute>
<multiplicity id="40" minimum="0" maximum="1">
<position height="0" width="0" x="0" y="0"/>
</multiplicity>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="41">
<end type="SOURCE" refId="5" navigable="false">
<attribute id="42" name="dbCon">
<position height="0" width="0" x="0" y="0"/>
</attribute>
<multiplicity id="43" minimum="0" maximum="1">
<position height="0" width="0" x="0" y="0"/>
</multiplicity>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="44">
<end type="SOURCE" refId="17" navigable="false">
<end type="SOURCE" refId="5" navigable="false">
<attribute id="45" name="dbCon">
<position height="0" width="0" x="0" y="0"/>
</attribute>
@@ -286,39 +287,26 @@
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="47">
<bendpoint x="1017" y="639"/>
<end type="SOURCE" refId="4" navigable="false">
<attribute id="48" name="dbCon">
<generalization id="47">
<end type="SOURCE" refId="16"/>
<end type="TARGET" refId="12"/>
</generalization>
<generalization id="48">
<end type="SOURCE" refId="8"/>
<end type="TARGET" refId="12"/>
</generalization>
<association id="49">
<end type="SOURCE" refId="17" navigable="false">
<attribute id="50" name="dbCon">
<position height="0" width="0" x="0" y="0"/>
</attribute>
<multiplicity id="49" minimum="0" maximum="1">
<multiplicity id="51" minimum="0" maximum="1">
<position height="0" width="0" x="0" y="0"/>
</multiplicity>
</end>
<end type="TARGET" refId="2" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<association id="50">
<end type="SOURCE" refId="5" navigable="false">
<attribute id="51" name="data">
<position height="0" width="0" x="0" y="0"/>
</attribute>
<multiplicity id="52" minimum="0" maximum="2147483647">
<position height="0" width="0" x="0" y="0"/>
</multiplicity>
</end>
<end type="TARGET" refId="19" navigable="true"/>
<display labels="true" multiplicity="true"/>
</association>
<generalization id="53">
<end type="SOURCE" refId="8"/>
<end type="TARGET" refId="12"/>
</generalization>
<generalization id="54">
<end type="SOURCE" refId="13"/>
<end type="TARGET" refId="12"/>
</generalization>
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/>

View File

@@ -13,8 +13,8 @@ public class ArticleController {
public ArticleController(DbConnector pDbCon, HashMap<String, Object> pModels){
dbCon = pDbCon;
articleTableModel = (ArticleTableModel)pModels.get("articlemodel");
freeArticleTableModel = (FreeArticleTableModel)pModels.get("freearticlemodel");
articleTableModel = (ArticleTableModel)pModels.get("articletablemodel");
freeArticleTableModel = (FreeArticleTableModel)pModels.get("freearticletablemodel");
}
/**
@@ -59,10 +59,13 @@ public class ArticleController {
/**
* L<>scht den Artikel mit der gegebenen ID in der Datenbank und aktualisiert die Tabelle.
*
* @param id ID des Artikels, der gel<65>scht werden soll.
* @param pRow Row des Artikels, der gel<65>scht werden soll.
* @return true, wenn der Artikel erfolgreich gel<65>scht wurde. false, wenn ein Fehler aufgetreten ist.
*/
public boolean deleteArticle(int id) {
public boolean deleteArticle(int pRow) {
int id = articleTableModel.getArticleByRow(pRow).getId();
if(this.dbCon.deleteArticle(id)){
articleTableModel.updateModel();
freeArticleTableModel.updateModel();

View File

@@ -0,0 +1,36 @@
package de.katho.kBorrow.controller;
import java.util.HashMap;
import de.katho.kBorrow.Util;
import de.katho.kBorrow.data.KLending;
import de.katho.kBorrow.db.DbConnector;
import de.katho.kBorrow.models.FreeArticleTableModel;
import de.katho.kBorrow.models.LendingTableModel;
public class ManageLendingsController {
private DbConnector dbCon;
private FreeArticleTableModel freeArticleTableModel;
private LendingTableModel lendingTableModel;
public ManageLendingsController(DbConnector pDbCon, HashMap<String, Object> pModels){
dbCon = pDbCon;
freeArticleTableModel = (FreeArticleTableModel)pModels.get("freearticletablemodel");
lendingTableModel = (LendingTableModel)pModels.get("lendingtablemodel");
}
public void returnLending(int pRow) {
KLending lending = lendingTableModel.getLendingByRow(pRow);
int artId = lending.getArticleId();
int lendingId = lending.getId();
dbCon.returnLending(lendingId, artId, Util.getCurrentDate());
freeArticleTableModel.updateModel();
lendingTableModel.updateModel();
}
}

View File

@@ -10,6 +10,7 @@ import de.katho.kBorrow.data.KLender;
import de.katho.kBorrow.db.DbConnector;
import de.katho.kBorrow.models.FreeArticleTableModel;
import de.katho.kBorrow.models.LenderModel;
import de.katho.kBorrow.models.LendingTableModel;
import de.katho.kBorrow.models.UserListModel;
public class NewLendingController {
@@ -17,12 +18,14 @@ public class NewLendingController {
private UserListModel userListModel;
private LenderModel lenderModel;
private FreeArticleTableModel freeArticleModel;
private LendingTableModel lendingTableModel;
public NewLendingController(DbConnector pDbCon, HashMap<String, Object> pModels){
dbCon = pDbCon;
userListModel = (UserListModel)pModels.get("userlistmodel");
lenderModel = (LenderModel)pModels.get("lendermodel");
freeArticleModel = (FreeArticleTableModel)pModels.get("freearticlemodel");
freeArticleModel = (FreeArticleTableModel)pModels.get("freearticletablemodel");
lendingTableModel = (LendingTableModel)pModels.get("lendingtablemodel");
}
/**
@@ -34,10 +37,12 @@ public class NewLendingController {
* 3: Das R<>ckgabedatum ist fr<66>her oder gleich dem Ausleihdatum
* 4: Die gegebene Kombination aus Lender-Name, -Surname und -Studentnumber
* existiert mehrmals in der Datenbank. Das darf nicht sein und wirft daher einen Fehler!
* 5: Matrikelnummer muss eine Zahl sein!
*/
public int newLending(int pArtId, String pLName, String pLSurname, String pLSN, String pStartDate, Date pEstEndDate, String pUsername){
if(pArtId == -1 || pStartDate.isEmpty() || pEstEndDate == null || pLName.isEmpty() || pLSurname.isEmpty() || pUsername.isEmpty()) return 2;
if(pEstEndDate.before(new Date())) return 3;
if(!pLSN.matches("[0-9]+")) return 5;
ArrayList<KLender> lenders = lenderModel.getLenders(pLName, pLSurname, pLSN);
if(lenders.size() == 0) {
@@ -45,6 +50,7 @@ public class NewLendingController {
if(result == 0){
lenderModel.updateModel();
return newLending(pArtId, pLName, pLSurname, pLSN, pStartDate, pEstEndDate, pUsername);
}
else return result;
@@ -57,6 +63,7 @@ public class NewLendingController {
if(result == 0){
freeArticleModel.updateModel();
lendingTableModel.updateModel();
return result;
}
else return result;

View File

@@ -14,7 +14,7 @@ public class UserController {
public UserController(DbConnector pDbCon, HashMap<String, Object> pModels) {
dbCon = pDbCon;
userTableModel = (UserTableModel)pModels.get("usermodel");
userTableModel = (UserTableModel)pModels.get("usertablemodel");
userListModel = (UserListModel)pModels.get("userlistmodel");
}
@@ -38,7 +38,9 @@ public class UserController {
return status;
}
public boolean deleteUser(int id){
public boolean deleteUser(int pRow){
int id = userTableModel.getUserByRow(pRow).getId();
if(dbCon.deleteUser(id)){
userTableModel.updateModel();
userListModel.updateModel();

View File

@@ -0,0 +1,49 @@
package de.katho.kBorrow.data;
public class KLending {
private int id;
private int user_id;
private int article_id;
private int lender_id;
private String start_date;
private String expected_end_date;
private String end_date;
public KLending(int pId, int pUserId, int pLenderId, int pArticleId, String pStartDate, String pExpEndDate, String pEndDate){
id = pId;
user_id = pUserId;
article_id = pArticleId;
lender_id = pLenderId;
start_date = pStartDate;
expected_end_date = pExpEndDate;
end_date = pEndDate;
}
public int getId(){
return id;
}
public int getUserId(){
return user_id;
}
public int getLenderId(){
return lender_id;
}
public int getArticleId(){
return article_id;
}
public String getStartDate() {
return start_date;
}
public String getExpectedEndDate() {
return expected_end_date;
}
public String getEndDate(){
return end_date;
}
}

View File

@@ -4,6 +4,7 @@ import java.util.ArrayList;
import de.katho.kBorrow.data.KArticle;
import de.katho.kBorrow.data.KLender;
import de.katho.kBorrow.data.KLending;
import de.katho.kBorrow.data.KUser;
public interface DbConnector {
@@ -20,5 +21,6 @@ public interface DbConnector {
public ArrayList<KLender> getLenderList();
public int createNewLending(int pArtId, int pUId, int pLId, String pStartDate, String pEstEndDate);
public int createNewLender(String pLName, String pLSurname, String pLSN);
public ArrayList<KLending> getActiveLendingList();
public int returnLending(int lendingId, int artId, String string);
}

View File

@@ -4,6 +4,7 @@ import java.util.ArrayList;
import de.katho.kBorrow.data.KArticle;
import de.katho.kBorrow.data.KLender;
import de.katho.kBorrow.data.KLending;
import de.katho.kBorrow.data.KUser;
public class SqlConnector implements DbConnector{
@@ -86,4 +87,16 @@ public class SqlConnector implements DbConnector{
return 0;
}
@Override
public ArrayList<KLending> getActiveLendingList() {
// TODO Auto-generated method stub
return null;
}
@Override
public int returnLending(int id, int artId, String end_date) {
// TODO Auto-generated method stub
return 0;
}
}

View File

@@ -14,6 +14,7 @@ import java.util.Map.Entry;
import de.katho.kBorrow.data.KArticle;
import de.katho.kBorrow.data.KLender;
import de.katho.kBorrow.data.KLending;
import de.katho.kBorrow.data.KUser;
/**
@@ -264,6 +265,27 @@ public class SqliteConnector implements DbConnector {
}
}
public ArrayList<KLending> getActiveLendingList() {
ArrayList<KLending> lendingArr = new ArrayList<KLending>();
try {
Statement st = connection.createStatement();
String query = "SELECT id, user_id, lender_id, article_id, start_date, expected_end_date, end_date FROM lending WHERE end_date IS NULL";
ResultSet rs = st.executeQuery(query);
while (rs.next()){
lendingArr.add(new KLending(rs.getInt("id"), rs.getInt("user_id"), rs.getInt("lender_id"), rs.getInt("article_id"), rs.getString("start_date"), rs.getString("expected_end_date"), rs.getString("end_date")));
}
return lendingArr;
}
catch(SQLException e){
e.printStackTrace();
return lendingArr;
}
}
/**
*
* @return 0: Benutzer erfolgreich erzeugt
@@ -404,4 +426,21 @@ public class SqliteConnector implements DbConnector {
}
}
public int returnLending(int lendingId, int artId, String end_date) {
try{
Statement st = connection.createStatement();
String query = "UPDATE article SET is_free = 1 WHERE id = '"+artId+"';"
+ "UPDATE lending SET end_date = '"+end_date+"' WHERE id = '"+lendingId+"';";
st.executeUpdate(query);
return 0;
}
catch(SQLException e){
e.printStackTrace();
return 1;
}
}
}

View File

@@ -24,6 +24,7 @@ import javax.swing.UIManager;
import javax.swing.border.TitledBorder;
import de.katho.kBorrow.controller.ArticleController;
import de.katho.kBorrow.data.KArticle;
import de.katho.kBorrow.db.DbConnector;
import de.katho.kBorrow.listener.ArticleDeleteTableButton;
import de.katho.kBorrow.listener.ArticleEditTableButton;
@@ -49,7 +50,7 @@ public class ArticlePanel extends JPanel implements ActionListener, KeyListener
public ArticlePanel(final DbConnector dbCon, HashMap<String, Object> pModels) throws IOException {
super();
this.setLayout(null);
articleTableModel = (ArticleTableModel)pModels.get("articlemodel");
articleTableModel = (ArticleTableModel)pModels.get("articletablemodel");
articleController = new ArticleController(dbCon, pModels);
/*
@@ -170,11 +171,13 @@ public class ArticlePanel extends JPanel implements ActionListener, KeyListener
this.textAreaArticleDescription.setText("");
}
public void setModeEditArticle(int articleId, String articleName, String articleDescription) {
public void setModeEditArticle(int pRow) {
KArticle art = articleTableModel.getArticleByRow(pRow);
this.articleModeEdit = true;
this.articleEditId = articleId;
this.textFieldArticleName.setText(articleName);
this.textAreaArticleDescription.setText(articleDescription);
this.articleEditId = art.getId();
this.textFieldArticleName.setText(art.getName());
this.textAreaArticleDescription.setText(art.getDescription());
}
private void saveButtonPressed(){

View File

@@ -20,6 +20,7 @@ import de.katho.kBorrow.db.SqliteConnector;
import de.katho.kBorrow.models.ArticleTableModel;
import de.katho.kBorrow.models.FreeArticleTableModel;
import de.katho.kBorrow.models.LenderModel;
import de.katho.kBorrow.models.LendingTableModel;
import de.katho.kBorrow.models.UserTableModel;
import de.katho.kBorrow.models.UserListModel;
@@ -62,11 +63,12 @@ public class MainWindow {
}
models = new HashMap<String, Object>();
models.put("usermodel", new UserTableModel(dbCon));
models.put("usertablemodel", new UserTableModel(dbCon));
models.put("userlistmodel", new UserListModel(dbCon));
models.put("articlemodel", new ArticleTableModel(dbCon));
models.put("freearticlemodel", new FreeArticleTableModel(dbCon));
models.put("articletablemodel", new ArticleTableModel(dbCon));
models.put("freearticletablemodel", new FreeArticleTableModel(dbCon));
models.put("lendermodel", new LenderModel(dbCon));
models.put("lendingtablemodel", new LendingTableModel(dbCon, models));
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
frame.getContentPane().add(this.tabbedPane, BorderLayout.CENTER);

View File

@@ -1,24 +1,63 @@
package de.katho.kBorrow.gui;
import java.awt.Color;
import java.util.HashMap;
import javax.swing.JPanel;
import de.katho.kBorrow.controller.ManageLendingsController;
import de.katho.kBorrow.db.DbConnector;
import de.katho.kBorrow.listener.LendingReturnTableButton;
import de.katho.kBorrow.models.LendingTableModel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;
import java.awt.BorderLayout;
import java.io.IOException;
public class ManageLendingsPanel extends JPanel {
/**
*
*/
private static final long serialVersionUID = -1559803834099586468L;
private static final long serialVersionUID = 925691137664223491L;
/**
* Create the panel.
* @param dbCon
*/
public ManageLendingsPanel(DbConnector dbCon, HashMap<String, Object> pModels) {
private LendingTableModel lendingTableModel;
private ManageLendingsController manageLendingsController;
public ManageLendingsPanel(DbConnector dbCon, HashMap<String, Object> models) throws IOException {
lendingTableModel = (LendingTableModel)models.get("lendingtablemodel");
manageLendingsController = new ManageLendingsController(dbCon, models);
// Lending-Table
JTable lendingTable = new JTable(lendingTableModel);
lendingTable.setFillsViewportHeight(true);
lendingTable.setRowHeight(30);
LendingReturnTableButton lrtb = new LendingReturnTableButton("Ausleihe beenden", lendingTable, manageLendingsController);
for(int i = 5; i <= 6; i++){
lendingTable.getColumnModel().getColumn(i).setCellEditor(i == 5 ? null : lrtb);
lendingTable.getColumnModel().getColumn(i).setCellRenderer(i == 5 ? null : lrtb);
lendingTable.getColumnModel().getColumn(i).setMinWidth(30);
lendingTable.getColumnModel().getColumn(i).setMaxWidth(30);
lendingTable.getColumnModel().getColumn(i).setPreferredWidth(30);
}
lendingTable.getColumnModel().getColumn(0).setMinWidth(30);
lendingTable.getColumnModel().getColumn(0).setMaxWidth(30);
lendingTable.getColumnModel().getColumn(0).setPreferredWidth(30);
setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Aktive Ausleihen", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
setLayout(new BorderLayout(0, 0));
add(new JScrollPane(lendingTable));
}
}

View File

@@ -33,6 +33,7 @@ import de.katho.kBorrow.controller.NewLendingController;
import de.katho.kBorrow.converter.LenderNameConverter;
import de.katho.kBorrow.converter.LenderStudentnumberConverter;
import de.katho.kBorrow.converter.LenderSurnameConverter;
import de.katho.kBorrow.data.KArticle;
import de.katho.kBorrow.data.KLender;
import de.katho.kBorrow.db.DbConnector;
import de.katho.kBorrow.listener.NewLendingTableButton;
@@ -74,7 +75,7 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
articleId = -1;
// FreeArticleTable
freeArticleTableModel = (FreeArticleTableModel)pModel.get("freearticlemodel");
freeArticleTableModel = (FreeArticleTableModel)pModel.get("freearticletablemodel");
userListModel = (UserListModel)pModel.get("userlistmodel");
lenderModel = (LenderModel)pModel.get("lendermodel");
newLendingController = new NewLendingController(dbCon, pModel);
@@ -244,14 +245,18 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
lblStatus.setText("Die gegebene Kombination aus Lender-Name, -Surname und -Studentnumber" +
"existiert mehrmals in der Datenbank. Das darf nicht sein und wirft daher einen Fehler!");
break;
case 5:
lblStatus.setText("Matrikelnummer muss eine Zahl sein!");
break;
}
}
public void setModeNewLending(int pArticleId, String articleName) {
public void setModeNewLending(int pRow) {
KArticle art = freeArticleTableModel.getArticleByRow(pRow);
lblStartDate.setText(Util.getCurrentDate());
lblArticleName.setText(articleName);
articleId = pArticleId;
lblArticleName.setText(art.getName());
articleId = art.getId();
}

View File

@@ -20,6 +20,7 @@ import javax.swing.UIManager;
import javax.swing.border.TitledBorder;
import de.katho.kBorrow.controller.UserController;
import de.katho.kBorrow.data.KUser;
import de.katho.kBorrow.db.DbConnector;
import de.katho.kBorrow.listener.UserDeleteTableButton;
import de.katho.kBorrow.listener.UserEditTableButton;
@@ -41,7 +42,7 @@ public class UserPanel extends JPanel implements ActionListener, KeyListener {
public UserPanel(final DbConnector dbCon, HashMap<String, Object> pModels) throws IOException{
super();
setLayout(null);
userTableModel = (UserTableModel)pModels.get("usermodel");
userTableModel = (UserTableModel)pModels.get("usertablemodel");
userController = new UserController(dbCon, pModels);
//Tabelle und drumherum
@@ -146,11 +147,13 @@ public class UserPanel extends JPanel implements ActionListener, KeyListener {
this.textFieldUserSurname.setText("");
}
public void setModeEditUser(int pId, String pName, String pSurname){
public void setModeEditUser(int pRow){
KUser user = userTableModel.getUserByRow(pRow);
this.userModeEdit = true;
this.userEditId = pId;
this.textFieldUserName.setText(pName);
this.textFieldUserSurname.setText(pSurname);
this.userEditId = user.getId();
this.textFieldUserName.setText(user.getName());
this.textFieldUserSurname.setText(user.getSurname());
}
private void saveButtonPressed(){

View File

@@ -11,7 +11,6 @@ import javax.swing.JTable;
import de.katho.kBorrow.controller.ArticleController;
import de.katho.kBorrow.gui.ArticlePanel;
import de.katho.kBorrow.models.ArticleTableModel;
public class ArticleDeleteTableButton extends TableButton {
@@ -31,12 +30,9 @@ public class ArticleDeleteTableButton extends TableButton {
public void actionPerformed(ActionEvent e){
fireEditingStopped();
ArticleTableModel model = (ArticleTableModel) pTable.getModel();
int row = pTable.getSelectedRow();
int id = model.getArticleId(row);
pController.deleteArticle(id);
pController.deleteArticle(row);
pPanel.resetModeEditArticle();
}
});

View File

@@ -10,7 +10,6 @@ import javax.swing.ImageIcon;
import javax.swing.JTable;
import de.katho.kBorrow.gui.ArticlePanel;
import de.katho.kBorrow.models.ArticleTableModel;
public class ArticleEditTableButton extends TableButton {
@@ -30,10 +29,9 @@ public class ArticleEditTableButton extends TableButton {
public void actionPerformed(ActionEvent e){
fireEditingStopped();
ArticleTableModel model = (ArticleTableModel) pTable.getModel();
int row = pTable.getSelectedRow();
articleTab.setModeEditArticle(model.getArticleId(row), model.getArticleName(row), model.getArticleDescription(row));
articleTab.setModeEditArticle(row);
}
});
}

View File

@@ -0,0 +1,40 @@
package de.katho.kBorrow.listener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JTable;
import de.katho.kBorrow.controller.ManageLendingsController;
public class LendingReturnTableButton extends TableButton {
/**
*
*/
private static final long serialVersionUID = 4841475504601928160L;
public LendingReturnTableButton(String pLabel, final JTable pTable, final ManageLendingsController pController) throws IOException {
super(pLabel);
ImageIcon icon = new ImageIcon(ImageIO.read(new File("assets/icons/edit-undo.png")));
this.buttonE.setIcon(icon);
this.buttonR.setIcon(icon);
this.buttonE.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
fireEditingStopped();
int row = pTable.getSelectedRow();
pController.returnLending(row);
}
});
}
}

View File

@@ -10,7 +10,6 @@ import javax.swing.ImageIcon;
import javax.swing.JTable;
import de.katho.kBorrow.gui.NewLendingPanel;
import de.katho.kBorrow.models.FreeArticleTableModel;
public class NewLendingTableButton extends TableButton {
@@ -30,10 +29,9 @@ public class NewLendingTableButton extends TableButton {
public void actionPerformed(ActionEvent e){
fireEditingStopped();
FreeArticleTableModel model = (FreeArticleTableModel) pTable.getModel();
int row = pTable.getSelectedRow();
pPanel.setModeNewLending(model.getArticleId(row), model.getArticleName(row));
pPanel.setModeNewLending(row);
}
});
}

View File

@@ -11,7 +11,6 @@ import javax.swing.JTable;
import de.katho.kBorrow.controller.UserController;
import de.katho.kBorrow.gui.UserPanel;
import de.katho.kBorrow.models.UserTableModel;
public class UserDeleteTableButton extends TableButton {
@@ -28,12 +27,9 @@ public class UserDeleteTableButton extends TableButton {
public void actionPerformed(ActionEvent e){
fireEditingStopped();
UserTableModel model = (UserTableModel) pTable.getModel();
int row = pTable.getSelectedRow();
int id = model.getUserId(row);
pController.deleteUser(id);
pController.deleteUser(row);
pPanel.resetModeEditUser();
}
});

View File

@@ -10,7 +10,6 @@ import javax.swing.ImageIcon;
import javax.swing.JTable;
import de.katho.kBorrow.gui.UserPanel;
import de.katho.kBorrow.models.UserTableModel;
public class UserEditTableButton extends TableButton {
@@ -30,10 +29,9 @@ public class UserEditTableButton extends TableButton {
public void actionPerformed(ActionEvent e){
fireEditingStopped();
UserTableModel model = (UserTableModel) pTable.getModel();
int row = pTable.getSelectedRow();
pPanel.setModeEditUser(model.getUserId(row), model.getUserName(row), model.getUserSurname(row));
pPanel.setModeEditUser(row);
}
});

View File

@@ -63,37 +63,6 @@ public class ArticleTableModel extends AbstractTableModel {
return false;
}
/**
* Gibt die ID der gegebenen Tabellenzeile aus.
*
* @param row Tabellenzeile, zu der die ID ausgegeben werden soll.
* @return Artikel-ID als int.
*/
public int getArticleId(int row) {
return this.data.get(row).getId();
}
/**
* Gibt den Artikelnamen der gegebenen Tabellenzeile aus.
*
* @param pRow Tabellenzeile, zu der der Name ausgegeben werden soll.
* @return Artikelname als String
*/
public String getArticleName(int pRow){
return this.data.get(pRow).getName();
}
/**
* Gibt die Artikelbeschreibung der gegebenen Tabellenzeile aus.
*
* @param pRow Tabellenzeile, zu der die Beschreibung ausgegeben werden soll
* @return Artikelbeschreibung als String.
*/
public String getArticleDescription(int pRow){
return this.data.get(pRow).getDescription();
}
/**
* Gibt die entsprechende Zeile in der Tabelle f<>r ein Objekt mit der gegebenen ID zur<75>ck.
*
@@ -114,7 +83,7 @@ public class ArticleTableModel extends AbstractTableModel {
* @return KArticle-Objekt
*/
public KArticle getArticleByRow(int pRow){
return this.data.get(pRow);
return data.get(pRow);
}
/**

View File

@@ -104,4 +104,15 @@ public class LenderModel {
return elems;
}
public KLender getLenderById(int pId){
for(KLender elem : data){
if(elem.getId() == pId) return elem;
}
return null;
}
public KLender getLenderByRow(int pRow){
return data.get(pRow);
}
}

View File

@@ -0,0 +1,95 @@
package de.katho.kBorrow.models;
import java.util.ArrayList;
import java.util.HashMap;
import javax.swing.table.AbstractTableModel;
import de.katho.kBorrow.data.KArticle;
import de.katho.kBorrow.data.KLender;
import de.katho.kBorrow.data.KLending;
import de.katho.kBorrow.db.DbConnector;
public class LendingTableModel extends AbstractTableModel {
/**
*
*/
private static final long serialVersionUID = 1375465648631587292L;
private DbConnector dbCon;
private String[] header = {"ID", "Artikel", "Ausleiher", "Ausleihdatum", "Vor. R<>ckgabe", "", ""};
private ArrayList<KLending> data = new ArrayList<KLending>();
private ArticleTableModel articleModel;
private LenderModel lenderModel;
public LendingTableModel(DbConnector pDbCon, HashMap<String, Object> pModels ) {
dbCon = pDbCon;
articleModel = (ArticleTableModel)pModels.get("articletablemodel");
lenderModel = (LenderModel)pModels.get("lendermodel");
updateModel();
}
public int getColumnCount() {
return header.length;
}
public String getColumnName(int index){
return header[index];
}
public int getRowCount() {
return data.size();
}
public Object getValueAt(int row, int col) {
switch (col){
case 0:
return data.get(row).getId();
case 1:
int artId = data.get(row).getArticleId();
KArticle art = articleModel.getArticleById(artId);
return art.getName();
case 2:
int lenderId = data.get(row).getLenderId();
KLender lender = lenderModel.getLenderById(lenderId);
return lender.getName()+" "+lender.getSurname()+" ("+lender.getStudentnumber()+")";
case 3:
return data.get(row).getStartDate();
case 4:
return data.get(row).getExpectedEndDate();
default:
return null;
}
}
// Die Funktion muss differenzierter werden
public boolean isCellEditable(int row, int col){
if (col > 4) return true;
return false;
}
public void updateModel(){
data = dbCon.getActiveLendingList();
fireTableDataChanged();
}
public KLending getLendingByRow(int row) {
return data.get(row);
}
public KLending getLendingById(int id){
for(KLending elem : data){
if(elem.getId() == id) return elem;
}
return null;
}
}

View File

@@ -22,17 +22,14 @@ public class UserTableModel extends AbstractTableModel {
updateModel();
}
@Override
public int getColumnCount() {
return this.header.length;
}
@Override
public int getRowCount() {
return this.data.size();
}
@Override
public String getValueAt(int row, int col) {
switch(col){
case 0:
@@ -64,18 +61,6 @@ public class UserTableModel extends AbstractTableModel {
return false;
}
public int getUserId(int row){
return this.data.get(row).getId();
}
public String getUserName(int row){
return this.data.get(row).getName();
}
public String getUserSurname(int row){
return this.data.get(row).getSurname();
}
/**
*
* @param pId