Erste Arbeiten an einer PDF-Export-Funktion.
This commit is contained in:
@@ -6,5 +6,6 @@
|
|||||||
<classpathentry kind="lib" path="lib/mysql-connector-java-5.1.32-bin.jar"/>
|
<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/sqlite-jdbc-3.7.2.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/swingx-all-1.6.4.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"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|||||||
@@ -12,4 +12,7 @@ This software uses the Oracle MySQL Java Connector (http://dev.mysql.com/downloa
|
|||||||
|
|
||||||
### Tango Desktop Project
|
### Tango Desktop Project
|
||||||
This software also uses icons provided by the Tango Desktop Project (http://tango.freedesktop.org/).
|
This software also uses icons provided by the Tango Desktop Project (http://tango.freedesktop.org/).
|
||||||
License will follow!
|
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.
@@ -1,12 +1,23 @@
|
|||||||
package de.katho.kBorrow.controller;
|
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.edit.PDPageContentStream;
|
||||||
|
import org.apache.pdfbox.pdmodel.font.PDFont;
|
||||||
|
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.data.KArticle;
|
||||||
import de.katho.kBorrow.data.KLender;
|
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.db.DbConnector;
|
||||||
import de.katho.kBorrow.models.ArticleTableModel;
|
import de.katho.kBorrow.models.ArticleTableModel;
|
||||||
import de.katho.kBorrow.models.FreeArticleTableModel;
|
import de.katho.kBorrow.models.FreeArticleTableModel;
|
||||||
@@ -62,16 +73,51 @@ public class NewLendingController {
|
|||||||
KLender lender = lenders.get(0);
|
KLender lender = lenders.get(0);
|
||||||
int uId = userListModel.getIdByFullname(pUsername);
|
int uId = userListModel.getIdByFullname(pUsername);
|
||||||
DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
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();
|
freeArticleModel.updateModel();
|
||||||
articleTableModel.updateModel();
|
articleTableModel.updateModel();
|
||||||
lendingTableModel.updateModel();
|
lendingTableModel.updateModel();
|
||||||
return result;
|
createPdfFile(result[1]);
|
||||||
|
|
||||||
|
return result[0];
|
||||||
}
|
}
|
||||||
else return result;
|
else return result[0];
|
||||||
}
|
}
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO http://www.coderanch.com/how-to/java/PDFBoxExample
|
||||||
|
private void createPdfFile(int pLendingId){
|
||||||
|
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();
|
||||||
|
doc.addPage(page);
|
||||||
|
|
||||||
|
PDFont font = PDType1Font.HELVETICA;
|
||||||
|
try {
|
||||||
|
PDPageContentStream contentStream = new PDPageContentStream(doc, page);
|
||||||
|
contentStream.beginText();
|
||||||
|
contentStream.setFont(font, 12);
|
||||||
|
contentStream.moveTextPositionByAmount(100, 700);
|
||||||
|
contentStream.drawString("hallo");
|
||||||
|
contentStream.drawString("hallo2");
|
||||||
|
contentStream.endText();
|
||||||
|
contentStream.close();
|
||||||
|
|
||||||
|
doc.save("test.pdf");
|
||||||
|
doc.close();
|
||||||
|
} catch (IOException | COSVisitorException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public interface DbConnector {
|
|||||||
public int editArticle(int pId, String pName, String pDesc);
|
public int editArticle(int pId, String pName, String pDesc);
|
||||||
public ArrayList<KArticle> getFreeArticleList();
|
public ArrayList<KArticle> getFreeArticleList();
|
||||||
public ArrayList<KLender> getLenderList();
|
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 int createNewLender(String pLName, String pLSurname, String pLSN);
|
||||||
public ArrayList<KLending> getActiveLendingList();
|
public ArrayList<KLending> getActiveLendingList();
|
||||||
public int returnLending(int lendingId, int artId, String string);
|
public int returnLending(int lendingId, int artId, String string);
|
||||||
|
|||||||
@@ -75,10 +75,10 @@ public class SqlConnector implements DbConnector{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int createNewLending(int pArtId, int pUId, int pLId,
|
public int[] createNewLending(int pArtId, int pUId, int pLId,
|
||||||
String pStartDate, String pEstEndDate) {
|
String pStartDate, String pEstEndDate) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return 0;
|
return new int[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -430,25 +430,40 @@ public class SqliteConnector implements DbConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Erstellt eine neue Ausleihe.
|
||||||
*
|
*
|
||||||
* @return Status-Code:
|
*
|
||||||
* 0: Erfolg
|
* @return R<>ckgabewert ist ein Array mit zwei Werten.
|
||||||
* 1: SQL-Fehler
|
*
|
||||||
|
* 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{
|
try{
|
||||||
Statement st = connection.createStatement();
|
Statement st = connection.createStatement();
|
||||||
String query = "INSERT INTO lending (article_id, user_id, lender_id, start_date, expected_end_date ) "
|
String query = "INSERT INTO lending (article_id, user_id, lender_id, start_date, expected_end_date ) "
|
||||||
+ "VALUES ("+pArtId+", "+pUId+", "+pLId+", '"+pStartDate+"', '"+pEstEndDate+"');"
|
+ "VALUES ("+pArtId+", "+pUId+", "+pLId+", '"+pStartDate+"', '"+pEstEndDate+"');"
|
||||||
+ "UPDATE article SET is_free = 0 WHERE id = "+pArtId+";";
|
+ "UPDATE article SET is_free = 0 WHERE id = "+pArtId+";";
|
||||||
|
|
||||||
st.executeUpdate(query);
|
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){
|
catch(SQLException e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return 1;
|
return new int[]{1,0};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,13 @@ public class UserListModel extends AbstractListModel<String> implements ComboBox
|
|||||||
return -1;
|
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