Created
December 1, 2015 04:22
-
-
Save hugoangeles0810/e41df788ed4e38c2a27e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 controller; | |
import entity.Empleados; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RequestMethod; | |
import org.springframework.web.bind.annotation.RequestParam; | |
import org.springframework.web.servlet.ModelAndView; | |
import service.EmpleadosService; | |
import service.UsuarioService; | |
/** | |
* | |
* @author jhongger | |
*/ | |
@Controller | |
public class controlador { | |
@Autowired | |
private UsuarioService usuarioService; | |
@Autowired | |
private EmpleadosService empleadoService; | |
@RequestMapping(value = "/index.html") | |
public String inicio() { | |
return "index"; | |
} | |
@RequestMapping(value = "/inicio.html", method = RequestMethod.POST) | |
public ModelAndView modificar(@RequestParam("usuario") String usuario, @RequestParam("pass") String pass, @RequestParam("rol") Integer rol) { | |
ModelAndView mv; | |
if (usuarioService.existe(usuario, pass, rol)) { | |
mv = new ModelAndView("inicio"); | |
mv.addObject("empleados", empleadoService.listarTodos()); | |
} else { | |
mv = new ModelAndView("index"); | |
mv.addObject("informacion", "Usuario, Contrase�a o rol incorrecto"); | |
} | |
return mv; | |
} | |
@RequestMapping(value = "/inicio.html", method = RequestMethod.GET) | |
public ModelAndView modificar() { | |
ModelAndView mv; | |
mv = new ModelAndView("inicio"); | |
return mv; | |
} | |
@RequestMapping(value = "/modificar.html", method = RequestMethod.GET) | |
public ModelAndView modifica() { | |
ModelAndView mv; | |
mv = new ModelAndView("modificar"); | |
return mv; | |
} | |
@RequestMapping(value = "/modificar.html", method = RequestMethod.POST) | |
public ModelAndView modEmp(@RequestParam("id") Integer id, | |
@RequestParam("nombre") String nombre, | |
@RequestParam("apPat") String apPat, | |
@RequestParam("apMat") String apMat, | |
@RequestParam("sexo") Integer sexo, | |
@RequestParam("direccion") String direccion, | |
@RequestParam("Lugnac") String lugNac, | |
@RequestParam("email") String email, | |
@RequestParam("fecNac") String fecNac) { | |
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); | |
System.out.println("fecha" + fecNac); | |
ModelAndView mv= new ModelAndView("modificar"); | |
// Autores autor= new Autores(); | |
Empleados empleado = new Empleados(); | |
empleado.setCi(id); | |
empleado.setNombre(nombre); | |
empleado.setApellidoPaterno(apPat); | |
empleado.setApellidoMaterno(apMat); | |
empleado.setIdsexo(sexo); | |
empleado.setDireccion(direccion); | |
empleado.setLugarNacimiento(lugNac); | |
empleado.setCorreoElectronico(email); | |
try { | |
empleado.setFechaNac(df.parse(fecNac)); | |
} catch (ParseException ex) { | |
Logger.getLogger(controlador.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
empleadoService.guardar(empleado); | |
return mv; | |
} | |
@RequestMapping(value = "/agregar.html", method = RequestMethod.POST) | |
public ModelAndView addEmp1(@RequestParam("id") Integer id, @RequestParam("nombre") String nombre, @RequestParam("apPat") String apPat, @RequestParam("apMat") String apMat, @RequestParam("sexo") Integer sexo, @RequestParam("direccion") String direccion, @RequestParam("Lugnac") String lugNac, @RequestParam("email") String email, @RequestParam("fecNac") Date fecNac) { | |
ModelAndView mv= new ModelAndView("modificar"); | |
// Autores autor= new Autores(); | |
Empleados empleado = new Empleados(); | |
empleado.setCi(id); | |
empleado.setNombre(nombre); | |
empleado.setApellidoPaterno(apPat); | |
empleado.setApellidoMaterno(apMat); | |
empleado.setIdsexo(sexo); | |
empleado.setDireccion(direccion); | |
empleado.setLugarNacimiento(lugNac); | |
empleado.setCorreoElectronico(email); | |
empleado.setFechaNac(fecNac); | |
empleadoService.guardar(empleado); | |
return mv; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment