강상위

feature update

1 +env
2 +__pycache__
3 +test.py
...\ No newline at end of file ...\ No newline at end of file
1 +# DB 함수 사용법
2 +## 사전설정
3 +- pymysql 패키지가 있어야 합니다.
4 +> pip install pymysql
5 +- 보안상 user_info에서 DB id, password를 가져옵니다.
6 +- user_info.py에서 DB id, password를 설정하고 사용해주세요.
7 +## 외부에서 사용법:
8 +> from ReservationControl import *
9 +> from Users import *
...\ No newline at end of file ...\ No newline at end of file
1 +#-*- coding: utf-8 -*-
2 +# 한글 인코딩을 위한 주석입니다.
3 +
4 +# 사전설정:
5 + # pymysql 패키지가 있어야 합니다.
6 + # pip install pymysql
7 + # 보안상 user_info에서 DB id, password를 가져옵니다.
8 + # user_info.py에서 DB id, password를 설정하고 사용해주세요.
9 +# 외부에서 사용법:
10 + # from ReservationControl import *
11 +
12 +import pymysql
13 +import user_info
14 +import datetime
15 +
16 +
17 +
18 +
19 +
20 +
21 +
22 +
23 +# getReservations - 대여현황반환 함수
24 +# input:
25 + # string user_id
26 +# output:
27 + # 성공시 : tuple형태로 반환 => ( (1 ,"steven123", 7, datetime.datetime(2018,12,5,12,0,0), datetime.datetime(2018,12,5,12,10,0), ), )
28 + # 실패시 : tuple형태로 반환 => ( ("SQL Error!", ), )
29 +# 사용예:
30 + # result = getReservations("khucse123")
31 + # reservation_start_time = result[0][3]
32 +
33 +def getReservations(user_id):
34 + try:
35 + db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd, db='FRS', charset='utf8')
36 + curs = db.cursor()
37 +
38 + curs.execute("select * from reservations where user_id=%s", user_id)
39 + result = curs.fetchall()
40 + print("Fetch Success!")
41 + return result
42 + except:
43 + print("SQL Error!")
44 + return (("SQL Error!",),)
45 +
46 + finally:
47 + db.close()
48 +
49 +
50 +# deleteReservations - 대여현황삭제 함수
51 +# input:
52 + # int reservations_id
53 +# output:
54 + # 성공시 : True
55 + # 실패시 : False
56 +# 사용예:
57 + # deleteReservations(5)
58 +# 주의사항:
59 + # 테스트환경에서 없는 reservations_id를 넣으면 에러가 날 수 있음
60 +
61 +def deleteReservations(reservations_id):
62 + try:
63 + db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd, db='FRS', charset='utf8')
64 + curs = db.cursor()
65 +
66 + curs.execute("delete from reservations where reservations_id=%s", reservations_id)
67 + db.commit()
68 + print("Delete Success!")
69 + return True
70 + except:
71 + print("SQL Error!")
72 + return False
73 +
74 + finally:
75 + db.close()
76 +
77 +
78 +# addReservations - 대여현황추가 함수
79 +# input:
80 + # string user_id
81 + # int facility_id
82 + # datetime.datetime start_time
83 + # datetime.datetime end_time
84 +# output:
85 + # 성공시 : True
86 + # 실패시 : False
87 +# 사용예:
88 + # tstart = datetime.datetime(2018,12,5,0,11,12)
89 + # tend = datetime.datetime(2018,12,5,0,20,12)
90 + # addReservations("khucse123", 6, tstart, tend)
91 +# 주의사항:
92 + # 테스트환경에서 없는 user_id를 넣으면 에러가 날 수 있음
93 + # 테스트환경에서 없는 facility_id를 넣으면 에러가 날 수 있음
94 +
95 +def addReservations(user_id, facility_id, start_time, end_time):
96 + try:
97 + 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 + curs = db.cursor()
99 +
100 + 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))
101 + db.commit()
102 + print("Add Reservation Success!")
103 + return True
104 + except:
105 + print("SQL Error!")
106 + return False
107 +
108 + finally:
109 + db.close()
110 +
111 +
112 +
1 +#-*- coding: utf-8 -*-
2 +# 한글 인코딩을 위한 주석입니다.
3 +
4 +# 사전설정:
5 + # pymysql 패키지가 있어야 합니다.
6 + # pip install pymysql
7 + # 보안상 user_info에서 DB id, password를 가져옵니다.
8 + # user_info.py에서 DB id, password를 설정하고 사용해주세요.
9 +# 외부에서 사용법:
10 + # from Users import *
11 +
12 +import pymysql
13 +import user_info
14 +
15 +
16 +
17 +
18 +
19 +
20 +
21 +
22 +
23 +
24 +# UserLogin - 유저 로그인 함수
25 +# input:
26 + # string user_id
27 + # string password
28 +# output:
29 + # 성공시 : True
30 + # 실패시 : False
31 +# 사용예:
32 + # UserLogin("khucse124", "steven1234")
33 +
34 +def UserLogin(user_id, password):
35 + try:
36 + db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd, db='FRS', charset='utf8')
37 + curs = db.cursor()
38 +
39 + curs.execute("select exists (select user_name from users where user_id=%s and password=%s) as result", (user_id, password))
40 + result = curs.fetchall()
41 +
42 + if(result[0][0]==1):
43 + print("User login Success!")
44 + return True
45 + else:
46 + print("User login Failed!")
47 + return False
48 +
49 + except:
50 + print("SQL ERROR!!")
51 + return False
52 +
53 + finally:
54 + db.close()
55 +
56 +
57 +
58 +# UserJoin - 유저 회원가입 함수
59 +# input:
60 + # string user_id
61 + # int dept_id
62 + # string user_name
63 + # string pwd
64 + # string phone
65 + # string mail
66 +# output:
67 + # 성공시 : True
68 + # 실패시 : False
69 +# 사용예:
70 + # UserJoin("khucse124", 7, "Steven", "steven1234", "031-201-2566", "cs@khu.ac.kr")
71 +# 주의사항:
72 + # 테스트환경에서 같은 user_id가 있으면 에러가 날 수 있음
73 + # 테스트환경에서 dept_id는 departments 테이블에 없는 값을 넣으면 에러가 날 수 있음
74 +
75 +def UserJoin(user_id, dept_id, user_name, pwd, phone, mail):
76 + try:
77 + db = pymysql.connect(host='1.201.139.92', port=3306, user=user_info.user_id, password=user_info.user_passwd, db='FRS', charset='utf8')
78 + curs = db.cursor()
79 +
80 + curs.execute("insert into users (user_id, department_id, user_name, password, phone, mail_address) values (%s,%s,%s,%s,%s,%s)",(user_id, dept_id, user_name, pwd, phone, mail))
81 + db.commit()
82 + print("User Join Success!")
83 + return True
84 +
85 + except:
86 + print("SQL ERROR!!")
87 + return False
88 +
89 + finally:
90 + db.close()
91 +
1 +user_id = ' '
2 +user_passwd = ' '
...\ No newline at end of file ...\ No newline at end of file