Skip to content

Commit

Permalink
Merge pull request #40 from gaarden/geunchan
Browse files Browse the repository at this point in the history
transaction#1 complete
  • Loading branch information
geunchanKim authored Dec 5, 2023
2 parents cbe7893 + fa04353 commit f7a0bdf
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 125 deletions.
151 changes: 151 additions & 0 deletions KNU_MUSEUM/src/main/webapp/group_apply_fail.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page language="java"
import="java.text.*, java.sql.*, java.time.LocalDate, java.util.ArrayList, java.util.List, java.util.Random"%>
<%@ page import="common.Person"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>KNU_MUSEUM</title>
<link rel="stylesheet" type="text/css" href="css/program_apply.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
crossorigin="anonymous">
</head>
<body>
<%
String serverIP = "localhost";
//String strSID = "xe";
String strSID = "orcl";
String portNum = "1521";
String user = "KNU_MUSEUM";
String pass = "comp322";
String url = "jdbc:oracle:thin:@" + serverIP + ":" + portNum + ":" + strSID;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs;
Statement stmt = null;
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, user, pass);
conn.setAutoCommit(false);
stmt = conn.createStatement();
request.setCharacterEncoding("utf-8");
String UserID = (String) session.getAttribute("UserID");
String GAppDate = request.getParameter("selectedDate");
String GAppTime = request.getParameter("time");
String ApplyNum = request.getParameter("num");
String CuserID = UserID;
String CadminID;
// grouptourID 설정
String maxGroupTourIDQuery = "SELECT MAX(TO_NUMBER(SUBSTR(GroupTourID, 10))) AS MaxGroupTourID FROM GROUP_TOUR_APPLICATION";
ResultSet maxGroupTourIDResultSet = stmt.executeQuery(maxGroupTourIDQuery);
maxGroupTourIDResultSet.next();
int maxGroupTourIDNumber = maxGroupTourIDResultSet.getInt(1);
int newGroupTourIDNumber = maxGroupTourIDNumber + 1;
String newGroupTourID = "grouptour" + newGroupTourIDNumber;
maxGroupTourIDResultSet.close();
// 랜덤으로 adminID 가져오기
String adminIDQuery = "SELECT AdminID FROM ADMIN";
ResultSet CadminIDResultSet = stmt.executeQuery(adminIDQuery);
List<String> adminIDList = new ArrayList<>();
while (CadminIDResultSet.next()) {
adminIDList.add(CadminIDResultSet.getString(1));
}
Random random = new Random();
CadminID = adminIDList.get(random.nextInt(adminIDList.size()));
CadminIDResultSet.close();
try {
String sql = "INSERT INTO GROUP_TOUR_APPLICATION (GroupTourID, GAppDate, GAppTime, ApplyNum, Status, CuserID, CadminID) VALUES (?, TO_DATE(?, 'YYYY.MM.DD'), ?, ?, ?, ?, ?)"; CadminID = "admin168";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, newGroupTourID);
pstmt.setString(2, GAppDate);
pstmt.setInt(3, Integer.parseInt(GAppTime));
pstmt.setInt(4, Integer.parseInt(ApplyNum));
pstmt.setInt(5, 2); // Status 0: 반려, Status 1: 승인, Status 2: 대기
pstmt.setString(6, CuserID);
pstmt.setString(7, CadminID);
int res = pstmt.executeUpdate();
if (res > 0) {
conn.commit();
}
} catch (SQLException e) {
// Handle exceptions if necessary
e.printStackTrace();
conn.rollback(); // Rollback the transaction if there's an exception
} finally {
try {
if (pstmt != null)
pstmt.close();
// Close other resources if needed
} catch (SQLException e) {
e.printStackTrace();
}
}
%>

<nav class="navbar navbar-expand-lg bg-body-tertiary">
<div class="container-fluid">
<a class="navbar-brand" href="main.html"> <img
src="img/knu_museum_logo.jpg" alt="Logo" width="30" height="24"
class="d-inline-block align-text-top">
</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item"><a class="nav-link active"
aria-current="page" href="info_for_user.jsp">이용안내</a></li>
<li class="nav-item"><a class="nav-link active"
aria-current="page" href="artifact_for_user.jsp">소장유물</a></li>
<li class="nav-item"><a class="nav-link active"
aria-current="page" href="program_for_user.jsp">체험프로그램</a></li>
<li class="nav-item"><a class="nav-link active"
aria-current="page" href="program_apply.jsp">체험 프로그램 신청</a></li>
<li class="nav-item"><a class="nav-link active"
aria-current="page" href="group_apply.jsp">단체관람 신청</a></li>
</ul>
<span class="navbar-text">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item"><a class="nav-link" href="user_view.jsp">My
Page</a></li>
<li class="nav-item"><a class="nav-link" href="main.html">로그아웃</a></li>
</ul>
</span>
</div>
</div>
</nav>

<div class="box">
<h2 style="margin-bottom: 20px;">신청이 완료되었습니다.</h2>
<table class="table">
<thead>
<tr>
<th scope="col">신청 날짜</th>
<th scope="col">시작 시간</th>
<th scope="col">신청 인원</th>
</tr>
</thead>
<tbody>
<tr>
<td><%=GAppDate%></td>
<td><%=GAppTime%></td>
<td><%=ApplyNum%></td>
</tr>
</tbody>
</table>
<br /> <a href="user_view.jsp" style="color:#626A72"><h4>단체관람 신청내역 확인하기</h4></a>
</div>



