python+mysql实现教务管理系统
作者:ShellMeShell丶 发布时间:2024-01-26 11:43:03
标签:python,管理系统
本文实例为大家分享了python实现教务管理系统,供大家参考,具体内容如下
mysql+python构成教务管理系统,提供系统管理员,教职工,学生 * 。有注册,添加,修改,发布信息等功能。
Login.py
#-*- coding:utf-8 -*-
#####系统登录
import os
import MySQLdb
import time
class Login:
def __init__(self,conn):
self.account = ''
self.password = ''
self.level = 2
self.conn = conn
def LoginSurface(self,info):
os.system('cls')
width = 50
title = 'LOGIN'
body1 = '[A]Admin'
body2 = '[T]Teacher'
body3 = '[S]Student'
body4 = '[Q]Quit'
print '=' * width
print ' ' * ((width-len(title))/2), title
print ' ' * ((width-len(body1))/2),body1
print ' ' * ((width-len(body1))/2),body2
print ' ' * ((width-len(body1))/2),body3
print ' ' * ((width-len(body1))/2),body4
print ' ' * ((width-len(info))/2), info
print '-' * width
def MainFunc(self):
err = ''
while True:
self.LoginSurface(err)
level = raw_input('Access:')
level = level.upper()
if level == 'A':self.level = 0
elif level == 'T': self.level = 1
elif level == 'S': self.level = 2
elif level =='Q': return False
else :
err = 'Error Action!'
continue
self.account = raw_input('Account:')
self.password = raw_input('Password:')
if self.CheckAccount():
err = 'Login Success!'
self.LoginSurface(err)
print 'Please wait...'
time.sleep(3)
return True;
else :
err = 'Login Failed!'
def GetLoginAccount(self):
return [self.account,self.password,self.level]
def CheckAccount(self):
cur = self.conn.cursor()
sqlcmd = "select Account,Password,AccountLevel from LoginAccount where Account = '%s'" % self.account
if cur.execute(sqlcmd) == 0: return False
temp = cur.fetchone()
cur.close()
if temp[1] == self.password and temp[2] == self.level:
return True
else: return False
def Quit(self):
pass
if __name__ == '__main__':
conn = MySQLdb.connect(user='root',passwd = '123456',db = 'test');
a = Login(conn)
a.MainFunc()
a.Quit()
conn.close()
main.py
#-*- coding:utf-8 -*-
####系统入口
import os
import MySQLdb
import Student
import Teacher
import Login
import SystemManager
if __name__ == '__main__':
conn = MySQLdb.connect(user='root',passwd = '123456',db = 'test')
log = Login.Login(conn)
if log.MainFunc():
account = log.GetLoginAccount()
if account[2] == 0:
usr = SystemManager.SystemManager(conn,account[0],account[1])
usr.MainFunc()
elif account[2] == 1:
usr = Teacher.Teacher(conn,account[0],account[1])
usr.MainFunc()
elif account[2] == 2:
usr = Student.Student(conn,account[0],account[1])
usr.MainFunc()
else :
conn.close()
raise exception()
conn.close()
Student.py
#-*- coding:utf-8 -*-
####学生账号
import MySQLdb
import os
class Student:
def __init__(self,conn,account,passwd):
###构造,conn连接数据库
cur = conn.cursor()
sqlcmd = "select Name,Gender,Birth,Academy,Major,Grade,TeacherNo from StudentInfo where StudentNo = '%s'" % account
cur.execute(sqlcmd)
res = cur.fetchone()
sqlcmd = "select Name from TeacherInfo where TeacherNo = '%s'" % res[6]
cur.execute(sqlcmd)
TeacherName = cur.fetchone()
cur.close()
self.width = 150
self.conn = conn
self.account = account
self.Password= passwd
self.Name = res[0]
self.Gender = res[1]
self.Birth = res[2]
self.Accademy= res[3]
self.Major = res[4]
self.Grade = res[5]
self.Teacher = TeacherName[0]
def MainFunc(self):
###主要执行函数
info = ''
while True:
self.MainSurface(info)
choice = raw_input('What to do?')
choice = choice.upper()
if choice != 'P' and choice != 'M' and choice != 'Q':
info = 'Error Action!'
continue
if choice == 'P':
info = self.PersonalInfo()
elif choice == 'M':
info = self.OperatMessage()
else : break
def PersonalInfo(self):
###个人信息
info = ''
while True:
self.PersonalInfoSurface(info)
choice = raw_input('What to do?')
choice = choice.upper()
if choice != 'C' and choice != 'Q':
info = 'Error Action!'
continue
if choice == 'C':
info = self.ChangePersonalInfo()
else : break
return info
def ChangePersonalInfo(self):
###修改个人信息
NewGender = self.Gender
NewBirth = self.Birth
NewPw = self.Password
while True:
choice = raw_input('Change Gender?(y/n)')
choice = choice.lower()
if choice == 'y':
NewGender = raw_input('New Gender:')
break
elif choice == 'n': break
else : pass
while True:
choice = raw_input('change Born Date?(y/n)')
choice = choice.lower()
if choice == 'y':
NewBirth = raw_input('New Born Date:')
break
elif choice == 'n': break
else : pass
while True:
choice = raw_input('change Password?(y/n)')
choice = choice.lower()
if choice == 'y':
NewPw = raw_input('New Password:')
break
elif choice == 'n': break
else : pass
info = 'Change Success!'
cur = self.conn.cursor()
if NewGender != self.Gender or NewBirth != self.Birth:
sqlcmd = "update StudentInfo set Gender = '%s',Birth = '%s' where StudentNo = '%s'" % (NewGender,NewBirth,self.account)
if cur.execute(sqlcmd) == 0:
self.conn.rollback()
cur.close()
return 'Change Fail!'
if NewPw != self.Password:
sqlcmd = "update LoginAccount set Password = '%s' where Account='%s'" % (NewPw,self.account)
if cur.execute(sqlcmd) == 0:
self.conn.rollback()
cur.close()
return 'Change Fail!'
else :
self.conn.commit()
self.Gender = NewGender
self.Birth = NewBirth
self.Password = NewPw
cur.close()
return 'Change Success!'
def OperatMessage(self):
info = ''
while True:
self.MessageSurface(info)
self.MessageList()
choice = raw_input('What to do?')
choice = choice.upper()
if choice == 'M':
msg = input('Message Id:')
info = self.MessageInfo(msg)
elif choice == 'Q': break;
else : info = 'Error Action!'
return info
def MessageList(self):
###查看消息列表
cur = self.conn.cursor()
print ''
sqlcmd = "select Id,SenderName,SendTime,Title from AllMessage where statu = 'pass' and MsgLevel = 1"
if cur.execute(sqlcmd) == 0: return
print '-' * self.width
while True:
temp = cur.fetchone()
if not temp: break;
print '%3d%-20s%-50s%s' % (temp[0],temp[1],temp[3],temp[2])
print '-' * self.width
cur.close()
def MessageInfo(self,MsgNo):
###查看详细消息, No消息编号
cur = self.conn.cursor()
sqlcmd = "select SenderName,SendTime,Title,Content from AllMessage where Id = %d" % MsgNo
if cur.execute(sqlcmd) == 0:
cur.close()
return 'Read Fail!'
article = cur.fetchone()
cur.close()
os.system('cls')
print '=' * self.width
print ' ' * ((self.width - len(article[2]))/2) , article[2]
head = article[0] + ' ' + str(article[1])
print ' ' * ((self.width - len(head))/2) , head
print '-' * self.width
print article[3]
print '=' * self.width
raw_input('Press any key to return!')
return ''
def Quit(self):
###退出
pass
def MainSurface(self,info):
###主界面
os.system('cls')
print '=' * self.width
title = 'Welcome %s!' % self.Name
body1 = '[P]Personal Information'
body2 = '[M]Message'
body3 = '[Q]Quit'
print ' ' * ((self.width - len(title))/2),title
print ' ' * ((self.width - len(body1))/2),body1
print ' ' * ((self.width - len(body1))/2),body2
print ' ' * ((self.width - len(body1))/2),body3
print ' ' * ((self.width - len(info))/2),info
print '=' * self.width
def MessageSurface(self,info):
###消息界面
os.system('cls')
print '=' * self.width
title = 'MESSAGES'
body1 = '[M]Message Detail'
body2 = '[Q]Quit'
print ' ' * ((self.width - len(title))/2),title
print ' ' * ((self.width - len(body1))/2),body1
print ' ' * ((self.width - len(body1))/2),body2
print ' ' * ((self.width - len(info))/2),info
print '=' * self.width
def PersonalInfoSurface(self,info):
###个人信息界面
os.system('cls')
print '=' * self.width
title = 'PERSONAL INFORMATION'
body1 = '[C]Change Information'
body2 = '[Q]Quit'
print ' ' * ((self.width - len(title))/2),title
print ' ' * ((self.width - len(body1))/2),body1
print ' ' * ((self.width - len(body1))/2),body2
print ' ' * ((self.width - len(info))/2),info
print '-' * self.width
body3 = ' Name: %s' % self.Name
body4 = 'Student Number: %s' % self.account
body5 = ' Gender: %s' % self.Gender
body6 = ' Birth: %s' % self.Birth
body7 = ' Accademy: %s' % self.Accademy
body8 = ' Major: %s' % self.Major
body9 = ' Grade: %s' % self.Grade
body10= ' Teacher: %s' % self.Teacher
print ' ' * ((self.width - len(body6))/2),body3
print ' ' * ((self.width - len(body6))/2),body4
print ' ' * ((self.width - len(body6))/2),body5
print ' ' * ((self.width - len(body6))/2),body6
print ' ' * ((self.width - len(body6))/2),body7
print ' ' * ((self.width - len(body6))/2),body8
print ' ' * ((self.width - len(body6))/2),body9
print ' ' * ((self.width - len(body6))/2),body10
print '=' * self.width
if __name__ == '__main__':
conn = MySQLdb.connect(user='root',passwd = '123456',db = 'test')
stu = Student(conn,'0000001','123456')
stu.MainFunc()
conn.close()
完整代码请点击下载:python实现教务管理系统


