Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
txtEmpCedula.setEnabled(false);
}
}catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Error"+ex);
}
}
});
--validacion cedula
public Boolean validarcedula(String c1){
c1=c1.trim();
int sw=0;
try {
if (c1.isEmpty()){
txtEmpCedula.requestFocus();
}
int l=c1.length();
if ((l>10) || (l<10)){
txtEmpCedula.requestFocus();
}
if (!c1.matches("^[0-9]{10}$")){
txtEmpCedula.requestFocus();
}
int v = Integer.parseInt(String.valueOf(c1.charAt(9)));
int suma=0;
String c3;
for (int i = 0; i<=8; i++){
int valor = Integer.parseInt(String.valueOf(c1.charAt(i)));
int j=i+1;
if (!enteroespar(j)){
valor=valor*2;
if (valor >9){
valor=valor-9;
}
}
suma=suma+valor;
}
int verifica = 10-(suma -(suma/10)*10);
if (verifica==10){
verifica=0;
}
if(verifica != v){
sw=1;
}
}
catch (NumberFormatException nfe) {
return false;
}
catch (Exception err){
return false;
}
if (sw==1){
return false;
} else {
return true;
}
}
public Boolean enteroespar(int v1){
if (((v1/2)*2)!=v1){
return false;
}
return true;
}
--foto
public void fotoPredefinida(){
try {
ImageIcon icoImagen;
txtEmpCargar.setText("src\\imagenes\\hombre.jpg");
BufferedImage read;
File directorio = new File("src\\imagenes\\hombre.jpg");
read = ImageIO.read(directorio);
Image scaledInstance =
read.getScaledInstance(lbFoto.getWidth(),lbFoto.getHeight(),
Image.SCALE_DEFAULT);
lbFoto.setIcon(new ImageIcon(scaledInstance));
} catch (IOException ex) {
}
}
--compo estado civil
public void cargarComboEstadoCivil(){
txtEstadoCivil.setEnabled(false);
String sql ="select EST_CIVIL FROM estadocivil";
try {
conexion cc=new conexion();
Connection cn=cc.conectar();
sql="select * from estadocivil";
Statement psw = cn.createStatement();
ResultSet rs = psw.executeQuery(sql);
while(rs.next()){
id = rs.getString("EST_CIVIL");
descripcion=rs.getString("EST_CIVILDESC");
cmbEmpEstCivil.addItem(descripcion);
txtEstadoCivil.setText(rs.getString("EST_CIVIL"));
}
} catch (SQLException ex) {
//Logger.getLogger(Materias.class.getName()).log(Level.SEVERE,
null, ex);
//JOptionPane.showMessageDialog(null, ex);
}
}
--foto segn sexo
public void Foto_segun_sexo(){
if(cmbEmpSexo.getSelectedItem().equals("M")){
try {
ImageIcon icoImagen;
txtEmpCargar.setText("src\\imagenes\\hombre.jpg");
BufferedImage read;
File directorio = new File("src\\imagenes\\hombre.jpg");
read = ImageIO.read(directorio);
Image scaledInstance =
read.getScaledInstance(lbFoto.getWidth(), lbFoto.getHeight(),
Image.SCALE_DEFAULT);
lbFoto.setIcon(new ImageIcon(scaledInstance));
} catch (IOException ex) {
}
}
else
if(cmbEmpSexo.getSelectedItem().equals("F")){
try {
ImageIcon icoImagen;
txtEmpCargar.setText("src\\imagenes\\mujer.jpg");
BufferedImage read;
File directorio = new File("src\\imagenes\\mujer.jpg");
read = ImageIO.read(directorio);
Image scaledInstance =
read.getScaledInstance(lbFoto.getWidth(),lbFoto.getHeight(),
Image.SCALE_DEFAULT);
lbFoto.setIcon(new ImageIcon(scaledInstance));
} catch (IOException ex) {
}
}
}
--foto cargar
public void cargar_foto(){
JFileChooser dir = new JFileChooser();
FileNameExtensionFilter filter = new
FileNameExtensionFilter("imagenes", "jpg", "gif","png","bmp");
dir.setFileFilter(filter);
int op = dir.showOpenDialog(this);
if (op == JFileChooser.APPROVE_OPTION) {
String direccion = dir.getSelectedFile().getAbsolutePath();
ImageIcon logo=new ImageIcon(direccion);
Icon icono = new
ImageIcon(logo.getImage().getScaledInstance(lbFoto.getWidth(),
lbFoto.getHeight(), Image.SCALE_DEFAULT));
lbFoto.setIcon(icono);
txtEmpCargar.setText(direccion);
nombreArchivo=dir.getSelectedFile().getName();
}
}
Guardar foto
public void guardaralumno(){
if(txtEmpCedula.getText().trim().isEmpty()){
JOptionPane.showMessageDialog(null, "no puede ingresar alumnos
sin cdula");
txtEmpCedula.requestFocus();
}
else{
if(txtEmpNombre.getText().trim().isEmpty()){
JOptionPane.showMessageDialog(null, "no puede ingresar alumnos
sin nombre");
txtEmpNombre.requestFocus();
}
if(txtEmpApellido.getText().trim().isEmpty()){
JOptionPane.showMessageDialog(null, "no puede ingresar alumnos
sin apellido");
txtEmpApellido.requestFocus();
}
else{
if(txtEmpTelefono.getText().trim().isEmpty()){
JOptionPane.showMessageDialog(null, "no puede ingresar
alumnos sin telefono");
txtEmpTelefono.requestFocus();
}
else{
if(txtEmpDireccion.getText().trim().isEmpty()){
JOptionPane.showMessageDialog(null, "no puede ingresar
alumnos sin direccion");
txtEmpDireccion.requestFocus();
}
else{
conexion cc= new conexion();
Connection cn = cc.conectar();
String CEDULA, NOMBRE, APELLIDO, ESTADO_CIVIL, SEXO,
FECHA_NACIMIENTO, DIRECCION, TELEFONO;
String sql="";
CEDULA=txtEmpCedula.getText();
NOMBRE=txtEmpNombre.getText();
APELLIDO=txtEmpApellido.getText();
//ESTADO_CIVIL=(String) cmbEmpEstCivil.getSelectedItem();
ESTADO_CIVIL=txtEstadoCivil.getText();
SEXO=(String) cmbEmpSexo.getSelectedItem();
java.util.Date fecha1 = dateEmpFecNac.getDate();
String fecha = dt.format(fecha1);
FECHA_NACIMIENTO=fecha;
DIRECCION=txtEmpDireccion.getText();
TELEFONO=txtEmpTelefono.getText();
String nombre=txtEmpApellido.getText()
+txtEmpNombre.getText();
String FOTO="src/imagenes/"+nombre+".jpg";
//JOptionPane.showMessageDialog(this, sql);
sql="INSERT INTO EMPLEADOS (EMP_CEDULA, EMP_NOMBRE,
EMP_APELLIDO, EMP_CIVIL , EMP_SEXO, EMP_FECHA_NACIMIENTO,
EMP_DIRECCION, EMP_TELEFONO, EMP_FOTO) VALUES(?,?,?,?,?,?,?,?,?)";
try {
PreparedStatement psw= cn.prepareStatement(sql);
psw.setString(1, CEDULA);
psw.setString(2, NOMBRE);
psw.setString(3, APELLIDO);
psw.setString(4, ESTADO_CIVIL);
psw.setString(5, SEXO);
psw.setString(6, FECHA_NACIMIENTO);
psw.setString(7, DIRECCION);
psw.setString(8, TELEFONO);
psw.setString(9, FOTO);
"',DIR_EMP='"+txtEmpDireccion.getText()
+"',TEL_EMP='"+txtEmpTelefono.getText()+
"',FOTO_EMP='"+direc+"'"+
", FEC_NAC_EMP='"+dateEmpFecNac+"' where
CI_EMP='"+txtEmpCedula.getText()+"'";
try {
PreparedStatement psw =cn.prepareStatement(sql);
int n=psw.executeUpdate();
if(n>0){
JOptionPane.showMessageDialog(null, "Se actualizo
correctamente");
if(!txtEmpCargar.getText().startsWith("src/imagenes/") ){
CopiarFicheros(txtEmpCargar.getText(),direc);
}
cargarTablaEmpleados("","","");
limpiar();
btnActualizar.setEnabled(false);
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null,"No se actualizo" +ex);
}
}
--eliminar
public void borrar(){
if(JOptionPane.showConfirmDialog(new JInternalFrame(),"Esta seguro
de Eliminar el regidtro","Borrar
registro",JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION){
conexion cc=new conexion();
Connection cn=cc.conectar();
String sql="";
sql="delete from alumnos where
alu_cedula='"+txtEmpCedula.getText()+"'";
try{
PreparedStatement psw=cn.prepareStatement(sql);
int n=psw.executeUpdate();
if(n>0){
JOptionPane.showMessageDialog(null,"Se elimino
correctamente");
cargarTablaEmpleados("","","");
limpiar();
}
}catch(SQLException ex){
JOptionPane.showMessageDialog(null,"NO se elimino");
}
}
}
--posiciona el puntero
txtEmpNombre.requestFocus();
--habilita
txtEmpApellido.setEnabled(true);
--en el keytyped cantidad de espacio disponible
char letras = evt.getKeyChar();
if(txtEmpNombre.getText().length()>=30) evt.consume();
this.dispose();
}
}
}else{
lblAviso.setVisible(true);
}
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex);
}
}
--actualizar table
private void actualizarTabla() {
conexion cc = new conexion();
Connection cn = cc.conectar();
int fila = tUsuarios.getSelectedRow();
String sql = "";
if (fila != -1) {
sql = "UPDATE USUARIOS "
+ "SET USU_NOMBRE='" + tUsuarios.getValueAt(fila,
1).toString().trim().toUpperCase() + "',"
+ "USU_CLAVE='" + tUsuarios.getValueAt(fila,
2).toString().trim().toUpperCase() + "',"
+ "USU_USUARIO='" + tUsuarios.getValueAt(fila,
3).toString().trim().toUpperCase() + "',"
+ "USU_ROL='" + tUsuarios.getValueAt(fila,
4).toString().trim().toUpperCase() + "'"
+ "WHERE USU_ID='" + tUsuarios.getValueAt(fila, 0).toString()
+ "'";
try {
PreparedStatement psw = cn.prepareStatement(sql);
int n = psw.executeUpdate();
if (n > 0) {
JOptionPane.showMessageDialog(this, "Actualizacion correcta");
cargarTablaUsuarios("", "");
limpiar();
desactivar();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Error en la Actualizacion"
+ e);
}
}
}
--encriptado
public String md5(char[] c) {
try {
MessageDigest digs = MessageDigest.getInstance("MD5");
digs.update((new String(c).getBytes("UTF8")));
//Logger.getLogger(Alumnos.class.getName()).log(Level.SEVERE,
null, ex);
}
}
--aadir al menu
try {
// materias m=new materias("");
// jDesktopPane1.add(m);
// m.setMaximum(true);
//
m.show();
// } catch (PropertyVetoException ex) {
// // Logger.getLogger(menu.class.getName()).log(Level.SEVERE, null, ex);
//
}