ArticleInspect-Fenster ist grundlegend implementiert und zeigt alle
Ausleihen zu einem Artikel an.
This commit is contained in:
@@ -3,9 +3,6 @@ import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import de.katho.kBorrow.db.DbConnector;
|
||||
|
||||
|
||||
public class Util {
|
||||
public static String getCurrentDate(){
|
||||
DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
|
||||
|
||||
@@ -23,4 +23,5 @@ public interface DbConnector {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -98,5 +98,11 @@ public class SqlConnector implements DbConnector{
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<KLending> getLendingListForArticle(int pArtId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -286,6 +286,27 @@ public class SqliteConnector implements DbConnector {
|
||||
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){
|
||||
e.printStackTrace();
|
||||
return lendingArr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -9,7 +9,11 @@ import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTable;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
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 {
|
||||
|
||||
@@ -19,32 +23,58 @@ 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 pArtId, HashMap<String, Object> pModels) {
|
||||
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(100, 100, 660, 541);
|
||||
setTitle("Details: "+article.getName());
|
||||
|
||||
// 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);
|
||||
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
contentPane.setLayout(new BorderLayout(0, 0));
|
||||
setContentPane(contentPane);
|
||||
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
contentPane.add(panel, BorderLayout.CENTER);
|
||||
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("Artikelname");
|
||||
JLabel lblNewLabel_1 = new JLabel("Artikelname:");
|
||||
JLabel lblArticleName = new JLabel(article.getName());
|
||||
JLabel lblNewLabel_2 = new JLabel ("Artikelbeschreibung:");
|
||||
JLabel lblArticleDesc = new JLabel(article.getDescription());
|
||||
|
||||
lblNewLabel_1.setBounds(0, 0, 100, 30);
|
||||
lblNewLabel_2.setBounds(0, 20, 100, 30);
|
||||
lblArticleName.setBounds(120, 0, 100, 30);
|
||||
lblArticleDesc.setBounds(120, 20, 200, 60);
|
||||
|
||||
|
||||
panel.add(lblNewLabel_1);
|
||||
panel.add(lblNewLabel_2);
|
||||
panel.add(lblArticleName);
|
||||
panel.add(lblArticleDesc);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("New label");
|
||||
lblNewLabel.setBounds(0, 45, 634, 45);
|
||||
panel.add(lblNewLabel);
|
||||
table = new JTable();
|
||||
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
setContentPane(contentPane);
|
||||
contentPane.add(panel, BorderLayout.CENTER);
|
||||
contentPane.add(scrollPane, BorderLayout.SOUTH);
|
||||
|
||||
setVisible(true);
|
||||
|
||||
@@ -62,7 +62,7 @@ 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, pModels);
|
||||
ArticleInspectTableButton articleInspectTableButton = new ArticleInspectTableButton("Details", articleTable, dbCon, pModels);
|
||||
|
||||
for (int i = 3; i <= 5; i++){
|
||||
articleTable.getColumnModel().getColumn(i).setCellEditor(i == 3 ? articleInspectTableButton : i == 4 ? articleEditTableButton : articleDeleteTableButton);
|
||||
|
||||
@@ -2,14 +2,15 @@ package de.katho.kBorrow.listener;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
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 {
|
||||
@@ -19,9 +20,10 @@ public class ArticleInspectTableButton extends TableButton {
|
||||
*/
|
||||
private static final long serialVersionUID = -2591133864537097893L;
|
||||
|
||||
public ArticleInspectTableButton(String pLabel, final JTable pTable, final HashMap<String, Object> pModels) throws IOException {
|
||||
public ArticleInspectTableButton(String pLabel, final JTable pTable, final DbConnector dbCon, final HashMap<String, Object> pModels) throws IOException {
|
||||
super(pLabel);
|
||||
ImageIcon icon = new ImageIcon(ImageIO.read(new File("assets/icons/system-search.png")));
|
||||
URL url = Main.class.getResource("/icons/system-search.png");
|
||||
ImageIcon icon = new ImageIcon(url);
|
||||
|
||||
buttonE.setIcon(icon);
|
||||
buttonR.setIcon(icon);
|
||||
@@ -32,7 +34,7 @@ public class ArticleInspectTableButton extends TableButton {
|
||||
|
||||
int row = pTable.getSelectedRow();
|
||||
|
||||
new ArticleInspectFrame(row, pModels);
|
||||
new ArticleInspectFrame(row, dbCon, pModels);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
89
src/de/katho/kBorrow/models/ArticleInspectTableModel.java
Normal file
89
src/de/katho/kBorrow/models/ArticleInspectTableModel.java
Normal file
@@ -0,0 +1,89 @@
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user