猜你喜欢
- 步骤:1. 掌握几种对象及其关系2. 了解每类对象的基本操作方法3. 通过转化关系转化涉及对象1. datetime>>>
- 最近,W3C的一项公告称,在W3C与XHTML2的合同于今年年底到期后将不会续签。这意味着W3C停止了对XHTML2的开发,转而大力支持HT
- 前序1、cookie介绍Cookie是一段不超过4KB的小型文本数据,保存在客户端浏览器中,由一个名称(Name)、一个值(Value)和其
- 首先,假设我们有如下餐厅数据集:import pandas as pddf = pd.DataFrame({ 'rest
- 所以对应的asp处理代码如下代码如下:dedearr=split(xiangguanid2,chr(13)) '分割成数组
- QSlider 是一个具有可来回拉动手柄的控件。有时使用滑块比输入数字或使用旋转框更方便。在我们的例子中,我们将创建一个滑块和一个标签。标签
- 使用drop()方法删除pandas.DataFrame的行和列。在0.21.0版之前,请使用参数labels和axis指定行和列。从0.2
- Pytorch多GPU运行设置可用GPU环境变量。例如,使用0号和1号GPU'os.environ["CUDA_VISIB
- 先导上一期讲了在ABAP中,ALV的普通写法,流程以及相关属性,还讲了基本DEMO ,但是在真正开发中,不会写这么多的代码.原则上是一切从简
- <?php/*定义和用法strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。该函数返回字符串的其余部分(从匹配点)。如果
- 使用函数 ugettext() 来指定一个翻译字符串。 作为惯例,使用短别名 _ 来引入这个函数以节省键入时间.在下面这个例子中,文本 &q
- 插入代码块使用sum函数:numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]print(sum(number
- 前言上篇介绍了go-grpc-middleware的grpc_zap、grpc_auth和grpc_recovery使用,本篇将介绍grpc
- 接下来我利用一点空余时间发一个函数里面包含和添加和删除功能。实验的架构可以使用IIS.5WEB服务器ACCESS数据库。这个我其实不用说的很
- 任何一位数据库程序员都会有这样的体会:高通信量的数据库驱动程序中,一条糟糕的SQL查询语句可对整个应用程序的运行产生严重的影响,其不仅消耗掉
- python中的dir()函数是一个非常重要的函数,它可以帮助我们查看函数的功能和特性。中文说明:不带参数时,返回当前范围内的变量、方法和定
- 可能由于操作系统不同,或者在安装SQL 2008的时候已经安装SQL其他版本,因此可能会遇到问题,那么这时我们的实际经验和动手测试的能力也是
- 安装docker桌面程序从docker官网下载并安装桌面程序。安装好后启动桌面程序。若出现以下错误,说明你的docker 没有启动。1. d
- 本文实例讲述了python自动化测试之从命令行运行测试用例with verbosity,分享给大家供大家参考。具体如下:实例文件recipe
- 问题描述 windows错误安装方法:pip3 install numpy这种情况下虽然安装成功,但是在import numpy时会出现如下