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



import COMPONENTES_DISENHO.Icono;
import CONTROL.ControlInterfaz;
import CONTROL.ControlInterfazSedes;
import CONTROL.ControlRoles;
import CONTROL.Validaciones;
import ENTIDADES.SQL_Sede;
import ENTIDADES.Usuario;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;


/**
 *
 * @author neox
 */
public class gestion_sedes extends javax.swing.JFrame implements ControlInterfaz{
    
   
    
    private GUI_Menu menu;
    private Listar_sedes listaSedes;
    private ControlRoles manejador_roles;
    private Usuario usuario;//recordar que las interfaces tiene un usuario que es seteado luego 
    private ControlInterfazSedes control_sedes;
    private SQL_Sede sql_sede;
    private Validaciones validar;
    
    private boolean funcion;//para determinar si se va a agregar o a modificar.
    
    
    /**
     * Creates new form gestion_sedes
     */
    public gestion_sedes(GUI_Menu menu) {
        
        initComponents();
        Icono icon = new Icono(this);
        
        //---------- Instanciación de elementos ---------------//
        
        this.menu = menu;
        this.control_sedes = new ControlInterfazSedes();
        this.sql_sede = new SQL_Sede();
        this.validar = new Validaciones();
        
        nombre_sede.setEnabled(false);
        
        direccion_sede.setEnabled(false);
        telefono_sede.setEnabled(false);
        estado_sede.setEnabled(false);
        correo_sede.setEnabled(false);
        ciudad_sede.setEnabled(false);
        id_sede.setEnabled(false);
        
        btn_crear.setEnabled(false);
        btn_cancelar.setEnabled(false);
        btn_limpiar.setEnabled(false);
    }

    //----------- GETTER'S ---------

    public JButton getBtn_agregar() {
        return btn_agregar;
    }

    public JButton getBtn_cancelar() {
        return btn_cancelar;
    }

    public JButton getBtn_crear() {
        return btn_crear;
    }

    public JButton getBtn_limpiar() {
        return btn_limpiar;
    }

    public JButton getBtn_listar() {
        return btn_listar;
    }

    public JButton getBtn_menu() {
        return btn_menu;
    }

    public JButton getBtn_modificar() {
        return btn_modificar;
    }

    public JButton getBtn_salir() {
        return btn_salir;
    }

    public JLabel getEstadoSede_jLabel() {
        return EstadoSede_jLabel;
    }

    public JTextField getCiudad_sede() {
        return ciudad_sede;
    }

    public JTextField getCorreo_sede() {
        return correo_sede;
    }

    public JTextField getDireccion_sede() {
        return direccion_sede;
    }

    public JComboBox getEstado_sede() {
        return estado_sede;
    }

    public JTextField getId_sede() {
        return id_sede;
    }

    public JTextField getNombre_sede() {
        return nombre_sede;
    }

    public JTextField getTelefono_sede() {
        return telefono_sede;
    }
    
