daily pastebin goal
44%
SHARE
TWEET

Guest

a guest Sep 26th, 2016 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package group_project;
  2.  
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.sql.Statement;
  7. import java.text.ParseException;
  8. import java.text.SimpleDateFormat;
  9. import java.util.Date;
  10.  
  11. public class Guest extends Admin {
  12.     String userOnline;
  13.    
  14.     public Guest() {
  15.        
  16.     }
  17.    
  18.    
  19.     public String getDateUpdate() throws SQLException {
  20.         String query = "SELECT DateUpdate FROM extra_service WHERE ID = ?";
  21.         PreparedStatement statement = getConnection().prepareStatement(query);
  22.         statement.setInt(1, getId());
  23.         ResultSet rs = statement.executeQuery();
  24.         if (rs.next()) {
  25.             dateUpdate = rs.getString(1);
  26.         }
  27.         return dateUpdate;
  28.     }
  29.    
  30.    
  31.    
  32.     /* @author Jasmin Bektic
  33.      *
  34.      * Method acting like LogIn form */
  35.     public void logIn() throws Exception {
  36.         Statement s = getConnection().createStatement();
  37.         s.executeQuery("SELECT UserName, Password FROM information");
  38.         ResultSet rs = s.getResultSet();
  39.  
  40.         //username and pass input
  41.         boolean boo = true;
  42.         while (boo) {
  43.             System.out.println("Enter username:");
  44.             userName = input.next();
  45.             System.out.println("Enter password:");
  46.             password = input.next();
  47.            
  48.             //Processing current data and comparing to data from database
  49.             while (rs.next()) {
  50.                 String user = rs.getString("UserName");
  51.                 String pass = rs.getString("Password");
  52.                 if (userName.equals(user) && password.equals(pass)) {
  53.                     boo = false;
  54.                     break;
  55.                 }
  56.             }
  57.             //Supporting message, in case of input failure
  58.             if (boo == true) System.out.println("Incorrect user name or password, try again:");
  59.         }
  60.         System.out.println();
  61.        
  62.         //Add username in array
  63.         PreparedStatement statement = getConnection().prepareStatement("SELECT UserName FROM information WHERE information.UserName = ?");
  64.         statement.setString(1, userName);
  65.         userOnline = (rs.getString(1));
  66.         rs.close ();
  67.         s.close ();
  68.         setList(userOnline);
  69.     }
  70.    
  71.     /* Method acts like LogOut form */
  72.     public void logOut() {
  73.         list.remove(list.size() - 1);
  74.         // ovdje ide metoda za glavni meni
  75.     }
  76.    
  77.     /* @author Jasmin Bektic
  78.      *
  79.      * Method used for guest order option */
  80.     public void orderExtraService() throws SQLException, ParseException {
  81.         int[] extraService = new int[5];
  82.         int sum = 0;
  83.        
  84.         //Getting old extra service prices and sum
  85.         String query = "SELECT Gym, Cinema, Restaurant, Pool, Sauna FROM extra_service WHERE ID = ?";
  86.         PreparedStatement statement = getConnection().prepareStatement(query);
  87.         statement.setInt(1, getId());
  88.         ResultSet rs = statement.executeQuery();
  89.         while (rs.next()) {
  90.             for (int i = 0; i < 5; i++) {
  91.                 extraService[i] = rs.getInt(i + 1);
  92.                 sum += rs.getInt(i + 1);
  93.             }
  94.         }
  95.        
  96.         //Updating extra service list
  97.         System.out.println("1- Gym\n2- Cinema\n3- Restaurant\n4- Pool\n5- Sauna\n\n0- Finish my order");
  98.         int index = 0;
  99.         while (true) {
  100.             System.out.println("Order service entering adequate number or finish your order:");
  101.             index = input.nextInt();
  102.             if (index == 0) break;
  103.             extraService[index - 1] = this.extraService[index - 1];
  104.         }
  105.        
  106.         //Current date and time
  107.         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  108.         Date date = new Date();
  109.         String orderDate = df.format(date);
  110.         Date d1 = df.parse(getDateUpdate());
  111.         Date d2 = df.parse(orderDate);
  112.        
  113.         //Number of days between current date and checkIn date (time is default, 12:00:00)
  114.         long diff = d2.getTime() - d1.getTime();
  115.         long diffDays = diff / (24 * 60 * 60 * 1000);
  116.         String dateTime = orderDate.substring(0, 10) + " 12:00:00";
  117.         int balance = 0;
  118.         if (diffDays == 0) {
  119.             balance = sum;
  120.         } else
  121.             balance = (int) (diffDays * sum);
  122.        
  123.         //Update query with specified ID
  124.         String sql = "UPDATE extra_service SET Gym = ?, Cinema= ?, Restaurant= ?, Pool = ?, Sauna = ?, Balance = ?, DateUpdate = ? WHERE ID = ?";
  125.         PreparedStatement s = getConnection().prepareStatement(sql);
  126.         s.setInt(1, extraService[0]);
  127.         s.setInt(2, extraService[1]);
  128.         s.setInt(3, extraService[2]);
  129.         s.setInt(4, extraService[3]);
  130.         s.setInt(5, extraService[4]);
  131.         s.setInt(6, balance);
  132.         s.setString(7, dateTime);
  133.         s.setInt(8, getId());
  134.         s.executeUpdate();
  135.     }
  136. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top