</body>
</html>
128 changes: 3 additions & 125 deletions KNU_MUSEUM/src/main/webapp/program_apply_complete.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -17,110 +17,6 @@
crossorigin="anonymous">
</head>
<body>
<%
String serverIP = "localhost";
//String strSID = "xe";
String strSID = "orcl";
String portNum = "1521";
String user = "KNU_MUSEUM";
String pass = "comp322";
String url = "jdbc:oracle:thin:@" + serverIP + ":" + portNum + ":" + strSID;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs;
Statement stmt = null;
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, user, pass);
conn.setAutoCommit(false);
stmt = conn.createStatement();
request.setCharacterEncoding("utf-8");
String UserID = (String) session.getAttribute("UserID");
String CeduID = request.getParameter("program");
String ApplyNum = request.getParameter("num");
String MAppDate = request.getParameter("selectedDate");
String MAppTimeS = request.getParameter("time");
String CuserID = UserID;
String title = "";
// CeduID 설정
if (request.getSession().getAttribute("selectedEduID") != null) {
CeduID = (String) request.getSession().getAttribute("selectedEduID");
}
try {
conn.setAutoCommit(false);
// ApplyID 설정
String maxApplyIDQuery = "SELECT MAX(TO_NUMBER(SUBSTR(ApplyID, 6))) AS MaxApplyID FROM MUSEUM_PROGRAM_APPLICATION";
ResultSet maxApplyIDResultSet = stmt.executeQuery(maxApplyIDQuery);
maxApplyIDResultSet.next();
int maxApplyIDNumber = maxApplyIDResultSet.getInt(1);
int newApplyIDNumber = maxApplyIDNumber + 1;
String newApplyID = "apply" + newApplyIDNumber;
maxApplyIDResultSet.close();
// 해당 프로그램에 맞는 CadminID 가져오기
String sql2 = "SELECT MadminID FROM MUSEUM_PROGRAM_LIST WHERE EduID = ?";
PreparedStatement pstmt3 = conn.prepareStatement(sql2);
pstmt3.setString(1, CeduID);
ResultSet adminIDResultSet = pstmt3.executeQuery();
String CadminID = null;
if (adminIDResultSet.next()) {
CadminID = adminIDResultSet.getString(1);
} else {
// Handle the case when no matching EduID is found
out.println("No matching EduID found in the museum_program_list table.");
}
pstmt3.close();
adminIDResultSet.close();
String sql = "INSERT INTO MUSEUM_PROGRAM_APPLICATION (ApplyID, ApplyNum, MAppDate, MAppTime, Status, CeduID, CuserID, CadminID) VALUES (?, ?, TO_DATE(?, 'YYYY.MM.DD'), ?, ?, ?, ?, ?)";
PreparedStatement pstmt2 = conn.prepareStatement(sql);
pstmt2.setString(1, newApplyID);
pstmt2.setInt(2, Integer.parseInt(ApplyNum));
pstmt2.setString(3, MAppDate);
pstmt2.setInt(4, Integer.parseInt(MAppTimeS));
pstmt2.setInt(5, 2); // Status 0: 반려, Status 1: 승인, Status 2: 대기
pstmt2.setString(6, CeduID);
pstmt2.setString(7, CuserID);
pstmt2.setString(8, CadminID);
int res = pstmt2.executeUpdate();
pstmt2.close();
String sql1 = "select title from museum_program_list where eduid = ?";
PreparedStatement pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, CeduID);
ResultSet rs1 = pstmt1.executeQuery();
if (rs1.next()) {
title = rs1.getString(1);
} else {
out.println("No matching title found in the museum_program_list table.");
}
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
conn.rollback();
} finally {
try {
if (pstmt != null) {
pstmt.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
%>

<nav class="navbar navbar-expand-lg bg-body-tertiary">
<div class="container-fluid">
Expand Down Expand Up @@ -153,27 +49,9 @@
</nav>

<div class="box">
<h2 style="margin-bottom: 20px;">신청이 완료되었습니다.</h2>
<table class="table">
<thead>
<tr>
<th scope="col">프로그램 제목</th>
<th scope="col">신청 날짜</th>
<th scope="col">신청 시간</th>
<th scope="col">신청 인원</th>
</tr>
</thead>
<tbody>
<tr>
<td><%=title%></td>
<td><%=MAppDate%></td>
<td><%=MAppTimeS%></td>
<td><%=ApplyNum%></td>
</tr>
</tbody>
</table>
<a href="user_view.jsp" style="color:#626A72"><h4 style="margin-bottom: 20px;">
신청내역 확인하기</h4></a>
<h2 style="margin-bottom: 20px;">신청에 실패했습니다.</h2>
<a href="program_apply.jsp" style="color: #626A72"><h4
style="margin-bottom: 20px;">다시 신청하러 가기</h4></a>
</div>


Expand Down

0 comments on commit f7a0bdf

Please sign in to comment.