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
f26f65ff
Commit
f26f65ff
authored
Jan 09, 2018
by
Alonso Moreno Postigo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[EDIT] PersonaSqlserverDAO - ResponseHelper
parent
d03d3150
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
87 deletions
+62
-87
PersonaSqlserverDAO.java
src/java/demojsoncrud/sqlserverdao/PersonaSqlserverDAO.java
+59
-65
ResponseHelper.java
src/java/demojsoncrud/utils/ResponseHelper.java
+0
-19
persona.js
web/js/pages/persona.js
+3
-3
No files found.
src/java/demojsoncrud/sqlserverdao/PersonaSqlserverDAO.java
View file @
f26f65ff
...
...
@@ -22,11 +22,6 @@ import org.json.JSONObject;
*/
public
class
PersonaSqlserverDAO
implements
PersonaDAO
{
public
static
void
main
(
String
[]
args
)
{
PersonaSqlserverDAO
personaSqlserverDAO
=
new
PersonaSqlserverDAO
();
System
.
out
.
println
(
personaSqlserverDAO
.
listarPersonaTest
());
}
@Override
public
JSONObject
listarPersonaTest
()
{
...
...
@@ -73,7 +68,7 @@ public class PersonaSqlserverDAO implements PersonaDAO {
response
.
setStatus
(
true
);
}
catch
(
SQLException
e
)
{
response
.
setMe
nsaj
e
(
"Error -> "
+
e
.
getMessage
()
+
" ["
+
e
.
getErrorCode
()
+
"]"
);
response
.
setMe
ssag
e
(
"Error -> "
+
e
.
getMessage
()
+
" ["
+
e
.
getErrorCode
()
+
"]"
);
response
.
setStatus
(
false
);
}
finally
{
try
{
...
...
@@ -87,12 +82,13 @@ public class PersonaSqlserverDAO implements PersonaDAO {
connection
.
close
();
}
}
catch
(
SQLException
e
)
{
response
.
setMe
nsaj
e
(
"Error -> "
+
e
.
getMessage
()
+
" ["
+
e
.
getErrorCode
()
+
"]"
);
response
.
setMe
ssag
e
(
"Error -> "
+
e
.
getMessage
()
+
" ["
+
e
.
getErrorCode
()
+
"]"
);
response
.
setStatus
(
false
);
}
}
jsonReturn
=
new
JSONObject
(
response
);
return
jsonReturn
;
}
...
...
@@ -181,7 +177,7 @@ public class PersonaSqlserverDAO implements PersonaDAO {
connection
.
close
();
}
}
catch
(
SQLException
e
)
{
jsonReturn
.
put
(
"Error"
,
"Error inesperado -> "
+
e
.
getMessage
()
+
"
Code: "
+
e
.
getErrorCode
()
);
jsonReturn
.
put
(
"Error"
,
"Error inesperado -> "
+
e
.
getMessage
()
+
"
["
+
e
.
getErrorCode
()
+
"]"
);
}
}
...
...
@@ -190,7 +186,7 @@ public class PersonaSqlserverDAO implements PersonaDAO {
@Override
public
JSONObject
registrarPersona
(
PersonaBean
bean
)
{
JSONObject
jsonReturn
=
n
ull
;
JSONObject
jsonReturn
=
n
ew
JSONObject
()
;
int
resultDni
=
0
;
int
resultPersona
=
0
;
String
base
=
"demojsoncrud"
;
...
...
@@ -220,25 +216,21 @@ public class PersonaSqlserverDAO implements PersonaDAO {
psInsertarPersona
.
setString
(
c
++,
bean
.
getCorreo
());
resultPersona
=
psInsertarPersona
.
executeUpdate
();
if
(
resultPersona
==
1
)
{
response
.
setMe
nsaje
(
"Se registro correctamente
"
);
response
.
set
Resultado
(
"1"
);
// REGISTRO
response
.
setMe
ssage
(
"Registro correcto!
"
);
response
.
set
Status
(
true
);
}
else
{
response
.
setMe
nsaj
e
(
"Error al registrar"
);
response
.
set
Resultado
(
"0"
);
// ERROR
response
.
setMe
ssag
e
(
"Error al registrar"
);
response
.
set
Status
(
false
);
// ERROR
}
}
else
{
response
.
setMe
nsaje
(
"El número de documento ya existe
"
);
response
.
set
Resultado
(
"2"
);
// DNI REPETIDO
response
.
setMe
ssage
(
"El documento ya existe en mi base de datos. Prueba otro.
"
);
response
.
set
Status
(
false
);
// DNI REPETIDO
}
jsonReturn
=
new
JSONObject
(
response
);
}
catch
(
SQLException
e
)
{
response
.
setResultado
(
"-1"
);
response
.
setMensaje
(
"Error al registrar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
jsonReturn
=
new
JSONObject
(
response
);
response
.
setStatus
(
false
);
response
.
setMessage
(
"Error al registrar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
}
finally
{
try
{
if
(
connection
!=
null
)
{
...
...
@@ -248,9 +240,13 @@ public class PersonaSqlserverDAO implements PersonaDAO {
psInsertarPersona
.
close
();
}
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
"Error inesperado registrarPersona -> "
+
e
.
getMessage
());
response
.
setStatus
(
false
);
response
.
setMessage
(
"Error al registrar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
}
}
jsonReturn
=
new
JSONObject
(
response
);
return
jsonReturn
;
}
...
...
@@ -274,28 +270,25 @@ public class PersonaSqlserverDAO implements PersonaDAO {
+
"where codigo = ?"
;
psEditarPersona
=
connection
.
prepareStatement
(
sql
);
int
c
=
1
;
// CONTADOR PARA LAS COLUMNAS
psEditarPersona
.
setString
(
c
++,
bean
.
getApellidos
());
psEditarPersona
.
setString
(
c
++,
bean
.
getNombres
());
psEditarPersona
.
setString
(
c
++,
bean
.
getEdad
());
psEditarPersona
.
setString
(
c
++,
bean
.
getCorreo
());
psEditarPersona
.
setString
(
c
++,
bean
.
getCodigo
());
int
q
=
1
;
// CONTADOR PARA LAS COLUMNAS
psEditarPersona
.
setString
(
q
++,
bean
.
getApellidos
());
psEditarPersona
.
setString
(
q
++,
bean
.
getNombres
());
psEditarPersona
.
setString
(
q
++,
bean
.
getEdad
());
psEditarPersona
.
setString
(
q
++,
bean
.
getCorreo
());
psEditarPersona
.
setString
(
q
++,
bean
.
getCodigo
());
resultPersona
=
psEditarPersona
.
executeUpdate
();
if
(
resultPersona
==
1
)
{
response
.
setMe
nsaj
e
(
"Se actualizo correctamente"
);
response
.
set
Resultado
(
"1"
);
// ACTUALIZO
response
.
setMe
ssag
e
(
"Se actualizo correctamente"
);
response
.
set
Status
(
true
);
// ACTUALIZO
}
else
{
response
.
setMe
nsaj
e
(
"Error al actualizar"
);
response
.
set
Resultado
(
"0"
);
// ERROR
response
.
setMe
ssag
e
(
"Error al actualizar"
);
response
.
set
Status
(
false
);
// ERROR
}
jsonReturn
=
new
JSONObject
(
response
);
}
catch
(
SQLException
e
)
{
response
.
setResultado
(
"-1"
);
response
.
setMensaje
(
"Error al actualizar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
jsonReturn
=
new
JSONObject
(
response
);
response
.
setStatus
(
false
);
response
.
setMessage
(
"Error al actualizar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
}
finally
{
try
{
if
(
connection
!=
null
)
{
...
...
@@ -305,10 +298,13 @@ public class PersonaSqlserverDAO implements PersonaDAO {
psEditarPersona
.
close
();
}
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
"Error inesperado editarPersona -> "
+
e
.
getMessage
());
response
.
setStatus
(
false
);
response
.
setMessage
(
"Error al actualizar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
}
}
jsonReturn
=
new
JSONObject
(
response
);
return
jsonReturn
;
}
...
...
@@ -327,26 +323,23 @@ public class PersonaSqlserverDAO implements PersonaDAO {
=
"update persona "
+
"set estado = 1 "
+
"where codigo = ?"
;
System
.
out
.
println
(
sql
);
psEditarPersona
=
connection
.
prepareStatement
(
sql
);
int
c
=
1
;
// CONTADOR PARA LAS COLUMNAS
psEditarPersona
.
setString
(
c
++
,
bean
.
getCodigo
());
psEditarPersona
.
setString
(
1
,
bean
.
getCodigo
());
resultPersona
=
psEditarPersona
.
executeUpdate
();
if
(
resultPersona
==
1
)
{
response
.
setMe
nsaj
e
(
"Se actualizo correctamente"
);
response
.
set
Resultado
(
"1"
);
// ACTUALIZO
response
.
setMe
ssag
e
(
"Se actualizo correctamente"
);
response
.
set
Status
(
true
);
// ACTUALIZO
}
else
{
response
.
setMe
nsaj
e
(
"Error al actualizar"
);
response
.
set
Resultado
(
"0"
);
// ERROR
response
.
setMe
ssag
e
(
"Error al actualizar"
);
response
.
set
Status
(
false
);
// ERROR
}
jsonReturn
=
new
JSONObject
(
response
);
}
catch
(
SQLException
e
)
{
response
.
setResultado
(
"-1"
);
response
.
setMensaje
(
"Error al actualizar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
jsonReturn
=
new
JSONObject
(
response
);
response
.
setStatus
(
false
);
response
.
setMessage
(
"Error al actualizar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
}
finally
{
try
{
if
(
connection
!=
null
)
{
...
...
@@ -356,10 +349,13 @@ public class PersonaSqlserverDAO implements PersonaDAO {
psEditarPersona
.
close
();
}
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
"Error inesperado activarPersona -> "
+
e
.
getMessage
());
response
.
setStatus
(
false
);
response
.
setMessage
(
"Error al actualizar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
}
}
jsonReturn
=
new
JSONObject
(
response
);
return
jsonReturn
;
}
...
...
@@ -378,26 +374,22 @@ public class PersonaSqlserverDAO implements PersonaDAO {
=
"update persona "
+
"set estado = 0 "
+
"where codigo = ?"
;
System
.
out
.
println
(
sql
);
psEditarPersona
=
connection
.
prepareStatement
(
sql
);
int
c
=
1
;
// CONTADOR PARA LAS COLUMNAS
psEditarPersona
.
setString
(
c
++,
bean
.
getCodigo
());
psEditarPersona
.
setString
(
1
,
bean
.
getCodigo
());
resultPersona
=
psEditarPersona
.
executeUpdate
();
if
(
resultPersona
==
1
)
{
response
.
setMe
nsaj
e
(
"Se actualizo correctamente"
);
response
.
set
Resultado
(
"1"
);
// ACTUALIZO
response
.
setMe
ssag
e
(
"Se actualizo correctamente"
);
response
.
set
Status
(
true
);
// ACTUALIZO
}
else
{
response
.
setMe
nsaj
e
(
"Error al actualizar"
);
response
.
set
Resultado
(
"0"
);
// ERROR
response
.
setMe
ssag
e
(
"Error al actualizar"
);
response
.
set
Status
(
false
);
// ERROR
}
jsonReturn
=
new
JSONObject
(
response
);
}
catch
(
SQLException
e
)
{
response
.
setResultado
(
"-1"
);
response
.
setMensaje
(
"Error al actualizar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
jsonReturn
=
new
JSONObject
(
response
);
response
.
setStatus
(
false
);
response
.
setMessage
(
"Error al actualizar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
}
finally
{
try
{
if
(
connection
!=
null
)
{
...
...
@@ -407,10 +399,12 @@ public class PersonaSqlserverDAO implements PersonaDAO {
psEditarPersona
.
close
();
}
}
catch
(
SQLException
e
)
{
System
.
out
.
println
(
"Error inesperado registrarPersona -> "
+
e
.
getMessage
());
response
.
setStatus
(
false
);
response
.
setMessage
(
"Error al actualizar -> "
+
e
.
getMessage
()
+
"["
+
e
.
getErrorCode
()
+
"]"
);
}
}
jsonReturn
=
new
JSONObject
(
response
);
return
jsonReturn
;
}
...
...
src/java/demojsoncrud/utils/ResponseHelper.java
View file @
f26f65ff
...
...
@@ -13,9 +13,6 @@ import java.io.Serializable;
*/
public
class
ResponseHelper
implements
Serializable
{
private
String
resultado
;
private
String
mensaje
;
private
Object
data
;
private
boolean
status
;
private
String
message
;
...
...
@@ -40,22 +37,6 @@ public class ResponseHelper implements Serializable {
this
.
message
=
message
;
}
public
String
getResultado
()
{
return
resultado
;
}
public
void
setResultado
(
String
resultado
)
{
this
.
resultado
=
resultado
;
}
public
String
getMensaje
()
{
return
mensaje
;
}
public
void
setMensaje
(
String
mensaje
)
{
this
.
mensaje
=
mensaje
;
}
public
Object
getData
()
{
return
data
;
}
...
...
web/js/pages/persona.js
View file @
f26f65ff
...
...
@@ -17,7 +17,7 @@ $(document).ready(function () {
$
(
'#btn_cerar_registrar_persona'
).
on
(
'click'
,
function
()
{
$
(
"form_registrar_persona"
).
validate
().
resetForm
();
});
filtrarPersona
();
});
...
...
@@ -240,7 +240,7 @@ function listarPersona() {
var
json
=
{
codigo
:
data_row
.
codigo
};
console
.
log
(
data_row
.
codigo
);
swal
({
title
:
"¿Estás seguro?"
,
text
:
"¿Desea desactivar a "
+
data_row
.
apellidos
+
", "
+
data_row
.
nombres
+
" ?"
,
...
...
@@ -277,7 +277,7 @@ function listarPersona() {
var
json
=
{
codigo
:
data_row
.
codigo
};
console
.
log
(
data_row
.
codigo
);
swal
({
title
:
"¿Estás seguro?"
,
text
:
"¿Desea activar a "
+
data_row
.
apellidos
+
", "
+
data_row
.
nombres
+
" ?"
,
...
...
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