/*
* VentanaCargarSalones.java
*
* Created on 3 de agosto de 2007, 12:20 PM
*/
package ManejoVentanas;
import GeneracionHorarios.*;
import ManejoArchivos.ArchivoSalon;
import ManejoBD.AccesoBD;
import ManejoBD.SalonBD;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.*;
public class VentanaCargarSalones extends javax.swing.JDialog {
private EstructuraGeneral estGeneral;
public VentanaCargarSalones(VentanaPrincipal parent,EstructuraGeneral estGeneral) {
super(parent, true);
initComponents();
this.estGeneral=estGeneral;
this.txtLun.setText("C:\\Archivos_IA\\LUNES.txt");
this.txtMar.setText("C:\\Archivos_IA\\MARTES.txt");
this.txtMie.setText("C:\\Archivos_IA\\MIERCOLES.txt");
this.txtJue.setText("C:\\Archivos_IA\\JUEVES.txt");
this.txtVie.setText("C:\\Archivos_IA\\VIERNES.txt");
this.txtSab.setText("C:\\Archivos_IA\\SABADO.txt");
this.setVisible(true);
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
fchRuta = new javax.swing.JFileChooser();
lblLun = new javax.swing.JLabel();
txtLun = new javax.swing.JTextField();
btnLun = new javax.swing.JButton();
lblMar = new javax.swing.JLabel();
lblMie = new javax.swing.JLabel();
lblJue = new javax.swing.JLabel();
lblVie = new javax.swing.JLabel();
txtMar = new javax.swing.JTextField();
txtMie = new javax.swing.JTextField();
txtJue = new javax.swing.JTextField();
txtVie = new javax.swing.JTextField();
btnMar = new javax.swing.JButton();
btnMie = new javax.swing.JButton();
btnJue = new javax.swing.JButton();
btnVie = new javax.swing.JButton();
btnAceptar = new javax.swing.JButton();
btnCancelar = new javax.swing.JButton();
lblIndicaciones = new javax.swing.JLabel();
lblSab = new javax.swing.JLabel();
txtSab = new javax.swing.JTextField();
btnSab = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Cargar Salones");
lblLun.setText("Lunes: ");
btnLun.setText("Examinar...");
btnLun.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnLunActionPerformed(evt);
}
});
lblMar.setText("Martes:");
lblMie.setText("Miercoles:");
lblJue.setText("Jueves:");
lblVie.setText("Viernes:");
btnMar.setText("Examinar...");
btnMar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnMarActionPerformed(evt);
}
});
btnMie.setText("Examinar...");
btnMie.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnMieActionPerformed(evt);
}
});
btnJue.setText("Examinar...");
btnJue.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnJueActionPerformed(evt);
}
});
btnVie.setText("Examinar...");
btnVie.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnVieActionPerformed(evt);
}
});
btnAceptar.setText("Aceptar");
btnAceptar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAceptarActionPerformed(evt);
}
});
btnCancelar.setText("Cancelar");
btnCancelar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCancelarActionPerformed(evt);
}
});
lblIndicaciones.setText("Ingrese la ruta de archivos para los d\u00edas respectivos:");
lblSab.setText("S\u00e1bado:");
btnSab.setText("Examinar...");
btnSab.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSabActionPerformed(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(50, 50, 50)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblMie)
.addComponent(lblMar)
.addComponent(lblJue)
.addComponent(lblVie)
.addComponent(lblLun)
.addComponent(lblSab))
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(txtMie, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtVie, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
.addComponent(txtJue, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(btnAceptar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
.addComponent(btnCancelar))
.addComponent(txtSab, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)))
.addComponent(txtMar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
.addComponent(txtLun, javax.swing.GroupLayout.Alignment.LEADING))
.addGap(25, 25, 25)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnSab)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(btnLun)
.addComponent(btnMar)
.addComponent(btnMie)
.addComponent(btnJue)
.addComponent(btnVie))))
.addGroup(layout.createSequentialGroup()
.addGap(93, 93, 93)
.addComponent(lblIndicaciones)))
.addContainerGap(38, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblIndicaciones)
.addGap(15, 15, 15)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblLun)
.addComponent(txtLun, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnLun))
.addGap(21, 21, 21)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtMar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblMar)
.addComponent(btnMar))
.addGap(25, 25, 25)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtMie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblMie)
.addComponent(btnMie))
.addGap(19, 19, 19)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtJue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnJue))
.addComponent(lblJue))
.addGap(23, 23, 23)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtVie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnVie))
.addComponent(lblVie, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(16, 16, 16)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblSab)
.addComponent(txtSab, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnSab))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnAceptar)
.addComponent(btnCancelar))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnSabActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSabActionPerformed
leerRuta(txtSab);
}//GEN-LAST:event_btnSabActionPerformed
private void btnVieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVieActionPerformed
leerRuta(txtVie);
}//GEN-LAST:event_btnVieActionPerformed
private void btnJueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnJueActionPerformed
leerRuta(txtJue);
}//GEN-LAST:event_btnJueActionPerformed
private void btnMieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMieActionPerformed
leerRuta(txtMie);
}//GEN-LAST:event_btnMieActionPerformed
private void btnMarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMarActionPerformed
leerRuta(txtMar);
}//GEN-LAST:event_btnMarActionPerformed
private void btnLunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLunActionPerformed
leerRuta(txtLun);
}//GEN-LAST:event_btnLunActionPerformed
private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
String salones[] = new String[6];
salones[0] = this.txtLun.getText();
salones[1] = this.txtMar.getText();
salones[2] = this.txtMie.getText();
salones[3] = this.txtJue.getText();
salones[4] = this.txtVie.getText();
salones[5] = this.txtSab.getText();
ArchivoSalon archSalon = null;
try {
//Cargamos los salones en la BD
AccesoBD.conexionODBC("horariosBD");
for (int i=0;i<salones.length;i++){
archSalon = new ArchivoSalon(salones[i]);
Salon salon;
String dia;
switch (i){
case 0 : dia = "LUNES";break;
case 1 : dia = "MARTES";break;
case 2 : dia = "MIERCOLES";break;
case 3 : dia = "JUEVES";break;
case 4 : dia = "VIERNES";break;
default : dia = "SABADO";
}
estGeneral.modificarDia(dia,i);
while (true){
try{
salon = archSalon.leer(dia);
} catch(IOException ex){
break;
}
SalonBD.agregarSalon(salon,dia);
AccesoBD.conn.commit();
estGeneral.modificarEst(salon,i);
}
}
JOptionPane.showMessageDialog(this,"Los archivos se cargaron correctamente");
} catch (Exception ex) {
JOptionPane.showMessageDialog(this,"Error en la carga de archivos : " + ex);
} finally {
try {
if (archSalon!=null) archSalon.finLectura();
AccesoBD.desconexion();
} catch (Exception ex) {}
dispose();
}
}//GEN-LAST:event_btnAceptarActionPerformed
private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
dispose();
}//GEN-LAST:event_btnCancelarActionPerformed
private void leerRuta(JTextField txtRuta){
int result = fchRuta.showOpenDialog(VentanaCargarSalones.this);
if (result == fchRuta.APPROVE_OPTION){
txtRuta.setText(fchRuta.getSelectedFile().getAbsolutePath());
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAceptar;
private javax.swing.JButton btnCancelar;
private javax.swing.JButton btnJue;
private javax.swing.JButton btnLun;
private javax.swing.JButton btnMar;
private javax.swing.JButton btnMie;
private javax.swing.JButton btnSab;
private javax.swing.JButton btnVie;
private javax.swing.JFileChooser fchRuta;
private javax.swing.JLabel lblIndicaciones;
private javax.swing.JLabel lblJue;
private javax.swing.JLabel lblLun;
private javax.swing.JLabel lblMar;
private javax.swing.JLabel lblMie;
private javax.swing.JLabel lblSab;
private javax.swing.JLabel lblVie;
private javax.swing.JTextField txtJue;
private javax.swing.JTextField txtLun;
private javax.swing.JTextField txtMar;
private javax.swing.JTextField txtMie;
private javax.swing.JTextField txtSab;
private javax.swing.JTextField txtVie;
// End of variables declaration//GEN-END:variables
}