Package club.ui

Source Code of club.ui.AdminManagerDialog

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package club.ui;

import club.beans.AdministratorBean;
import club.data.DataAdmin;
import club.ulti.FormatConverter;
import club.ulti.Validator;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
*
* @author sior
*/
public class AdminManagerDialog extends javax.swing.JDialog {

    /**
     * Creates new form AdminManagerDialog
     */
    public AdminManagerDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        this.setLocation(370, 100);
        initComponents();
        init();
    }
   
    private void init(){
        panelForm.setVisible(false);
        this.setSize(this.getWidth(), 290);
        initAdminTable();
        initStatus();
    }
   
    private void initStatus(){
        cbbStatus.removeAllItems();
        cbbStatus.addItem("Deactived");
        cbbStatus.addItem("Staff");
        cbbStatus.addItem("Admin");
        cbbStatus.setSelectedIndex(1);
    }
   
    private void initAdminTable(){
        adminColName = new Vector();
        adminColName.add("ID");
        adminColName.add("Fullname");
        adminColName.add("Account");
        adminColName.add("Status");
        updateAdminTable();
    }
   
    public void updateAdminTable(){
        adminData = new Vector();
        List<AdministratorBean> lists = dataAdmin.getAllAdmins();
        for(AdministratorBean bean : lists){
            Vector row = new Vector();
            row.add(bean.getAdminID());
            row.add(bean.getFullname());
            row.add(bean.getAccount());
            row.add(FormatConverter.showAdminStatus(bean.getStatus()));
            adminData.add(row);
        }
        adminModel = new DefaultTableModel(){  
            @Override
            public boolean isCellEditable(int row, int column) {
                //all cells false
                return false;
            }
        };
        adminModel.setDataVector(adminData, adminColName);
        tblAdmin.setModel(adminModel);
    }
   
    private void clearAllInput(){
        tfAdminName.setText(null);
        tfNewpassword.setText(null);
        tfConfirmPassword.setText(null);
    }
    private ArrayList validateAllForm(){
        ArrayList errors = new ArrayList();
        if (!Validator.checkIsNotEmpty(tfAdminName.getText())){
            errors.add("Name can not be empty");
        }
        if (!Validator.checkIsNotEmpty(tfAccount.getText())){
            errors.add("Account can not be empty");
        } else if (tfAccount.getText().trim().length() < 3){
            errors.add("Account has at least 3 characters");
        }
        if (!Validator.checkIsNotEmpty(tfNewpassword.getText())){
            errors.add("Password can not be empty");
        } else if (tfConfirmPassword.getText().trim().length() < 5){
            errors.add("Password has at least 5 characters");
        }
        if (!Validator.checkMatchPassword(tfNewpassword.getText(), tfConfirmPassword.getText())){
            errors.add("Password does not match");
        }
       
        return errors;
    }
   
    private void addAdmin(){
       
    }

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

        jScrollPane1 = new javax.swing.JScrollPane();
        tblAdmin = new javax.swing.JTable();
        btn_Add = new javax.swing.JButton();
        btn_Update = new javax.swing.JButton();
        btn_Delete = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        panelForm = new javax.swing.JPanel();
        lbLine1 = new javax.swing.JLabel();
        tfAdminName = new javax.swing.JTextField();
        btn_ApplyName = new javax.swing.JButton();
        btn_Abort = new javax.swing.JButton();
        txtHiddenID = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        lbLine2 = new javax.swing.JLabel();
        lbLine3 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        cbbStatus = new javax.swing.JComboBox();
        btn_ApplyStatus = new javax.swing.JButton();
        btn_ApplyPassword = new javax.swing.JButton();
        btn_Submit = new javax.swing.JButton();
        tfNewpassword = new javax.swing.JPasswordField();
        tfConfirmPassword = new javax.swing.JPasswordField();
        lbAccount = new javax.swing.JLabel();
        tfAccount = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Manage admin");
        setResizable(false);

        tblAdmin.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"
            }
        ));
        jScrollPane1.setViewportView(tblAdmin);

        btn_Add.setText("Add");
        btn_Add.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_AddActionPerformed(evt);
            }
        });

        btn_Update.setText("Update");
        btn_Update.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_UpdateActionPerformed(evt);
            }
        });

        btn_Delete.setText("Delete");
        btn_Delete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_DeleteActionPerformed(evt);
            }
        });

        btnCancel.setText("Cancel");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        panelForm.setBorder(javax.swing.BorderFactory.createTitledBorder("Administrator Details"));

        lbLine1.setText("Administrator Name");

        tfAdminName.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tfAdminNameFocusGained(evt);
            }
        });
        tfAdminName.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tfAdminNameKeyReleased(evt);
            }
        });

        btn_ApplyName.setText("Apply");
        btn_ApplyName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ApplyNameActionPerformed(evt);
            }
        });

        btn_Abort.setText("Abort");
        btn_Abort.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_AbortActionPerformed(evt);
            }
        });

        txtHiddenID.setEditable(false);
        txtHiddenID.setBackground(new java.awt.Color(204, 204, 204));
        txtHiddenID.setText("#");

        jLabel6.setText("ID");

        lbLine2.setText("New Password");

        lbLine3.setText("Confirm New Password");

        jLabel1.setText("Status");

        cbbStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        btn_ApplyStatus.setText("Apply");
        btn_ApplyStatus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ApplyStatusActionPerformed(evt);
            }
        });

        btn_ApplyPassword.setText("Apply");
        btn_ApplyPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ApplyPasswordActionPerformed(evt);
            }
        });

        btn_Submit.setText("Add");
        btn_Submit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_SubmitActionPerformed(evt);
            }
        });

        tfNewpassword.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tfNewpasswordFocusGained(evt);
            }
        });
        tfNewpassword.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tfNewpasswordKeyReleased(evt);
            }
        });

        tfConfirmPassword.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tfConfirmPasswordFocusGained(evt);
            }
        });
        tfConfirmPassword.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tfConfirmPasswordKeyReleased(evt);
            }
        });

        lbAccount.setText("Account");

        tfAccount.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                tfAccountFocusGained(evt);
            }
        });
        tfAccount.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tfAccountKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout panelFormLayout = new javax.swing.GroupLayout(panelForm);
        panelForm.setLayout(panelFormLayout);
        panelFormLayout.setHorizontalGroup(
            panelFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFormLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelFormLayout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(48, 48, 48)
                        .addComponent(lbLine1)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(panelFormLayout.createSequentialGroup()
                        .addComponent(txtHiddenID, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(panelFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbLine2)
                            .addGroup(panelFormLayout.createSequentialGroup()
                                .addGroup(panelFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(panelFormLayout.createSequentialGroup()
                                        .addComponent(tfAdminName, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                                    .addGroup(panelFormLayout.createSequentialGroup()
                                        .addComponent(tfNewpassword)
                                        .addGap(6, 6, 6)))
                                .addGroup(panelFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(btn_ApplyName)
                                    .addComponent(btn_ApplyPassword)))
                            .addComponent(lbLine3)
                            .addGroup(panelFormLayout.createSequentialGroup()
                                .addGroup(panelFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cbbStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel1))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btn_ApplyStatus))
                            .addComponent(tfConfirmPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lbAccount)
                            .addComponent(tfAccount, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(panelFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(btn_Submit, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btn_Abort, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(14, Short.MAX_VALUE))))
        );
        panelFormLayout.setVerticalGroup(
            panelFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelFormLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(lbLine1))
                .addGroup(panelFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelFormLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtHiddenID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tfAdminName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btn_ApplyName))
                        .addGap(4, 4, 4)
                        .addComponent(lbAccount)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfAccount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(7, 7, 7)
                        .addComponent(lbLine2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(btn_ApplyPassword)
                            .addComponent(tfNewpassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lbLine3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfConfirmPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelFormLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbbStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btn_ApplyStatus)))
                    .addGroup(panelFormLayout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(btn_Submit, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_Abort, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelFormLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btn_Abort, btn_Submit});

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelForm, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btn_Add)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_Update)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_Delete)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCancel)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_Add)
                    .addComponent(btn_Update)
                    .addComponent(btnCancel)
                    .addComponent(btn_Delete))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelForm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(23, Short.MAX_VALUE))
        );

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

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnCancelActionPerformed

    private void tfAdminNameKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfAdminNameKeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_tfAdminNameKeyReleased

    private void btn_AbortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_AbortActionPerformed
        clearAllInput();
        panelForm.setVisible(false);
        this.setSize(this.getWidth(), 290);
    }//GEN-LAST:event_btn_AbortActionPerformed

    private void btn_AddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_AddActionPerformed
        // TODO add your handling code here:
        tfAdminName.setText("");
        txtHiddenID.setText("#");
        lbAccount.setVisible(true);
        tfAccount.setVisible(true);
        lbLine2.setText("Password");
        lbLine3.setText("Confirm Password                        ");
        btn_ApplyName.setVisible(false);
        btn_ApplyPassword.setVisible(false);
        btn_ApplyStatus.setVisible(false);
        btn_Submit.setVisible(true);
        panelForm.setVisible(true);
        this.setSize(this.getWidth(),620);
    }//GEN-LAST:event_btn_AddActionPerformed

    private void btn_UpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_UpdateActionPerformed
        // TODO add your handling code here:
        int selectedRow = tblAdmin.getSelectedRow();
        if (selectedRow == -1) {
            JOptionPane.showMessageDialog(rootPane, "You must chose one admin first!", "Error!", JOptionPane.ERROR_MESSAGE);
        } else {
            int id = (int) tblAdmin.getModel().getValueAt(selectedRow, 0);
            AdministratorBean bean = DataAdmin.getAdminByID(id);
            lbAccount.setVisible(false);
            tfAccount.setVisible(false);
            tfAdminName.setText(bean.getFullname());
            txtHiddenID.setText(bean.getAdminID() + "");
            tfNewpassword.setText("");
            tfConfirmPassword.setText("");
            lbLine2.setText("New password");
            lbLine3.setText("Confirm new password");
            btn_ApplyName.setVisible(true);
            btn_ApplyPassword.setVisible(true);
            btn_ApplyStatus.setVisible(true);
            btn_Submit.setVisible(false);
            cbbStatus.setSelectedIndex(bean.getStatus());
            panelForm.setVisible(true);
            this.setSize(this.getWidth(), 580);
        }
    }//GEN-LAST:event_btn_UpdateActionPerformed

    private void btn_SubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_SubmitActionPerformed
        // TODO add your handling code here:
        if (validateAllForm().isEmpty()){
            if (DataAdmin.insertAdmin(tfAccount.getText(), tfNewpassword.getText(), tfAdminName.getText(), cbbStatus.getSelectedIndex())){
                JOptionPane.showMessageDialog(rootPane, "Successfully add new administrator");
                updateAdminTable();
                clearAllInput();
                panelForm.setVisible(false);
                this.setSize(this.getWidth(), 290);
            } else{
                JOptionPane.showMessageDialog(rootPane, "Error occured! Try again.");
            }
        } else{
            Validator.showErrors(validateAllForm());
        }
       
    }//GEN-LAST:event_btn_SubmitActionPerformed

    private void btn_ApplyNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ApplyNameActionPerformed
        // TODO add your handling code here:
        if (!Validator.checkIsNotEmpty(tfAdminName.getText())){
            JOptionPane.showMessageDialog(rootPane, "Name can not be empty");
        } else{
            if (DataAdmin.updateAdminByID("Fullname", tfAdminName.getText(), Integer.parseInt(txtHiddenID.getText()))){
                JOptionPane.showMessageDialog(rootPane, "Successfully changed name");
                updateAdminTable();
                clearAllInput();
                panelForm.setVisible(false);
                this.setSize(this.getWidth(), 290);
            } else{
                JOptionPane.showMessageDialog(rootPane, "Error occured! Try again.");
            }
        }
    }//GEN-LAST:event_btn_ApplyNameActionPerformed

    private void btn_ApplyPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ApplyPasswordActionPerformed
        // TODO add your handling code here:
        if (!Validator.checkIsNotEmpty(tfNewpassword.getText())){
            JOptionPane.showMessageDialog(rootPane, "Password can not be empty");
        } else if (tfNewpassword.getText().trim().length() < 5){
            JOptionPane.showMessageDialog(rootPane, "Password must have at least 5 characters");
        } else if (!Validator.checkMatchPassword(tfNewpassword.getText(), tfConfirmPassword.getText())){
            JOptionPane.showMessageDialog(rootPane, "Password does not match");
        } else {
            if (DataAdmin.updateAdminByID("Password", tfNewpassword.getText(), Integer.parseInt(txtHiddenID.getText()))){
                JOptionPane.showMessageDialog(rootPane, "Successfully changed passwor");
                updateAdminTable();
                clearAllInput();
                panelForm.setVisible(false);
                this.setSize(this.getWidth(), 290);
               
            } else{
                JOptionPane.showMessageDialog(rootPane, "Error occured! Try again.");
            }
        }
    }//GEN-LAST:event_btn_ApplyPasswordActionPerformed

    private void btn_ApplyStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ApplyStatusActionPerformed
        // TODO add your handling code here:
        if (3 == 4){
            JOptionPane.showMessageDialog(rootPane, "validate status");
        } else {
            String stt = cbbStatus.getSelectedIndex() + "";
            if (DataAdmin.updateAdminByID("Status", stt, Integer.parseInt(txtHiddenID.getText()))){
                JOptionPane.showMessageDialog(rootPane, "Successfully changed status");
                updateAdminTable();
                clearAllInput();
                panelForm.setVisible(false);
                this.setSize(this.getWidth(), 290);
               
            } else{
                JOptionPane.showMessageDialog(rootPane, "Error occured! Try again.");
            }
        }
    }//GEN-LAST:event_btn_ApplyStatusActionPerformed

    private void btn_DeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_DeleteActionPerformed
        // TODO add your handling code here:
        int selectedRow = tblAdmin.getSelectedRow();
        if (selectedRow == -1) {
            JOptionPane.showMessageDialog(rootPane, "You must chose one admin first!", "Error!", JOptionPane.ERROR_MESSAGE);
        } else {
            int id = (int) tblAdmin.getModel().getValueAt(selectedRow, 0);
            AdministratorBean bean = DataAdmin.getAdminByID(id);
           
        }
    }//GEN-LAST:event_btn_DeleteActionPerformed

    private void tfAdminNameFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfAdminNameFocusGained
        // TODO add your handling code here:
        tfAdminName.selectAll();
    }//GEN-LAST:event_tfAdminNameFocusGained

    private void tfAccountFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfAccountFocusGained
        // TODO add your handling code here:
        tfAccount.selectAll();
    }//GEN-LAST:event_tfAccountFocusGained

    private void tfNewpasswordFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfNewpasswordFocusGained
        // TODO add your handling code here:
        tfNewpassword.selectAll();
    }//GEN-LAST:event_tfNewpasswordFocusGained

    private void tfConfirmPasswordFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfConfirmPasswordFocusGained
        // TODO add your handling code here:
        tfConfirmPassword.selectAll();
    }//GEN-LAST:event_tfConfirmPasswordFocusGained

    private void tfNewpasswordKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfNewpasswordKeyReleased
        // TODO add your handling code here:
        Validator.Validate(tfNewpassword, Validator.checkPassword(tfNewpassword.getPassword()));
    }//GEN-LAST:event_tfNewpasswordKeyReleased

    private void tfConfirmPasswordKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfConfirmPasswordKeyReleased
        // TODO add your handling code here:
        Validator.Validate(tfConfirmPassword, Validator.checkMatchPassword(tfNewpassword.getText(),tfConfirmPassword.getText()));
    }//GEN-LAST:event_tfConfirmPasswordKeyReleased

    private void tfAccountKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfAccountKeyReleased
        // TODO add your handling code here:
        Validator.Validate(tfConfirmPassword, Validator.checkAccount(tfAccount.getText()));
    }//GEN-LAST:event_tfAccountKeyReleased

    private DefaultTableModel adminModel;
    private Vector adminData;
    private Vector adminColName;
    DataAdmin dataAdmin = new DataAdmin();
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btn_Abort;
    private javax.swing.JButton btn_Add;
    private javax.swing.JButton btn_ApplyName;
    private javax.swing.JButton btn_ApplyPassword;
    private javax.swing.JButton btn_ApplyStatus;
    private javax.swing.JButton btn_Delete;
    private javax.swing.JButton btn_Submit;
    private javax.swing.JButton btn_Update;
    private javax.swing.JComboBox cbbStatus;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbAccount;
    private javax.swing.JLabel lbLine1;
    private javax.swing.JLabel lbLine2;
    private javax.swing.JLabel lbLine3;
    private javax.swing.JPanel panelForm;
    private javax.swing.JTable tblAdmin;
    private javax.swing.JTextField tfAccount;
    private javax.swing.JTextField tfAdminName;
    private javax.swing.JPasswordField tfConfirmPassword;
    private javax.swing.JPasswordField tfNewpassword;
    private javax.swing.JTextField txtHiddenID;
    // End of variables declaration//GEN-END:variables
}
TOP

Related Classes of club.ui.AdminManagerDialog

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.