Compare commits
14 Commits
v1.0
...
#13_except
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ecb496f35b | ||
|
|
102a46428b | ||
|
|
831d3bda09 | ||
|
|
428806c5b9 | ||
|
|
6dae70df05 | ||
|
|
0d02edec31 | ||
|
|
ff76f0557f | ||
|
|
8c0e5481fe | ||
|
|
a8014deaa5 | ||
|
|
c32b6c7ab9 | ||
|
|
4f71db4fa0 | ||
|
|
051c6df2a4 | ||
|
|
8b652dceef | ||
|
|
32c8042b75 |
@@ -6,5 +6,6 @@
|
||||
<classpathentry kind="lib" path="lib/mysql-connector-java-5.1.32-bin.jar"/>
|
||||
<classpathentry kind="lib" path="lib/sqlite-jdbc-3.7.2.jar"/>
|
||||
<classpathentry kind="lib" path="lib/swingx-all-1.6.4.jar"/>
|
||||
<classpathentry kind="lib" path="lib/pdfbox-app-1.8.7.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
@@ -13,3 +13,6 @@ This software uses the Oracle MySQL Java Connector (http://dev.mysql.com/downloa
|
||||
### Tango Desktop Project
|
||||
This software also uses icons provided by the Tango Desktop Project (http://tango.freedesktop.org/).
|
||||
License will follow!
|
||||
|
||||
### Apache PDFBox
|
||||
This software uses the Apache PDFBox (https://pdfbox.apache.org/) package which is published under Apache License v2.0 (http://www.apache.org/licenses/LICENSE-2.0);
|
||||
BIN
lib/pdfbox-app-1.8.7.jar
Normal file
BIN
lib/pdfbox-app-1.8.7.jar
Normal file
Binary file not shown.
49
src/de/katho/kBorrow/KLogger.java
Normal file
49
src/de/katho/kBorrow/KLogger.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package de.katho.kBorrow;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.SimpleFormatter;
|
||||
|
||||
public class KLogger {
|
||||
private static Logger logger;
|
||||
private Handler fileHandler;
|
||||
private Formatter plainText;
|
||||
|
||||
|
||||
private KLogger() throws IOException {
|
||||
logger = Logger.getLogger(Util.class.getName());
|
||||
String fDir = System.getProperty("user.home")+"/kBorrow";
|
||||
String fName = "kBorrow.log";
|
||||
File dir = new File(fDir);
|
||||
File file = new File(fDir+"/"+fName);
|
||||
|
||||
if(!dir.isDirectory()) dir.mkdir();
|
||||
if(!file.isFile()) file.createNewFile();
|
||||
|
||||
fileHandler = new FileHandler(fDir+"/"+fName, true);
|
||||
plainText = new SimpleFormatter();
|
||||
fileHandler.setFormatter(plainText);
|
||||
logger.addHandler(fileHandler);
|
||||
}
|
||||
|
||||
private static Logger getLogger(){
|
||||
if(logger == null){
|
||||
try{
|
||||
new KLogger();
|
||||
} catch(IOException e){
|
||||
Util.showError(e);
|
||||
}
|
||||
}
|
||||
return logger;
|
||||
}
|
||||
|
||||
public static void log(Level pLevel, String pMsg, Exception e){
|
||||
getLogger().log(pLevel, pMsg, e);
|
||||
System.out.println(pMsg);
|
||||
}
|
||||
}
|
||||
@@ -15,13 +15,13 @@ public class Settings {
|
||||
private String filePath;
|
||||
private String fileName;
|
||||
|
||||
public Settings() {
|
||||
this.properties = new Properties();
|
||||
this.filePath = System.getProperty("user.home")+"/kBorrow";
|
||||
this.fileName = "Settings.cfg";
|
||||
public Settings() throws Exception {
|
||||
properties = new Properties();
|
||||
filePath = System.getProperty("user.home")+"/kBorrow";
|
||||
fileName = "Settings.cfg";
|
||||
|
||||
if(!this.filePathHasValidConfig()){
|
||||
this.createDefaultConfig();
|
||||
if(!filePathHasValidConfig()){
|
||||
createDefaultConfig();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,14 +31,14 @@ public class Settings {
|
||||
*/
|
||||
private boolean filePathHasValidConfig(){
|
||||
try {
|
||||
InputStream in = new FileInputStream(this.filePath+"/"+this.fileName);
|
||||
this.properties = new Properties();
|
||||
InputStream in = new FileInputStream(filePath+"/"+fileName);
|
||||
properties = new Properties();
|
||||
|
||||
this.properties.load(in);
|
||||
properties.load(in);
|
||||
|
||||
// Check if the properties file holds certain keys and values.
|
||||
if( (this.properties.containsKey("dBType") && this.properties.containsValue("sqlite") && this.properties.containsKey("sqlitePath")) ||
|
||||
(this.properties.contains("dbType") && this.properties.containsValue("mysql") && this.properties.containsKey("mysqlDB") && this.properties.containsKey("mysqlHost") && this.properties.containsKey("mysqlUser") && this.properties.containsKey("mysqlPass"))) {
|
||||
if( (properties.containsKey("dBType") && properties.containsValue("sqlite") && properties.containsKey("sqlitePath")) ||
|
||||
(properties.contains("dbType") && properties.containsValue("mysql") && properties.containsKey("mysqlDB") && properties.containsKey("mysqlHost") && properties.containsKey("mysqlUser") && properties.containsKey("mysqlPass"))) {
|
||||
in.close();
|
||||
return true;
|
||||
|
||||
@@ -49,21 +49,23 @@ public class Settings {
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
Util.showWarning(new Exception("Kann die Settingsdatei nicht finden. Versuche, eine neue zu erzeugen.", e));
|
||||
return false;
|
||||
} catch (IOException e){
|
||||
e.printStackTrace();
|
||||
Util.showWarning(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a default config to the config file.
|
||||
* @throws Exception
|
||||
*
|
||||
*/
|
||||
private void createDefaultConfig() {
|
||||
private void createDefaultConfig() throws Exception {
|
||||
try {
|
||||
File dir = new File(this.filePath);
|
||||
File file = new File(this.filePath+"/"+this.fileName);
|
||||
File dir = new File(filePath);
|
||||
File file = new File(filePath+"/"+fileName);
|
||||
if(!dir.isDirectory()) dir.mkdir();
|
||||
if(!file.isFile()) file.createNewFile();
|
||||
else {
|
||||
@@ -73,39 +75,40 @@ public class Settings {
|
||||
|
||||
OutputStream os = new FileOutputStream(this.filePath+"/"+this.fileName);
|
||||
|
||||
this.properties.put("dBType", "sqlite");
|
||||
this.properties.put("sqlitePath",System.getProperty("user.home").replace("\\", "/")+"/kBorrow/kBorrow.db" );
|
||||
this.properties.store(os, null);
|
||||
properties.put("dBType", "sqlite");
|
||||
properties.put("sqlitePath",System.getProperty("user.home").replace("\\", "/")+"/kBorrow/kBorrow.db" );
|
||||
properties.store(os, null);
|
||||
|
||||
os.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("I couldn't find the specified properties file while trying to create a default config.");
|
||||
e.printStackTrace();
|
||||
throw new Exception("I couldn't find the specified properties file while trying to create a default config.", e);
|
||||
} catch (IOException e) {
|
||||
System.out.println("I had problems, writing to the properties file while trying to create a default config.");
|
||||
e.printStackTrace();
|
||||
throw new Exception("I had problems writing to the properties file while trying to create a default config.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getProperty(String pKey){
|
||||
return this.properties.getProperty(pKey);
|
||||
if(properties.containsKey(pKey)) return properties.getProperty(pKey);
|
||||
return "";
|
||||
}
|
||||
|
||||
public void setProperty(String pKey, String pValue){
|
||||
this.properties.put(pKey, pValue);
|
||||
public void setProperty(String pKey, String pValue) throws IOException{
|
||||
properties.put(pKey, pValue);
|
||||
|
||||
OutputStream os;
|
||||
try {
|
||||
os = new FileOutputStream(this.filePath+"/"+this.fileName);
|
||||
this.properties.store(os, null);
|
||||
properties.store(os, null);
|
||||
|
||||
os.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println("I couldn't find the specified properties file while trying to write the config.");
|
||||
e.printStackTrace();
|
||||
throw new FileNotFoundException("I couldn't find the specified properties file while trying to write the config.");
|
||||
} catch (IOException e) {
|
||||
System.out.println("I had problems, writing to the properties file while saving a setting.");
|
||||
e.printStackTrace();
|
||||
throw new IOException("I had problems, writing to the properties file while saving a setting.");
|
||||
}
|
||||
}
|
||||
|
||||
public String getSettingsDir(){
|
||||
return filePath;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,52 @@
|
||||
package de.katho.kBorrow;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import de.katho.kBorrow.db.DbConnector;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import org.jdesktop.swingx.JXErrorPane;
|
||||
import org.jdesktop.swingx.error.ErrorInfo;
|
||||
|
||||
public final class Util {
|
||||
private static JFrame mainwindow;
|
||||
|
||||
public class Util {
|
||||
public static String getCurrentDate(){
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
||||
Date date = new Date();
|
||||
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
|
||||
public static String generateRandomString(int length) {
|
||||
char[] chars = "abcdefghijklmnopqrstuvwxyz".toCharArray();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Random random = new Random();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
char c = chars[random.nextInt(chars.length)];
|
||||
sb.append(c);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static void showWarning(Exception e){
|
||||
KLogger.log(Level.WARNING, e.getMessage(), e);
|
||||
ErrorInfo info = new ErrorInfo("Warnung", e.getMessage(), null, null, e, Level.WARNING, null);
|
||||
JXErrorPane.showDialog(mainwindow, info);
|
||||
}
|
||||
|
||||
public static void showError(Exception e){
|
||||
KLogger.log(Level.SEVERE, e.getMessage(), e);
|
||||
ErrorInfo info = new ErrorInfo("Fehler", e.getMessage(), null, null, e, Level.SEVERE, null);
|
||||
JXErrorPane.showDialog(mainwindow, info);
|
||||
}
|
||||
|
||||
public static void setMainWindow(JFrame p){
|
||||
mainwindow = p;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,20 +60,23 @@ public class ArticleController {
|
||||
* L<>scht den Artikel mit der gegebenen ID in der Datenbank und aktualisiert die Tabelle.
|
||||
*
|
||||
* @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.
|
||||
* @return 0: Artikel konnte erfolgreich gel<65>scht werden
|
||||
* 1: Artikel konnte nicht gel<65>scht werden, unbekannter Fehler (SQL-Fehler)
|
||||
* 2: Artikel konnte nicht gel<65>scht werden, weil er im Moment verliehen ist.
|
||||
*/
|
||||
public boolean deleteArticle(int pRow) {
|
||||
public int deleteArticle(int pRow) {
|
||||
|
||||
if(!articleTableModel.getArticleByRow(pRow).getIsFree()) return 2;
|
||||
|
||||
int id = articleTableModel.getArticleByRow(pRow).getId();
|
||||
int returnCode = dbCon.deleteArticle(id);
|
||||
|
||||
if(this.dbCon.deleteArticle(id)){
|
||||
if(returnCode == 0){
|
||||
articleTableModel.updateModel();
|
||||
freeArticleTableModel.updateModel();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ 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.ArticleTableModel;
|
||||
import de.katho.kBorrow.models.FreeArticleTableModel;
|
||||
import de.katho.kBorrow.models.LendingTableModel;
|
||||
|
||||
@@ -12,12 +13,14 @@ public class ManageLendingsController {
|
||||
|
||||
private DbConnector dbCon;
|
||||
private FreeArticleTableModel freeArticleTableModel;
|
||||
private ArticleTableModel articleTableModel;
|
||||
private LendingTableModel lendingTableModel;
|
||||
|
||||
public ManageLendingsController(DbConnector pDbCon, HashMap<String, Object> pModels){
|
||||
dbCon = pDbCon;
|
||||
|
||||
freeArticleTableModel = (FreeArticleTableModel)pModels.get("freearticletablemodel");
|
||||
articleTableModel = (ArticleTableModel)pModels.get("articletablemodel");
|
||||
lendingTableModel = (LendingTableModel)pModels.get("lendingtablemodel");
|
||||
}
|
||||
|
||||
@@ -30,6 +33,7 @@ public class ManageLendingsController {
|
||||
dbCon.returnLending(lendingId, artId, Util.getCurrentDate());
|
||||
|
||||
freeArticleTableModel.updateModel();
|
||||
articleTableModel.updateModel();
|
||||
lendingTableModel.updateModel();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,30 @@
|
||||
package de.katho.kBorrow.controller;
|
||||
|
||||
import org.apache.pdfbox.exceptions.COSVisitorException;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.pdmodel.PDPage;
|
||||
import org.apache.pdfbox.pdmodel.common.PDRectangle;
|
||||
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
|
||||
import org.apache.pdfbox.pdmodel.font.PDFont;
|
||||
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
import de.katho.kBorrow.Settings;
|
||||
import de.katho.kBorrow.Util;
|
||||
import de.katho.kBorrow.data.KArticle;
|
||||
import de.katho.kBorrow.data.KLender;
|
||||
import de.katho.kBorrow.data.KLending;
|
||||
import de.katho.kBorrow.data.KUser;
|
||||
import de.katho.kBorrow.db.DbConnector;
|
||||
import de.katho.kBorrow.models.ArticleTableModel;
|
||||
import de.katho.kBorrow.models.FreeArticleTableModel;
|
||||
import de.katho.kBorrow.models.LenderModel;
|
||||
import de.katho.kBorrow.models.LendingTableModel;
|
||||
@@ -19,13 +36,17 @@ public class NewLendingController {
|
||||
private LenderModel lenderModel;
|
||||
private FreeArticleTableModel freeArticleModel;
|
||||
private LendingTableModel lendingTableModel;
|
||||
private ArticleTableModel articleTableModel;
|
||||
private Settings settings;
|
||||
|
||||
public NewLendingController(DbConnector pDbCon, HashMap<String, Object> pModels){
|
||||
public NewLendingController(DbConnector pDbCon, HashMap<String, Object> pModels, final Settings pSettings){
|
||||
dbCon = pDbCon;
|
||||
userListModel = (UserListModel)pModels.get("userlistmodel");
|
||||
lenderModel = (LenderModel)pModels.get("lendermodel");
|
||||
freeArticleModel = (FreeArticleTableModel)pModels.get("freearticletablemodel");
|
||||
articleTableModel = (ArticleTableModel)pModels.get("articletablemodel");
|
||||
lendingTableModel = (LendingTableModel)pModels.get("lendingtablemodel");
|
||||
settings = pSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,8 +59,9 @@ public class NewLendingController {
|
||||
* 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!
|
||||
* @throws Exception
|
||||
*/
|
||||
public int newLending(int pArtId, String pLName, String pLSurname, String pLSN, String pStartDate, Date pEstEndDate, String pUsername){
|
||||
public int newLending(int pArtId, String pLName, String pLSurname, String pLSN, String pStartDate, Date pEstEndDate, String pUsername) throws Exception{
|
||||
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;
|
||||
@@ -59,15 +81,114 @@ public class NewLendingController {
|
||||
KLender lender = lenders.get(0);
|
||||
int uId = userListModel.getIdByFullname(pUsername);
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
||||
int result = dbCon.createNewLending(pArtId, uId, lender.getId(), pStartDate, dateFormat.format(pEstEndDate));
|
||||
|
||||
if(result == 0){
|
||||
int[] result = dbCon.createNewLending(pArtId, uId, lender.getId(), pStartDate, dateFormat.format(pEstEndDate));
|
||||
|
||||
if(result[0] == 0){
|
||||
freeArticleModel.updateModel();
|
||||
articleTableModel.updateModel();
|
||||
lendingTableModel.updateModel();
|
||||
return result;
|
||||
createPdfFile(result[1]);
|
||||
|
||||
return result[0];
|
||||
}
|
||||
else return result;
|
||||
else return result[0];
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
private void createPdfFile(int pLendingId) throws Exception {
|
||||
KLending lending = lendingTableModel.getLendingById(pLendingId);
|
||||
KArticle article = articleTableModel.getArticleById(lending.getArticleId());
|
||||
KUser user = userListModel.getUserById(lending.getUserId());
|
||||
KLender lender = lenderModel.getLenderById(lending.getLenderId());
|
||||
|
||||
PDDocument doc = new PDDocument();
|
||||
PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
|
||||
PDRectangle rect = page.getMediaBox();
|
||||
doc.addPage(page);
|
||||
|
||||
PDFont fontNormal = PDType1Font.HELVETICA;
|
||||
PDFont fontBold = PDType1Font.HELVETICA_BOLD;
|
||||
|
||||
String[] text = {
|
||||
"Artikel: ",
|
||||
"Verliehen von: ",
|
||||
"Ausgeliehen an: ",
|
||||
"Start der Ausleihe: ",
|
||||
"Voraussichtliche R<>ckgabe: "
|
||||
};
|
||||
String[] vars = {
|
||||
article.getName(),
|
||||
user.getName()+" "+user.getSurname(),
|
||||
lender.getName()+" "+lender.getSurname()+" ("+lender.getStudentnumber()+")",
|
||||
lending.getStartDate(),
|
||||
lending.getExpectedEndDate()
|
||||
};
|
||||
try {
|
||||
File file = createRandomFile();
|
||||
|
||||
PDPageContentStream cos = new PDPageContentStream(doc, page);
|
||||
|
||||
cos.beginText();
|
||||
cos.moveTextPositionByAmount(100, rect.getHeight() - 100);
|
||||
cos.setFont(fontBold, 16);
|
||||
cos.drawString("Ausleihe #"+lending.getId());
|
||||
cos.endText();
|
||||
|
||||
int i = 0;
|
||||
|
||||
while (i < text.length){
|
||||
cos.beginText();
|
||||
cos.moveTextPositionByAmount(100, rect.getHeight() - 25*(i+2) - 100 );
|
||||
cos.setFont(fontBold, 12);
|
||||
cos.drawString(text[i]);
|
||||
cos.moveTextPositionByAmount(rect.getWidth() / 2 - 100, 0);
|
||||
cos.setFont(fontNormal, 12);
|
||||
cos.drawString(vars[i]);
|
||||
cos.endText();
|
||||
i++;
|
||||
}
|
||||
|
||||
i = i+2;
|
||||
cos.setLineWidth(1);
|
||||
cos.addLine(100, rect.getHeight() - 25*(i+2) - 100, 300, rect.getHeight() - 25*(i+2) - 100);
|
||||
cos.closeAndStroke();
|
||||
|
||||
i++;
|
||||
|
||||
cos.beginText();
|
||||
cos.moveTextPositionByAmount(100, rect.getHeight() - 25*(i+2) - 100);
|
||||
cos.setFont(fontNormal, 12);
|
||||
cos.drawString("Unterschrift "+lender.getName()+" "+lender.getSurname());
|
||||
cos.endText();
|
||||
|
||||
cos.close();
|
||||
doc.save(file);
|
||||
doc.close();
|
||||
|
||||
if(Desktop.isDesktopSupported()){
|
||||
Desktop desktop = Desktop.getDesktop();
|
||||
if(desktop.isSupported(Desktop.Action.OPEN)){
|
||||
desktop.open(file);
|
||||
}
|
||||
}
|
||||
} catch (IOException | COSVisitorException e) {
|
||||
throw new Exception("Problem bei der Erstellung der PDF-Datei.", e);
|
||||
}
|
||||
}
|
||||
|
||||
private File createRandomFile() throws IOException{
|
||||
File dir = new File(settings.getSettingsDir()+"/tmp");
|
||||
File file = new File(settings.getSettingsDir()+"/tmp/"+Util.generateRandomString(8)+".pdf");
|
||||
if(!dir.isDirectory()) dir.mkdir();
|
||||
if(!file.isFile()) file.createNewFile();
|
||||
else {
|
||||
file.delete();
|
||||
file.createNewFile();
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
|
||||
@@ -11,11 +15,13 @@ public class UserController {
|
||||
private DbConnector dbCon;
|
||||
private UserTableModel userTableModel;
|
||||
private UserListModel userListModel;
|
||||
private LendingTableModel lendingTableModel;
|
||||
|
||||
public UserController(DbConnector pDbCon, HashMap<String, Object> pModels) {
|
||||
dbCon = pDbCon;
|
||||
userTableModel = (UserTableModel)pModels.get("usertablemodel");
|
||||
userListModel = (UserListModel)pModels.get("userlistmodel");
|
||||
lendingTableModel = (LendingTableModel)pModels.get("lendingtablemodel");
|
||||
}
|
||||
|
||||
public int createUser(String pName, String pSurname){
|
||||
@@ -38,16 +44,39 @@ public class UserController {
|
||||
return status;
|
||||
}
|
||||
|
||||
public boolean deleteUser(int pRow){
|
||||
public boolean deleteUser(int pRow) {
|
||||
int id = userTableModel.getUserByRow(pRow).getId();
|
||||
|
||||
boolean isOccupied = false;
|
||||
ArrayList<KLending> lendingList = lendingTableModel.getLendingList();
|
||||
for(KLending elem : lendingList){
|
||||
if(elem.getUserId() == id){
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,31 +4,41 @@ public class KArticle {
|
||||
private int id;
|
||||
private String name;
|
||||
private String description;
|
||||
private boolean isFree;
|
||||
|
||||
public KArticle(int pId, String pName, String pDesc) {
|
||||
this.id = pId;
|
||||
this.name = pName;
|
||||
this.description = pDesc;
|
||||
public KArticle(int pId, String pName, boolean pFree, String pDesc) {
|
||||
id = pId;
|
||||
name = pName;
|
||||
description = pDesc;
|
||||
isFree = pFree;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
return description;
|
||||
}
|
||||
|
||||
public boolean getIsFree(){
|
||||
return isFree;
|
||||
}
|
||||
|
||||
public void setName(String pName){
|
||||
this.name = pName;
|
||||
name = pName;
|
||||
}
|
||||
|
||||
public void setDescription(String pDesc){
|
||||
this.description = pDesc;
|
||||
description = pDesc;
|
||||
}
|
||||
|
||||
public void setIsFree(boolean pFree){
|
||||
isFree = pFree;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,12 +15,15 @@ public interface DbConnector {
|
||||
public int editUser(int pId, String pName, String pSurname);
|
||||
public ArrayList<KArticle> getArticleList();
|
||||
public int createArticle(String pName, String pDesc);
|
||||
public boolean deleteArticle(int id);
|
||||
public int deleteArticle(int id);
|
||||
public int editArticle(int pId, String pName, String pDesc);
|
||||
public ArrayList<KArticle> getFreeArticleList();
|
||||
public ArrayList<KLender> getLenderList();
|
||||
public int createNewLending(int pArtId, int pUId, int pLId, String pStartDate, String pEstEndDate);
|
||||
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);
|
||||
public ArrayList<KLending> getLendingListForArticle(int pArtId);
|
||||
public ArrayList<KUser> getRewriteUserList(int id);
|
||||
public boolean rewriteToNewUser(int pOldId, int pNewId);
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ public class SqlConnector implements DbConnector{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteArticle(int id) {
|
||||
public int deleteArticle(int id) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -75,10 +75,10 @@ public class SqlConnector implements DbConnector{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int createNewLending(int pArtId, int pUId, int pLId,
|
||||
public int[] createNewLending(int pArtId, int pUId, int pLId,
|
||||
String pStartDate, String pEstEndDate) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
return new int[2];
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,4 +99,22 @@ public class SqlConnector implements DbConnector{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<KLending> getLendingListForArticle(int pArtId) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import de.katho.kBorrow.Util;
|
||||
import de.katho.kBorrow.data.KArticle;
|
||||
import de.katho.kBorrow.data.KLender;
|
||||
import de.katho.kBorrow.data.KLending;
|
||||
@@ -92,7 +93,7 @@ public class SqliteConnector implements DbConnector {
|
||||
return true;
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
Util.showWarning(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -108,7 +109,7 @@ public class SqliteConnector implements DbConnector {
|
||||
return true;
|
||||
}
|
||||
catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
Util.showWarning(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -201,7 +202,27 @@ public class SqliteConnector implements DbConnector {
|
||||
return userArr;
|
||||
}
|
||||
catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
Util.showWarning(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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){
|
||||
Util.showWarning(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -211,17 +232,17 @@ public class SqliteConnector implements DbConnector {
|
||||
|
||||
try {
|
||||
Statement st = this.connection.createStatement();
|
||||
String query = "SELECT id, name, description FROM article";
|
||||
String query = "SELECT id, name, is_free, description FROM article";
|
||||
ResultSet rs = st.executeQuery(query);
|
||||
|
||||
while (rs.next()){
|
||||
artArr.add(new KArticle(rs.getInt("id"), rs.getString("name"), rs.getString("description")));
|
||||
artArr.add(new KArticle(rs.getInt("id"), rs.getString("name"), rs.getBoolean("is_free"), rs.getString("description")));
|
||||
}
|
||||
|
||||
return artArr;
|
||||
}
|
||||
catch (SQLException ex){
|
||||
ex.printStackTrace();
|
||||
Util.showWarning(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -231,17 +252,17 @@ public class SqliteConnector implements DbConnector {
|
||||
|
||||
try {
|
||||
Statement st = this.connection.createStatement();
|
||||
String query = "SELECT id, name, description FROM article WHERE is_free = 1;";
|
||||
String query = "SELECT id, name, is_free, description FROM article WHERE is_free = 1;";
|
||||
ResultSet rs = st.executeQuery(query);
|
||||
|
||||
while (rs.next()){
|
||||
artArr.add(new KArticle(rs.getInt("id"), rs.getString("name"), rs.getString("description")));
|
||||
artArr.add(new KArticle(rs.getInt("id"), rs.getString("name"), rs.getBoolean("is_free"), rs.getString("description")));
|
||||
}
|
||||
|
||||
return artArr;
|
||||
}
|
||||
catch(SQLException ex){
|
||||
ex.printStackTrace();
|
||||
Util.showWarning(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -261,7 +282,7 @@ public class SqliteConnector implements DbConnector {
|
||||
return lendArr;
|
||||
}
|
||||
catch(SQLException ex){
|
||||
ex.printStackTrace();
|
||||
Util.showWarning(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -282,7 +303,28 @@ public class SqliteConnector implements DbConnector {
|
||||
return lendingArr;
|
||||
}
|
||||
catch(SQLException e){
|
||||
e.printStackTrace();
|
||||
Util.showWarning(e);
|
||||
return lendingArr;
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<KLending> getLendingListForArticle(int pArtId){
|
||||
ArrayList<KLending> lendingArr = new ArrayList<KLending>();
|
||||
|
||||
try{
|
||||
Statement st = connection.createStatement();
|
||||
String query = "SELECT id, user_id, lender_id, start_date, expected_end_date, end_date FROM lending WHERE article_id = '"+pArtId+"' ORDER BY id DESC";
|
||||
|
||||
ResultSet rs = st.executeQuery(query);
|
||||
|
||||
while(rs.next()){
|
||||
lendingArr.add(new KLending(rs.getInt("id"), rs.getInt("user_id"), rs.getInt("lender_id"), pArtId, rs.getString("start_date"), rs.getString("expected_end_date"), rs.getString("end_date")));
|
||||
}
|
||||
|
||||
return lendingArr;
|
||||
}
|
||||
catch(SQLException e){
|
||||
Util.showWarning(e);
|
||||
return lendingArr;
|
||||
}
|
||||
}
|
||||
@@ -304,7 +346,7 @@ public class SqliteConnector implements DbConnector {
|
||||
return 0;
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
Util.showWarning(e);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -320,7 +362,7 @@ public class SqliteConnector implements DbConnector {
|
||||
return 0;
|
||||
}
|
||||
catch(SQLException e){
|
||||
e.printStackTrace();
|
||||
Util.showWarning(e);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -336,7 +378,7 @@ public class SqliteConnector implements DbConnector {
|
||||
return true;
|
||||
}
|
||||
catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
Util.showWarning(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -352,23 +394,23 @@ public class SqliteConnector implements DbConnector {
|
||||
return 0;
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
Util.showWarning(e);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean deleteArticle(int id) {
|
||||
public int deleteArticle(int id) {
|
||||
try {
|
||||
Statement st = this.connection.createStatement();
|
||||
Statement st = connection.createStatement();
|
||||
String query = "DELETE FROM article WHERE id = '"+id+"'";
|
||||
|
||||
st.executeUpdate(query);
|
||||
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
catch (SQLException e){
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
Util.showWarning(e);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,18 +425,26 @@ public class SqliteConnector implements DbConnector {
|
||||
return 0;
|
||||
}
|
||||
catch(SQLException e){
|
||||
e.printStackTrace();
|
||||
Util.showWarning(e);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Erstellt eine neue Ausleihe.
|
||||
*
|
||||
* @return Status-Code:
|
||||
* 0: Erfolg
|
||||
* 1: SQL-Fehler
|
||||
*
|
||||
* @return R<>ckgabewert ist ein Array mit zwei Werten.
|
||||
*
|
||||
* Index 0: Enth<74>lt den R<>ckgabestatus:
|
||||
* - Status 0: Alles in Ordnung
|
||||
* - Status 1: SQL-Fehler
|
||||
*
|
||||
* Index 1: Enth<74>lt die ID der gerade erzeugten Tabellenzeile
|
||||
*/
|
||||
public int createNewLending(int pArtId, int pUId, int pLId, String pStartDate, String pEstEndDate) {
|
||||
public int[] createNewLending(int pArtId, int pUId, int pLId, String pStartDate, String pEstEndDate) {
|
||||
int[] result = new int[2];
|
||||
|
||||
try{
|
||||
Statement st = connection.createStatement();
|
||||
String query = "INSERT INTO lending (article_id, user_id, lender_id, start_date, expected_end_date ) "
|
||||
@@ -403,27 +453,33 @@ public class SqliteConnector implements DbConnector {
|
||||
|
||||
st.executeUpdate(query);
|
||||
|
||||
return 0;
|
||||
query = "SELECT id FROM lending ORDER BY id DESC LIMIT 1;";
|
||||
|
||||
ResultSet rs = st.executeQuery(query);
|
||||
|
||||
result[1] = rs.getInt("id");
|
||||
result[0] = 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
catch(SQLException e){
|
||||
e.printStackTrace();
|
||||
return 1;
|
||||
Util.showWarning(e);
|
||||
return new int[]{1,0};
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
Util.showWarning(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,10 +494,26 @@ public class SqliteConnector implements DbConnector {
|
||||
return 0;
|
||||
}
|
||||
catch(SQLException e){
|
||||
e.printStackTrace();
|
||||
Util.showWarning(e);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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){
|
||||
Util.showWarning(e);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
93
src/de/katho/kBorrow/gui/ArticleInspectFrame.java
Normal file
93
src/de/katho/kBorrow/gui/ArticleInspectFrame.java
Normal file
@@ -0,0 +1,93 @@
|
||||
package de.katho.kBorrow.gui;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JTextArea;
|
||||
|
||||
import de.katho.kBorrow.data.KArticle;
|
||||
import de.katho.kBorrow.db.DbConnector;
|
||||
import de.katho.kBorrow.models.ArticleInspectTableModel;
|
||||
import de.katho.kBorrow.models.ArticleTableModel;
|
||||
|
||||
public class ArticleInspectFrame extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -8993341404926674307L;
|
||||
private JPanel contentPane;
|
||||
private JTable table;
|
||||
private ArticleInspectTableModel artInsModel;
|
||||
private ArticleTableModel articleModel;
|
||||
private KArticle article;
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public ArticleInspectFrame(int pRow, final DbConnector dbCon, HashMap<String, Object> pModels) {
|
||||
articleModel = (ArticleTableModel)pModels.get("articletablemodel");
|
||||
article = articleModel.getArticleByRow(pRow);
|
||||
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(150, 150, 660, 541);
|
||||
setTitle("Details: "+article.getName());
|
||||
|
||||
// ContentPane
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
// Panel Info
|
||||
JPanel panelInfo = new JPanel();
|
||||
panelInfo.setBounds(0, 0, 644, 134);
|
||||
panelInfo.setBorder(BorderFactory.createTitledBorder("Artikeldetails"));
|
||||
|
||||
panelInfo.setLayout(null);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("Artikelname:");
|
||||
JLabel lblArticleName = new JLabel(article.getName());
|
||||
JLabel lblNewLabel_2 = new JLabel ("Artikelbeschreibung:");
|
||||
JTextArea taArticleDesc = new JTextArea(article.getDescription());
|
||||
taArticleDesc.setRows(5);
|
||||
taArticleDesc.setBorder(BorderFactory.createEtchedBorder());
|
||||
|
||||
lblNewLabel_1.setBounds(10, 21, 100, 20);
|
||||
lblNewLabel_2.setBounds(10, 47, 100, 20);
|
||||
lblArticleName.setBounds(120, 21, 250, 20);
|
||||
taArticleDesc.setBounds(120, 45, 250, 78);
|
||||
taArticleDesc.setEditable(false);
|
||||
|
||||
panelInfo.add(lblNewLabel_1);
|
||||
panelInfo.add(lblNewLabel_2);
|
||||
panelInfo.add(lblArticleName);
|
||||
panelInfo.add(taArticleDesc);
|
||||
|
||||
// Table
|
||||
artInsModel = new ArticleInspectTableModel(pRow, dbCon, pModels);
|
||||
table = new JTable(artInsModel);
|
||||
table.setFillsViewportHeight(true);
|
||||
table.setRowHeight(30);
|
||||
table.getColumnModel().getColumn(0).setMinWidth(30);
|
||||
table.getColumnModel().getColumn(0).setMaxWidth(30);
|
||||
table.getColumnModel().getColumn(0).setPreferredWidth(30);
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
scrollPane.setBounds(0, 131, 644, 371);
|
||||
scrollPane.setBorder(BorderFactory.createTitledBorder("Alle Ausleihen des Artikels \""+article.getName()+"\""));
|
||||
|
||||
// Add components to ContentPane
|
||||
contentPane.add(panelInfo);
|
||||
contentPane.add(scrollPane);
|
||||
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import de.katho.kBorrow.data.KArticle;
|
||||
import de.katho.kBorrow.db.DbConnector;
|
||||
import de.katho.kBorrow.listener.ArticleDeleteTableButton;
|
||||
import de.katho.kBorrow.listener.ArticleEditTableButton;
|
||||
import de.katho.kBorrow.listener.ArticleInspectTableButton;
|
||||
import de.katho.kBorrow.models.ArticleTableModel;
|
||||
|
||||
public class ArticlePanel extends JPanel implements ActionListener, KeyListener {
|
||||
@@ -61,10 +62,11 @@ public class ArticlePanel extends JPanel implements ActionListener, KeyListener
|
||||
articleTable.setRowHeight(30);
|
||||
ArticleDeleteTableButton articleDeleteTableButton = new ArticleDeleteTableButton("L<EFBFBD>schen", articleTable, this, articleController);
|
||||
ArticleEditTableButton articleEditTableButton = new ArticleEditTableButton("Bearbeiten", articleTable, this);
|
||||
ArticleInspectTableButton articleInspectTableButton = new ArticleInspectTableButton("Details", articleTable, dbCon, pModels);
|
||||
|
||||
for (int i = 3; i <= 4; i++){
|
||||
articleTable.getColumnModel().getColumn(i).setCellEditor(i == 3 ? articleEditTableButton : articleDeleteTableButton);
|
||||
articleTable.getColumnModel().getColumn(i).setCellRenderer(i == 3 ? articleEditTableButton : articleDeleteTableButton);
|
||||
for (int i = 3; i <= 5; i++){
|
||||
articleTable.getColumnModel().getColumn(i).setCellEditor(i == 3 ? articleInspectTableButton : i == 4 ? articleEditTableButton : articleDeleteTableButton);
|
||||
articleTable.getColumnModel().getColumn(i).setCellRenderer(i == 3 ? articleInspectTableButton : i == 4 ? articleEditTableButton : articleDeleteTableButton);
|
||||
|
||||
articleTable.getColumnModel().getColumn(i).setMinWidth(30);
|
||||
articleTable.getColumnModel().getColumn(i).setMaxWidth(30);
|
||||
@@ -94,7 +96,7 @@ public class ArticlePanel extends JPanel implements ActionListener, KeyListener
|
||||
this.lblArticleStatus = new JLabel("");
|
||||
lblName.setBounds(10, 30, 70, 20);
|
||||
lblDescription.setBounds(10, 61, 70, 20);
|
||||
this.lblArticleStatus.setBounds(90, 145, 250, 14);
|
||||
this.lblArticleStatus.setBounds(90, 145, 390, 14);
|
||||
|
||||
// Edit: Name-Textfield
|
||||
this.textFieldArticleName = new JTextField();
|
||||
@@ -230,7 +232,6 @@ public class ArticlePanel extends JPanel implements ActionListener, KeyListener
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if(e.getKeyCode() == KeyEvent.VK_ENTER) saveButtonPressed();
|
||||
|
||||
@@ -246,4 +247,18 @@ public class ArticlePanel extends JPanel implements ActionListener, KeyListener
|
||||
|
||||
}
|
||||
|
||||
public void setDeleteStatusLabel(int pCode){
|
||||
switch(pCode){
|
||||
case 0:
|
||||
lblArticleStatus.setText("Artikel erfolgreich gel<65>scht.");
|
||||
break;
|
||||
case 1:
|
||||
lblArticleStatus.setText("Artikel kann nicht gel<65>scht werden.");
|
||||
break;
|
||||
case 2:
|
||||
lblArticleStatus.setText("Artikel kann nicht gel<65>scht werden, w<>hrend er verliehen ist.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,16 +5,13 @@ import javax.swing.JTabbedPane;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
|
||||
import org.jdesktop.swingx.JXErrorPane;
|
||||
import org.jdesktop.swingx.error.ErrorInfo;
|
||||
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import de.katho.kBorrow.Settings;
|
||||
import de.katho.kBorrow.Util;
|
||||
import de.katho.kBorrow.db.DbConnector;
|
||||
import de.katho.kBorrow.db.SqlConnector;
|
||||
import de.katho.kBorrow.db.SqliteConnector;
|
||||
@@ -46,14 +43,25 @@ public class MainWindow {
|
||||
* @throws ClassNotFoundException
|
||||
* @throws IOException
|
||||
*/
|
||||
public MainWindow() throws IOException {
|
||||
set = new Settings();
|
||||
public MainWindow() {
|
||||
// Delete all files in tmp-dir
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(){
|
||||
public void run(){
|
||||
File dir = new File(set.getSettingsDir()+"/tmp/");
|
||||
if(dir.isDirectory()){
|
||||
for(File file : dir.listFiles()) file.delete();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
frame = new JFrame();
|
||||
frame.setResizable(false);
|
||||
frame.setBounds(100, 100, 600, 500);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
Util.setMainWindow(frame);
|
||||
set = new Settings();
|
||||
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
|
||||
if(set.getProperty("dBType").equals("sqlite")){
|
||||
@@ -72,23 +80,22 @@ public class MainWindow {
|
||||
models.put("lendingtablemodel", new LendingTableModel(dbCon, models));
|
||||
|
||||
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||
frame.getContentPane().add(this.tabbedPane, BorderLayout.CENTER);
|
||||
tabbedPane.addTab("Neue Ausleihe", new NewLendingPanel(this.dbCon, models));
|
||||
frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
|
||||
tabbedPane.addTab("Neue Ausleihe", new NewLendingPanel(this.dbCon, models, set));
|
||||
tabbedPane.addTab("Ausleihen verwalten", new ManageLendingsPanel(this.dbCon, models));
|
||||
tabbedPane.addTab("Artikel verwalten", new ArticlePanel(this.dbCon, models));
|
||||
tabbedPane.addTab("Benutzer verwalten", new UserPanel(this.dbCon, models));
|
||||
|
||||
}
|
||||
catch(ClassNotFoundException | InstantiationException | IllegalAccessException | IOException | UnsupportedLookAndFeelException | SQLException e) {
|
||||
ErrorInfo info = new ErrorInfo("Exception", e.getMessage(), null, null, e, null, null);
|
||||
JXErrorPane.showDialog(frame, info);
|
||||
catch(Exception e) {
|
||||
Util.showError(e);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
this.frame.setVisible(true);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException{
|
||||
public static void main(String[] args) {
|
||||
new MainWindow();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import javax.swing.border.TitledBorder;
|
||||
import org.jdesktop.swingx.JXDatePicker;
|
||||
import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
|
||||
|
||||
import de.katho.kBorrow.Settings;
|
||||
import de.katho.kBorrow.Util;
|
||||
import de.katho.kBorrow.controller.NewLendingController;
|
||||
import de.katho.kBorrow.converter.LenderNameConverter;
|
||||
@@ -70,7 +71,7 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
||||
* @param dbCon
|
||||
* @throws IOException
|
||||
*/
|
||||
public NewLendingPanel(final DbConnector dbCon, HashMap<String, Object> pModel) throws IOException {
|
||||
public NewLendingPanel(final DbConnector dbCon, HashMap<String, Object> pModel, final Settings pSettings) throws IOException {
|
||||
setLayout(null);
|
||||
articleId = -1;
|
||||
|
||||
@@ -78,7 +79,7 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
||||
freeArticleTableModel = (FreeArticleTableModel)pModel.get("freearticletablemodel");
|
||||
userListModel = (UserListModel)pModel.get("userlistmodel");
|
||||
lenderModel = (LenderModel)pModel.get("lendermodel");
|
||||
newLendingController = new NewLendingController(dbCon, pModel);
|
||||
newLendingController = new NewLendingController(dbCon, pModel, pSettings);
|
||||
|
||||
JTable freeArticleTable = new JTable(freeArticleTableModel);
|
||||
freeArticleTable.setRowHeight(30);
|
||||
@@ -217,7 +218,7 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
||||
tfStudentNumber.setText("");
|
||||
}
|
||||
|
||||
private void saveButtonPressed(){
|
||||
private void saveButtonPressed() throws Exception {
|
||||
String pLName = tfName.getText();
|
||||
String pLSurname = tfSurname.getText();
|
||||
String startDate = lblStartDate.getText();
|
||||
@@ -266,7 +267,11 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
||||
}
|
||||
|
||||
if(pEvent.getSource() == btnSave){
|
||||
try {
|
||||
saveButtonPressed();
|
||||
} catch (Exception e) {
|
||||
Util.showError(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -287,7 +292,12 @@ public class NewLendingPanel extends JPanel implements ActionListener, FocusList
|
||||
}
|
||||
|
||||
public void keyPressed(KeyEvent pKeyPress) {
|
||||
if(pKeyPress.getKeyCode() == KeyEvent.VK_ENTER) saveButtonPressed();
|
||||
if(pKeyPress.getKeyCode() == KeyEvent.VK_ENTER)
|
||||
try {
|
||||
saveButtonPressed();
|
||||
} catch (Exception e) {
|
||||
Util.showError(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
public void keyPressed(KeyEvent pKeyPress) {
|
||||
if(pKeyPress.getKeyCode() == KeyEvent.VK_ENTER) saveButtonPressed();
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ArticleDeleteTableButton extends TableButton {
|
||||
|
||||
int row = pTable.getSelectedRow();
|
||||
|
||||
pController.deleteArticle(row);
|
||||
pPanel.setDeleteStatusLabel(pController.deleteArticle(row));
|
||||
pPanel.resetModeEditArticle();
|
||||
}
|
||||
});
|
||||
|
||||
42
src/de/katho/kBorrow/listener/ArticleInspectTableButton.java
Normal file
42
src/de/katho/kBorrow/listener/ArticleInspectTableButton.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package de.katho.kBorrow.listener;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JTable;
|
||||
|
||||
import sun.tools.jar.Main;
|
||||
import de.katho.kBorrow.db.DbConnector;
|
||||
import de.katho.kBorrow.gui.ArticleInspectFrame;
|
||||
|
||||
public class ArticleInspectTableButton extends TableButton {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -2591133864537097893L;
|
||||
|
||||
public ArticleInspectTableButton(String pLabel, final JTable pTable, final DbConnector dbCon, final HashMap<String, Object> pModels) throws IOException {
|
||||
super(pLabel);
|
||||
URL url = Main.class.getResource("/icons/system-search.png");
|
||||
ImageIcon icon = new ImageIcon(url);
|
||||
|
||||
buttonE.setIcon(icon);
|
||||
buttonR.setIcon(icon);
|
||||
|
||||
buttonE.addActionListener(new ActionListener(){
|
||||
public void actionPerformed(ActionEvent e){
|
||||
fireEditingStopped();
|
||||
|
||||
int row = pTable.getSelectedRow();
|
||||
|
||||
new ArticleInspectFrame(row, dbCon, pModels);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
93
src/de/katho/kBorrow/models/ArticleInspectTableModel.java
Normal file
93
src/de/katho/kBorrow/models/ArticleInspectTableModel.java
Normal file
@@ -0,0 +1,93 @@
|
||||
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.data.KUser;
|
||||
import de.katho.kBorrow.db.DbConnector;
|
||||
|
||||
public class ArticleInspectTableModel extends AbstractTableModel {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 2293157709447086998L;
|
||||
private String[] header;
|
||||
private ArrayList<KLending> data;
|
||||
private DbConnector dbCon;
|
||||
private KArticle article;
|
||||
private ArticleTableModel articleModel;
|
||||
private UserTableModel userModel;
|
||||
private LenderModel lenderModel;
|
||||
|
||||
|
||||
public ArticleInspectTableModel(int pRow, DbConnector pDbCon, HashMap<String, Object> pModels){
|
||||
header = new String[] {"ID", "Verliehen von:", "Ausgeliehen an:", "Ausleihdatum", "Vor. R<>ckgabe", "R<EFBFBD>ckgabe"};
|
||||
dbCon = pDbCon;
|
||||
articleModel = (ArticleTableModel)pModels.get("articletablemodel");
|
||||
userModel = (UserTableModel)pModels.get("usertablemodel");
|
||||
lenderModel = (LenderModel)pModels.get("lendermodel");
|
||||
|
||||
article = articleModel.getArticleByRow(pRow);
|
||||
|
||||
updateModel();
|
||||
}
|
||||
|
||||
public void updateModel() {
|
||||
data = dbCon.getLendingListForArticle(article.getId());
|
||||
fireTableDataChanged();
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return header.length;
|
||||
}
|
||||
|
||||
public String getColumnName(int col){
|
||||
return header[col];
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
public boolean isCellEditable(int pRow, int pCol){
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object getValueAt(int row, int col) {
|
||||
switch(col){
|
||||
case 0:
|
||||
return data.get(row).getId();
|
||||
|
||||
case 1:
|
||||
int uid = data.get(row).getUserId();
|
||||
KUser user = userModel.getUserById(uid);
|
||||
|
||||
return user.getName()+" "+user.getSurname();
|
||||
|
||||
case 2:
|
||||
int lid = data.get(row).getLenderId();
|
||||
KLender lender = lenderModel.getLenderById(lid);
|
||||
|
||||
return lender.getName()+" "+lender.getSurname()+" ("+lender.getStudentnumber()+")";
|
||||
|
||||
case 3:
|
||||
return data.get(row).getStartDate();
|
||||
|
||||
case 4:
|
||||
return data.get(row).getExpectedEndDate();
|
||||
|
||||
case 5:
|
||||
return data.get(row).getEndDate();
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class ArticleTableModel extends AbstractTableModel {
|
||||
protected ArrayList<KArticle> data = new ArrayList<KArticle>();
|
||||
|
||||
public ArticleTableModel(DbConnector pDbCon){
|
||||
header = new String [] {"ID", "Artikelname", "Artikelbeschreibung", "", ""};
|
||||
header = new String [] {"ID", "Artikelname", "Artikelbeschreibung", "", "", ""};
|
||||
this.dbCon = pDbCon;
|
||||
this.updateModel();
|
||||
}
|
||||
|
||||
@@ -79,7 +79,6 @@ public class LendingTableModel extends AbstractTableModel {
|
||||
}
|
||||
}
|
||||
|
||||
// Die Funktion muss differenzierter werden
|
||||
public boolean isCellEditable(int row, int col){
|
||||
if (col > 4) return true;
|
||||
return false;
|
||||
@@ -101,4 +100,8 @@ public class LendingTableModel extends AbstractTableModel {
|
||||
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 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();
|
||||
@@ -72,6 +72,13 @@ public class UserListModel extends AbstractListModel<String> implements ComboBox
|
||||
return -1;
|
||||
}
|
||||
|
||||
public KUser getUserById(int pId){
|
||||
for (KUser elem : data){
|
||||
if(elem.getId() == pId) return elem;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user