Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
proyecto-estandar
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Israel Gutierrez Salazar
proyecto-estandar
Commits
fb1b28ec
Commit
fb1b28ec
authored
Feb 21, 2018
by
Israel Gutierrez Salazar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cambio a ES6 a ubigeo
parent
d9d4acc7
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
196 additions
and
499 deletions
+196
-499
README.md
README.md
+12
-7
UbigeoBean.java
src/java/demojsoncrud/beans/UbigeoBean.java
+0
-9
PersonaDAO.java
src/java/demojsoncrud/dao/PersonaDAO.java
+0
-6
UbigeoDAO.java
src/java/demojsoncrud/dao/UbigeoDAO.java
+2
-2
PersonaService.java
src/java/demojsoncrud/services/PersonaService.java
+0
-28
UbigeoService.java
src/java/demojsoncrud/services/UbigeoService.java
+4
-13
PersonaServlet.java
src/java/demojsoncrud/servlets/PersonaServlet.java
+23
-57
UbigeoServlet.java
src/java/demojsoncrud/servlets/UbigeoServlet.java
+10
-34
PersonaSqlserverDAO.java
src/java/demojsoncrud/sqlserverdao/PersonaSqlserverDAO.java
+0
-174
UbigeoSqlserverDAO.java
src/java/demojsoncrud/sqlserverdao/UbigeoSqlserverDAO.java
+25
-24
general.js
web/js/general.js
+16
-0
persona.js
web/js/pages/persona.js
+8
-11
ubigeo.js
web/js/pages/ubigeo.js
+93
-131
index.jsp
web/vistas/index.jsp
+3
-3
No files found.
README.md
View file @
fb1b28ec
# Documentación
<img
src=
"http://sacooliveros.edu.pe/images/sacooliveros/Home/logos/logo-saco-apeiron.png"
align=
"center"
/>
-
[
Documentación
](
#documentación
)
-
[
Servlets
](
#servlets
)
-
[
Respuestas
](
#respuestas
)
# Proyecto Estandar
##
JSP
##
Introducción
## Beans
Este proyecto recopila los estándares que se utilizan en los proyectos con la finalidad de ayudar a entenderlos de una manera práctica.
## Servlets
## Documentación
-
[
Estructura de proyecto
](
)
-
[
Servlets
](
#servlets
)
-
[
Respuestas
](
#respuestas
)
### Servlets
-
Respuestas
...
...
src/java/demojsoncrud/beans/UbigeoBean.java
View file @
fb1b28ec
/*
* 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
demojsoncrud
.
beans
;
import
java.io.Serializable
;
/**
*
* @author Alonso
*/
public
class
UbigeoBean
implements
Serializable
{
private
String
codigoDepartamento
;
...
...
src/java/demojsoncrud/dao/PersonaDAO.java
View file @
fb1b28ec
...
...
@@ -5,17 +5,11 @@ import org.json.JSONObject;
public
interface
PersonaDAO
{
public
JSONObject
listarPersonaTest
();
public
JSONObject
listarPersona
(
String
search
,
String
draw
,
String
start
,
String
length
);
public
JSONObject
registrarPersona
(
JSONObject
datos
);
public
JSONObject
editarPersona
(
JSONObject
datos
);
public
JSONObject
activarPersona
(
PersonaBean
bean
);
public
JSONObject
desactivarPersona
(
PersonaBean
bean
);
public
JSONObject
cambiarEstado
(
JSONObject
datos
);
...
...
src/java/demojsoncrud/dao/UbigeoDAO.java
View file @
fb1b28ec
...
...
@@ -16,8 +16,8 @@ public interface UbigeoDAO {
public
JSONObject
listarDepartamento
();
public
JSONObject
listarProvincia
(
UbigeoBean
bean
);
public
JSONObject
listarProvincia
(
JSONObject
datos
);
public
JSONObject
listarDistrito
(
UbigeoBean
bean
);
public
JSONObject
listarDistrito
(
JSONObject
datos
);
}
src/java/demojsoncrud/services/PersonaService.java
View file @
fb1b28ec
...
...
@@ -10,16 +10,6 @@ public class PersonaService {
DAOFactory
daoFactory
=
DAOFactory
.
getDAOFactory
(
DAOFactory
.
SQL_SERVER
);
PersonaDAO
service
=
daoFactory
.
getPersonaDAO
();
public
JSONObject
listarPersonaTest
()
{
JSONObject
jsonReturn
=
null
;
try
{
jsonReturn
=
service
.
listarPersonaTest
();
}
catch
(
Exception
e
)
{
e
.
getMessage
();
}
return
jsonReturn
;
}
public
JSONObject
listarPersona
(
String
search
,
String
draw
,
String
start
,
String
length
)
{
JSONObject
jsonReturn
=
null
;
try
{
...
...
@@ -49,24 +39,6 @@ public class PersonaService {
}
return
jsonReturn
;
}
public
JSONObject
activarPersona
(
PersonaBean
bean
)
{
JSONObject
jsonReturn
=
null
;
try
{
jsonReturn
=
service
.
activarPersona
(
bean
);
}
catch
(
Exception
e
)
{
}
return
jsonReturn
;
}
public
JSONObject
desactivarPersona
(
PersonaBean
bean
)
{
JSONObject
jsonReturn
=
null
;
try
{
jsonReturn
=
service
.
desactivarPersona
(
bean
);
}
catch
(
Exception
e
)
{
}
return
jsonReturn
;
}
public
JSONObject
cambiarEstado
(
JSONObject
datos
)
{
JSONObject
respuesta
=
null
;
...
...
src/java/demojsoncrud/services/UbigeoService.java
View file @
fb1b28ec
/*
* 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
demojsoncrud
.
services
;
import
demojsoncrud.beans.UbigeoBean
;
...
...
@@ -10,10 +5,6 @@ import demojsoncrud.dao.DAOFactory;
import
demojsoncrud.dao.UbigeoDAO
;
import
org.json.JSONObject
;
/**
*
* @author Alonso
*/
public
class
UbigeoService
{
DAOFactory
daoFactory
=
DAOFactory
.
getDAOFactory
(
DAOFactory
.
SQL_SERVER
);
...
...
@@ -28,19 +19,19 @@ public class UbigeoService {
return
jsonReturn
;
}
public
JSONObject
listarProvincia
(
UbigeoBean
bean
)
{
public
JSONObject
listarProvincia
(
JSONObject
datos
)
{
JSONObject
jsonReturn
=
null
;
try
{
jsonReturn
=
service
.
listarProvincia
(
bean
);
jsonReturn
=
service
.
listarProvincia
(
datos
);
}
catch
(
Exception
e
)
{
}
return
jsonReturn
;
}
public
JSONObject
listarDistrito
(
UbigeoBean
bean
)
{
public
JSONObject
listarDistrito
(
JSONObject
datos
)
{
JSONObject
jsonReturn
=
null
;
try
{
jsonReturn
=
service
.
listarDistrito
(
bean
);
jsonReturn
=
service
.
listarDistrito
(
datos
);
}
catch
(
Exception
e
)
{
}
return
jsonReturn
;
...
...
src/java/demojsoncrud/servlets/PersonaServlet.java
View file @
fb1b28ec
package
demojsoncrud
.
servlets
;
import
demojsoncrud.beans.PersonaBean
;
import
demojsoncrud.services.PersonaService
;
import
static
demojsoncrud
.
utilities
.
CustomHttpServletRequest
.
getBodyJsonObject
;
import
java.io.IOException
;
...
...
@@ -16,31 +15,32 @@ public class PersonaServlet extends HttpServlet {
@Override
protected
void
service
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
String
param
=
request
.
getParameter
(
"accion"
);
if
(
"listarPersonaTest"
.
equals
(
param
))
{
listarPersonaTest
(
request
,
response
);
}
else
if
(
"listarPersona"
.
equals
(
param
))
{
listarPersona
(
request
,
response
);
}
else
if
(
"registrarPersona"
.
equals
(
param
))
{
registrarPersona
(
request
,
response
);
}
else
if
(
"editarPersona"
.
equals
(
param
))
{
editarPersona
(
request
,
response
);
}
else
if
(
"activarPersona"
.
equals
(
param
))
{
activarPersona
(
request
,
response
);
}
else
if
(
"desactivarPersona"
.
equals
(
param
))
{
desactivarPersona
(
request
,
response
);
}
else
if
(
"cambiarEstado"
.
equals
(
param
))
{
cambiarEstado
(
request
,
response
);
switch
(
param
)
{
case
"listarPersona"
:
listarPersona
(
request
,
response
);
break
;
case
"registrarPersona"
:
registrarPersona
(
request
,
response
);
break
;
case
"editarPersona"
:
editarPersona
(
request
,
response
);
break
;
case
"cambiarEstado"
:
cambiarEstado
(
request
,
response
);
break
;
default
:
response
.
setContentType
(
"application/json"
);
PrintWriter
pw
=
response
.
getWriter
();
JSONObject
respuesta
=
new
JSONObject
();
respuesta
.
put
(
"status"
,
false
)
.
put
(
"message"
,
"No existe la url solicitada."
)
.
put
(
"data"
,
""
);
pw
.
print
(
respuesta
);
break
;
}
}
private
void
listarPersonaTest
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
response
.
setContentType
(
"application/json"
);
PrintWriter
pw
=
response
.
getWriter
();
PersonaService
service
=
new
PersonaService
();
JSONObject
json
=
service
.
listarPersonaTest
();
pw
.
print
(
json
);
}
private
void
listarPersona
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
response
.
setContentType
(
"application/json"
);
PrintWriter
pw
=
response
.
getWriter
();
...
...
@@ -76,40 +76,6 @@ public class PersonaServlet extends HttpServlet {
pw
.
print
(
respuesta
);
}
private
void
activarPersona
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
response
.
setContentType
(
"application/json"
);
PersonaService
service
=
new
PersonaService
();
PrintWriter
pw
=
response
.
getWriter
();
String
json
=
request
.
getParameter
(
"json"
);
JSONObject
jsonObject
=
new
JSONObject
(
json
);
String
codigo
=
jsonObject
.
getString
(
"codigo"
);
PersonaBean
bean
=
new
PersonaBean
();
bean
.
setCodigo
(
codigo
);
JSONObject
jsonReturn
=
service
.
activarPersona
(
bean
);
pw
.
print
(
jsonReturn
);
}
private
void
desactivarPersona
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
response
.
setContentType
(
"application/json"
);
PersonaService
service
=
new
PersonaService
();
PrintWriter
pw
=
response
.
getWriter
();
String
json
=
request
.
getParameter
(
"json"
);
JSONObject
jsonObject
=
new
JSONObject
(
json
);
String
codigo
=
jsonObject
.
getString
(
"codigo"
);
PersonaBean
bean
=
new
PersonaBean
();
bean
.
setCodigo
(
codigo
);
JSONObject
jsonReturn
=
service
.
desactivarPersona
(
bean
);
pw
.
print
(
jsonReturn
);
}
private
void
cambiarEstado
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
response
.
setContentType
(
"application/json"
);
PrintWriter
pw
=
response
.
getWriter
();
...
...
src/java/demojsoncrud/servlets/UbigeoServlet.java
View file @
fb1b28ec
/*
* 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
demojsoncrud
.
servlets
;
import
demojsoncrud.beans.UbigeoBean
;
import
demojsoncrud.services.UbigeoService
;
import
static
demojsoncrud
.
utilities
.
CustomHttpServletRequest
.
getBodyJsonObject
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
javax.servlet.ServletException
;
...
...
@@ -15,16 +11,12 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
org.json.JSONObject
;
/**
*
* @author Alonso
*/
public
class
UbigeoServlet
extends
HttpServlet
{
@Override
protected
void
service
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
String
param
=
request
.
getParameter
(
"accion"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
if
(
"listarDepartamento"
.
equals
(
param
))
{
listarDepartamento
(
request
,
response
);
}
else
if
(
"listarProvincia"
.
equals
(
param
))
{
...
...
@@ -46,36 +38,20 @@ public class UbigeoServlet extends HttpServlet {
response
.
setContentType
(
"application/json"
);
PrintWriter
pw
=
response
.
getWriter
();
UbigeoService
service
=
new
UbigeoService
();
String
json
=
request
.
getParameter
(
"json"
);
JSONObject
jsonObject
=
new
JSONObject
(
json
);
String
codigoDepartamento
=
jsonObject
.
getString
(
"codigoDepartamento"
);
UbigeoBean
bean
=
new
UbigeoBean
();
bean
.
setCodigoDepartamento
(
codigoDepartamento
);
JSONObject
jsonReturn
=
service
.
listarProvincia
(
bean
);
pw
.
print
(
jsonReturn
);
JSONObject
datos
=
new
JSONObject
();
datos
=
getBodyJsonObject
(
request
);
JSONObject
respuesta
=
service
.
listarProvincia
(
datos
.
getJSONObject
(
"json"
));
pw
.
print
(
respuesta
);
}
private
void
listarDistrito
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
IOException
{
response
.
setContentType
(
"application/json"
);
PrintWriter
pw
=
response
.
getWriter
();
UbigeoService
service
=
new
UbigeoService
();
String
json
=
request
.
getParameter
(
"json"
);
JSONObject
jsonObject
=
new
JSONObject
(
json
);
String
codigoDepartamento
=
jsonObject
.
getString
(
"codigoDepartamento"
);
String
codigoProvincia
=
jsonObject
.
getString
(
"codigoProvincia"
);
UbigeoBean
bean
=
new
UbigeoBean
();
bean
.
setCodigoDepartamento
(
codigoDepartamento
);
bean
.
setCodigoProvincia
(
codigoProvincia
);
JSONObject
jsonReturn
=
service
.
listarDistrito
(
bean
);
pw
.
print
(
jsonReturn
);
JSONObject
datos
=
new
JSONObject
();
datos
=
getBodyJsonObject
(
request
);
JSONObject
respuesta
=
service
.
listarDistrito
(
datos
.
getJSONObject
(
"json"
));
pw
.
print
(
respuesta
);
}
}
src/java/demojsoncrud/sqlserverdao/PersonaSqlserverDAO.java
View file @
fb1b28ec
...
...
@@ -14,80 +14,6 @@ import org.json.JSONObject;
public
class
PersonaSqlserverDAO
implements
PersonaDAO
{
@Override
public
JSONObject
listarPersonaTest
()
{
JSONObject
jsonReturn
=
new
JSONObject
();
JSONArray
data
=
new
JSONArray
();
ResponseHelper
response
=
new
ResponseHelper
();
PreparedStatement
psListarPersona
=
null
;
ResultSet
rsListarPersona
=
null
;
Connection
connection
=
null
;
String
base
=
"demojsoncrud"
;
try
{
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
String
sql
=
"select "
+
"a.codigo, "
+
"a.dni, "
+
"a.apellidos, "
+
"a.nombres, "
+
"a.edad, "
+
"a.correo, "
+
"a.estado "
+
"from persona a "
;
psListarPersona
=
connection
.
prepareStatement
(
sql
);
rsListarPersona
=
psListarPersona
.
executeQuery
();
while
(
rsListarPersona
.
next
())
{
PersonaBean
personaBean
=
new
PersonaBean
();
int
q
=
1
;
//Contador para las columnas
personaBean
.
setCodigo
(
rsListarPersona
.
getString
(
q
++));
personaBean
.
setDni
(
rsListarPersona
.
getString
(
q
++));
personaBean
.
setApellidos
(
rsListarPersona
.
getString
(
q
++));
personaBean
.
setNombres
(
rsListarPersona
.
getString
(
q
++));
personaBean
.
setEdad
(
rsListarPersona
.
getString
(
q
++));
personaBean
.
setCorreo
(
rsListarPersona
.
getString
(
q
++));
personaBean
.
setEstado
(
rsListarPersona
.
getString
(
q
++));
JSONObject
obj
=
new
JSONObject
(
personaBean
);
data
.
put
(
obj
);
}
JSONObject
jsonData
=
new
JSONObject
();
jsonData
.
put
(
"personas"
,
data
);
response
.
setData
(
jsonData
);
response
.
setMessage
(
"Listado correcto!"
);
response
.
setStatus
(
true
);
}
catch
(
SQLException
e
)
{
response
.
setMessage
(
"Error -> "
+
e
.
getMessage
()
+
" ["
+
e
.
getErrorCode
()
+
"]"
);
response
.
setStatus
(
false
);
}
finally
{
try
{
if
(
rsListarPersona
!=
null
)
{
rsListarPersona
.
close
();
}
if
(
psListarPersona
!=
null
)
{
psListarPersona
.
close
();
}
if
(
connection
!=
null
)
{
connection
.
close
();
}
}
catch
(
SQLException
e
)
{
response
.
setMessage
(
"Error -> "
+
e
.
getMessage
()
+
" ["
+
e
.
getErrorCode
()
+
"]"
);
response
.
setStatus
(
false
);
}
}
jsonReturn
=
new
JSONObject
(
response
);
return
jsonReturn
;
}
@Override
public
JSONObject
listarPersona
(
String
search
,
String
draw
,
String
start
,
String
length
)
{
JSONObject
jsonReturn
=
new
JSONObject
();
JSONArray
data
=
new
JSONArray
();
...
...
@@ -303,106 +229,6 @@ public class PersonaSqlserverDAO implements PersonaDAO {
}
@Override
public
JSONObject
activarPersona
(
PersonaBean
bean
)
{
JSONObject
jsonReturn
=
new
JSONObject
();
String
base
=
"demojsoncrud"
;
Connection
connection
=
null
;
PreparedStatement
psEditarPersona
=
null
;
int
resultPersona
=
0
;
ResponseHelper
response
=
new
ResponseHelper
();
try
{
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
String
sql
=
"update persona "
+
"set estado = 1 "
+
"where codigo = ?"
;
psEditarPersona
=
connection
.
prepareStatement
(
sql
);
psEditarPersona
.
setString
(
1
,
bean
.
getCodigo
());
resultPersona
=
psEditarPersona
.
executeUpdate
();
if
(
resultPersona
==
1
)
{
response
.
setMessage
(
"Se actualizo correctamente"
);
response
.
setStatus
(
true
);
// ACTUALIZO
}
else
{
response
.
setMessage
(
"Error al actualizar"
);
response
.
setStatus
(
false
);
// ERROR
}
}
catch
(
SQLException
e
)
{
response
.
setStatus
(
false
);
response
.
setMessage
(
"Error al actualizar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
}
finally
{
try
{
if
(
connection
!=
null
)
{
connection
.
close
();
}
if
(
psEditarPersona
!=
null
)
{
psEditarPersona
.
close
();
}
}
catch
(
SQLException
e
)
{
response
.
setStatus
(
false
);
response
.
setMessage
(
"Error al actualizar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
}
}
jsonReturn
=
new
JSONObject
(
response
);
return
jsonReturn
;
}
@Override
public
JSONObject
desactivarPersona
(
PersonaBean
bean
)
{
JSONObject
jsonReturn
=
new
JSONObject
();
String
base
=
"demojsoncrud"
;
Connection
connection
=
null
;
PreparedStatement
psEditarPersona
=
null
;
int
resultPersona
=
0
;
ResponseHelper
response
=
new
ResponseHelper
();
try
{
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
String
sql
=
"update persona "
+
"set estado = 0 "
+
"where codigo = ?"
;
psEditarPersona
=
connection
.
prepareStatement
(
sql
);
psEditarPersona
.
setString
(
1
,
bean
.
getCodigo
());
resultPersona
=
psEditarPersona
.
executeUpdate
();
if
(
resultPersona
==
1
)
{
response
.
setMessage
(
"Se actualizo correctamente"
);
response
.
setStatus
(
true
);
// ACTUALIZO
}
else
{
response
.
setMessage
(
"Error al actualizar"
);
response
.
setStatus
(
false
);
// ERROR
}
}
catch
(
SQLException
e
)
{
response
.
setStatus
(
false
);
response
.
setMessage
(
"Error al actualizar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
}
finally
{
try
{
if
(
connection
!=
null
)
{
connection
.
close
();
}
if
(
psEditarPersona
!=
null
)
{
psEditarPersona
.
close
();
}
}
catch
(
SQLException
e
)
{
response
.
setStatus
(
false
);
response
.
setMessage
(
"Error al actualizar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
}
}
jsonReturn
=
new
JSONObject
(
response
);
return
jsonReturn
;
}
@Override
public
JSONObject
cambiarEstado
(
JSONObject
datos
)
{
System
.
out
.
println
(
datos
);
JSONObject
jsonReturn
=
new
JSONObject
();
...
...
src/java/demojsoncrud/sqlserverdao/UbigeoSqlserverDAO.java
View file @
fb1b28ec
...
...
@@ -34,12 +34,12 @@ public class UbigeoSqlserverDAO implements UbigeoDAO {
try
{
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
String
sql
=
"select "
+
"codDepartamento as codigoDepartamento, "
+
"nombreDepartamento as nombreDepartamento "
+
"from ubigeo "
+
"group by codDepartamento, nombreDepartamento "
+
"order by nombreDepartamento"
;
=
"select "
+
"codDepartamento as codigoDepartamento, "
+
"nombreDepartamento as nombreDepartamento "
+
"from ubigeo "
+
"group by codDepartamento, nombreDepartamento "
+
"order by nombreDepartamento"
;
psListarDepartamento
=
connection
.
prepareStatement
(
sql
);
rsListarDepartamento
=
psListarDepartamento
.
executeQuery
();
while
(
rsListarDepartamento
.
next
())
{
...
...
@@ -84,7 +84,8 @@ public class UbigeoSqlserverDAO implements UbigeoDAO {
}
@Override
public
JSONObject
listarProvincia
(
UbigeoBean
bean
)
{
public
JSONObject
listarProvincia
(
JSONObject
datos
)
{
System
.
out
.
println
(
datos
);
JSONObject
jsonReturn
=
new
JSONObject
();
JSONArray
data
=
new
JSONArray
();
PreparedStatement
psListarProvincia
=
null
;
...
...
@@ -96,15 +97,15 @@ public class UbigeoSqlserverDAO implements UbigeoDAO {
try
{
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
String
sql
=
"select "
+
"codProvincia as codigoProvincia, "
+
"nombreProvincia as nombreProvincia "
+
"from ubigeo "
+
"where codDepartamento = ? "
+
"group by codProvincia, nombreProvincia "
+
"order by nombreProvincia"
;
=
"select "
+
"codProvincia as codigoProvincia, "
+
"nombreProvincia as nombreProvincia "
+
"from ubigeo "
+
"where codDepartamento = ? "
+
"group by codProvincia, nombreProvincia "
+
"order by nombreProvincia"
;
psListarProvincia
=
connection
.
prepareStatement
(
sql
);
psListarProvincia
.
set
String
(
1
,
bean
.
getCodigoDepartamento
(
));
psListarProvincia
.
set
Int
(
1
,
datos
.
getInt
(
"codigoDepartamento"
));
rsListarProvincia
=
psListarProvincia
.
executeQuery
();
while
(
rsListarProvincia
.
next
())
{
UbigeoBean
ubigeoBean
=
new
UbigeoBean
();
...
...
@@ -148,7 +149,7 @@ public class UbigeoSqlserverDAO implements UbigeoDAO {
}
@Override
public
JSONObject
listarDistrito
(
UbigeoBean
bean
)
{
public
JSONObject
listarDistrito
(
JSONObject
datos
)
{
JSONObject
jsonReturn
=
new
JSONObject
();
JSONArray
data
=
new
JSONArray
();
PreparedStatement
psListarDistrito
=
null
;
...
...
@@ -160,15 +161,15 @@ public class UbigeoSqlserverDAO implements UbigeoDAO {
try
{
connection
=
SqlserverDAOFactory
.
obtenerConexion
(
base
);
String
sql
=
"select "
+
"codDistrito as codigoDistrito, "
+
"nombreDistrito as nombreDistrito "
+
"from ubigeo "
+
"where codProvincia = ? and codDepartamento = ? "
+
"order by nombreDistrito"
;
=
"select "
+
"codDistrito as codigoDistrito, "
+
"nombreDistrito as nombreDistrito "
+
"from ubigeo "
+
"where codProvincia = ? and codDepartamento = ? "
+
"order by nombreDistrito"
;
psListarDistrito
=
connection
.
prepareStatement
(
sql
);
psListarDistrito
.
set
String
(
1
,
bean
.
getCodigoProvincia
(
));
psListarDistrito
.
set
String
(
2
,
bean
.
getCodigoDepartamento
(
));
psListarDistrito
.
set
Int
(
1
,
datos
.
getInt
(
"codigoProvincia"
));
psListarDistrito
.
set
Int
(
2
,
datos
.
getInt
(
"codigoDepartamento"
));
rsListarDistrito
=
psListarDistrito
.
executeQuery
();
while
(
rsListarDistrito
.
next
())
{
UbigeoBean
ubigeoBean
=
new
UbigeoBean
();
...
...
web/js/general.js
View file @
fb1b28ec
...
...
@@ -35,6 +35,22 @@ let fetchSo = (url, object) => {
)
}
/**
* Crea los elementos option del array que se pase como parametro
* @method createSelectOptions
* @param {JSONArray} obj array de objetos
* @param {String} valueName la key del json que se usará como value del elemento option
* @param {String} textName la key del json que se usará como text del elemento option
* @returns {Promise} Promise retorna status, msg
*/
let
createSelectOptions
=
(
obj
,
valueName
,
textName
)
=>
{
let
options
=
''
obj
.
forEach
((
data
)
=>
{
options
+=
`<option value="
${
data
[
valueName
]}
">
${
data
[
textName
]}
</option>`
})
return
options
}
let
customSwal
=
{
alert
(
title
,
text
,
type
)
{
let
colors
=
{
...
...
web/js/pages/persona.js
View file @
fb1b28ec
...
...
@@ -70,10 +70,7 @@ let persona = {
url
:
'../PersonaServlet?accion=listarPersona'
,
type
:
'POST'
,
dataType
:
'json'
,
data
:
{
search
:
txtCriterioBusqueda
},
/*success: function (data) {
resolve(data)
}*/
data
:
{
search
:
txtCriterioBusqueda
}
},
columnDefs
:
[
{
targets
:
0
,
orderable
:
false
,
width
:
'5%'
,
className
:
'centrado'
},
...
...
@@ -194,8 +191,7 @@ let limpiarCajasTexto = () => {
$
(
'#btn_agregar_persona'
).
on
(
'click'
,
function
()
{
$
(
'#txt_numero_documento'
).
attr
({
autofocus
:
true
})
$
(
'#txt_numero_documento'
).
val
(
''
)
}).
val
(
''
)
$
(
'#txt_apellidos'
).
val
(
''
)
$
(
'#txt_nombres'
).
val
(
''
)
$
(
'#txt_edad'
).
val
(
''
)
...
...
@@ -233,7 +229,7 @@ let asignarEventos = () => {
})
$
(
'#tbl-persona tbody'
).
on
(
'click'
,
'.editarPersona'
,
(
event
)
=>
{
let
rowData
=
$
(
'#tbl-persona'
).
DataTable
().
row
(
$
(
event
.
currentTarget
).
parents
(
'tr'
)).
data
(
)
let
rowData
=
obtenerDatosTabla
(
$
(
event
.
currentTarget
).
parents
(
'tr'
)
)
$
(
'#txt_numero_documento_editar'
).
val
(
rowData
.
dni
)
$
(
'#txt_apellidos_editar'
).
val
(
rowData
.
apellidos
)
$
(
'#txt_nombres_editar'
).
val
(
rowData
.
nombres
)
...
...
@@ -286,7 +282,7 @@ let asignarEventos = () => {
.
registrar
()
.
then
((
data
)
=>
{
customSwal
.
alert
(
'¡Exito!'
,
'Se registró con exito.'
,
'success'
)
.
alert
(
'¡Exito!'
,
data
.
message
,
'success'
)
.
then
(()
=>
{
$
(
'#modal_registrar_persona'
).
modal
(
'hide'
)
})
...
...
@@ -295,7 +291,7 @@ let asignarEventos = () => {
})
})
.
catch
((
data
)
=>
{
customSwal
.
alert
(
'¡Error!'
,
'No se registró con exito.'
,
'error'
)
customSwal
.
alert
(
'¡Error!'
,
data
.
message
,
'error'
)
})
}
})
...
...
@@ -337,7 +333,7 @@ let asignarEventos = () => {
.
editar
()
.
then
((
data
)
=>
{
customSwal
.
alert
(
'¡Exito!'
,
'Se actualizó con exito.'
,
'success'
)
.
alert
(
'¡Exito!'
,
data
.
message
,
'success'
)
.
then
(()
=>
{
$
(
'#modal_editar_persona'
).
modal
(
'hide'
)
})
...
...
@@ -346,7 +342,7 @@ let asignarEventos = () => {
})
})
.
catch
((
data
)
=>
{
customSwal
.
alert
(
'¡Error!'
,
'No se actualizó con exito.'
,
'error'
)
customSwal
.
alert
(
'¡Error!'
,
data
.
message
,
'error'
)
})
}
})
...
...
@@ -354,6 +350,7 @@ let asignarEventos = () => {
$
(
'#btn_buscar_criterio'
).
on
(
'click'
,
function
()
{
persona
.
listar
()
})
$
(
'#txt-busqueda'
).
keyup
(
function
(
e
)
{
if
(
e
.
keyCode
===
13
)
{
persona
.
listar
()
...
...
web/js/pages/ubigeo.js
View file @
fb1b28ec
/*
* 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.
*/
$
(
document
).
ready
(
function
()
{
init
();
validarSelect
();
});
function
init
()
{
listarDepartamento
();
listarProvincia
();
listarDistrito
();
}
function
listarDepartamento
()
{
$
.
ajax
({
type
:
'POST'
,
url
:
'../UbigeoServlet?accion=listarDepartamento'
,
beforeSend
:
function
(
xhr
)
{
},
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
var
status
=
data
.
status
;
var
departamentos
=
data
.
data
.
departamentos
;
if
(
status
)
{
var
select_departamento
=
'<option value="0">[ SELECCIONE ]</option>'
;
for
(
var
i
in
departamentos
)
{
select_departamento
+=
'<option value="'
+
departamentos
[
i
].
codigoDepartamento
+
'">'
+
departamentos
[
i
].
nombreDepartamento
+
'</option>'
;
}
$
(
'#select_departamento'
).
html
(
select_departamento
);
$
(
'#select_departamento'
).
selectpicker
(
'refresh'
);
}
else
{
}
},
complete
:
function
(
jqXHR
,
textStatus
)
{
let
ubigeo
=
{
consultarDepartamento
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
fetchSo
(
'../UbigeoServlet?accion=listarDepartamento'
)
.
then
((
data
)
=>
{
resolve
(
data
)
})
.
catch
((
data
)
=>
{
reject
(
data
)
})
})
},
consultarProvincia
(
codigoDepartamento
)
{
let
json
=
{
codigoDepartamento
:
codigoDepartamento
}
});
}
function
listarProvincia
()
{
$
(
'#select_departamento'
).
on
(
'change'
,
function
()
{
var
json
=
{
codigoDepartamento
:
$
(
'#select_departamento'
).
val
()
};
$
.
ajax
({
type
:
'POST'
,
url
:
'../UbigeoServlet?accion=listarProvincia'
,
dataType
:
'json'
,
data
:
{
json
:
JSON
.
stringify
(
json
)},
beforeSend
:
function
(
xhr
)
{
},
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
var
status
=
data
.
status
;
var
provincias
=
data
.
data
.
provincias
;
if
(
status
)
{
var
select_provincia
=
'<option value="0">[ SELECCIONE ]</option>'
;
for
(
var
i
in
provincias
)
{
select_provincia
+=
'<option value="'
+
provincias
[
i
].
codigoProvincia
+
'">'
+
provincias
[
i
].
nombreProvincia
+
'</option>'
;
}
$
(
'#select_provincia'
).
html
(
select_provincia
);
$
(
'#select_provincia'
).
selectpicker
(
'refresh'
);
}
else
{
}
},
complete
:
function
(
jqXHR
,
textStatus
)
{
}
});
});
}
function
listarDistrito
()
{
$
(
'#select_provincia'
).
on
(
'change'
,
function
()
{
var
json
=
{
codigoDepartamento
:
$
(
'#select_departamento'
).
val
(),
codigoProvincia
:
$
(
'#select_provincia'
).
val
()
};
$
.
ajax
({
type
:
'POST'
,
url
:
'../UbigeoServlet?accion=listarDistrito'
,
dataType
:
'json'
,
data
:
{
json
:
JSON
.
stringify
(
json
)},
beforeSend
:
function
(
xhr
)
{
},
success
:
function
(
data
,
textStatus
,
jqXHR
)
{
var
status
=
data
.
status
;
var
distritos
=
data
.
data
.
distritos
;
if
(
status
)
{
var
select_distrito
=
'<option value="0">[ SELECCIONE ]</option>'
;
for
(
var
i
in
distritos
)
{
select_distrito
+=
'<option value="'
+
distritos
[
i
].
codigoDistrito
+
'">'
+
distritos
[
i
].
nombreDistrito
+
'</option>'
;
}
$
(
'#select_distrito'
).
html
(
select_distrito
);
$
(
'#select_distrito'
).
selectpicker
(
'refresh'
);
}
else
{
}
},
complete
:
function
(
jqXHR
,
textStatus
)
{
}
});
});
return
new
Promise
((
resolve
,
reject
)
=>
{
fetchSo
(
'../UbigeoServlet?accion=listarProvincia'
,
json
)
.
then
((
data
)
=>
{
resolve
(
data
)
})
.
catch
((
data
)
=>
{
reject
(
data
)
})
})
},
consultarDistrito
(
codigoDepartamento
,
codigoProvincia
)
{
let
json
=
{
codigoProvincia
:
codigoProvincia
,
codigoDepartamento
:
codigoDepartamento
}
return
new
Promise
((
resolve
,
reject
)
=>
{
fetchSo
(
'../UbigeoServlet?accion=listarDistrito'
,
json
)
.
then
((
data
)
=>
{
resolve
(
data
)
})
.
catch
((
data
)
=>
{
reject
(
data
)
})
})
}
}
function
validarSelect
()
{
$
(
'#select_departamento'
).
on
(
'change'
,
function
()
{
var
select_departamento
=
$
(
'#select_departamento'
).
val
();
if
(
select_departamento
===
'0'
)
{
$
(
'#select_provincia'
).
html
(
'<option value="0">[ SELECCIONE ]</option>'
);
$
(
'#select_distrito'
).
html
(
'<option value="0">[ SELECCIONE ]</option>'
);
$
(
'#select_provincia'
).
selectpicker
(
'refresh'
);
$
(
'#select_distrito'
).
selectpicker
(
'refresh'
);
let
asignarEventos
=
()
=>
{
let
slDepartamento
=
document
.
querySelector
(
'#select_departamento'
)
let
slProvincia
=
document
.
querySelector
(
'#select_provincia'
)
let
slDistrito
=
document
.
querySelector
(
'#select_distrito'
)
slDepartamento
.
addEventListener
(
'change'
,
(
e
)
=>
{
let
codigoDepartamento
=
parseInt
(
e
.
target
.
value
)
ubigeo
.
consultarProvincia
(
codigoDepartamento
)
.
then
((
data
)
=>
{
let
opt
=
'<option value="0">[ SELECCIONE ]</option>'
opt
+=
createSelectOptions
(
data
.
data
.
provincias
,
'codigoProvincia'
,
'nombreProvincia'
)
slProvincia
.
innerHTML
=
opt
})
.
then
(()
=>
{
$
(
'#select_provincia'
).
selectpicker
(
'refresh'
)
})
})
slProvincia
.
addEventListener
(
'change'
,
(
e
)
=>
{
let
codigoDepartamento
=
parseInt
(
slDepartamento
.
value
)
let
codigoProvincia
=
parseInt
(
e
.
target
.
value
)
ubigeo
.
consultarDistrito
(
codigoDepartamento
,
codigoProvincia
)
.
then
((
data
)
=>
{
let
opt
=
'<option value="0">[ SELECCIONE ]</option>'
opt
+=
createSelectOptions
(
data
.
data
.
distritos
,
'codigoDistrito'
,
'nombreDistrito'
)
slDistrito
.
innerHTML
=
opt
})
.
then
(()
=>
{
$
(
'#select_distrito'
).
selectpicker
(
'refresh'
)
})
})
slDepartamento
.
addEventListener
(
'change'
,
(
e
)
=>
{
let
departamento
=
parseInt
(
e
.
target
.
value
)
if
(
departamento
===
0
)
{
slProvincia
.
innerHTML
=
'<option value="0">[ SELECCIONE ]</option>'
slDistrito
.
innerHTML
=
'<option value="0">[ SELECCIONE ]</option>'
}
else
{
$
(
'#select_provincia'
).
val
(
0
);
$
(
'#select_distrito'
).
val
(
0
);
$
(
'#select_distrito'
).
html
(
'<option value="0">[ SELECCIONE ]</option>'
);
$
(
'#select_provincia'
).
selectpicker
(
'refresh'
);
$
(
'#select_distrito'
).
selectpicker
(
'refresh'
);
slProvincia
.
value
=
0
slDistrito
.
value
=
0
}
});
$
(
'#select_provincia'
).
selectpicker
(
'refresh'
)
$
(
'#select_distrito'
).
selectpicker
(
'refresh'
)
})
}
}
\ No newline at end of file
ubigeo
.
consultarDepartamento
()
.
then
((
data
)
=>
{
let
element
=
document
.
querySelector
(
'#select_departamento'
)
let
opt
=
'<option value="0">[ SELECCIONE ]</option>'
opt
+=
createSelectOptions
(
data
.
data
.
departamentos
,
'codigoDepartamento'
,
'nombreDepartamento'
)
element
.
innerHTML
=
opt
})
.
then
(()
=>
{
$
(
'#select_departamento'
).
selectpicker
(
'refresh'
)
})
asignarEventos
()
\ No newline at end of file
web/vistas/index.jsp
View file @
fb1b28ec
<
%
--
<
%
--
Document
:
index
Created
on
:
05-ene-2018
,
20:49:32
Author
:
Alonso
...
...
@@ -31,7 +31,7 @@
<div
class=
"col-md-4"
>
<div
class=
"form-group"
>
<label
class=
"text-uppercase"
>
departamento
<span
class=
"text-danger"
>
(*)
</span></label>
<select
id=
"select_departamento"
class=
"
bootstrap-select
"
data-width=
"100%"
>
<select
id=
"select_departamento"
class=
"
form-control
"
data-width=
"100%"
>
<option
value=
"0"
>
[ SELECCIONE ]
</option>
</select>
</div>
...
...
@@ -74,7 +74,7 @@
<script
type=
"text/javascript"
src=
"../plantilla/assets/js/pages/form_bootstrap_select.js"
></script>
<!--js-->
<script
src=
"../js/general.js"
type=
"text/javascript"
></script>
<script
src=
"../js/pages/ubigeo.js"
type=
"text/javascript"
></script>
</body>
</html>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment