seungmin lee

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

1차완성
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
......
This diff is collapsed. Click to expand it.
#-*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# 한글 인코딩을 위한 주석입니다.
# 사전설정:
# pymysql 패키지가 있어야 합니다.
# pip install pymysql
# 보안상 user_info에서 DB id, password를 가져옵니다.
# user_info.py에서 DB id, password를 설정하고 사용해주세요.
# pymysql 패키지가 있어야 합니다.
# pip install pymysql
# 보안상 user_info에서 DB id, password를 가져옵니다.
# user_info.py에서 DB id, password를 설정하고 사용해주세요.
# 외부에서 사용법:
# from ReservationControl import *
# from ReservationControl import *
import pymysql
import user_info
import datetime
# getReservations - 대여현황반환 함수
# input:
# string user_id
# string user_id
# output:
# 성공시 : tuple형태로 반환 => ( (1 ,"steven123", 7, "전자정보대학", "136호", 10, datetime.datetime(2018,12,5,12,0,0), datetime.datetime(2018,12,5,12,10,0), ), )
# 순서 : reservations_id, user_id, facility_id, location, location_detail, capacity, start_time, end_time
# 성공시 : tuple형태로 반환 => ( (1 ,"steven123", 7, "전자정보대학", "136호", 10, datetime.datetime(2018,12,5,12,0,0), datetime.datetime(2018,12,5,12,10,0), ), )
# 순서 : reservations_id, user_id, facility_id, location, location_detail, capacity, start_time, end_time
# 실패시 : tuple형태로 반환 => ( ("SQL Error!", ), )
# 실패시 : result[0][0]="SQL Error!"인 tuple 반환 => ( ("SQL Error!", ), )
# 사용예:
# result = getReservations("khucse123")
# reservation_start_time = result[0][3]
# result = getReservations("khucse123")
# reservation_start_time = result[0][3]
def getReservations(user_id):
try:
db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd, db='FRS', charset='utf8')
db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd,
db='FRS', charset='utf8')
curs = db.cursor()
#curs.execute("select * from reservations where user_id=%s", user_id)
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)
# curs.execute("select * from reservations where user_id=%s", user_id)
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)
result = curs.fetchall()
print("Fetch Success!")
return result
......@@ -52,18 +49,19 @@ def getReservations(user_id):
# deleteReservations - 대여현황삭제 함수
# input:
# int reservations_id
# int reservations_id
# output:
# 성공시 : True
# 실패시 : False
# 성공시 : True
# 실패시 : False
# 사용예:
# deleteReservations(5)
# deleteReservations(5)
# 주의사항:
# 테스트환경에서 없는 reservations_id를 넣으면 에러가 날 수 있음
# 테스트환경에서 없는 reservations_id를 넣으면 에러가 날 수 있음
def deleteReservations(reservations_id):
try:
db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd, db='FRS', charset='utf8')
db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd,
db='FRS', charset='utf8')
curs = db.cursor()
curs.execute("delete from reservations where reservations_id=%s", reservations_id)
......@@ -80,27 +78,29 @@ def deleteReservations(reservations_id):
# addReservations - 대여현황추가 함수
# input:
# string user_id
# int facility_id
# datetime.datetime start_time
# datetime.datetime end_time
# string user_id
# int facility_id
# datetime.datetime start_time
# datetime.datetime end_time
# output:
# 성공시 : True
# 실패시 : False
# 성공시 : True
# 실패시 : False
# 사용예:
# tstart = datetime.datetime(2018,12,5,0,11,12)
# tend = datetime.datetime(2018,12,5,0,20,12)
# addReservations("khucse123", 6, tstart, tend)
# tstart = datetime.datetime(2018,12,5,0,11,12)
# tend = datetime.datetime(2018,12,5,0,20,12)
# addReservations("khucse123", 6, tstart, tend)
# 주의사항:
# 테스트환경에서 없는 user_id를 넣으면 에러가 날 수 있음
# 테스트환경에서 없는 facility_id를 넣으면 에러가 날 수 있음
# 테스트환경에서 없는 user_id를 넣으면 에러가 날 수 있음
# 테스트환경에서 없는 facility_id를 넣으면 에러가 날 수 있음
def addReservations(user_id, facility_id, start_time, end_time):
try:
db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd, db='FRS', charset='utf8')
db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd,
db='FRS', charset='utf8')
curs = db.cursor()
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))
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))
db.commit()
print("Add Reservation Success!")
return True
......@@ -111,3 +111,49 @@ def addReservations(user_id, facility_id, start_time, end_time):
finally:
db.close()
# getAvailableFacilities - 사용가능시설물 반환함수
# input:
# string location
# int capacity
# datetime.datetime start_time
# datetime.datetime end_time
# output:
# 성공시 : tuple형태로 반환 => ( (1, "전자정보대학", "B01호", 40, "강의실", "빔프로젝터", ), )
# 순서 : facility_id, location, location_detail, capacity, facility_type, equipment
# 사용가능한 시설물이 없을 시 : result[0][0]="NoAvailableFacilites"인 tuple 반환 => ( ("NoAvailableFacilites", ), )
# 실패시 : result[0][0]="SQL Error!"인 tuple 반환 => ( ("SQL Error!", ), )
# 사용예:
# tstart = datetime.datetime(2018,12,5,12,11,12)
# tend = datetime.datetime(2018,12,5,14,20,12)
# result = getAvailableFacilities("전자정보대학", 40, tstart, tend)
# facility_id = result[0][0]
def getAvailableFacilities(location, capacity, start_time, end_time):
try:
db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd,
db='FRS', charset='utf8')
curs = db.cursor()
curs.execute(
"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;",
(start_time, start_time, end_time, end_time, start_time, end_time, location, capacity))
result = curs.fetchall()
print("Fetch Success!")
# 사용 가능한 시설물이 있을 경우
if (len(result) != 0):
return result
# 사용 가능한 시설물이 없을 경우
else:
print("No Available Facilities")
return (("NoAvailableFacilities",),)
except:
print("SQL Error!")
return (("SQL Error!",),)
finally:
db.close()
......
......@@ -79,22 +79,30 @@ def book():
@app.route('/search/result', methods=['POST'])
def search_result():
searchdata = request.form
print(searchdata)
starttime = datetime.strptime(searchdata.get('starttime'),'%Y-%m-%dT%H:%M')
endtime = datetime.strptime(searchdata.get('endtime'),'%Y-%m-%dT%H:%M')
print(starttime,endtime)
if searchdata.get('search'):
# searchdata.get('searchinput') 얻어와서 sql 검색 쿼리
pass
elif searchdata.get('cat'):
# searchdata.get('searchinput') 얻어와서 sql 검색 쿼리
pass
return render_template("searchresult.html", result)
if(starttime.strftime('%Y%m%d') == endtime.strftime('%Y%m%d')):
result = getAvailableFacilities(searchdata.get('deptid'),searchdata.get('capacity'),starttime,endtime)
print(result)
return render_template("searchresult.html", resv_list=result, starttime=starttime, endtime=endtime)
else:
flash("2일 이상의 일정으로 예약 불가합니다")
return redirect("/search")
@app.route('/search/resv', methods=['POST'])
def book_confirm():
pass #search_result 페이지에서 JS로든 요청 보내면 예약 처리
book_query=request.form
print(book_query)
starttime = datetime.strptime(book_query.get('start_time'), '%Y-%m-%d%H:%M')
endtime = datetime.strptime(book_query.get('end_time'), '%Y-%m-%d%H:%M')
if addReservations(session['ID'],book_query.get('fac_id'),starttime,endtime):
flash("예약에 성공했습니다")
return redirect('/myhome')
else:
flash("예약에 실패했습니다.")
return redirect('/search')
......
......@@ -77,7 +77,7 @@ input{
</style>
{% endblock %}
{% block content %}
<img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/>
<a href="/myhome"> <img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/></a>
<form action="/join/confirm" method="post">
<br><br>
......
......@@ -22,6 +22,7 @@ input[type=text] {
transition: 0.5s;
outline: none;
font-family: 'MyWebFont';
min-width: 200px;
}
input[type=text]:focus {
border: 3px solid #555;
......@@ -37,6 +38,7 @@ input[type=password] {
outline: none;
margin-right: 7px;
font-family: 'MyWebFont';
min-width: 200px;
}
input[type=password]:focus {
border: 3px solid #555;
......
......@@ -64,7 +64,7 @@ img {
</style>
{% block style %}{% endblock %}
<body >
<body>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
......
......@@ -6,7 +6,6 @@
<style>
body {
background-color: rgb(230, 243, 255);
text-align: center;
}
#select1 {
......@@ -146,7 +145,7 @@ select{
border-radius: 5px;
}
#maxpeople{
width: 55%;
width: 60%;
padding: 12px 20px;
box-sizing: border-box;
border: 3px solid #ccc;
......@@ -169,29 +168,38 @@ h3 {
margin-top: 15px;
}
</style>
{% endblock %}
{% block content %}
</style>
<body>
<br>
<img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/>
<a href="/myhome"> <img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/></a>
<div id="wrapper">
<form action="/search/result" method="post">
<br><br>
<div class="item"><H3>부서 ID</H3>
<select name="deptid" required><option value="1">전자정보대학</option>
<option value="2">외국어대학</option>
<option value="3">공과대학</option>
<option value="4">예술디자인대학</option>
<option value="5">체육대학</option>
<option value="6">국제대학</option>
<option value="7">대학본부</option></select>
<div class="item"><H3>건물</H3>
<select name="deptid" required><option value="전자정보대학">전자정보대학</option>
<option value="외국어대학">외국어대학</option>
<option value="공과대학">공과대학</option>
<option value="예술,디자인대학">예술,디자인대학</option>
<option value="체육대학">체육대학</option>
<option value="국제대학">국제대학</option>
<option value="1호관 테니스장">1호관 테니스장</option>
<option value="3호관 운동장">3호관 운동장</option>
<option value="3호관 테니스장">3호관 테니스장</option>
<option value="6호관 야구장">6호관 야구장</option>
<option value="6호관 운동장">6호관 운동장</option>
<option value="골프 연습장">골프 연습장</option>
<option value="6호관 운동장">6호관 운동장</option>
<option value="수영장">수영장</option>
<option value="필드 하키장(공과대학 앞)">필드 하키장(공과대학 앞)</option>
<option value="학생회관">학생회관</option></select>
<br></div>
<center><div class="item"><H3>사용 인원 수</H3><input type="number" id="maxpeople" name="quantity" min="1" max="200"></div></center><br>
<center><div class="item"><H3>사용 인원 수</H3><input type="number" id="maxpeople" name="capacity" min="1" max="200"></div></center><br>
<center>시작 시간<br><br><input type="datetime-local" name="starttime"></center><br>
......
......@@ -36,7 +36,7 @@
</style>
{% endblock %}
{% block content %}
<img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/><br>
<a href="/myhome"> <img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/></a>
<h1>예약 현황</h1>
{% if not resv_list %}
<p>예약 데이터가 없습니다.</p>
......
......@@ -6,7 +6,7 @@
{% block style %}
<style>
#list_item{
width: 275px;
width: 263px;
height: 100px;
font-size:20px;
font-family: '배달의민족 도현';
......@@ -17,17 +17,18 @@
vertical-align: bottom;
line-height: 150%;
display: inline-block;
padding-left: 7px;
}
#delete_btn{
width: 47px;
width: 60px;
height: 110px;
box-sizing: border-box;
font-size: 20px;
font-family: '배달의민족 도현';
background-color: rgb(255, 101, 101);
background-color: rgb(90, 200, 90);
color: white;
border-radius:5px;
border: solid 5px rgb(255, 101, 101);
border: solid 5px rgb(90, 200, 90);
float: right;
display: inline-block;
......@@ -36,18 +37,20 @@
</style>
{% endblock %}
{% block content %}
<img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/><br>
<a href="/myhome"> <img style="border-radius:15px;" width="300px;" src="{{ url_for('static', filename = '캡처6.png') }}"/></a><br>
<h1>검색 결과</h1>
{% if not resv_list %}
{% if resv_list[0][0] == "NoAvailableFacilities" %}
<p>가능한 강의실이 없습니다.</p>
{% endif %}
{% else %}
<table>
{% for resv_item in resv_list %}
<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') }}
<form method="post" action="/deleteresv">
<input type="hidden" name="resv_id" value="{{ 강의실ID }}">
<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') }}
<input type="hidden" name="fac_id" value="{{ resv_item[0] }}">
<input type="hidden" name="start_time" value="{{ starttime.strftime('%Y-%m-%d%H:%M') }}">
<input type="hidden" name="end_time" value="{{ endtime.strftime('%Y-%m-%d%H:%M') }}">
</div><input type="submit" id="delete_btn" value="예약"></form></td></tr>
{% endfor %}
</table>
{% endif %}
{% endblock %}
......