Post on 03-Jun-2018
8/11/2019 Java Practicas y Sustentacion
1/158
8/11/2019 Java Practicas y Sustentacion
2/158
private JPanel contentPane;
private JTextField txt_id;
private JPasswordField txt_clave;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FrmAutenticacionUsuario frame = new
FrmAutenticacionUsuario();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public FrmAutenticacionUsuario() {
8/11/2019 Java Practicas y Sustentacion
3/158
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 385, 154);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNewLabel = new JLabel("Usuario:");
lblNewLabel.setBounds(50, 27, 77, 14);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("Clave:");
lblNewLabel_1.setBounds(50, 52, 46, 14);
contentPane.add(lblNewLabel_1);
txt_id = new JTextField();
txt_id.setBounds(125, 24, 221, 20);
contentPane.add(txt_id);
txt_id.setColumns(10);
txt_clave = new JPasswordField();
txt_clave.setBounds(125, 52, 221, 20);
contentPane.add(txt_clave);
JButton btnNewButton = new JButton("Ingresar");
8/11/2019 Java Practicas y Sustentacion
4/158
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
validarUsuario();
}
});
btnNewButton.setBounds(135, 82, 89, 23);
contentPane.add(btnNewButton);
}
public void validarUsuario(){
String id = this.txt_id.getText();
String clave = String.valueOf(this.txt_clave.getPassword());
Usuario u = new Usuario();
u.setId(id);
u.setClave(clave);
Conexion c = new Conexion();
try{
c.conectar();
if(c.esUsuarioValido(u)){
FrmPrincipal frm = new FrmPrincipal();
frm.setVisible(true);
this.dispose();
}else{
System.out.println("INVLIDO");
}
8/11/2019 Java Practicas y Sustentacion
5/158
}catch(Exception e){
System.out.println("Ocurri un error");
}
}
}
8/11/2019 Java Practicas y Sustentacion
6/158
package formularios;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class FrmMantenimientoPersona extends JFrame {
private JPanel contentPane;
private JTable table;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FrmMantenimientoPersona frame = new
FrmMantenimientoPersona();
8/11/2019 Java Practicas y Sustentacion
7/158
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public FrmMantenimientoPersona() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(57, 26, 316, 178);
contentPane.add(scrollPane);
table = new JTable();
table.setModel(new DefaultTableModel(
8/11/2019 Java Practicas y Sustentacion
8/158
new Object[][] {
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
},
new String[] {
"New column", "New column", "New column", "New column", "New
column"
}
));
scrollPane.setViewportView(table);
}
8/11/2019 Java Practicas y Sustentacion
9/158
}
8/11/2019 Java Practicas y Sustentacion
10/158
package formularios;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
public class FrmPrincipal extends JFrame {
private JPanel contentPane;
/**
* Create the frame.
*/
public FrmPrincipal() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
JMenuBar menuBar = new JMenuBar();
8/11/2019 Java Practicas y Sustentacion
11/158
setJMenuBar(menuBar);
JMenu mnInicio = new JMenu("Inicio");
menuBar.add(mnInicio);
JMenuItem mntmMiCuenta = new JMenuItem("Mi cuenta");
mnInicio.add(mntmMiCuenta);
JMenuItem mntmNewMenuItem = new JMenuItem("Cerrar sesi\u00F3n");
mnInicio.add(mntmNewMenuItem);
JMenuItem mntmNewMenuItem_1 = new JMenuItem("Salir");
mnInicio.add(mntmNewMenuItem_1);
JMenu mnMantenimiento = new JMenu("Mantenimiento");
menuBar.add(mnMantenimiento);
JMenuItem mntmNewMenuItem_2 = new JMenuItem("Cliente");
mnMantenimiento.add(mntmNewMenuItem_2);
JMenuItem mntmNewMenuItem_3 = new JMenuItem("Producto");
mnMantenimiento.add(mntmNewMenuItem_3);
JMenuItem mntmNewMenuItem_4 = new JMenuItem("Usuario");
mnMantenimiento.add(mntmNewMenuItem_4);
8/11/2019 Java Practicas y Sustentacion
12/158
JMenu mnProcesos = new JMenu("Procesos");
menuBar.add(mnProcesos);
JMenu mnAcercaDe = new JMenu("Acerca de..");
menuBar.add(mnAcercaDe);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
}
}
8/11/2019 Java Practicas y Sustentacion
13/158
package entidades;
public class Usuario {
private String id;
private String clave;
private char rol;
private char estado;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getClave() {
return clave;
}
public void setClave(String clave) {
this.clave = clave;
}
public char getRol() {
return rol;
}
public void setRol(char rol) {
8/11/2019 Java Practicas y Sustentacion
14/158
this.rol = rol;
}
public char getEstado() {
return estado;
}
public void setEstado(char estado) {
this.estado = estado;
}
8/11/2019 Java Practicas y Sustentacion
15/158
PRACTICA 2
package general;
import java.util.ArrayList;
import java.util.Scanner;
import bd.*;
import entidades.*;
public class Principal {
public static void main(String args[]){
System.out.println("Prctica SQL");
//INGRESO
/*
Conexion c = new Conexion();
try{
c.conectar();
Scanner sc = new Scanner(System.in);
System.out.print("CDULA:");
String cedula = sc.nextLine();
System.out.print("NOMBRES:");
String nombres = sc.nextLine();
System.out.print("APELLIDOS:");
String apellidos = sc.nextLine();
8/11/2019 Java Practicas y Sustentacion
16/158
System.out.print("EDAD:");
int edad = sc.nextInt();
Persona p = new Persona(cedula,nombres,apellidos,edad);
if(c.ingresarPersona(p)){
System.out.println("Se ingres el registro");
}else{
System.out.println("Ocurri un error en el ingreso");
}
}catch(Exception e){
System.out.println("Error en la conexin");
}
c.desconectar();
*/
//CONSULTA
/*
Conexion c = new Conexion();
try{
c.conectar();
Scanner sc = new Scanner(System.in);
System.out.print("TIPO:");
String tipo = sc.nextLine();
System.out.print("DESCRIPCIN:");
String descripcion = sc.nextLine();
8/11/2019 Java Practicas y Sustentacion
17/158
ArrayList personas = c.consultarPersonas(descripcion,tipo);
for(int i=0;i
8/11/2019 Java Practicas y Sustentacion
18/158
Persona p = new Persona(cedula,nombres,apellidos,edad);
if(c.modificarPersona(p)){
System.out.println("Se modific el registro");
}else{
System.out.println("Ocurri un error en la
modificacin");
}
}catch(Exception e){
System.out.println("Error en la conexin");
}
c.desconectar();
*/
Conexion c = new Conexion();
try{
c.conectar();
Scanner sc = new Scanner(System.in);
System.out.print("CDULA:");
String cedula = sc.nextLine();
Persona p = new Persona();
p.setCedula(cedula);
if(c.eliminarPersona(p)){
System.out.println("Se elimin el registro");
8/11/2019 Java Practicas y Sustentacion
19/158
}else{
System.out.println("Ocurri un error en la eliminacin");
}
}catch(Exception e){
System.out.println("Error en la conexin");
}
c.desconectar();
}
}
8/11/2019 Java Practicas y Sustentacion
20/158
package entidades;
public class Persona {
private String cedula;
private String nombres;
private String apellidos;
private int edad;
public Persona(){}
public Persona(String cedula, String nombres, String apellidos, int edad) {
super();
this.cedula = cedula;
this.nombres = nombres;
this.apellidos = apellidos;
this.edad = edad;
}
public String getCedula() {
return cedula;
}
public void setCedula(String cedula) {
this.cedula = cedula;
}
public String getNombres() {
8/11/2019 Java Practicas y Sustentacion
21/158
return nombres;
}
public void setNombres(String nombres) {
this.nombres = nombres;
}
public String getApellidos() {
return apellidos;
}
public void setApellidos(String apellidos) {
this.apellidos = apellidos;
}
public int getEdad() {
return edad;
}
public void setEdad(int edad) {
this.edad = edad;
}
public void imprimirInfo(){
System.out.println("CEDULA:"+cedula);
System.out.println("NOMBRES:"+nombres);
System.out.println("APELLIDOS:"+apellidos);
System.out.println("EDAD:"+edad);
}
8/11/2019 Java Practicas y Sustentacion
22/158
}
8/11/2019 Java Practicas y Sustentacion
23/158
package entidades;
public class Usuario {
private String id;
private String clave;
private char rol;
private char estado;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getClave() {
return clave;
}
public void setClave(String clave) {
this.clave = clave;
}
public char getRol() {
return rol;
}
public void setRol(char rol) {
this.rol = rol;
8/11/2019 Java Practicas y Sustentacion
24/158
}
public char getEstado() {
return estado;
}
public void setEstado(char estado) {
this.estado = estado;
}
}
8/11/2019 Java Practicas y Sustentacion
25/158
PRACTICA 3
package general;
import formularios.FrmPrincipal;
public class Principal {
public static void main(String args[]){
FrmPrincipal frm = new FrmPrincipal();
frm.setVisible(true);
}
}
8/11/2019 Java Practicas y Sustentacion
26/158
package formularios;
import java.awt.BorderLayout;
import db.*;
import entidades.*;
import java.util.ArrayList;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JLabel;
public class FrmPrincipal extends JFrame {
private JPanel contentPane;
private JTextField txt_codigo;
8/11/2019 Java Practicas y Sustentacion
27/158
private JTextField txt_id_cliente;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FrmPrincipal frame = new FrmPrincipal();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public FrmPrincipal() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 365, 157);
contentPane = new JPanel();
8/11/2019 Java Practicas y Sustentacion
28/158
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnNewButton = new JButton("Realizar Venta");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
realizarVenta();
}
});
btnNewButton.setBounds(109, 65, 118, 23);
contentPane.add(btnNewButton);
txt_codigo = new JTextField();
txt_codigo.setBounds(92, 11, 38, 20);
contentPane.add(txt_codigo);
txt_codigo.setColumns(10);
txt_id_cliente = new JTextField();
txt_id_cliente.setBounds(229, 11, 58, 20);
contentPane.add(txt_id_cliente);
txt_id_cliente.setColumns(10);
JLabel lblIdVenta = new JLabel("COD. FACTURA");
lblIdVenta.setBounds(10, 14, 72, 14);
8/11/2019 Java Practicas y Sustentacion
29/158
contentPane.add(lblIdVenta);
JLabel lblNewLabel = new JLabel("ID CLIENTE");
lblNewLabel.setBounds(154, 14, 65, 14);
contentPane.add(lblNewLabel);
}
private void realizarVenta(){
String codigo = this.txt_codigo.getText();
int id_cliente = Integer.parseInt(this.txt_id_cliente.getText());
Conexion c = new Conexion();
try{
c.conectar();
Factura f = new Factura();
f.setCodigo(codigo);
f.setId_cliente(id_cliente);
f.setTotal(100.0F);
Detalle_Factura df = new Detalle_Factura();
df.setId_producto(1);
df.setCantidad(1);
df.setPrecio(10.0F);
df.setTotal(10.0F);
8/11/2019 Java Practicas y Sustentacion
30/158
Detalle_Factura df2 = new Detalle_Factura();
df2.setId_producto(2);
df2.setCantidad(1);
df2.setPrecio(12.35F);
df2.setTotal(12.35F);
ArrayList d = new ArrayList();
d.add(df);
d.add(df2);
if(c.procesarVenta(f,d)){
JOptionPane.showMessageDialog(rootPane,"SE REALIZO LA VENTA CON XITO", "XITO",
JOptionPane.INFORMATION_MESSAGE);
}else{
JOptionPane.showMessageDialog(rootPane,"OCURRI UN ERROR EN LA VENTA",
"ERROR", JOptionPane.ERROR_MESSAGE);
}
}catch(Exception e){
JOptionPane.showMessageDialog(rootPane,"OCURRI UN ERROR EN LA CONEXIN",
"ERROR", JOptionPane.ERROR_MESSAGE);
}
c.desconectar();
}
}
8/11/2019 Java Practicas y Sustentacion
31/158
8/11/2019 Java Practicas y Sustentacion
32/158
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package entidades;
/**
*
* @author VR
*/
public class Cliente {
private int id_cliente;
private String identificacion;
private String nombre;
private String direccion;
private String telefono;
public Cliente(int id_cliente, String identificacion, String nombre, String direccion, String telefono) {
this.id_cliente = id_cliente;
this.identificacion = identificacion;
this.nombre = nombre;
this.direccion = direccion;
this.telefono = telefono;
}
8/11/2019 Java Practicas y Sustentacion
33/158
public Cliente() {
}
/**
* @return the id_cliente
*/
public int getId_cliente() {
return id_cliente;
}
/**
* @param id_cliente the id_cliente to set
*/
public void setId_cliente(int id_cliente) {
this.id_cliente = id_cliente;
}
/**
* @return the identificacion
*/
public String getIdentificacion() {
return identificacion;
}
/**
8/11/2019 Java Practicas y Sustentacion
34/158
* @param identificacion the identificacion to set
*/
public void setIdentificacion(String identificacion) {
this.identificacion = identificacion;
}
/**
* @return the nombre
*/
public String getNombre() {
return nombre;
}
/**
* @param nombre the nombre to set
*/
public void setNombre(String nombre) {
this.nombre = nombre;
}
/**
* @return the direccion
*/
public String getDireccion() {
return direccion;
8/11/2019 Java Practicas y Sustentacion
35/158
}
/**
* @param direccion the direccion to set
*/
public void setDireccion(String direccion) {
this.direccion = direccion;
}
/**
* @return the telefono
*/
public String getTelefono() {
return telefono;
}
/**
* @param telefono the telefono to set
*/
public void setTelefono(String telefono) {
this.telefono = telefono;
}
}
8/11/2019 Java Practicas y Sustentacion
36/158
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package entidades;
/**
*
* @author VR
*/
public class Detalle_Factura {
private int id_det_factura;
private int id_factura;
private int id_producto;
private int cantidad;
private float precio;
private float total;
public Detalle_Factura(int id_det_factura, int id_factura, int id_producto, int cantidad, float precio,
float total) {
this.id_det_factura = id_det_factura;
this.id_factura = id_factura;
this.id_producto = id_producto;
this.cantidad = cantidad;
this.precio = precio;
this.total = total;
8/11/2019 Java Practicas y Sustentacion
37/158
}
public Detalle_Factura() {
}
/**
* @return the id_det_factura
*/
public int getId_det_factura() {
return id_det_factura;
}
/**
* @param id_det_factura the id_det_factura to set
*/
public void setId_det_factura(int id_det_factura) {
this.id_det_factura = id_det_factura;
}
/**
* @return the id_factura
*/
public int getId_factura() {
8/11/2019 Java Practicas y Sustentacion
38/158
return id_factura;
}
/**
* @param id_factura the id_factura to set
*/
public void setId_factura(int id_factura) {
this.id_factura = id_factura;
}
/**
* @return the id_producto
*/
public int getId_producto() {
return id_producto;
}
/**
* @param id_producto the id_producto to set
*/
public void setId_producto(int id_producto) {
this.id_producto = id_producto;
}
/**
8/11/2019 Java Practicas y Sustentacion
39/158
* @return the cantidad
*/
public int getCantidad() {
return cantidad;
}
/**
* @param cantidad the cantidad to set
*/
public void setCantidad(int cantidad) {
this.cantidad = cantidad;
}
/**
* @return the precio
*/
public float getPrecio() {
return precio;
}
/**
* @param precio the precio to set
*/
public void setPrecio(float precio) {
this.precio = precio;
8/11/2019 Java Practicas y Sustentacion
40/158
}
/**
* @return the total
*/
public float getTotal() {
return total;
}
/**
* @param total the total to set
*/
public void setTotal(float total) {
this.total = total;
}
}
8/11/2019 Java Practicas y Sustentacion
41/158
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package entidades;
import java.util.Date;
/**
*
* @author VR
*/
public class Factura {
private int id_factura;
private String codigo;
private int id_cliente;
private Date fecha;
private float total;
public Factura() {
}
public Factura(int id_factura, String codigo, int id_cliente, Date fecha, float total) {
this.id_factura = id_factura;
this.codigo = codigo;
8/11/2019 Java Practicas y Sustentacion
42/158
8/11/2019 Java Practicas y Sustentacion
43/158
/**
* @param codigo the codigo to set
*/
public void setCodigo(String codigo) {
this.codigo = codigo;
}
/**
* @return the id_cliente
*/
public int getId_cliente() {
return id_cliente;
}
/**
* @param id_cliente the id_cliente to set
*/
public void setId_cliente(int id_cliente) {
this.id_cliente = id_cliente;
}
/**
* @return the fecha
*/
8/11/2019 Java Practicas y Sustentacion
44/158
public Date getFecha() {
return fecha;
}
/**
* @param fecha the fecha to set
*/
public void setFecha(Date fecha) {
this.fecha = fecha;
}
/**
* @return the total
*/
public float getTotal() {
return total;
}
/**
* @param total the total to set
*/
public void setTotal(float total) {
this.total = total;
}
}
8/11/2019 Java Practicas y Sustentacion
45/158
8/11/2019 Java Practicas y Sustentacion
46/158
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package entidades;
import java.util.ArrayList;
/**
*
* @author VR
*/
public class Producto {
private int id_producto;
private String nombre;
private String descripcion;
private int stock;
private float precio;
public Producto() {
}
public Producto(int id_producto, String nombre, String descripcion, int stock, float precio) {
this.id_producto = id_producto;
this.nombre = nombre;
8/11/2019 Java Practicas y Sustentacion
47/158
this.descripcion = descripcion;
this.stock = stock;
this.precio = precio;
}
/**
* @return the id_producto
*/
public int getId_producto() {
return id_producto;
}
/**
* @param id_producto the id_producto to set
*/
public void setId_producto(int id_producto) {
this.id_producto = id_producto;
}
/**
* @return the nombre
*/
public String getNombre() {
8/11/2019 Java Practicas y Sustentacion
48/158
return nombre;
}
/**
* @param nombre the nombre to set
*/
public void setNombre(String nombre) {
this.nombre = nombre;
}
/**
* @return the descripcion
*/
public String getDescripcion() {
return descripcion;
}
/**
* @param descripcion the descripcion to set
*/
public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}
/**
8/11/2019 Java Practicas y Sustentacion
49/158
* @return the stock
*/
public int getStock() {
return stock;
}
/**
* @param stock the stock to set
*/
public void setStock(int stock) {
this.stock = stock;
}
/**
* @return the precio
*/
public float getPrecio() {
return precio;
}
/**
* @param precio the precio to set
*/
public void setPrecio(float precio) {
this.precio = precio;
8/11/2019 Java Practicas y Sustentacion
50/158
}
public static Producto obtenerProductoPorId(ArrayList productos, int id_producto){
for(int i=0; i
8/11/2019 Java Practicas y Sustentacion
51/158
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package entidades;
/**
*
* @author VR
*/
public class Usuario {
private String id_usuario;
private String clave;
private String nombres;
private String apellidos;
private char tipo;
private char estado;
public Usuario(){}
public Usuario(String id_usuario, String nombres, String apellidos, char tipo, char estado) {
this.id_usuario = id_usuario;
this.nombres = nombres;
this.apellidos = apellidos;
this.tipo = tipo;
8/11/2019 Java Practicas y Sustentacion
52/158
this.estado = estado;
}
public Usuario(String id_usuario, String clave, String nombres, String apellidos, char tipo, char estado){
this.id_usuario = id_usuario;
this.clave = clave;
this.nombres = nombres;
this.apellidos = apellidos;
this.tipo = tipo;
this.estado = estado;
}
/**
* @return the id_usuario
*/
public String getId_usuario() {
return id_usuario;
}
/**
* @param id_usuario the id_usuario to set
*/
public void setId_usuario(String id_usuario) {
this.id_usuario = id_usuario;
}
8/11/2019 Java Practicas y Sustentacion
53/158
/**
* @return the clave
*/
public String getClave() {
return clave;
}
/**
* @param clave the clave to set
*/
public void setClave(String clave) {
this.clave = clave;
}
/**
* @return the nombres
*/
public String getNombres() {
return nombres;
}
/**
* @param nombres the nombres to set
*/
8/11/2019 Java Practicas y Sustentacion
54/158
public void setNombres(String nombres) {
this.nombres = nombres;
}
/**
* @return the apellidos
*/
public String getApellidos() {
return apellidos;
}
/**
* @param apellidos the apellidos to set
*/
public void setApellidos(String apellidos) {
this.apellidos = apellidos;
}
/**
* @return the tipo
*/
public char getTipo() {
return tipo;
}
8/11/2019 Java Practicas y Sustentacion
55/158
8/11/2019 Java Practicas y Sustentacion
56/158
SUSTENTACION Y PROYECTO
package general;
import formularios.FrmInicio;
public class Principal {
public static void main(String args[]){
FrmInicio nuevo=new FrmInicio();
nuevo.setVisible(true);
}
}
8/11/2019 Java Practicas y Sustentacion
57/158
package entidades;
public class Usuario {
private String id;
private String nombres;
private String apellidos;
private String clave;
private char rol;
private char estado;
private String cntCorreo;
private String cntFacebook;
private String telMovil;
private String fecha_reg;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getNombres() {
return nombres;
}
public void setNombres(String nombres) {
this.nombres = nombres;
8/11/2019 Java Practicas y Sustentacion
58/158
}
public String getApellidos() {
return apellidos;
}
public void setApellidos(String apellidos) {
this.apellidos = apellidos;
}
public String getClave() {
return clave;
}
public void setClave(String clave) {
this.clave = clave;
}
public char getRol() {
return rol;
}
public void setRol(char rol) {
this.rol = rol;
}
public char getEstado() {
return estado;
}
public void setEstado(char estado) {
this.estado = estado;
}
8/11/2019 Java Practicas y Sustentacion
59/158
public String getCntCorreo() {
return cntCorreo;
}
public void setCntCorreo(String cntCorreo) {
this.cntCorreo = cntCorreo;
}
public String getCntFacebook() {
return cntFacebook;
}
public void setCntFacebook(String cntFacebook) {
this.cntFacebook = cntFacebook;
}
public String getTelMovil() {
return telMovil;
}
public void setTelMovil(String telMovil) {
this.telMovil = telMovil;
}
public String getFecha_reg() {
return fecha_reg;
}
public void setFecha_reg(String fecha_reg) {
this.fecha_reg = fecha_reg;
}
8/11/2019 Java Practicas y Sustentacion
60/158
public Usuario(String id, String nombres, String apellidos,String clave, char rol, char estado,
String cntCorreo, String cntFacebook, String telMovil){
this.id=id;
this.nombres=nombres;
this.apellidos=apellidos;
this.clave=clave;
this.rol=rol;
this.estado=estado;
this.cntCorreo=cntCorreo;
this.cntFacebook=cntFacebook;
this.telMovil=telMovil;
}
public Usuario(String id, String nombres, String apellidos,String clave, char rol, char estado,
String cntCorreo, String cntFacebook, String telMovil, String fecha_reg){
this.id=id;
this.nombres=nombres;
this.apellidos=apellidos;
this.clave=clave;
this.rol=rol;
this.estado=estado;
this.cntCorreo=cntCorreo;
this.cntFacebook=cntFacebook;
this.telMovil=telMovil;
this.fecha_reg=fecha_reg;
}
8/11/2019 Java Practicas y Sustentacion
61/158
public Usuario(String id, String nombres, String apellidos, char rol, char estado, String cntCorreo,
String cntFacebook, String telMovil){
this.id=id;
this.nombres=nombres;
this.apellidos=apellidos;
this.rol=rol;
this.estado=estado;
this.cntCorreo=cntCorreo;
this.cntFacebook=cntFacebook;
this.telMovil=telMovil;
}
public Usuario(String id, String nombres, String apellidos, String cntCorreo, String cntFacebook,
String telMovil){
this.id=id;
this.nombres=nombres;
this.apellidos=apellidos;
this.cntCorreo=cntCorreo;
this.cntFacebook=cntFacebook;
this.telMovil=telMovil;
}
public Usuario(){
}
8/11/2019 Java Practicas y Sustentacion
62/158
}
8/11/2019 Java Practicas y Sustentacion
63/158
package entidades;
public class Tipo {
private int id;
private String nombre;
private int tiempoMeses;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public int getTiempoMeses() {
return tiempoMeses;
}
public void setTiempoMeses(int tiempoMeses) {
this.tiempoMeses = tiempoMeses;
}
8/11/2019 Java Practicas y Sustentacion
64/158
8/11/2019 Java Practicas y Sustentacion
65/158
package entidades;
public class Evento {
private int id;
private String nombre;
private String descripcion;
private String relevancia;
private String fecha;
private String idUsuario;
private int idTipo;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getDescripcion() {
return descripcion;
8/11/2019 Java Practicas y Sustentacion
66/158
}
public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}
public String getRelevancia() {
return relevancia;
}
public void setRelevancia(String relevancia) {
this.relevancia = relevancia;
}
public String getFecha() {
return fecha;
}
public void setFecha(String fecha) {
this.fecha = fecha;
}
public String getIdUsuario() {
return idUsuario;
}
public void setIdUsuario(String idUsuario) {
this.idUsuario = idUsuario;
}
public int getIdTipo() {
return idTipo;
}
8/11/2019 Java Practicas y Sustentacion
67/158
public void setIdTipo(int idTipo) {
this.idTipo = idTipo;
}
public Evento(String nombre, String descripcion, String relevancia,String idUsuario, int idTipo){
this.nombre=nombre;
this.descripcion=descripcion;
this.relevancia=relevancia;
this.idUsuario=idUsuario;
this.idTipo=idTipo;
}
public Evento(String nombre, String descripcion, String relevancia,String idUsuario, int idTipo,
String fecha){
this.nombre=nombre;
this.descripcion=descripcion;
this.relevancia=relevancia;
this.idUsuario=idUsuario;
this.idTipo=idTipo;
this.fecha=fecha;
}
public Evento(int idEvento,String nombre, String descripcion, String relevancia,String idUsuario,
int idTipo,String fecha){
this.id=idEvento;
this.nombre=nombre;
8/11/2019 Java Practicas y Sustentacion
68/158
8/11/2019 Java Practicas y Sustentacion
69/158
package formularios;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JButton;
import db.Conexion;
import entidades.Usuario;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.awt.Color;
public class FrmUser extends JFrame {
private JPanel contentPane;
private Usuario datos=new Usuario();
private String estado;
private String rol;
8/11/2019 Java Practicas y Sustentacion
70/158
/**
* Launch the application.
*/
/**
* Create the frame.
*/
public FrmUser() {
setForeground(new Color(255, 255, 255));
setBackground(new Color(105, 105, 105));
setTitle("Informacion Usuario");
obtenerDatos();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 520, 500);
contentPane = new JPanel();
contentPane.setBackground(new Color(211, 211, 211));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblUsuario = new JLabel(datos.getId());
lblUsuario.setBounds(212, 12, 262, 15);
contentPane.add(lblUsuario);
8/11/2019 Java Practicas y Sustentacion
71/158
JLabel lblContrasena = new JLabel("********");
lblContrasena.setBounds(212, 62, 93, 15);
contentPane.add(lblContrasena);
JLabel lblNombres = new JLabel(datos.getNombres());
lblNombres.setBounds(222, 101, 252, 15);
contentPane.add(lblNombres);
JLabel lblApellidos = new JLabel(datos.getApellidos());
lblApellidos.setBounds(222, 143, 252, 15);
contentPane.add(lblApellidos);
JLabel lblRol = new JLabel(rol);
lblRol.setBounds(222, 183, 252, 15);
contentPane.add(lblRol);
JLabel lblEstado = new JLabel(estado);
lblEstado.setBounds(222, 216, 252, 15);
contentPane.add(lblEstado);
JLabel lblCorreo = new JLabel(datos.getCntCorreo());
lblCorreo.setBounds(222, 249, 262, 15);
contentPane.add(lblCorreo);
8/11/2019 Java Practicas y Sustentacion
72/158
JLabel lblTelefonoMovil = new JLabel(datos.getTelMovil());
lblTelefonoMovil.setBounds(222, 283, 262, 15);
contentPane.add(lblTelefonoMovil);
JLabel lblFacebook = new JLabel(datos.getCntFacebook());
lblFacebook.setBounds(222, 310, 262, 15);
contentPane.add(lblFacebook);
JButton btnCambiar = new JButton("Cambiar");
btnCambiar.setBackground(new Color(143, 188, 143));
btnCambiar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FrmClave nueva= new FrmClave();
nueva.setVisible(true);
}
});
btnCambiar.setBounds(323, 57, 98, 25);
contentPane.add(btnCambiar);
JButton btnEditar = new JButton("Editar");
btnEditar.setBackground(new Color(218, 165, 32));
btnEditar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FrmEditarUserBasico nuevo= new FrmEditarUserBasico();
nuevo.setVisible(true);
8/11/2019 Java Practicas y Sustentacion
73/158
dispose();
}
});
btnEditar.setBounds(92, 390, 117, 53);
contentPane.add(btnEditar);
JButton btnAceptar = new JButton("Aceptar");
btnAceptar.setBackground(new Color(176, 196, 222));
btnAceptar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
dispose();
}
});
btnAceptar.setBounds(323, 390, 117, 53);
contentPane.add(btnAceptar);
JLabel lblUsuario_1 = new JLabel("Usuario:");
lblUsuario_1.setBounds(110, 12, 70, 15);
contentPane.add(lblUsuario_1);
JLabel lblContrasena_1 = new JLabel("Contrasena:");
lblContrasena_1.setBounds(92, 62, 88, 15);
contentPane.add(lblContrasena_1);
JLabel lblNombres_1 = new JLabel("Nombres:");
8/11/2019 Java Practicas y Sustentacion
74/158
lblNombres_1.setBounds(110, 101, 70, 15);
contentPane.add(lblNombres_1);
JLabel lblApellidos_1 = new JLabel("Apellidos:");
lblApellidos_1.setBounds(110, 143, 70, 15);
contentPane.add(lblApellidos_1);
JLabel lblRol_1 = new JLabel("Rol:");
lblRol_1.setBounds(153, 183, 70, 15);
contentPane.add(lblRol_1);
JLabel lblEstado_1 = new JLabel("Estado:");
lblEstado_1.setBounds(131, 216, 70, 15);
contentPane.add(lblEstado_1);
JLabel lblCorreo_1 = new JLabel("Correo:");
lblCorreo_1.setBounds(131, 249, 70, 15);
contentPane.add(lblCorreo_1);
JLabel lblTelefonoMovil_1 = new JLabel("Telefono Movil:");
lblTelefonoMovil_1.setBounds(75, 283, 117, 15);
contentPane.add(lblTelefonoMovil_1);
JLabel lblCuentaFacebook = new JLabel("Cuenta Facebook:");
lblCuentaFacebook.setBounds(50, 310, 142, 15);
8/11/2019 Java Practicas y Sustentacion
75/158
contentPane.add(lblCuentaFacebook);
JLabel lblFecharegistro = new JLabel(datos.getFecha_reg());
lblFecharegistro.setBounds(222, 348, 262, 15);
contentPane.add(lblFecharegistro);
JLabel lblFechaDeRegistro = new JLabel("Fecha de Registro:");
lblFechaDeRegistro.setBounds(50, 348, 142, 15);
contentPane.add(lblFechaDeRegistro);
}
public void obtenerDatos(){
try{
Conexion c=new Conexion();
c.conectar();
datos=c.consultarUsuario(FrmInicio.getIdUsuarioIngresado());
if(datos.getEstado()=='A'){
estado="Usuario Activo";
}else{
estado="Usuario Inactivo";
}
if(datos.getRol()=='A'){
rol="Administrador";
}else{
8/11/2019 Java Practicas y Sustentacion
76/158
rol="Basico";
}
}catch(Exception e){
System.out.println(e);
}
}
}
8/11/2019 Java Practicas y Sustentacion
77/158
package formularios;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JDesktopPane;
import javax.swing.JTabbedPane;
import javax.swing.JInternalFrame;
import java.awt.Panel;
import javax.swing.JLabel;
8/11/2019 Java Practicas y Sustentacion
78/158
import javax.swing.JTable;
import db.Conexion;
import entidades.Evento;
import entidades.Usuario;
import java.awt.Color;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Vector;
import com.toedter.calendar.JCalendar;
public class FrmPrincipal extends JFrame {
private JPanel contentPane;
private DefaultTableModel model;
private Usuario datos=new Usuario();
private String numEventos;
private JTable table;
private ArrayList eventos=new ArrayList();
/**
* Launch the application.
8/11/2019 Java Practicas y Sustentacion
79/158
*/
/**
* Create the frame.
*/
public FrmPrincipal(final Usuario u) {
setBackground(new Color(105, 105, 105));
setForeground(new Color(255, 255, 255));
setTitle("Principal");
obtenerDatos();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 520, 500);
contentPane = new JPanel();
contentPane.setBackground(new Color(211, 211, 211));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JMenuBar menuBar = new JMenuBar();
menuBar.setBounds(0, 0, 520, 21);
contentPane.add(menuBar);
JMenu mnInicio = new JMenu("Inicio");
menuBar.add(mnInicio);
8/11/2019 Java Practicas y Sustentacion
80/158
JMenuItem mntmMiCuenta = new JMenuItem("Mi cuenta");
mntmMiCuenta.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
FrmUser abc= new FrmUser();
abc.setVisible(true);
}
});
mnInicio.add(mntmMiCuenta);
JMenuItem mntmCerrarSesion = new JMenuItem("Cerrar Sesion");
mntmCerrarSesion.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FrmInicio frm=new FrmInicio();
frm.setVisible(true);
dispose();
}
});
mnInicio.add(mntmCerrarSesion);
JMenuItem mntmSalir = new JMenuItem("Salir");
mntmSalir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
8/11/2019 Java Practicas y Sustentacion
81/158
mnInicio.add(mntmSalir);
JMenu mnMantenimiento = new JMenu("Eventos");
menuBar.add(mnMantenimiento);
JMenuItem mntmCliente = new JMenuItem("Nuevo");
mntmCliente.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
FrmNewEvent frm=new FrmNewEvent();
frm.setVisible(true);
}
});
mnMantenimiento.add(mntmCliente);
JMenuItem mntmEditar = new JMenuItem("Editar");
mntmEditar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FrmEditarEvento editar= new FrmEditarEvento();
editar.setVisible(true);
}
});
mnMantenimiento.add(mntmEditar);
JMenu mnProcesos = new JMenu("Calendario");
8/11/2019 Java Practicas y Sustentacion
82/158
8/11/2019 Java Practicas y Sustentacion
83/158
mnAyuda.add(mntmAcercaDe);
JMenu mnSustentacion = new JMenu("Sustentaci\u00F3n");
menuBar.add(mnSustentacion);
JMenuItem mntmExportar = new JMenuItem("Exportar");
mntmExportar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//SUSTENTACION
try{
Conexion c=new Conexion();
c.conectar();
c.obtenerRegistroUsuario();
c.obtenerRegistroEvento();
JOptionPane.showMessageDialog(null, "REGISTROS CREADOS","ADVERTENCIA", JOptionPane.INFORMATION_MESSAGE);
}catch(Exception e){
System.out.println(e);
}
//SUSTENTACION
}
8/11/2019 Java Practicas y Sustentacion
84/158
});
mnSustentacion.add(mntmExportar);
/*SOLO ADMIN*/
if(u.getRol()=='A'){
JMenu mnMantenimiento_1 = new JMenu("Mantenimiento");
menuBar.add(mnMantenimiento_1);
JMenuItem mntmConsultar_1 = new JMenuItem("Usuarios");
mntmConsultar_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FrmEditarUser nuevo=new FrmEditarUser();
nuevo.setVisible(true);
}
});
mnMantenimiento_1.add(mntmConsultar_1);
JMenuItem mntmUsuarioNuevo = new JMenuItem("Crear Usuario");
mntmUsuarioNuevo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FrmNewUser frm= new FrmNewUser();
frm.setVisible(true);
}
8/11/2019 Java Practicas y Sustentacion
85/158
});
mnMantenimiento_1.add(mntmUsuarioNuevo);
JMenuItem mntmTipoNuevo = new JMenuItem("Crear Tipo");
mntmTipoNuevo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FrmNewTipo nuevo=new FrmNewTipo();
nuevo.setVisible(true);
}
});
mnMantenimiento_1.add(mntmTipoNuevo);
}
/*FIN SOLO ADMIN*/
JLabel lblEventos = new JLabel("Eventos:");
lblEventos.setBounds(212, 434, 70, 15);
contentPane.add(lblEventos);
JLabel lblHola = new JLabel("Bienvenido");
lblHola.setBounds(160, 46, 92, 15);
contentPane.add(lblHola);
JLabel lblProximoEvento = new JLabel("Proximos eventos:");
8/11/2019 Java Practicas y Sustentacion
86/158
lblProximoEvento.setBounds(56, 273, 144, 15);
contentPane.add(lblProximoEvento);
/*infoTabla();
String[] columnNames = {"Nombre",
"Descripcion",
"Relevancia",
"Fecha"};
Object[][] data = {
{eventos.get(0).getNombre(), eventos.get(0).getDescripcion(),
eventos.get(0).getRelevancia(), eventos.get(0).getFecha()},
{eventos.get(1).getNombre(), eventos.get(1).getDescripcion(),
eventos.get(1).getRelevancia(), eventos.get(1).getFecha()},
{eventos.get(2).getNombre(), eventos.get(2).getDescripcion(),
eventos.get(2).getRelevancia(), eventos.get(2).getFecha()},
{eventos.get(3).getNombre(), eventos.get(3).getDescripcion(),eventos.get(3).getRelevancia(), eventos.get(3).getFecha()},
//{eventos.get(4).getNombre(), eventos.get(4).getDescripcion(),
eventos.get(4).getRelevancia(), eventos.get(4).getFecha()}
};
model=new DefaultTableModel(data, columnNames);
table = new JTable();
table.setModel(model);
table.setRowSelectionAllowed(false);
8/11/2019 Java Practicas y Sustentacion
87/158
table.setBounds(56, 300, 442, 107);
contentPane.add(table);*/
JLabel lbUsuario = new JLabel(datos.getNombres());
lbUsuario.setBounds(241, 46, 169, 15);
contentPane.add(lbUsuario);
JLabel lbNumEventos = new JLabel(numEventos);
lbNumEventos.setBounds(288, 434, 70, 15);
contentPane.add(lbNumEventos);
JCalendar calendar = new JCalendar();
calendar.setBounds(170, 73, 223, 159);
contentPane.add(calendar);
}
public void obtenerDatos(){
try{
Conexion c=new Conexion();
c.conectar();
datos=c.consultarUsuario(FrmInicio.getIdUsuarioIngresado());
numEventos=String.valueOf(c.eventosUsuario(FrmInicio.getIdUsuarioIngresado()));
}catch(Exception e){
System.out.println(e);
}
}
8/11/2019 Java Practicas y Sustentacion
88/158
}
8/11/2019 Java Practicas y Sustentacion
89/158
package formularios;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.DefaultComboBoxModel;
import db.Conexion;
import entidades.Usuario;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
public class FrmNewUser extends JFrame {
8/11/2019 Java Practicas y Sustentacion
90/158
private JPanel contentPane;
private JTextField tfUser;
private JTextField tfNombre;
private JTextField tfApellidos;
private JTextField tfCorreo;
private JPasswordField tfPass;
private JTextField tfMovil;
private JTextField tfFacebook;
private String id;
private String nombres;
private String apellidos;
private String clave;
private char rol;
private String cntCorreo;
private String cntFacebook;
private String telMovil;
private char estado;
/**
* Create the frame.
*/
public FrmNewUser() {
setForeground(new Color(255, 255, 255));
8/11/2019 Java Practicas y Sustentacion
91/158
setBackground(new Color(105, 105, 105));
setTitle("Usuario Nuevo");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 520, 500);
contentPane = new JPanel();
contentPane.setBackground(new Color(211, 211, 211));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblIdUsuario = new JLabel("Id Usuario:");
lblIdUsuario.setBounds(74, 39, 100, 15);
contentPane.add(lblIdUsuario);
JLabel lblContrasena = new JLabel("Contrasena:");
lblContrasena.setBounds(62, 83, 112, 15);
contentPane.add(lblContrasena);
JLabel lblNombre = new JLabel("Nombre:");
lblNombre.setBounds(92, 130, 70, 15);
contentPane.add(lblNombre);
JLabel lblApellidos = new JLabel("Apellidos:");
lblApellidos.setBounds(82, 175, 70, 15);
contentPane.add(lblApellidos);
8/11/2019 Java Practicas y Sustentacion
92/158
/* FIN SOLO ADMIN*/
JLabel lblCorreo = new JLabel("Correo:");
lblCorreo.setBounds(102, 218, 70, 15);
contentPane.add(lblCorreo);
JLabel lblTelefonoMovil = new JLabel("Telefono movil:");
lblTelefonoMovil.setBounds(47, 263, 127, 15);
contentPane.add(lblTelefonoMovil);
JLabel lblFacebook = new JLabel("Facebook:");
lblFacebook.setBounds(80, 303, 127, 15);
contentPane.add(lblFacebook);
tfUser = new JTextField();
tfUser.setBounds(180, 37, 273, 19);
contentPane.add(tfUser);
tfUser.setColumns(10);
tfNombre = new JTextField();
tfNombre.setBounds(180, 128, 273, 19);
contentPane.add(tfNombre);
tfNombre.setColumns(10);
8/11/2019 Java Practicas y Sustentacion
93/158
tfApellidos = new JTextField();
tfApellidos.setBounds(180, 173, 273, 19);
contentPane.add(tfApellidos);
tfApellidos.setColumns(10);
tfCorreo = new JTextField();
tfCorreo.setBounds(179, 216, 274, 19);
contentPane.add(tfCorreo);
tfCorreo.setColumns(10);
tfPass = new JPasswordField();
tfPass.setBounds(180, 81, 273, 19);
contentPane.add(tfPass);
tfMovil = new JTextField();
tfMovil.setBounds(179, 261, 274, 19);
contentPane.add(tfMovil);
tfMovil.setColumns(10);
tfFacebook = new JTextField();
tfFacebook.setBounds(180, 305, 273, 19);
contentPane.add(tfFacebook);
tfFacebook.setColumns(10);
JButton btnIngresar = new JButton("Ingresar");
8/11/2019 Java Practicas y Sustentacion
94/158
btnIngresar.setBackground(new Color(176, 196, 222));
btnIngresar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(IngresoVal()){
Conexion c=new Conexion();
try{
c.conectar();
Usuario nuevo=new
Usuario(id,nombres,apellidos,clave,rol,estado,cntCorreo,cntFacebook,telMovil);
if(c.ingresarUsuario(nuevo)){
JOptionPane.showMessageDialog(null, "Ingeso
exitoso", "WIIII", JOptionPane.INFORMATION_MESSAGE);
dispose();
}else{
JOptionPane.showMessageDialog(null, "Error al
ingresar a la BD", "ERROR", JOptionPane.ERROR_MESSAGE);
}
}catch(Exception e){
System.out.println("Error en la conexin");
}
c.desconectar();
limpiar();
}
}
});
btnIngresar.setBounds(355, 368, 117, 67);
8/11/2019 Java Practicas y Sustentacion
95/158
contentPane.add(btnIngresar);
JButton btnLimpiar = new JButton("Limpiar");
btnLimpiar.setBackground(new Color(218, 165, 32));
btnLimpiar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
limpiar();
}
});
btnLimpiar.setBounds(211, 369, 117, 64);
contentPane.add(btnLimpiar);
JButton btnCerrar = new JButton("Cerrar");
btnCerrar.setBackground(new Color(255, 127, 80));
btnCerrar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
dispose();
}
});
btnCerrar.setBounds(62, 368, 117, 65);
contentPane.add(btnCerrar);
}
private void limpiar(){
tfUser.setText(null);
8/11/2019 Java Practicas y Sustentacion
96/158
tfApellidos.setText(null);
tfNombre.setText(null);
tfCorreo.setText(null);
tfFacebook.setText(null);
tfMovil.setText(null);
tfPass.setText(null);
}
public boolean IngresoVal(){
id=tfUser.getText();
clave=String.valueOf(tfPass.getPassword());
nombres=tfNombre.getText();
apellidos=tfApellidos.getText();
cntCorreo=tfCorreo.getText();
telMovil=tfMovil.getText();
cntFacebook=("facebook.com/"+tfFacebook.getText());
estado='A';
rol='B';
if (id.equals("")){
JOptionPane.showMessageDialog(null, "Ingresar ID", "ERROR",JOptionPane.ERROR_MESSAGE);
return false;
}
if (clave.equals("")){
8/11/2019 Java Practicas y Sustentacion
97/158
JOptionPane.showMessageDialog(null, "Ingresar una contrasena", "ERROR",
JOptionPane.ERROR_MESSAGE);
return false;
}
if (nombres.equals("")){
JOptionPane.showMessageDialog(null, "Ingresar nombres", "ERROR",
JOptionPane.ERROR_MESSAGE);
return false;
}
if (apellidos.equals("")){
JOptionPane.showMessageDialog(null, "Ingresar apellidos", "ERROR",
JOptionPane.ERROR_MESSAGE);
return false;
}
if (cntCorreo.equals("")){
JOptionPane.showMessageDialog(null, "Ingresar Correo", "ERROR",
JOptionPane.ERROR_MESSAGE);
return false;
}
if (!cntCorreo.contains("@")){
JOptionPane.showMessageDialog(null, "Ingresar un correo valido", "ERROR",
JOptionPane.ERROR_MESSAGE);
return false;
}else if(!cntCorreo.contains(".com")){
JOptionPane.showMessageDialog(null, "Ingresar un correo valido", "ERROR",
JOptionPane.ERROR_MESSAGE);
return false;
}
8/11/2019 Java Practicas y Sustentacion
98/158
return true;
}
}
8/11/2019 Java Practicas y Sustentacion
99/158
package formularios;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import db.Conexion;
import entidades.Tipo;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class FrmNewTipo extends JFrame {
private JPanel contentPane;
private JTextField tfNombreTipo;
8/11/2019 Java Practicas y Sustentacion
100/158
private JComboBox cbMeses;
private String nombreTipo;
private int meses;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
FrmNewTipo frame = new FrmNewTipo();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public FrmNewTipo() {
setTitle("Tipo Nuevo");
8/11/2019 Java Practicas y Sustentacion
101/158
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblNombre = new JLabel("Nombre:");
lblNombre.setBounds(95, 38, 109, 15);
contentPane.add(lblNombre);
JLabel lblTiempoEnMeses = new JLabel("Tiempo en meses:");
lblTiempoEnMeses.setBounds(44, 98, 136, 15);
contentPane.add(lblTiempoEnMeses);
tfNombreTipo = new JTextField();
tfNombreTipo.setBounds(196, 36, 192, 19);
contentPane.add(tfNombreTipo);
tfNombreTipo.setColumns(10);
cbMeses = new JComboBox();
cbMeses.setModel(new DefaultComboBoxModel(new String[] {"1", "2", "3", "4", "5","6", "7", "8", "9", "10", "11", "12"}));
cbMeses.setBounds(196, 93, 192, 24);
contentPane.add(cbMeses);
8/11/2019 Java Practicas y Sustentacion
102/158
JButton btnCerrar = new JButton("Cerrar");
btnCerrar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
btnCerrar.setBounds(25, 180, 117, 58);
contentPane.add(btnCerrar);
JButton btnLimpiar = new JButton("Limpiar");
btnLimpiar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
limpiar();
}
});
btnLimpiar.setBounds(165, 180, 117, 58);
contentPane.add(btnLimpiar);
JButton btnIngresar = new JButton("Ingresar");
btnIngresar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(validacionTipo()){
Conexion c=new Conexion();
try{
c.conectar();
8/11/2019 Java Practicas y Sustentacion
103/158
Tipo nuevo= new Tipo(nombreTipo, meses);
if(c.ingresarTipo(nuevo)){
JOptionPane.showMessageDialog(null, "Ingeso
exitoso", "WIIII", JOptionPane.INFORMATION_MESSAGE);
}else{
JOptionPane.showMessageDialog(null, "Error al
ingresar a la BD", "ERROR", JOptionPane.ERROR_MESSAGE);
}
}catch(Exception e){
System.out.println("Error en la conexin");
}
c.desconectar();
limpiar();
}
}
});
btnIngresar.setBounds(304, 180, 117, 58);
contentPane.add(btnIngresar);
}
private void limpiar(){
tfNombreTipo.setText(null);
cbMeses.setSelectedIndex(0);
}
public boolean validacionTipo(){
8/11/2019 Java Practicas y Sustentacion
104/158
nombreTipo=tfNombreTipo.getText();
meses=Integer.parseInt(String.valueOf(cbMeses.getSelectedItem()));
if(nombreTipo.equals("")){
JOptionPane.showMessageDialog(null, "Ingresar nombre", "ERROR",
JOptionPane.ERROR_MESSAGE);
return false;
}
return true;
}
}
8/11/2019 Java Practicas y Sustentacion
105/158
package formularios;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import javax.swing.DefaultComboBoxModel;
import db.Conexion;
import entidades.Evento;
8/11/2019 Java Practicas y Sustentacion
106/158
import java.awt.Color;
public class FrmNewEvent extends JFrame {
private JPanel contentPane;
private JTextField tfNombreEvento;
private JTextField tfDescripcion;
private JComboBox cbTipo;
private JComboBox cbRelevancia;
private String nombreEvento;
private String descripcion;
private String relevancia;
private String tipoSeleccionado;
private String dateNow;
/**
* Launch the application.
*/
/**
* Create the frame.
*/
public FrmNewEvent() {
setForeground(new Color(255, 255, 255));
setBackground(new Color(105, 105, 105));
8/11/2019 Java Practicas y Sustentacion
107/158
8/11/2019 Java Practicas y Sustentacion
108/158
limpiar();
}
});
btnLimpiar.setBounds(206, 379, 117, 60);
contentPane.add(btnLimpiar);
JButton btnIngresar = new JButton("Ingresar");
btnIngresar.setBackground(new Color(176, 196, 222));
btnIngresar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(validarIngreso()){
Conexion c=new Conexion();
try{
c.conectar();
Evento nuevo=new
Evento(nombreEvento,descripcion,relevancia,FrmInicio.getIdUsuarioIngresado(),c.obtenerIDtipo(tipoSel
eccionado),dateNow);
if(c.ingresarEvento(nuevo)){
JOptionPane.showMessageDialog(null, "Ingeso
exitoso", "WIIII", JOptionPane.INFORMATION_MESSAGE);
dispose();
}else{
JOptionPane.showMessageDialog(null, "Error alingresar a la BD", "ERROR", JOptionPane.ERROR_MESSAGE);
}
}catch(Exception e){
System.out.println(e);
8/11/2019 Java Practicas y Sustentacion
109/158
}
}
}
});
btnIngresar.setBounds(357, 379, 117, 60);
contentPane.add(btnIngresar);
tfNombreEvento = new JTextField();
tfNombreEvento.setBounds(206, 74, 211, 19);
contentPane.add(tfNombreEvento);
tfNombreEvento.setColumns(10);
tfDescripcion = new JTextField();
tfDescripcion.setBounds(209, 141, 208, 19);
contentPane.add(tfDescripcion);
tfDescripcion.setColumns(10);
cbRelevancia = new JComboBox();
cbRelevancia.setModel(new DefaultComboBoxModel(new String[] {"Normal",
"Importante"}));
cbRelevancia.setBounds(206, 211, 211, 24);
contentPane.add(cbRelevancia);
JLabel lblTipo = new JLabel("Tipo:");
lblTipo.setBounds(116, 293, 70, 15);
contentPane.add(lblTipo);
8/11/2019 Java Practicas y Sustentacion
110/158
/*AGREGAR NOMBRE DE TIPOS DE EVENTOS AL COMBO BOX*/
Conexion tipos=new Conexion();
try{
tipos.conectar();
cbTipo = new JComboBox();
ArrayList abc=tipos.obtenerTipos();
for(int a=0;a
8/11/2019 Java Practicas y Sustentacion
111/158
});
btnCerrar.setBounds(52, 379, 117, 60);
contentPane.add(btnCerrar);
}
private void limpiar(){
tfNombreEvento.setText(null);
tfDescripcion.setText(null);
cbRelevancia.setSelectedIndex(0);
cbTipo.setSelectedIndex(0);
}
private boolean validarIngreso(){
nombreEvento=tfNombreEvento.getText();
descripcion=tfDescripcion.getText();
relevancia=String.valueOf(cbRelevancia.getSelectedItem());
tipoSeleccionado=String.valueOf(cbTipo.getSelectedItem());
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat formatter=
new SimpleDateFormat("yyyy-MM-dd");
dateNow = formatter.format(currentDate.getTime());
8/11/2019 Java Practicas y Sustentacion
112/158
Conexion obtenerIDtipo= new Conexion();
try{
obtenerIDtipo.conectar();
}catch(Exception e){
System.out.println(e);
}
if (nombreEvento.equals("")){
JOptionPane.showMessageDialog(null, "Ingresar Nombre", "ERROR",
JOptionPane.ERROR_MESSAGE);
return false;
}
return true;
}
}
8/11/2019 Java Practicas y Sustentacion
113/158
package formularios;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import db.Conexion;
import entidades.*;
import general.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPasswordField;
import java.awt.Color;
import javax.swing.UIManager;
import java.awt.Font;
8/11/2019 Java Practicas y Sustentacion
114/158
public class FrmInicio extends JFrame {
private JPanel contentPane;
private JTextField userTf;
private JPasswordField passTf;
private static String idUsuarioIngresado;
public static String getIdUsuarioIngresado() {
return idUsuarioIngresado;
}
public void setIdUsuarioIngresado(String idUsuarioIngresado) {
this.idUsuarioIngresado = idUsuarioIngresado;
}
/**
* Launch the application.
*/
/**
* Create the frame.
*/
public FrmInicio() {
setForeground(new Color(255, 255, 255));
8/11/2019 Java Practicas y Sustentacion
115/158
setBackground(new Color(47, 79, 79));
setTitle("Proyecto Primer Parcial");
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 520, 500);
contentPane = new JPanel();
contentPane.setBackground(Color.LIGHT_GRAY);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblBienvenido = new JLabel("Bienvenido!");
lblBienvenido.setFont(new Font("Dialog", Font.BOLD, 16));
lblBienvenido.setBounds(210, 91, 107, 15);
contentPane.add(lblBienvenido);
JLabel lblUsuario = new JLabel("Usuario: ");
lblUsuario.setBounds(123, 388, 70, 15);
contentPane.add(lblUsuario);
JLabel lblPassword = new JLabel("Password:");
8/11/2019 Java Practicas y Sustentacion
116/158
lblPassword.setBounds(112, 415, 93, 15);
contentPane.add(lblPassword);
userTf = new JTextField();
userTf.setBounds(205, 386, 150, 19);
contentPane.add(userTf);
userTf.setColumns(10);
JButton btnIng = new JButton(">");
btnIng.setBackground(new Color(176, 196, 222));
btnIng.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
validarUser();
}
});
btnIng.setBounds(367, 386, 44, 42);
contentPane.add(btnIng);
passTf = new JPasswordField();
passTf.setBounds(205, 413, 150, 19);
contentPane.add(passTf);
JButton btnUsuarioNuevo = new JButton("Usuario nuevo");
btnUsuarioNuevo.setFont(new Font("Dialog", Font.PLAIN, 8));
btnUsuarioNuevo.setBackground(new Color(143, 188, 143));
8/11/2019 Java Practicas y Sustentacion
117/158
btnUsuarioNuevo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FrmNewUser frm=new FrmNewUser();
frm.setVisible(true);
}
});
btnUsuarioNuevo.setBounds(397, 12, 100, 42);
contentPane.add(btnUsuarioNuevo);
}
public void validarUser(){
String id=this.userTf.getText();
String clave=String.valueOf(this.passTf.getPassword());
Usuario a = new Usuario();
a.setId(id);
a.setClave(clave);
Conexion abc = new Conexion();
try{
abc.conectar();
if (abc.esUsuarioValido(a)){
idUsuarioIngresado=a.getId();
JOptionPane.showMessageDialog(null, "Bienvenido a la version Beta deldemo de C-Remember", "ADVERTENCIA", JOptionPane.INFORMATION_MESSAGE);
FrmPrincipal uno = new FrmPrincipal(a);
uno.setVisible(true);
this.dispose();
8/11/2019 Java Practicas y Sustentacion
118/158
} else {
System.out.println("User invalido!1");
}
}catch(Exception e){
System.out.println("ERROARRRRR! 2");
}
}
}
8/11/2019 Java Practicas y Sustentacion
119/158
package formularios;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import db.Conexion;
import entidades.Usuario;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class FrmEditarUserBasico extends JFrame {
private JPanel contentPane;
8/11/2019 Java Practicas y Sustentacion
120/158
private JTextField tfNombres;
private JTextField tfApellidos;
private JTextField tfCorreo;
private JTextField tfMovil;
private JTextField tfFacebook;
private String nombres;
private String apellidos;
private String correo;
private String movil;
private String facebook;
private Usuario editar;
private JLabel lbUser;
private char estado;
private char rol;
/**
* Launch the application.
*/
/**
* Create the frame.
*/
public FrmEditarUserBasico() {
setForeground(new Color(255, 255, 255));
8/11/2019 Java Practicas y Sustentacion
121/158
setTitle("Editar Usuario");
setBackground(new Color(105, 105, 105));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 520, 500);
contentPane = new JPanel();
contentPane.setBackground(new Color(211, 211, 211));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblIdUsuario = new JLabel("ID Usuario:");
lblIdUsuario.setBounds(84, 37, 134, 15);
contentPane.add(lblIdUsuario);
lbUser = new JLabel("New label");
lbUser.setBounds(213, 37, 225, 15);
contentPane.add(lbUser);
JLabel lblNombres = new JLabel("Nombres:");
lblNombres.setBounds(100, 81, 70, 15);
contentPane.add(lblNombres);
JLabel lblApellidos = new JLabel("Apellidos:");
lblApellidos.setBounds(100, 138, 70, 15);
8/11/2019 Java Practicas y Sustentacion
122/158
contentPane.add(lblApellidos);
JLabel lblCorreo = new JLabel("Correo:");
lblCorreo.setBounds(112, 192, 70, 15);
contentPane.add(lblCorreo);
JLabel lblTelefonoMovil = new JLabel("Telefono Movil:");
lblTelefonoMovil.setBounds(58, 254, 124, 15);
contentPane.add(lblTelefonoMovil);
JLabel lblFacebook = new JLabel("Facebook:");
lblFacebook.setBounds(84, 311, 112, 15);
contentPane.add(lblFacebook);
JButton btnCancelar = new JButton("Cancelar");
btnCancelar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
dispose();
}
});
btnCancelar.setBackground(new Color(255, 127, 80));
btnCancelar.setBounds(40, 365, 117, 61);
contentPane.add(btnCancelar);
JButton btnEliminar = new JButton("Eliminar");
8/11/2019 Java Practicas y Sustentacion
123/158
btnEliminar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(validarDatos()){
try{
Conexion c=new Conexion();
Usuario editar=new
Usuario(FrmInicio.getIdUsuarioIngresado(),nombres,apellidos,rol,estado,correo,facebook,movil);
if(c.eliminarUsuario(editar)){
JOptionPane.showMessageDialog(null, "Usuario
eliminado", "Exito!", JOptionPane.INFORMATION_MESSAGE);
dispose();
}else{
JOptionPane.showMessageDialog(null, "Error al
eliminar", "ERROR", JOptionPane.ERROR_MESSAGE);
}
}catch(Exception e){
System.out.println(e);
}
}
}
});
btnEliminar.setBackground(new Color(218, 165, 32));
btnEliminar.setBounds(202, 365, 117, 61);
contentPane.add(btnEliminar);
JButton btnActualizar = new JButton("Actualizar");
8/11/2019 Java Practicas y Sustentacion
124/158
btnActualizar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(validarDatos()){
try{
Conexion c=new Conexion();
c.conectar();
Usuario editar=new
Usuario(FrmInicio.getIdUsuarioIngresado(),nombres,apellidos,rol,estado,correo,facebook,movil);
if(c.editarUsuario(editar)){
JOptionPane.showMessageDialog(null,
"Actualizacion exitosa", "Exito!", JOptionPane.INFORMATION_MESSAGE);
FrmUser nuevo=new FrmUser();
nuevo.setVisible(true);
dispose();
}else{
JOptionPane.showMessageDialog(null, "Error al
actualizar", "ERROR", JOptionPane.ERROR_MESSAGE);
}
}catch(Exception e){
System.out.println(e);
}
}
}
});
btnActualizar.setBackground(new Color(176, 196, 222));
btnActualizar.setBounds(361, 365, 117, 61);
contentPane.add(btnActualizar);
8/11/2019 Java Practicas y Sustentacion
125/158
tfNombres = new JTextField();
tfNombres.setBounds(213, 79, 199, 19);
contentPane.add(tfNombres);
tfNombres.setColumns(10);
tfApellidos = new JTextField();
tfApellidos.setBounds(213, 136, 199, 19);
contentPane.add(tfApellidos);
tfApellidos.setColumns(10);
tfCorreo = new JTextField();
tfCorreo.setBounds(213, 190, 199, 19);
contentPane.add(tfCorreo);
tfCorreo.setColumns(10);
tfMovil = new JTextField();
tfMovil.setBounds(213, 252, 199, 19);
contentPane.add(tfMovil);
tfMovil.setColumns(10);
tfFacebook = new JTextField();
tfFacebook.setBounds(213, 309, 199, 19);
contentPane.add(tfFacebook);
tfFacebook.setColumns(10);
8/11/2019 Java Practicas y Sustentacion
126/158
obtenerDatos();
}
public boolean validarDatos(){
nombres=tfNombres.getText();
apellidos=tfApellidos.getText();
correo=tfCorreo.getText();
movil=tfMovil.getText();
facebook=tfFacebook.getText();
if (nombres.equals("")){
JOptionPane.showMessageDialog(null, "Ingresar nombres", "ERROR",
JOptionPane.ERROR_MESSAGE);
return false;
}
if (apellidos.equals("")){
JOptionPane.showMessageDialog(null, "Ingresar apellidos", "ERROR",
JOptionPane.ERROR_MESSAGE);
return false;
}
return true;
}
public void obtenerDatos(){
8/11/2019 Java Practicas y Sustentacion
127/158
Conexion c=new Conexion();
try{
c.conectar();
editar=c.consultarUsuario(FrmInicio.getIdUsuarioIngresado());
mostrarDatos();
}catch(Exception e){
System.out.println(e);
}
}
public void mostrarDatos(){
lbUser.setText(editar.getId());
tfNombres.setText(editar.getNombres());
tfApellidos.setText(editar.getApellidos());
tfCorreo.setText(editar.getCntCorreo());
tfMovil.setText(editar.getTelMovil());
tfFacebook.setText(editar.getCntFacebook());
estado=editar.getEstado();
rol=editar.getRol();
}
}
8/11/2019 Java Practicas y Sustentacion
128/158
package formularios;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Image;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComboBox;
import db.Conexion;
import entidades.Usuario;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.DefaultComboBoxModel;
import java.awt.Color;
8/11/2019 Java Practicas y Sustentacion
129/158
public class FrmEditarUser extends JFrame {
private JPanel contentPane;
private JTextField tfUser;
private JTextField tfFB;
private JTextField tfMovil;
private JTextField tfCorreo;
private JTextField tfApellidos;
private JTextField tfNombres;
private JComboBox cbRol;
private JComboBox cbEstado;
private Usuario editar;
private JButton btnCancelar;
private JButton btnActualizar;
private JLabel lblRol;
private JLabel lblNombres;
private JLabel lblApellidos;
private JLabel lblCorreo;
private JLabel lblTelefonoMovil;
private JLabel lblEstado;
private JLabel lblFacebook;
private String idUser;
private String nombres;
private String apellidos;
8/11/2019 Java Practicas y Sustentacion
130/158
private String correo;
private String facebook;
private String movil;
private String rolSelect;
private String estadoSelect;
private JButton btnEliminar;
/**
* Launch the application.
*/
/**
* Create the frame.
*/
public FrmEditarUser() {
setForeground(new Color(255, 255, 255));
setBackground(new Color(105, 105, 105));
setTitle("Usuarios");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 520, 500);
contentPane = new JPanel();
contentPane.setBackground(new Color(211, 211, 211));
8/11/2019 Java Practicas y Sustentacion
131/158
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel lblIdUsuario = new JLabel("ID usuario:");
lblIdUsuario.setBounds(56, 32, 95, 15);
contentPane.add(lblIdUsuario);
tfUser = new JTextField();
tfUser.setBounds(195, 30, 187, 19);
contentPane.add(tfUser);
tfUser.setColumns(10);
JButton btnBuscar = new JButton("Buscar");
btnBuscar.setBackground(new Color(143, 188, 143));
btnBuscar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(buscarUser()){
mostrarDatos();
}
}
});
btnBuscar.setBounds(394, 12, 82, 55);
contentPane.add(btnBuscar);
8/11/2019 Java Practicas y Sustentacion
132/158
lblNombres = new JLabel("Nombres:");
lblNombres.setBounds(69, 96, 70, 15);
contentPane.add(lblNombres);
lblNombres.setVisible(false);
lblApellidos = new JLabel("Apellidos:");
lblApellidos.setBounds(69, 135, 70, 15);
contentPane.add(lblApellidos);
lblApellidos.setVisible(false);
lblCorreo = new JLabel("Correo:");
lblCorreo.setBounds(82, 172, 95, 15);
contentPane.add(lblCorreo);
lblCorreo.setVisible(false);
lblTelefonoMovil = new JLabel("Telefono Movil:");
lblTelefonoMovil.setBounds(34, 210, 117, 15);
contentPane.add(lblTelefonoMovil);
lblTelefonoMovil.setVisible(false);
lblFacebook = new JLabel("Facebook:");
lblFacebook.setBounds(73, 237, 104, 15);
contentPane.add(lblFacebook);
lblFacebook.setVisible(false);
8/11/2019 Java Practicas y Sustentacion
133/158
lblEstado = new JLabel("Estado:");
lblEstado.setBounds(91, 275, 70, 15);
contentPane.add(lblEstado);
lblEstado.setVisible(false);
lblRol = new JLabel("Rol:");
lblRol.setBounds(123, 311, 70, 15);
contentPane.add(lblRol);
lblRol.setVisible(false);
cbEstado = new JComboBox();
cbEstado.setModel(new DefaultComboBoxModel(new String[] {"Activo", "Inactivo"}));
cbEstado.setBounds(195, 270, 187, 24);
contentPane.add(cbEstado);
cbEstado.setVisible(false);
cbRol = new JComboBox();
cbRol.setModel(new DefaultComboBoxModel(new String[] {"Basico",
"Administrador"}));
cbRol.setBounds(196, 306, 186, 24);
contentPane.add(cbRol);
cbRol.setVisible(false);
tfFB = new JTextField();
tfFB.setBounds(195, 239, 187, 19);
contentPane.add(tfFB);
8/11/2019 Java Practicas y Sustentacion
134/158
8/11/2019 Java Practicas y Sustentacion
135/158
tfNombres.setVisible(false);
tfNombres.setVisible(false);
btnCancelar = new JButton("Cancelar");
btnCancelar.setBackground(new Color(218, 165, 32));
btnCancelar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
btnCancelar.setBounds(44, 376, 117, 62);
contentPane.add(btnCancelar);
btnActualizar = new JButton("Actualizar");
btnActualizar.setBackground(new Color(176, 196, 222));
btnActualizar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(validarDatos()){
try{
Conexion c=new Conexion();
c.conectar();
Usuario editar=newUsuario(idUser,nombres,apellidos,rolSelect.charAt(0),estadoSelect.charAt(0),correo,facebook,movil);
if(c.editarUsuario(editar)){
JOptionPane.showMessageDialog(null,
"Actualizacion exitosa", "Exito!", JOptionPane.INFORMATION_MESSAGE);
8/11/2019 Java Practicas y Sustentacion
136/158
dispose();
}else{
JOptionPane.showMessageDialog(null, "Error al
actualizar", "ERROR", JOptionPane.ERROR_MESSAGE);
}
}catch(Exception e){
System.out.println(e);
}
}
}
});
btnActualizar.setBounds(359, 376, 117, 62);
contentPane.add(btnActualizar);
btnEliminar = new JButton("Eliminar");
btnEliminar.setBackground(new Color(255, 127, 80));
btnEliminar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(validarDatos()){
try{
Conexion c=new Conexion();
Usuario editar=new
Usuario(idUser,nombres,apellidos,rolSelect.charAt(0),estadoSelect.charAt(0),correo,facebook,movil);
if(c.eliminarUsuario(editar)){
JOptionPane.showMessageDialog(null, "Usuario
eliminado", "Exito!", JOptionPane.INFORMATION_MESSAGE);
dispose();
8/11/2019 Java Practicas y Sustentacion
137/158
}else{
JOptionPane.showMessageDialog(null, "Error al
eliminar", "ERROR", JOptionPane.ERROR_MESSAGE);
}
}catch(Exception e){
System.out.println(e);
}
}
}
});
btnEliminar.setBounds(207, 376, 117, 62);
contentPane.add(btnEliminar);
btnActualizar.setVisible(false);
btnEliminar.setVisible(false);
}
public boolean buscarUser(){
try{
if (tfUser.getText().equals("")){
JOptionPane.showMessageDialog(null, "Ingresar ID", "ERROR",
JOptionPane.ERROR_MESSAGE);
return false;
}else{
Conexion c=new Conexion();
c.conectar();
editar=c.consultarUsuario(tfUser.getText());
8/11/2019 Java Practicas y Sustentacion
138/158
if(editar.getId()==null){
JOptionPane.showMessageDialog(null, "No existe usuario",
"ERROR", JOptionPane.ERROR_MESSAGE);
return false;
}
}
}catch(Exception e){
System.out.println(e);
return false;
}
idUser=editar.getId();
return true;
}
public void mostrarDatos(){
lblNombres.setVisible(true);
lblApellidos.setVisible(true);
lblCorreo.setVisible(true);
lblTelefonoMovil.setVisible(true);
lblFacebook.setVisible(true);
lblEstado.setVisible(true);
lblRol.setVisible(true);
cbEstado.setVisible(true);
cbRol.setVisible(true);
tfFB.setVisible(true);
8/11/2019 Java Practicas y Sustentacion
139/158
8/11/2019 Java Practicas y Sustentacion
140/158
}
public boolean validarDatos(){
nombres=tfNombres.getText();
apellidos=tfApellidos.getText();
correo=tfCorreo.getText();
movil=tfMovil.getText();
facebook=tfFB.getText();
rolSelect=String.valueOf(cbRol.getSelectedItem());
estadoSelect=String.valueOf(cbEstado.getSelectedItem());
if (nombres.equals("")){
JOptionPane.showMessageDialog(null, "Ingresar nombres", "ERROR",
JOptionPane.ERROR_MESSAGE);
return false;
}
if (apellidos.equals("")){
JOptionPane.showMessageDialog(null, "Ingresar apellidos", "ERROR",
JOptionPane.ERROR_MESSAGE);
return false;
}
return true;
}
}
8/11/2019 Java Practicas y Sustentacion
141/158
8/11/2019 Java Practicas y Sustentacion
142/158
package formularios;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import