Subordoante.Sub.java Source code

Java tutorial

Introduction

Here is the source code for Subordoante.Sub.java

Source

/*
 * 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 Subordoante;

import AppPackage.AnimationClass;
import Boss.Boss;
import Wired.*;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Toolkit;
import static java.awt.image.ImageObserver.ALLBITS;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import static java.lang.Integer.parseInt;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Reda ben
 */
public final class Sub extends javax.swing.JFrame {
    Timer time;
    PlaySound p;
    int Notification = 0;

    public Sub() {
        initComponents();
        Border blackline = BorderFactory.createLineBorder(Color.black);
        jLabel1.setBorder(blackline);
        subordonate();
        p = new PlaySound(System.getProperty("user.dir") + "/src/Wired/sound.wav");
        time = new Timer();
        time.schedule(new Sub.RemindTask(), 0, //initial delay
                5 * 1000);
    }

    class RemindTask extends TimerTask {
        int z = 0;

        @Override
        public void run() {
            int i = Notification;
            loadNotification();
            if (Notification > i && z > 0) {
                p.play();
                i = Notification;
            }
            z = 1;
        }
    }

    /**
     * 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() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jLabel4 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jReport = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel18 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jReqeusts = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jLabel10 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jFirst = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setUndecorated(true);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }

            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }

            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel4.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel4MouseClicked(evt);
            }
        });
        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(772, 10, 20, 20));

        jLabel20.setIcon(new javax.swing.ImageIcon(getClass().getResource("/about.png"))); // NOI18N
        jLabel20.setText("jLabel7");
        getContentPane().add(jLabel20, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, -560, 800, 560));

        jLabel7.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel7MouseClicked(evt);
            }
        });
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(260, 20, 30, 30));

        jLabel8.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(241, 157, 20));
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel8.setText("55");
        jLabel8.setToolTipText("");
        jLabel8.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel8.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel8MouseClicked(evt);
            }
        });
        getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(273, 15, 20, -1));

        jLabel5.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel5MouseClicked(evt);
            }
        });
        getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(744, 10, 20, 20));

        jLabel3.setFont(new java.awt.Font("Arial", 0, 24)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(51, 51, 51));
        jLabel3.setText("Reda Ben");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 10, 180, 50));

        jLabel2.setFont(new java.awt.Font("Arial", 0, 24)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(51, 51, 51));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("7");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, 40, 50));

        jReport.setOpaque(false);
        jReport.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jRadioButton1.setText("Finished");
        jRadioButton1.setOpaque(false);
        jReport.add(jRadioButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(326, 140, -1, -1));

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
        jRadioButton2.setText("Error");
        jRadioButton2.setOpaque(false);
        jReport.add(jRadioButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(416, 140, -1, -1));

        jScrollPane1.setBorder(null);
        jScrollPane1.setPreferredSize(new java.awt.Dimension(339, 127));

        jTextArea1.setBackground(new java.awt.Color(249, 249, 249));
        jTextArea1.setColumns(20);
        jTextArea1.setFont(new java.awt.Font("Leelawadee UI", 1, 18)); // NOI18N
        jTextArea1.setForeground(new java.awt.Color(51, 51, 51));
        jTextArea1.setLineWrap(true);
        jTextArea1.setRows(5);
        jTextArea1.setText("Description");
        jTextArea1.setToolTipText("");
        jTextArea1.setBorder(null);
        jTextArea1.setMargin(new java.awt.Insets(20, 20, 20, 20));
        jTextArea1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jTextArea1MouseReleased(evt);
            }
        });
        jScrollPane1.setViewportView(jTextArea1);

        jReport.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 180, 400, 200));

        jLabel18.setFont(new java.awt.Font("Arial", 0, 24)); // NOI18N
        jLabel18.setForeground(new java.awt.Color(102, 102, 102));
        jLabel18.setText("Please Select a choice");
        jReport.add(jLabel18, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 120, 250, 30));

        jLabel15.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
        jLabel15.setForeground(new java.awt.Color(87, 87, 87));
        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel15.setText("2");
        jReport.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(487, 73, 60, 30));

        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/reportBg.png"))); // NOI18N
        jReport.add(jLabel16, new org.netbeans.lib.awtextra.AbsoluteConstraints(188, 76, 490, 310));

        jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/replyB.png"))); // NOI18N
        jLabel17.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel17.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel17MouseClicked(evt);
            }

            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabel17MouseEntered(evt);
            }

            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabel17MouseExited(evt);
            }

            public void mousePressed(java.awt.event.MouseEvent evt) {
                jLabel17MousePressed(evt);
            }

            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jLabel17MouseReleased(evt);
            }
        });
        jReport.add(jLabel17, new org.netbeans.lib.awtextra.AbsoluteConstraints(297, 410, 210, 61));

        getContentPane().add(jReport, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 70, 800, 490));

        jReqeusts.setOpaque(false);
        jReqeusts.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/arrow.png"))); // NOI18N
        jReqeusts.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(457, 400, 31, 15));

        jScrollPane2.setBackground(new java.awt.Color(249, 249, 249));
        jScrollPane2.setBorder(null);

        jTable2.setBackground(new java.awt.Color(249, 249, 249));
        jTable2.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jTable2.setForeground(new java.awt.Color(51, 51, 51));
        jTable2.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "Seen", "Request Id", "Description", "State", "Date" }) {
            Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.String.class,
                    java.lang.String.class, java.lang.String.class };
            boolean[] canEdit = new boolean[] { false, false, false, false, false };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        jTable2.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jTable2.setFocusable(false);
        jTable2.setGridColor(new java.awt.Color(255, 255, 255));
        jTable2.setRowHeight(30);
        jTable2.setSelectionBackground(new java.awt.Color(226, 226, 226));
        jTable2.setSelectionForeground(new java.awt.Color(0, 0, 0));
        jTable2.getTableHeader().setResizingAllowed(false);
        jTable2.getTableHeader().setReorderingAllowed(false);
        jTable2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable2MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable2);
        if (jTable2.getColumnModel().getColumnCount() > 0) {
            jTable2.getColumnModel().getColumn(0).setResizable(false);
            jTable2.getColumnModel().getColumn(1).setResizable(false);
            jTable2.getColumnModel().getColumn(2).setResizable(false);
            jTable2.getColumnModel().getColumn(3).setResizable(false);
            jTable2.getColumnModel().getColumn(4).setResizable(false);
        }

        jReqeusts.add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 780, 360));

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel10.setForeground(new java.awt.Color(102, 102, 102));
        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel10.setText("Double-click to print a request");
        jReqeusts.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 450, 800, 40));

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/reportB.png"))); // NOI18N
        jLabel12.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel12MouseClicked(evt);
            }

            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabel12MouseEntered(evt);
            }

            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabel12MouseExited(evt);
            }

            public void mousePressed(java.awt.event.MouseEvent evt) {
                jLabel12MousePressed(evt);
            }

            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jLabel12MouseReleased(evt);
            }
        });
        jReqeusts.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(295, 380, 210, 62));

        jLabel14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/arrow.png"))); // NOI18N
        jReqeusts.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(457, 400, 31, 15));

        getContentPane().add(jReqeusts, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 70, 800, 490));

        jFirst.setOpaque(false);
        jFirst.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Boss/FirstBG.png"))); // NOI18N
        jFirst.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 50, 340, 400));

        getContentPane().add(jFirst, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 70, 800, 490));

        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/lockB.png"))); // NOI18N
        jLabel9.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel9.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel9MouseClicked(evt);
            }

            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jLabel9MouseEntered(evt);
            }

            public void mouseExited(java.awt.event.MouseEvent evt) {
                jLabel9MouseExited(evt);
            }
        });
        getContentPane().add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(720, 5, 16, 24));

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/refreshB.png"))); // NOI18N
        jLabel11.setText("Show all requests");
        jLabel11.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel11.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel11MouseClicked(evt);
            }

            public void mousePressed(java.awt.event.MouseEvent evt) {
                jLabel11MousePressed(evt);
            }

            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jLabel11MouseReleased(evt);
            }
        });
        getContentPane().add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(380, 20, 34, 34));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/subordonateBg.png"))); // NOI18N
        jLabel1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jLabel1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                jLabel1MouseDragged(evt);
            }
        });
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jLabel1MousePressed(evt);
            }
        });
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 800, 560));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jLabel4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel4MouseClicked

        if (new File("user.txt").delete())
            System.out.println("user.txt Deleted :D ");
        else
            System.out.println("user.txt Not deleted ");
        if (new File("login.conf").delete())
            System.out.println("login.conf Deleted :D ");
        else
            System.out.println("login.txt Not deleted ");
        if (new File("admin.conf").delete())
            System.out.println("admin.conf Deleted :D ");
        else
            System.out.println("admin.txt Not deleted ");
        if (new File("boss.conf").delete())
            System.out.println("boss.conf Deleted :D ");
        else
            System.out.println("boss.conf Not deleted ");
        if (new File("sub.conf").delete())
            System.out.println("sub.conf Deleted :D ");
        else
            System.out.println("sub.conf Not deleted ");
        if (new File("report.pdf").delete())
            System.out.println("report.pdf Deleted :D ");
        else
            System.out.println("report.pdf Not deleted ");
        if (new File("printreq.pdf").delete())
            System.out.println("printreq.pdf Deleted :D ");
        else
            System.out.println("printreq.pdf Not deleted ");
        System.exit(0);

    }//GEN-LAST:event_jLabel4MouseClicked

    private void jLabel5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel5MouseClicked
        this.setState(Sub.ICONIFIED);
    }//GEN-LAST:event_jLabel5MouseClicked

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        BufferedReader reader = null;
        try {
            this.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width / 2 - 400,
                    Toolkit.getDefaultToolkit().getScreenSize().height / 2 - 300);
            subordonate();
            reader = new BufferedReader(new FileReader("sub.conf"));
            String line;
            int l = 0, w = Toolkit.getDefaultToolkit().getScreenSize().width / 2 - 400,
                    h = Toolkit.getDefaultToolkit().getScreenSize().height / 2 - 300;
            while ((line = reader.readLine()) != null) {
                if (l == 0) {
                    w = parseInt(line);
                    l++;
                } else
                    h = parseInt(line);
            }
            reader.close();
            this.setLocation(w, h);
            jLabel2.setText(subordinate.intGetter("idTeam") + "");
            jLabel3.setText(subordinate.getter("name") + " " + subordinate.getter("lname"));
            showrecords();
            jReqeusts.setVisible(false);
            jReport.setVisible(false);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                reader.close();
            } catch (IOException ex) {
                Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }//GEN-LAST:event_formWindowOpened

    int x, y;

    private void jLabel1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MousePressed
        x = evt.getX();
        y = evt.getY();
    }//GEN-LAST:event_jLabel1MousePressed

    private void jLabel1MouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseDragged
        this.setLocation(evt.getXOnScreen() - x, evt.getYOnScreen() - y);
    }//GEN-LAST:event_jLabel1MouseDragged

    private void jLabel8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel8MouseClicked
        jReport.setVisible(false);
        jTextArea1.setText("Description");
        jReqeusts.setVisible(true);
        showrecordsR();
        Se = true;
    }//GEN-LAST:event_jLabel8MouseClicked

    private void jLabel9MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseEntered
        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/lockBH.png")));
    }//GEN-LAST:event_jLabel9MouseEntered

    private void jLabel9MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseExited
        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/lockB.png")));

    }//GEN-LAST:event_jLabel9MouseExited

    private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel9MouseClicked
        FileWriter fw = null;
        try {
            if (new File("user.txt").delete())
                System.out.println("user.txt Deleted :D ");
            fw = new FileWriter("login.conf");
            PrintWriter pw = new PrintWriter(fw);
            pw.println(this.getLocationOnScreen().x);
            pw.print(this.getLocationOnScreen().y);
            pw.close();
            this.dispose();
            new Login.login().setVisible(true);
        } catch (IOException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                fw.close();
            } catch (IOException ex) {
                Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jLabel9MouseClicked

    private void jLabel11MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel11MousePressed
        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/refreshBP.png")));
    }//GEN-LAST:event_jLabel11MousePressed

    private void jLabel11MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel11MouseReleased
        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/refreshB.png")));
    }//GEN-LAST:event_jLabel11MouseReleased

    private void jLabel12MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel12MouseEntered
        c = new AnimationClass();
        c.jLabelXRight(457, 505, 3, 1, jLabel13);
        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/reportBH.png")));

    }//GEN-LAST:event_jLabel12MouseEntered

    private void jLabel12MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel12MouseExited
        jLabel13.setLocation(457, jLabel13.getLocation().y);
        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/reportB.png")));

    }//GEN-LAST:event_jLabel12MouseExited

    private void jLabel12MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel12MousePressed

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/reportBP.png")));
    }//GEN-LAST:event_jLabel12MousePressed

    private void jLabel12MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel12MouseReleased
        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/reportBH.png")));

    }//GEN-LAST:event_jLabel12MouseReleased

    private void jTextArea1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextArea1MouseReleased
        if (jTextArea1.getText().equals("Description")) {
            jTextArea1.setText("");
        }
    }//GEN-LAST:event_jTextArea1MouseReleased

    private void jLabel17MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel17MouseEntered
        jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/replyBH.png")));
    }//GEN-LAST:event_jLabel17MouseEntered

    private void jLabel17MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel17MouseExited
        jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/replyB.png")));
    }//GEN-LAST:event_jLabel17MouseExited

    private void jLabel17MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel17MousePressed
        jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/replyBP.png")));
    }//GEN-LAST:event_jLabel17MousePressed

    private void jLabel17MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel17MouseReleased
        jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Subordoante/replyBH.png")));
    }//GEN-LAST:event_jLabel17MouseReleased

    private void jLabel12MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel12MouseClicked

        if (getSelectedrequest() > 0) {
            jLabel10.setText("Double-click to print a request");
            jReport.setVisible(true);
            jReqeusts.setVisible(false);
            jLabel18.setVisible(false);
            request();
            SetSeen();
            setWindows();
        } else {
            jLabel10.setText("Please select a request");
        }

    }//GEN-LAST:event_jLabel12MouseClicked

    private void jLabel17MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel17MouseClicked
        try {
            jReport.setVisible(false);
            jReqeusts.setVisible(true);
            connect = new Connection();
            Statement st = connect.con.createStatement();
            if (jRadioButton1.isSelected() || jRadioButton2.isSelected()) {
                sendReport();
                if (jRadioButton1.isSelected()) {
                    if (request.stringGetter("requestType").equalsIgnoreCase("Transfer")) {
                        String s = "UPDATE client set address ='" + request.stringGetter("address2")
                                + "' where  fullName = '" + request.stringGetter("clientName") + "'";
                        st.execute(s);
                    }
                    if (request.stringGetter("requestType").equalsIgnoreCase("Instalation")) {
                        String s = "UPDATE client set address ='" + request.stringGetter("address1")
                                + "',service = '" + request.stringGetter("requestNet") + "' where  fullName = '"
                                + request.stringGetter("clientName") + "'";
                        st.execute(s);
                    }
                }
            } else {
                jLabel18.setVisible(true);
            }
            showrecords();
            jTextArea1.setText("Description");
        } catch (SQLException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_jLabel17MouseClicked

    private void jLabel11MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel11MouseClicked
        Se = false;
        jTextArea1.setText("Description");
        jReport.setVisible(false);
        jReqeusts.setVisible(true);
        showrecords();
    }//GEN-LAST:event_jLabel11MouseClicked

    private void jTable2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable2MouseClicked
        if (evt.getClickCount() == 2) {
            request();
            openPDF();
            SetSeen();
            if (Se) {
                showrecordsR();
            } else
                showrecords();
        }
    }//GEN-LAST:event_jTable2MouseClicked

    boolean Se = false;

    private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseClicked
        jReport.setVisible(false);
        jReqeusts.setVisible(true);
        jTextArea1.setText("Description");
        showrecordsR();
        Se = true;
    }//GEN-LAST:event_jLabel7MouseClicked

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing

    }//GEN-LAST:event_formWindowClosing

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed

    }//GEN-LAST:event_formWindowClosed

    boolean about;

    public void request() {
        try {
            connect = new Connection();
            Statement stmt = connect.con.createStatement();
            int idrequest = getSelectedrequest();
            String SQL = "SELECT * FROM request where idrequest =" + idrequest;
            ResultSet results = stmt.executeQuery(SQL);
            results.next();
            boolean s = false, e = false, v = false;
            if (parseInt(results.getString("seen")) == 0 || parseInt(results.getString("seen")) == 1) {
                s = false;
            }
            if (parseInt(results.getString("seen")) == 2) {
                s = true;
            }
            if (parseInt(results.getString("error")) == 0 || parseInt(results.getString("error")) == 1) {
                e = false;
            }
            if (parseInt(results.getString("error")) == 2) {
                e = true;
            }
            if (parseInt(results.getString("finished")) == 0 || parseInt(results.getString("finished")) == 1) {
                v = false;
            }
            if (parseInt(results.getString("finished")) == 2) {
                v = true;
            }
            String type = "";
            if (parseInt(results.getString("id_type")) == 1) {
                type = "Instalation";
            }
            if (parseInt(results.getString("id_type")) == 2) {
                type = "Transfer";
            }
            if (parseInt(results.getString("id_type")) == 3) {
                type = "Maintenance";
            }
            String sDd;
            if (!results.getString("seendate").equals("0000-00-00")) {
                sDd = results.getString("seendate").substring(0, 4) + "/"
                        + results.getString("seendate").substring(5, 7) + "/"
                        + results.getString("seendate").substring(8, 10);
            } else {
                sDd = "0000/00/00";
            }
            Date sD = new Date(sDd);
            if (!results.getString("ERRORDATE").equals("0000-00-00")) {
                sDd = results.getString("ERRORDATE").substring(0, 4) + "/"
                        + results.getString("ERRORDATE").substring(5, 7) + "/"
                        + results.getString("ERRORDATE").substring(8, 10);
            } else {
                sDd = "0000/00/00";
            }
            Date eD = new Date(sDd);
            if (!results.getString("FINISHEDDATE").equals("0000-00-00")) {
                sDd = results.getString("FINISHEDDATE").substring(0, 4) + "/"
                        + results.getString("FINISHEDDATE").substring(5, 7) + "/"
                        + results.getString("FINISHEDDATE").substring(8, 10);
            } else {
                sDd = "0000/00/00";
            }
            Date vD = new Date(sDd);
            request = new Request(parseInt(results.getString("idrequest")), results.getString("telclient"),
                    results.getString("address1"), results.getString("address2"), results.getString("clientname"),
                    s, v, e, sD, eD, vD, type, results.getString("net"), parseInt(results.getString("id_user")),
                    parseInt(results.getString("idteam")), results.getString("problem"));
        } catch (SQLException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void loadNotification() {
        int i = 0;
        try {
            connect = new Connection();
            Statement stmt = connect.con.createStatement();
            String SQL = "SELECT idteam FROM user where ID_USER =" + subordinate.getId();
            ;
            ResultSet results = stmt.executeQuery(SQL);
            results.next();
            SQL = "SELECT * FROM request where idteam = " + results.getInt("idteam") + " and finished =" + 1
                    + " and error = " + 1;
            results = stmt.executeQuery(SQL);
            while (results.next()) {
                i++;
            }
            if (i <= 99) {
                jLabel8.setFont(new java.awt.Font("Arial", 1, 14));
                jLabel8.setText(i + "");
            } else {
                jLabel8.setFont(new java.awt.Font("Arial", 1, 11)); // NOI18N
                jLabel8.setText(i + "");
            }
            Notification = i;
        } catch (SQLException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void openPDF() {
        Document document = new Document();
        try {
            PdfWriter.getInstance(document, new FileOutputStream("printreq.pdf"));
            document.open();
            SimpleDateFormat td = new SimpleDateFormat("yyyy-MM-dd");
            Date now = new Date();
            String tdnow = td.format(now);
            Paragraph paragraph = new Paragraph(ALLBITS);
            paragraph.add(new Paragraph(tdnow));
            paragraph.add(new Paragraph("Request : \n\n",
                    FontFactory.getFont(FontFactory.TIMES, 20, Font.BOLD, BaseColor.DARK_GRAY)));
            document.add(paragraph);
            PdfPTable table = new PdfPTable(2);
            table.addCell("ID Request :");
            table.addCell(request.intGetter("idRequest") + "");
            table.addCell("Request type :");
            table.addCell(request.stringGetter("requestNet"));
            table.addCell("Client name :");
            table.addCell(request.stringGetter("clientName"));
            table.addCell("Phone number :");
            table.addCell(request.stringGetter("clientTel"));
            table.addCell("Address  :");
            table.addCell(request.stringGetter("address1"));
            if (request.stringGetter("requestType").equalsIgnoreCase("Transfer")) {
                table.addCell("Transfer address:");
                table.addCell(request.stringGetter("address2"));
            } else if (request.stringGetter("requestType").equalsIgnoreCase("Maintenance")) {
                table.addCell("Problem :");
                table.addCell(request.stringGetter("problem"));
            } else
                ;

            document.add(table);
            document.close();
            /* Open Pdf */
            Desktop desktop = Desktop.getDesktop();
            if (desktop.isSupported(Desktop.Action.OPEN)) {
                desktop.open(new File("printreq.pdf"));
            } else {
                System.out.println("Open is not supported");
            }
        } catch (DocumentException | IOException ex) {
        }
    }

    private int iduser = 0;

    public void subordonate() {
        try {
            connect = new Connection();
            Statement stmt = connect.con.createStatement();
            FileReader fr;
            fr = new FileReader("user.txt");
            BufferedReader br = new BufferedReader(fr);
            iduser = parseInt(br.readLine());
            fr.close();
            String SQL = "SELECT * FROM user where ID_USER =" + iduser;
            ResultSet results = stmt.executeQuery(SQL);
            results.next();
            subordinate = new Subordinates(iduser, parseInt(results.getString("idteam")), results.getString("name"),
                    results.getString("lastname"), results.getString("nid"), results.getString("position"),
                    results.getString("password"));
        } catch (SQLException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void showrecords() {
        try {
            model = (DefaultTableModel) jTable2.getModel();
            connect = new Connection();
            Statement st = connect.con.createStatement();
            model.getDataVector().removeAllElements();
            revalidate();
            String sql = "Select * from request where idteam =" + subordinate.intGetter("idTeam") + "";
            ResultSet rs = st.executeQuery(sql);
            while (rs.next()) {
                String description = "";
                String v = "";
                String seen = "";
                if (parseInt(rs.getString("id_type")) == 1) {
                    description = "Instalation";
                }
                if (parseInt(rs.getString("id_type")) == 2) {
                    description = "Transfer";
                }
                if (parseInt(rs.getString("id_type")) == 3) {
                    description = "Maintenance";
                }
                if (rs.getInt("seen") == 1) {
                    seen = "Not yet";
                } else {
                    seen = "Yes";
                }
                if (rs.getInt("Finished") == 2) {
                    v = "Validated";
                } else {
                    v = "Error";
                }

                if (rs.getInt("Finished") == 1 && rs.getInt("ERROR") == 1) {
                    v = "In Progress";
                }
                model.addRow(
                        new Object[] { seen, rs.getString("idrequest"), description, v, rs.getString("SENDDATE") });
            }
        } catch (SQLException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public void showrecordsR() {
        try {
            model = (DefaultTableModel) jTable2.getModel();
            connect = new Connection();
            Statement st = connect.con.createStatement();
            model.getDataVector().removeAllElements();
            revalidate();
            String sql = "Select * from request where idteam =" + subordinate.intGetter("idTeam")
                    + " and Finished = " + 1 + " and Error = " + 1;
            ResultSet rs = st.executeQuery(sql);
            while (rs.next()) {
                String description = "";
                String v = "";
                String seen = "";
                if (parseInt(rs.getString("id_type")) == 1) {
                    description = "Instalation";
                }
                if (parseInt(rs.getString("id_type")) == 2) {
                    description = "Transfer";
                }
                if (parseInt(rs.getString("id_type")) == 3) {
                    description = "Maintenance";
                }
                if (rs.getInt("seen") == 1) {
                    seen = "Not yet";
                } else {
                    seen = "Yes";
                }
                if (rs.getInt("Finished") == 2) {
                    v = "Validated";
                } else {
                    v = "Error";
                }

                if (rs.getInt("Finished") == 1 && rs.getInt("ERROR") == 1) {
                    v = "In Progress";
                }
                if (v.equals("In Progress")) {
                    model.addRow(new Object[] { seen, rs.getString("idrequest"), description, v,
                            rs.getString("SENDDATE") });
                }
            }
        } catch (SQLException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    private int getSelectedrequest() {
        try {
            model = (DefaultTableModel) jTable2.getModel();
            return parseInt((String) jTable2.getValueAt(jTable2.getSelectedRow(), 1));
        } catch (Exception e) {
            jLabel10.setText("Please select a request");
        }
        return 0;
    }

    public void SetSeen() {
        try {
            int idrequest = getSelectedrequest();
            connect = new Connection();
            Statement stmt = connect.con.createStatement();
            String SQL = "Update request set seen =" + 2 + " where IDREQUEST=" + idrequest;
            stmt.executeUpdate(SQL);
        } catch (SQLException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void setreq() {
        try {
            int idrequest = getSelectedrequest();
            connect = new Connection();
            Statement stmt = connect.con.createStatement();
            String SQL = "";
            if (jRadioButton1.isSelected()) {
                SQL = "Update request set finished =" + 2 + ",error =" + 1 + " where IDREQUEST=" + idrequest;
            }
            if (jRadioButton2.isSelected()) {
                SQL = "Update request set finished =" + 1 + ",error =" + 2 + " where IDREQUEST=" + idrequest;
            }
            stmt.executeUpdate(SQL);
        } catch (SQLException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public int getLastReport() {
        int idr = 0;
        try {

            connect = new Connection();
            Statement st = connect.con.createStatement();
            String sql = "Select * from report";
            ResultSet rs = st.executeQuery(sql);
            while (rs.next()) {
                idr = parseInt(rs.getString("idreport"));
            }

        } catch (SQLException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        }
        return idr + 1;
    }

    public void sendReport() {
        try {
            setreq();
            boolean Exist = false;
            int idrequest = getSelectedrequest();
            connect = new Connection();
            Statement stmt = connect.con.createStatement();
            String SQL = "Select * from report where idrequest =" + idrequest;
            ResultSet results = stmt.executeQuery(SQL);
            Exist = results.next();
            int re = 0;
            if (Exist) {
                re = results.getInt("idreport");
            }
            SQL = "Select IDREPORT from report";
            results = stmt.executeQuery(SQL);
            int idreport = getLastReport();
            Calendar cal = Calendar.getInstance();
            if (!Exist) {
                System.err.println(iduser);
                SQL = "INSERT INTO report(IDREPORT,IDREQUEST,REPORT,REPORTDATE,idSender,seen)" + "values ('"
                        + idreport + "','" + idrequest + "','" + jTextArea1.getText() + "','"
                        + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.getTime()) + "'," + iduser + ",0)";
                stmt.executeUpdate(SQL);
            } else {
                SQL = "update report set report = '" + jTextArea1.getText() + "',idSender=" + iduser
                        + " where idreport = " + re;
                stmt.executeUpdate(SQL);
                int F, E;
                if (jRadioButton1.isSelected()) {
                    F = 2;
                } else {
                    F = 1;
                }
                if (jRadioButton2.isSelected()) {
                    E = 2;
                } else {
                    E = 1;
                }
                SQL = "UPDATE  request SET error = " + E + ",Finished = " + F + " where idrequest = " + idrequest;
                stmt.executeUpdate(SQL);
            }

        } catch (SQLException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void setWindows() {
        try {
            int idrequest = getSelectedrequest();
            connect = new Connection();
            Statement stmt = connect.con.createStatement();
            String SQL = "SELECT * from request where idrequest =" + idrequest;
            ResultSet results = stmt.executeQuery(SQL);
            results.next();
            if (results.getInt("ERROR") == 2) {
                jRadioButton2.setSelected(true);
            }
            if (results.getInt("FINISHED") == 2) {
                jRadioButton1.setSelected(true);
            }
            SQL = "SELECT * from REPORT where idrequest =" + idrequest;
            results = stmt.executeQuery(SQL);
            if (results.next()) {
                jTextArea1.setText(results.getString("REPORT"));
            }
        } catch (SQLException ex) {
            Logger.getLogger(Sub.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    /**
     * @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 ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Sub.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(() -> {
            new Sub().setVisible(true);
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JPanel jFirst;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel3;
    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.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JPanel jReport;
    private javax.swing.JPanel jReqeusts;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables
    Connection connect;
    Subordinates subordinate;
    public DefaultTableModel model;
    AnimationClass c;
    Request request;
}