Java tutorial
/* * 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. */ package voedselbank; import java.io.File; import java.io.FileInputStream; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import javax.swing.JFileChooser; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCreationHelper; import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.DataFormatter; /** * * @author Dave */ public class MainFrame extends javax.swing.JFrame { /** * Creates new form NewJFrame */ public MainFrame() { initComponents(); setOptions(); } private void setOptions() { setTitle("Voedselbank Haaglanden"); setLocationRelativeTo(null); setDefaultCloseOperation(EXIT_ON_CLOSE); addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent windowEvent) { SimpleDataSourceV2.closeConnection(); System.out.println("De database is succesvol afgesloten"); System.exit(0); } }); } /** * 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() { jOptionPane1 = new javax.swing.JOptionPane(); jSeparator1 = new javax.swing.JSeparator(); jPanel1 = new javax.swing.JPanel(); clienttoevoegenKnop = new javax.swing.JButton(); clientwijzigenKnop = new javax.swing.JButton(); uitgiftepunttoevoegenKnop = new javax.swing.JButton(); uitgiftepuntwijzigenKnop = new javax.swing.JButton(); overzichtenKnop = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jMenuBar1 = new javax.swing.JMenuBar(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); clienttoevoegenKnop.setText("Clint toevoegen"); clienttoevoegenKnop.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { clienttoevoegenKnopActionPerformed(evt); } }); clientwijzigenKnop.setText("Clintgegevens wijzigen/verwijderen"); clientwijzigenKnop.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { clientwijzigenKnopActionPerformed(evt); } }); uitgiftepunttoevoegenKnop.setText("Uitgiftepunt toevoegen"); uitgiftepunttoevoegenKnop.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { uitgiftepunttoevoegenKnopActionPerformed(evt); } }); uitgiftepuntwijzigenKnop.setText("Uitgiftepunt wijzigen/verwijderen"); uitgiftepuntwijzigenKnop.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { uitgiftepuntwijzigenKnopActionPerformed(evt); } }); overzichtenKnop.setText("Overzichten"); overzichtenKnop.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { overzichtenKnopActionPerformed(evt); } }); jButton1.setText("Importeer uit Excel"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("Hulpverlener toevoegen"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton3.setText("Hulpverlener wijzigen/verwijderen"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout .setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(clienttoevoegenKnop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(clientwijzigenKnop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(uitgiftepunttoevoegenKnop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(uitgiftepuntwijzigenKnop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(overzichtenKnop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap(258, Short.MAX_VALUE))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(clienttoevoegenKnop) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(clientwijzigenKnop) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(uitgiftepunttoevoegenKnop) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(uitgiftepuntwijzigenKnop) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(overzichtenKnop) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton1) .addContainerGap(194, Short.MAX_VALUE))); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent( jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); pack(); }// </editor-fold>//GEN-END:initComponents private void clientwijzigenKnopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clientwijzigenKnopActionPerformed ClientZoeken z = new ClientZoeken(); z.setVisible(true); }//GEN-LAST:event_clientwijzigenKnopActionPerformed private void clienttoevoegenKnopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clienttoevoegenKnopActionPerformed ClientAanmaken a = new ClientAanmaken(); a.setVisible(true); }//GEN-LAST:event_clienttoevoegenKnopActionPerformed private void overzichtenKnopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_overzichtenKnopActionPerformed OverzichtScherm s = new OverzichtScherm(); s.setVisible(true); }//GEN-LAST:event_overzichtenKnopActionPerformed private void uitgiftepunttoevoegenKnopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uitgiftepunttoevoegenKnopActionPerformed UitgiftepuntAanmaken u = new UitgiftepuntAanmaken(); u.setVisible(true); }//GEN-LAST:event_uitgiftepunttoevoegenKnopActionPerformed private void uitgiftepuntwijzigenKnopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uitgiftepuntwijzigenKnopActionPerformed UitgiftepuntZoeken u = new UitgiftepuntZoeken(); u.setVisible(true); }//GEN-LAST:event_uitgiftepuntwijzigenKnopActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed JFileChooser fc = new JFileChooser(); fc.showOpenDialog(this); DataFormatter formatter = new DataFormatter(); DateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd"); File file = fc.getSelectedFile(); try { FileInputStream fileInputStream = new FileInputStream(file); HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream); HSSFSheet worksheet = workbook.getSheet("Intakestatus"); boolean begin = false; boolean einde = false; for (int i = 0; begin == false; i++) { String content = formatter.formatCellValue(worksheet.getRow(i).getCell(0)); if (content.equals("Kaartnummer")) { begin = true; i = i + 1; while (einde == false) { if (!formatter.formatCellValue(worksheet.getRow(i).getCell(0)).equals("")) { Date startdatum_uitgifte = new Date(0); Date intakedatum = new Date(0); Date datum_herintake = new Date(0); Date datum_stopzetting = new Date(0); String kaartnummer = formatter.formatCellValue(worksheet.getRow(i).getCell(0)); String naam = formatter.formatCellValue(worksheet.getRow(i).getCell(1)); String naamPartner = formatter.formatCellValue(worksheet.getRow(i).getCell(2)); String telefoonnummer = formatter.formatCellValue(worksheet.getRow(i).getCell(3)); String email = formatter.formatCellValue(worksheet.getRow(i).getCell(4)); String mobiel = formatter.formatCellValue(worksheet.getRow(i).getCell(5)); String aantalPersonen = formatter.formatCellValue(worksheet.getRow(i).getCell(6)); String adres = formatter.formatCellValue(worksheet.getRow(i).getCell(13)); String postcode = formatter.formatCellValue(worksheet.getRow(i).getCell(14)); String plaats = formatter.formatCellValue(worksheet.getRow(i).getCell(15)); String status = formatter.formatCellValue(worksheet.getRow(i).getCell(16)); String intaker = formatter.formatCellValue(worksheet.getRow(i).getCell(17)); if (worksheet.getRow(i).getCell(19).getDateCellValue() != null) { startdatum_uitgifte = worksheet.getRow(i).getCell(19).getDateCellValue(); } if (worksheet.getRow(i).getCell(18).getDateCellValue() != null) { intakedatum = worksheet.getRow(i).getCell(18).getDateCellValue(); } if (worksheet.getRow(i).getCell(20).getDateCellValue() != null) { datum_herintake = worksheet.getRow(i).getCell(20).getDateCellValue(); } if (worksheet.getRow(i).getCell(21).getDateCellValue() != null) { datum_stopzetting = worksheet.getRow(i).getCell(21).getDateCellValue(); } String reden_stopzetting = formatter.formatCellValue(worksheet.getRow(i).getCell(22)); String uitgifte_punt = formatter.formatCellValue(worksheet.getRow(i).getCell(31)); String pakket = formatter.formatCellValue(worksheet.getRow(i).getCell(32)); Client client = new Client(Integer.parseInt(kaartnummer), naam, telefoonnummer, adres, postcode, plaats, email, mobiel, Integer.parseInt(aantalPersonen), status, naamPartner); Voedselpakket voedselpakket = new Voedselpakket(startdatum_uitgifte, pakket); Intake intake = new Intake(0, 0, intaker, intakedatum, startdatum_uitgifte, datum_herintake, datum_stopzetting, reden_stopzetting); client.checkBestaat(client, uitgifte_punt, voedselpakket, intake); i++; } else { einde = true; } } } } } catch (Exception e) { System.out.println(e); } }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed HulpverlenerToevoegen h = new HulpverlenerToevoegen(); h.setVisible(true); }//GEN-LAST:event_jButton2ActionPerformed private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed HulpverlenerZoeken z = new HulpverlenerZoeken(); z.setVisible(true); }//GEN-LAST:event_jButton3ActionPerformed public static void main(String[] args) { MainFrame f = new MainFrame(); f.setVisible(true); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton clienttoevoegenKnop; private javax.swing.JButton clientwijzigenKnop; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JOptionPane jOptionPane1; private javax.swing.JPanel jPanel1; private javax.swing.JSeparator jSeparator1; private javax.swing.JButton overzichtenKnop; private javax.swing.JButton uitgiftepunttoevoegenKnop; private javax.swing.JButton uitgiftepuntwijzigenKnop; // End of variables declaration//GEN-END:variables }