SQL-Funktionen zum Hinzufügen, Löschen und Bearbeiten von Artikeln
hinzugefügt. Erzeugung der einzelnen Tabs in eigene Klassen ausgelagert, um die MainWindow-Klasse übersichtlicher zu gestalten.
This commit is contained in:
@@ -12,5 +12,8 @@ public interface DbConnector {
|
|||||||
public boolean deleteUser(int id);
|
public boolean deleteUser(int id);
|
||||||
public int editUser(int pId, String pName, String pSurname);
|
public int editUser(int pId, String pName, String pSurname);
|
||||||
public ArrayList<KArticle> getArticleList();
|
public ArrayList<KArticle> getArticleList();
|
||||||
|
public int createArticle(String pName, String pDesc);
|
||||||
|
public boolean deleteArticle(int id);
|
||||||
|
public int editArticle(int pId, String pName, String pDesc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,5 +41,23 @@ public class SqlConnector implements DbConnector{
|
|||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int createArticle(String pName, String pDesc) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteArticle(int id) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int editArticle(int pId, String pName, String pDesc) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,7 +240,6 @@ public class SqliteConnector implements DbConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ArrayList<KArticle> getArticleList() {
|
public ArrayList<KArticle> getArticleList() {
|
||||||
ArrayList<KArticle> artArr = new ArrayList<KArticle>();
|
ArrayList<KArticle> artArr = new ArrayList<KArticle>();
|
||||||
|
|
||||||
@@ -261,7 +260,6 @@ public class SqliteConnector implements DbConnector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int editUser(int pId, String pName, String pSurname) {
|
public int editUser(int pId, String pName, String pSurname) {
|
||||||
if(pName.isEmpty() && pSurname.isEmpty()) return 2;
|
if(pName.isEmpty() && pSurname.isEmpty()) return 2;
|
||||||
try {
|
try {
|
||||||
@@ -277,5 +275,52 @@ public class SqliteConnector implements DbConnector {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int createArticle(String pName, String pDesc) {
|
||||||
|
if (pName.isEmpty()) return 2;
|
||||||
|
try {
|
||||||
|
Statement st = this.connection.createStatement();
|
||||||
|
String query = "INSERT INTO article (name, description) VALUES ('"+pName+"', '"+pDesc+"')";
|
||||||
|
|
||||||
|
st.executeUpdate(query);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean deleteArticle(int id) {
|
||||||
|
try {
|
||||||
|
Statement st = this.connection.createStatement();
|
||||||
|
String query = "DELETE FROM article WHERE id = '"+id+"'";
|
||||||
|
|
||||||
|
st.executeUpdate(query);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (SQLException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int editArticle(int pId, String pName, String pDesc) {
|
||||||
|
if(pName.isEmpty()) return 2;
|
||||||
|
try {
|
||||||
|
Statement st = this.connection.createStatement();
|
||||||
|
String query = "UPDATE article SET name = '"+pName+"', description = '"+pDesc+"' WHERE id = '"+pId+"'";
|
||||||
|
|
||||||
|
st.executeUpdate(query);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch(SQLException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
192
src/de/katho/kBorrow/gui/ArticleTab.java
Normal file
192
src/de/katho/kBorrow/gui/ArticleTab.java
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
package de.katho.kBorrow.gui;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.border.TitledBorder;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.db.DbConnector;
|
||||||
|
import de.katho.kBorrow.listener.ArticleDeleteTableButton;
|
||||||
|
import de.katho.kBorrow.listener.ArticleEditTableButton;
|
||||||
|
|
||||||
|
public class ArticleTab extends JPanel implements ActionListener {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -8511924597640457608L;
|
||||||
|
private ArticleTableModel articleTableModel;
|
||||||
|
private JTextArea textAreaArticleDescription;
|
||||||
|
private JTextField textFieldArticleName;
|
||||||
|
private JButton btnArticleSave;
|
||||||
|
private JButton btnArticleCancel;
|
||||||
|
private JLabel lblArticleStatus;
|
||||||
|
private boolean articleModeEdit;
|
||||||
|
private int articleEditId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the panel.
|
||||||
|
*/
|
||||||
|
public ArticleTab(final DbConnector dbCon) {
|
||||||
|
super();
|
||||||
|
this.setLayout(null);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Tabelle und drumherum
|
||||||
|
*/
|
||||||
|
this.articleTableModel = new ArticleTableModel(dbCon);
|
||||||
|
JTable articleTable = new JTable(articleTableModel);
|
||||||
|
ArticleDeleteTableButton articleDeleteTableButton = new ArticleDeleteTableButton("L<EFBFBD>schen", articleTable);
|
||||||
|
ArticleEditTableButton articleEditTableButton = new ArticleEditTableButton("Bearbeiten", articleTable, this);
|
||||||
|
|
||||||
|
articleTable.getColumnModel().getColumn(4).setCellEditor(articleDeleteTableButton);
|
||||||
|
articleTable.getColumnModel().getColumn(4).setCellRenderer(articleDeleteTableButton);
|
||||||
|
|
||||||
|
articleTable.getColumnModel().getColumn(3).setCellEditor(articleEditTableButton);
|
||||||
|
articleTable.getColumnModel().getColumn(3).setCellRenderer(articleEditTableButton);
|
||||||
|
|
||||||
|
articleTable.setFillsViewportHeight(true);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Panel Articlelist
|
||||||
|
*/
|
||||||
|
JPanel panelArticleList = new JPanel();
|
||||||
|
panelArticleList.setBorder(new TitledBorder(null, "Artikelliste", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||||
|
panelArticleList.setBounds(0, 0, 589, 275);
|
||||||
|
panelArticleList.setLayout(new BorderLayout(0, 0));
|
||||||
|
panelArticleList.add(new JScrollPane(articleTable));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Edit: Labels
|
||||||
|
*/
|
||||||
|
JLabel lblName = new JLabel("Name");
|
||||||
|
JLabel lblDescription = new JLabel("Beschreibung");
|
||||||
|
this.lblArticleStatus = new JLabel("");
|
||||||
|
lblName.setBounds(10, 30, 70, 20);
|
||||||
|
lblDescription.setBounds(10, 61, 70, 20);
|
||||||
|
this.lblArticleStatus.setBounds(90, 145, 250, 14);
|
||||||
|
|
||||||
|
// Edit: Name-Textfield
|
||||||
|
this.textFieldArticleName = new JTextField();
|
||||||
|
this.textFieldArticleName.setBounds(90, 30, 250, 20);
|
||||||
|
this.textFieldArticleName.setColumns(10);
|
||||||
|
|
||||||
|
//Edit: Desc-TextArea
|
||||||
|
this.textAreaArticleDescription = new JTextArea(5, 30);
|
||||||
|
this.textAreaArticleDescription.setFont(new Font("Tahoma", Font.PLAIN, 11));
|
||||||
|
this.textAreaArticleDescription.setLineWrap(true);
|
||||||
|
this.textAreaArticleDescription.setBounds(90, 59, 250, 80);
|
||||||
|
this.textAreaArticleDescription.setBorder(BorderFactory.createEtchedBorder());
|
||||||
|
|
||||||
|
//Edit: Button-Save
|
||||||
|
this.btnArticleSave = new JButton("Speichern");
|
||||||
|
this.btnArticleSave.addActionListener(this);
|
||||||
|
this.btnArticleSave.setBounds(490, 136, 89, 23);
|
||||||
|
|
||||||
|
//Edit: Button-Cancel
|
||||||
|
this.btnArticleCancel = new JButton("Abbrechen");
|
||||||
|
this.btnArticleCancel.addActionListener(this);
|
||||||
|
this.btnArticleCancel.setBounds(490, 102, 89, 23);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* PanelArticleEdit
|
||||||
|
*/
|
||||||
|
JPanel panelArticleEdit = new JPanel();
|
||||||
|
panelArticleEdit.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Artikel hinzuf\u00FCgen / bearbeiten", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
||||||
|
panelArticleEdit.setBounds(0, 273, 589, 170);
|
||||||
|
panelArticleEdit.setLayout(null);
|
||||||
|
panelArticleEdit.add(lblName);
|
||||||
|
panelArticleEdit.add(lblDescription);
|
||||||
|
panelArticleEdit.add(textFieldArticleName);
|
||||||
|
panelArticleEdit.add(this.textAreaArticleDescription);
|
||||||
|
panelArticleEdit.add(this.btnArticleSave);
|
||||||
|
panelArticleEdit.add(this.btnArticleCancel);
|
||||||
|
panelArticleEdit.add(lblArticleStatus);
|
||||||
|
|
||||||
|
this.add(panelArticleList);
|
||||||
|
this.add(panelArticleEdit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aktionen f<>r den Button "Artikel speichern"
|
||||||
|
*/
|
||||||
|
if(e.getSource() == this.btnArticleSave){
|
||||||
|
if(this.articleModeEdit){
|
||||||
|
int re = this.articleTableModel.editArticle(this.articleEditId, this.textFieldArticleName.getText(), this.textAreaArticleDescription.getText());
|
||||||
|
|
||||||
|
switch(re){
|
||||||
|
case 0:
|
||||||
|
this.lblArticleStatus.setText("Artikel-ID \""+this.articleEditId+"\" erfolgreich bearbeitet.");
|
||||||
|
this.textFieldArticleName.setText("");
|
||||||
|
this.textAreaArticleDescription.setText("");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
this.lblArticleStatus.setText("SQL-Fehler. Artikel konnte nicht bearbeitet werden.");
|
||||||
|
this.textFieldArticleName.setText("");
|
||||||
|
this.textAreaArticleDescription.setText("");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
this.lblArticleStatus.setText("Artikelname muss ausgef<65>llt sein.");
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
this.articleModeEdit = false;
|
||||||
|
this.articleEditId = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
int re = this.articleTableModel.createArticle(this.textFieldArticleName.getText(), this.textAreaArticleDescription.getText());
|
||||||
|
|
||||||
|
switch(re){
|
||||||
|
case 0:
|
||||||
|
this.lblArticleStatus.setText("Artikel \""+this.textFieldArticleName.getText()+"\" erfolgreich hinzugef<65>gt.");
|
||||||
|
this.textFieldArticleName.setText("");
|
||||||
|
this.textAreaArticleDescription.setText("");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
this.lblArticleStatus.setText("SQL-Fehler. Artikel konnte nicht erstellt werden.");
|
||||||
|
this.textFieldArticleName.setText("");
|
||||||
|
this.textAreaArticleDescription.setText("");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
this.lblArticleStatus.setText("Es muss ein Artikelname vergeben werden");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aktionen f<>r den Button "Artikel abbrechen"
|
||||||
|
*/
|
||||||
|
if(e.getSource() == this.btnArticleCancel){
|
||||||
|
this.articleModeEdit = false;
|
||||||
|
this.textFieldArticleName.setText("");
|
||||||
|
this.textAreaArticleDescription.setText("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModeEditArticle(int articleId, String articleName, String articleDescription) {
|
||||||
|
this.articleModeEdit = true;
|
||||||
|
this.articleEditId = articleId;
|
||||||
|
this.textFieldArticleName.setText(articleName);
|
||||||
|
this.textAreaArticleDescription.setText(articleDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -37,12 +37,12 @@ public class ArticleTableModel extends AbstractTableModel {
|
|||||||
return this.header.length;
|
return this.header.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getRowCount() {
|
public int getRowCount() {
|
||||||
return this.data.size();
|
return this.data.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getValueAt(int pRow, int pCol) {
|
public Object getValueAt(int pRow, int pCol) {
|
||||||
switch(pCol){
|
switch(pCol){
|
||||||
case 0:
|
case 0:
|
||||||
@@ -64,31 +64,105 @@ public class ArticleTableModel extends AbstractTableModel {
|
|||||||
return false;
|
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) {
|
public int getArticleId(int row) {
|
||||||
return this.data.get(row).getId();
|
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){
|
public String getArticleName(int pRow){
|
||||||
return this.data.get(pRow).getName();
|
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){
|
public String getArticleDescription(int pRow){
|
||||||
return this.data.get(pRow).getDescription();
|
return this.data.get(pRow).getDescription();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteArticle(int id) {
|
/**
|
||||||
// TODO Auto-generated method stub
|
* 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.
|
||||||
|
* @return true, wenn der Artikel erfolgreich gel<65>scht wurde. false, wenn ein Fehler aufgetreten ist.
|
||||||
|
*/
|
||||||
|
public boolean deleteArticle(int id) {
|
||||||
|
if(this.dbCon.deleteArticle(id)){
|
||||||
|
int row = this.getRowFromId(id);
|
||||||
|
this.data.remove(row);
|
||||||
|
this.fireTableRowsDeleted(row, row);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Gibt die entsprechende Zeile in der Tabelle f<>r ein Objekt mit der gegebenen ID zur<75>ck.
|
||||||
|
*
|
||||||
|
* @param id ID, f<>r die die Tabellenzeile herausgesucht werden soll
|
||||||
|
* @return Zeile in der Tabelle. -1, wenn die ID nicht vorhanden ist.
|
||||||
|
*/
|
||||||
|
private int getRowFromId(int id) {
|
||||||
|
for (KArticle elem : this.data){
|
||||||
|
if(elem.getId() == id) return data.indexOf(elem);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Erzeugt einen neuen Artikel in der Datenbank und aktualisiert die Tabelle
|
||||||
|
*
|
||||||
|
* @param pName Name des Artikels
|
||||||
|
* @param pDesc Beschreibung des Artikels
|
||||||
|
* @return 0: Artikel erfolgreich erzeugt
|
||||||
|
* 1: SQL-Fehler beim Erzeugen
|
||||||
|
* 2: Feld "Name" leer
|
||||||
|
*/
|
||||||
public int createArticle(String pName, String pDesc) {
|
public int createArticle(String pName, String pDesc) {
|
||||||
// TODO Auto-generated method stub
|
int status = this.dbCon.createArticle(pName, pDesc);
|
||||||
return 0;
|
|
||||||
|
updateTable();
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <20>ndert einen Artikel in der Datenbank und aktualisiert die Tabelle
|
||||||
|
*
|
||||||
|
* @param pId Id des Artikels, der ge<67>ndert werden soll
|
||||||
|
* @param pName (Neuer) Name des Artikels
|
||||||
|
* @param pDesc (Neue) Beschreibung des Artikels
|
||||||
|
* @return 0: Artikel erfolgreich ge<67>ndert
|
||||||
|
* 1: SQL-Fehler beim Erzeugen
|
||||||
|
* 2: Artikelname ist leer
|
||||||
|
*/
|
||||||
public int editArticle(int pId, String pName, String pDesc) {
|
public int editArticle(int pId, String pName, String pDesc) {
|
||||||
// TODO Auto-generated method stub
|
int status = this.dbCon.editArticle(pId, pName, pDesc);
|
||||||
return 0;
|
|
||||||
|
if(status == 0){
|
||||||
|
int row = this.getRowFromId(pId);
|
||||||
|
|
||||||
|
this.data.get(row).setName(pName);
|
||||||
|
this.data.get(row).setDescription(pDesc);
|
||||||
|
this.fireTableRowsUpdated(row, row);
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.katho.kBorrow.gui;
|
package de.katho.kBorrow.gui;
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JTabbedPane;
|
import javax.swing.JTabbedPane;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
@@ -8,62 +7,17 @@ import javax.swing.UnsupportedLookAndFeelException;
|
|||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.JTextField;
|
|
||||||
import javax.swing.border.TitledBorder;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JButton;
|
|
||||||
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import de.katho.kBorrow.db.DbConnector;
|
import de.katho.kBorrow.db.DbConnector;
|
||||||
import de.katho.kBorrow.listener.ArticleDeleteTableButton;
|
|
||||||
import de.katho.kBorrow.listener.ArticleEditTableButton;
|
|
||||||
import de.katho.kBorrow.listener.UserDeleteTableButton;
|
|
||||||
import de.katho.kBorrow.listener.UserEditTableButton;
|
|
||||||
|
|
||||||
import javax.swing.JTable;
|
|
||||||
|
|
||||||
import java.awt.Color;
|
public class MainWindow {
|
||||||
|
|
||||||
import javax.swing.JTextArea;
|
|
||||||
|
|
||||||
import java.awt.Font;
|
|
||||||
|
|
||||||
public class MainWindow implements ActionListener {
|
|
||||||
|
|
||||||
private DbConnector dbCon;
|
private DbConnector dbCon;
|
||||||
private boolean userModeEdit = false;
|
|
||||||
private boolean articleModeEdit = false;
|
|
||||||
private int userEditId;
|
|
||||||
private int articleEditId;
|
|
||||||
|
|
||||||
private JFrame frame;
|
private JFrame frame;
|
||||||
private JTabbedPane tabbedPane;
|
private JTabbedPane tabbedPane;
|
||||||
private JPanel panelUserEdit;
|
|
||||||
private JLabel lblUserName;
|
|
||||||
private JLabel lblUserSurname;
|
|
||||||
private JTextField textFieldUserName;
|
|
||||||
private JTextField textFieldUserSurname;
|
|
||||||
private JButton btnUserSave;
|
|
||||||
private JLabel lblUserStatus;
|
|
||||||
private JTable userTable;
|
|
||||||
private UserTableModel userTableModel;
|
|
||||||
private ArticleTableModel articleTableModel;
|
|
||||||
private JScrollPane scrollUserList;
|
|
||||||
private JPanel panelUserList;
|
|
||||||
private JButton btnUserCancel;
|
|
||||||
private JPanel panelArticleList;
|
|
||||||
private JPanel panelArticleEdit;
|
|
||||||
private JScrollPane scrollArticleList;
|
|
||||||
private JTable articleTable;
|
|
||||||
private JTextField textFieldArticleName;
|
|
||||||
private JButton btnArticleSave;
|
|
||||||
private JButton btnArticleCancel;
|
|
||||||
private JTextArea textAreaArticleDescription;
|
|
||||||
private JLabel lblArticleStatus;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,291 +42,15 @@ public class MainWindow implements ActionListener {
|
|||||||
*/
|
*/
|
||||||
private void initialize() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
|
private void initialize() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
|
||||||
this.frame = new JFrame();
|
this.frame = new JFrame();
|
||||||
frame.setResizable(false);
|
this.frame.setResizable(false);
|
||||||
this.frame.setBounds(100, 100, 600, 500);
|
this.frame.setBounds(100, 100, 600, 500);
|
||||||
this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
|
|
||||||
this.tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
this.tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||||
this.frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
|
this.frame.getContentPane().add(this.tabbedPane, BorderLayout.CENTER);
|
||||||
|
|
||||||
this.initArticleTab();
|
this.tabbedPane.addTab("Artikel verwalten", new ArticleTab(this.dbCon));
|
||||||
this.initUserTab();
|
this.tabbedPane.addTab("Benutzer verwalten", new UserTab(this.dbCon));
|
||||||
}
|
|
||||||
|
|
||||||
private void initArticleTab() {
|
|
||||||
JPanel panelArticle = new JPanel();
|
|
||||||
articleTableModel = new ArticleTableModel(this.dbCon);
|
|
||||||
articleTable = new JTable(articleTableModel);
|
|
||||||
panelArticleList = new JPanel();
|
|
||||||
|
|
||||||
ArticleDeleteTableButton articleDeleteTableButton = new ArticleDeleteTableButton("L<EFBFBD>schen", this.articleTable);
|
|
||||||
articleTable.getColumnModel().getColumn(4).setCellEditor(articleDeleteTableButton);
|
|
||||||
articleTable.getColumnModel().getColumn(4).setCellRenderer(articleDeleteTableButton);
|
|
||||||
|
|
||||||
ArticleEditTableButton articleEditTableButton = new ArticleEditTableButton("Bearbeiten", this.articleTable, this);
|
|
||||||
articleTable.getColumnModel().getColumn(3).setCellEditor(articleEditTableButton);
|
|
||||||
articleTable.getColumnModel().getColumn(3).setCellRenderer(articleEditTableButton);
|
|
||||||
|
|
||||||
this.tabbedPane.addTab("Artikel verwalten", null, panelArticle, null);
|
|
||||||
panelArticle.setLayout(null);
|
|
||||||
|
|
||||||
panelArticleList.setBorder(new TitledBorder(null, "Artikelliste", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
|
||||||
panelArticleList.setBounds(0, 0, 589, 275);
|
|
||||||
panelArticle.add(panelArticleList);
|
|
||||||
panelArticleList.setLayout(new BorderLayout(0, 0));
|
|
||||||
|
|
||||||
articleTable.setFillsViewportHeight(true);
|
|
||||||
scrollArticleList = new JScrollPane(articleTable);
|
|
||||||
panelArticleList.add(scrollArticleList);
|
|
||||||
|
|
||||||
panelArticleEdit = new JPanel();
|
|
||||||
panelArticleEdit.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Artikel hinzuf\u00FCgen / bearbeiten", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
|
|
||||||
panelArticleEdit.setBounds(0, 273, 589, 170);
|
|
||||||
panelArticle.add(panelArticleEdit);
|
|
||||||
panelArticleEdit.setLayout(null);
|
|
||||||
|
|
||||||
JLabel lblNewLabel = new JLabel("Name");
|
|
||||||
lblNewLabel.setBounds(10, 30, 70, 20);
|
|
||||||
panelArticleEdit.add(lblNewLabel);
|
|
||||||
|
|
||||||
JLabel lblBeschreibung = new JLabel("Beschreibung");
|
|
||||||
lblBeschreibung.setBounds(10, 61, 70, 20);
|
|
||||||
panelArticleEdit.add(lblBeschreibung);
|
|
||||||
|
|
||||||
textFieldArticleName = new JTextField();
|
|
||||||
textFieldArticleName.setBounds(90, 30, 250, 20);
|
|
||||||
panelArticleEdit.add(textFieldArticleName);
|
|
||||||
textFieldArticleName.setColumns(10);
|
|
||||||
|
|
||||||
this.textAreaArticleDescription = new JTextArea(5, 30);
|
|
||||||
this.textAreaArticleDescription.setFont(new Font("Tahoma", Font.PLAIN, 11));
|
|
||||||
this.textAreaArticleDescription.setLineWrap(true);
|
|
||||||
this.textAreaArticleDescription.setBounds(90, 59, 250, 80);
|
|
||||||
this.textAreaArticleDescription.setBorder(BorderFactory.createEtchedBorder());
|
|
||||||
panelArticleEdit.add(this.textAreaArticleDescription);
|
|
||||||
|
|
||||||
this.btnArticleSave = new JButton("Speichern");
|
|
||||||
this.btnArticleSave.addActionListener(this);
|
|
||||||
this.btnArticleSave.setBounds(490, 136, 89, 23);
|
|
||||||
panelArticleEdit.add(this.btnArticleSave);
|
|
||||||
|
|
||||||
this.btnArticleCancel = new JButton("Abbrechen");
|
|
||||||
this.btnArticleCancel.addActionListener(this);
|
|
||||||
this.btnArticleCancel.setBounds(490, 102, 89, 23);
|
|
||||||
panelArticleEdit.add(this.btnArticleCancel);
|
|
||||||
|
|
||||||
this.lblArticleStatus = new JLabel("");
|
|
||||||
lblArticleStatus.setBounds(90, 145, 46, 14);
|
|
||||||
panelArticleEdit.add(lblArticleStatus);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initUserTab(){
|
|
||||||
JPanel panelUser = new JPanel();
|
|
||||||
this.tabbedPane.addTab("Benutzer verwalten", null, panelUser, null);
|
|
||||||
|
|
||||||
panelUser.setLayout(null);
|
|
||||||
|
|
||||||
panelUserList = new JPanel();
|
|
||||||
panelUserList.setBounds(0, 0, 589, 320);
|
|
||||||
panelUserList.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Benutzerliste", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
|
||||||
panelUser.add(panelUserList);
|
|
||||||
panelUserList.setLayout(new BorderLayout(0, 0));
|
|
||||||
|
|
||||||
userTableModel = new UserTableModel(this.dbCon);
|
|
||||||
userTable = new JTable(userTableModel);
|
|
||||||
userTable.setFillsViewportHeight(true);
|
|
||||||
|
|
||||||
UserDeleteTableButton userDeleteTableButton = new UserDeleteTableButton("L<EFBFBD>schen", this.userTable);
|
|
||||||
userTable.getColumnModel().getColumn(4).setCellEditor(userDeleteTableButton);
|
|
||||||
userTable.getColumnModel().getColumn(4).setCellRenderer(userDeleteTableButton);
|
|
||||||
|
|
||||||
UserEditTableButton userEditTableButton = new UserEditTableButton("Bearbeiten", this.userTable, this);
|
|
||||||
userTable.getColumnModel().getColumn(3).setCellEditor(userEditTableButton);
|
|
||||||
userTable.getColumnModel().getColumn(3).setCellRenderer(userEditTableButton);
|
|
||||||
|
|
||||||
scrollUserList = new JScrollPane(userTable);
|
|
||||||
panelUserList.add(scrollUserList);
|
|
||||||
scrollUserList.setViewportBorder(null);
|
|
||||||
|
|
||||||
// User-Edit-Pane
|
|
||||||
panelUserEdit = new JPanel();
|
|
||||||
panelUserEdit.setBounds(0, 331, 589, 111);
|
|
||||||
panelUserEdit.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Benutzer hinzuf\u00FCgen / bearbeiten", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
|
||||||
panelUserEdit.setLayout(null);
|
|
||||||
panelUser.add(this.panelUserEdit);
|
|
||||||
|
|
||||||
lblUserName = new JLabel("Vorname");
|
|
||||||
lblUserSurname = new JLabel("Nachname");
|
|
||||||
lblUserStatus = new JLabel("");
|
|
||||||
textFieldUserName = new JTextField();
|
|
||||||
textFieldUserSurname= new JTextField();
|
|
||||||
btnUserSave = new JButton("Speichern");
|
|
||||||
btnUserCancel = new JButton("Abbrechen");
|
|
||||||
|
|
||||||
lblUserName.setBounds(10, 30, 70, 20);
|
|
||||||
textFieldUserName.setBounds(90, 30, 120, 20);
|
|
||||||
textFieldUserName.setColumns(10);
|
|
||||||
lblUserSurname.setBounds(10, 61, 70, 20);
|
|
||||||
textFieldUserSurname.setBounds(90, 61, 121, 20);
|
|
||||||
textFieldUserSurname.setColumns(10);
|
|
||||||
btnUserSave.addActionListener(this);
|
|
||||||
btnUserSave.setBounds(479, 61, 100, 20);
|
|
||||||
btnUserCancel.setBounds(479, 30, 100, 20);
|
|
||||||
btnUserCancel.addActionListener(this);
|
|
||||||
lblUserStatus.setBounds(6, 89, 413, 14);
|
|
||||||
|
|
||||||
panelUserEdit.add(this.lblUserName);
|
|
||||||
panelUserEdit.add(this.textFieldUserName);
|
|
||||||
panelUserEdit.add(this.lblUserSurname);
|
|
||||||
panelUserEdit.add(this.textFieldUserSurname);
|
|
||||||
panelUserEdit.add(this.textFieldUserSurname);
|
|
||||||
panelUserEdit.add(this.btnUserSave);
|
|
||||||
panelUserEdit.add(this.lblUserStatus);
|
|
||||||
panelUserEdit.add(this.btnUserCancel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setModeEditUser(int pId, String pName, String pSurname){
|
|
||||||
this.userModeEdit = true;
|
|
||||||
this.userEditId = pId;
|
|
||||||
this.textFieldUserName.setText(pName);
|
|
||||||
this.textFieldUserSurname.setText(pSurname);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setModeEditArticle(int articleId, String articleName, String articleDescription) {
|
|
||||||
this.articleModeEdit = true;
|
|
||||||
this.articleEditId = articleId;
|
|
||||||
this.textFieldArticleName.setText(articleName);
|
|
||||||
this.textAreaArticleDescription.setText(articleDescription);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Aktionen f<>r den Button "Benutzer speichern"
|
|
||||||
*/
|
|
||||||
if(e.getSource() == this.btnUserSave){
|
|
||||||
if(this.userModeEdit){
|
|
||||||
int re = this.userTableModel.editUser(this.userEditId, this.textFieldUserName.getText(), this.textFieldUserSurname.getText());
|
|
||||||
|
|
||||||
switch(re){
|
|
||||||
case 0:
|
|
||||||
this.lblUserStatus.setText("Benutzer-ID \""+this.userEditId+"\" erfolgreich bearbeitet.");
|
|
||||||
this.textFieldUserName.setText("");
|
|
||||||
this.textFieldUserSurname.setText("");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
this.lblUserStatus.setText("SQL-Fehler. Benutzer konnte nicht bearbeitet werden.");
|
|
||||||
this.textFieldUserName.setText("");
|
|
||||||
this.textFieldUserSurname.setText("");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
this.lblUserStatus.setText("Entweder Vor- oder Nachname m<>ssen ausgef<65>llt sein.");
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this.userModeEdit = false;
|
|
||||||
this.userEditId = -1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
int re = this.userTableModel.createUser(this.textFieldUserName.getText(), this.textFieldUserSurname.getText());
|
|
||||||
|
|
||||||
switch (re){
|
|
||||||
case 0:
|
|
||||||
this.lblUserStatus.setText("Benutzer \""+this.textFieldUserName.getText()+" "+this.textFieldUserSurname.getText()+"\" erfolgreich hinzugef<65>gt.");
|
|
||||||
this.textFieldUserName.setText("");
|
|
||||||
this.textFieldUserSurname.setText("");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
this.lblUserStatus.setText("SQL-Fehler. Benutzer konnte nicht erstellt werden.");
|
|
||||||
this.textFieldUserName.setText("");
|
|
||||||
this.textFieldUserSurname.setText("");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
this.lblUserStatus.setText("Entweder Vor- oder Nachname m<>ssen ausgef<65>llt sein.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Aktionen f<>r den Button "Artikel speichern"
|
|
||||||
*/
|
|
||||||
if(e.getSource() == this.btnArticleSave){
|
|
||||||
if(this.userModeEdit){
|
|
||||||
int re = this.articleTableModel.editArticle(this.articleEditId, this.textFieldArticleName.getText(), this.textAreaArticleDescription.getText());
|
|
||||||
|
|
||||||
switch(re){
|
|
||||||
case 0:
|
|
||||||
this.lblArticleStatus.setText("Artikel-ID \""+this.articleEditId+"\" erfolgreich bearbeitet.");
|
|
||||||
this.textFieldArticleName.setText("");
|
|
||||||
this.textAreaArticleDescription.setText("");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
this.lblArticleStatus.setText("SQL-Fehler. Artikel konnte nicht bearbeitet werden.");
|
|
||||||
this.textFieldArticleName.setText("");
|
|
||||||
this.textAreaArticleDescription.setText("");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
this.lblArticleStatus.setText("Artikelname muss ausgef<65>llt sein.");
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this.articleModeEdit = false;
|
|
||||||
this.articleEditId = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
int re = this.articleTableModel.createArticle(this.textFieldArticleName.getText(), this.textAreaArticleDescription.getText());
|
|
||||||
|
|
||||||
switch(re){
|
|
||||||
case 0:
|
|
||||||
this.lblArticleStatus.setText("Artikel \""+this.textFieldArticleName.getText()+"\" erfolgreich hinzugef<65>gt.");
|
|
||||||
this.textFieldArticleName.setText("");
|
|
||||||
this.textAreaArticleDescription.setText("");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
this.lblArticleStatus.setText("SQL-Fehler. Artikel konnte nicht erstellt werden.");
|
|
||||||
this.textFieldArticleName.setText("");
|
|
||||||
this.textAreaArticleDescription.setText("");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
this.lblArticleStatus.setText("Es muss ein Artikelname vergeben werden");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Aktionen f<>r den Button "Benutzer abbrechen"
|
|
||||||
*/
|
|
||||||
if(e.getSource() == this.btnUserCancel){
|
|
||||||
this.userModeEdit = false;
|
|
||||||
this.textFieldUserName.setText("");
|
|
||||||
this.textFieldUserSurname.setText("");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Aktionen f<>r den Button "Artikel abbrechen"
|
|
||||||
*/
|
|
||||||
if(e.getSource() == this.btnArticleCancel){
|
|
||||||
this.articleModeEdit = false;
|
|
||||||
this.textFieldArticleName.setText("");
|
|
||||||
this.textAreaArticleDescription.setText("");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
166
src/de/katho/kBorrow/gui/UserTab.java
Normal file
166
src/de/katho/kBorrow/gui/UserTab.java
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
package de.katho.kBorrow.gui;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.border.TitledBorder;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.db.DbConnector;
|
||||||
|
import de.katho.kBorrow.listener.UserDeleteTableButton;
|
||||||
|
import de.katho.kBorrow.listener.UserEditTableButton;
|
||||||
|
|
||||||
|
public class UserTab extends JPanel implements ActionListener {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -319340262589243978L;
|
||||||
|
private JLabel lblUserStatus;
|
||||||
|
private JTextField textFieldUserName;
|
||||||
|
private JTextField textFieldUserSurname;
|
||||||
|
private JButton btnUserSave;
|
||||||
|
private JButton btnUserCancel;
|
||||||
|
private boolean userModeEdit;
|
||||||
|
private int userEditId;
|
||||||
|
private UserTableModel userTableModel;
|
||||||
|
|
||||||
|
public UserTab(final DbConnector dbCon){
|
||||||
|
super();
|
||||||
|
this.setLayout(null);
|
||||||
|
|
||||||
|
//Tabelle und drumherum
|
||||||
|
this.userTableModel = new UserTableModel(dbCon);
|
||||||
|
JTable userTable = new JTable(userTableModel);
|
||||||
|
UserDeleteTableButton userDeleteTableButton = new UserDeleteTableButton("L<EFBFBD>schen", userTable);
|
||||||
|
userTable.getColumnModel().getColumn(4).setCellEditor(userDeleteTableButton);
|
||||||
|
userTable.getColumnModel().getColumn(4).setCellRenderer(userDeleteTableButton);
|
||||||
|
|
||||||
|
UserEditTableButton userEditTableButton = new UserEditTableButton("Bearbeiten", userTable, this);
|
||||||
|
userTable.getColumnModel().getColumn(3).setCellEditor(userEditTableButton);
|
||||||
|
userTable.getColumnModel().getColumn(3).setCellRenderer(userEditTableButton);
|
||||||
|
|
||||||
|
userTable.setFillsViewportHeight(true);
|
||||||
|
|
||||||
|
//Panel Userlist
|
||||||
|
JPanel panelUserList = new JPanel();
|
||||||
|
panelUserList.setBounds(0, 0, 589, 320);
|
||||||
|
panelUserList.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Benutzerliste", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||||
|
panelUserList.setLayout(new BorderLayout(0, 0));
|
||||||
|
panelUserList.add(new JScrollPane(userTable));
|
||||||
|
|
||||||
|
// Edit: Labels
|
||||||
|
JLabel lblUserName = new JLabel("Vorname");
|
||||||
|
JLabel lblUserSurname = new JLabel("Nachname");
|
||||||
|
this.lblUserStatus = new JLabel("");
|
||||||
|
lblUserName.setBounds(10, 30, 70, 20);
|
||||||
|
lblUserSurname.setBounds(10, 61, 70, 20);
|
||||||
|
lblUserStatus.setBounds(6, 89, 413, 14);
|
||||||
|
|
||||||
|
//Edit: Textfields
|
||||||
|
textFieldUserName = new JTextField();
|
||||||
|
textFieldUserSurname= new JTextField();
|
||||||
|
textFieldUserName.setBounds(90, 30, 120, 20);
|
||||||
|
textFieldUserName.setColumns(10);
|
||||||
|
textFieldUserSurname.setBounds(90, 61, 121, 20);
|
||||||
|
textFieldUserSurname.setColumns(10);
|
||||||
|
|
||||||
|
// Edit: Buttons
|
||||||
|
btnUserSave = new JButton("Speichern");
|
||||||
|
btnUserCancel = new JButton("Abbrechen");
|
||||||
|
btnUserSave.addActionListener(this);
|
||||||
|
btnUserSave.setBounds(479, 61, 100, 20);
|
||||||
|
btnUserCancel.setBounds(479, 30, 100, 20);
|
||||||
|
btnUserCancel.addActionListener(this);
|
||||||
|
|
||||||
|
// User-Edit-Pane
|
||||||
|
JPanel panelUserEdit = new JPanel();
|
||||||
|
panelUserEdit.setBounds(0, 331, 589, 111);
|
||||||
|
panelUserEdit.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Benutzer hinzuf\u00FCgen / bearbeiten", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||||
|
panelUserEdit.setLayout(null);
|
||||||
|
panelUserEdit.add(lblUserName);
|
||||||
|
panelUserEdit.add(this.textFieldUserName);
|
||||||
|
panelUserEdit.add(lblUserSurname);
|
||||||
|
panelUserEdit.add(this.textFieldUserSurname);
|
||||||
|
panelUserEdit.add(this.textFieldUserSurname);
|
||||||
|
panelUserEdit.add(this.btnUserSave);
|
||||||
|
panelUserEdit.add(this.lblUserStatus);
|
||||||
|
panelUserEdit.add(this.btnUserCancel);
|
||||||
|
|
||||||
|
this.add(panelUserList);
|
||||||
|
this.add(panelUserEdit);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if(e.getSource() == this.btnUserSave){
|
||||||
|
if(this.userModeEdit){
|
||||||
|
int re = this.userTableModel.editUser(this.userEditId, this.textFieldUserName.getText(), this.textFieldUserSurname.getText());
|
||||||
|
|
||||||
|
switch(re){
|
||||||
|
case 0:
|
||||||
|
this.lblUserStatus.setText("Benutzer-ID \""+this.userEditId+"\" erfolgreich bearbeitet.");
|
||||||
|
this.textFieldUserName.setText("");
|
||||||
|
this.textFieldUserSurname.setText("");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
this.lblUserStatus.setText("SQL-Fehler. Benutzer konnte nicht bearbeitet werden.");
|
||||||
|
this.textFieldUserName.setText("");
|
||||||
|
this.textFieldUserSurname.setText("");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
this.lblUserStatus.setText("Entweder Vor- oder Nachname m<>ssen ausgef<65>llt sein.");
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
this.userModeEdit = false;
|
||||||
|
this.userEditId = -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int re = this.userTableModel.createUser(this.textFieldUserName.getText(), this.textFieldUserSurname.getText());
|
||||||
|
|
||||||
|
switch (re){
|
||||||
|
case 0:
|
||||||
|
this.lblUserStatus.setText("Benutzer \""+this.textFieldUserName.getText()+" "+this.textFieldUserSurname.getText()+"\" erfolgreich hinzugef<65>gt.");
|
||||||
|
this.textFieldUserName.setText("");
|
||||||
|
this.textFieldUserSurname.setText("");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
this.lblUserStatus.setText("SQL-Fehler. Benutzer konnte nicht erstellt werden.");
|
||||||
|
this.textFieldUserName.setText("");
|
||||||
|
this.textFieldUserSurname.setText("");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
this.lblUserStatus.setText("Entweder Vor- oder Nachname m<>ssen ausgef<65>llt sein.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aktionen f<>r den Button "Benutzer abbrechen"
|
||||||
|
*/
|
||||||
|
if(e.getSource() == this.btnUserCancel){
|
||||||
|
this.userModeEdit = false;
|
||||||
|
this.textFieldUserName.setText("");
|
||||||
|
this.textFieldUserSurname.setText("");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setModeEditUser(int pId, String pName, String pSurname){
|
||||||
|
this.userModeEdit = true;
|
||||||
|
this.userEditId = pId;
|
||||||
|
this.textFieldUserName.setText(pName);
|
||||||
|
this.textFieldUserSurname.setText(pSurname);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,8 +5,8 @@ import java.awt.event.ActionListener;
|
|||||||
|
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
|
|
||||||
|
import de.katho.kBorrow.gui.ArticleTab;
|
||||||
import de.katho.kBorrow.gui.ArticleTableModel;
|
import de.katho.kBorrow.gui.ArticleTableModel;
|
||||||
import de.katho.kBorrow.gui.MainWindow;
|
|
||||||
|
|
||||||
public class ArticleEditTableButton extends TableButton {
|
public class ArticleEditTableButton extends TableButton {
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ public class ArticleEditTableButton extends TableButton {
|
|||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -5902626427691636902L;
|
private static final long serialVersionUID = -5902626427691636902L;
|
||||||
|
|
||||||
public ArticleEditTableButton(String pLabel, JTable pTable, final MainWindow pMainWindow) {
|
public ArticleEditTableButton(String pLabel, JTable pTable, final ArticleTab articleTab) {
|
||||||
super(pLabel, pTable);
|
super(pLabel, pTable);
|
||||||
|
|
||||||
this.buttonE.addActionListener(new ActionListener(){
|
this.buttonE.addActionListener(new ActionListener(){
|
||||||
@@ -25,7 +25,7 @@ public class ArticleEditTableButton extends TableButton {
|
|||||||
ArticleTableModel model = (ArticleTableModel) table.getModel();
|
ArticleTableModel model = (ArticleTableModel) table.getModel();
|
||||||
int row = table.getSelectedRow();
|
int row = table.getSelectedRow();
|
||||||
|
|
||||||
pMainWindow.setModeEditArticle(model.getArticleId(row), model.getArticleName(row), model.getArticleDescription(row));
|
articleTab.setModeEditArticle(model.getArticleId(row), model.getArticleName(row), model.getArticleDescription(row));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import java.awt.event.ActionListener;
|
|||||||
|
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
|
|
||||||
import de.katho.kBorrow.gui.MainWindow;
|
import de.katho.kBorrow.gui.UserTab;
|
||||||
import de.katho.kBorrow.gui.UserTableModel;
|
import de.katho.kBorrow.gui.UserTableModel;
|
||||||
|
|
||||||
public class UserEditTableButton extends TableButton {
|
public class UserEditTableButton extends TableButton {
|
||||||
@@ -15,7 +15,7 @@ public class UserEditTableButton extends TableButton {
|
|||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -886584066497429394L;
|
private static final long serialVersionUID = -886584066497429394L;
|
||||||
|
|
||||||
public UserEditTableButton(String pLabel, JTable pTable, final MainWindow pMainWindow){
|
public UserEditTableButton(String pLabel, JTable pTable, final UserTab pPanel){
|
||||||
super(pLabel, pTable);
|
super(pLabel, pTable);
|
||||||
|
|
||||||
this.buttonE.addActionListener(new ActionListener(){
|
this.buttonE.addActionListener(new ActionListener(){
|
||||||
@@ -25,7 +25,7 @@ public class UserEditTableButton extends TableButton {
|
|||||||
UserTableModel model = (UserTableModel) table.getModel();
|
UserTableModel model = (UserTableModel) table.getModel();
|
||||||
int row = table.getSelectedRow();
|
int row = table.getSelectedRow();
|
||||||
|
|
||||||
pMainWindow.setModeEditUser(model.getUserId(row), model.getUserName(row), model.getUserSurname(row));
|
pPanel.setModeEditUser(model.getUserId(row), model.getUserName(row), model.getUserSurname(row));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user