python实现教务管理系统


Posted in Python onMarch 12, 2018

这是一个使用Python实现基于dos下面向数据库的教务管理系统,实现了管理员、教职工、学生三种不同身份的操作,可以实现的功能有:学生、教职工信息管理、不同权限的信息发布、管理各种信息等。代码约1200行,对于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 = '',db = 'DB_EducationalManagementSystem');
 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 = '',db = 'db_educationalmanagementsystem')
 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 = '',db = 'db_educationalmanagementsystem')
 stu = Student(conn,'0000001','123456')
 stu.MainFunc()
 conn.close()

源码下载:python实现教务管理系统

更多学习资料请关注专题《管理系统开发》。

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

Python 相关文章推荐
使用Python标准库中的wave模块绘制乐谱的简单教程
Mar 30 Python
Python中特殊函数集锦
Jul 27 Python
Python找出9个连续的空闲端口
Feb 01 Python
pandas DataFrame 删除重复的行的实现方法
Jan 29 Python
Python+OpenCV采集本地摄像头的视频
Apr 25 Python
Python递归函数 二分查找算法实现解析
Aug 12 Python
为什么说Python可以实现所有的算法
Oct 04 Python
Python坐标线性插值应用实现
Nov 13 Python
Django重设Admin密码过程解析
Feb 10 Python
Python读取配置文件(config.ini)以及写入配置文件
Apr 08 Python
python实现图像外边界跟踪操作
Jul 13 Python
python实现大文本文件分割成多个小文件
Apr 20 Python
python编写弹球游戏的实现代码
Mar 12 #Python
python学生管理系统代码实现
Apr 05 #Python
python图书管理系统
Apr 05 #Python
怎么使用pipenv管理你的python项目
Mar 12 #Python
python实现图书管理系统
Mar 12 #Python
python实现快速排序的示例(二分法思想)
Mar 12 #Python
Python中的pack和unpack的使用
Mar 12 #Python
You might like
php 禁止页面缓存输出
2009/01/07 PHP
PHP的变量总结 新手推荐
2011/04/18 PHP
关于PHP语言构造器介绍
2013/07/08 PHP
PHP基于GD库的图像处理方法小结
2016/09/27 PHP
PHP中number_format()函数的用法讲解
2019/04/08 PHP
jQuery的animate函数学习记录
2014/08/08 Javascript
JavaScript中split() 使用方法汇总
2015/04/17 Javascript
DOM 高级编程
2015/05/06 Javascript
js点击文本框弹出可选择的checkbox复选框
2016/02/03 Javascript
关于JS中match() 和 exec() 返回值和属性的测试
2016/03/21 Javascript
layui文件上传实现代码
2017/05/20 Javascript
Angularjs中使用轮播图指令swiper
2017/05/30 Javascript
AngularJS实现注册表单验证功能
2017/10/16 Javascript
JS+HTML+CSS实现轮播效果
2017/11/28 Javascript
JavaScript中常用的3种弹出提示框(alert、confirm、prompt)
2020/11/10 Javascript
Python解析树及树的遍历
2016/02/03 Python
Python常用库推荐
2016/12/04 Python
Python 40行代码实现人脸识别功能
2017/04/02 Python
python实现数独游戏 java简单实现数独游戏
2018/03/30 Python
python实现微信小程序自动回复
2018/09/10 Python
用python3教你任意Html主内容提取功能
2018/11/05 Python
pandas去除重复列的实现方法
2019/01/29 Python
GUESS西班牙官方网上商城:美国服饰品牌
2017/03/15 全球购物
介绍一下MYSQL常用的优化技巧
2012/10/25 面试题
计算机科学与技术应届生求职信
2013/11/07 职场文书
大学校园活动策划书
2014/02/04 职场文书
药学专业学生的自我评价分享
2014/02/06 职场文书
怎样写好创业计划书的内容
2014/02/06 职场文书
入党积极分子自我批评思想汇报
2014/10/10 职场文书
财务部岗位职责
2015/02/03 职场文书
同学聚会通知书
2015/04/20 职场文书
2015年大学班级工作总结
2015/04/28 职场文书
公司开业的祝贺语大全(60条)
2019/07/05 职场文书
浅谈Python项目的服务器部署
2021/04/25 Python
python异常中else的实例用法
2021/06/15 Python
Java并发编程之Executor接口的使用
2021/06/21 Java/Android