Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package yomusico;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Scanner;
- /**
- *
- * @author cristian
- */
- public class Yomusico {
- static Scanner teclado = new Scanner(System.in);
- // CONEXIÓN A LA BASE DE DATOS
- static String servidor = "jdbc:mysql://localhost/yomusico";
- static String usuario = "root";
- static String contraseña = "1234";
- private static String num;
- private static void menu() {
- Integer op;
- do {
- System.out.println("-----------------------------------\n"
- + "||Menu Principal ||\n"
- + "-----------------------------------\n"
- + "|1.Empleados |\n"
- + "|2.Tiendas |\n"
- + "|3.Pedidos |\n"
- + "|4.Clientes |\n"
- + "|5.Instrumentos |\n"
- + "|0.Salir |\n"
- + "-----------------------------------");
- op = teclado.nextInt();
- if (op == null) {
- op = 100;
- }
- switch (op) {
- case 1:
- Empleados();
- break;
- case 2:
- Tiendas();
- break;
- case 3:
- Pedidos();
- break;
- case 4:
- Clientes();
- break;
- case 5:
- Instrumentos();
- break;
- case 0:
- System.out.println("Saliendo...\n\nHasta Pronto");
- break;
- default:
- System.out.println("Opcion no valida");
- }
- } while (op != 0);
- }
- // TABLA EMPLEADOS
- private static void Empleados() {
- Integer op;
- do {
- System.out.println("-----------------------------------\n"
- + "||Menu Principal ||\n"
- + "-----------------------------------\n"
- + "|1.Mostrar Empleados |\n"
- + "|2.Tiendas |\n"
- + "|3.Pedidos |\n"
- + "|4.Clientes |\n"
- + "|5.Instrumentos |\n"
- + "|0.Salir |\n"
- + "-----------------------------------");
- op = teclado.nextInt();
- if (op == null) {
- op = 100;
- }
- switch (op) {
- case 1:
- mostrarEmpleados();
- break;
- case 2:
- añadirEmpleados();
- break;
- case 3:
- eliminarEmpleados();
- break;
- case 4:
- modificarEmpleados();
- case 0:
- System.out.println("Volviendo...\n");
- break;
- default:
- System.out.println("Opcion no valida");
- }
- } while (op != 0);
- }
- private static void mostrarEmpleados(Statement sentencia, String empleado) {
- try {
- Scanner sc = new Scanner(System.in);
- System.out.println("Introduce el nombre del Empleado a buscar:");
- empleado = sc.nextLine();
- String sentenciaSQL = "SELECT * FROM Empleados where nombre =\'" + empleado + "\'";
- ResultSet rs = sentencia.executeQuery(sentenciaSQL);
- while (rs.next()) {
- String res = rs.getString("numemp") + "\t "
- + rs.getString("nombre") + "\t"
- + rs.getString("edad") + "\t"
- + rs.getString("oficina") + "\t"
- + rs.getString("titulo") + "\t"
- + rs.getString("contrato") + "\t"
- + rs.getString("jefe") + "\t"
- + rs.getString("cuota") + "\t"
- + rs.getString("ventas");
- System.out.println(res);
- }
- if (!existeEmpleado(sentencia, empleado)) {
- System.out.println("No existe este Empleado.");
- } else {
- mostrarEmpleados(sentencia, empleado);
- }
- } catch (SQLException ex) {
- System.out.println("Error SQL");
- }
- }
- static boolean existeEmpleado(Statement sentencia, String empleado) {
- boolean existe = false;
- String s = "SELECT * FROM Empleado WHERE nombre=\'" + empleado + "\'";
- ResultSet rs;
- try {
- rs = sentencia.executeQuery(s);
- if (rs.next()) {
- existe = true;
- } else {
- existe = false;
- }
- } catch (SQLException ex) {
- }
- return existe;
- }
- private static void añadirEmpleados() {
- System.out.println("Registrar Empleado");
- String consulta;
- System.out.println("Introduce la referencia");
- int ref = teclado.nextInt();
- //comprobar si el suelo existe
- if (!repetido("Suelos", "ref", ref)) {
- System.out.println("Introduce el numemp (número id): ");
- int num = teclado.nextInt();
- System.out.println("Introduce el Nombre del empleado: ");
- String nom = teclado.nextLine();
- System.out.println("Introduce la edad del empleado: ");
- int edad = teclado.nextInt();
- System.out.println("Introduce la tienda donde trabaja el Empleado a introducir: ");
- String tien = teclado.nextLine();
- System.out.println("Introduce el trabajo que realiza el empleado: ");
- String ejer = teclado.nextLine();
- System.out.println("Introduce la fecha del contrato de cuando se realizó: ");
- int contrato = teclado.nextInt();
- System.out.println("Introduce la cuota de dicho Empleado: ");
- String cuota = teclado.nextLine();
- System.out.println("Introduce las ventas realizada por el Empleado: ");
- String ventas = teclado.nextLine();
- consulta = "INSERT INTO Empleados VALUE ('" + num + "','" + nom + "','" + edad + "','" + tien + "','" + ejer + "','" + contrato + "' ,'" + cuota + "','" + ventas + "');";
- System.out.println("Suelo registrado");
- } else {
- System.out.println("El Empleado ya existe.");
- }
- }
- private static void eliminarEmpleados() {
- String consulta;
- System.out.println("Introduzca el numemp del Empleado que deseas eliminar: ");
- String numemp = teclado.nextLine();
- if (existe("Empleados", "numemp", numemp)) {
- System.out.println("Los Empleados con la referencia " + numemp + " son:");
- sueloCampo("numep", numemp);
- System.out.println("Desea continuar? (s/n)");
- char sn = teclado.nextLine();
- if (sn == 's') {
- consulta = "DELETE FROM Empleados WHERE numemp = '" + numemp + "';";
- System.out.println("Empleado eliminado con exito.");
- } else {
- System.out.println("Volviendo...\n");
- }
- } else {
- System.out.println("No existen Empleados con este " + numemp);
- }
- }
- private static boolean repetido(String suelos, String ref, int ref0) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- private static boolean existe(String suelos, String ref, String ref0) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- private static void sueloCampo(String numep, String numemp) {
- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
- }
- private static void modificarEmpleado() {
- Integer op;
- System.out.println("Introduzca la referencia");
- String iden = teclado.nextLine();
- if (existe("Suelos", "ref", iden)) {
- System.out.println("Los suelos con referencia: " + iden + " son:");
- sueloCampo("ref", iden);
- System.out.println("\nSe modificaran todos los suelos mostrados\nDesea continuar? (s/n)");
- String sn = teclado.nextLine();
- if (sn == 's') {
- do {
- System.out.println("-----------------------------------\n"
- + "||Modifición de Empleados ||\n"
- + "-----------------------------------\n"
- + "|1.Modificar Nombre |\n"
- + "|2.Modificar Edad |\n"
- + "|3.Modificar Tienda |\n"
- + "|4.Modificar Trabajo que ejerce |\n"
- + "|5.Modificar Contrato |\n"
- + "|6.Modificar Cuota |\n"
- + "|7.Modificar Ventas |\n"
- + "|0.Volver |\n"
- + "-----------------------------------");
- op = teclado.nextInt();
- if (op == null) {
- op = 100;
- } switch (op) {
- case 1:
- //Nombre
- System.out.println("Introduzca el nuevo Nombre: ");
- String nombre = teclado.nextLine();
- break;
- case 2:
- //Edad
- System.out.println("Introduzca la nueva edad: ");
- int edad = teclado.nextInt();
- break;
- case 3:
- //tienda
- System.out.println("Introduzca la nueva tienda: ");
- int tienda = teclado.nextInt();
- break;
- case 4:
- //EJERCE
- System.out.println("Introduzca el nuevo trabajo: ");
- String ejerce = teclado.nextLine();
- break;
- case 5:
- //CONTRATO
- System.out.println("Introduzca el nuevo contrato: ");
- int contrato = teclado.nextInt();
- break;
- case 6:
- //CUOTA
- System.out.println("Introduzca la nueva cuota: ");
- int cuota = teclado.nextInt();
- break;
- case 7:
- //VENTAS
- System.out.println("Introduzca las nuevas ventas: ");
- int ventas = teclado.nextInt();
- break;
- case 0:
- System.out.println("Volviendo...\n");
- break;
- default:
- System.out.println("Opcion no valida");
- }
- if (op != 100 && op != 0) {
- System.out.println("Pulse 'Intro' para continuar");
- teclado.nextLine();
- }
- } while (op != 0);
- } else {
- System.out.println("Volviendo...\n");
- }
- } else {
- System.out.println("No exiten Empleados con la referencia " + iden);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement