-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_option.py
383 lines (321 loc) · 12.3 KB
/
main_option.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
import method, resources, datetime, os
import Student_model as s
from statistics import mean
def main_option(file_name, kind, option, account_check):
def option_case(func):
while True:
os.system("clear")
with open(f"{file_name}") as danhsach:
ds = danhsach.readlines()
danhsach.seek(0)
print(danhsach.read())
num_pick = input(f"Nhập vào {kind} muốn chọn: ")
method.cross()
# Quay lại
if num_pick == "back":
break
# Thông tin chi tiết
if num_pick in method.str_range(ds):
# FUNCTION CHI TIẾT
func(int(num_pick), account_check)
else:
method.option_error()
if option == 1: option_case(course_option)
elif option == 2: option_case(student_option)
else: option_case(lecturer_option)
def course_option(num, a_check):
while True:
os.system("clear")
course = resources.courses[num - 1]
resources.update_course()
# Kiểm tra số lượng học viên qua môn
course.rate = resources.update_student_pass(0, course.course_name)
# Show thông tin
course.course_info()
method.read("Course/Course_info.text")
num_pick = input(f"Nhập vào số thông tin muốn chỉnh sửa hoặc xem danh sách học viên qua môn: ")
method.cross()
# Không thể chỉnh sửa số học viên
if num_pick == "1":
if "HIEUTRUONG" in a_check:
print("Bạn chỉ có thể chỉnh sửa số lượng học viên tối đa của khoá !")
max_num = input("Nhập vào số học viên tối đa bạn muốn chỉnh sửa: ")
method.cross()
if method.input_condition(max_num, True, False):
if int(max_num) < course.quantity:
method.fail("Bạn không thể chỉnh sửa số lượng tối đa thấp hơn số lượng học viên hiện có")
else:
course.max_quantity = int(max_num)
method.success("Chỉnh sửa thành công")
else:
method.not_allow()
# Chỉnh sửa mô tả
elif num_pick == "2":
if "HIEUTRUONG" in a_check:
replace_text = input("Bạn muốn chỉnh sửa thành: ")
method.input_condition(replace_text)
course.description = replace_text
method.success("Chỉnh sửa thành công")
else:
method.not_allow()
# Không thể chỉnh sửa Giảng viên
elif num_pick == "3":
if "HIEUTRUONG" in a_check:
method.fail("Bạn không thể chỉnh sửa mục giảng viên tại đây, vui lòng sang option 3 !")
else:
method.not_allow()
# Show danh sách học viên qua môn
elif num_pick == "4":
os.system("clear")
method.read("Course/Course_pass_list.text")
input("Nhấn Enter để quay lại ")
# Quay lại
elif num_pick == "back":
break
else:
method.option_error()
def student_option(num, a_check):
while True:
os.system("clear")
student = resources.students[num - 1]
student.student_info()
resources.update_student()
resources.update_student_result(num - 1)
method.read("Student/Student_info.text")
info_pick = input("Nhập vào số của thông tin muốn chỉnh sửa hoặc xem điểm: ")
method.cross()
# Chỉnh sửa tên học viên
if info_pick == "1":
if not "GIAOVIEN" in a_check:
replace_text = input("Bạn muốn chỉnh sửa thành: ")
if method.input_condition(replace_text, False):
student.full_name = replace_text
method.success("Chỉnh sửa thành công")
else:
method.not_allow()
# Chỉnh sửa tuổi học viên
elif info_pick == "2":
if not "GIAOVIEN" in a_check:
replace_text = input("Bạn muốn chỉnh sửa thành: ")
if method.input_condition(replace_text, True, False):
student.age = int(replace_text)
method.success("Chỉnh sửa thành công")
else:
method.not_allow()
# Chỉnh sửa sở thích học viên
elif info_pick == "3":
if not "GIAOVIEN" in a_check:
replace_text = input("Bạn muốn chỉnh sửa thành: ")
if method.input_condition(replace_text, False, True):
habits = replace_text.split(", ")
student.habits = habits
method.success("Chỉnh sửa thành công")
else:
method.not_allow()
# Chỉnh sửa khoá học học viên tham gia
elif info_pick == "4":
if not "GIAOVIEN" in a_check:
while True:
os.system("clear")
student.student_cls_change()
method.read("Student/Student_cls_change.text")
print("Lưu ý: Nếu bạn thoát khoá học, điểm của khoá học đó sẽ mất.")
num_pick = input("Nhập vào khoá học muốn thoát / lựa chọn tham gia: ")
method.cross()
# Lựa chọn tham gia khoá học
if num_pick == str(len(student.courses) + 1):
# Nếu có 3 khoá học
if len(student.courses) == 3:
method.fail("Học viên không thể tham gia quá 3 khoá học")
# Ít hơn 3 khoá
else:
method.read("Course/Course_list.text")
pick = input("Nhập vào khoá học bạn muốn tham gia: ")
method.cross()
if pick in method.str_range_inclue(resources.courses):
course_pick = resources.courses[int(pick) - 1]
# Trường hợp KH full
if course_pick.quantity == course_pick.max_quantity:
method.fail("Khoá học đã full, không thể tham gia")
# Trường hợp KH có thể tham gia
elif course_pick.quantity < course_pick.max_quantity:
# Trường hợp trùng KH
if course_pick.course_name in [c.course_name for c in student.courses]:
method.fail("Khoá học này học viên đã tham gia, không thể tham gia trùng 1 lớp")
# Trường hợp không trùng
else:
# Update học viên tham gia khoá học
student.courses.insert(int(pick) - 1 ,s.Stu_Course(course_pick.course_name))
resources.update_student()
# Update khoá học
course_pick.quantity += 1
resources.update_course()
method.success("Đã tham gia thành công")
elif pick == "back":
pass
else:
method.option_error()
# Lựa chọn huỷ lớp
elif num_pick in method.str_range_inclue(student.courses):
course_pick = student.courses[int(num_pick) - 1]
# Update khoá học
for c in resources.courses:
if c.course_name == course_pick.course_name:
c.quantity -= 1
resources.update_course()
# Update học viên huỷ khoá học
student.courses.pop(int(num_pick) - 1)
resources.update_student()
method.success("Đã huỷ thành công")
# Quay lại
elif num_pick == "back":
break
else:
method.option_error()
else:
method.not_allow()
# Xem / Chỉnh sửa điểm
elif info_pick == "5":
if "GIAOVIEN" in a_check:
while True:
os.system("clear")
resources.update_student_result(num - 1)
method.read("Student/Student_info_results.text")
pick = input("Nhập vào khoá học bạn muốn chỉnh sửa điểm: ")
method.cross()
# Chỉnh sửa điểm
if pick in method.str_range_inclue(student.courses):
print("Vui lòng nhập điểm theo thứ tự Toán Văn Anh! (Yêu cầu: 10 > điểm > 0)")
math = input("Toán: ")
liter = input("Văn: ")
eng = input("Anh: ")
text = math + liter + eng
# Check điểm chỉnh sửa
if method.mark_condition(text, math, liter, eng):
stu_point = student.courses[int(pick) - 1]
stu_point.math = math
stu_point.literature = liter
stu_point.eng = eng
stu_point.avg = round(mean([float(math),float(liter),float(eng)]), 1)
stu_point.grade = s.grade(stu_point.avg)
method.success("Đã chỉnh sửa thành công")
else:
method.fail("Vui lòng điền lại số theo yêu cầu và không có chữ!")
# Quay lại
elif pick == "back":
break
else:
method.option_error()
#Chỉ xem điểm
else:
os.system("clear")
method.read("Student/Student_info_results.text")
input("Bạn không có quyền hạn để chỉnh sửa điểm. Nhấn 'Enter' de quay lai")
# Quay lại
elif info_pick == "back":
break
else:
method.option_error()
def lecturer_option(num, a_check):
while True:
os.system("clear")
lecturer = resources.lecturers[num - 1]
lecturer.lecturer_info()
lecturer.lecturer_course_info()
resources.update_lecturer()
method.read("Lecturer/Lecturer_info.text")
if "HIEUTRUONG" in a_check:
num_pick = input("Nhập vào thông tin giảng viên muốn chỉnh sửa: ")
method.cross()
# Chỉnh sửa tên giảng viên
if num_pick == "1":
replace_text = input("Bạn muốn chỉnh sửa thành: ")
if method.input_condition(replace_text, False):
for c in resources.courses:
if c.lecturer == lecturer.full_name:
c.lecturer = replace_text
lecturer.full_name = replace_text
resources.update_course()
method.success("Chỉnh sửa thành công")
# Chỉnh sửa khoá học đang giảng dạy
elif num_pick == "2":
while True:
os.system("clear")
# List ra các khoá học
lecturer.lecturer_course_info()
method.read("Lecturer/Lecturer_course_info.text")
pick = input("Nhập vào khoá học muốn huỷ dạy / lựa chọn tham gia: ")
method.cross()
# Lựa chọn tham gia khoá học còn trống
if pick == str(len(lecturer.courses) + 1):
# Xét điều kiện đăng ký với thời hạn hợp đồng
valid_date = datetime.datetime.strptime(lecturer.valid, '%d/%m/%Y')
today = datetime.datetime.today()
if valid_date > today or valid_date == today:
method.read("Course/Course_list.text")
pick_course = input("Nhập vào khoá học bạn muốn tham gia giảng dạy: ")
# Nếu đủ điều kiện
if pick_course in method.str_range_inclue(resources.courses):
course_pick = resources.courses[int(pick_course) - 1]
method.cross()
# Nếu lớp còn trống
if course_pick.lecturer == "":
course_pick.lecturer = lecturer.full_name
lecturer.courses.insert(int(pick_course) - 1, course_pick.course_name)
method.success("Đã tham gia thành công")
# Nếu lớp đã có giảng viên
else:
method.fail("Bạn không thể giảng dạy khoá học đã có giảng viên, vui lòng xem khoá học tại option 1")
# Quay lại
elif num_pick == "back":
break
else:
method.option_error()
else:
method.fail("Bạn không thể giảng dạy khoá học vì đã hết thời hạn hợp đồng")
# Lựa chọn huỷ dạy khoá học
elif pick in method.str_range_inclue(lecturer.courses):
course_pick = lecturer.courses[int(pick) - 1]
# Update khoá học
for c in resources.courses:
if c.course_name == course_pick:
c.lecturer = ""
resources.update_course()
# Update giảng viên dạy khoá học
lecturer.courses.pop(int(pick) - 1)
lecturer.lecturer_course_info()
resources.update_lecturer()
method.success("Đã huỷ thành công")
# Quay lại
elif pick == "back":
break
else:
method.option_error()
# Chỉnh sửa thời hạn hợp đồng
elif num_pick == "3":
os.system("clear")
print("Vui lòng nhập ngày tháng năm theo thứ tự !")
day = input("Ngày (2 chữ số): ")
month = input("Tháng (2 chữ số): ")
year = input("Năm (4 chữ số và 2020 < năm < 2100): ")
method.cross()
d = int(day)
m = int(month)
l = method.listToStr([day,month,year], "")
# Check ngày tháng năm
if method.date_condition1(day, month, year) and method.date_condition2(d, m) and method.input_condition(l , True, False):
# Cập nhật thời hạn hợp đồng
l = method.listToStr([day,month,year], "/")
lecturer.valid = l
resources.update_lecturer()
method.success("Chỉnh sửa thành công")
else:
method.fail("Vui lòng nhập lại ngày tháng năm đúng theo lịch và chỉ có số")
# Quay lại
elif num_pick == "back":
break
else:
method.option_error()
else:
input("Bạn không có quyền hạn để chỉnh sửa thông tin giảng viên. Nhấn 'Enter' de quay lai")
break