You are on page 1of 13

create database if not exists Bancoins; use bancoins; create table if not exists Clientes( no_cuenta VARCHAR (15)

NOT NULL , nombre VARCHAR(45) NOT NULL , apellido_p VARCHAR(20) NOT NULL , apellido_m VARCHAR(20) NOT NULL , saldo Double precision NOT NULL , sucursal_id VARCHAR(8) NOT NULL , PRIMARY KEY (no_cuenta)); ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS Movimientos ( folio INT NOT NULL auto_increment unique, fecha DATE NOT NULL , deposito Double precision NOT NULL , retiro Double precision NOT NULL , cantidad Double precision NOT NULL , clientes_no_cuenta VARCHAR(15) NOT NULL , PRIMARY KEY (folio)); ENGINE = InnoDB; CREATE TABLE IF NOT EXISTS Sucursal ( id VARCHAR(8) NOT NULL , nombre VARCHAR(50) NOT NULL , PRIMARY KEY (id)); ENGINE = InnoDB;

insert into clientes values ('0100204050','Edna Isamar','Hernandez','Hernandez','1500','01'), ('0100204750','Adalyd','Castillo','Santander','15000','01'), ('0100204850','Dayra','Garcia','Marquez','5000','01'), ('0100204950','Yolanda','Zuiga','Mera','150000','01'), ('0100205050','Adalyd','Castillo','Santander','15000','01');

