Advertisement
Guest User

appointmentregister.jsp

a guest
Jul 20th, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. <%--
  2. Document : appointmentregister
  3. Created on : Jul 1, 2018, 10:56:02 PM
  4. Author : hp
  5. --%>
  6.  
  7. <%
  8. String UserID = "";
  9. if (((String) session.getAttribute("UserID")) != null) {
  10. UserID = (String) session.getAttribute("UserID");
  11. }
  12. String Group = "";
  13. if (((String) session.getAttribute("Group")) != null) {
  14. Group = (String) session.getAttribute("Group");
  15. }
  16.  
  17. String Name = "";
  18. if (((String) session.getAttribute("Name")) != null) {
  19. Name = (String) session.getAttribute("Name");
  20. }
  21. %>
  22. <%@page import = "java.sql.ResultSet"%>
  23. <%@page import = "java.sql.Connection"%>
  24. <%@page import = "java.sql.Statement"%>
  25. <%@page import = "java.sql.DriverManager"%>
  26. <%@page contentType = "text/html" pageEncoding="UTF-8"%>
  27. <!DOCTYPE html>
  28. <html>
  29. <head>
  30. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  31. <title>VSMS</title>
  32. </head>
  33. <body>
  34. <%
  35. //TO CONNECT WITH dms DATABASE
  36. Connection connection = null;
  37.  
  38. try {
  39. Class.forName("org.gjt.mm.mysql.Driver");
  40. String url = "jdbc:mysql://localhost/dbcarservices";
  41. String user = "root";
  42. String pwd = "";
  43. connection = DriverManager.getConnection(url, user, pwd);
  44. Statement statement = connection.createStatement();
  45.  
  46. //GET DATA FROM STAFF FORM
  47. String platno = request.getParameter("platno");
  48. String appointmentdate = request.getParameter("appointmentdate");
  49. String appointmentstatus = "In Progress";
  50. String id = "";
  51. int min = 100;
  52. int count = 0;
  53.  
  54. String select = "select * from working where workingdate = '" + appointmentdate + "'";
  55. ResultSet rows = statement.executeQuery(select);
  56.  
  57. while (rows.next()) {
  58. if (min > rows.getInt("totalwork")){
  59. min = rows.getInt("totalwork");
  60. id = rows.getString("staffID");
  61. count++;
  62. }
  63. }
  64. if (count==0){
  65. out.println("<script>alert('Mechanic not available ! ');window.history.back();</script>");
  66. }
  67.  
  68. int total = min + 1;
  69. String update = "UPDATE working "
  70. + "SET "
  71. + "totalwork = '"+total+"' "
  72. + "WHERE staffID = '" + id + "'";
  73.  
  74. int j = statement.executeUpdate(update);
  75.  
  76.  
  77. //UPDATE STAFF TABLE
  78. String sql = "UPDATE appointment "
  79. + "SET "
  80. + "appointmentstatus = '" + appointmentstatus + "', staffID = '" + id + "'"
  81. + "WHERE platno = '" + platno + "' AND appointmentdate = '" + appointmentdate + "'";
  82.  
  83. int i = statement.executeUpdate(sql);
  84.  
  85.  
  86.  
  87. if (i== 1) {
  88. out.println("<script>alert('Appointment for "+platno+" on "+appointmentdate+" Successfully Registered! ');document.location.href='appointmentlist.jsp';</script>");
  89. } else {
  90. out.println("<script>alert('Failed to Register an Appointment for "+platno+" on "+appointmentdate+". Try Again ! ');window.history.back();</script>");
  91. }
  92.  
  93.  
  94. if (connection != null) {
  95. connection.close();
  96. }
  97.  
  98. } catch (Exception e) {
  99. out.println("Error" + e);
  100. System.out.println("Error" + e);
  101. //It is a good practice to use System.out.println()
  102. //for printing the error messages in the server console
  103. } finally {
  104. if (null != connection) {
  105. connection.close();
  106. }
  107. }
  108.  
  109. %>
  110. </body>
  111. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement