1.需求
管理员:
添加教师:一个教师作为一个班级的班主任,同时也作为一个或多个课程的代课老师
添加课程:指定课程名,学分,任课老师。
添加班级:指定班级名称,班主任
老师:
添加学生:作为一个班级的班主任,该老师为其班级添加学生
添加课程:作为一个班级的班主任,该老师为其班级添加课程
给出成绩:作为一门课程的任课老师,该老师给出他所带课程的学生成绩
查看学生成绩:作为一门课程的任课老师,查看学生成绩
学生:
查看自己成绩单
查看已修学分情况
2.代码
工具:Utils.py
#date:2019/9/20
import pymysql
import hashlib
class SqlUtils:
@staticmethod
def getConn():
# 获取连接
conn = pymysql.connect(host='localhost',user='root',password='root',database='sc')
return conn
@staticmethod
def close(cursor,conn):
cursor.close()
conn.close()
class MD5Utils:
@staticmethod
def getMD5(string):
md5 = hashlib.md5(bytes('salt',encoding='utf-8'))
md5.update(bytes(string))
return md5.hexdigest()
页面:View.py
#date:2019/9/20
import Service
def Mainframe():
while True:
print('*****************')
print('1.管理员登录')
print('2.教师登录')
print('3.学生登录')
print("*****************")
op = input('请选择: ')
if op=='1':
username = input('请输入账号:')
password = input('请输入密码: ')
if Service.Login.login(username,password,1)==0:
print('用户名或密码错误!')
continue
adminFrame()
elif op=='2':
username = input('请输入账号:')
password = input('请输入密码: ')
if Service.Login.login(username,password,2)==0:
print('用户名或密码错误!')
continue
teacherFrame(username)
elif op=='3':
username = input('请输入账号:')
password = input('请输入密码: ')
if Service.Login.login(username, password, 3) == 0:
print('用户名或密码错误!')
continue
stuFrame(username)
else:
print("无效重新输入")
def teacherFrame(teacherName):
while True:
print('********老师*******')
print('1.添加学生')
print('2.录入成绩')
print('3.查看学生成绩')
print('4.给学生选课')
print('0.退出')
op = input('请选择: ')
if op == '1':
Service.Teacher.addStudent(teacherName)
elif op == '2':
Service.Teacher.addScore(teacherName)
elif op == '3':
Service.Teacher.findScore(teacherName)
elif op == '4':
Service.Teacher.selectCourse(teacherName)
elif op =='0':
break
else:
print("无效重新输入")
def adminFrame():
while True:
print('********管理员*******')
print('1.添加老师')
print('2.添加班级')
print('3.添加课程')
print('0.退出')
op = input('请选择: ')
if op == '1':
Service.Admin.addTeatcher()
elif op == '2':
Service.Admin.addClass()
elif op == '3':
Service.Admin.addCourse()
elif op =='0':
break
else:
print("无效重新输入")
def stuFrame(studentName):
while True:
print('********学生端*******')
print('1.查看个人成绩')
print('2.个人学分情况')
print('0.退出')
op = input('请选择: ')
if op == '1':
Service.Student.selScore(studentName)
elif op == '2':
Service.Student.count(studentName)
elif op == '0':
break
else:
print("无效重新输入")
if '__main__'==__name__:
Mainframe()
业务:Service.py
#date:2019/9/20
import pymysql
import Utils
class Login:
@staticmethod
def login(username ,passwrod,role):
conn = Utils.SqlUtils.getConn()
cursor = conn.cursor()
sql = 'select * from user where name=%s and password=%s and role=%s'
res = cursor.execute(sql,(username,passwrod,role))
return res
#### 管理员添加老师
class Admin:
@staticmethod
def addTeatcher():
list=[]
conn = Utils.SqlUtils.getConn()
cursor = conn.cursor()
while True:
teacherName = input("请输入老师名字:")
teacherSex = input


204

被折叠的 条评论
为什么被折叠?