drop table surcursal; insert into sucursal values ('01','Actopan'),('02','Pachuca'); select * from clientes; PROGRAMACION PARA LA APLICACIN /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package bantec; import javax.swing.JOptionPane; public class Bantec {

public static void main(String[] args) {

String s,d,r, ax;

double de,re;

int op =0;

JOptionPane.showMessageDialog(null," BIENVENIDO","Bancoin",JOptionPane.PLAIN_MESSAGE);

s= JOptionPane.showInputDialog(null,"Escribe el numero de cuenta:","Bancorp",JOptionPane.PLAIN_MESSAGE); Servicio nuevo = new Servicio (s); do {

ax=JOptionPane.showInputDialog(null, "1.- Consultar \n 2.- Depositar \n 3.- Retirar \n 4.Salir"); //if(ax!=null && auxi.isNum(ax)){

op = Integer.parseInt(ax);

switch (op) {

case 1:

JOptionPane.showMessageDialog(null,"Consultar","Bancoin",JOptionPane.PLAIN_MESSAGE); nuevo.Cuenta(s);

//System.exit(0);

break; case 2:

JOptionPane.showMessageDialog(null,"Desea realizar un deposito?","BANTEC",JOptionPane.PLAIN_MESSAGE); d= JOptionPane.showInputDialog(null,"Deposito:","BANTEC",JOptionPane.PLAIN_MESSAGE); de=Double.parseDouble(d); nuevo.Deposito(de); JOptionPane.showMessageDialog(null,"Deposito realizado con exito!","Bancoin",JOptionPane.PLAIN_MESSAGE); nuevo.Cuenta(s); //System.exit(0); break; case 3: JOptionPane.showMessageDialog(null,"Accion: Realizar un retiro?","Bancoin",JOptionPane.PLAIN_MESSAGE);

r=JOptionPane.showInputDialog(null,"Retiro:","BANTEC",JOptionPane.PLAIN_MESSAGE); re=Double.parseDouble(r); nuevo.Retiro(re); JOptionPane.showMessageDialog(null,"Retiro realizado con exito!","BANTEC",JOptionPane.PLAIN_MESSAGE);

nuevo.Cuenta(s);

//System.exit(0); break;

case 4:

JOptionPane.showMessageDialog(null,"SALIR","BANTEC",JOptionPane.PLAIN_MESSAGE);

//System.exit(0);

break;

default:

break;

// System.exit(0); }

//}else {JOptionPane.showMessageDialog(null,"Digite una opcion valida","BANTEC",JOptionPane.PLAIN_MESSAGE); } } while (op !=5);

nuevo.Cuenta(s);

} }

/* * To change this template, choose Tools | Templates * and open the template in the editor. */

package bantec;

import java.sql.SQLException;

import java.util.logging.Level;

import java.util.logging.Logger; import javax.swing.JOptionPane;

/** **/

public class Servicio extends SQLQUERY{

String nc;

public Servicio(String t){

this.nc=t;

public void Cuenta(String cuenta){

this.nc=cuenta;

try { Inicio();

if (this.datos.next()){

System.out.println("Numero cuenta: "+this.datos.getString("no_cuenta")+ "\n Nombre: "+this.datos.getString("nombre")+ "\n Apellido paterno: "+this.datos.getString("apellido_p")+ "\n Apellido materno: "+this.datos.getString("apellido_m")+ "\n Saldo: "+this.datos.getString("saldo")+ "\n Sucursal: "+this.datos.getString("sucursal_id"));

JOptionPane.showMessageDialog(null,"Numero cuenta: "+this.datos.getString("no_cuenta")+ "\n Nombre: "+this.datos.getString("nombre")+ this.datos.getString("apellido_p")+ this.datos.getString("apellido_m")+ "\n Saldo: "+this.datos.getString("saldo")+ "\n Sucursal: "+this.datos.getString("sucursal_id"),"BANTEC",JOptionPane.PLAIN_MESSAGE); } } catch (ClassNotFoundException ex) { Logger.getLogger(Servicio.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) {

Logger.getLogger(Servicio.class.getName()).log(Level.SEVERE, null, ex); } } public void Deposito(double dp) { double gs; try { Inicio(); if (this.datos.next()){ gs=this.datos.getDouble("saldo")+dp; this.consulta = this.conn.prepareStatement("UPDATE clientes set saldo="+gs+"where no_cuenta="+nc);

this.consulta.executeUpdate();

} catch (ClassNotFoundException ex) {

Logger.getLogger(Servicio.class.getName()).log(Level.SEVERE, null, ex);

} catch (SQLException ex) {

Logger.getLogger(Servicio.class.getName()).log(Level.SEVERE, null, ex); }

public void Retiro(double rt) {

double ret=0, sal=0;

String s = "saldo";

try {

Inicio();

if (this.datos.next()){

sal=this.datos.getDouble("saldo");

if (rt<=sal) {

ret=this.datos.getDouble("saldo")-rt;

this.consulta = this.conn.prepareStatement("UPDATE clientes set saldo="+ret+"where no_cuenta="+nc);

this.consulta.executeUpdate();

} else JOptionPane.showMessageDialog(null,"Usted no tiene saldo suficiente","BANTEC",JOptionPane.PLAIN_MESSAGE);

} } catch (ClassNotFoundException ex) {

Logger.getLogger(Servicio.class.getName()).log(Level.SEVERE, null, ex);

} catch (SQLException ex) {

Logger.getLogger(Servicio.class.getName()).log(Level.SEVERE, null, ex);

} }

public void Inicio()throws ClassNotFoundException, SQLException{

if("04001".equals(nc.substring(0, 5)))

{ this.conectar("127.0.0.1", "bantec", "root", "valeria");

this.consulta = this.conn.prepareStatement("SELECT * from clientes where no_cuenta="+nc);

this.datos = this.consulta.executeQuery();

} if("01001".equals(nc.substring(0, 5))) {

this.conectar("192.168.0.3", "bantec", "cliente3", "mari");

this.consulta = this.conn.prepareStatement("SELECT * from clientes where no_cuenta="+nc);

this.datos = this.consulta.executeQuery();

} if("04001".equals(nc.substring(0, 5))) {

this.conectar("192.168.0.15", "bantec", "cliente 1", "a");

this.consulta = this.conn.prepareStatement("SELECT * from clientes where no_cuenta="+nc);

this.datos = this.consulta.executeQuery(); } } }

You might also like