Commit 082e885b by Alonso Moreno Postigo

[FIX] Arreglado bug al realizar acciones en la fila

parent 79700058
......@@ -36,15 +36,15 @@ public class PersonaSqlserverDAO implements PersonaDAO {
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 ";
= "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();
......@@ -63,7 +63,10 @@ public class PersonaSqlserverDAO implements PersonaDAO {
data.put(obj);
}
response.setData(data);
JSONObject jsonData = new JSONObject();
jsonData.put("personas", data);
response.setData(jsonData);
response.setMessage("Listado correcto!");
response.setStatus(true);
......@@ -116,18 +119,18 @@ public class PersonaSqlserverDAO implements PersonaDAO {
try {
connection = SqlserverDAOFactory.obtenerConexion(base);
String sql
= "select top " + length + " "
+ "a.codigo, "
+ "a.dni, "
+ "a.apellidos, "
+ "a.nombres, "
+ "a.edad, "
+ "a.correo, "
+ "a.estado "
+ "from persona a "
+ "where a.codigo not in (select top " + start + " b.codigo from persona b order by 1 desc) "
+ condicion + " "
+ "order by 1 desc";
= "select top " + length + " "
+ "a.codigo, "
+ "a.dni, "
+ "a.apellidos, "
+ "a.nombres, "
+ "a.edad, "
+ "a.correo, "
+ "a.estado "
+ "from persona a "
+ "where a.codigo not in (select top " + start + " b.codigo from persona b order by 1 desc) "
+ condicion + " "
+ "order by 1 desc";
psListarPersona = connection.prepareStatement(sql);
rsListarPersona = psListarPersona.executeQuery();
......@@ -143,7 +146,6 @@ public class PersonaSqlserverDAO implements PersonaDAO {
personaBean.setCorreo(rsListarPersona.getString(c++));
personaBean.setEstado(rsListarPersona.getString(c++));
JSONObject obj = new JSONObject(personaBean);
obj.put("item", numeroFilas++);
data.put(obj);
}
......@@ -205,8 +207,8 @@ public class PersonaSqlserverDAO implements PersonaDAO {
if (resultDni == 0) {
String sql
= "insert into persona (dni, apellidos, nombres, edad, correo, estado) values "
+ "(?,RTRIM(UPPER(?)),RTRIM(UPPER(?)),?,RTRIM(UPPER(?)),1)";
= "insert into persona (dni, apellidos, nombres, edad, correo, estado) values "
+ "(?,RTRIM(UPPER(?)),RTRIM(UPPER(?)),?,RTRIM(UPPER(?)),1)";
int c = 1; //contador para las columnas
psInsertarPersona = connection.prepareStatement(sql);
psInsertarPersona.setString(c++, bean.getDni());
......@@ -262,12 +264,12 @@ public class PersonaSqlserverDAO implements PersonaDAO {
try {
connection = SqlserverDAOFactory.obtenerConexion(base);
String sql
= "update persona "
+ "set apellidos = RTRIM(UPPER(?)), "
+ "nombres = RTRIM(UPPER(?)), "
+ "edad = ?, "
+ "correo = RTRIM(UPPER(?)) "
+ "where codigo = ?";
= "update persona "
+ "set apellidos = RTRIM(UPPER(?)), "
+ "nombres = RTRIM(UPPER(?)), "
+ "edad = ?, "
+ "correo = RTRIM(UPPER(?)) "
+ "where codigo = ?";
psEditarPersona = connection.prepareStatement(sql);
int q = 1; // CONTADOR PARA LAS COLUMNAS
......@@ -320,9 +322,9 @@ public class PersonaSqlserverDAO implements PersonaDAO {
try {
connection = SqlserverDAOFactory.obtenerConexion(base);
String sql
= "update persona "
+ "set estado = 1 "
+ "where codigo = ?";
= "update persona "
+ "set estado = 1 "
+ "where codigo = ?";
psEditarPersona = connection.prepareStatement(sql);
......@@ -371,9 +373,9 @@ public class PersonaSqlserverDAO implements PersonaDAO {
try {
connection = SqlserverDAOFactory.obtenerConexion(base);
String sql
= "update persona "
+ "set estado = 0 "
+ "where codigo = ?";
= "update persona "
+ "set estado = 0 "
+ "where codigo = ?";
psEditarPersona = connection.prepareStatement(sql);
psEditarPersona.setString(1, bean.getCodigo());
......
......@@ -6,6 +6,7 @@
package demojsoncrud.utils;
import java.io.Serializable;
import org.json.JSONObject;
/**
*
......@@ -13,7 +14,7 @@ import java.io.Serializable;
*/
public class ResponseHelper implements Serializable {
private Object data;
private JSONObject data;
private boolean status;
private String message;
......@@ -21,28 +22,28 @@ public class ResponseHelper implements Serializable {
}
public boolean isStatus() {
return status;
public JSONObject getData() {
return data;
}
public void setStatus(boolean status) {
this.status = status;
public boolean isStatus() {
return status;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
public void setData(JSONObject data) {
this.data = data;
}
public Object getData() {
return data;
public void setStatus(boolean status) {
this.status = status;
}
public void setData(Object data) {
this.data = data;
public void setMessage(String message) {
this.message = message;
}
}
......@@ -36,8 +36,13 @@ function listarPersonaTest() {
beforeSend: function (xhr) {
// console.log('Antes de...');
}, success: function (data, textStatus, jqXHR) {
// console.log(data);
// console.log("listadoTest");
console.log(data);
// var personas = data.data.personas;
// for (var i = 0; i < personas.length; i++) {
// var persona = personas[i];
// console.log(persona.apellidos);
// }
//// console.log("listadoTest");
}, complete: function (jqXHR, textStatus) {
// console.log('Siempre ejecutará esta función');
}
......@@ -88,8 +93,8 @@ function registrarPersona() {
var status = data.status;
if (status) {
imprimirAlerta('Correcto!', data.message, 'success');
var table = $('#tabla_persona').DataTable();
table.ajax.reload();
// var table = $('#tabla_persona').DataTable();
// table.ajax.reload();
recargarTabla();
$('#modal_registrar_persona').modal('hide');
} else {
......@@ -194,7 +199,7 @@ function listarPersona() {
ScrollCollapse: true,
columns: [
{data: "item"},
{data: "codigo"},
{data: "dni"},
{
data: null,
......@@ -254,8 +259,7 @@ $('#tabla_persona tbody').on('click', '.desactivarPersona', function () {
var json = {
codigo: data_row.codigo
};
alert(data_row.codigo);
console.log(data_row.codigo);
swal({
title: "¿Estás seguro?",
text: "¿Desea desactivar a " + data_row.apellidos + ", " + data_row.nombres + " ?",
......@@ -299,8 +303,7 @@ $('#tabla_persona tbody').on('click', '.activarPersona', function () {
var json = {
codigo: data_row.codigo
};
console.log(data_row.codigo);
alert(data_row.codigo);
swal({
title: "¿Estás seguro?",
text: "¿Desea activar a " + data_row.apellidos + ", " + data_row.nombres + " ?",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment