import pickle
import os
class kech:
'''
课程的的名字时间周期代课老师
'''
def __init__(self,courses,price,cycle,teacher):
self.Courses = courses
self.Price = price
self.Cycle = cycle
self.Teacher = teacher
class Xs:
'''
学生的名字
年龄,性别
'''
def __init__(self,name,grade):
self.Name = name
self.grade = grade
self.courses = []
def selected(self):
with open("课程信息","rb")as f:
while True:
try:
zhmm = pickle.load(f)
yield zhmm
except EOFError:
return False
def xuzekc(self,xsxx):
while True:
for i in self.selected():print(i.__dict__)
a = input("请输入课程名字 : ").strip()
for i in self.selected():
if i.Courses == a:
if a in xsxx.courses:
print("课程存在!!")
else:
print("添加%s课程成功" % a)
return xsxx.courses.append(a)
elif a.upper() == "Q":
return
def chakask(self):
with open("Student","rb")as f:
while True:
try:
zhmm = pickle.load(f)
yield zhmm
except EOFError:
return False
class Gly:
'''
1、创建课程
2、创建学生学生账号
3、查看所有课程
4、查看所有学生
5、查看所有学生的选课情况
6、退出程序
'''
def __init__(self,name):
self.name = name
def found(self):#1、创建课程
courses = input("请输入创建的课程 : ").strip()
price = input("输入课程价格 : ").strip()
cycle = input("请输入课程周期 : ").strip()
teacher = input("请输入授课老师 : ").strip()
a = kech(courses, price, cycle, teacher)
with open("课程信息","ab")as f:
pickle.dump(a,f)
print("%s课程创建成功"%(a.__dict__))
def Create_account(self):
Account1 = input("学生账号 : ").strip()
Code = input("学生密码 : ").strip()
name = input("学生姓名 : ").strip()
grade = input("学生班级 : ").strip()
with open("账号密码","ab")as f:
s = {"ID":"学生","账号":Account1,"密码":Code,"姓名":name,"班级":grade}
print(s,"\033[0;33m注册成功\033[0m")
pickle.dump(s,f)
with open("Student","ab")as f :
a = Xs(name,grade)
pickle.dump(a,f)
def cksuoykc(self):
with open("课程信息","rb")as f:
while True:
try:
zhmm = pickle.load(f)
yield zhmm
except EOFError:
return False
def ckansuoyouxues(self):
for i in dqwenjian():
if i["ID"] == "学生":
print(i["姓名"],i["班级"])
def cksuoyouxsxk(self):
with open("Student","rb")as f:
while True:
try:
zhmm = pickle.load(f)
yield zhmm
except EOFError:
return False
def glyzc():#注册管理员
Account = input("\033[0;31mInput virus : \033[0m").strip()
Password= input("\033[0;31mSelect the virus : \033[0m").strip()
name = input("\033[0;31mName entry : \033[0m").strip()
with open("账号密码","ab")as f:
s = {"ID": "管理员", "账号": Account, "密码": Password,"姓名":name}
pickle.dump(s,f)
def dqwenjian():#打开文件进行读取
with open("账号密码","rb")as f:
while True:
try:
zhmm = pickle.load(f)
yield zhmm
except EOFError:
return False
def pad(zh,m_m):#判断输入账号密码是否存在
for i in dqwenjian():
if i["账号"] == zh and i["密码"] == m_m:
if i["ID"] == "管理员":
print("\033[0;32mWelcome administrator login\033[0m")
if i["ID"] == "管理员":
guanly(i)
exit("ROBOCOP PRIME DIRECTIVES")
else:
print("\033[0;31mWelcome to\033[0m")
if i["ID"] == "学生":
xueshen(i)
exit("ROBOCOP PRIME DIRECTIVES")
else:
print("\033[0;31m Wrong account or password\033[0m")
def guanly(xx): #管理员操作界面
while True:
print("\033[0;35m1、创建课程\n"
"2、创建学生学生账号\n"
"3、查看所有课程\n"
"4、查看所有学生\n"
"5、查看所有学生的选课情况\n"
"6、退出程序\033[0m")
name = Gly(xx["姓名"])
# print("欢迎\033[0;31m%s\033[0m登录管理员界面!!!"%name.name)
num = input("选择你要执行的序号>>>").strip()
if num == "1":
name.found()
if num == "2":
name.Create_account()
if num == "3":
for i in name.cksuoykc():print("\033[0;36m",i.__dict__,"\033[0m")
if num == "4":
name.ckansuoyouxues()
if num == "5":
for i in name.cksuoyouxsxk():print(i.Name,i.grade,i.courses)
if num == "6":
return
def xus(xx):
with open("Student","rb")as f:
while True:
try:
xsxx = pickle.load(f)
yield xsxx
except EOFError:
return False
def dyxus(xx):
for i in xus(xx):
if i.Name == xx["姓名"]:
return i
def xueshen(xx):#学生操作界面
# print("欢迎%s同学登录学生界面!!!" % xx["姓名"])
while True:
print("\033[0;35m1、查看所有课程\n"
"2、选择课程\n"
"3、查看所选课程\n"
"4、退出程序\033[0m")
a =input("输入要执行的序号 : ")
xsxx = dyxus(xx)
if a == "1":
for j,i in enumerate(xsxx.selected(),1):print(j,i.__dict__)
if a == "2":
xsxx.xuzekc(xsxx)
with open("Student1","wb")as f:
for i in xus(xx):
if i.Name == xsxx.Name:
pickle.dump(xsxx,f)
else:
pickle.dump(i,f)
os.remove("Student")
os.rename("Student1","Student")
if a == "3":
for i in xsxx.chakask():
if i.Name == xsxx.Name:
print(i.Name,i.courses)
if a == "4": return
while True:
zh = input("\033[1;32;40m账号>>>\033[0m").strip()
m_m = input("\033[1;32;40m密码>>>\033[0m").strip()
if zh =="Looking for virus" and m_m == "#@!@!#":
glyzc()
pad(zh,m_m)