    //--------------------------
    
    
    //-------- SETTER'S -----------
    
    
    public void setControl_roles(ControlRoles control_roles) {
        this.manejador_roles = control_roles;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

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

        info_jPanel = new javax.swing.JPanel();
        icono_jLabel = new javax.swing.JLabel();
        sedes_jLabel = new javax.swing.JLabel();
        ppal_jPanel = new javax.swing.JPanel();
        btn_salir = new javax.swing.JButton();
        btn_menu = new javax.swing.JButton();
        opcionSedes_jPanel = new javax.swing.JPanel();
        btn_agregar = new javax.swing.JButton();
        btn_modificar = new javax.swing.JButton();
        btn_listar = new javax.swing.JButton();
        gestion_jPanel = new javax.swing.JPanel();

        nombreSede_jLabel = new javax.swing.JLabel();
        nombre_sede = new javax.swing.JTextField();
        nombre_sede.setEditable(false);
        direccionSede_jLabel = new javax.swing.JLabel();
        direccion_sede = new javax.swing.JTextField();
        direccion_sede.setEditable(false);
        telefonoSede_jLabel = new javax.swing.JLabel();
        telefono_sede = new javax.swing.JTextField();
        EstadoSede_jLabel = new javax.swing.JLabel();
        correoSede_jLabel = new javax.swing.JLabel();
        correo_sede = new javax.swing.JTextField();
        ciudadSede_jLabel = new javax.swing.JLabel();
        ciudad_sede = new javax.swing.JTextField();
        estado_sede = new javax.swing.JComboBox();
        IdSede_jLabel = new javax.swing.JLabel();
        id_sede = new javax.swing.JTextField();
        iconoSedes_jLabel = new javax.swing.JLabel();
        btn_crear = new javax.swing.JButton();
        btn_cancelar = new javax.swing.JButton();
        btn_limpiar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        icono_jLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/files/icono.png"))); // NOI18N
        icono_jLabel.setText("jLabel1");

        sedes_jLabel.setFont(new java.awt.Font("Kalinga", 1, 18)); // NOI18N
        sedes_jLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        sedes_jLabel.setText("Gestión de sedes");

        javax.swing.GroupLayout info_jPanelLayout = new javax.swing.GroupLayout(info_jPanel);
        info_jPanel.setLayout(info_jPanelLayout);
        info_jPanelLayout.setHorizontalGroup(
            info_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, info_jPanelLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(sedes_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(98, 98, 98)
                .addComponent(icono_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        info_jPanelLayout.setVerticalGroup(
            info_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, info_jPanelLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(info_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(icono_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(sedes_jLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        btn_salir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/files/16-em-cross.png"))); // NOI18N
        btn_salir.setText("Salir");
        btn_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_salirActionPerformed(evt);
            }
        });

        btn_menu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/files/24-frame.png"))); // NOI18N
        btn_menu.setText("Menú");
        btn_menu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_menuActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout ppal_jPanelLayout = new javax.swing.GroupLayout(ppal_jPanel);
        ppal_jPanel.setLayout(ppal_jPanelLayout);
        ppal_jPanelLayout.setHorizontalGroup(
            ppal_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ppal_jPanelLayout.createSequentialGroup()
                .addContainerGap(58, Short.MAX_VALUE)
                .addComponent(btn_menu)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_salir))
        );
        ppal_jPanelLayout.setVerticalGroup(
            ppal_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ppal_jPanelLayout.createSequentialGroup()
                .addGroup(ppal_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_salir)
                    .addComponent(btn_menu, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btn_agregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/files/24-image-add.png"))); // NOI18N
        btn_agregar.setText("Agregar");
        btn_agregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_agregarActionPerformed(evt);
            }
        });

        btn_modificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/files/24-image-open.png"))); // NOI18N
        btn_modificar.setText("Modificar");
        btn_modificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_modificarActionPerformed(evt);
            }
        });

        btn_listar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/files/24-sidebar.png"))); // NOI18N
        btn_listar.setText("Listar");
        btn_listar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_listarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout opcionSedes_jPanelLayout = new javax.swing.GroupLayout(opcionSedes_jPanel);
        opcionSedes_jPanel.setLayout(opcionSedes_jPanelLayout);
        opcionSedes_jPanelLayout.setHorizontalGroup(
            opcionSedes_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(opcionSedes_jPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btn_agregar, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btn_modificar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_listar)
                .addContainerGap(35, Short.MAX_VALUE))
        );
        opcionSedes_jPanelLayout.setVerticalGroup(
            opcionSedes_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(opcionSedes_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(btn_modificar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btn_agregar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(opcionSedes_jPanelLayout.createSequentialGroup()
                .addComponent(btn_listar)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        gestion_jPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Nueva Sede"));

        nombreSede_jLabel.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N
        nombreSede_jLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        nombreSede_jLabel.setText("Nombre*");

        nombre_sede.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nombre_sedeActionPerformed(evt);
            }
        });

        direccionSede_jLabel.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N
        direccionSede_jLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        direccionSede_jLabel.setText("Dirección*");

        telefonoSede_jLabel.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N
        telefonoSede_jLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        telefonoSede_jLabel.setText("Telefono*");

        telefono_sede.setEditable(false);

        EstadoSede_jLabel.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N
        EstadoSede_jLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        EstadoSede_jLabel.setText("Estado*");

        correoSede_jLabel.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N
        correoSede_jLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        correoSede_jLabel.setText("Correo*");

        correo_sede.setEditable(false);

        ciudadSede_jLabel.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N
        ciudadSede_jLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        ciudadSede_jLabel.setText("Ciudad");

        ciudad_sede.setEditable(false);
        ciudad_sede.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ciudad_sedeActionPerformed(evt);
            }
        });

        estado_sede.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Seleccione", "Activa", "Inactiva" }));
        estado_sede.setEnabled(false);
        estado_sede.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                estado_sedeActionPerformed(evt);
            }
        });

        IdSede_jLabel.setFont(new java.awt.Font("Kalinga", 0, 12)); // NOI18N
        IdSede_jLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        IdSede_jLabel.setText("ID-Sede");

        id_sede.setEditable(false);
        id_sede.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                id_sedeActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout gestion_jPanelLayout = new javax.swing.GroupLayout(gestion_jPanel);
        gestion_jPanel.setLayout(gestion_jPanelLayout);
        gestion_jPanelLayout.setHorizontalGroup(
            gestion_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gestion_jPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(gestion_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(gestion_jPanelLayout.createSequentialGroup()
                        .addComponent(nombreSede_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(nombre_sede, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(gestion_jPanelLayout.createSequentialGroup()
                        .addComponent(direccionSede_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(direccion_sede, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(gestion_jPanelLayout.createSequentialGroup()
                        .addComponent(telefonoSede_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(telefono_sede, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(gestion_jPanelLayout.createSequentialGroup()
                        .addComponent(EstadoSede_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(estado_sede, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(gestion_jPanelLayout.createSequentialGroup()
                        .addComponent(correoSede_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(correo_sede, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(gestion_jPanelLayout.createSequentialGroup()
                        .addComponent(ciudadSede_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ciudad_sede, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(gestion_jPanelLayout.createSequentialGroup()
                        .addComponent(IdSede_jLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(id_sede, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        gestion_jPanelLayout.setVerticalGroup(
            gestion_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gestion_jPanelLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(gestion_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nombreSede_jLabel)
                    .addComponent(nombre_sede, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gestion_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(direccionSede_jLabel)
                    .addComponent(direccion_sede, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gestion_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(telefonoSede_jLabel)
                    .addComponent(telefono_sede, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gestion_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(EstadoSede_jLabel)
                    .addComponent(estado_sede, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gestion_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(correoSede_jLabel)
                    .addComponent(correo_sede, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gestion_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ciudadSede_jLabel)
                    .addComponent(ciudad_sede, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gestion_jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(IdSede_jLabel)
                    .addComponent(id_sede, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(47, Short.MAX_VALUE))
        );

        iconoSedes_jLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/files/sedes.jpg"))); // NOI18N

        btn_crear.setIcon(new javax.swing.ImageIcon(getClass().getResource("/files/16-em-check.png"))); // NOI18N
        btn_crear.setText("Aceptar");
        btn_crear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_crearActionPerformed(evt);
            }
        });

        btn_cancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/files/12-em-cross.png"))); // NOI18N
        btn_cancelar.setText("Cancelar");
        btn_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_cancelarActionPerformed(evt);
            }
        });

        btn_limpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/files/16-broom_opt.png"))); // NOI18N
        btn_limpiar.setText("Limpiar");
        btn_limpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_limpiarActionPerformed(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)
                    .addComponent(info_jPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(opcionSedes_jPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ppal_jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(gestion_jPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(51, 51, 51)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(iconoSedes_jLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btn_crear, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btn_cancelar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(btn_limpiar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(info_jPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(ppal_jPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(opcionSedes_jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(gestion_jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(iconoSedes_jLabel)
                        .addGap(18, 18, 18)
                        .addComponent(btn_crear)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_cancelar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btn_limpiar)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );

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

    private void btn_menuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_menuActionPerformed
        menu.setVisible(true);
        this.setVisible(false);
       
    }//GEN-LAST:event_btn_menuActionPerformed

    private void btn_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_salirActionPerformed
        System.exit(0);
    }//GEN-LAST:event_btn_salirActionPerformed

    private void btn_agregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_agregarActionPerformed
        
        this.control_sedes.activarBotones(btn_crear, btn_cancelar, btn_limpiar);
        this.btn_crear.setText("Crear");
        this.funcion = true;
        int idSede = sql_sede.cantidadSedes();
        this.control_sedes.habilitarGestion(nombre_sede, direccion_sede, telefono_sede, estado_sede, correo_sede, ciudad_sede, id_sede, idSede);
                                                  
    }//GEN-LAST:event_btn_agregarActionPerformed

    private void btn_modificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_modificarActionPerformed

        
        this.control_sedes.activarBotones(btn_crear, btn_cancelar, btn_limpiar);
        this.btn_crear.setText("Modificar");
        this.funcion = false;
        this.control_sedes.habilitarGestionParaModificar(nombre_sede, direccion_sede, telefono_sede, estado_sede, correo_sede, ciudad_sede, id_sede);
        String id_Mod = "";
        id_Mod = JOptionPane.showInputDialog(null, "Por favor ingrese el ID de la Sede que desea modificar o\n" +
                                                           "Elija la opcion listar y seleccione la sede que desee modificar");
        
        if(id_Mod != null){
            if(sql_sede.existeSede(id_Mod))
            {
                this.sql_sede.datosParaModificarSede(id_Mod, nombre_sede, direccion_sede, telefono_sede, estado_sede, correo_sede, ciudad_sede, id_sede);
            }
            else
            {
                JOptionPane.showMessageDialog(this, "ID no valido", "Error", JOptionPane.ERROR_MESSAGE);
                this.control_sedes.reestablecerGestion(nombre_sede, direccion_sede, telefono_sede, estado_sede, correo_sede, ciudad_sede, id_sede);
            }
        }
        else
        {
            this.control_sedes.reestablecerGestion(nombre_sede, direccion_sede, telefono_sede, estado_sede, correo_sede, ciudad_sede, id_sede);
        }
        
    }//GEN-LAST:event_btn_modificarActionPerformed

    private void nombre_sedeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nombre_sedeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_nombre_sedeActionPerformed

    private void btn_listarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_listarActionPerformed
        this.listaSedes = new Listar_sedes(this);
        listaSedes.iniciar();
        listaSedes.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_btn_listarActionPerformed

    private void estado_sedeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_estado_sedeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_estado_sedeActionPerformed

    private void ciudad_sedeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ciudad_sedeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ciudad_sedeActionPerformed

    private void id_sedeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_id_sedeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_id_sedeActionPerformed

    private void btn_crearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_crearActionPerformed
        
        try {
            validar.ingresoCorrectoNombre(nombre_sede);
            validar.ingresoCorrectoDireccion(direccion_sede);
            validar.ingresoCorrectoTelefono(telefono_sede);
            validar.ingresoCorrectoEstadoSede(estado_sede);
            validar.ingresoCorrectoCorreo(correo_sede);
            validar.ingresoCorrectoCodSede(id_sede);
            validar.ingresoCorrectoCiudad(ciudad_sede);
            String nombreSede = this.nombre_sede.getText();
            String direccionSede = this.direccion_sede.getText();
            String telefonoSede = this.telefono_sede.getText();
            String estadoSede = String.valueOf(this.estado_sede.getSelectedItem());
            String correo = this.correo_sede.getText();
            String ciudad = this.ciudad_sede.getText();
            String idSede = this.id_sede.getText();

            if (this.funcion) {
                if ((sql_sede.ingresarSede(nombreSede, direccionSede, telefonoSede, estadoSede, correo, ciudad, idSede)) != -1) {
                    JOptionPane.showMessageDialog(null, "Registro exitoso", "Aviso", JOptionPane.INFORMATION_MESSAGE);
                    control_sedes.actualizarGestion(nombre_sede, direccion_sede, telefono_sede, estado_sede, correo_sede, ciudad_sede, id_sede);
                    control_sedes.habilitarGestion(nombre_sede, direccion_sede, telefono_sede, estado_sede, correo_sede, ciudad_sede, id_sede, Integer.valueOf(idSede));
                    this.control_sedes.reestablecerGestion(nombre_sede, direccion_sede, telefono_sede, estado_sede, correo_sede, ciudad_sede, id_sede);
                } else {
                    JOptionPane.showMessageDialog(this, "Nombre de usuario y/o contraseña no válidos", "Error de reg", JOptionPane.ERROR_MESSAGE);
                }
            } else if (sql_sede.modificarSede(nombreSede, direccionSede, telefonoSede, estadoSede, correo, ciudad, idSede) != -1) {
                JOptionPane.showMessageDialog(this, "Modificación exitosa", "Aviso", JOptionPane.INFORMATION_MESSAGE);
                control_sedes.actualizarGestion(nombre_sede, direccion_sede, telefono_sede, estado_sede, correo_sede, ciudad_sede, id_sede);
                this.control_sedes.reestablecerGestion(nombre_sede, direccion_sede, telefono_sede, estado_sede, correo_sede, ciudad_sede, id_sede);
            } else {
                JOptionPane.showMessageDialog(this, "Nombre de usuario y/o contraseña no válidos", "Error de reg", JOptionPane.ERROR_MESSAGE);
            }
        }   catch (NumberFormatException e) {
        }   catch (Exception e) {
        }

            
    }//GEN-LAST:event_btn_crearActionPerformed

    private void btn_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_cancelarActionPerformed
        this.control_sedes.reestablecerGestion(nombre_sede, direccion_sede, telefono_sede, estado_sede, correo_sede, ciudad_sede, id_sede);
    }//GEN-LAST:event_btn_cancelarActionPerformed

    private void btn_limpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_limpiarActionPerformed
        this.control_sedes.limpiarGestion(nombre_sede, direccion_sede, telefono_sede, estado_sede, correo_sede, ciudad_sede, id_sede);
    }//GEN-LAST:event_btn_limpiarActionPerformed
    public JButton getAceptar_jButton(){
        return btn_crear;
    }
    //sigue :#
    public JButton getCancelar_jButton(){
        return btn_cancelar;
    }
    
    public JButton getLimpiar_jButton(){
        return btn_limpiar;
    }
    
    public JTextField getNombre_jTextField(){
        return nombre_sede;
    }
    
    public JTextField getDireccion_jTextField(){
        return direccion_sede;
    }
    
    public JTextField getTelefono_jTextField(){
        return telefono_sede;
    }
    
    public JComboBox getEstado_jComboBox(){
        return estado_sede;
    }
    
    public JTextField getEmail_jTextField(){
        return correo_sede;
    }
    
    public JTextField getCiudad_jComboBox(){ //Ciudad no es combobox PANAAA
        return ciudad_sede;
    }
    
    public JTextField getIdSede_jComboBox(){
        return id_sede;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel EstadoSede_jLabel;
    private javax.swing.JLabel IdSede_jLabel;
    private javax.swing.JButton btn_agregar;
    private javax.swing.JButton btn_cancelar;
    private javax.swing.JButton btn_crear;
    private javax.swing.JButton btn_limpiar;
    private javax.swing.JButton btn_listar;
    private javax.swing.JButton btn_menu;
    private javax.swing.JButton btn_modificar;
    private javax.swing.JButton btn_salir;
    private javax.swing.JLabel ciudadSede_jLabel;
    private javax.swing.JTextField ciudad_sede;
    private javax.swing.JLabel correoSede_jLabel;
    private javax.swing.JTextField correo_sede;
    private javax.swing.JLabel direccionSede_jLabel;
    private javax.swing.JTextField direccion_sede;
    private javax.swing.JComboBox estado_sede;
    private javax.swing.JPanel gestion_jPanel;
    private javax.swing.JLabel iconoSedes_jLabel;
    private javax.swing.JLabel icono_jLabel;
    private javax.swing.JTextField id_sede;
    private javax.swing.JPanel info_jPanel;
    private javax.swing.JLabel nombreSede_jLabel;
    private javax.swing.JTextField nombre_sede;
    private javax.swing.JPanel opcionSedes_jPanel;
    private javax.swing.JPanel ppal_jPanel;
    private javax.swing.JLabel sedes_jLabel;
    private javax.swing.JLabel telefonoSede_jLabel;
    private javax.swing.JTextField telefono_sede;
    // End of variables declaration//GEN-END:variables

    @Override
    public void activarInterfaz() {
        
        boolean agregar_sede = this.manejador_roles.isRegistrar_sede();
        boolean modificar_sede = this.manejador_roles.isModificar_sede();
        boolean listar_sede = this.manejador_roles.isListar_sedes();
        
        this.btn_agregar.setEnabled(agregar_sede);
        this.btn_modificar.setEnabled(modificar_sede);
        this.btn_listar.setEnabled(listar_sede);
        
       
    }
    
    
    
}
