diff --git a/Additional files/.DS_Store b/Additional files/.DS_Store new file mode 100644 index 0000000..ceaf9cb Binary files /dev/null and b/Additional files/.DS_Store differ diff --git a/Additional files/Java file/Auction.java b/Additional files/Java file/Auction.java new file mode 100644 index 0000000..0be459b --- /dev/null +++ b/Additional files/Java file/Auction.java @@ -0,0 +1,1164 @@ +import java.io.Console; +import java.io.InputStream; +import java.math.BigDecimal; +import java.sql.*; +import java.util.Date; +import java.util.Scanner; +import java.util.concurrent.TimeUnit; +import java.util.*; + +public class Auction { + static String url = "jdbc:mysql://localhost:3306/auction_house?autoReconnect=true&useSSL=false"; + static String dbuname = "root"; + static String dbpass = "admin"; + static String classForName = "com.mysql.jdbc.Driver"; + + public static void main(String[] args) throws Exception { + + while (true) { + System.out.println("\b"); + System.out.println("********* Welcome to Rita's Auction House ***********"); + System.out.println("Please select your role to proceed:"); + System.out.println("1. Seller"); + System.out.println("2. Bidder"); + System.out.print("Please enter your choice: "); + + Scanner scan = new Scanner(System.in); + String fOption = scan.next(); + char[] a = fOption.toCharArray(); + int asci = (int) a[0]; + + switch (asci) { + case 49: + System.out.println("\n1. Sign-in"); + System.out.println("2. Register"); + System.out.print("Please enter your choice: "); + int sOption = scan.nextInt(); + + switch (sOption) { + case 1: + int auth = authenticate(49); + switch (auth) { + case 0: + System.out.println("Username/Password did not match. Please try again."); + break; + default: + int sellerOption = 0; + while (sellerOption != 10) { + System.out.println("\n Welcome back seller !"); + System.out.println("1. Submit item(s) for auction"); + System.out.println("2. Set/change base price for your submitted item"); + System.out.println("3. Set time duration for auction"); + System.out.println("4. View all the running auctions"); + System.out.println("5. View (approval) status of your items"); + System.out.println("6. View all the bids for your item"); + System.out.println("7. View earnings (after auction)"); + System.out.println("8. Withdraw item from auction"); + System.out.println("9. View withdrawn items"); + System.out.println("10. Exit"); + System.out.println("\b"); + System.out.print("Please enter your choice: "); + sellerOption = scan.nextInt(); + switch (sellerOption) { + case 1: + sellerSubmitItem(auth); + break; + case 2: + sellerSetBasePrice(auth); + break; + case 3: + sellerSetTime(auth); + break; + case 4: + sellerViewRunningAuctions(auth); + break; + case 5: + sellerViewItemStatus(auth); + break; + case 6: + sellerViewBids(auth); + break; + case 7: + sellerViewSellerEarnings(auth); + break; + case 8: + sellerWithdrawAuction(auth); + break; + case 9: + sellerViewWithdrawnItems(auth); + break; + } + } + } + break; + case 2: + int reg = register(49); + if (!(reg > 0)) + System.out.println("Oops ! Something went wrong. Please try again after some time."); + break; + } + break; + case 50: + System.out.println("\n1. Sign-in"); + System.out.println("2. Register"); + System.out.print("Please enter your choice: "); + int bOption = scan.nextInt(); + + switch (bOption) { + case 1: + int auth = authenticate(50); + switch (auth) { + case 0: + System.out.println("Username/Password did not match. Please try again."); + break; + default: + int bidderOption = 0; + while (bidderOption != 5) { + System.out.println("\n Welcome back bidder !"); + System.out.println("1. View available and running auctions"); + System.out.println("2. View my bids"); + System.out.println("3. Bid for an auction"); + System.out.println("4. View bought items"); + System.out.println("5. Exit"); + System.out.println("\b"); + System.out.print("Please enter your choice: "); + bidderOption = scan.nextInt(); + switch (bidderOption) { + case 1: + bidderAvailAucs(auth); + break; + case 2: + bidderMyBids(auth); + break; + case 3: + bidderBid(auth); + break; + case 4: + bidderBought(auth); + break; + } + } + } + break; + case 2: + int reg = register(50); + if (!(reg > 0)) + System.out.println("Oops ! Something went wrong. Please try again after some time."); + break; + } + break; + case 97: + System.out.println("\b"); + System.out.println("Hello Rita !"); + int auth = authenticate(97); + switch (auth) { + case 0: + System.out.println("Username/Password did not match. Please try again."); + break; + default: + int adminOption = 0; + while (adminOption != 6) { + System.out.println("\n Welcome back admin !"); + System.out.println("1. Accept seller auction request"); + System.out.println("2. Start timer for an auction"); + System.out.println("3. View all running auctions and bids"); + System.out.println("4. View all sold products and earnings"); + System.out.println("5. View all withdrawn items from auction"); + System.out.println("6. Exit"); + System.out.println("\b"); + System.out.print("Please enter your choice: "); + adminOption = scan.nextInt(); + switch (adminOption) { + case 1: + adminAcceptSeller(); + break; + case 2: + adminStartTimer(); + break; + case 3: + adminViewAucBid(); + break; + case 4: + adminViewSoldEarn(); + break; + case 5: + adminViewWithdrawn(); + break; + } + } + } + break; + } + } + } + + private static void bidderBought(int auth) throws Exception { + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select id, pname, des, baseprice, BidValue from product where endTime < (select NOW()) and approved = 1 and lastBidder = " + + auth; + ResultSet rs = st.executeQuery(query1); + System.out.println("\b"); + int i = 0; + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%3s%13s%20s%28s%15s%14s\n","S.No","Product ID","Product Name","Product Description","Base Price","Your Bid"); + } + System.out.printf("%2d%11d%23s%30s%13s%14s\n",i,rs.getInt(1),rs.getString(2),rs.getString(3),"$ "+rs.getString(4),"$ "+rs.getString(5)); + } + if (i == 0) { + System.out.println( + "You haven't been sold any items yet. Reasons:\n1. You have not placed any bid.\n2. The auction is not over yet.\nPlease check back in some time."); + } + st.close(); + con.close(); + } + + private static void bidderBid(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select id, pname, des, baseprice, BidValue, endTime from product where endTime > (select NOW()) and approved = 1 "; + ResultSet rs = st.executeQuery(query1); + System.out.println("\b"); + int i = 0; + LinkedHashMap lhm = new LinkedHashMap(); + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%5s%15s%30s%45s%23s%18s%25s\n","S.No","Product ID","Product Name","Product Description","Base Price","Last Bid","Valid For"); + } + if (rs.getDouble(5) > rs.getDouble(4)) + lhm.put((int) rs.getInt(1), rs.getDouble(5)); + else + lhm.put((int) rs.getInt(1), rs.getDouble(4)); + + Date end = rs.getTimestamp(6); + Date today = new Date(); + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(end); + long endMili = calendar.getTimeInMillis(); + + calendar.setTime(today); + long todayMili = calendar.getTimeInMillis(); + long millis = endMili - todayMili; + + long days = TimeUnit.MILLISECONDS.toDays(millis); + millis -= TimeUnit.DAYS.toMillis(days); + long hours = TimeUnit.MILLISECONDS.toHours(millis); + millis -= TimeUnit.HOURS.toMillis(hours); + long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); + millis -= TimeUnit.MINUTES.toMillis(minutes); + long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); + + StringBuilder sb = new StringBuilder(64); + if (days != 0) { + sb.append(days); + sb.append(" days "); + } + if (hours != 0) { + sb.append(hours); + sb.append(" hrs "); + } + if (minutes != 0) { + sb.append(minutes); + sb.append(" mins "); + } + if (seconds != 0) { + sb.append(seconds); + sb.append(" secs"); + } + + String duration = sb.toString(); + + System.out.printf("%4s%12s%35s%50s%17s%17s%33s\n",i,rs.getInt(1),rs.getString(2),rs.getString(3),"$ "+rs.getString(4),"$ "+rs.getString(5),duration); + } + + if (i > 0) { + System.out.print("Product ID: "); + int prodId = scan.nextInt(); + int myBid = 0; + Set set = lhm.entrySet(); + Iterator itr = set.iterator(); + double val = 0; + while (itr.hasNext()) { + Map.Entry me = (Map.Entry) itr.next(); + if (prodId == (int) me.getKey()) { + val = (double) me.getValue(); + break; + } + } + + System.out.print("Your Bid (with 2 decimal places): $ "); + double newBid = scan.nextDouble(); + while (newBid < val) { + System.out.println( + "New bid cannot be lesser than the base price/original bid.\nPlease enter a bigger bid: $ "); + newBid = scan.nextDouble(); + } + + String query2 = "update product set BidValue = " + newBid + ", lastBidder = '" + auth + "' where id = " + + prodId + " and endTime > (select NOW()) and approved = 1"; + int ret = st.executeUpdate(query2); + + switch (ret) { + case 0: + System.out.println("Cannot bid on this product now. \nPlease select another product."); + break; + case 1: + String query3 = "insert into bidder_bids(uname, productId, bidValue, placed, wen) values (" + auth + "," + + prodId + "," + newBid + ", 1, (select NOW()))"; + int result = st.executeUpdate(query3); + if (result == 1) { + System.out.println("\b"); + System.out.println("Your bid has been successfully placed !"); + } + break; + } + } else { + System.out.println("\b"); + System.out.println("Sorry, no active auctions found!"); + } + st.close(); + con.close(); + } + + private static void bidderMyBids(int auth) throws Exception { + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select B.id, B.productId, P.pname, B.bidValue , B.wen from bidder_bids B inner join product P on B.productId = P.id where P.approved = 1 and uname = " + + auth + " ORDER BY B.id DESC"; + ResultSet rs = st.executeQuery(query1); + int i = 0; + System.out.println("\b"); + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%3s%17s%14s%17s\n","S.No","Product Name","Bid Value","Time"); + } + System.out.printf("%2d%19s%13s%27s\n",i,rs.getString(3),"$ "+rs.getString(4),rs.getString(5)); + } + if (i == 0) { + System.out.println("You don't have active bids at this moment!"); + } + st.close(); + con.close(); + } + + private static void bidderAvailAucs(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select id, pname, des, baseprice, BidValue, endTime from product where endTime > (select NOW()) and approved = 1"; + ResultSet rs = st.executeQuery(query1); + System.out.println("\b"); + int i = 0; + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%5s%15s%30s%45s%23s%18s%25s\n","S.No","Product ID","Product Name","Product Description","Base Price","Last Bid","Valid For"); + } + Date end = rs.getTimestamp(6); + Date today = new Date(); + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(end); + long endMili = calendar.getTimeInMillis(); + + calendar.setTime(today); + long todayMili = calendar.getTimeInMillis(); + long millis = endMili - todayMili; + + long days = TimeUnit.MILLISECONDS.toDays(millis); + millis -= TimeUnit.DAYS.toMillis(days); + long hours = TimeUnit.MILLISECONDS.toHours(millis); + millis -= TimeUnit.HOURS.toMillis(hours); + long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); + millis -= TimeUnit.MINUTES.toMillis(minutes); + long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); + + StringBuilder sb = new StringBuilder(64); + if (days != 0) { + sb.append(days); + sb.append(" days "); + } + if (hours != 0) { + sb.append(hours); + sb.append(" hrs "); + } + if (minutes != 0) { + sb.append(minutes); + sb.append(" mins "); + } + if (seconds != 0) { + sb.append(seconds); + sb.append(" secs "); + } + + String duration = sb.toString(); + + System.out.printf("%4s%12s%35s%50s%17s%17s%33s\n",i,rs.getInt(1),rs.getString(2),rs.getString(3),"$ "+rs.getString(4),"$ "+rs.getString(5),duration); + } + if (i == 0) { + System.out.println("Sorry, no active auctions at this moment!"); + } + st.close(); + con.close(); + } + + private static void sellerViewWithdrawnItems(int auth) throws Exception{ + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + System.out.println("\b"); + String query2 = "select W.productId, W.pname, W.uname, W.wen, W.baseprice, W.lastbid from withdraws W inner join seller_sells S on W.productId = S.productId where S.uname = "+auth; + ResultSet rs2 = st.executeQuery(query2); + int i = 0; + while(rs2.next()){ + i++; + if (i == 1) { + System.out.printf("%10s%22s%20s%20s%25s%15s\n","Product ID","Product Name","Reason","When","Base Price","Last Bid"); + } + String reason = ""; + if(rs2.getInt(3) == 0) + reason = "No bids/Timeout"; + else + reason = "Self"; + String val = ""; + if(rs2.getString(6) == null){ + val = "0.00"; + } + else{ + val = rs2.getString(6); + } + System.out.printf("%6s%27s%23s%25s%14s%17s\n",rs2.getInt(1),rs2.getString(2),reason,rs2.getString(4),"$ "+rs2.getString(5),"$ "+val); + } + if(i==0){ + System.out.println("No item has been withdrawn!"); + } + } + + private static void sellerWithdrawAuction(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + System.out.println("\b"); + String query2 = "select S.productId, P.pname, P.baseprice, P.BidValue from seller_sells S inner join product P on S.productId = P.id where P.endTime > (SELECT NOW()) and P.approved = 1 and S.uname = " + + auth; + ResultSet rs2 = st.executeQuery(query2); + LinkedHashMap lhm = new LinkedHashMap(); + int l = 0; + while (rs2.next()) { + l++; + if (l == 1) { + System.out.printf("%8s%25s%18s%20s\n","Product ID","Product Name","Base Price","Current Bid Value"); + } + System.out.printf("%7s%31s%14s%18s\n",rs2.getInt(1),rs2.getString(2),"$ "+rs2.getString(3),"$ "+rs2.getString(4)); + lhm.put(rs2.getInt(1), rs2.getString(2) + " " + rs2.getString(3) + " " + rs2.getString(4)); + } + if (l > 0) { + System.out.println("\b"); + System.out.print("Enter Product ID to withdraw: "); + int n = scan.nextInt(); + Set set = lhm.entrySet(); + Iterator itr = set.iterator(); + String name = ""; + double base = 0.00; + double bidV = 0.00; + while (itr.hasNext()) { + Map.Entry me = (Map.Entry) itr.next(); + int key = (int) me.getKey(); + if (n == key) { + String value = me.getValue().toString(); + String[] ar = value.split(" "); + name = ar[0]; + base = Double.parseDouble(ar[ar.length - 2]); + bidV = Double.parseDouble(ar[ar.length - 1]); + } + } + + String query3 = "update product set approved = 0 where id = " + n; + int ret = st.executeUpdate(query3); + if (ret == 0) { + System.out.println("\b"); + System.out.println("Could not delete auction request.\nPlease try again later."); + } else { + System.out.println("\b"); + System.out.println("Product from auction : "); + + String query4 = "insert into withdraws(productId, pname, uname, wen, baseprice, lastbid) values (" + n + + ",'" + name + "'," + auth + ",(select NOW())," + base + "," + bidV + ")"; + int result = st.executeUpdate(query4); + switch (result) { + case 0: + System.out.println("Could not insert. try again later"); + break; + case 1: + System.out.print("Success !"); + break; + } + } + } else { + System.out.println("\b"); + System.out.println("Sorry, no item can be withdrawn from auction at this time!"); + } + + st.close(); + con.close(); + } + + private static void sellerViewSellerEarnings(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + System.out.println("\b"); + String query2 = "select P.pname, (0.95*P.BidValue) as earning from product P inner join seller_sells S on S.productId = P.id where P.endTime < (SELECT NOW()) and P.approved = 1 and S.uname = " + + auth; + ResultSet rs2 = st.executeQuery(query2); + double earning = 0.00; + int i = 0; + while (rs2.next()) { + i++; + if (i == 1) { + System.out.printf("%20s%20s\n","Product Name","Earnings"); + } + BigDecimal bd = new BigDecimal(String.valueOf(rs2.getDouble(2))).setScale(2, BigDecimal.ROUND_FLOOR); + System.out.printf("%20s%19s\n",rs2.getString(1),"$ "+bd); + earning += rs2.getDouble(2); + } + System.out.println("\b"); + BigDecimal bd = new BigDecimal(String.valueOf(earning)).setScale(2, BigDecimal.ROUND_FLOOR); + System.out.println("Total earning: $ " + bd); + st.close(); + con.close(); + } + + private static void sellerViewRunningAuctions(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + System.out.println("\b"); + String query2 = "select id, pname, baseprice, BidValue, startTime, endTime from product P where endTime > (SELECT NOW()) and approved = 1"; + ResultSet rs2 = st.executeQuery(query2); + int i = 0; + while (rs2.next()) { + i++; + if (i == 1) { + System.out.printf("%8s%25s%18s%16s%24s%24s\n","Product ID","Product Name","Base Price","Last Bid","Start Time","End Time"); + } + System.out.printf("%7s%31s%14s%16s%28s%28s\n",rs2.getInt(1),rs2.getString(2),"$ "+rs2.getString(3),rs2.getString(4),rs2.getString(5),rs2.getString(6)); + } + if (i == 0) { + System.out.println("No active auctions found!"); + } + st.close(); + con.close(); + } + + private static void sellerViewItemStatus(int auth) throws Exception { + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select S.productId, P.pname, P.approved from seller_sells S inner join product P on S.productId = P.id where uname = " + + auth; + ResultSet rs = st.executeQuery(query1); + int i = 0; + System.out.println("\b"); + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%8s%22s%30s\n","Product ID","Product Name","Approval Status"); + } + int status = rs.getInt(3); + String stat = ""; + if (status == 0) + stat = "Pending approval/Item withdrawn"; + else + stat = "Approved"; + System.out.printf("%4d%28s%36s\n",rs.getInt(1),rs.getString(2),stat); + } + if (i == 0) { + System.out.println("Please submit items for auction."); + } + st.close(); + con.close(); + } + + private static void sellerViewBids(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + System.out.println("\b"); + String query2 = "select S.productId, P.pname, B.bidValue, B.wen from seller_sells S inner join bidder_bids B on S.productId = B.productId inner join product P on S.productId = P.id where S.uname = " + + auth + " ORDER BY productId DESC, wen DESC"; + ResultSet rs2 = st.executeQuery(query2); + int k = 0; + while (rs2.next()) { + k++; + if (k == 1) { + System.out.printf("%10s%20s%20s%20s\n","Product ID","Product Name","Bid Value","Time"); + } + System.out.printf("%4d%26s%19s%28s\n",rs2.getInt(1),rs2.getString(2),"$ "+rs2.getString(3),rs2.getString(4)); + } + if (k == 0) + System.out.println("No bids received for any of your items."); + st.close(); + con.close(); + } + + private static void sellerSetTime(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query2 = "select S.productId, P.pname, P.duration from seller_sells S inner join product P on S.productId = P.id where P.sold = 0 and P.endTime > (SELECT NOW()) and S.uname = " + + auth; + ResultSet rs2 = st.executeQuery(query2); + System.out.println("\b"); + int j = 0; + String duration = ""; + while (rs2.next()) { + j++; + if (j == 1) { + System.out.printf("%10s%25s%25s\n","Product ID","Product Name","Duration"); + } + long millis = rs2.getLong(3); + long days = TimeUnit.MILLISECONDS.toDays(millis); + millis -= TimeUnit.DAYS.toMillis(days); + long hours = TimeUnit.MILLISECONDS.toHours(millis); + millis -= TimeUnit.HOURS.toMillis(hours); + long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); + millis -= TimeUnit.MINUTES.toMillis(minutes); + long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); + + StringBuilder sb = new StringBuilder(64); + if (days != 0) { + sb.append(days); + sb.append(" Days "); + } + if (hours != 0) { + sb.append(hours); + sb.append(" Hrs "); + } + if (minutes != 0) { + sb.append(minutes); + sb.append(" Mins "); + } + if (seconds != 0) { + sb.append(seconds); + sb.append(" Sec"); + } + + duration = sb.toString(); + System.out.printf("%6s%32s%30s\n",rs2.getInt(1),rs2.getString(2),duration); + } + if (j > 0) { + String quit = "Y"; + long newMilli = 0; + while (!quit.equals("N")) { + System.out.println("\b"); + System.out.print("Product number to change: "); + int opt = scan.nextInt(); + System.out.print("Enter new duration in days hrs mins secs. \n"); + System.out.print("Days: "); + int days = scan.nextInt(); + System.out.print("Hours: "); + int hours = scan.nextInt(); + System.out.print("Minutes: "); + int minutes = scan.nextInt(); + System.out.print("Seconds: "); + int seconds = scan.nextInt(); + + newMilli = TimeUnit.SECONDS.toMillis(seconds) + TimeUnit.MINUTES.toMillis(minutes) + + TimeUnit.HOURS.toMillis(hours) + TimeUnit.DAYS.toMillis(days); + + String query3 = "update product set duration = " + newMilli + " , endTime = DATE_ADD(NOW(), INTERVAL " + + (newMilli / 1000) + " second) where id = " + opt; + int ret = st.executeUpdate(query3); + if (ret == 0) { + System.out.println("No row updated !"); + } else { + System.out.println("\b"); + System.out + .print("Duration updated successfully ! \nDo you wish to make any more updates ? (Y/N): "); + quit = scan.next().toUpperCase(); + } + } + } else { + System.out.println("\b"); + System.out.println("Sorry, you haven't submitted any new items for auction !"); + } + st.close(); + con.close(); + } + + private static void sellerSetBasePrice(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con2 = DriverManager.getConnection(url, dbuname, dbpass); + Statement st2 = con2.createStatement(); + Connection con3 = DriverManager.getConnection(url, dbuname, dbpass); + Statement st3 = con3.createStatement(); + + String query2 = "select S.productId, P.pname, P.baseprice from seller_sells S inner join product P on S.productId = P.id where P.startTime IS NULL and S.uname = " + + auth; + ResultSet rs2 = st2.executeQuery(query2); + System.out.println("\b"); + int j = 0; + while (rs2.next()) { + j++; + if (j == 1) { + System.out.printf("%10s%20s%15s\n","Product ID","Product Name","Base Price"); + } + System.out.printf("%5s%20s%18s\n",rs2.getInt(1),rs2.getString(2),"$ "+rs2.getString(3)); + } + if (j > 0) { + String quit = "Y"; + while (!quit.equals("N")) { + System.out.println("\b"); + System.out.print("Product number to change: "); + int opt = scan.nextInt(); + System.out.print("New base price (with 2 decimal digits): $ "); + double newBase = scan.nextDouble(); + + String query3 = "update product set baseprice = " + newBase + " where id = " + opt; + int ret = st3.executeUpdate(query3); + if (ret == 0) { + System.out.println("No row updated !"); + } else { + System.out.println("\b"); + System.out.print( + "Base price updated successfully ! \nDo you wish to make any more updates ? (Y/N): "); + quit = scan.next().toUpperCase(); + } + } + } else { + System.out.println("\b"); + System.out.println("Sorry, you haven't submitted any new items for auction !"); + } + st3.close(); + con3.close(); + st2.close(); + con2.close(); + } + + private static void sellerSubmitItem(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + System.out.println("\b"); + System.out.println("Welcome Seller ID (" + auth + "). Please give the product details:"); + System.out.println("\b"); + System.out.print("Product Name: "); + String prodName = scan.nextLine(); + System.out.print("Product Desciption (12-15 words): "); + String prodDesc = scan.nextLine(); + prodDesc = prodDesc.substring(0, Math.min(prodDesc.length(), 98)); + System.out.print("Base Price (with 2 decimal digits): $ "); + double prodBase = scan.nextDouble(); + System.out.print("Auction Duration:\n"); + System.out.print("days: "); + int dd = scan.nextInt(); + System.out.print("hours: "); + int hh = scan.nextInt(); + System.out.print("mins: "); + int mm = scan.nextInt(); + System.out.print("seconds: "); + int ss = scan.nextInt(); + + int milliSec = ss * 1000 + (mm * 60 * 1000) + (hh * 60 * 60 * 1000) + (dd * 24 * 60 * 60 * 1000); + + String query = "insert into product(pname, des, baseprice, duration) values ('" + prodName + "','" + prodDesc + + "','" + prodBase + "','" + milliSec + "')"; + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + int count = st.executeUpdate(query, Statement.RETURN_GENERATED_KEYS); + ResultSet rs = st.getGeneratedKeys(); + int productId = 0; + if (rs.next()) { + productId = rs.getInt(1); + } + if (count == 0) { + System.out.println("Could not save data. Please try again later."); + } else { + System.out.println("\b"); + System.out.println( + "Item saved successfully ! The admin will soon approve your auction request and start the timer."); + String query2 = "insert into seller_sells(uname, productId) values (" + auth + "," + productId + ")"; + int count2 = st.executeUpdate(query2, Statement.RETURN_GENERATED_KEYS); + ResultSet rs2 = st.getGeneratedKeys(); + int requestId = 0; + if (rs2.next()) { + requestId = rs2.getInt(1); + System.out.println("\b"); + System.out.println("For reference, your request ID is " + requestId); + } + } + st.close(); + con.close(); + } + + private static void adminViewWithdrawn() throws Exception { + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select id, productId, pname, uname, wen, baseprice, lastbid from withdraws"; + ResultSet rs = st.executeQuery(query1); + System.out.println("\b"); + int i = 0; + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%5s%15s%23s%18s%20s%23s%18s\n","S.No.","Product ID","Product Name","Seller ID","Time","Base Price","Last Bid"); + } + String val = ""; + if(rs.getString(7) == null) + val = "0.00"; + else + val = rs.getString(7); + System.out.printf("%3s%14s%26s%14s%31s%15s%18s\n",rs.getInt(1),rs.getInt(2),rs.getString(3),rs.getString(4),rs.getString(5),"$ "+rs.getString(6),"$ "+val); + } + if (i == 0) { + System.out.println("No items have been withdrawn from auction!"); + } + } + + private static void adminViewSoldEarn() throws Exception { + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select id, pname, baseprice, BidValue, lastBidder from product where endTime < (select NOW()) and approved = 1"; + ResultSet rs = st.executeQuery(query1); + ResultSetMetaData rsmd = rs.getMetaData(); + int cols = rsmd.getColumnCount(); + System.out.println("\b"); + double earning = 0.00; + int i = 0; + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%10s%20s%17s%15s%20s%15s\n","Product ID","Product Name","Base Price","Last Bid","Last Bidder ID","Earning"); + } + double val = (0.05 * rs.getDouble(4)); + BigDecimal bd = new BigDecimal(String.valueOf(val)).setScale(2, BigDecimal.ROUND_FLOOR); + + System.out.printf("%6d%24s%15s%16s%15s%21s\n",rs.getInt(1),rs.getString(2),"$ "+rs.getString(3),"$ "+rs.getString(4),rs.getInt(5),"$ "+bd); + earning += (0.05 * rs.getDouble(4));; + } + System.out.println("\b"); + BigDecimal bd = new BigDecimal(String.valueOf(earning)).setScale(2, BigDecimal.ROUND_FLOOR); + System.out.println("Total earning so far: $ " + bd); + st.close(); + con.close(); + } + + private static void adminViewAucBid() throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select id, pname, baseprice, BidValue, startTime, endTime from product where endTime > (select NOW()) and approved = 1"; + ResultSet rs = st.executeQuery(query1); + System.out.println("\b"); + int i = 0; + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%8s%25s%18s%18s%24s%25s\n","Product ID","Product Name","Base Price","Last Bid","Start Time","End Time"); + } + System.out.printf("%7s%30s%16s%18s%27s%27s\n",rs.getInt(1),rs.getString(2),"$ "+rs.getString(3),"$ "+rs.getString(4),rs.getString(5),rs.getString(6)); + } + if (i > 0) { + System.out.println("\b"); + System.out.print("Enter product id to view bids: "); + int prodId = scan.nextInt(); + + String query2 = "select id, uname, bidValue, wen from bidder_bids where productId = " + prodId + + " order by id desc"; + ResultSet rs2 = st.executeQuery(query2); + System.out.println("\b"); + int j = 0; + while (rs2.next()) { + j++; + if (j == 1) { + System.out.printf("%10s%15s%18s%18s\n","Bid ID","Bidder ID","Bid Value","Time"); + } + System.out.printf("%7s%13s%21s%28s\n",rs2.getInt(1),rs2.getInt(2),"$ "+rs2.getString(3),rs2.getString(4)); + } + if (j == 0) { + System.out.println("\b"); + System.out.println("No bids have been placed so far for this product id!"); + } + } else { + System.out.println("\b"); + System.out.println("No active auctions!"); + } + st.close(); + con.close(); + } + + private static void adminStartTimer() throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + Connection con2 = DriverManager.getConnection(url, dbuname, dbpass); + Statement st2 = con2.createStatement(); + + String query1 = "select * from product where startTime IS NULL"; + ResultSet rs = st.executeQuery(query1); + System.out.println("\b"); + int i = 0; + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%10s%27s%43s%30s%30s\n","Product ID","Product Name","Product Description","Base Price","Duration"); + } + long millis = rs.getLong(5); + long days = TimeUnit.MILLISECONDS.toDays(millis); + millis -= TimeUnit.DAYS.toMillis(days); + long hours = TimeUnit.MILLISECONDS.toHours(millis); + millis -= TimeUnit.HOURS.toMillis(hours); + long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); + millis -= TimeUnit.MINUTES.toMillis(minutes); + long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); + + StringBuilder sb = new StringBuilder(64); + if (days != 0) { + sb.append(days); + sb.append(" Days "); + } + if (hours != 0) { + sb.append(hours); + sb.append(" Hrs "); + } + if (minutes != 0) { + sb.append(minutes); + sb.append(" Mins "); + } + if (seconds != 0) { + sb.append(seconds); + sb.append(" Sec"); + } + + String duration = sb.toString(); + System.out.printf("%5s%38s%50s%17s%37s\n",rs.getInt(1),rs.getString(2),rs.getString(3),"$ "+rs.getString(4),duration); + System.out.println("\b"); + System.out.print("Start timer for this product? (Y/N): "); + String ans2 = scan.nextLine().toUpperCase(); + String query2 = ""; + switch (ans2) { + case "Y": + long milli = rs.getLong(5); + long sec = milli / 1000; + query2 = "update product set approved = 1 , startTime = (select NOW()) , endTime = ((select NOW()) + INTERVAL " + + sec + " SECOND) where id = " + (int) rs.getInt(1); + break; + } + int ret = st2.executeUpdate(query2); + if (ret > 0) { + System.out.println("\b"); + System.out.println("Record updated succesfully !"); + } + } + if (i == 0) { + System.out.println("No request to start timer!"); + } + st.close(); + con.close(); + } + + private static void adminAcceptSeller() throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + Connection con2 = DriverManager.getConnection(url, dbuname, dbpass); + Statement st2 = con2.createStatement(); + + String query1 = "select * from product where approved = 0 and startTime IS NULL"; + ResultSet rs = st.executeQuery(query1); + System.out.println("\b"); + int i = 0; + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%10s%27s%43s%30s%30s\n","Product ID","Product Name","Product Description","Base Price","Duration"); + } + long millis = rs.getLong(5); + long days = TimeUnit.MILLISECONDS.toDays(millis); + millis -= TimeUnit.DAYS.toMillis(days); + long hours = TimeUnit.MILLISECONDS.toHours(millis); + millis -= TimeUnit.HOURS.toMillis(hours); + long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); + millis -= TimeUnit.MINUTES.toMillis(minutes); + long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); + + StringBuilder sb = new StringBuilder(64); + if (days != 0) { + sb.append(days); + sb.append(" Days "); + } + if (hours != 0) { + sb.append(hours); + sb.append(" Hrs "); + } + if (minutes != 0) { + sb.append(minutes); + sb.append(" Mins "); + } + if (seconds != 0) { + sb.append(seconds); + sb.append(" Sec"); + } + + String duration = sb.toString(); + System.out.printf("%5s%38s%50s%17s%37s\n",rs.getInt(1),rs.getString(2),rs.getString(3),"$ "+rs.getString(4),duration); + System.out.println("\b"); + System.out.print("Approve? (Y/N): "); + String ans1 = scan.nextLine().toUpperCase(); + int ans11; + if (ans1.equals("Y")) + ans11 = 1; + else + ans11 = 0; + System.out.println("\b"); + System.out.print("Start auction of this product? (Y/N): "); + String ans2 = scan.nextLine().toUpperCase(); + String query2 = ""; + switch (ans2) { + case "N": + query2 = "update product set approved = " + ans11 + " where id = " + (int) rs.getInt(1); + break; + case "Y": + long milli = rs.getLong(5); + long sec = milli / 1000; + query2 = "update product set approved = " + ans11 + + " , startTime = (select NOW()) , endTime = ((select NOW()) + INTERVAL " + sec + + " SECOND) where id = " + (int) rs.getInt(1); + break; + } + int ret = st2.executeUpdate(query2); + if (ret > 0) { + System.out.println("\b"); + System.out.println("Record updated succesfully !"); + } + } + if (i == 0) { + System.out.println("No auction request!"); + } + st.close(); + con.close(); + st2.close(); + con2.close(); + } + + private static int register(int i) throws Exception { + Scanner scan = new Scanner(System.in); + System.out.println("\b"); + System.out.println("Registration: "); + System.out.println("\b"); + System.out.print("Password: "); + String passWord = scan.nextLine(); + System.out.print("First name: "); + String firstName = scan.nextLine(); + System.out.print("Last Name: "); + String lastName = scan.nextLine(); + System.out.print("Phone: "); + String phone = scan.nextLine(); + System.out.print("Email ID: "); + String emailID = scan.nextLine(); + String userType = ""; + + String query = ""; + switch (i) { + case 49: + userType = "(seller)"; + query = "insert into seller(pass, fname, lname, ph, email) values ('" + passWord + "','" + firstName + "','" + + lastName + "','" + phone + "','" + emailID + "')"; + break; + case 50: + userType = "(bidder)"; + query = "insert into bidder(pass, fname, lname, ph, email) values ('" + passWord + "','" + firstName + "','" + + lastName + "','" + phone + "','" + emailID + "')"; + break; + } + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + st.executeUpdate(query, Statement.RETURN_GENERATED_KEYS); + ResultSet rs = st.getGeneratedKeys(); + int key = 0; + if (rs.next()) { + key = rs.getInt(1); + } + System.out.println("\b"); + System.out.println( + "Your " + userType + " username is: " + key + "\nPlease use your username and password to sign in."); + st.close(); + con.close(); + return key; + } + + private static int authenticate(int i) throws Exception { + System.out.println("\b"); + System.out.print("Username: "); + Scanner scan = new Scanner(System.in); + int uname = scan.nextInt(); + System.out.print("Password: "); + String pass = scan.next(); + + String query = ""; + switch (i) { + case 49: + query = "select pass from seller where uname = " + uname; + break; + case 50: + query = "select pass from bidder where uname = " + uname; + break; + case 97: + query = "select pass from admin where uname = " + uname; + break; + } + + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + ResultSet rs = st.executeQuery(query); + int returnVal = 0; + if (rs.next()) { + String passFetch = rs.getString("pass"); + if (pass.equals(passFetch)) { + System.out.println("\b"); + System.out.println("Successfully verified !"); + returnVal = uname; + } + } + st.close(); + con.close(); + return returnVal; + } +} diff --git a/Additional files/SQL full dump with data/auction_house_admin.sql b/Additional files/SQL full dump with data/auction_house_admin.sql new file mode 100644 index 0000000..57c8a41 --- /dev/null +++ b/Additional files/SQL full dump with data/auction_house_admin.sql @@ -0,0 +1,53 @@ +CREATE DATABASE IF NOT EXISTS `auction_house` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */; +USE `auction_house`; +-- MySQL dump 10.13 Distrib 5.7.9, for osx10.9 (x86_64) +-- +-- Host: localhost Database: auction_house +-- ------------------------------------------------------ +-- Server version 5.7.10 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `admin` +-- + +DROP TABLE IF EXISTS `admin`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `admin` ( + `uname` int(11) NOT NULL AUTO_INCREMENT, + `pass` varchar(45) COLLATE utf8_bin NOT NULL, + PRIMARY KEY (`uname`) +) ENGINE=InnoDB AUTO_INCREMENT=787 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `admin` +-- + +LOCK TABLES `admin` WRITE; +/*!40000 ALTER TABLE `admin` DISABLE KEYS */; +INSERT INTO `admin` VALUES (786,'admin'); +/*!40000 ALTER TABLE `admin` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2016-11-13 12:12:14 diff --git a/Additional files/SQL full dump with data/auction_house_bidder.sql b/Additional files/SQL full dump with data/auction_house_bidder.sql new file mode 100644 index 0000000..a4501a7 --- /dev/null +++ b/Additional files/SQL full dump with data/auction_house_bidder.sql @@ -0,0 +1,60 @@ +CREATE DATABASE IF NOT EXISTS `auction_house` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */; +USE `auction_house`; +-- MySQL dump 10.13 Distrib 5.7.9, for osx10.9 (x86_64) +-- +-- Host: localhost Database: auction_house +-- ------------------------------------------------------ +-- Server version 5.7.10 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `bidder` +-- + +DROP TABLE IF EXISTS `bidder`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `bidder` ( + `uname` int(11) NOT NULL AUTO_INCREMENT, + `pass` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `fname` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `lname` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `ph` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `email` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `approved` int(11) DEFAULT '0', + PRIMARY KEY (`uname`), + UNIQUE KEY `ph` (`ph`), + UNIQUE KEY `email` (`email`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `bidder` +-- + +LOCK TABLES `bidder` WRITE; +/*!40000 ALTER TABLE `bidder` DISABLE KEYS */; +INSERT INTO `bidder` VALUES (3,'bid1','Kunal','Tyagi','45678992345','k.f@g.com',0),(4,'bid2','Kannu','Priya','7895341234','k.p@g.com',0); +/*!40000 ALTER TABLE `bidder` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2016-11-13 12:12:14 diff --git a/Additional files/SQL full dump with data/auction_house_bidder_bids.sql b/Additional files/SQL full dump with data/auction_house_bidder_bids.sql new file mode 100644 index 0000000..56499da --- /dev/null +++ b/Additional files/SQL full dump with data/auction_house_bidder_bids.sql @@ -0,0 +1,61 @@ +CREATE DATABASE IF NOT EXISTS `auction_house` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */; +USE `auction_house`; +-- MySQL dump 10.13 Distrib 5.7.9, for osx10.9 (x86_64) +-- +-- Host: localhost Database: auction_house +-- ------------------------------------------------------ +-- Server version 5.7.10 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `bidder_bids` +-- + +DROP TABLE IF EXISTS `bidder_bids`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `bidder_bids` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `uname` int(11) DEFAULT NULL, + `productId` int(11) DEFAULT NULL, + `bidValue` double(10,2) DEFAULT NULL, + `placed` int(11) DEFAULT '0', + `wen` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `uname_idx` (`uname`), + KEY `productId_idx` (`productId`), + CONSTRAINT `productId2` FOREIGN KEY (`productId`) REFERENCES `product` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `uname2` FOREIGN KEY (`uname`) REFERENCES `bidder` (`uname`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `bidder_bids` +-- + +LOCK TABLES `bidder_bids` WRITE; +/*!40000 ALTER TABLE `bidder_bids` DISABLE KEYS */; +INSERT INTO `bidder_bids` VALUES (1,3,2,1000010.00,1,'2016-11-13 11:44:37'),(2,3,4,855.00,1,'2016-11-13 11:47:11'),(3,4,2,1001000.50,1,'2016-11-13 11:49:52'),(4,4,1,3050.00,1,'2016-11-13 11:50:35'),(5,4,1,3060.50,1,'2016-11-13 11:56:12'); +/*!40000 ALTER TABLE `bidder_bids` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2016-11-13 12:12:14 diff --git a/Additional files/SQL full dump with data/auction_house_product.sql b/Additional files/SQL full dump with data/auction_house_product.sql new file mode 100644 index 0000000..a5c0036 --- /dev/null +++ b/Additional files/SQL full dump with data/auction_house_product.sql @@ -0,0 +1,66 @@ +CREATE DATABASE IF NOT EXISTS `auction_house` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */; +USE `auction_house`; +-- MySQL dump 10.13 Distrib 5.7.9, for osx10.9 (x86_64) +-- +-- Host: localhost Database: auction_house +-- ------------------------------------------------------ +-- Server version 5.7.10 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `product` +-- + +DROP TABLE IF EXISTS `product`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `product` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `pname` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `des` varchar(100) COLLATE utf8_bin DEFAULT NULL, + `baseprice` double(10,2) DEFAULT NULL, + `duration` mediumtext COLLATE utf8_bin, + `sold` int(11) DEFAULT '0', + `BidValue` double(10,2) DEFAULT NULL, + `startTime` datetime DEFAULT NULL, + `endTime` datetime DEFAULT NULL, + `lastBidder` int(11) DEFAULT NULL, + `approved` int(11) DEFAULT '0', + PRIMARY KEY (`id`), + UNIQUE KEY `pname` (`pname`), + UNIQUE KEY `des` (`des`), + KEY `lastBidder_idx` (`lastBidder`), + CONSTRAINT `lastBidder` FOREIGN KEY (`lastBidder`) REFERENCES `bidder` (`uname`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `product` +-- + +LOCK TABLES `product` WRITE; +/*!40000 ALTER TABLE `product` DISABLE KEYS */; +INSERT INTO `product` VALUES (1,'car','A vintage styled car',3000.00,'900000',1,3060.50,'2016-11-13 11:45:42','2016-11-13 12:00:42',4,1),(2,'house','A big good ventilated house near USC',1000000.00,'7210000',0,1001000.50,'2016-11-13 11:38:17','2016-11-13 13:38:27',4,1),(3,'dining table','A big table for seating 7 people',250.00,'20000',3,NULL,'2016-11-13 11:45:47','2016-11-13 11:46:07',NULL,0),(4,'laptop','A gaming laptop',850.00,'135000',1,855.00,'2016-11-13 11:45:51','2016-11-13 11:48:06',3,1),(5,'jewellery','antique jewellery',500.00,'20000',3,NULL,'2016-11-13 11:55:05','2016-11-13 11:55:25',NULL,0); +/*!40000 ALTER TABLE `product` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2016-11-13 12:12:13 diff --git a/Additional files/SQL full dump with data/auction_house_routines.sql b/Additional files/SQL full dump with data/auction_house_routines.sql new file mode 100644 index 0000000..5640ef7 --- /dev/null +++ b/Additional files/SQL full dump with data/auction_house_routines.sql @@ -0,0 +1,81 @@ +CREATE DATABASE IF NOT EXISTS `auction_house` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */; +USE `auction_house`; +-- MySQL dump 10.13 Distrib 5.7.9, for osx10.9 (x86_64) +-- +-- Host: localhost Database: auction_house +-- ------------------------------------------------------ +-- Server version 5.7.10 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Dumping events for database 'auction_house' +-- +/*!50106 SET @save_time_zone= @@TIME_ZONE */ ; +/*!50106 DROP EVENT IF EXISTS `myevent` */; +DELIMITER ;; +/*!50003 SET @saved_cs_client = @@character_set_client */ ;; +/*!50003 SET @saved_cs_results = @@character_set_results */ ;; +/*!50003 SET @saved_col_connection = @@collation_connection */ ;; +/*!50003 SET character_set_client = utf8 */ ;; +/*!50003 SET character_set_results = utf8 */ ;; +/*!50003 SET collation_connection = utf8_general_ci */ ;; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ;; +/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ;; +/*!50003 SET @saved_time_zone = @@time_zone */ ;; +/*!50003 SET time_zone = 'SYSTEM' */ ;; +/*!50106 CREATE*/ /*!50117 DEFINER=`root`@`localhost`*/ /*!50106 EVENT `myevent` ON SCHEDULE EVERY 1 SECOND STARTS '2016-11-12 16:44:44' ON COMPLETION NOT PRESERVE ENABLE COMMENT 'Moves auctions with no bids to withdraws table.' DO CALL delete_obsolete_auctions() */ ;; +/*!50003 SET time_zone = @saved_time_zone */ ;; +/*!50003 SET sql_mode = @saved_sql_mode */ ;; +/*!50003 SET character_set_client = @saved_cs_client */ ;; +/*!50003 SET character_set_results = @saved_cs_results */ ;; +/*!50003 SET collation_connection = @saved_col_connection */ ;; +DELIMITER ; +/*!50106 SET TIME_ZONE= @save_time_zone */ ; + +-- +-- Dumping routines for database 'auction_house' +-- +/*!50003 DROP PROCEDURE IF EXISTS `delete_obsolete_auctions` */; +/*!50003 SET @saved_cs_client = @@character_set_client */ ; +/*!50003 SET @saved_cs_results = @@character_set_results */ ; +/*!50003 SET @saved_col_connection = @@collation_connection */ ; +/*!50003 SET character_set_client = utf8 */ ; +/*!50003 SET character_set_results = utf8 */ ; +/*!50003 SET collation_connection = utf8_general_ci */ ; +/*!50003 SET @saved_sql_mode = @@sql_mode */ ; +/*!50003 SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' */ ; +DELIMITER ;; +CREATE DEFINER=`root`@`localhost` PROCEDURE `delete_obsolete_auctions`() +BEGIN + update product set sold = 1 where endTime < (SELECT NOW()) and approved = 1 and BidValue IS NOT null; + update product set approved = 0 where endTime < (SELECT NOW()) and approved = 1 and BidValue IS null; + INSERT INTO withdraws(productId, pname, uname, wen, baseprice, lastbid) + select id, pname, 0, (select NOW()), baseprice, BidValue FROM product where endTime < (SELECT NOW()) and approved = 0 and sold = 0 and BidValue IS null; + update product set sold = 3 where endTime < (SELECT NOW()) and approved = 0 and sold = 0 and BidValue IS null; +END ;; +DELIMITER ; +/*!50003 SET sql_mode = @saved_sql_mode */ ; +/*!50003 SET character_set_client = @saved_cs_client */ ; +/*!50003 SET character_set_results = @saved_cs_results */ ; +/*!50003 SET collation_connection = @saved_col_connection */ ; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2016-11-13 12:12:14 diff --git a/Additional files/SQL full dump with data/auction_house_seller.sql b/Additional files/SQL full dump with data/auction_house_seller.sql new file mode 100644 index 0000000..41a307d --- /dev/null +++ b/Additional files/SQL full dump with data/auction_house_seller.sql @@ -0,0 +1,58 @@ +CREATE DATABASE IF NOT EXISTS `auction_house` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */; +USE `auction_house`; +-- MySQL dump 10.13 Distrib 5.7.9, for osx10.9 (x86_64) +-- +-- Host: localhost Database: auction_house +-- ------------------------------------------------------ +-- Server version 5.7.10 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `seller` +-- + +DROP TABLE IF EXISTS `seller`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `seller` ( + `uname` int(11) NOT NULL AUTO_INCREMENT, + `pass` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `fname` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `lname` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `ph` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `email` varchar(45) COLLATE utf8_bin DEFAULT NULL, + PRIMARY KEY (`uname`), + UNIQUE KEY `uname_UNIQUE` (`uname`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `seller` +-- + +LOCK TABLES `seller` WRITE; +/*!40000 ALTER TABLE `seller` DISABLE KEYS */; +INSERT INTO `seller` VALUES (1,'sel1','Sahil','Wadhwa','3236786789','s@g.com'),(2,'sel2','Mohan','Kumar','9123345678','m.k@g.com'),(3,'sel3','Vipul','Kishore','4568769081','v.p@g.com'),(4,'sel4','Manisha','Koyrl','3456781234','m.k@g.com'); +/*!40000 ALTER TABLE `seller` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2016-11-13 12:12:14 diff --git a/Additional files/SQL full dump with data/auction_house_seller_sells.sql b/Additional files/SQL full dump with data/auction_house_seller_sells.sql new file mode 100644 index 0000000..0500b14 --- /dev/null +++ b/Additional files/SQL full dump with data/auction_house_seller_sells.sql @@ -0,0 +1,58 @@ +CREATE DATABASE IF NOT EXISTS `auction_house` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */; +USE `auction_house`; +-- MySQL dump 10.13 Distrib 5.7.9, for osx10.9 (x86_64) +-- +-- Host: localhost Database: auction_house +-- ------------------------------------------------------ +-- Server version 5.7.10 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `seller_sells` +-- + +DROP TABLE IF EXISTS `seller_sells`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `seller_sells` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `uname` int(11) DEFAULT NULL, + `productId` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `productid_idx` (`productId`), + KEY `uname` (`uname`), + CONSTRAINT `productid` FOREIGN KEY (`productId`) REFERENCES `product` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `uname` FOREIGN KEY (`uname`) REFERENCES `seller` (`uname`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `seller_sells` +-- + +LOCK TABLES `seller_sells` WRITE; +/*!40000 ALTER TABLE `seller_sells` DISABLE KEYS */; +INSERT INTO `seller_sells` VALUES (1,1,1),(2,1,2),(3,2,3),(4,3,4),(5,4,5); +/*!40000 ALTER TABLE `seller_sells` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2016-11-13 12:12:14 diff --git a/Additional files/SQL full dump with data/auction_house_withdraws.sql b/Additional files/SQL full dump with data/auction_house_withdraws.sql new file mode 100644 index 0000000..b3aad40 --- /dev/null +++ b/Additional files/SQL full dump with data/auction_house_withdraws.sql @@ -0,0 +1,61 @@ +CREATE DATABASE IF NOT EXISTS `auction_house` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */; +USE `auction_house`; +-- MySQL dump 10.13 Distrib 5.7.9, for osx10.9 (x86_64) +-- +-- Host: localhost Database: auction_house +-- ------------------------------------------------------ +-- Server version 5.7.10 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `withdraws` +-- + +DROP TABLE IF EXISTS `withdraws`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `withdraws` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `productId` int(11) DEFAULT NULL, + `pname` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `uname` int(11) DEFAULT NULL, + `wen` datetime DEFAULT NULL, + `baseprice` double(10,2) DEFAULT NULL, + `lastbid` double(10,2) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `productId_idx` (`productId`), + KEY `uname_idx` (`uname`), + CONSTRAINT `productId4` FOREIGN KEY (`productId`) REFERENCES `product` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `withdraws` +-- + +LOCK TABLES `withdraws` WRITE; +/*!40000 ALTER TABLE `withdraws` DISABLE KEYS */; +INSERT INTO `withdraws` VALUES (1,3,'dining table',0,'2016-11-13 11:46:08',250.00,NULL),(2,5,'jewellery',0,'2016-11-13 11:55:26',500.00,NULL); +/*!40000 ALTER TABLE `withdraws` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2016-11-13 12:12:13 diff --git a/AuctionHouse/.classpath b/AuctionHouse/.classpath new file mode 100755 index 0000000..dd0b8fa --- /dev/null +++ b/AuctionHouse/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/AuctionHouse/.project b/AuctionHouse/.project new file mode 100755 index 0000000..0b462fa --- /dev/null +++ b/AuctionHouse/.project @@ -0,0 +1,17 @@ + + + AuctionHouse + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/AuctionHouse/.settings/org.eclipse.jdt.core.prefs b/AuctionHouse/.settings/org.eclipse.jdt.core.prefs new file mode 100755 index 0000000..3a21537 --- /dev/null +++ b/AuctionHouse/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/AuctionHouse/bin/AuctionHouse.class b/AuctionHouse/bin/AuctionHouse.class new file mode 100755 index 0000000..89301d6 Binary files /dev/null and b/AuctionHouse/bin/AuctionHouse.class differ diff --git a/AuctionHouse/src/AuctionHouse.java b/AuctionHouse/src/AuctionHouse.java new file mode 100755 index 0000000..f858b2d --- /dev/null +++ b/AuctionHouse/src/AuctionHouse.java @@ -0,0 +1,1164 @@ +import java.io.Console; +import java.io.InputStream; +import java.math.BigDecimal; +import java.sql.*; +import java.util.Date; +import java.util.Scanner; +import java.util.concurrent.TimeUnit; +import java.util.*; + +public class AuctionHouse { + static String url = "jdbc:mysql://localhost:3306/auction_house?autoReconnect=true&useSSL=false"; + static String dbuname = "root"; + static String dbpass = "admin"; + static String classForName = "com.mysql.jdbc.Driver"; + + public static void main(String[] args) throws Exception { + + while (true) { + System.out.println("\b"); + System.out.println("********* Welcome to Rita's Auction House ***********"); + System.out.println("Please select your role to proceed:"); + System.out.println("1. Seller"); + System.out.println("2. Bidder"); + System.out.print("Please enter your choice: "); + + Scanner scan = new Scanner(System.in); + String fOption = scan.next(); + char[] a = fOption.toCharArray(); + int asci = (int) a[0]; + + switch (asci) { + case 49: + System.out.println("\n1. Sign-in"); + System.out.println("2. Register"); + System.out.print("Please enter your choice: "); + int sOption = scan.nextInt(); + + switch (sOption) { + case 1: + int auth = authenticate(49); + switch (auth) { + case 0: + System.out.println("Username/Password did not match. Please try again."); + break; + default: + int sellerOption = 0; + while (sellerOption != 10) { + System.out.println("\n Welcome back seller !"); + System.out.println("1. Submit item(s) for auction"); + System.out.println("2. Set/change base price for your submitted item"); + System.out.println("3. Set time duration for auction"); + System.out.println("4. View all the running auctions"); + System.out.println("5. View (approval) status of your items"); + System.out.println("6. View all the bids for your item"); + System.out.println("7. View earnings (after auction)"); + System.out.println("8. Withdraw item from auction"); + System.out.println("9. View withdrawn items"); + System.out.println("10. Exit"); + System.out.println("\b"); + System.out.print("Please enter your choice: "); + sellerOption = scan.nextInt(); + switch (sellerOption) { + case 1: + sellerSubmitItem(auth); + break; + case 2: + sellerSetBasePrice(auth); + break; + case 3: + sellerSetTime(auth); + break; + case 4: + sellerViewRunningAuctions(auth); + break; + case 5: + sellerViewItemStatus(auth); + break; + case 6: + sellerViewBids(auth); + break; + case 7: + sellerViewSellerEarnings(auth); + break; + case 8: + sellerWithdrawAuction(auth); + break; + case 9: + sellerViewWithdrawnItems(auth); + break; + } + } + } + break; + case 2: + int reg = register(49); + if (!(reg > 0)) + System.out.println("Oops ! Something went wrong. Please try again after some time."); + break; + } + break; + case 50: + System.out.println("\n1. Sign-in"); + System.out.println("2. Register"); + System.out.print("Please enter your choice: "); + int bOption = scan.nextInt(); + + switch (bOption) { + case 1: + int auth = authenticate(50); + switch (auth) { + case 0: + System.out.println("Username/Password did not match. Please try again."); + break; + default: + int bidderOption = 0; + while (bidderOption != 5) { + System.out.println("\n Welcome back bidder !"); + System.out.println("1. View available and running auctions"); + System.out.println("2. View my bids"); + System.out.println("3. Bid for an auction"); + System.out.println("4. View bought items"); + System.out.println("5. Exit"); + System.out.println("\b"); + System.out.print("Please enter your choice: "); + bidderOption = scan.nextInt(); + switch (bidderOption) { + case 1: + bidderAvailAucs(auth); + break; + case 2: + bidderMyBids(auth); + break; + case 3: + bidderBid(auth); + break; + case 4: + bidderBought(auth); + break; + } + } + } + break; + case 2: + int reg = register(50); + if (!(reg > 0)) + System.out.println("Oops ! Something went wrong. Please try again after some time."); + break; + } + break; + case 97: + System.out.println("\b"); + System.out.println("Hello Rita !"); + int auth = authenticate(97); + switch (auth) { + case 0: + System.out.println("Username/Password did not match. Please try again."); + break; + default: + int adminOption = 0; + while (adminOption != 6) { + System.out.println("\n Welcome back admin !"); + System.out.println("1. Accept seller auction request"); + System.out.println("2. Start timer for an auction"); + System.out.println("3. View all running auctions and bids"); + System.out.println("4. View all sold products and earnings"); + System.out.println("5. View all withdrawn items from auction"); + System.out.println("6. Exit"); + System.out.println("\b"); + System.out.print("Please enter your choice: "); + adminOption = scan.nextInt(); + switch (adminOption) { + case 1: + adminAcceptSeller(); + break; + case 2: + adminStartTimer(); + break; + case 3: + adminViewAucBid(); + break; + case 4: + adminViewSoldEarn(); + break; + case 5: + adminViewWithdrawn(); + break; + } + } + } + break; + } + } + } + + private static void bidderBought(int auth) throws Exception { + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select id, pname, des, baseprice, BidValue from product where endTime < (select NOW()) and approved = 1 and lastBidder = " + + auth; + ResultSet rs = st.executeQuery(query1); + System.out.println("\b"); + int i = 0; + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%3s%13s%20s%28s%15s%14s\n","S.No","Product ID","Product Name","Product Description","Base Price","Your Bid"); + } + System.out.printf("%2d%11d%23s%30s%13s%14s\n",i,rs.getInt(1),rs.getString(2),rs.getString(3),"$ "+rs.getString(4),"$ "+rs.getString(5)); + } + if (i == 0) { + System.out.println( + "You haven't been sold any items yet. Reasons:\n1. You have not placed any bid.\n2. The auction is not over yet.\nPlease check back in some time."); + } + st.close(); + con.close(); + } + + private static void bidderBid(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select id, pname, des, baseprice, BidValue, endTime from product where endTime > (select NOW()) and approved = 1 "; + ResultSet rs = st.executeQuery(query1); + System.out.println("\b"); + int i = 0; + LinkedHashMap lhm = new LinkedHashMap(); + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%5s%15s%30s%45s%23s%18s%25s\n","S.No","Product ID","Product Name","Product Description","Base Price","Last Bid","Valid For"); + } + if (rs.getDouble(5) > rs.getDouble(4)) + lhm.put((int) rs.getInt(1), rs.getDouble(5)); + else + lhm.put((int) rs.getInt(1), rs.getDouble(4)); + + Date end = rs.getTimestamp(6); + Date today = new Date(); + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(end); + long endMili = calendar.getTimeInMillis(); + + calendar.setTime(today); + long todayMili = calendar.getTimeInMillis(); + long millis = endMili - todayMili; + + long days = TimeUnit.MILLISECONDS.toDays(millis); + millis -= TimeUnit.DAYS.toMillis(days); + long hours = TimeUnit.MILLISECONDS.toHours(millis); + millis -= TimeUnit.HOURS.toMillis(hours); + long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); + millis -= TimeUnit.MINUTES.toMillis(minutes); + long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); + + StringBuilder sb = new StringBuilder(64); + if (days != 0) { + sb.append(days); + sb.append(" days "); + } + if (hours != 0) { + sb.append(hours); + sb.append(" hrs "); + } + if (minutes != 0) { + sb.append(minutes); + sb.append(" mins "); + } + if (seconds != 0) { + sb.append(seconds); + sb.append(" secs"); + } + + String duration = sb.toString(); + + System.out.printf("%4s%12s%35s%50s%17s%17s%33s\n",i,rs.getInt(1),rs.getString(2),rs.getString(3),"$ "+rs.getString(4),"$ "+rs.getString(5),duration); + } + + if (i > 0) { + System.out.print("Product ID: "); + int prodId = scan.nextInt(); + int myBid = 0; + Set set = lhm.entrySet(); + Iterator itr = set.iterator(); + double val = 0; + while (itr.hasNext()) { + Map.Entry me = (Map.Entry) itr.next(); + if (prodId == (int) me.getKey()) { + val = (double) me.getValue(); + break; + } + } + + System.out.print("Your Bid (with 2 decimal places): $ "); + double newBid = scan.nextDouble(); + while (newBid < val) { + System.out.println( + "New bid cannot be lesser than the base price/original bid.\nPlease enter a bigger bid: $ "); + newBid = scan.nextDouble(); + } + + String query2 = "update product set BidValue = " + newBid + ", lastBidder = '" + auth + "' where id = " + + prodId + " and endTime > (select NOW()) and approved = 1"; + int ret = st.executeUpdate(query2); + + switch (ret) { + case 0: + System.out.println("Cannot bid on this product now. \nPlease select another product."); + break; + case 1: + String query3 = "insert into bidder_bids(uname, productId, bidValue, placed, wen) values (" + auth + "," + + prodId + "," + newBid + ", 1, (select NOW()))"; + int result = st.executeUpdate(query3); + if (result == 1) { + System.out.println("\b"); + System.out.println("Your bid has been successfully placed !"); + } + break; + } + } else { + System.out.println("\b"); + System.out.println("Sorry, no active auctions found!"); + } + st.close(); + con.close(); + } + + private static void bidderMyBids(int auth) throws Exception { + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select B.id, B.productId, P.pname, B.bidValue , B.wen from bidder_bids B inner join product P on B.productId = P.id where P.approved = 1 and uname = " + + auth + " ORDER BY B.id DESC"; + ResultSet rs = st.executeQuery(query1); + int i = 0; + System.out.println("\b"); + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%3s%17s%14s%17s\n","S.No","Product Name","Bid Value","Time"); + } + System.out.printf("%2d%19s%13s%27s\n",i,rs.getString(3),"$ "+rs.getString(4),rs.getString(5)); + } + if (i == 0) { + System.out.println("You don't have active bids at this moment!"); + } + st.close(); + con.close(); + } + + private static void bidderAvailAucs(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select id, pname, des, baseprice, BidValue, endTime from product where endTime > (select NOW()) and approved = 1"; + ResultSet rs = st.executeQuery(query1); + System.out.println("\b"); + int i = 0; + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%5s%15s%30s%45s%23s%18s%25s\n","S.No","Product ID","Product Name","Product Description","Base Price","Last Bid","Valid For"); + } + Date end = rs.getTimestamp(6); + Date today = new Date(); + + Calendar calendar = Calendar.getInstance(); + calendar.setTime(end); + long endMili = calendar.getTimeInMillis(); + + calendar.setTime(today); + long todayMili = calendar.getTimeInMillis(); + long millis = endMili - todayMili; + + long days = TimeUnit.MILLISECONDS.toDays(millis); + millis -= TimeUnit.DAYS.toMillis(days); + long hours = TimeUnit.MILLISECONDS.toHours(millis); + millis -= TimeUnit.HOURS.toMillis(hours); + long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); + millis -= TimeUnit.MINUTES.toMillis(minutes); + long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); + + StringBuilder sb = new StringBuilder(64); + if (days != 0) { + sb.append(days); + sb.append(" days "); + } + if (hours != 0) { + sb.append(hours); + sb.append(" hrs "); + } + if (minutes != 0) { + sb.append(minutes); + sb.append(" mins "); + } + if (seconds != 0) { + sb.append(seconds); + sb.append(" secs "); + } + + String duration = sb.toString(); + + System.out.printf("%4s%12s%35s%50s%17s%17s%33s\n",i,rs.getInt(1),rs.getString(2),rs.getString(3),"$ "+rs.getString(4),"$ "+rs.getString(5),duration); + } + if (i == 0) { + System.out.println("Sorry, no active auctions at this moment!"); + } + st.close(); + con.close(); + } + + private static void sellerViewWithdrawnItems(int auth) throws Exception{ + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + System.out.println("\b"); + String query2 = "select W.productId, W.pname, W.uname, W.wen, W.baseprice, W.lastbid from withdraws W inner join seller_sells S on W.productId = S.productId where S.uname = "+auth; + ResultSet rs2 = st.executeQuery(query2); + int i = 0; + while(rs2.next()){ + i++; + if (i == 1) { + System.out.printf("%10s%22s%20s%20s%25s%15s\n","Product ID","Product Name","Reason","When","Base Price","Last Bid"); + } + String reason = ""; + if(rs2.getInt(3) == 0) + reason = "No bids/Timeout"; + else + reason = "Self"; + String val = ""; + if(rs2.getString(6) == null){ + val = "0.00"; + } + else{ + val = rs2.getString(6); + } + System.out.printf("%6s%27s%23s%25s%14s%17s\n",rs2.getInt(1),rs2.getString(2),reason,rs2.getString(4),"$ "+rs2.getString(5),"$ "+val); + } + if(i==0){ + System.out.println("No item has been withdrawn!"); + } + } + + private static void sellerWithdrawAuction(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + System.out.println("\b"); + String query2 = "select S.productId, P.pname, P.baseprice, P.BidValue from seller_sells S inner join product P on S.productId = P.id where P.endTime > (SELECT NOW()) and P.approved = 1 and S.uname = " + + auth; + ResultSet rs2 = st.executeQuery(query2); + LinkedHashMap lhm = new LinkedHashMap(); + int l = 0; + while (rs2.next()) { + l++; + if (l == 1) { + System.out.printf("%8s%25s%18s%20s\n","Product ID","Product Name","Base Price","Current Bid Value"); + } + System.out.printf("%7s%31s%14s%18s\n",rs2.getInt(1),rs2.getString(2),"$ "+rs2.getString(3),"$ "+rs2.getString(4)); + lhm.put(rs2.getInt(1), rs2.getString(2) + " " + rs2.getString(3) + " " + rs2.getString(4)); + } + if (l > 0) { + System.out.println("\b"); + System.out.print("Enter Product ID to withdraw: "); + int n = scan.nextInt(); + Set set = lhm.entrySet(); + Iterator itr = set.iterator(); + String name = ""; + double base = 0.00; + double bidV = 0.00; + while (itr.hasNext()) { + Map.Entry me = (Map.Entry) itr.next(); + int key = (int) me.getKey(); + if (n == key) { + String value = me.getValue().toString(); + String[] ar = value.split(" "); + name = ar[0]; + base = Double.parseDouble(ar[ar.length - 2]); + bidV = Double.parseDouble(ar[ar.length - 1]); + } + } + + String query3 = "update product set approved = 0 where id = " + n; + int ret = st.executeUpdate(query3); + if (ret == 0) { + System.out.println("\b"); + System.out.println("Could not delete auction request.\nPlease try again later."); + } else { + System.out.println("\b"); + System.out.println("Product from auction : "); + + String query4 = "insert into withdraws(productId, pname, uname, wen, baseprice, lastbid) values (" + n + + ",'" + name + "'," + auth + ",(select NOW())," + base + "," + bidV + ")"; + int result = st.executeUpdate(query4); + switch (result) { + case 0: + System.out.println("Could not insert. try again later"); + break; + case 1: + System.out.print("Success !"); + break; + } + } + } else { + System.out.println("\b"); + System.out.println("Sorry, no item can be withdrawn from auction at this time!"); + } + + st.close(); + con.close(); + } + + private static void sellerViewSellerEarnings(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + System.out.println("\b"); + String query2 = "select P.pname, (0.95*P.BidValue) as earning from product P inner join seller_sells S on S.productId = P.id where P.endTime < (SELECT NOW()) and P.approved = 1 and S.uname = " + + auth; + ResultSet rs2 = st.executeQuery(query2); + double earning = 0.00; + int i = 0; + while (rs2.next()) { + i++; + if (i == 1) { + System.out.printf("%20s%20s\n","Product Name","Earnings"); + } + BigDecimal bd = new BigDecimal(String.valueOf(rs2.getDouble(2))).setScale(2, BigDecimal.ROUND_FLOOR); + System.out.printf("%20s%19s\n",rs2.getString(1),"$ "+bd); + earning += rs2.getDouble(2); + } + System.out.println("\b"); + BigDecimal bd = new BigDecimal(String.valueOf(earning)).setScale(2, BigDecimal.ROUND_FLOOR); + System.out.println("Total earning: $ " + bd); + st.close(); + con.close(); + } + + private static void sellerViewRunningAuctions(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + System.out.println("\b"); + String query2 = "select id, pname, baseprice, BidValue, startTime, endTime from product P where endTime > (SELECT NOW()) and approved = 1"; + ResultSet rs2 = st.executeQuery(query2); + int i = 0; + while (rs2.next()) { + i++; + if (i == 1) { + System.out.printf("%8s%25s%18s%16s%24s%24s\n","Product ID","Product Name","Base Price","Last Bid","Start Time","End Time"); + } + System.out.printf("%7s%31s%14s%16s%28s%28s\n",rs2.getInt(1),rs2.getString(2),"$ "+rs2.getString(3),rs2.getString(4),rs2.getString(5),rs2.getString(6)); + } + if (i == 0) { + System.out.println("No active auctions found!"); + } + st.close(); + con.close(); + } + + private static void sellerViewItemStatus(int auth) throws Exception { + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select S.productId, P.pname, P.approved from seller_sells S inner join product P on S.productId = P.id where uname = " + + auth; + ResultSet rs = st.executeQuery(query1); + int i = 0; + System.out.println("\b"); + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%8s%22s%30s\n","Product ID","Product Name","Approval Status"); + } + int status = rs.getInt(3); + String stat = ""; + if (status == 0) + stat = "Pending approval/Item withdrawn"; + else + stat = "Approved"; + System.out.printf("%4d%28s%36s\n",rs.getInt(1),rs.getString(2),stat); + } + if (i == 0) { + System.out.println("Please submit items for auction."); + } + st.close(); + con.close(); + } + + private static void sellerViewBids(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + System.out.println("\b"); + String query2 = "select S.productId, P.pname, B.bidValue, B.wen from seller_sells S inner join bidder_bids B on S.productId = B.productId inner join product P on S.productId = P.id where S.uname = " + + auth + " ORDER BY productId DESC, wen DESC"; + ResultSet rs2 = st.executeQuery(query2); + int k = 0; + while (rs2.next()) { + k++; + if (k == 1) { + System.out.printf("%10s%20s%20s%20s\n","Product ID","Product Name","Bid Value","Time"); + } + System.out.printf("%4d%26s%19s%28s\n",rs2.getInt(1),rs2.getString(2),"$ "+rs2.getString(3),rs2.getString(4)); + } + if (k == 0) + System.out.println("No bids received for any of your items."); + st.close(); + con.close(); + } + + private static void sellerSetTime(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query2 = "select S.productId, P.pname, P.duration from seller_sells S inner join product P on S.productId = P.id where P.sold = 0 and P.endTime > (SELECT NOW()) and S.uname = " + + auth; + ResultSet rs2 = st.executeQuery(query2); + System.out.println("\b"); + int j = 0; + String duration = ""; + while (rs2.next()) { + j++; + if (j == 1) { + System.out.printf("%10s%25s%25s\n","Product ID","Product Name","Duration"); + } + long millis = rs2.getLong(3); + long days = TimeUnit.MILLISECONDS.toDays(millis); + millis -= TimeUnit.DAYS.toMillis(days); + long hours = TimeUnit.MILLISECONDS.toHours(millis); + millis -= TimeUnit.HOURS.toMillis(hours); + long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); + millis -= TimeUnit.MINUTES.toMillis(minutes); + long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); + + StringBuilder sb = new StringBuilder(64); + if (days != 0) { + sb.append(days); + sb.append(" Days "); + } + if (hours != 0) { + sb.append(hours); + sb.append(" Hrs "); + } + if (minutes != 0) { + sb.append(minutes); + sb.append(" Mins "); + } + if (seconds != 0) { + sb.append(seconds); + sb.append(" Sec"); + } + + duration = sb.toString(); + System.out.printf("%6s%32s%30s\n",rs2.getInt(1),rs2.getString(2),duration); + } + if (j > 0) { + String quit = "Y"; + long newMilli = 0; + while (!quit.equals("N")) { + System.out.println("\b"); + System.out.print("Product number to change: "); + int opt = scan.nextInt(); + System.out.print("Enter new duration in days hrs mins secs. \n"); + System.out.print("Days: "); + int days = scan.nextInt(); + System.out.print("Hours: "); + int hours = scan.nextInt(); + System.out.print("Minutes: "); + int minutes = scan.nextInt(); + System.out.print("Seconds: "); + int seconds = scan.nextInt(); + + newMilli = TimeUnit.SECONDS.toMillis(seconds) + TimeUnit.MINUTES.toMillis(minutes) + + TimeUnit.HOURS.toMillis(hours) + TimeUnit.DAYS.toMillis(days); + + String query3 = "update product set duration = " + newMilli + " , endTime = DATE_ADD(NOW(), INTERVAL " + + (newMilli / 1000) + " second) where id = " + opt; + int ret = st.executeUpdate(query3); + if (ret == 0) { + System.out.println("No row updated !"); + } else { + System.out.println("\b"); + System.out + .print("Duration updated successfully ! \nDo you wish to make any more updates ? (Y/N): "); + quit = scan.next().toUpperCase(); + } + } + } else { + System.out.println("\b"); + System.out.println("Sorry, you haven't submitted any new items for auction !"); + } + st.close(); + con.close(); + } + + private static void sellerSetBasePrice(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con2 = DriverManager.getConnection(url, dbuname, dbpass); + Statement st2 = con2.createStatement(); + Connection con3 = DriverManager.getConnection(url, dbuname, dbpass); + Statement st3 = con3.createStatement(); + + String query2 = "select S.productId, P.pname, P.baseprice from seller_sells S inner join product P on S.productId = P.id where P.startTime IS NULL and S.uname = " + + auth; + ResultSet rs2 = st2.executeQuery(query2); + System.out.println("\b"); + int j = 0; + while (rs2.next()) { + j++; + if (j == 1) { + System.out.printf("%10s%20s%15s\n","Product ID","Product Name","Base Price"); + } + System.out.printf("%5s%20s%18s\n",rs2.getInt(1),rs2.getString(2),"$ "+rs2.getString(3)); + } + if (j > 0) { + String quit = "Y"; + while (!quit.equals("N")) { + System.out.println("\b"); + System.out.print("Product number to change: "); + int opt = scan.nextInt(); + System.out.print("New base price (with 2 decimal digits): $ "); + double newBase = scan.nextDouble(); + + String query3 = "update product set baseprice = " + newBase + " where id = " + opt; + int ret = st3.executeUpdate(query3); + if (ret == 0) { + System.out.println("No row updated !"); + } else { + System.out.println("\b"); + System.out.print( + "Base price updated successfully ! \nDo you wish to make any more updates ? (Y/N): "); + quit = scan.next().toUpperCase(); + } + } + } else { + System.out.println("\b"); + System.out.println("Sorry, you haven't submitted any new items for auction !"); + } + st3.close(); + con3.close(); + st2.close(); + con2.close(); + } + + private static void sellerSubmitItem(int auth) throws Exception { + Scanner scan = new Scanner(System.in); + System.out.println("\b"); + System.out.println("Welcome Seller ID (" + auth + "). Please give the product details:"); + System.out.println("\b"); + System.out.print("Product Name: "); + String prodName = scan.nextLine(); + System.out.print("Product Desciption (12-15 words): "); + String prodDesc = scan.nextLine(); + prodDesc = prodDesc.substring(0, Math.min(prodDesc.length(), 98)); + System.out.print("Base Price (with 2 decimal digits): $ "); + double prodBase = scan.nextDouble(); + System.out.print("Auction Duration:\n"); + System.out.print("days: "); + int dd = scan.nextInt(); + System.out.print("hours: "); + int hh = scan.nextInt(); + System.out.print("mins: "); + int mm = scan.nextInt(); + System.out.print("seconds: "); + int ss = scan.nextInt(); + + int milliSec = ss * 1000 + (mm * 60 * 1000) + (hh * 60 * 60 * 1000) + (dd * 24 * 60 * 60 * 1000); + + String query = "insert into product(pname, des, baseprice, duration) values ('" + prodName + "','" + prodDesc + + "','" + prodBase + "','" + milliSec + "')"; + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + int count = st.executeUpdate(query, Statement.RETURN_GENERATED_KEYS); + ResultSet rs = st.getGeneratedKeys(); + int productId = 0; + if (rs.next()) { + productId = rs.getInt(1); + } + if (count == 0) { + System.out.println("Could not save data. Please try again later."); + } else { + System.out.println("\b"); + System.out.println( + "Item saved successfully ! The admin will soon approve your auction request and start the timer."); + String query2 = "insert into seller_sells(uname, productId) values (" + auth + "," + productId + ")"; + int count2 = st.executeUpdate(query2, Statement.RETURN_GENERATED_KEYS); + ResultSet rs2 = st.getGeneratedKeys(); + int requestId = 0; + if (rs2.next()) { + requestId = rs2.getInt(1); + System.out.println("\b"); + System.out.println("For reference, your request ID is " + requestId); + } + } + st.close(); + con.close(); + } + + private static void adminViewWithdrawn() throws Exception { + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select id, productId, pname, uname, wen, baseprice, lastbid from withdraws"; + ResultSet rs = st.executeQuery(query1); + System.out.println("\b"); + int i = 0; + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%5s%15s%23s%18s%20s%23s%18s\n","S.No.","Product ID","Product Name","Seller ID","Time","Base Price","Last Bid"); + } + String val = ""; + if(rs.getString(7) == null) + val = "0.00"; + else + val = rs.getString(7); + System.out.printf("%3s%14s%26s%14s%31s%15s%18s\n",rs.getInt(1),rs.getInt(2),rs.getString(3),rs.getString(4),rs.getString(5),"$ "+rs.getString(6),"$ "+val); + } + if (i == 0) { + System.out.println("No items have been withdrawn from auction!"); + } + } + + private static void adminViewSoldEarn() throws Exception { + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select id, pname, baseprice, BidValue, lastBidder from product where endTime < (select NOW()) and approved = 1"; + ResultSet rs = st.executeQuery(query1); + ResultSetMetaData rsmd = rs.getMetaData(); + int cols = rsmd.getColumnCount(); + System.out.println("\b"); + double earning = 0.00; + int i = 0; + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%10s%20s%17s%15s%20s%15s\n","Product ID","Product Name","Base Price","Last Bid","Last Bidder ID","Earning"); + } + double val = (0.05 * rs.getDouble(4)); + BigDecimal bd = new BigDecimal(String.valueOf(val)).setScale(2, BigDecimal.ROUND_FLOOR); + + System.out.printf("%6d%24s%15s%16s%15s%21s\n",rs.getInt(1),rs.getString(2),"$ "+rs.getString(3),"$ "+rs.getString(4),rs.getInt(5),"$ "+bd); + earning += (0.05 * rs.getDouble(4));; + } + System.out.println("\b"); + BigDecimal bd = new BigDecimal(String.valueOf(earning)).setScale(2, BigDecimal.ROUND_FLOOR); + System.out.println("Total earning so far: $ " + bd); + st.close(); + con.close(); + } + + private static void adminViewAucBid() throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + + String query1 = "select id, pname, baseprice, BidValue, startTime, endTime from product where endTime > (select NOW()) and approved = 1"; + ResultSet rs = st.executeQuery(query1); + System.out.println("\b"); + int i = 0; + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%8s%25s%18s%18s%24s%25s\n","Product ID","Product Name","Base Price","Last Bid","Start Time","End Time"); + } + System.out.printf("%7s%30s%16s%18s%27s%27s\n",rs.getInt(1),rs.getString(2),"$ "+rs.getString(3),"$ "+rs.getString(4),rs.getString(5),rs.getString(6)); + } + if (i > 0) { + System.out.println("\b"); + System.out.print("Enter product id to view bids: "); + int prodId = scan.nextInt(); + + String query2 = "select id, uname, bidValue, wen from bidder_bids where productId = " + prodId + + " order by id desc"; + ResultSet rs2 = st.executeQuery(query2); + System.out.println("\b"); + int j = 0; + while (rs2.next()) { + j++; + if (j == 1) { + System.out.printf("%10s%15s%18s%18s\n","Bid ID","Bidder ID","Bid Value","Time"); + } + System.out.printf("%7s%13s%21s%28s\n",rs2.getInt(1),rs2.getInt(2),"$ "+rs2.getString(3),rs2.getString(4)); + } + if (j == 0) { + System.out.println("\b"); + System.out.println("No bids have been placed so far for this product id!"); + } + } else { + System.out.println("\b"); + System.out.println("No active auctions!"); + } + st.close(); + con.close(); + } + + private static void adminStartTimer() throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + Connection con2 = DriverManager.getConnection(url, dbuname, dbpass); + Statement st2 = con2.createStatement(); + + String query1 = "select * from product where startTime IS NULL"; + ResultSet rs = st.executeQuery(query1); + System.out.println("\b"); + int i = 0; + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%10s%27s%43s%30s%30s\n","Product ID","Product Name","Product Description","Base Price","Duration"); + } + long millis = rs.getLong(5); + long days = TimeUnit.MILLISECONDS.toDays(millis); + millis -= TimeUnit.DAYS.toMillis(days); + long hours = TimeUnit.MILLISECONDS.toHours(millis); + millis -= TimeUnit.HOURS.toMillis(hours); + long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); + millis -= TimeUnit.MINUTES.toMillis(minutes); + long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); + + StringBuilder sb = new StringBuilder(64); + if (days != 0) { + sb.append(days); + sb.append(" Days "); + } + if (hours != 0) { + sb.append(hours); + sb.append(" Hrs "); + } + if (minutes != 0) { + sb.append(minutes); + sb.append(" Mins "); + } + if (seconds != 0) { + sb.append(seconds); + sb.append(" Sec"); + } + + String duration = sb.toString(); + System.out.printf("%5s%38s%50s%17s%37s\n",rs.getInt(1),rs.getString(2),rs.getString(3),"$ "+rs.getString(4),duration); + System.out.println("\b"); + System.out.print("Start timer for this product? (Y/N): "); + String ans2 = scan.nextLine().toUpperCase(); + String query2 = ""; + switch (ans2) { + case "Y": + long milli = rs.getLong(5); + long sec = milli / 1000; + query2 = "update product set approved = 1 , startTime = (select NOW()) , endTime = ((select NOW()) + INTERVAL " + + sec + " SECOND) where id = " + (int) rs.getInt(1); + break; + } + int ret = st2.executeUpdate(query2); + if (ret > 0) { + System.out.println("\b"); + System.out.println("Record updated succesfully !"); + } + } + if (i == 0) { + System.out.println("No request to start timer!"); + } + st.close(); + con.close(); + } + + private static void adminAcceptSeller() throws Exception { + Scanner scan = new Scanner(System.in); + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + Connection con2 = DriverManager.getConnection(url, dbuname, dbpass); + Statement st2 = con2.createStatement(); + + String query1 = "select * from product where approved = 0 and startTime IS NULL"; + ResultSet rs = st.executeQuery(query1); + System.out.println("\b"); + int i = 0; + while (rs.next()) { + i++; + if (i == 1) { + System.out.printf("%10s%27s%43s%30s%30s\n","Product ID","Product Name","Product Description","Base Price","Duration"); + } + long millis = rs.getLong(5); + long days = TimeUnit.MILLISECONDS.toDays(millis); + millis -= TimeUnit.DAYS.toMillis(days); + long hours = TimeUnit.MILLISECONDS.toHours(millis); + millis -= TimeUnit.HOURS.toMillis(hours); + long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); + millis -= TimeUnit.MINUTES.toMillis(minutes); + long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); + + StringBuilder sb = new StringBuilder(64); + if (days != 0) { + sb.append(days); + sb.append(" Days "); + } + if (hours != 0) { + sb.append(hours); + sb.append(" Hrs "); + } + if (minutes != 0) { + sb.append(minutes); + sb.append(" Mins "); + } + if (seconds != 0) { + sb.append(seconds); + sb.append(" Sec"); + } + + String duration = sb.toString(); + System.out.printf("%5s%38s%50s%17s%37s\n",rs.getInt(1),rs.getString(2),rs.getString(3),"$ "+rs.getString(4),duration); + System.out.println("\b"); + System.out.print("Approve? (Y/N): "); + String ans1 = scan.nextLine().toUpperCase(); + int ans11; + if (ans1.equals("Y")) + ans11 = 1; + else + ans11 = 0; + System.out.println("\b"); + System.out.print("Start auction of this product? (Y/N): "); + String ans2 = scan.nextLine().toUpperCase(); + String query2 = ""; + switch (ans2) { + case "N": + query2 = "update product set approved = " + ans11 + " where id = " + (int) rs.getInt(1); + break; + case "Y": + long milli = rs.getLong(5); + long sec = milli / 1000; + query2 = "update product set approved = " + ans11 + + " , startTime = (select NOW()) , endTime = ((select NOW()) + INTERVAL " + sec + + " SECOND) where id = " + (int) rs.getInt(1); + break; + } + int ret = st2.executeUpdate(query2); + if (ret > 0) { + System.out.println("\b"); + System.out.println("Record updated succesfully !"); + } + } + if (i == 0) { + System.out.println("No auction request!"); + } + st.close(); + con.close(); + st2.close(); + con2.close(); + } + + private static int register(int i) throws Exception { + Scanner scan = new Scanner(System.in); + System.out.println("\b"); + System.out.println("Registration: "); + System.out.println("\b"); + System.out.print("Password: "); + String passWord = scan.nextLine(); + System.out.print("First name: "); + String firstName = scan.nextLine(); + System.out.print("Last Name: "); + String lastName = scan.nextLine(); + System.out.print("Phone: "); + String phone = scan.nextLine(); + System.out.print("Email ID: "); + String emailID = scan.nextLine(); + String userType = ""; + + String query = ""; + switch (i) { + case 49: + userType = "(seller)"; + query = "insert into seller(pass, fname, lname, ph, email) values ('" + passWord + "','" + firstName + "','" + + lastName + "','" + phone + "','" + emailID + "')"; + break; + case 50: + userType = "(bidder)"; + query = "insert into bidder(pass, fname, lname, ph, email) values ('" + passWord + "','" + firstName + "','" + + lastName + "','" + phone + "','" + emailID + "')"; + break; + } + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + st.executeUpdate(query, Statement.RETURN_GENERATED_KEYS); + ResultSet rs = st.getGeneratedKeys(); + int key = 0; + if (rs.next()) { + key = rs.getInt(1); + } + System.out.println("\b"); + System.out.println( + "Your " + userType + " username is: " + key + "\nPlease use your username and password to sign in."); + st.close(); + con.close(); + return key; + } + + private static int authenticate(int i) throws Exception { + System.out.println("\b"); + System.out.print("Username: "); + Scanner scan = new Scanner(System.in); + int uname = scan.nextInt(); + System.out.print("Password: "); + String pass = scan.next(); + + String query = ""; + switch (i) { + case 49: + query = "select pass from seller where uname = " + uname; + break; + case 50: + query = "select pass from bidder where uname = " + uname; + break; + case 97: + query = "select pass from admin where uname = " + uname; + break; + } + + Class.forName(classForName); + Connection con = DriverManager.getConnection(url, dbuname, dbpass); + Statement st = con.createStatement(); + ResultSet rs = st.executeQuery(query); + int returnVal = 0; + if (rs.next()) { + String passFetch = rs.getString("pass"); + if (pass.equals(passFetch)) { + System.out.println("\b"); + System.out.println("Successfully verified !"); + returnVal = uname; + } + } + st.close(); + con.close(); + return returnVal; + } +} diff --git a/AuctionHouseSchema.sql b/AuctionHouseSchema.sql new file mode 100644 index 0000000..0019e8e --- /dev/null +++ b/AuctionHouseSchema.sql @@ -0,0 +1,107 @@ +create schema if not exists `auction_house`; +Use auction_house; + +CREATE TABLE `admin` ( + `uname` int(11) NOT NULL AUTO_INCREMENT, + `pass` varchar(45) COLLATE utf8_bin NOT NULL, + PRIMARY KEY (`uname`) +) ENGINE=InnoDB AUTO_INCREMENT=787 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +insert into admin values(786,"admin"); + +CREATE TABLE `seller` ( + `uname` int(11) NOT NULL AUTO_INCREMENT, + `pass` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `fname` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `lname` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `ph` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `email` varchar(45) COLLATE utf8_bin DEFAULT NULL, + PRIMARY KEY (`uname`), + UNIQUE KEY `uname_UNIQUE` (`uname`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +CREATE TABLE `bidder` ( + `uname` int(11) NOT NULL AUTO_INCREMENT, + `pass` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `fname` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `lname` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `ph` varchar(45) COLLATE utf8_bin DEFAULT NULL UNIQUE, + `email` varchar(45) COLLATE utf8_bin DEFAULT NULL UNIQUE, + `approved` int(11) DEFAULT '0', + PRIMARY KEY (`uname`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +CREATE TABLE `product` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `pname` varchar(45) COLLATE utf8_bin DEFAULT NULL UNIQUE, + `des` varchar(100) COLLATE utf8_bin DEFAULT NULL UNIQUE, + `baseprice` double(10,2), + `duration` long, + `sold` int(11) DEFAULT '0', + `BidValue` double(10,2), + `startTime` datetime DEFAULT NULL, + `endTime` datetime DEFAULT NULL, + `lastBidder` int(11) DEFAULT NULL, + `approved` int(11) DEFAULT '0', + PRIMARY KEY (`id`), + KEY `lastBidder_idx` (`lastBidder`), + CONSTRAINT `lastBidder` FOREIGN KEY (`lastBidder`) REFERENCES `bidder` (`uname`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +CREATE TABLE `seller_sells` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `uname` int(11) DEFAULT NULL, + `productId` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `productid_idx` (`productId`), + CONSTRAINT `productid` FOREIGN KEY (`productId`) REFERENCES `product` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `uname` FOREIGN KEY (`uname`) REFERENCES `seller` (`uname`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +CREATE TABLE `bidder_bids` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `uname` int(11) DEFAULT NULL, + `productId` int(11) DEFAULT NULL, + `bidValue` double(10,2), + `placed` int(11) DEFAULT '0', + `wen` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `uname_idx` (`uname`), + KEY `productId_idx` (`productId`), + CONSTRAINT `productId2` FOREIGN KEY (`productId`) REFERENCES `product` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `uname2` FOREIGN KEY (`uname`) REFERENCES `bidder` (`uname`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +CREATE TABLE `withdraws` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `productId` int(11) DEFAULT NULL, + `pname` varchar(45) COLLATE utf8_bin DEFAULT NULL, + `uname` int(11) DEFAULT NULL, + `wen` datetime DEFAULT NULL, + `baseprice` double(10,2), + `lastbid` double(10,2), + PRIMARY KEY (`id`), + KEY `productId_idx` (`productId`), + KEY `uname_idx` (`uname`), + CONSTRAINT `productId4` FOREIGN KEY (`productId`) REFERENCES `product` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +DELIMITER // +CREATE PROCEDURE `auction_house`.`delete_obsolete_auctions` () +BEGIN + update product set sold = 1 where endTime < (SELECT NOW()) and approved = 1 and BidValue IS NOT null; + update product set approved = 0 where endTime < (SELECT NOW()) and approved = 1 and BidValue IS null; + INSERT INTO withdraws(productId, pname, uname, wen, baseprice, lastbid) + select id, pname, 0, (select NOW()), baseprice, BidValue FROM product where endTime < (SELECT NOW()) and approved = 0 and sold = 0 and BidValue IS null; + update product set sold = 3 where endTime < (SELECT NOW()) and approved = 0 and sold = 0 and BidValue IS null; +END // +DELIMITER ; + +SET SQL_SAFE_UPDATES=0; +SET GLOBAL event_scheduler = ON; +SET GLOBAL event_scheduler = 1; +CREATE EVENT myevent + ON SCHEDULE EVERY 1 SECOND + COMMENT 'Moves auctions with no bids to withdraws table.' + DO + CALL delete_obsolete_auctions(); \ No newline at end of file diff --git a/mysql-connector-java-5.1.40-bin.jar b/mysql-connector-java-5.1.40-bin.jar new file mode 100644 index 0000000..60bef5c Binary files /dev/null and b/mysql-connector-java-5.1.40-bin.jar differ