Java tutorial
import POJO.Film; import POJO.Gatunek; import POJO.GatunekFilm; import POJO.GatunekFilmId; import POJO.Klient; import POJO.Nosnik; import POJO.Pracownik; import POJO.Rezyser; import POJO.Transakcja; import java.awt.Color; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Vector; import javax.swing.DefaultListModel; import javax.swing.ListModel; import javax.swing.table.DefaultTableModel; import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.Session; import util.NewHibernateUtil; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author menf */ public class NewJFrame extends javax.swing.JFrame { private static String QUERY_BASED_ON_FIRST_NAME = "from Klient a where a.imie like '"; private static String QUERY_BASED_ON_LAST_NAME = "from Klient a where a.nazwisko like '"; private Session session; private int ROLE = -1; private int loggedId = -1; /** * Creates new form NewJFrame */ public NewJFrame() { initComponents(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { loginPanel = new javax.swing.JPanel(); passField = new javax.swing.JPasswordField(); loginButton = new javax.swing.JButton(); logField = new javax.swing.JTextField(); label1 = new java.awt.Label(); label2 = new java.awt.Label(); label3 = new java.awt.Label(); loginError = new javax.swing.JLabel(); moviesPanel = new javax.swing.JPanel(); jScrollPane2 = new javax.swing.JScrollPane(); moviesTable = new javax.swing.JTable(); jLabel4 = new javax.swing.JLabel(); orderButton = new javax.swing.JButton(); addMoviePanel = new javax.swing.JPanel(); jLabel5 = new javax.swing.JLabel(); newMovieTitle = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); newMovieYear = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); newMovieQuant = new javax.swing.JTextField(); jLabel8 = new javax.swing.JLabel(); newMovieCarrier = new javax.swing.JComboBox<>(); jLabel9 = new javax.swing.JLabel(); newMovieDirector = new javax.swing.JComboBox<>(); addMovieButton = new javax.swing.JButton(); newMovieError = new javax.swing.JLabel(); addMovieSuccess = new javax.swing.JLabel(); jScrollPanee = new javax.swing.JScrollPane(); newMovieGenre = new javax.swing.JList<>(); jLabel11 = new javax.swing.JLabel(); removeMoviePanel = new javax.swing.JPanel(); removeMovieError = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); removeMovieButton = new javax.swing.JButton(); jScrollPane4 = new javax.swing.JScrollPane(); removeMovieTable = new javax.swing.JTable(); removeMovieSuccess = new javax.swing.JLabel(); transactionPanel = new javax.swing.JPanel(); jScrollPane3 = new javax.swing.JScrollPane(); transactionTable = new javax.swing.JTable(); acceptTransactionButton = new javax.swing.JButton(); declineTransactionButton = new javax.swing.JButton(); addGenrePanel = new javax.swing.JPanel(); jLabel10 = new javax.swing.JLabel(); newGenreName = new javax.swing.JTextField(); newGenreNotify = new javax.swing.JLabel(); addGenreButton = new javax.swing.JButton(); removeGenrePanel = new javax.swing.JPanel(); removeGenreButton = new javax.swing.JButton(); removeGenreNotify = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); removeGenreTable = new javax.swing.JTable(); jLabel2 = new javax.swing.JLabel(); jMenuBar1 = new javax.swing.JMenuBar(); transakcjeMenu = new javax.swing.JMenu(); adminMenu = new javax.swing.JMenu(); jMenu1 = new javax.swing.JMenu(); addMovie = new javax.swing.JMenuItem(); removeMovie = new javax.swing.JMenuItem(); jMenu2 = new javax.swing.JMenu(); addGatunekMenuItem = new javax.swing.JMenuItem(); removeGatunekMenuItem = new javax.swing.JMenuItem(); moviesMenu = new javax.swing.JMenu(); menuLogOut = new javax.swing.JMenu(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); loginPanel.setName("jPanel_Login"); // NOI18N loginButton.setLabel("Zaloguj"); loginButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { loginButtonActionPerformed(evt); } }); label1.setMinimumSize(new java.awt.Dimension(40, 20)); label1.setText("Login:"); label2.setText("Haso:"); label3.setAlignment(java.awt.Label.CENTER); label3.setFont(new java.awt.Font("Dialog", 0, 18)); // NOI18N label3.setText("Logowanie"); loginError.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N loginError.setForeground(new java.awt.Color(255, 0, 51)); loginError.setText("Bld uwierzytelniania"); javax.swing.GroupLayout loginPanelLayout = new javax.swing.GroupLayout(loginPanel); loginPanel.setLayout(loginPanelLayout); loginPanelLayout.setHorizontalGroup(loginPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(loginPanelLayout.createSequentialGroup().addContainerGap().addGroup(loginPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(label3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, loginPanelLayout.createSequentialGroup().addGap(97, 97, 97) .addGroup(loginPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(label2, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(loginPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(passField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE) .addComponent(logField))) .addGroup(loginPanelLayout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(loginButton))) .addGap(135, 135, 135)) .addGroup(loginPanelLayout.createSequentialGroup().addComponent(loginError, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))); loginPanelLayout.setVerticalGroup( loginPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, loginPanelLayout.createSequentialGroup().addGap(54, 54, 54) .addComponent(label3, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(loginPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(label1, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE) .addComponent(logField)) .addGap(12, 12, 12) .addGroup(loginPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(label2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(passField)) .addGap(18, 18, 18).addComponent(loginButton).addGap(30, 30, 30) .addComponent(loginError).addContainerGap(96, Short.MAX_VALUE))); moviesTable.setAutoCreateRowSorter(true); moviesTable.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null } }, new String[] { "Title 1", "Title 2", "Title 3", "Title 4" }) { boolean[] canEdit = new boolean[] { false, false, false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); moviesTable.getTableHeader().setReorderingAllowed(false); moviesTable.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { moviesTableMouseClicked(evt); } }); jScrollPane2.setViewportView(moviesTable); jLabel4.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel4.setText("Dostpne pozycje"); orderButton.setText("Zamw"); orderButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { orderButtonActionPerformed(evt); } }); javax.swing.GroupLayout moviesPanelLayout = new javax.swing.GroupLayout(moviesPanel); moviesPanel.setLayout(moviesPanelLayout); moviesPanelLayout.setHorizontalGroup(moviesPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 613, Short.MAX_VALUE) .addGroup(moviesPanelLayout.createSequentialGroup() .addGroup(moviesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(moviesPanelLayout.createSequentialGroup().addGap(182, 182, 182) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(moviesPanelLayout.createSequentialGroup().addContainerGap() .addComponent(orderButton))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); moviesPanelLayout .setVerticalGroup(moviesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(moviesPanelLayout.createSequentialGroup().addContainerGap().addComponent(jLabel4) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(orderButton) .addContainerGap(59, Short.MAX_VALUE))); jLabel5.setText("Tytu"); jLabel6.setText("Rok produkcji"); jLabel7.setText("Ilo"); jLabel8.setText("Nonik"); newMovieCarrier.setModel( new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); jLabel9.setText("Reyser"); newMovieDirector.setModel( new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); addMovieButton.setText("Dodaj Film"); addMovieButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addMovieButtonActionPerformed(evt); } }); newMovieError.setForeground(new java.awt.Color(255, 0, 51)); newMovieError.setText("Wprowad poprawne dane!"); addMovieSuccess.setForeground(new java.awt.Color(51, 255, 0)); addMovieSuccess.setText("Dodano film do bazy!"); newMovieGenre.setModel(new javax.swing.AbstractListModel<String>() { String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; public int getSize() { return strings.length; } public String getElementAt(int i) { return strings[i]; } }); jScrollPanee.setViewportView(newMovieGenre); jLabel11.setText("Gatunek"); javax.swing.GroupLayout addMoviePanelLayout = new javax.swing.GroupLayout(addMoviePanel); addMoviePanel.setLayout(addMoviePanelLayout); addMoviePanelLayout .setHorizontalGroup( addMoviePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( addMoviePanelLayout.createSequentialGroup().addContainerGap() .addGroup(addMoviePanelLayout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup( addMoviePanelLayout.createSequentialGroup() .addComponent(newMovieError) .addGap(63, 63, 63) .addComponent( addMovieSuccess) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(addMoviePanelLayout.createSequentialGroup() .addGroup(addMoviePanelLayout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel9).addComponent(jLabel8) .addComponent(jLabel7).addComponent(jLabel6) .addComponent(jLabel5)) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE) .addGroup( addMoviePanelLayout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(newMovieTitle, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE) .addComponent( newMovieYear, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(newMovieQuant, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(newMovieCarrier, javax.swing.GroupLayout.Alignment.TRAILING, 0, 130, Short.MAX_VALUE) .addComponent(newMovieDirector, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(addMoviePanelLayout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup(addMoviePanelLayout .createSequentialGroup() .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE) .addGroup(addMoviePanelLayout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent( addMovieButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jScrollPanee)) .addGap(49, 49, 49)) .addGroup(addMoviePanelLayout .createSequentialGroup() .addGap(47, 47, 47) .addComponent(jLabel11) .addContainerGap( javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))))); addMoviePanelLayout.setVerticalGroup(addMoviePanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(addMoviePanelLayout.createSequentialGroup().addGap(67, 67, 67) .addGroup(addMoviePanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(addMoviePanelLayout.createSequentialGroup().addGroup(addMoviePanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(newMovieTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(addMoviePanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(newMovieYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(addMoviePanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(newMovieQuant, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(addMoviePanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(newMovieCarrier, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGroup(addMoviePanelLayout.createSequentialGroup() .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPanee, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(addMoviePanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(newMovieDirector, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(addMovieButton)) .addGap(33, 33, 33) .addGroup( addMoviePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(newMovieError).addComponent(addMovieSuccess)) .addContainerGap(43, Short.MAX_VALUE))); removeMovieError.setForeground(new java.awt.Color(255, 0, 0)); removeMovieError.setText("Nie mona usun filmu!"); jLabel12.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel12.setText("Wybierz film"); removeMovieButton.setText("Usu Film"); removeMovieButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { removeMovieButtonActionPerformed(evt); } }); removeMovieTable .setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null } }, new String[] { "Title 1", "Title 2", "Title 3", "Title 4" })); jScrollPane4.setViewportView(removeMovieTable); removeMovieSuccess.setForeground(new java.awt.Color(0, 204, 0)); removeMovieSuccess.setText("Pomylnie usunito film!"); javax.swing.GroupLayout removeMoviePanelLayout = new javax.swing.GroupLayout(removeMoviePanel); removeMoviePanel.setLayout(removeMoviePanelLayout); removeMoviePanelLayout.setHorizontalGroup(removeMoviePanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(removeMoviePanelLayout.createSequentialGroup().addGroup(removeMoviePanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(removeMoviePanelLayout.createSequentialGroup().addContainerGap() .addComponent(removeMovieError).addGap(33, 33, 33).addComponent(removeMovieButton) .addGap(40, 40, 40).addComponent(removeMovieSuccess, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(removeMoviePanelLayout.createSequentialGroup().addContainerGap().addComponent( jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(removeMoviePanelLayout.createSequentialGroup().addGap(150, 150, 150).addComponent( jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); removeMoviePanelLayout.setVerticalGroup( removeMoviePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, removeMoviePanelLayout.createSequentialGroup() .addGroup(removeMoviePanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(removeMoviePanelLayout .createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(removeMovieSuccess)) .addGroup(removeMoviePanelLayout.createSequentialGroup().addGap(33, 33, 33) .addComponent(jLabel12) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE) .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(removeMoviePanelLayout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup( removeMoviePanelLayout .createSequentialGroup().addGap( 22, 22, 22) .addComponent(removeMovieError)) .addGroup(removeMoviePanelLayout.createSequentialGroup() .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(removeMovieButton))))) .addGap(23, 23, 23))); transactionTable .setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null } }, new String[] { "Title 1", "Title 2", "Title 3", "Title 4" })); jScrollPane3.setViewportView(transactionTable); acceptTransactionButton.setText("Zatwierd Transakcj"); acceptTransactionButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { acceptTransactionButtonActionPerformed(evt); } }); declineTransactionButton.setText("Odrzu Transakcj"); declineTransactionButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { declineTransactionButtonActionPerformed(evt); } }); javax.swing.GroupLayout transactionPanelLayout = new javax.swing.GroupLayout(transactionPanel); transactionPanel.setLayout(transactionPanelLayout); transactionPanelLayout.setHorizontalGroup( transactionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 476, Short.MAX_VALUE) .addGroup(transactionPanelLayout.createSequentialGroup().addContainerGap() .addComponent(acceptTransactionButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(declineTransactionButton, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap())); transactionPanelLayout.setVerticalGroup(transactionPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(transactionPanelLayout.createSequentialGroup().addGap(77, 77, 77) .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(transactionPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(acceptTransactionButton).addComponent(declineTransactionButton)) .addContainerGap(106, Short.MAX_VALUE))); jLabel10.setText("Nazwa"); addGenreButton.setText("Dodaj"); addGenreButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addGenreButtonActionPerformed(evt); } }); javax.swing.GroupLayout addGenrePanelLayout = new javax.swing.GroupLayout(addGenrePanel); addGenrePanel.setLayout(addGenrePanelLayout); addGenrePanelLayout.setHorizontalGroup( addGenrePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, addGenrePanelLayout.createSequentialGroup().addContainerGap() .addComponent(newGenreNotify, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(addGenrePanelLayout.createSequentialGroup() .addGroup(addGenrePanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(addGenrePanelLayout.createSequentialGroup().addGap(61, 61, 61) .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(newGenreName, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(addGenrePanelLayout.createSequentialGroup().addGap(144, 144, 144) .addComponent(addGenreButton))) .addContainerGap(130, Short.MAX_VALUE))); addGenrePanelLayout .setVerticalGroup(addGenrePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(addGenrePanelLayout.createSequentialGroup().addGap(107, 107, 107) .addGroup(addGenrePanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(newGenreName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18).addComponent(addGenreButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE) .addComponent(newGenreNotify, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(44, 44, 44))); removeGenreButton.setText("Usu"); removeGenreButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { removeGenreButtonActionPerformed(evt); } }); removeGenreNotify.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); removeGenreTable .setModel(new javax.swing.table.DefaultTableModel(new Object[][] { {}, {}, {}, {} }, new String[] { })); jScrollPane1.setViewportView(removeGenreTable); jLabel2.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel2.setText("Gatunki"); javax.swing.GroupLayout removeGenrePanelLayout = new javax.swing.GroupLayout(removeGenrePanel); removeGenrePanel.setLayout(removeGenrePanelLayout); removeGenrePanelLayout.setHorizontalGroup(removeGenrePanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(removeGenrePanelLayout.createSequentialGroup().addGroup(removeGenrePanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(removeGenrePanelLayout.createSequentialGroup().addContainerGap().addComponent( removeGenreNotify, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(removeGenrePanelLayout.createSequentialGroup().addGap(157, 157, 157) .addComponent(removeGenreButton).addGap(0, 0, Short.MAX_VALUE)) .addGroup(removeGenrePanelLayout.createSequentialGroup().addContainerGap().addComponent( jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))) .addContainerGap()) .addGroup(removeGenrePanelLayout .createSequentialGroup().addGap(120, 120, 120).addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(136, Short.MAX_VALUE))); removeGenrePanelLayout.setVerticalGroup(removeGenrePanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, removeGenrePanelLayout.createSequentialGroup() .addGap(36, 36, 36).addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(removeGenreButton).addGap(18, 18, 18) .addComponent(removeGenreNotify).addGap(64, 64, 64))); transakcjeMenu.setText("Transakcje"); transakcjeMenu.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { transakcjeMenuMouseClicked(evt); } }); jMenuBar1.add(transakcjeMenu); adminMenu.setText("Administracja"); jMenu1.setText("Film"); addMovie.setText("Dodaj Film"); addMovie.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addMovieActionPerformed(evt); } }); jMenu1.add(addMovie); removeMovie.setText("Usu Film"); removeMovie.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { removeMovieActionPerformed(evt); } }); jMenu1.add(removeMovie); adminMenu.add(jMenu1); jMenu2.setText("Gatunek"); addGatunekMenuItem.setText("Dodaj Gatunek"); addGatunekMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addGatunekMenuItemActionPerformed(evt); } }); jMenu2.add(addGatunekMenuItem); removeGatunekMenuItem.setText("Usu Gatunek"); removeGatunekMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { removeGatunekMenuItemActionPerformed(evt); } }); jMenu2.add(removeGatunekMenuItem); adminMenu.add(jMenu2); jMenuBar1.add(adminMenu); moviesMenu.setText("Baza Filmw"); moviesMenu.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { moviesMenuMouseClicked(evt); } }); jMenuBar1.add(moviesMenu); menuLogOut.setText("Wyloguj"); menuLogOut.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { menuLogOutMouseClicked(evt); } }); jMenuBar1.add(menuLogOut); menuLogOut.getAccessibleContext().setAccessibleName("jMenu_User"); menuLogOut.getAccessibleContext().setAccessibleDescription(""); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 615, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(loginPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(moviesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(addMoviePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(removeMoviePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(transactionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(addGenrePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(removeGenrePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE)))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 379, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(loginPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(moviesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(addMoviePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(removeMoviePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(transactionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(addGenrePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE))) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(removeGenrePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE)))); loginPanel.getAccessibleContext().setAccessibleName("jPanel_Login"); moviesPanel.getAccessibleContext().setAccessibleName(""); pack(); }// </editor-fold>//GEN-END:initComponents private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginButtonActionPerformed String pass = new String(passField.getPassword()); if (!logField.getText().trim().equals("") && pass.length() > 0) { loginError.setVisible(false); try { session = NewHibernateUtil.getSessionFactory().openSession(); List uzytkownicy; session.beginTransaction(); Query query = session.createQuery( "from Klient where login is '" + logField.getText() + "' and haslo is '" + pass + "'"); uzytkownicy = query.list(); session.getTransaction().commit(); if (!uzytkownicy.isEmpty()) { ROLE = 0; loggedId = ((Klient) uzytkownicy.get(0)).getIdKlienta(); loginPanel.setVisible(false); showMovies(); moviesPanel.setVisible(true); } else { session = NewHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); query = session.createQuery("from Pracownik where login is '" + logField.getText() + "' and haslo is '" + pass + "'"); uzytkownicy = query.list(); if (!uzytkownicy.isEmpty()) { Pracownik p = (Pracownik) uzytkownicy.get(0); if (p.getIdStanowiska() == 1) { ROLE = 1; showMovies(); moviesPanel.setVisible(true); } else { ROLE = 2; setVisibilities(); showTransactions(); transactionPanel.setVisible(true); } loggedId = ((Pracownik) uzytkownicy.get(0)).getIdPracownika(); loginPanel.setVisible(false); } loginError.setVisible(true); } } catch (HibernateException he) { he.printStackTrace(); } } setVisibilities(); }//GEN-LAST:event_loginButtonActionPerformed private void moviesMenuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_moviesMenuMouseClicked // TODO add your handling code here: if (!moviesPanel.isVisible()) { hideAll(); moviesPanel.setVisible(true); showMovies(); } }//GEN-LAST:event_moviesMenuMouseClicked private void menuLogOutMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_menuLogOutMouseClicked // TODO add your handling code here: ROLE = -1; loggedId = -1; hideAll(); loginPanel.setVisible(true); setVisibilities(); }//GEN-LAST:event_menuLogOutMouseClicked private void addMovieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addMovieActionPerformed // TODO add your handling code here: if (!addMoviePanel.isVisible()) { hideAll(); addMoviePanel.setVisible(true); List carriers = null, directors = null, genres = null; newMovieCarrier.removeAllItems(); session = NewHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Query q = session.createQuery("from Nosnik order by idNosnika"); carriers = q.list(); session.getTransaction().commit(); for (Object nosnik : carriers) { newMovieCarrier.addItem(((Nosnik) nosnik).getTyp()); } newMovieDirector.removeAllItems(); session.beginTransaction(); q = session.createQuery("from Rezyser order by idRezysera"); directors = q.list(); session.getTransaction().commit(); for (Object rezyser : directors) { newMovieDirector.addItem(((Rezyser) rezyser).getImie() + " " + ((Rezyser) rezyser).getNazwisko()); } newMovieGenre.setListData(new String[0]); DefaultListModel listModel = new DefaultListModel(); listModel.removeAllElements(); session.beginTransaction(); q = session.createQuery("from Gatunek order by idGatunku"); genres = q.list(); session.getTransaction().commit(); for (Object gatunek : genres) { listModel.addElement(((Gatunek) gatunek).getIdGatunku() + ". " + ((Gatunek) gatunek).getNazwa()); } newMovieGenre.setModel(listModel); session.close(); } }//GEN-LAST:event_addMovieActionPerformed private void removeMovieButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeMovieButtonActionPerformed // TODO add your handling code here: int id = Integer .parseInt(removeMovieTable.getModel().getValueAt(removeMovieTable.getSelectedRow(), 0).toString()); try { session = NewHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Query query = session.createQuery("delete GatunekFilm where id.idFilmu =:id"); query.setParameter("id", id); int result1 = query.executeUpdate(); session.getTransaction().commit(); session.beginTransaction(); query = session.createQuery("delete Film where idFilmu =:id"); query.setParameter("id", id); int result = query.executeUpdate(); if (result > 0) { removeMovieSuccess.setVisible(true); } } catch (HibernateException he) { he.printStackTrace(); removeMovieError.setVisible(true); } finally { session.getTransaction().commit(); session.close(); reloadRemoveMoviesTable(); } }//GEN-LAST:event_removeMovieButtonActionPerformed private void reloadRemoveMoviesTable() { removeMoviePanel.setVisible(true); session = NewHibernateUtil.getSessionFactory().openSession(); List moviesList = null, directorList = null; removeMovieTable.removeAll(); try { session.beginTransaction(); Query q = session.createQuery("from Film"); moviesList = q.list(); session.getTransaction().commit(); } catch (HibernateException he) { he.printStackTrace(); } finally { session.close(); } Vector<String> tableHeaders = new Vector<>(); Vector tableData = new Vector(); tableHeaders.add("Id"); tableHeaders.add("Tytu"); tableHeaders.add("Rok Produkcji"); tableHeaders.add("Reyser"); tableHeaders.add("Nonik"); tableHeaders.add("Dostpno"); if (!moviesList.isEmpty()) { session = NewHibernateUtil.getSessionFactory().openSession(); Film film; session.beginTransaction(); Query q; for (Object o : moviesList) { film = (Film) o; Vector<Object> oneRow = new Vector<>(); q = session.createQuery("from Rezyser a where a.idRezysera IS " + film.getIdRezysera().toString()); directorList = q.list(); q = session.createQuery("from Nosnik a where a.idNosnika IS " + film.getIdNosnika().toString()); oneRow.add(film.getIdFilmu()); oneRow.add(film.getTytul()); oneRow.add(film.getRokProdukcji()); oneRow.add(((Rezyser) (directorList.get(0))).getNazwisko()); oneRow.add(((Nosnik) q.list().get(0)).getTyp()); if (film.getIlosc() > 0) { oneRow.add("Dostpny"); } else { oneRow.add("Niedostpny"); } tableData.add(oneRow); } session.getTransaction().commit(); removeMovieTable.setModel(new DefaultTableModel(tableData, tableHeaders) { public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }); removeMovieTable.removeColumn(removeMovieTable.getColumnModel().getColumn(0)); session.close(); } } private void removeMovieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeMovieActionPerformed if (!removeMoviePanel.isVisible()) { hideAll(); reloadRemoveMoviesTable(); } }//GEN-LAST:event_removeMovieActionPerformed private void orderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_orderButtonActionPerformed if (moviesTable.getSelectedRow() != -1) { if (moviesTable.getValueAt(moviesTable.getSelectedRow(), 4).toString().equalsIgnoreCase("Dostpny")) { session = NewHibernateUtil.getSessionFactory().openSession(); try { Transakcja t; t = new Transakcja(); t.setIdKlienta(loggedId); t.setIdFilmu(Integer.parseInt( moviesTable.getModel().getValueAt(moviesTable.getSelectedRow(), 0).toString())); DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd"); Date date = new Date(); t.setDataTransakcji(date); t.setTyp("WYP"); session.beginTransaction(); session.save(t); session.getTransaction().commit(); session.beginTransaction(); Query query = session.createQuery("update Film set ilosc =ilosc - 1 where idFilmu =:id"); query.setParameter("id", Integer.parseInt( moviesTable.getModel().getValueAt(moviesTable.getSelectedRow(), 0).toString())); query.executeUpdate(); session.getTransaction().commit(); session.flush(); moviesPanel.setVisible(false); showMovies(); moviesPanel.setVisible(true); } catch (HibernateException he) { he.printStackTrace(); } session.close(); } } }//GEN-LAST:event_orderButtonActionPerformed private void acceptTransactionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptTransactionButtonActionPerformed if (transactionTable.getSelectedRow() != -1) { if (transactionTable.getValueAt(transactionTable.getSelectedRow(), 3).toString() .equalsIgnoreCase("Wypoyczenie")) { session = NewHibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction(); Query query = session .createQuery("update Transakcja set idPracownika =:id where idTransakcji =:idT"); query.setParameter("id", loggedId); query.setParameter("idT", Integer.parseInt(transactionTable.getModel() .getValueAt(transactionTable.getSelectedRow(), 0).toString())); query.executeUpdate(); session.getTransaction().commit(); transactionPanel.setVisible(false); showTransactions(); transactionPanel.setVisible(true); } catch (HibernateException he) { he.printStackTrace(); } } } }//GEN-LAST:event_acceptTransactionButtonActionPerformed private void declineTransactionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_declineTransactionButtonActionPerformed if (transactionTable.getSelectedRow() != -1) { if (transactionTable.getValueAt(transactionTable.getSelectedRow(), 3).toString() .equalsIgnoreCase("Wypoyczenie")) { session = NewHibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction(); Query query = session.createQuery("delete Transakcja where idTransakcji =:idT"); query.setParameter("idT", Integer.parseInt(transactionTable.getModel() .getValueAt(transactionTable.getSelectedRow(), 0).toString())); query.executeUpdate(); session.getTransaction().commit(); transactionPanel.setVisible(false); showTransactions(); transactionPanel.setVisible(true); } catch (HibernateException he) { he.printStackTrace(); } } } }//GEN-LAST:event_declineTransactionButtonActionPerformed private void showTransactions() { List transactionList = null, filmList = null; session = NewHibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction(); Query q = session.createQuery("from Transakcja where idPracownika is NULL"); transactionList = q.list(); session.getTransaction().commit(); Vector<String> tableHeaders = new Vector<>(); Vector tableData = new Vector(); tableHeaders.add("Id"); tableHeaders.add("Id Klienta"); tableHeaders.add("Tytu Filmu"); tableHeaders.add("Data Transakcji"); tableHeaders.add("Typ"); if (!transactionList.isEmpty()) { session = NewHibernateUtil.getSessionFactory().openSession(); Transakcja transakcja; session.beginTransaction(); for (Object o : transactionList) { transakcja = (Transakcja) o; Vector<Object> oneRow = new Vector<>(); q = session.createQuery("from Film a where a.idFilmu IS " + transakcja.getIdFilmu().toString()); filmList = q.list(); oneRow.add(transakcja.getIdTransakcji()); oneRow.add(transakcja.getIdKlienta()); oneRow.add(((Film) filmList.get(0)).getTytul()); oneRow.add(transakcja.getDataTransakcji()); if (transakcja.getTyp().equals("WYP")) { oneRow.add("Wypoyczenie"); } else { oneRow.add("Zwrot"); } tableData.add(oneRow); } } transactionTable.setModel(new DefaultTableModel(tableData, tableHeaders) { public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }); transactionTable.removeColumn(transactionTable.getColumnModel().getColumn(0)); session.close(); } catch (HibernateException he) { he.printStackTrace(); } } private void transakcjeMenuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_transakcjeMenuMouseClicked if (!transactionPanel.isVisible()) { hideAll(); transactionPanel.setVisible(true); } showTransactions(); }//GEN-LAST:event_transakcjeMenuMouseClicked private void addGenreButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addGenreButtonActionPerformed // TODO add your handling code here: session = NewHibernateUtil.getSessionFactory().openSession(); newGenreNotify.setVisible(false); if (newGenreName.getText().trim().equals("")) { newGenreNotify.setText("Wprowad poprawne dane!"); newGenreNotify.setForeground(Color.red); newGenreNotify.setVisible(true); } else { Gatunek newGatunek = new Gatunek(); newGatunek.setNazwa(newGenreName.getText()); try { session.beginTransaction(); session.save(newGatunek); addMovieSuccess.setVisible(true); newGenreNotify.setText("Dodano gatunek!"); newGenreNotify.setForeground(Color.green); newGenreNotify.setVisible(true); } catch (HibernateException he) { he.printStackTrace(); newGenreNotify.setText("Co poszo nie tak!"); newGenreNotify.setForeground(Color.red); newGenreNotify.setVisible(true); } finally { session.getTransaction().commit(); newGatunek = null; session.close(); } } }//GEN-LAST:event_addGenreButtonActionPerformed private void addGatunekMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addGatunekMenuItemActionPerformed if (!addGenrePanel.isVisible()) { hideAll(); addGenrePanel.setVisible(true); } }//GEN-LAST:event_addGatunekMenuItemActionPerformed private void removeGatunekMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeGatunekMenuItemActionPerformed if (!removeGenrePanel.isVisible()) { hideAll(); removeGenrePanel.setVisible(true); reloadRemoveGenresTable(); } }//GEN-LAST:event_removeGatunekMenuItemActionPerformed private void reloadRemoveGenresTable() { removeGenrePanel.setVisible(true); session = NewHibernateUtil.getSessionFactory().openSession(); List genres = null; removeGenreTable.removeAll(); try { session.beginTransaction(); Query q = session.createQuery("from Gatunek"); genres = q.list(); session.getTransaction().commit(); } catch (HibernateException he) { } finally { session.close(); } Vector<String> tableHeaders = new Vector<>(); Vector tableData = new Vector(); tableHeaders.add("Id"); tableHeaders.add("Gatunek"); if (!genres.isEmpty()) { Gatunek gatunek; for (Object o : genres) { gatunek = (Gatunek) o; Vector<Object> oneRow = new Vector<>(); oneRow.add(gatunek.getIdGatunku()); oneRow.add(gatunek.getNazwa()); tableData.add(oneRow); } removeGenreTable.setModel(new DefaultTableModel(tableData, tableHeaders) { public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }); } } private void removeGenreButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeGenreButtonActionPerformed int id = Integer .parseInt(removeGenreTable.getModel().getValueAt(removeGenreTable.getSelectedRow(), 0).toString()); try { session = NewHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Query query = session.createQuery("delete Gatunek where idGatunku =:id"); query.setParameter("id", id); int result = query.executeUpdate(); if (result > 0) { removeGenreNotify.setText("Usunito gatunek!"); removeGenreNotify.setForeground(Color.green); removeGenreNotify.setVisible(true); } } catch (HibernateException he) { removeGenreNotify.setText("Nie mona usun gatunku!"); removeGenreNotify.setForeground(Color.red); removeGenreNotify.setVisible(true); } finally { session.getTransaction().commit(); session.close(); reloadRemoveGenresTable(); } }//GEN-LAST:event_removeGenreButtonActionPerformed private void addMovieButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addMovieButtonActionPerformed session = NewHibernateUtil.getSessionFactory().openSession(); newMovieError.setVisible(false); addMovieSuccess.setVisible(false); if (newMovieTitle.getText().trim().equals("") || Integer.parseInt(newMovieYear.getText()) < 1895 || Integer.parseInt(newMovieQuant.getText()) < 0 || newMovieCarrier.getSelectedIndex() < 0 || newMovieDirector.getSelectedIndex() < 0 || newMovieGenre.getSelectedIndices().length <= 0) { newMovieError.setVisible(true); } else { Film newFilm = new Film(); newFilm.setTytul(newMovieTitle.getText()); newFilm.setRokProdukcji(Short.parseShort(newMovieYear.getText())); newFilm.setIlosc(Long.parseLong(newMovieQuant.getText())); newFilm.setIdRezysera(newMovieDirector.getSelectedIndex() + 1); newFilm.setIdNosnika(newMovieCarrier.getSelectedIndex() + 1); try { session.beginTransaction(); session.save(newFilm); session.getTransaction().commit(); ListModel model = newMovieGenre.getModel(); int[] indexes = newMovieGenre.getSelectedIndices(); GatunekFilm[] gatFilm = new GatunekFilm[newMovieGenre.getSelectedIndices().length]; session.beginTransaction(); for (int i = 0; i < gatFilm.length; i++) { session.save(new GatunekFilm(new GatunekFilmId( Integer.parseInt(model.getElementAt(indexes[i]).toString().substring(0, model.getElementAt(indexes[i]).toString().indexOf("."))), newFilm.getIdFilmu()))); } addMovieSuccess.setVisible(true); } catch (HibernateException he) { he.printStackTrace(); } finally { session.getTransaction().commit(); newFilm = null; session.close(); } } }//GEN-LAST:event_addMovieButtonActionPerformed private void moviesTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_moviesTableMouseClicked if (evt.getClickCount() == 2 && !evt.isConsumed()) { evt.consume(); Film film = new Film(); Rezyser rezyser = new Rezyser(); List gatunki = null; int id = Integer .parseInt(moviesTable.getModel().getValueAt(moviesTable.getSelectedRow(), 0).toString()); try { session = NewHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Query q = session.createQuery("from Film where idFilmu IS " + id); film = (Film) q.list().get(0); q = session.createQuery("from Rezyser where idRezysera IS " + film.getIdRezysera()); rezyser = (Rezyser) q.list().get(0); q = session.createQuery( "from Gatunek a where a.idGatunku IN (select id.idGatunku from GatunekFilm where id.idFilmu is " + film.getIdFilmu() + ")"); gatunki = q.list(); session.getTransaction().commit(); } catch (HibernateException he) { he.printStackTrace(); } finally { session.close(); } Informacje info = new Informacje(); for (Object o : gatunki) { Gatunek gatunek = (Gatunek) o; info.gatunek.setText(info.gatunek.getText() + " | " + gatunek.getNazwa()); } info.gatunek.setText(info.gatunek.getText() + " |"); info.jLabel3.setText(film.getTytul()); info.rezyser.setText(rezyser.getNazwisko() + " " + rezyser.getImie()); info.rok.setText(film.getRokProdukcji().toString()); info.setVisible(true); } }//GEN-LAST:event_moviesTableMouseClicked private void showMovies() { if (ROLE != 0) { orderButton.setVisible(false); } else { orderButton.setVisible(true); } moviesTable.removeAll(); List moviesList = null, directorList = null; try { session = NewHibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); Query q = session.createQuery("from Film"); moviesList = q.list(); session.getTransaction().commit(); } catch (HibernateException he) { he.printStackTrace(); } Vector<String> tableHeaders = new Vector<>(); Vector tableData = new Vector(); tableHeaders.add("Id"); tableHeaders.add("Tytu"); tableHeaders.add("Rok Produkcji"); tableHeaders.add("Reyser"); tableHeaders.add("Nonik"); tableHeaders.add("Dostpno"); if (!moviesList.isEmpty()) { Film film; session.beginTransaction(); Query q; for (Object o : moviesList) { film = (Film) o; Vector<Object> oneRow = new Vector<>(); q = session.createQuery("from Rezyser a where a.idRezysera IS " + film.getIdRezysera().toString()); directorList = q.list(); q = session.createQuery("from Nosnik a where a.idNosnika IS " + film.getIdNosnika().toString()); oneRow.add(film.getIdFilmu()); oneRow.add(film.getTytul()); oneRow.add(film.getRokProdukcji()); oneRow.add(((Rezyser) (directorList.get(0))).getNazwisko()); oneRow.add(((Nosnik) q.list().get(0)).getTyp()); if (film.getIlosc() > 0) { oneRow.add("Dostpny"); } else { oneRow.add("Niedostpny"); } tableData.add(oneRow); } session.getTransaction().commit(); moviesTable.setModel(new DefaultTableModel(tableData, tableHeaders) { public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }); moviesTable.removeColumn(moviesTable.getColumnModel().getColumn(0)); session.close(); } } private void hideAll() { loginPanel.setVisible(false); moviesPanel.setVisible(false); addMoviePanel.setVisible(false); transactionPanel.setVisible(false); addGenrePanel.setVisible(false); removeGenrePanel.setVisible(false); removeMoviePanel.setVisible(false); hideErrors(); } private void hideErrors() { loginError.setVisible(false); removeMovieSuccess.setVisible(false); removeMovieError.setVisible(false); addMovieSuccess.setVisible(false); newMovieError.setVisible(false); newGenreNotify.setVisible(false); } private void setVisibilities() { transakcjeMenu.setVisible(false); adminMenu.setVisible(false); menuLogOut.setVisible(false); moviesMenu.setVisible(false); loginError.setVisible(false); switch (ROLE) { case 0: //uzytkownik menuLogOut.setVisible(true); moviesMenu.setVisible(true); break; case 1: //admin adminMenu.setVisible(true); menuLogOut.setVisible(true); moviesMenu.setVisible(true); break; case 2: //pracownik menuLogOut.setVisible(true); moviesMenu.setVisible(true); transakcjeMenu.setVisible(true); break; default: } } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { NewJFrame frame = new NewJFrame(); frame.setVisibilities(); frame.hideAll(); frame.loginPanel.setVisible(true); frame.setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton acceptTransactionButton; private javax.swing.JMenuItem addGatunekMenuItem; private javax.swing.JButton addGenreButton; private javax.swing.JPanel addGenrePanel; private javax.swing.JMenuItem addMovie; private javax.swing.JButton addMovieButton; private javax.swing.JPanel addMoviePanel; private javax.swing.JLabel addMovieSuccess; private javax.swing.JMenu adminMenu; private javax.swing.JButton declineTransactionButton; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JScrollPane jScrollPane4; private javax.swing.JScrollPane jScrollPanee; private java.awt.Label label1; private java.awt.Label label2; private java.awt.Label label3; private javax.swing.JTextField logField; private javax.swing.JButton loginButton; private javax.swing.JLabel loginError; private javax.swing.JPanel loginPanel; private javax.swing.JMenu menuLogOut; private javax.swing.JMenu moviesMenu; private javax.swing.JPanel moviesPanel; private javax.swing.JTable moviesTable; private javax.swing.JTextField newGenreName; private javax.swing.JLabel newGenreNotify; private javax.swing.JComboBox<String> newMovieCarrier; private javax.swing.JComboBox<String> newMovieDirector; private javax.swing.JLabel newMovieError; private javax.swing.JList<String> newMovieGenre; private javax.swing.JTextField newMovieQuant; private javax.swing.JTextField newMovieTitle; private javax.swing.JTextField newMovieYear; private javax.swing.JButton orderButton; private javax.swing.JPasswordField passField; private javax.swing.JMenuItem removeGatunekMenuItem; private javax.swing.JButton removeGenreButton; private javax.swing.JLabel removeGenreNotify; private javax.swing.JPanel removeGenrePanel; private javax.swing.JTable removeGenreTable; private javax.swing.JMenuItem removeMovie; private javax.swing.JButton removeMovieButton; private javax.swing.JLabel removeMovieError; private javax.swing.JPanel removeMoviePanel; private javax.swing.JLabel removeMovieSuccess; private javax.swing.JTable removeMovieTable; private javax.swing.JPanel transactionPanel; private javax.swing.JTable transactionTable; private javax.swing.JMenu transakcjeMenu; // End of variables declaration//GEN-END:variables }