本文实例为大家分享了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"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"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实现教务管理系统

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。  

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。