package biblioteca.gui;
import biblioteca.model.Aluno;
import biblioteca.service.AlunoService;
import javax.swing.JOptionPane;
/**
*
* @author Camila
*/
public class ConsultarStatus extends javax.swing.JFrame {
/** Cria novo formulário para consulta de matrícula */
public ConsultarStatus() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
categoria = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
matricula = new javax.swing.JTextField();
consultar = new javax.swing.JButton();
limpar = new javax.swing.JButton();
voltar = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel5.setFont(new java.awt.Font("Times New Roman", 1, 14));
jLabel5.setText("Informe abaixo os dados referentes ao solicitante do empréstimo:");
jLabel6.setFont(new java.awt.Font("Times New Roman", 1, 24));
jLabel6.setText("Consultar Status");
jLabel9.setFont(new java.awt.Font("Times New Roman", 1, 18));
jLabel9.setText("Categoria:");
categoria.setFont(new java.awt.Font("Times New Roman", 2, 14));
categoria.setForeground(new java.awt.Color(204, 204, 255));
jLabel7.setFont(new java.awt.Font("Times New Roman", 1, 18));
jLabel7.setText("Matrícula:");
matricula.setFont(new java.awt.Font("Times New Roman", 2, 14));
matricula.setForeground(new java.awt.Color(204, 204, 255));
consultar.setFont(new java.awt.Font("Times New Roman", 1, 18));
consultar.setText("Consultar");
consultar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
consultarActionPerformed(evt);
}
});
limpar.setFont(new java.awt.Font("Times New Roman", 1, 18));
limpar.setText("Limpar");
limpar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
limparActionPerformed(evt);
}
});
voltar.setFont(new java.awt.Font("Times New Roman", 1, 18));
voltar.setText("Voltar");
voltar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
voltarActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(consultar)
.addGap(41, 41, 41)
.addComponent(limpar)
.addGap(36, 36, 36)
.addComponent(voltar))
.addGroup(layout.createSequentialGroup()
.addGap(122, 122, 122)
.addComponent(jLabel6))
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jLabel5))
.addGroup(layout.createSequentialGroup()
.addGap(95, 95, 95)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel9)
.addComponent(jLabel7))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(categoria)
.addComponent(matricula, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(16, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel6)
.addGap(18, 18, 18)
.addComponent(jLabel5)
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel9)
.addGap(18, 18, 18)
.addComponent(jLabel7))
.addGroup(layout.createSequentialGroup()
.addComponent(categoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(matricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(52, 52, 52)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(consultar)
.addComponent(limpar)
.addComponent(voltar))
.addContainerGap(23, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void consultarActionPerformed(java.awt.event.ActionEvent evt) {
if(categoria.getText().equals("")){
JOptionPane.showMessageDialog(null, "O campo CATEGORIA não pode ser nulo!");
return;
}
if(!categoria.getText().equals("ALUNO") && !categoria.getText().equals("PROFESSOR")
&& !categoria.getText().equals("FUNCIONARIO")){
JOptionPane.showMessageDialog(null, "O campo CATEGORIA deve ser preenchido com uma das opções abaixo:"
+ "\n 1. ALUNO"
+ "\n 2. PROFESSOR"
+ "\n 3. FUNCIONARIO");
categoria.setText(null);
return;
}
if(matricula.getText().equals("")){
JOptionPane.showMessageDialog(null, "O campo MATRÍCULA não pode ser nulo!");
return;
}
if(categoria.getText().equals("ALUNO")){
Aluno aluno = new Aluno();
try {
String Smatricula = matricula.getText();
if(Smatricula.length()>7){
JOptionPane.showMessageDialog(null, "O campo MATRÍCULA não pode conter mais de 7 dígitos!");
matricula.setText(null);
return;
}
aluno.setMatricula(Smatricula);
}
catch (NumberFormatException e){
JOptionPane.showMessageDialog(null,"O campo MATRÍCULA deve conter apenas números!" );
matricula.setText(null);
return;
}
//Consulta:
try{
AlunoService.getInstance().selectStatus(aluno.getMatricula());
}
catch(Exception e){
JOptionPane.showMessageDialog(null,"Erro : " + e.getMessage());
}
}
}
public void limpaDados(){
categoria.setText(null);
matricula.setText(null);
}
private void limparActionPerformed(java.awt.event.ActionEvent evt) {
limpaDados();
}
private void voltarActionPerformed(java.awt.event.ActionEvent evt) {
new PaginaInicial().setVisible(true);
dispose();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ConsultarStatus().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField categoria;
private javax.swing.JButton consultar;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel9;
private javax.swing.JButton limpar;
private javax.swing.JTextField matricula;
private javax.swing.JButton voltar;
// End of variables declaration
}