[EDIT] Cambios

parent 3524a041
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="demojsoncrud" default="default" basedir=".">
<description>Builds, tests, and runs the project demojsoncrud.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-dist: called before archive building
-post-dist: called after archive building
-post-clean: called after cleaning build products
-pre-run-deploy: called before deploying
-post-run-deploy: called after deploying
Example of pluging an obfuscator after the compilation could look like
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Other way how to customize the build is by overriding existing main targets.
The target of interest are:
init-macrodef-javac: defines macro for javac compilation
init-macrodef-junit: defines macro for junit execution
init-macrodef-debug: defines macro for class debugging
do-dist: archive building
run: execution of project
javadoc-build: javadoc generation
Example of overriding the target for project execution could look like
<target name="run" depends="<PROJNAME>-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that overridden target depends on jar target and not only on
compile target as regular run target does. Again, for list of available
properties which you can use check the target you are overriding in
nbproject/build-impl.xml file.
-->
</project>
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="demojsoncrud" default="default" basedir=".">
<description>Builds, tests, and runs the project demojsoncrud.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-dist: called before archive building
-post-dist: called after archive building
-post-clean: called after cleaning build products
-pre-run-deploy: called before deploying
-post-run-deploy: called after deploying
Example of pluging an obfuscator after the compilation could look like
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Other way how to customize the build is by overriding existing main targets.
The target of interest are:
init-macrodef-javac: defines macro for javac compilation
init-macrodef-junit: defines macro for junit execution
init-macrodef-debug: defines macro for class debugging
do-dist: archive building
run: execution of project
javadoc-build: javadoc generation
Example of overriding the target for project execution could look like
<target name="run" depends="<PROJNAME>-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that overridden target depends on jar target and not only on
compile target as regular run target does. Again, for list of available
properties which you can use check the target you are overriding in
nbproject/build-impl.xml file.
-->
</project>
This source diff could not be displayed because it is too large. You can view the blob instead.
build.xml.data.CRC32=4cd4cb5e
build.xml.script.CRC32=615931b7
build.xml.stylesheet.CRC32=651128d4@1.77.1.1
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=4cd4cb5e
nbproject/build-impl.xml.script.CRC32=efa11df6
nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.77.1.1
build.xml.data.CRC32=66ba06da
build.xml.script.CRC32=615931b7
build.xml.stylesheet.CRC32=651128d4@1.77.1.1
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=66ba06da
nbproject/build-impl.xml.script.CRC32=816bdc64
nbproject/build-impl.xml.stylesheet.CRC32=99ea4b56@1.77.1.1
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=true
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.web.dir}/WEB-INF/classes
build.classes.excludes=**/*.java,**/*.form
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
build.web.dir=${build.dir}/web
build.web.excludes=${build.classes.excludes}
client.urlPart=
compile.jsps=false
conf.dir=${source.root}/conf
debug.classpath=${build.classes.dir}:${javac.classpath}
debug.test.classpath=\
${run.test.classpath}
display.browser=true
# Files to be excluded from distribution war
dist.archive.excludes=
dist.dir=dist
dist.ear.war=${dist.dir}/${war.ear.name}
dist.javadoc.dir=${dist.dir}/javadoc
dist.war=${dist.dir}/${war.name}
endorsed.classpath=\
${libs.javaee-endorsed-api-7.0.classpath}
excludes=
file.reference.json-20160810.jar=F:\\LIBRERIAS\\json-20160810.jar
file.reference.sqljdbc4-2.0.jar=F:\\LIBRERIAS\\sqljdbc4-2.0.jar
includes=**
j2ee.compile.on.save=true
j2ee.copy.static.files.on.save=true
j2ee.deploy.on.save=true
j2ee.platform=1.7-web
j2ee.platform.classpath=${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/cdi-api.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar
j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar
j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar
j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar
j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar
j2ee.platform.wsit.classpath=
j2ee.server.type=gfv3ee6
jar.compress=false
javac.classpath=\
${file.reference.json-20160810.jar}:\
${file.reference.sqljdbc4-2.0.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.debug=true
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.preview=true
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
lib.dir=${web.docbase.dir}/WEB-INF/lib
persistence.xml.dir=${conf.dir}
platform.active=default_platform
resource.dir=setup
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
# Space-separated list of JVM arguments used when running a class with a main method or a unit test
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value):
runmain.jvmargs=
source.encoding=UTF-8
source.root=src
src.dir=${source.root}/java
test.src.dir=test
war.content.additional=
war.ear.name=${war.name}
war.name=demojsoncrud.war
web.docbase.dir=web
webinf.dir=web/WEB-INF
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=true
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.web.dir}/WEB-INF/classes
build.classes.excludes=**/*.java,**/*.form
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
build.web.dir=${build.dir}/web
build.web.excludes=${build.classes.excludes}
client.urlPart=
compile.jsps=false
conf.dir=${source.root}/conf
debug.classpath=${build.classes.dir}:${javac.classpath}
debug.test.classpath=\
${run.test.classpath}
display.browser=true
# Files to be excluded from distribution war
dist.archive.excludes=
dist.dir=dist
dist.ear.war=${dist.dir}/${war.ear.name}
dist.javadoc.dir=${dist.dir}/javadoc
dist.war=${dist.dir}/${war.name}
endorsed.classpath=\
${libs.javaee-endorsed-api-7.0.classpath}
excludes=
file.reference.json-20160212.jar=D:\\LIBRERIAS\\json-20160212.jar
file.reference.sqljdbc4.jar=D:\\LIBRERIAS\\sqljdbc4.jar
includes=**
j2ee.compile.on.save=true
j2ee.copy.static.files.on.save=true
j2ee.deploy.on.save=true
j2ee.platform=1.7-web
j2ee.platform.classpath=${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/cdi-api.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar
j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar
j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar
j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar
j2ee.platform.wsimport.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar
j2ee.platform.wsit.classpath=
j2ee.server.type=gfv3ee6
jar.compress=false
javac.classpath=\
${file.reference.json-20160212.jar}:\
${file.reference.sqljdbc4.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.debug=true
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.preview=true
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
lib.dir=${web.docbase.dir}/WEB-INF/lib
persistence.xml.dir=${conf.dir}
platform.active=default_platform
resource.dir=setup
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
# Space-separated list of JVM arguments used when running a class with a main method or a unit test
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value):
runmain.jvmargs=
source.encoding=UTF-8
source.root=src
src.dir=${source.root}/java
test.src.dir=test
war.content.additional=
war.ear.name=${war.name}
war.name=demojsoncrud.war
web.docbase.dir=web
webinf.dir=web/WEB-INF
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.web.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/web-project/3">
<name>demojsoncrud</name>
<minimum-ant-version>1.6.5</minimum-ant-version>
<web-module-libraries>
<library dirs="200">
<file>${file.reference.json-20160810.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${file.reference.sqljdbc4-2.0.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
</web-module-libraries>
<web-module-additional-libraries/>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.web.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/web-project/3">
<name>demojsoncrud</name>
<minimum-ant-version>1.6.5</minimum-ant-version>
<web-module-libraries>
<library dirs="200">
<file>${file.reference.json-20160212.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
<library dirs="200">
<file>${file.reference.sqljdbc4.jar}</file>
<path-in-war>WEB-INF/lib</path-in-war>
</library>
</web-module-libraries>
<web-module-additional-libraries/>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>
/*
* 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 PersonaBean implements Serializable {
private String codigo;
private String dni;
private String apellidos;
private String nombres;
private String edad;
private String correo;
private String estado;
public PersonaBean() {
}
public String getCodigo() {
return codigo;
}
public void setCodigo(String codigo) {
this.codigo = codigo;
}
public String getDni() {
return dni;
}
public void setDni(String dni) {
this.dni = dni;
}
public String getApellidos() {
return apellidos;
}
public void setApellidos(String apellidos) {
this.apellidos = apellidos;
}
public String getNombres() {
return nombres;
}
public void setNombres(String nombres) {
this.nombres = nombres;
}
public String getEdad() {
return edad;
}
public void setEdad(String edad) {
this.edad = edad;
}
public String getCorreo() {
return correo;
}
public void setCorreo(String correo) {
this.correo = correo;
}
public String getEstado() {
return estado;
}
public void setEstado(String estado) {
this.estado = estado;
}
}
package demojsoncrud.beans;
import java.io.Serializable;
/**
*
* @author Alonso
*/
public class PersonaBean implements Serializable {
private String codigo;
private String dni;
private String apellidos;
private String nombres;
private String edad;
private String correo;
private String estado;
public PersonaBean() {
}
public String getCodigo() {
return codigo;
}
public void setCodigo(String codigo) {
this.codigo = codigo;
}
public String getDni() {
return dni;
}
public void setDni(String dni) {
this.dni = dni;
}
public String getApellidos() {
return apellidos;
}
public void setApellidos(String apellidos) {
this.apellidos = apellidos;
}
public String getNombres() {
return nombres;
}
public void setNombres(String nombres) {
this.nombres = nombres;
}
public String getEdad() {
return edad;
}
public void setEdad(String edad) {
this.edad = edad;
}
public String getCorreo() {
return correo;
}
public void setCorreo(String correo) {
this.correo = correo;
}
public String getEstado() {
return estado;
}
public void setEstado(String estado) {
this.estado = estado;
}
}
/*
* 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.dao;
import demojsoncrud.sqlserverdao.SqlserverDAOFactory;
/**
*
* @author Alonso
*/
public abstract class DAOFactory {
public static final int SQL_SERVER = 1;
public static final int MYSQL = 2;
public static DAOFactory getDAOFactory(int whichFactory) {
switch (whichFactory) {
case SQL_SERVER:
return new SqlserverDAOFactory();
default:
return null;
}
}
public abstract PersonaDAO getPersonaDAO();
}
package demojsoncrud.dao;
import demojsoncrud.sqlserverdao.SqlserverDAOFactory;
public abstract class DAOFactory {
public static final int SQL_SERVER = 1;
public static final int MYSQL = 2;
public static DAOFactory getDAOFactory(int whichFactory) {
switch (whichFactory) {
case SQL_SERVER:
return new SqlserverDAOFactory();
default:
return null;
}
}
public abstract PersonaDAO getPersonaDAO();
}
/*
* 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.dao;
import demojsoncrud.beans.PersonaBean;
import org.json.JSONObject;
/**
*
* @author Alonso
*/
public interface PersonaDAO {
public JSONObject listarPersonaTest();
public JSONObject listarPersona(String search, String draw, String start, String length);
public JSONObject registrarPersona(PersonaBean bean);
public JSONObject editarPersona(PersonaBean bean);
public JSONObject activarPersona(PersonaBean bean);
public JSONObject desactivarPersona(PersonaBean bean);
}
package demojsoncrud.dao;
import demojsoncrud.beans.PersonaBean;
import org.json.JSONObject;
public interface PersonaDAO {
public JSONObject listarPersonaTest();
public JSONObject listarPersona(String search, String draw, String start, String length);
public JSONObject registrarPersona(PersonaBean bean);
public JSONObject editarPersona(PersonaBean bean);
public JSONObject activarPersona(PersonaBean bean);
public JSONObject desactivarPersona(PersonaBean bean);
}
/*
* 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.PersonaBean;
import demojsoncrud.dao.DAOFactory;
import demojsoncrud.dao.PersonaDAO;
import org.json.JSONObject;
/**
*
* @author Alonso
*/
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 {
jsonReturn = service.listarPersona(search, draw, start, length);
} catch (Exception e) {
e.getMessage();
}
return jsonReturn;
}
public JSONObject registrarPersona(PersonaBean bean) {
JSONObject jsonReturn = null;
try {
jsonReturn = service.registrarPersona(bean);
} catch (Exception e) {
e.getMessage();
}
return jsonReturn;
}
public JSONObject editarPersona(PersonaBean bean) {
JSONObject jsonReturn = null;
try {
jsonReturn = service.editarPersona(bean);
} catch (Exception e) {
e.getMessage();
}
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;
}
}
package demojsoncrud.services;
import demojsoncrud.beans.PersonaBean;
import demojsoncrud.dao.DAOFactory;
import demojsoncrud.dao.PersonaDAO;
import org.json.JSONObject;
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 {
jsonReturn = service.listarPersona(search, draw, start, length);
} catch (Exception e) {
e.getMessage();
}
return jsonReturn;
}
public JSONObject registrarPersona(PersonaBean bean) {
JSONObject jsonReturn = null;
try {
jsonReturn = service.registrarPersona(bean);
} catch (Exception e) {
e.getMessage();
}
return jsonReturn;
}
public JSONObject editarPersona(PersonaBean bean) {
JSONObject jsonReturn = null;
try {
jsonReturn = service.editarPersona(bean);
} catch (Exception e) {
e.getMessage();
}
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;
}
}
/*
* 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.PersonaBean;
import demojsoncrud.services.PersonaService;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONObject;
/**
*
* @author Alonso
*/
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);
}
}
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();
PersonaService service = new PersonaService();
String draw = request.getParameter("draw");
String start = request.getParameter("start");
String length = request.getParameter("length");
String search = request.getParameter("search");
JSONObject json = service.listarPersona(search, draw, start, length);
pw.print(json);
}
private void registrarPersona(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("application/json");
PrintWriter pw = response.getWriter();
PersonaService service = new PersonaService();
String json = request.getParameter("json");
JSONObject jsonObject = new JSONObject(json);
String dni = jsonObject.getString("dni");
String apellidos = jsonObject.getString("apellidos");
String nombres = jsonObject.getString("nombres");
String edad = jsonObject.getString("edad");
String correo = jsonObject.getString("correo");
PersonaBean bean = new PersonaBean();
bean.setDni(dni);
bean.setApellidos(apellidos);
bean.setNombres(nombres);
bean.setEdad(edad);
bean.setCorreo(correo);
JSONObject jsonReturn = service.registrarPersona(bean);
pw.print(jsonReturn);
}
private void editarPersona(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 apellidos = jsonObject.getString("apellidos");
String nombres = jsonObject.getString("nombres");
String edad = jsonObject.getString("edad");
String correo = jsonObject.getString("correo");
String codigo = jsonObject.getString("codigo");
PersonaBean bean = new PersonaBean();
bean.setApellidos(apellidos);
bean.setNombres(nombres);
bean.setEdad(edad);
bean.setCorreo(correo);
bean.setCodigo(codigo);
JSONObject jsonReturn = service.editarPersona(bean);
pw.print(jsonReturn);
}
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);
}
}
package demojsoncrud.servlets;
import demojsoncrud.beans.PersonaBean;
import demojsoncrud.services.PersonaService;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.JSONObject;
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);
}
}
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();
PersonaService service = new PersonaService();
String draw = request.getParameter("draw");
String start = request.getParameter("start");
String length = request.getParameter("length");
String search = request.getParameter("search");
JSONObject json = service.listarPersona(search, draw, start, length);
pw.print(json);
}
private void registrarPersona(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("application/json");
PrintWriter pw = response.getWriter();
PersonaService service = new PersonaService();
String json = request.getParameter("json");
JSONObject jsonObject = new JSONObject(json);
String dni = jsonObject.getString("dni");
String apellidos = jsonObject.getString("apellidos");
String nombres = jsonObject.getString("nombres");
String edad = jsonObject.getString("edad");
String correo = jsonObject.getString("correo");
PersonaBean bean = new PersonaBean();
bean.setDni(dni);
bean.setApellidos(apellidos);
bean.setNombres(nombres);
bean.setEdad(edad);
bean.setCorreo(correo);
JSONObject jsonReturn = service.registrarPersona(bean);
pw.print(jsonReturn);
}
private void editarPersona(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 apellidos = jsonObject.getString("apellidos");
String nombres = jsonObject.getString("nombres");
String edad = jsonObject.getString("edad");
String correo = jsonObject.getString("correo");
String codigo = jsonObject.getString("codigo");
PersonaBean bean = new PersonaBean();
bean.setApellidos(apellidos);
bean.setNombres(nombres);
bean.setEdad(edad);
bean.setCorreo(correo);
bean.setCodigo(codigo);
JSONObject jsonReturn = service.editarPersona(bean);
pw.print(jsonReturn);
}
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);
}
}
/*
* 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.sqlserverdao;
import demojsoncrud.beans.PersonaBean;
import demojsoncrud.dao.PersonaDAO;
import demojsoncrud.utils.ResponseHelper;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
*
* @author Alonso
*/
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();
PreparedStatement psListarPersona = null;
ResultSet rsListarPersona = null;
Connection connection = null;
String base = "demojsoncrud";
String condicion = "";
String condiciones = " (a.nombres like '%" + search + "%' or a.apellidos like '%" + search + "%') ";
int numeroFilas = Integer.parseInt(start) + 1; //Contador para el numero de filas a listar
int cantidadPersonas = 0;
if (!search.equals("")) {
condicion = " and " + condiciones;
}
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";
psListarPersona = connection.prepareStatement(sql);
rsListarPersona = psListarPersona.executeQuery();
while (rsListarPersona.next()) {
PersonaBean personaBean = new PersonaBean();
int c = 1; //Contador para las columnas
personaBean.setCodigo(rsListarPersona.getString(c++));
personaBean.setDni(rsListarPersona.getString(c++));
personaBean.setApellidos(rsListarPersona.getString(c++));
personaBean.setNombres(rsListarPersona.getString(c++));
personaBean.setEdad(rsListarPersona.getString(c++));
personaBean.setCorreo(rsListarPersona.getString(c++));
personaBean.setEstado(rsListarPersona.getString(c++));
JSONObject obj = new JSONObject(personaBean);
data.put(obj);
}
if (!search.equals("")) {
condicion = " where " + condiciones;
}
String sqlCantidadPersonas = "select count(1) as cantidadPersonas from persona a " + condicion;
PreparedStatement psCantidadPersonas = connection.prepareStatement(sqlCantidadPersonas);
ResultSet rsCantidadPersonas = psCantidadPersonas.executeQuery();
rsCantidadPersonas.next();
cantidadPersonas = rsCantidadPersonas.getInt("cantidadPersonas");
jsonReturn.put("data", data);
jsonReturn.put("recordsFiltered", cantidadPersonas);
jsonReturn.put("recordsTotal", cantidadPersonas);
jsonReturn.put("draw", draw);
} catch (SQLException | JSONException e) {
jsonReturn.put("Error", "Error -> " + e.getMessage());
} finally {
try {
if (rsListarPersona != null) {
rsListarPersona.close();
}
if (psListarPersona != null) {
psListarPersona.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
jsonReturn.put("Error", "Error inesperado -> " + e.getMessage() + " [" + e.getErrorCode() + "]");
}
}
return jsonReturn;
}
@Override
public JSONObject registrarPersona(PersonaBean bean) {
JSONObject jsonReturn = new JSONObject();
int resultDni = 0;
int resultPersona = 0;
String base = "demojsoncrud";
PreparedStatement psInsertarPersona = null;
Connection connection = null;
ResponseHelper response = new ResponseHelper();
try {
connection = SqlserverDAOFactory.obtenerConexion(base);
String sqlGetDni = "select count(1) dni from persona where dni = ?";
PreparedStatement psGetDni = connection.prepareStatement(sqlGetDni);
psGetDni.setString(1, bean.getDni());
ResultSet rsGetDni = psGetDni.executeQuery();
rsGetDni.next();
resultDni = rsGetDni.getInt("dni");
if (resultDni == 0) {
String sql
= "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());
psInsertarPersona.setString(c++, bean.getApellidos());
psInsertarPersona.setString(c++, bean.getNombres());
psInsertarPersona.setString(c++, bean.getEdad());
psInsertarPersona.setString(c++, bean.getCorreo());
resultPersona = psInsertarPersona.executeUpdate();
if (resultPersona == 1) {
response.setMessage("Registro correcto!");
response.setStatus(true);
} else {
response.setMessage("Error al registrar");
response.setStatus(false); // ERROR
}
} else {
response.setMessage("El documento ya existe en mi base de datos. Prueba otro.");
response.setStatus(false); // DNI REPETIDO
}
} catch (SQLException e) {
response.setStatus(false);
response.setMessage("Error al registrar -> " + e.getMessage() + "[" + e.getErrorCode() + "]");
} finally {
try {
if (connection != null) {
connection.close();
}
if (psInsertarPersona != null) {
psInsertarPersona.close();
}
} catch (SQLException e) {
response.setStatus(false);
response.setMessage("Error al registrar -> " + e.getMessage() + "[" + e.getErrorCode() + "]");
}
}
jsonReturn = new JSONObject(response);
return jsonReturn;
}
@Override
public JSONObject editarPersona(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 apellidos = RTRIM(UPPER(?)), "
+ "nombres = RTRIM(UPPER(?)), "
+ "edad = ?, "
+ "correo = RTRIM(UPPER(?)) "
+ "where codigo = ?";
psEditarPersona = connection.prepareStatement(sql);
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.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 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;
}
}
package demojsoncrud.sqlserverdao;
import demojsoncrud.beans.PersonaBean;
import demojsoncrud.dao.PersonaDAO;
import demojsoncrud.utilities.ResponseHelper;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.json.JSONArray;
import org.json.JSONException;
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();
PreparedStatement psListarPersona = null;
ResultSet rsListarPersona = null;
Connection connection = null;
String base = "demojsoncrud";
String condicion = "";
String condiciones = " (a.nombres like '%" + search + "%' or a.apellidos like '%" + search + "%') ";
int numeroFilas = Integer.parseInt(start) + 1; //Contador para el numero de filas a listar
int cantidadPersonas = 0;
if (!search.equals("")) {
condicion = " and " + condiciones;
}
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";
psListarPersona = connection.prepareStatement(sql);
rsListarPersona = psListarPersona.executeQuery();
while (rsListarPersona.next()) {
PersonaBean personaBean = new PersonaBean();
int c = 1; //Contador para las columnas
personaBean.setCodigo(rsListarPersona.getString(c++));
personaBean.setDni(rsListarPersona.getString(c++));
personaBean.setApellidos(rsListarPersona.getString(c++));
personaBean.setNombres(rsListarPersona.getString(c++));
personaBean.setEdad(rsListarPersona.getString(c++));
personaBean.setCorreo(rsListarPersona.getString(c++));
personaBean.setEstado(rsListarPersona.getString(c++));
JSONObject obj = new JSONObject(personaBean);
data.put(obj);
}
if (!search.equals("")) {
condicion = " where " + condiciones;
}
String sqlCantidadPersonas = "select count(1) as cantidadPersonas from persona a " + condicion;
PreparedStatement psCantidadPersonas = connection.prepareStatement(sqlCantidadPersonas);
ResultSet rsCantidadPersonas = psCantidadPersonas.executeQuery();
rsCantidadPersonas.next();
cantidadPersonas = rsCantidadPersonas.getInt("cantidadPersonas");
jsonReturn.put("data", data);
jsonReturn.put("recordsFiltered", cantidadPersonas);
jsonReturn.put("recordsTotal", cantidadPersonas);
jsonReturn.put("draw", draw);
} catch (SQLException | JSONException e) {
jsonReturn.put("Error", "Error -> " + e.getMessage());
} finally {
try {
if (rsListarPersona != null) {
rsListarPersona.close();
}
if (psListarPersona != null) {
psListarPersona.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
jsonReturn.put("Error", "Error inesperado -> " + e.getMessage() + " [" + e.getErrorCode() + "]");
}
}
return jsonReturn;
}
@Override
public JSONObject registrarPersona(PersonaBean bean) {
JSONObject jsonReturn = new JSONObject();
int resultDni = 0;
int resultPersona = 0;
String base = "demojsoncrud";
PreparedStatement psInsertarPersona = null;
Connection connection = null;
ResponseHelper response = new ResponseHelper();
try {
connection = SqlserverDAOFactory.obtenerConexion(base);
String sqlGetDni = "select count(1) dni from persona where dni = ?";
PreparedStatement psGetDni = connection.prepareStatement(sqlGetDni);
psGetDni.setString(1, bean.getDni());
ResultSet rsGetDni = psGetDni.executeQuery();
rsGetDni.next();
resultDni = rsGetDni.getInt("dni");
if (resultDni == 0) {
String sql
= "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());
psInsertarPersona.setString(c++, bean.getApellidos());
psInsertarPersona.setString(c++, bean.getNombres());
psInsertarPersona.setString(c++, bean.getEdad());
psInsertarPersona.setString(c++, bean.getCorreo());
resultPersona = psInsertarPersona.executeUpdate();
if (resultPersona == 1) {
response.setMessage("Registro correcto!");
response.setStatus(true);
} else {
response.setMessage("Error al registrar");
response.setStatus(false); // ERROR
}
} else {
response.setMessage("El documento ya existe en mi base de datos. Prueba otro.");
response.setStatus(false); // DNI REPETIDO
}
} catch (SQLException e) {
response.setStatus(false);
response.setMessage("Error al registrar -> " + e.getMessage() + "[" + e.getErrorCode() + "]");
} finally {
try {
if (connection != null) {
connection.close();
}
if (psInsertarPersona != null) {
psInsertarPersona.close();
}
} catch (SQLException e) {
response.setStatus(false);
response.setMessage("Error al registrar -> " + e.getMessage() + "[" + e.getErrorCode() + "]");
}
}
jsonReturn = new JSONObject(response);
return jsonReturn;
}
@Override
public JSONObject editarPersona(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 apellidos = RTRIM(UPPER(?)), "
+ "nombres = RTRIM(UPPER(?)), "
+ "edad = ?, "
+ "correo = RTRIM(UPPER(?)) "
+ "where codigo = ?";
psEditarPersona = connection.prepareStatement(sql);
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.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 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;
}
}
/*
* 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.sqlserverdao;
import demojsoncrud.dao.DAOFactory;
import demojsoncrud.dao.PersonaDAO;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author Alonso
*/
public class SqlserverDAOFactory extends DAOFactory {
public static Connection obtenerConexion(String base) {
Connection connection = null;
if (base.equalsIgnoreCase("demojsoncrud")) {
String user = "sa";
String pwd = "Saco1357$";
String url = "jdbc:sqlserver://localhost:1433;databaseName=demojsoncrud";
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
try {
Class.forName(driver);
connection = DriverManager.getConnection(url, user, pwd);
} catch (ClassNotFoundException | SQLException e) {
System.out.println("Error al conectarse => " + e.getMessage());
}
}
return connection;
}
// public static void main(String[] args) {
// SqlserverDAOFactory sqlserverDAOFactory = new SqlserverDAOFactory();
// System.out.println(sqlserverDAOFactory.obtenerConexion("demojsoncrud"));
// }
@Override
public PersonaDAO getPersonaDAO() {
return new PersonaSqlserverDAO();
}
}
package demojsoncrud.sqlserverdao;
import demojsoncrud.dao.DAOFactory;
import demojsoncrud.dao.PersonaDAO;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class SqlserverDAOFactory extends DAOFactory {
public static Connection obtenerConexion(String base) {
Connection connection = null;
if (base.equalsIgnoreCase("demojsoncrud")) {
String user = "sa";
String pwd = "Saco1357$";
String url = "jdbc:sqlserver://172.16.2.118:1433;databaseName=demojsoncrud";
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
try {
Class.forName(driver);
connection = DriverManager.getConnection(url, user, pwd);
} catch (ClassNotFoundException | SQLException e) {
System.out.println("Error al conectarse => " + e.getMessage());
}
}
return connection;
}
// public static void main(String[] args) {
// SqlserverDAOFactory sqlserverDAOFactory = new SqlserverDAOFactory();
// System.out.println(sqlserverDAOFactory.obtenerConexion("demojsoncrud"));
// }
@Override
public PersonaDAO getPersonaDAO() {
return new PersonaSqlserverDAO();
}
}
/*
* 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.utils;
import java.io.Serializable;
import org.json.JSONObject;
/**
*
* @author Alonso
*/
public class ResponseHelper implements Serializable {
private JSONObject data;
private boolean status;
private String message;
public ResponseHelper() {
}
public JSONObject getData() {
return data;
}
public boolean isStatus() {
return status;
}
public String getMessage() {
return message;
}
public void setData(JSONObject data) {
this.data = data;
}
public void setStatus(boolean status) {
this.status = status;
}
public void setMessage(String message) {
this.message = message;
}
}
package demojsoncrud.utilities;
import java.io.Serializable;
import org.json.JSONObject;
public class ResponseHelper implements Serializable {
private JSONObject data;
private boolean status;
private String message;
public ResponseHelper() {
}
public JSONObject getData() {
return data;
}
public boolean isStatus() {
return status;
}
public String getMessage() {
return message;
}
public void setData(JSONObject data) {
this.data = data;
}
public void setStatus(boolean status) {
this.status = status;
}
public void setMessage(String message) {
this.message = message;
}
}
/*
* 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 () {
listarPersonaTest();
initInputs();
init(); // METODOS CRUD
MyValidate();
filtrarPersona();
$('#btn_agregar_persona').on('click', function () {
limpiarInputs();
});
});
var codigoPersona;
function init() {
listarPersona();
registrarPersona();
editarPersona();
}
function listarPersonaTest() {
$.ajax({
url: '../PersonaServlet?accion=listarPersonaTest',
type: 'POST',
beforeSend: function (xhr) {
// console.log('Antes de...');
}, success: function (data, textStatus, jqXHR) {
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');
}
});
}
function registrarPersona() {
$('#btn_registrar_persona').on('click', function () {
var validator = $('#form_registrar_persona').validate({
rules: {
txt_numero_documento: {required: true, digits: true, minlength: 8, maxlength: 8},
txt_apellidos: {required: true, lettersonly: true, maxlength: 50},
txt_nombres: {required: true, lettersonly: true, maxlength: 50},
txt_edad: {required: true, digits: true, maxlength: 2},
txt_correo: {required: true, email: true, maxlength: 50}
},
messages: {
txt_numero_documento: {required: "Ingresar número de documento.", minlength: "Ingresar 8 dígitos.", maxlength: "Ingresar 8 dígitos.", digits: "Ingresar solo números."},
txt_apellidos: {required: "Ingresar apellidos.", maxlength: "Ingresar 50 letras como máximo.", lettersonly: "Ingresar solo letras"},
txt_nombres: {required: "Ingresar nombres.", maxlength: "Ingresar 50 letras como máximo.", lettersonly: "Ingresar solo letras"},
txt_edad: {required: "Ingresar edad.", maxlength: "Ingresar 2 dígitos como máximo", digits: "Ingresar solo números"},
txt_correo: {required: "Ingresar correo.", maxlength: "Ingresar 50 letras como máximo.", email: "Ingresar un correo válido"}
}
});
var estado = validator.form();
if (estado) {
var json = {
dni: $('#txt_numero_documento').val().trim(),
apellidos: $('#txt_apellidos').val().trim(),
nombres: $('#txt_nombres').val().trim(),
edad: $('#txt_edad').val().trim(),
correo: $('#txt_correo').val().trim()
};
$.ajax({
type: 'POST',
url: '../PersonaServlet?accion=registrarPersona',
dataType: 'json',
data: {json: JSON.stringify(json)},
beforeSend: function (xhr) {
console.log('cargando...');
},
success: function (data, textStatus, jqXHR) {
console.log(data);
var status = data.status;
if (status) {
imprimirAlerta('Correcto!', data.message, 'success');
// var table = $('#tabla_persona').DataTable();
// table.ajax.reload();
recargarTabla();
$('#modal_registrar_persona').modal('hide');
} else {
imprimirAlerta('Error!', data.message, 'error');
}
},
complete: function (jqXHR, textStatus) {
}
});
}
});
}
function editarPersona() {
$('#btn_editar_persona').on('click', function () {
var validator = $('#form_editar_persona').validate({
rules: {
txt_apellidos_editar: {required: true, lettersonly: true, maxlength: 50},
txt_nombres_editar: {required: true, lettersonly: true, maxlength: 50},
txt_edad_editar: {required: true, digits: true, maxlength: 2},
txt_correo_editar: {required: true, email: true, maxlength: 50}
},
messages: {
txt_apellidos_editar: {required: "Ingresar apellidos.", maxlength: "Ingresar 50 letras como máximo.", lettersonly: "Ingresar solo letras"},
txt_nombres_editar: {required: "Ingresar nombres.", maxlength: "Ingresar 50 letras como máximo.", lettersonly: "Ingresar solo letras"},
txt_edad_editar: {required: "Ingresar edad.", maxlength: "Ingresar 2 dígitos como máximo", digits: "Ingresar solo números"},
txt_correo_editar: {required: "Ingresar correo.", maxlength: "Ingresar 50 letras como máximo.", email: "Ingresar un correo válido"}
}
});
var estado = validator.form();
if (estado) {
var json = {
apellidos: $('#txt_apellidos_editar').val().trim(),
nombres: $('#txt_nombres_editar').val().trim(),
edad: $('#txt_edad_editar').val().trim(),
correo: $('#txt_correo_editar').val().trim(),
codigo: codigoPersona
};
$.ajax({
type: 'POST',
url: '../PersonaServlet?accion=editarPersona',
dataType: 'json',
data: {json: JSON.stringify(json)},
beforeSend: function (xhr) {
console.log('cargando...');
},
success: function (data, textStatus, jqXHR) {
console.log(data);
var status = data.status;
if (status) {
imprimirAlerta('Correcto!', data.message, 'success');
recargarTabla();
$('#modal_editar_persona').modal('hide');
} else {
imprimirAlerta('Error!', data.message, 'error');
}
},
complete: function (jqXHR, textStatus) {
}
});
}
});
}
function listarPersona() {
var txt_criterio_busqueda = $('#txt_criterio_busqueda').val().trim();
var tabla_persona = $('#tabla_persona').DataTable({
language: {
paginate: {'next': '&rarr; ', 'previous': ' &larr;'},
emptyTable: 'No hay registros'
},
ajax: {
url: '../PersonaServlet?accion=listarPersona',
type: 'POST',
dataType: 'json',
data: {search: txt_criterio_busqueda}
},
processing: true,
serverSide: true,
responsive: true,
iDisplayLength: 10,
bSort: false,
bInfo: false,
searching: false,
bLengthChange: false,
bFilter: false,
aaSorting: [],
ordering: false,
scrollX: false,
ScrollCollapse: true,
columns: [
{data: "codigo"},
{data: "dni"},
{
data: null,
render: function (data, type, row) {
return data.apellidos + ", " + data.nombres;
}
},
{data: "edad", className: 'text-center'},
{data: "correo"},
{
data: "estado",
className: 'text-center',
render: function (data, type, row) {
return data === "1" ? '<span class="label label-success">activo</span>' : '<span class="label label-danger">inactivo</span>';
}
},
{
data: null,
className: 'text-center',
render: function (data, type, row) {
return data.estado === "1" ? '<ul class="icons-list"><li title="Editar" data-toggle="modal" data-target="#modal_editar_persona" class="text-primary-600"><a href="#" class="editarPersona"><i class="icon-pencil7"></i></a></li><li title="Desactivar" class="text-success-600"><a href="#" class="desactivarPersona"><i class="icon-switch2"></i></a></li></ul>' : '<ul class="icons-list"><li title="Editar" data-toggle="modal" data-target="#modal_editar_persona" class="text-primary-600"><a href="#" class="editarPersona"><i class="icon-pencil7"></i></a></li><li title="Activar" class="text-danger-600"><a href="#" class="activarPersona"><i class="icon-switch2"></i></a></li></ul>';
}
}
],
fnRowCallback: function (row, data, displayIndex, displayIndexFull) {
},
fnPreDrawCallback: function (settings) {
},
fnDrawCallback: function (settings) {
},
createdRow: function (row, data, dataIndex) {
},
initComplete: function (settings, json) {
}
});
}
$('#tabla_persona tbody').on('click', '.editarPersona', function () {
var data_row = $('#tabla_persona').DataTable().row($(this).parents('tr')).data();
console.log(data_row);
codigoPersona = '';
$('#txt_numero_documento_editar').val(data_row.dni);
$('#txt_apellidos_editar').val(data_row.apellidos);
$('#txt_nombres_editar').val(data_row.nombres);
$('#txt_edad_editar').val(data_row.edad);
$('#txt_correo_editar').val(data_row.correo);
codigoPersona = data_row.codigo;
});
$('#tabla_persona tbody').on('click', '.desactivarPersona', function () {
var data_row = $('#tabla_persona').DataTable().row($(this).parents('tr')).data();
var json = {
codigo: data_row.codigo
};
swal({
title: "¿Estás seguro?",
text: "¿Desea desactivar a " + data_row.apellidos + ", " + data_row.nombres + " ?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#EF5350",
confirmButtonText: "Si!",
cancelButtonText: "No!",
closeOnConfirm: false,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm) {
$.ajax({
url: '../PersonaServlet?accion=desactivarPersona',
type: 'POST',
dataType: 'json',
data: {json: JSON.stringify(json)},
beforeSend: function (xhr) {
},
success: function (data, textStatus, jqXHR) {
console.log(data);
var status = data.status;
if (status) {
imprimirAlerta('Desactivado!', data_row.apellidos + ', ' + data_row.nombres + ' fue desactivado con exito!', 'success');
recargarTabla();
} else {
imprimirAlerta('Error!', data.message, 'error');
}
}
});
}
});
});
$('#tabla_persona tbody').on('click', '.activarPersona', function () {
var data_row = $('#tabla_persona').DataTable().row($(this).parents('tr')).data();
var json = {
codigo: data_row.codigo
};
swal({
title: "¿Estás seguro?",
text: "¿Desea activar a " + data_row.apellidos + ", " + data_row.nombres + " ?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#EF5350",
confirmButtonText: "Si!",
cancelButtonText: "No!",
closeOnConfirm: false,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm) {
$.ajax({
url: '../PersonaServlet?accion=activarPersona',
type: 'POST',
dataType: 'json',
data: {json: JSON.stringify(json)},
beforeSend: function (xhr) {
},
success: function (data, textStatus, jqXHR) {
console.log(data);
var status = data.status;
if (status) {
imprimirAlerta('Activado!', data_row.apellidos + ', ' + data_row.nombres + ' fue activado con exito!', 'success');
recargarTabla();
} else {
imprimirAlerta('Error!', data.message, 'error');
}
}
});
}
});
});
function initInputs() {
var txt_correo = $('#txt_correo');
var txt_correo_editar = $('#txt_correo_editar');
txt_correo_editar.attr({
disabled: true
});
txt_correo.attr({
disabled: true
});
}
function imprimirAlerta(title, text, type) {
var s_col = "#66BB6A";
var e_col = "#EF5350";
var w_col = "#FF7043";
var btnCol;
if (type === 'error') {
btnCol = e_col;
} else if (type === 'warning') {
btnCol = w_col;
} else {
btnCol = s_col;
}
swal({
title: title,
text: text,
confirmButtonColor: btnCol,
type: type
});
}
function recargarTabla() {
$('#tabla_persona').DataTable().destroy();
listarPersona();
}
function filtrarPersona() {
// PRIMERA FORMA: CON BOTON
$('#btn_buscar_criterio').on('click', function () {
recargarTabla();
});
// SEGUNDA FORMA: MIENTRAS SE ESCRIBE
// $('#txt_criterio_busqueda').keyup(function (e) {
// recargarTabla();
// });
// TERCERA FORMA: PRESIONANDO ENTER
$('#txt_criterio_busqueda').keyup(function (e) {
if (e.keyCode === 13) {
recargarTabla();
}
});
}
function limpiarInputs() {
$('#txt_numero_documento').attr({
autofocus: true
});
$('#txt_numero_documento').val('');
$('#txt_apellidos').val('');
$('#txt_nombres').val('');
$('#txt_edad').val('');
$('#txt_correo').val('');
}
function MyValidate() {
function stripHtml(value) {
// remove html tags and space chars
return value.replace(/<.[^<>]*?>/g, ' ').replace(/&nbsp;|&#160;/gi, ' ')
// remove numbers and punctuation
.replace(/[0-9.(),;:!?%#$'"_+=\/-]*/g, '');
}
jQuery.validator.addMethod("lettersonly", function (value, element) {
return this.optional(element) || /^[a-z\s]+$/i.test(value);
}, "Solo letras.");
jQuery.validator.setDefaults({
debug: true,
ignore: 'input[type=hidden], .select2-search__field', // ignore hidden fields
errorClass: 'validation-error-label',
successClass: 'validation-valid-label',
highlight: function (element, errorClass) {
$(element).removeClass(errorClass);
},
unhighlight: function (element, errorClass) {
$(element).removeClass(errorClass);
},
// Different components require proper error label placement
errorPlacement: function (error, element) {
// Styled checkboxes, radios, bootstrap switch
if (element.parents('div').hasClass("checker") || element.parents('div').hasClass("choice") || element.parent().hasClass('bootstrap-switch-container')) {
if (element.parents('label').hasClass('checkbox-inline') || element.parents('label').hasClass('radio-inline')) {
error.appendTo(element.parent().parent().parent().parent());
} else {
error.appendTo(element.parent().parent().parent().parent().parent());
}
}
// Unstyled checkboxes, radios
else if (element.parents('div').hasClass('checkbox') || element.parents('div').hasClass('radio')) {
error.appendTo(element.parent().parent().parent());
}
// Input with icons and Select2
else if (element.parents('div').hasClass('has-feedback') || element.hasClass('select2-hidden-accessible')) {
error.appendTo(element.parent());
}
// Inline checkboxes, radios
else if (element.parents('label').hasClass('checkbox-inline') || element.parents('label').hasClass('radio-inline')) {
error.appendTo(element.parent().parent());
}
// Input group, styled file input
else if (element.parent().hasClass('uploader') || element.parents().hasClass('input-group')) {
error.appendTo(element.parent().parent());
} else {
error.insertAfter(element);
}
}
});
}
function initInputs() {
var txt_numero_documento = $('#txt_numero_documento');
var txt_apellidos = $('#txt_apellidos');
var txt_nombres = $('#txt_nombres');
var txt_edad = $('#txt_edad');
var txt_correo = $('#txt_correo');
var dominio_correo = '.TI@SACOOLIVEROS.EDU.PE';
// txt_correo.attr({
// disabled: true
// });
$(document).ready(function () {
listarPersonaTest();
initInputs();
init(); // METODOS CRUD
MyValidate();
filtrarPersona();
$('#btn_agregar_persona').on('click', function () {
limpiarInputs();
});
});
var codigoPersona;
function init() {
listarPersona();
registrarPersona();
editarPersona();
}
function listarPersonaTest() {
$.ajax({
url: '../PersonaServlet?accion=listarPersonaTest',
type: 'POST',
beforeSend: function (xhr) {
// console.log('Antes de...');
}, success: function (data, textStatus, jqXHR) {
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');
}
});
}
function registrarPersona() {
$('#btn_registrar_persona').on('click', function () {
var validator = $('#form_registrar_persona').validate({
rules: {
txt_numero_documento: {required: true, digits: true, minlength: 8, maxlength: 8},
txt_apellidos: {required: true, lettersonly: true, maxlength: 50},
txt_nombres: {required: true, lettersonly: true, maxlength: 50},
txt_edad: {required: true, digits: true, maxlength: 2},
txt_correo: {required: true, email: true, maxlength: 50}
},
messages: {
txt_numero_documento: {required: "Ingresar número de documento.", minlength: "Ingresar 8 dígitos.", maxlength: "Ingresar 8 dígitos.", digits: "Ingresar solo números."},
txt_apellidos: {required: "Ingresar apellidos.", maxlength: "Ingresar 50 letras como máximo.", lettersonly: "Ingresar solo letras"},
txt_nombres: {required: "Ingresar nombres.", maxlength: "Ingresar 50 letras como máximo.", lettersonly: "Ingresar solo letras"},
txt_edad: {required: "Ingresar edad.", maxlength: "Ingresar 2 dígitos como máximo", digits: "Ingresar solo números"},
txt_correo: {required: "Ingresar correo.", maxlength: "Ingresar 50 letras como máximo.", email: "Ingresar un correo válido"}
}
});
var estado = validator.form();
if (estado) {
var json = {
dni: $('#txt_numero_documento').val().trim(),
apellidos: $('#txt_apellidos').val().trim(),
nombres: $('#txt_nombres').val().trim(),
edad: $('#txt_edad').val().trim(),
correo: $('#txt_correo').val().trim()
};
$.ajax({
type: 'POST',
url: '../PersonaServlet?accion=registrarPersona',
dataType: 'json',
data: {json: JSON.stringify(json)},
beforeSend: function (xhr) {
console.log('cargando...');
},
success: function (data, textStatus, jqXHR) {
console.log(data);
var status = data.status;
if (status) {
imprimirAlerta('Correcto!', data.message, 'success');
// var table = $('#tabla_persona').DataTable();
// table.ajax.reload();
recargarTabla();
$('#modal_registrar_persona').modal('hide');
} else {
imprimirAlerta('Error!', data.message, 'error');
}
},
complete: function (jqXHR, textStatus) {
}
});
}
});
}
function editarPersona() {
$('#btn_editar_persona').on('click', function () {
var validator = $('#form_editar_persona').validate({
rules: {
txt_apellidos_editar: {required: true, lettersonly: true, maxlength: 50},
txt_nombres_editar: {required: true, lettersonly: true, maxlength: 50},
txt_edad_editar: {required: true, digits: true, maxlength: 2},
txt_correo_editar: {required: true, email: true, maxlength: 50}
},
messages: {
txt_apellidos_editar: {required: "Ingresar apellidos.", maxlength: "Ingresar 50 letras como máximo.", lettersonly: "Ingresar solo letras"},
txt_nombres_editar: {required: "Ingresar nombres.", maxlength: "Ingresar 50 letras como máximo.", lettersonly: "Ingresar solo letras"},
txt_edad_editar: {required: "Ingresar edad.", maxlength: "Ingresar 2 dígitos como máximo", digits: "Ingresar solo números"},
txt_correo_editar: {required: "Ingresar correo.", maxlength: "Ingresar 50 letras como máximo.", email: "Ingresar un correo válido"}
}
});
var estado = validator.form();
if (estado) {
var json = {
apellidos: $('#txt_apellidos_editar').val().trim(),
nombres: $('#txt_nombres_editar').val().trim(),
edad: $('#txt_edad_editar').val().trim(),
correo: $('#txt_correo_editar').val().trim(),
codigo: codigoPersona
};
$.ajax({
type: 'POST',
url: '../PersonaServlet?accion=editarPersona',
dataType: 'json',
data: {json: JSON.stringify(json)},
beforeSend: function (xhr) {
console.log('cargando...');
},
success: function (data, textStatus, jqXHR) {
console.log(data);
var status = data.status;
if (status) {
imprimirAlerta('Correcto!', data.message, 'success');
recargarTabla();
$('#modal_editar_persona').modal('hide');
} else {
imprimirAlerta('Error!', data.message, 'error');
}
},
complete: function (jqXHR, textStatus) {
}
});
}
});
}
function listarPersona() {
var txt_criterio_busqueda = $('#txt_criterio_busqueda').val().trim();
var tabla_persona = $('#tabla_persona').DataTable({
language: {
paginate: {'next': '&rarr; ', 'previous': ' &larr;'},
emptyTable: 'No hay registros'
},
ajax: {
url: '../PersonaServlet?accion=listarPersona',
type: 'POST',
dataType: 'json',
data: {
search: txt_criterio_busqueda
}
},
processing: true,
serverSide: true,
responsive: true,
iDisplayLength: 10,
bSort: false,
bInfo: false,
searching: false,
bLengthChange: false,
bFilter: false,
aaSorting: [],
ordering: false,
scrollX: false,
ScrollCollapse: true,
columns: [
{data: "codigo"},
{data: "dni"},
{
data: null,
render: function (data, type, row) {
return data.apellidos + ", " + data.nombres;
}
},
{data: "edad", className: 'text-center'},
{data: "correo"},
{
data: "estado",
className: 'text-center',
render: function (data, type, row) {
return data === "1" ? '<span class="label label-success">activo</span>' : '<span class="label label-danger">inactivo</span>';
}
},
{
data: null,
className: 'text-center',
render: function (data, type, row) {
return data.estado === "1" ? '<ul class="icons-list"><li title="Editar" data-toggle="modal" data-target="#modal_editar_persona" class="text-primary-600"><a href="#" class="editarPersona"><i class="icon-pencil7"></i></a></li><li title="Desactivar" class="text-success-600"><a href="#" class="desactivarPersona"><i class="icon-switch2"></i></a></li></ul>' : '<ul class="icons-list"><li title="Editar" data-toggle="modal" data-target="#modal_editar_persona" class="text-primary-600"><a href="#" class="editarPersona"><i class="icon-pencil7"></i></a></li><li title="Activar" class="text-danger-600"><a href="#" class="activarPersona"><i class="icon-switch2"></i></a></li></ul>';
}
}
],
fnRowCallback: function (row, data, displayIndex, displayIndexFull) {
},
fnPreDrawCallback: function (settings) {
},
fnDrawCallback: function (settings) {
},
createdRow: function (row, data, dataIndex) {
},
initComplete: function (settings, json) {
}
});
}
$('#tabla_persona tbody').on('click', '.editarPersona', function () {
var data_row = $('#tabla_persona').DataTable().row($(this).parents('tr')).data();
console.log(data_row);
codigoPersona = '';
$('#txt_numero_documento_editar').val(data_row.dni);
$('#txt_apellidos_editar').val(data_row.apellidos);
$('#txt_nombres_editar').val(data_row.nombres);
$('#txt_edad_editar').val(data_row.edad);
$('#txt_correo_editar').val(data_row.correo);
codigoPersona = data_row.codigo;
});
$('#tabla_persona tbody').on('click', '.desactivarPersona', function () {
var data_row = $('#tabla_persona').DataTable().row($(this).parents('tr')).data();
var json = {
codigo: data_row.codigo
};
swal({
title: "¿Estás seguro?",
text: "¿Desea desactivar a " + data_row.apellidos + ", " + data_row.nombres + " ?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#EF5350",
confirmButtonText: "Si!",
cancelButtonText: "No!",
closeOnConfirm: false,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm) {
$.ajax({
url: '../PersonaServlet?accion=desactivarPersona',
type: 'POST',
dataType: 'json',
data: {json: JSON.stringify(json)},
beforeSend: function (xhr) {
},
success: function (data, textStatus, jqXHR) {
console.log(data);
var status = data.status;
if (status) {
imprimirAlerta('Desactivado!', data_row.apellidos + ', ' + data_row.nombres + ' fue desactivado con exito!', 'success');
recargarTabla();
} else {
imprimirAlerta('Error!', data.message, 'error');
}
}
});
}
});
});
$('#tabla_persona tbody').on('click', '.activarPersona', function () {
var data_row = $('#tabla_persona').DataTable().row($(this).parents('tr')).data();
var json = {
codigo: data_row.codigo
};
swal({
title: "¿Estás seguro?",
text: "¿Desea activar a " + data_row.apellidos + ", " + data_row.nombres + " ?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#EF5350",
confirmButtonText: "Si!",
cancelButtonText: "No!",
closeOnConfirm: false,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm) {
$.ajax({
url: '../PersonaServlet?accion=activarPersona',
type: 'POST',
dataType: 'json',
data: {json: JSON.stringify(json)},
beforeSend: function (xhr) {
},
success: function (data, textStatus, jqXHR) {
console.log(data);
var status = data.status;
if (status) {
imprimirAlerta('Activado!', data_row.apellidos + ', ' + data_row.nombres + ' fue activado con exito!', 'success');
recargarTabla();
} else {
imprimirAlerta('Error!', data.message, 'error');
}
}
});
}
});
});
function initInputs() {
var txt_correo = $('#txt_correo');
var txt_correo_editar = $('#txt_correo_editar');
txt_correo_editar.attr({
disabled: true
});
txt_correo.attr({
disabled: true
});
}
function imprimirAlerta(title, text, type) {
var s_col = "#66BB6A";
var e_col = "#EF5350";
var w_col = "#FF7043";
var btnCol;
if (type === 'error') {
btnCol = e_col;
} else if (type === 'warning') {
btnCol = w_col;
} else {
btnCol = s_col;
}
swal({
title: title,
text: text,
confirmButtonColor: btnCol,
type: type
});
}
function recargarTabla() {
$('#tabla_persona').DataTable().destroy();
listarPersona();
}
function filtrarPersona() {
// PRIMERA FORMA: CON BOTON
$('#btn_buscar_criterio').on('click', function () {
recargarTabla();
});
// SEGUNDA FORMA: MIENTRAS SE ESCRIBE
// $('#txt_criterio_busqueda').keyup(function (e) {
// recargarTabla();
// });
// TERCERA FORMA: PRESIONANDO ENTER
$('#txt_criterio_busqueda').keyup(function (e) {
if (e.keyCode === 13) {
recargarTabla();
}
});
}
function limpiarInputs() {
$('#txt_numero_documento').attr({
autofocus: true
});
$('#txt_numero_documento').val('');
$('#txt_apellidos').val('');
$('#txt_nombres').val('');
$('#txt_edad').val('');
$('#txt_correo').val('');
}
function MyValidate() {
function stripHtml(value) {
// remove html tags and space chars
return value.replace(/<.[^<>]*?>/g, ' ').replace(/&nbsp;|&#160;/gi, ' ')
// remove numbers and punctuation
.replace(/[0-9.(),;:!?%#$'"_+=\/-]*/g, '');
}
jQuery.validator.addMethod("lettersonly", function (value, element) {
return this.optional(element) || /^[a-z\s]+$/i.test(value);
}, "Solo letras.");
jQuery.validator.setDefaults({
debug: true,
ignore: 'input[type=hidden], .select2-search__field', // ignore hidden fields
errorClass: 'validation-error-label',
successClass: 'validation-valid-label',
highlight: function (element, errorClass) {
$(element).removeClass(errorClass);
},
unhighlight: function (element, errorClass) {
$(element).removeClass(errorClass);
},
// Different components require proper error label placement
errorPlacement: function (error, element) {
// Styled checkboxes, radios, bootstrap switch
if (element.parents('div').hasClass("checker") || element.parents('div').hasClass("choice") || element.parent().hasClass('bootstrap-switch-container')) {
if (element.parents('label').hasClass('checkbox-inline') || element.parents('label').hasClass('radio-inline')) {
error.appendTo(element.parent().parent().parent().parent());
} else {
error.appendTo(element.parent().parent().parent().parent().parent());
}
}
// Unstyled checkboxes, radios
else if (element.parents('div').hasClass('checkbox') || element.parents('div').hasClass('radio')) {
error.appendTo(element.parent().parent().parent());
}
// Input with icons and Select2
else if (element.parents('div').hasClass('has-feedback') || element.hasClass('select2-hidden-accessible')) {
error.appendTo(element.parent());
}
// Inline checkboxes, radios
else if (element.parents('label').hasClass('checkbox-inline') || element.parents('label').hasClass('radio-inline')) {
error.appendTo(element.parent().parent());
}
// Input group, styled file input
else if (element.parent().hasClass('uploader') || element.parents().hasClass('input-group')) {
error.appendTo(element.parent().parent());
} else {
error.insertAfter(element);
}
}
});
}
function initInputs() {
var txt_numero_documento = $('#txt_numero_documento');
var txt_apellidos = $('#txt_apellidos');
var txt_nombres = $('#txt_nombres');
var txt_edad = $('#txt_edad');
var txt_correo = $('#txt_correo');
var dominio_correo = '.TI@SACOOLIVEROS.EDU.PE';
// txt_correo.attr({
// disabled: true
// });
}
\ No newline at end of file
<%--
Document : index
Created on : 05-ene-2018, 20:49:32
Author : Alonso
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@include file="templates/header.jsp" %>
<!--template-core-->
<!--css-->
<!--css-->
</head>
<body>
<%@include file="templates/header-body.jsp" %>
<!-- content -->
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-flat border-top-xlg border-top-primary">
<div class="panel-heading">
<h6 class="panel-title text-semibold"><i class="icon-cog3 position-left"></i> Mantenimiento persona</h6>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="control-label display-block">Ingresar criterio de búsqueda: </label>
<div class="input-group input-group-xlg">
<span class="input-group-addon"><i class="icon-search4"></i></span>
<input id="txt_criterio_busqueda" type="text" class="form-control" placeholder="Ingresar criterio">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<button id="btn_buscar_criterio" type="button" class="btn btn-primary"><i class="icon-search4 position-left"></i> Buscar</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-flat border-top-xlg border-top-primary">
<div class="panel-heading">
<h6 class="panel-title text-semibold"><i class=" icon-list3 position-left"></i> Listado persona</h6>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12 text-center">
<button id="btn_agregar_persona" type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal_registrar_persona"><i class="icon-plus3 position-left"></i> Agregar</button>
</div>
</div><br>
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-striped table-sm" id="tabla_persona">
<thead>
<tr>
<th>#</th>
<th>DNI</th>
<th>APELLIDOS Y NOMBRES</th>
<th>EDAD</th>
<th>CORREO ELECTRONICO</th>
<th>ESTADO</th>
<th>ACCIONES</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- / content -->
<!-- modal_registrar_persona -->
<div id="modal_registrar_persona" class="modal fade" data-backdrop="static">
<!--<div id="modal_registrar_persona">-->
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header bg-primary">
<h6 class="modal-title">Registrar persona</h6>
</div>
<div class="modal-body">
<form id="form_registrar_persona">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<!--<div class="form-group has-error has-feedback">-->
<label class="control-label display-block">Número de documento:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-vcard"></i></span>
<input id="txt_numero_documento" name="txt_numero_documento" type="text" class="form-control" placeholder="Ingresar número de documento">
</div>
<!-- <div class="form-control-feedback">
<i class="icon-cancel-circle2"></i>
</div>
<span class="help-block">Error input group helper</span>-->
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label display-block">Apellidos:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-user"></i></span>
<input id="txt_apellidos" name="txt_apellidos" type="text" class="form-control" placeholder="Ingresar apellidos">
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label display-block">Nombres:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-user"></i></span>
<input id="txt_nombres" name="txt_nombres" type="text" class="form-control" placeholder="Ingresar nombres">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="control-label display-block">Edad:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-user"></i></span>
<input id="txt_edad" name="txt_edad" type="text" class="form-control" placeholder="Ingresar edad">
</div>
</div>
</div>
<div class="col-md-8">
<div class="form-group">
<label class="control-label display-block">Correo electrónico:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-mention"></i></span>
<input id="txt_correo" name="txt_correo" type="text" class="form-control" placeholder="Ingresar correo electrónico">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<span class="text-danger pull-right">Campos obligatorios (*)</span>
</div>
</div>
</form>
</div>
<div class="modal-footer text-center">
<button id="btn_registrar_persona" type="button" class="btn btn-primary">Registrar</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>
<!-- /modal_registrar_persona -->
<!-- modal_editar_persona -->
<div id="modal_editar_persona" class="modal fade" data-backdrop="static">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header bg-primary">
<h6 class="modal-title">Editar persona</h6>
</div>
<div class="modal-body">
<form id="form_editar_persona">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="control-label display-block">Número de documento:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-vcard"></i></span>
<input disabled="disabled" id="txt_numero_documento_editar" name="txt_numero_documento_editar" type="text" class="form-control">
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label display-block">Apellidos:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-user"></i></span>
<input id="txt_apellidos_editar" name="txt_apellidos_editar" type="text" class="form-control" placeholder="Ingresar apellidos">
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label display-block">Nombres:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-user"></i></span>
<input id="txt_nombres_editar" name="txt_nombres_editar" type="text" class="form-control" placeholder="Ingresar nombres">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="control-label display-block">Edad:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-user"></i></span>
<input id="txt_edad_editar" name="txt_edad_editar" type="text" class="form-control" placeholder="Ingresar edad">
</div>
</div>
</div>
<div class="col-md-8">
<div class="form-group">
<label class="control-label display-block">Correo electrónico:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-mention"></i></span>
<input id="txt_correo_editar" name="txt_correo_editar" type="text" class="form-control" placeholder="Ingresar correo electrónico">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<span class="text-danger pull-right">Campos obligatorios (*)</span>
</div>
</div>
</form>
</div>
<div class="modal-footer text-center">
<button id="btn_editar_persona" type="button" class="btn btn-primary">Editar</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>
<!-- /modal_editar_persona -->
<%@include file="templates/footer-body.jsp" %>
<!--js plantilla-->
<!--jQueryValidator-->
<script type="text/javascript" src="../plantilla/assets/js/plugins/forms/validation/validate.min.js"></script>
<!--jQueryValidator-->
<!--form-->
<script type="text/javascript" src="../plantilla/assets/js/plugins/forms/inputs/touchspin.min.js"></script>
<script type="text/javascript" src="../plantilla/assets/js/pages/form_input_groups.js"></script>
<!--form-->
<!--modal-->
<script type="text/javascript" src="../plantilla/assets/js/pages/components_modals.js"></script>
<!--modal-->
<!--sweetalerts-->
<script type="text/javascript" src="../plantilla/assets/js/plugins/notifications/bootbox.min.js"></script>
<script type="text/javascript" src="../plantilla/assets/js/plugins/notifications/sweet_alert.min.js"></script>
<!--sweetalerts-->
<!--datatable-->
<script type="text/javascript" src="../plantilla/assets/js/plugins/tables/datatables/datatables.min.js"></script>
<script type="text/javascript" src="../plantilla/assets/js/plugins/forms/selects/select2.min.js"></script>
<!--datatable-->
<!--js plantilla-->
<!--mi js-->
<script src="../js/pages/persona.js" type="text/javascript"></script>
<!--mi js-->
</body>
</html>
<%--
Document : index
Created on : 05-ene-2018, 20:49:32
Author : Alonso
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@include file="templates/header.jsp" %>
<!--template-core-->
<!--css-->
<!--css-->
</head>
<body>
<%@include file="templates/header-body.jsp" %>
<!-- content -->
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-flat border-top-xlg border-top-primary">
<div class="panel-heading">
<h6 class="panel-title text-semibold"><i class="icon-cog3 position-left"></i> Mantenimiento persona</h6>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label class="control-label display-block">Ingresar criterio de búsqueda: </label>
<div class="input-group input-group-xlg">
<span class="input-group-addon"><i class="icon-search4"></i></span>
<input id="txt_criterio_busqueda" type="text" class="form-control" placeholder="Ingresar criterio">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<button id="btn_buscar_criterio" type="button" class="btn btn-primary"><i class="icon-search4 position-left"></i> Buscar</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="panel panel-flat border-top-xlg border-top-primary">
<div class="panel-heading">
<h6 class="panel-title text-semibold"><i class=" icon-list3 position-left"></i> Listado persona</h6>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12 text-center">
<button id="btn_agregar_persona" type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal_registrar_persona"><i class="icon-plus3 position-left"></i> Agregar</button>
</div>
</div><br>
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-striped table-sm" id="tabla_persona">
<thead>
<tr>
<th>#</th>
<th>DNI</th>
<th>APELLIDOS Y NOMBRES</th>
<th>EDAD</th>
<th>CORREO ELECTRONICO</th>
<th>ESTADO</th>
<th>ACCIONES</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- / content -->
<!-- modal_registrar_persona -->
<div id="modal_registrar_persona" class="modal fade" data-backdrop="static">
<!--<div id="modal_registrar_persona">-->
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header bg-primary">
<h6 class="modal-title">Registrar persona</h6>
</div>
<div class="modal-body">
<form id="form_registrar_persona">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="control-label display-block">Número de documento:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-vcard"></i></span>
<input id="txt_numero_documento" name="txt_numero_documento" type="text" class="form-control" placeholder="Ingresar número de documento">
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label display-block">Apellidos:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-user"></i></span>
<input id="txt_apellidos" name="txt_apellidos" type="text" class="form-control" placeholder="Ingresar apellidos">
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label display-block">Nombres:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-user"></i></span>
<input id="txt_nombres" name="txt_nombres" type="text" class="form-control" placeholder="Ingresar nombres">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="control-label display-block">Edad:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-user"></i></span>
<input id="txt_edad" name="txt_edad" type="text" class="form-control" placeholder="Ingresar edad">
</div>
</div>
</div>
<div class="col-md-8">
<div class="form-group">
<label class="control-label display-block">Correo electrónico:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-mention"></i></span>
<input id="txt_correo" name="txt_correo" type="text" class="form-control" placeholder="Ingresar correo electrónico">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<span class="text-danger pull-right">Campos obligatorios (*)</span>
</div>
</div>
</form>
</div>
<div class="modal-footer text-center">
<button id="btn_registrar_persona" type="button" class="btn btn-primary">Registrar</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>
<!-- /modal_registrar_persona -->
<!-- modal_editar_persona -->
<div id="modal_editar_persona" class="modal fade" data-backdrop="static">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header bg-primary">
<h6 class="modal-title">Editar persona</h6>
</div>
<div class="modal-body">
<form id="form_editar_persona">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="control-label display-block">Número de documento:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-vcard"></i></span>
<input disabled="disabled" id="txt_numero_documento_editar" name="txt_numero_documento_editar" type="text" class="form-control">
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label display-block">Apellidos:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-user"></i></span>
<input id="txt_apellidos_editar" name="txt_apellidos_editar" type="text" class="form-control" placeholder="Ingresar apellidos">
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label display-block">Nombres:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-user"></i></span>
<input id="txt_nombres_editar" name="txt_nombres_editar" type="text" class="form-control" placeholder="Ingresar nombres">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="control-label display-block">Edad:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-user"></i></span>
<input id="txt_edad_editar" name="txt_edad_editar" type="text" class="form-control" placeholder="Ingresar edad">
</div>
</div>
</div>
<div class="col-md-8">
<div class="form-group">
<label class="control-label display-block">Correo electrónico:<span class="text-danger"> (*)</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="icon-mention"></i></span>
<input id="txt_correo_editar" name="txt_correo_editar" type="text" class="form-control" placeholder="Ingresar correo electrónico">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<span class="text-danger pull-right">Campos obligatorios (*)</span>
</div>
</div>
</form>
</div>
<div class="modal-footer text-center">
<button id="btn_editar_persona" type="button" class="btn btn-primary">Editar</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
</div>
</div>
</div>
</div>
<!-- /modal_editar_persona -->
<%@include file="templates/footer-body.jsp" %>
<!--js plantilla-->
<!--jQueryValidator-->
<script type="text/javascript" src="../plantilla/assets/js/plugins/forms/validation/validate.min.js"></script>
<!--jQueryValidator-->
<!--form-->
<script type="text/javascript" src="../plantilla/assets/js/plugins/forms/inputs/touchspin.min.js"></script>
<script type="text/javascript" src="../plantilla/assets/js/pages/form_input_groups.js"></script>
<!--form-->
<!--modal-->
<script type="text/javascript" src="../plantilla/assets/js/pages/components_modals.js"></script>
<!--modal-->
<!--sweetalerts-->
<script type="text/javascript" src="../plantilla/assets/js/plugins/notifications/bootbox.min.js"></script>
<script type="text/javascript" src="../plantilla/assets/js/plugins/notifications/sweet_alert.min.js"></script>
<!--sweetalerts-->
<!--datatable-->
<script type="text/javascript" src="../plantilla/assets/js/plugins/tables/datatables/datatables.min.js"></script>
<script type="text/javascript" src="../plantilla/assets/js/plugins/forms/selects/select2.min.js"></script>
<!--datatable-->
<!--js plantilla-->
<!--mi js-->
<script src="../js/pages/persona.js" type="text/javascript"></script>
<!--mi js-->
</body>
</html>
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