Skip to content

Commit

Permalink
Merge pull request #42 from gaarden/geunchan
Browse files Browse the repository at this point in the history
transaction#program apply for user and admin
  • Loading branch information
geunchanKim authored Dec 5, 2023
2 parents 806074e + a1fd641 commit 849232a
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 34 deletions.
60 changes: 60 additions & 0 deletions KNU_MUSEUM/src/main/webapp/program_apply_manage_fail.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page language="java"
import="java.text.*, java.sql.*, java.time.LocalDate"%>
<%@ 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>

<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>
<a href="program_apply_manage.jsp" style="color: #626A72"><h4
style="margin-bottom: 20px;">다시 체험 프로그램 신청서 체크하기</h4></a>
</div>



</body>
</html>
72 changes: 40 additions & 32 deletions KNU_MUSEUM/src/main/webapp/program_apply_o.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -66,46 +66,54 @@
</nav>


<%
String ApplyID = request.getParameter("ApplyID");
String query = "UPDATE MUSEUM_PROGRAM_APPLICATION SET Status = '1' WHERE ApplyID = ?";
<%
PreparedStatement pstmt = null;
try {
conn.setAutoCommit(false);
pstmt = conn.prepareStatement(query);
pstmt.setString(1, ApplyID);
String ApplyID = request.getParameter("ApplyID");
// Check if the application still exists
String applicationCheckQuery = "SELECT COUNT(*) FROM MUSEUM_PROGRAM_APPLICATION WHERE ApplyID = ?";
PreparedStatement applicationCheckStmt = conn.prepareStatement(applicationCheckQuery);
applicationCheckStmt.setString(1, ApplyID);
ResultSet applicationCheckResult = applicationCheckStmt.executeQuery();
applicationCheckResult.next();
int applicationCount = applicationCheckResult.getInt(1);
applicationCheckStmt.close();
applicationCheckResult.close();
if (applicationCount == 0) {
response.sendRedirect("program_apply_manage_fail.jsp");
} else {
String query = "UPDATE MUSEUM_PROGRAM_APPLICATION SET Status = '1' WHERE ApplyID = ?";
pstmt = conn.prepareStatement(query);
pstmt.setString(1, ApplyID);
// executeUpdate 메서드를 사용하여 업데이트된 행 수를 반환
int rowsUpdated = pstmt.executeUpdate();
int rowsUpdated = pstmt.executeUpdate();
out.println("<div class=\"box\">");
if (rowsUpdated > 0) {
out.println("업데이트 성공");
conn.commit();
} else {
out.println("업데이트된 행이 없음");
conn.rollback();
}
out.println("<a href=\"program_apply_manage.jsp\">관리 페이지로 돌아가기</a>");
out.println("</div>");
}
out.println("<div class=\"box\">");
if (rowsUpdated > 0) {
out.println("업데이트 성공");
conn.commit();
} else {
out.println("업데이트된 행이 없음");
conn.rollback();
}
out.println("<a href=\"program_apply_manage.jsp\">관리 페이지로 돌아가기</a>");
out.println("</div>");
} catch (SQLException e) {
e.printStackTrace();
e.printStackTrace();
} finally {
// 리소스 해제
try {
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
// 리소스 해제
try {
if (pstmt != null) {
pstmt.close();
}
%>


} catch (SQLException e) {
e.printStackTrace();
}
}
%>
</body>
</html>
17 changes: 15 additions & 2 deletions KNU_MUSEUM/src/main/webapp/program_apply_x.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,24 @@
<%
String ApplyID = request.getParameter("ApplyID");
String query = "UPDATE MUSEUM_PROGRAM_APPLICATION SET Status = '0' WHERE ApplyID = ?";
PreparedStatement pstmt = null;
try {
conn.setAutoCommit(false);
// Check if the application still exists
String applicationCheckQuery = "SELECT COUNT(*) FROM MUSEUM_PROGRAM_APPLICATION WHERE ApplyID = ?";
PreparedStatement applicationCheckStmt = conn.prepareStatement(applicationCheckQuery);
applicationCheckStmt.setString(1, ApplyID);
ResultSet applicationCheckResult = applicationCheckStmt.executeQuery();
applicationCheckResult.next();
int applicationCount = applicationCheckResult.getInt(1);
applicationCheckStmt.close();
applicationCheckResult.close();
if (applicationCount == 0) {
response.sendRedirect("program_apply_manage_fail.jsp");
} else{
String query = "UPDATE MUSEUM_PROGRAM_APPLICATION SET Status = '0' WHERE ApplyID = ?";
pstmt = conn.prepareStatement(query);
pstmt.setString(1, ApplyID);
Expand All @@ -89,6 +102,7 @@
}
out.println("<a href=\"program_apply_manage.jsp\">관리 페이지로 돌아가기</a>");
out.println("</div>");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
Expand All @@ -101,7 +115,6 @@
e.printStackTrace();
}
}
%>

</body>
Expand Down

0 comments on commit 849232a

Please sign in to comment.