seungmin lee

현황보기, 검색하기, 예약하기 구현.

1차완성
1 <?xml version="1.0" encoding="UTF-8"?> 1 <?xml version="1.0" encoding="UTF-8"?>
2 <project version="4"> 2 <project version="4">
3 <component name="VcsDirectoryMappings"> 3 <component name="VcsDirectoryMappings">
4 - <mapping directory="$PROJECT_DIR$/.." vcs="Git" /> 4 + <mapping directory="$PROJECT_DIR$" vcs="Git" />
5 </component> 5 </component>
6 </project> 6 </project>
...\ No newline at end of file ...\ No newline at end of file
......
This diff is collapsed. Click to expand it.
1 -#-*- coding: utf-8 -*- 1 +# -*- coding: utf-8 -*-
2 # 한글 인코딩을 위한 주석입니다. 2 # 한글 인코딩을 위한 주석입니다.
3 3
4 # 사전설정: 4 # 사전설정:
5 - # pymysql 패키지가 있어야 합니다. 5 +# pymysql 패키지가 있어야 합니다.
6 - # pip install pymysql 6 +# pip install pymysql
7 - # 보안상 user_info에서 DB id, password를 가져옵니다. 7 +# 보안상 user_info에서 DB id, password를 가져옵니다.
8 - # user_info.py에서 DB id, password를 설정하고 사용해주세요. 8 +# user_info.py에서 DB id, password를 설정하고 사용해주세요.
9 # 외부에서 사용법: 9 # 외부에서 사용법:
10 - # from ReservationControl import * 10 +# from ReservationControl import *
11 11
12 import pymysql 12 import pymysql
13 import user_info 13 import user_info
14 import datetime 14 import datetime
15 15
16 16
17 -
18 -
19 -
20 -
21 -
22 -
23 # getReservations - 대여현황반환 함수 17 # getReservations - 대여현황반환 함수
24 # input: 18 # input:
25 - # string user_id 19 +# string user_id
26 # output: 20 # output:
27 - # 성공시 : tuple형태로 반환 => ( (1 ,"steven123", 7, "전자정보대학", "136호", 10, datetime.datetime(2018,12,5,12,0,0), datetime.datetime(2018,12,5,12,10,0), ), ) 21 +# 성공시 : tuple형태로 반환 => ( (1 ,"steven123", 7, "전자정보대학", "136호", 10, datetime.datetime(2018,12,5,12,0,0), datetime.datetime(2018,12,5,12,10,0), ), )
28 - # 순서 : reservations_id, user_id, facility_id, location, location_detail, capacity, start_time, end_time 22 +# 순서 : reservations_id, user_id, facility_id, location, location_detail, capacity, start_time, end_time
29 23
30 - # 실패시 : tuple형태로 반환 => ( ("SQL Error!", ), ) 24 +# 실패시 : result[0][0]="SQL Error!"인 tuple 반환 => ( ("SQL Error!", ), )
31 # 사용예: 25 # 사용예:
32 - # result = getReservations("khucse123") 26 +# result = getReservations("khucse123")
33 - # reservation_start_time = result[0][3] 27 +# reservation_start_time = result[0][3]
34 28
35 def getReservations(user_id): 29 def getReservations(user_id):
36 try: 30 try:
37 - db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd, db='FRS', charset='utf8') 31 + db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd,
32 + db='FRS', charset='utf8')
38 curs = db.cursor() 33 curs = db.cursor()
39 34
40 - #curs.execute("select * from reservations where user_id=%s", user_id) 35 + # curs.execute("select * from reservations where user_id=%s", user_id)
41 - curs.execute("select r.reservations_id, r.user_id, r.facility_id, f.location, f.location_detail, f.capacity, r.start_time, r.end_time from reservations r, facilities f where r.user_id=%s AND r.facility_id=f.facility_id;", user_id) 36 + curs.execute(
37 + "select r.reservations_id, r.user_id, r.facility_id, f.location, f.location_detail, f.capacity, r.start_time, r.end_time from reservations r, facilities f where r.user_id=%s AND r.facility_id=f.facility_id;",
38 + user_id)
42 result = curs.fetchall() 39 result = curs.fetchall()
43 print("Fetch Success!") 40 print("Fetch Success!")
44 return result 41 return result
...@@ -52,18 +49,19 @@ def getReservations(user_id): ...@@ -52,18 +49,19 @@ def getReservations(user_id):
52 49
53 # deleteReservations - 대여현황삭제 함수 50 # deleteReservations - 대여현황삭제 함수
54 # input: 51 # input:
55 - # int reservations_id 52 +# int reservations_id
56 # output: 53 # output:
57 - # 성공시 : True 54 +# 성공시 : True
58 - # 실패시 : False 55 +# 실패시 : False
59 # 사용예: 56 # 사용예:
60 - # deleteReservations(5) 57 +# deleteReservations(5)
61 # 주의사항: 58 # 주의사항:
62 - # 테스트환경에서 없는 reservations_id를 넣으면 에러가 날 수 있음 59 +# 테스트환경에서 없는 reservations_id를 넣으면 에러가 날 수 있음
63 60
64 def deleteReservations(reservations_id): 61 def deleteReservations(reservations_id):
65 try: 62 try:
66 - db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd, db='FRS', charset='utf8') 63 + db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd,
64 + db='FRS', charset='utf8')
67 curs = db.cursor() 65 curs = db.cursor()
68 66
69 curs.execute("delete from reservations where reservations_id=%s", reservations_id) 67 curs.execute("delete from reservations where reservations_id=%s", reservations_id)
...@@ -80,27 +78,29 @@ def deleteReservations(reservations_id): ...@@ -80,27 +78,29 @@ def deleteReservations(reservations_id):
80 78
81 # addReservations - 대여현황추가 함수 79 # addReservations - 대여현황추가 함수
82 # input: 80 # input:
83 - # string user_id 81 +# string user_id
84 - # int facility_id 82 +# int facility_id
85 - # datetime.datetime start_time 83 +# datetime.datetime start_time
86 - # datetime.datetime end_time 84 +# datetime.datetime end_time
87 # output: 85 # output:
88 - # 성공시 : True 86 +# 성공시 : True
89 - # 실패시 : False 87 +# 실패시 : False
90 # 사용예: 88 # 사용예:
91 - # tstart = datetime.datetime(2018,12,5,0,11,12) 89 +# tstart = datetime.datetime(2018,12,5,0,11,12)
92 - # tend = datetime.datetime(2018,12,5,0,20,12) 90 +# tend = datetime.datetime(2018,12,5,0,20,12)
93 - # addReservations("khucse123", 6, tstart, tend) 91 +# addReservations("khucse123", 6, tstart, tend)
94 # 주의사항: 92 # 주의사항:
95 - # 테스트환경에서 없는 user_id를 넣으면 에러가 날 수 있음 93 +# 테스트환경에서 없는 user_id를 넣으면 에러가 날 수 있음
96 - # 테스트환경에서 없는 facility_id를 넣으면 에러가 날 수 있음 94 +# 테스트환경에서 없는 facility_id를 넣으면 에러가 날 수 있음
97 95
98 def addReservations(user_id, facility_id, start_time, end_time): 96 def addReservations(user_id, facility_id, start_time, end_time):
99 try: 97 try:
100 - db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd, db='FRS', charset='utf8') 98 + db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd,
99 + db='FRS', charset='utf8')
101 curs = db.cursor() 100 curs = db.cursor()
102 101
103 - curs.execute("insert into reservations (user_id, facility_id, start_time, end_time) values (%s,%s,%s,%s)", (user_id, facility_id, start_time, end_time)) 102 + curs.execute("insert into reservations (user_id, facility_id, start_time, end_time) values (%s,%s,%s,%s)",
103 + (user_id, facility_id, start_time, end_time))
104 db.commit() 104 db.commit()
105 print("Add Reservation Success!") 105 print("Add Reservation Success!")
106 return True 106 return True
...@@ -111,3 +111,49 @@ def addReservations(user_id, facility_id, start_time, end_time): ...@@ -111,3 +111,49 @@ def addReservations(user_id, facility_id, start_time, end_time):
111 finally: 111 finally:
112 db.close() 112 db.close()
113 113
114 +
115 +# getAvailableFacilities - 사용가능시설물 반환함수
116 +# input:
117 +# string location
118 +# int capacity
119 +# datetime.datetime start_time
120 +# datetime.datetime end_time
121 +# output:
122 +# 성공시 : tuple형태로 반환 => ( (1, "전자정보대학", "B01호", 40, "강의실", "빔프로젝터", ), )
123 +# 순서 : facility_id, location, location_detail, capacity, facility_type, equipment
124 +# 사용가능한 시설물이 없을 시 : result[0][0]="NoAvailableFacilites"인 tuple 반환 => ( ("NoAvailableFacilites", ), )
125 +
126 +# 실패시 : result[0][0]="SQL Error!"인 tuple 반환 => ( ("SQL Error!", ), )
127 +# 사용예:
128 +# tstart = datetime.datetime(2018,12,5,12,11,12)
129 +# tend = datetime.datetime(2018,12,5,14,20,12)
130 +# result = getAvailableFacilities("전자정보대학", 40, tstart, tend)
131 +# facility_id = result[0][0]
132 +
133 +def getAvailableFacilities(location, capacity, start_time, end_time):
134 + try:
135 + db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd,
136 + db='FRS', charset='utf8')
137 + curs = db.cursor()
138 +
139 + curs.execute(
140 + "select facility_id, location, location_detail, capacity, facility_type, equipment from facilities where (facility_id not in(select facility_id from reservations where (start_time<=%s AND %s<end_time) OR (start_time<%s AND %s<=end_time) OR (%s<=start_time AND end_time<=%s))) AND location=%s AND %s<=capacity;",
141 + (start_time, start_time, end_time, end_time, start_time, end_time, location, capacity))
142 +
143 + result = curs.fetchall()
144 + print("Fetch Success!")
145 +
146 + # 사용 가능한 시설물이 있을 경우
147 + if (len(result) != 0):
148 + return result
149 + # 사용 가능한 시설물이 없을 경우
150 + else:
151 + print("No Available Facilities")
152 + return (("NoAvailableFacilities",),)
153 +
154 + except:
155 + print("SQL Error!")
156 + return (("SQL Error!",),)
157 +
158 + finally:
159 + db.close()
......
...@@ -79,22 +79,30 @@ def book(): ...@@ -79,22 +79,30 @@ def book():
79 @app.route('/search/result', methods=['POST']) 79 @app.route('/search/result', methods=['POST'])
80 def search_result(): 80 def search_result():
81 searchdata = request.form 81 searchdata = request.form
82 - print(searchdata)
83 starttime = datetime.strptime(searchdata.get('starttime'),'%Y-%m-%dT%H:%M') 82 starttime = datetime.strptime(searchdata.get('starttime'),'%Y-%m-%dT%H:%M')
84 endtime = datetime.strptime(searchdata.get('endtime'),'%Y-%m-%dT%H:%M') 83 endtime = datetime.strptime(searchdata.get('endtime'),'%Y-%m-%dT%H:%M')
85 - print(starttime,endtime) 84 + if(starttime.strftime('%Y%m%d') == endtime.strftime('%Y%m%d')):
86 - if searchdata.get('search'): 85 + result = getAvailableFacilities(searchdata.get('deptid'),searchdata.get('capacity'),starttime,endtime)
87 - # searchdata.get('searchinput') 얻어와서 sql 검색 쿼리 86 + print(result)
88 - pass 87 + return render_template("searchresult.html", resv_list=result, starttime=starttime, endtime=endtime)
89 - elif searchdata.get('cat'): 88 + else:
90 - # searchdata.get('searchinput') 얻어와서 sql 검색 쿼리 89 + flash("2일 이상의 일정으로 예약 불가합니다")
91 - pass 90 + return redirect("/search")
92 - return render_template("searchresult.html", result) 91 +
93 92
94 93
95 @app.route('/search/resv', methods=['POST']) 94 @app.route('/search/resv', methods=['POST'])
96 def book_confirm(): 95 def book_confirm():
97 - pass #search_result 페이지에서 JS로든 요청 보내면 예약 처리 96 + book_query=request.form
97 + print(book_query)
98 + starttime = datetime.strptime(book_query.get('start_time'), '%Y-%m-%d%H:%M')
99 + endtime = datetime.strptime(book_query.get('end_time'), '%Y-%m-%d%H:%M')
100 + if addReservations(session['ID'],book_query.get('fac_id'),starttime,endtime):
101 + flash("예약에 성공했습니다")
102 + return redirect('/myhome')
103 + else:
104 + flash("예약에 실패했습니다.")
105 + return redirect('/search')
98 106
99 107
100 108
......
...@@ -77,7 +77,7 @@ input{ ...@@ -77,7 +77,7 @@ input{
77 </style> 77 </style>
78 {% endblock %} 78 {% endblock %}
79 {% block content %} 79 {% block content %}
80 -<img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/> 80 +<a href="/myhome"> <img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/></a>
81 <form action="/join/confirm" method="post"> 81 <form action="/join/confirm" method="post">
82 82
83 <br><br> 83 <br><br>
......
...@@ -22,6 +22,7 @@ input[type=text] { ...@@ -22,6 +22,7 @@ input[type=text] {
22 transition: 0.5s; 22 transition: 0.5s;
23 outline: none; 23 outline: none;
24 font-family: 'MyWebFont'; 24 font-family: 'MyWebFont';
25 + min-width: 200px;
25 } 26 }
26 input[type=text]:focus { 27 input[type=text]:focus {
27 border: 3px solid #555; 28 border: 3px solid #555;
...@@ -37,6 +38,7 @@ input[type=password] { ...@@ -37,6 +38,7 @@ input[type=password] {
37 outline: none; 38 outline: none;
38 margin-right: 7px; 39 margin-right: 7px;
39 font-family: 'MyWebFont'; 40 font-family: 'MyWebFont';
41 + min-width: 200px;
40 } 42 }
41 input[type=password]:focus { 43 input[type=password]:focus {
42 border: 3px solid #555; 44 border: 3px solid #555;
......
...@@ -64,7 +64,7 @@ img { ...@@ -64,7 +64,7 @@ img {
64 </style> 64 </style>
65 {% block style %}{% endblock %} 65 {% block style %}{% endblock %}
66 66
67 -<body > 67 +<body>
68 {% with messages = get_flashed_messages(with_categories=true) %} 68 {% with messages = get_flashed_messages(with_categories=true) %}
69 {% if messages %} 69 {% if messages %}
70 {% for category, message in messages %} 70 {% for category, message in messages %}
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
6 <style> 6 <style>
7 body { 7 body {
8 background-color: rgb(230, 243, 255); 8 background-color: rgb(230, 243, 255);
9 - text-align: center;
10 } 9 }
11 10
12 #select1 { 11 #select1 {
...@@ -146,7 +145,7 @@ select{ ...@@ -146,7 +145,7 @@ select{
146 border-radius: 5px; 145 border-radius: 5px;
147 } 146 }
148 #maxpeople{ 147 #maxpeople{
149 - width: 55%; 148 + width: 60%;
150 padding: 12px 20px; 149 padding: 12px 20px;
151 box-sizing: border-box; 150 box-sizing: border-box;
152 border: 3px solid #ccc; 151 border: 3px solid #ccc;
...@@ -169,29 +168,38 @@ h3 { ...@@ -169,29 +168,38 @@ h3 {
169 margin-top: 15px; 168 margin-top: 15px;
170 169
171 } 170 }
171 +</style>
172 {% endblock %} 172 {% endblock %}
173 {% block content %} 173 {% block content %}
174 -</style>
175 174
176 -<body> 175 +
177 176
178 <br> 177 <br>
179 -<img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/> 178 +<a href="/myhome"> <img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/></a>
180 <div id="wrapper"> 179 <div id="wrapper">
181 <form action="/search/result" method="post"> 180 <form action="/search/result" method="post">
182 181
183 <br><br> 182 <br><br>
184 183
185 -<div class="item"><H3>부서 ID</H3> 184 +<div class="item"><H3>건물</H3>
186 - <select name="deptid" required><option value="1">전자정보대학</option> 185 + <select name="deptid" required><option value="전자정보대학">전자정보대학</option>
187 - <option value="2">외국어대학</option> 186 + <option value="외국어대학">외국어대학</option>
188 - <option value="3">공과대학</option> 187 + <option value="공과대학">공과대학</option>
189 - <option value="4">예술디자인대학</option> 188 + <option value="예술,디자인대학">예술,디자인대학</option>
190 - <option value="5">체육대학</option> 189 + <option value="체육대학">체육대학</option>
191 - <option value="6">국제대학</option> 190 + <option value="국제대학">국제대학</option>
192 - <option value="7">대학본부</option></select> 191 + <option value="1호관 테니스장">1호관 테니스장</option>
192 + <option value="3호관 운동장">3호관 운동장</option>
193 + <option value="3호관 테니스장">3호관 테니스장</option>
194 + <option value="6호관 야구장">6호관 야구장</option>
195 + <option value="6호관 운동장">6호관 운동장</option>
196 + <option value="골프 연습장">골프 연습장</option>
197 + <option value="6호관 운동장">6호관 운동장</option>
198 + <option value="수영장">수영장</option>
199 + <option value="필드 하키장(공과대학 앞)">필드 하키장(공과대학 앞)</option>
200 + <option value="학생회관">학생회관</option></select>
193 <br></div> 201 <br></div>
194 - <center><div class="item"><H3>사용 인원 수</H3><input type="number" id="maxpeople" name="quantity" min="1" max="200"></div></center><br> 202 + <center><div class="item"><H3>사용 인원 수</H3><input type="number" id="maxpeople" name="capacity" min="1" max="200"></div></center><br>
195 203
196 204
197 <center>시작 시간<br><br><input type="datetime-local" name="starttime"></center><br> 205 <center>시작 시간<br><br><input type="datetime-local" name="starttime"></center><br>
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
36 </style> 36 </style>
37 {% endblock %} 37 {% endblock %}
38 {% block content %} 38 {% block content %}
39 - <img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/><br> 39 + <a href="/myhome"> <img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/></a>
40 <h1>예약 현황</h1> 40 <h1>예약 현황</h1>
41 {% if not resv_list %} 41 {% if not resv_list %}
42 <p>예약 데이터가 없습니다.</p> 42 <p>예약 데이터가 없습니다.</p>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
6 {% block style %} 6 {% block style %}
7 <style> 7 <style>
8 #list_item{ 8 #list_item{
9 - width: 275px; 9 + width: 263px;
10 height: 100px; 10 height: 100px;
11 font-size:20px; 11 font-size:20px;
12 font-family: '배달의민족 도현'; 12 font-family: '배달의민족 도현';
...@@ -17,17 +17,18 @@ ...@@ -17,17 +17,18 @@
17 vertical-align: bottom; 17 vertical-align: bottom;
18 line-height: 150%; 18 line-height: 150%;
19 display: inline-block; 19 display: inline-block;
20 + padding-left: 7px;
20 } 21 }
21 #delete_btn{ 22 #delete_btn{
22 - width: 47px; 23 + width: 60px;
23 height: 110px; 24 height: 110px;
24 box-sizing: border-box; 25 box-sizing: border-box;
25 font-size: 20px; 26 font-size: 20px;
26 font-family: '배달의민족 도현'; 27 font-family: '배달의민족 도현';
27 - background-color: rgb(255, 101, 101); 28 + background-color: rgb(90, 200, 90);
28 color: white; 29 color: white;
29 border-radius:5px; 30 border-radius:5px;
30 - border: solid 5px rgb(255, 101, 101); 31 + border: solid 5px rgb(90, 200, 90);
31 float: right; 32 float: right;
32 display: inline-block; 33 display: inline-block;
33 34
...@@ -36,18 +37,20 @@ ...@@ -36,18 +37,20 @@
36 </style> 37 </style>
37 {% endblock %} 38 {% endblock %}
38 {% block content %} 39 {% block content %}
39 - <img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/><br> 40 + <a href="/myhome"> <img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/></a><br>
40 <h1>검색 결과</h1> 41 <h1>검색 결과</h1>
41 - {% if not resv_list %} 42 + {% if resv_list[0][0] == "NoAvailableFacilities" %}
42 <p>가능한 강의실이 없습니다.</p> 43 <p>가능한 강의실이 없습니다.</p>
43 -{% endif %} 44 +{% else %}
44 <table> 45 <table>
45 {% for resv_item in resv_list %} 46 {% for resv_item in resv_list %}
46 - <tr><td><form method="post" action="/search/resv"><div id="list_item">{{ resv_item[3] }} {{ resv_item[4] }}<br>{{ resv_item[6].strftime('%Y-%m-%d') }}<br>{{ resv_item[6].strftime('%H:%M') }} ~ {{ resv_item[7].strftime('%H:%M') }} 47 + <tr><td><form method="post" action="/search/resv"><div id="list_item">{{ resv_item[1] }} {{ resv_item[2] }}<br>{{ starttime.strftime('%Y-%m-%d') }}<br>{{ starttime.strftime('%H:%M') }} ~ {{ endtime.strftime('%H:%M') }}
47 - <form method="post" action="/deleteresv"> 48 + <input type="hidden" name="fac_id" value="{{ resv_item[0] }}">
48 - <input type="hidden" name="resv_id" value="{{ 강의실ID }}"> 49 + <input type="hidden" name="start_time" value="{{ starttime.strftime('%Y-%m-%d%H:%M') }}">
50 + <input type="hidden" name="end_time" value="{{ endtime.strftime('%Y-%m-%d%H:%M') }}">
49 </div><input type="submit" id="delete_btn" value="예약"></form></td></tr> 51 </div><input type="submit" id="delete_btn" value="예약"></form></td></tr>
50 {% endfor %} 52 {% endfor %}
51 </table> 53 </table>
54 + {% endif %}
52 {% endblock %} 55 {% endblock %}
53 56
......