예제 #1
0
  private static void ModifyWorks() throws ClassNotFoundException, SQLException {
    Scanner input = new Scanner(System.in);
    String option = new String();
    String var = new String();
    String val = new String();
    System.out.println("Modification of works");
    System.out.println("What is the work you which to modify");
    ArrayList<Work> selection = SelectWorks();
    System.out.println("The works you wish to modify are the following");
    DisplayWorks(selection);
    System.out.println("");
    System.out.println("What is the variable you which to modify?");
    System.out.println(
        "For the ID, enter 'I'. For the author ID, enter 'A'. For the title, enter 'T'. "
            + "For the date of first publication, enter 'P'. For the original language, enter 'L'");
    option = input.nextLine();
    switch (option) {
      case "I":
        var = "workid";
        break;
      case "A":
        var = "authorid";
        break;
      case "T":
        var = "title";
        break;
      case "P":
        var = "first_publication";
        break;
      case "L":
        var = "original_language";
        break;
      default:
        System.out.println("The value entered is not valid, please enter a correct one");
    }
    System.out.println("");
    System.out.println("What is the new value of this variable? ");
    val = input.nextLine();
    if (var.equals("authorid")) {
      while (libraryDAO.getAuthorFromQuery("authorid", val).isEmpty()) {
        System.out.println("This ID doesn't exist, please enter a valid ID");
        val = input.nextLine();
      }
    }

    libraryDAO.modifyWorkInQuery(selection, var, val);
  }
예제 #2
0
  private static void AddWorks() throws ClassNotFoundException, SQLException {
    Scanner input = new Scanner(System.in);
    String val = new String();
    String opt = new String();
    System.out.println("Addition of works");
    Work a = new Work();
    System.out.println("Please enter the ID of the new work");
    val = input.nextLine();
    while (!libraryDAO.getWorkFromQuery("workid", val).isEmpty()) {
      System.out.println("This ID is already used, please enter a valid ID");
      val = input.nextLine();
    }
    a.setWorkid(val);
    System.out.println("Is the author of this work a new author? (Y/N)");
    opt = input.nextLine();
    if (opt.equals("Y")) {
      ManageAuthors.AddAuthors();
    }
    System.out.println(" ");
    System.out.println("Please enter the ID of the author of the work");
    val = input.nextLine();
    while (libraryDAO.getAuthorFromQuery("authorid", val).isEmpty()) {
      System.out.println("This ID doesn't exist, please enter a valid ID");
      val = input.nextLine();
    }
    a.setAuthorid(val);

    System.out.println("");
    System.out.println("Please enter the title of the work");
    a.setTitle(input.nextLine());
    System.out.println("");
    System.out.println("Please enter the date of first publication of the work");
    a.setFirstPublication(input.nextLine());
    System.out.println("");
    System.out.println("Please enter the original language of the work");
    a.setOrigLanguage(input.nextLine());
    System.out.println("");
    System.out.println("The new work is:");
    a.toDisplay();
    libraryDAO.setWorkToQuery(a);
  }
예제 #3
0
 private static void DeleteWorks() throws ClassNotFoundException, SQLException {
   Scanner input = new Scanner(System.in);
   String option = new String();
   System.out.println("Deletion of works");
   ArrayList<Work> selection = SelectWorks();
   System.out.println("");
   System.out.println("The following works will be deleted.");
   DisplayWorks(selection);
   System.out.println("Do you confirm?");
   option = input.nextLine();
   if (option.equals("Y")) {
     for (Work a : selection) {
       libraryDAO.deleteWorkByQuery(a);
     }
   } else {
     System.out.println("The works were not deleted");
   }
 }
예제 #4
0
 private static ArrayList<Work> SelectWorks() throws ClassNotFoundException, SQLException {
   Scanner input = new Scanner(System.in);
   String id = new String();
   String var = new String();
   String val = new String();
   String option = new String();
   System.out.println("Selection of works");
   System.out.println("To search based on the ID, enter 'I'");
   System.out.println("To search based on the author ID, enter 'A'");
   System.out.println("To search based on the title, enter 'T'");
   System.out.println("To search based on the date of first publication, enter 'P'");
   System.out.println("To search based on the original language, enter 'L'");
   System.out.println("To quit this menu, enter 'Q'");
   option = input.nextLine();
   System.out.println("");
   switch (option) {
     case "I":
       var = "workid";
       break;
     case "A":
       var = "authorid";
       break;
     case "T":
       var = "title";
       break;
     case "P":
       var = "first_publication";
       break;
     case "L":
       var = "original_language";
       break;
     case "Q":
       break;
     default:
       System.out.println("The value entered is not valid, please enter a correct one");
       ;
   }
   System.out.println("Please enter the value you are look for");
   val = input.nextLine();
   System.out.println("");
   return libraryDAO.getWorkFromQuery(var, val);
 }
예제 #5
0
 private static void SummaryWorks() throws ClassNotFoundException, SQLException {
   Scanner input = new Scanner(System.in);
   String option = new String();
   System.out.println("Summary of Works");
   System.out.println("To display all works, enter 'A'");
   System.out.println("To select an specific work, enter 'S'");
   System.out.println("To quit this menu, enter 'Q'");
   option = input.nextLine();
   System.out.println("");
   switch (option) {
     case "A":
       DisplayWorks(libraryDAO.getAllWorks());
       break;
     case "S":
       DisplayWorks(SelectWorks());
       break;
     case "Q":
       break;
     default:
       System.out.println("The value entered is not valid, please enter a correct one");
       ;
   }
 }