Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.70 KB | None | 0 0
  1. package DB3;
  2.  
  3. import java.util.Scanner;
  4. import java.sql.*;
  5.  
  6. public class Employee {
  7.  
  8.     private String username;
  9.     public Scanner scanner;
  10.     public ResultSet myRs;
  11.     Connection myConn;
  12.     Statement myStmt;
  13.  
  14.  
  15.     public Employee(String username, Scanner scanner, ResultSet myRs, Connection myConn, Statement myStmt) {
  16.         this.username = username;
  17.         this.scanner = scanner;
  18.         this.myRs = myRs;
  19.         this.myConn = myConn;
  20.         this.myStmt = myStmt;
  21.     }
  22.  
  23.  
  24.     public void run() {
  25.         while (true) {
  26.             welcome();
  27.             int taskNumber = scanner.nextInt();
  28.             if (taskNumber == -1) {
  29.                 break;
  30.             }
  31.             executeTask(taskNumber);
  32.         }
  33.         System.out.print("CalendarProgram exited.");
  34.     }
  35.  
  36.     public void executeTask(int taskNumber) {
  37.         switch (taskNumber) {
  38.         case 1:         getNextAppointment();
  39.         break;
  40.         case 2:         getNextSevenAppointments();
  41.         break;
  42.         case 3:         getAllAppointments();
  43.         break;
  44.         case 4:         addNewUser();
  45.         break;
  46.         case 5:         makeNewAppointment();
  47.         break;
  48.         case 6:         deleteUser();
  49.         break;
  50.         case 7:         getAppointmentsWithAnotherUser();
  51.         break;
  52.         case 8:         getCommonAppointmentsWithAnotherUser();
  53.         break;
  54.         case 9:         addUserToAppointment();
  55.         break;
  56.         case 10:        editAppointment();
  57.         break;
  58.         default:        break;
  59.         }
  60.     }
  61.  
  62.     public void getNextAppointment() {
  63.         return;
  64.     }
  65.  
  66.  
  67.     public void getNextSevenAppointments() {
  68.         return;
  69.     }
  70.  
  71.     public void getAllAppointments() {
  72.         return;
  73.     }
  74.  
  75.     public void addNewUser() {
  76.         return;
  77.     }
  78.  
  79.     public void makeNewAppointment() {
  80.  
  81.         System.out.println("Når starter avtalen? (HH:MM)");
  82.         String avtaleStart = scanner.next();
  83.         System.out.println("Når slutter avtalen? (HH:MM)");
  84.         String avtaleSlutt = scanner.next();
  85.         System.out.println("Hvilken dato er avtalen? (DD/MM/YY)");
  86.         String avtaleDato = scanner.next();
  87.         System.out.println("Gi en kort beskrivelse av avtalen (Sted, osv.)");
  88.         String beskrivelse = scanner.next();
  89.         System.out.println("Vil du legge til andre brukere til avtalen? (Ja/Nei)");
  90.         String svar = scanner.next();
  91.         while (svar.equalsIgnoreCase("ja") || svar.equalsIgnoreCase("j")) {
  92.             System.out.println("Skriv inn brukernavn til brukeren du vil legge til:");
  93.             String addBruker = scanner.next();
  94.         }
  95.  
  96.         return;
  97.     }
  98.  
  99.     public void deleteUser() {
  100.         try {
  101.             System.out.println( "===========" );
  102.             System.out.println( "Delete user" );
  103.             System.out.println( "===========" );
  104.             System.out.println( "Please enter the username of the user you want to delete: " );
  105.             String toBeDeleted = scanner.next();
  106.             String query = "DELETE FROM ansatt WHERE brukernavn = '" + toBeDeleted + "';";
  107.             ResultSet rs = myStmt.executeQuery(query);
  108.             System.out.println( "User " + rs.getString("brukernavn") +  " successfully deleted.");
  109.         }
  110.         catch (Exception e) {
  111.  
  112.         }
  113.     }
  114.  
  115.     public void getAppointmentsWithAnotherUser() {
  116.         return;
  117.     }
  118.  
  119.     public void getCommonAppointmentsWithAnotherUser() {
  120.         return;
  121.     }
  122.  
  123.     public void addUserToAppointment() {
  124.         return;
  125.     }
  126.  
  127.     public void editAppointment() {
  128.         return;
  129.     }
  130.  
  131.     public void welcome() {
  132.         System.out.println("\nHi " + username + "! Here is the menu:");
  133.         System.out.println("1 - My next appointment");
  134.         System.out.println("2 - My appointments the next 7 days");
  135.         System.out.println("3 - List all my appointments");
  136.         System.out.println("4 - Add new user");
  137.         System.out.println("5 - Make new appointment");
  138.         System.out.println("6 - Delete user");
  139.         System.out.println("7 - Find participants in appointment");
  140.         System.out.println("8 - Common appointments with another user");
  141.         System.out.println("9 - Add user to appointment");
  142.         System.out.println("10 - Edit appointment");
  143.         System.out.println("-1 - Exit CalendarProgram");
  144.     }
  145.  
  146.     public String getUsername() {
  147.         return username;
  148.     }
  149.  
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement