python实现教务管理系统

 更新时间:2018年03月12日 11:00:31   作者:StoryMonster  
这篇文章主要介绍了python实现教务管理系统,实现了管理员、教职工、学生三种不同身份的操作,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud

(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

这是一个使用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中的模块、包和库

    这篇文章主要介绍了详细一文带你分清Python中的模块、包和库,Python?模块(Module),是一个?Python?文件,以?.py?结尾,包含了?Python?对象定义和Python语句,模块能定义函数,类和变量,模块也能包含可执行的代码,需要的朋友可以参考下
    2023-08-08
  • Python安装spark的详细过程

    Python安装spark的详细过程

    这篇文章主要介绍了Python安装spark的详细过程,本文通过图文实例代码相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2021-10-10
  • Sublime开发python程序的示例代码

    Sublime开发python程序的示例代码

    本篇文章主要介绍了Sublime开发python程序的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-01-01
  • 赚疯了!转手立赚800+?大佬的python「抢茅台脚本」使用教程

    赚疯了!转手立赚800+?大佬的python「抢茅台脚本」使用教程

    这篇文章主要介绍了如果利用python抢购京东茅台,帮助大家更好的理解和使用python,感兴趣的朋友可以了解下
    2021-01-01
  • Python中asyncio模块的深入讲解

    Python中asyncio模块的深入讲解

    这篇文章主要给大家介绍了关于Python中asyncio模块的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Python具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-06-06
  • 浅谈tensorflow使用张量时的一些注意点tf.concat,tf.reshape,tf.stack

    浅谈tensorflow使用张量时的一些注意点tf.concat,tf.reshape,tf.stack

    这篇文章主要介绍了浅谈tensorflow使用张量时的一些注意点tf.concat,tf.reshape,tf.stack,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-06-06
  • python爬虫之场内ETF基金获取

    python爬虫之场内ETF基金获取

    这篇文章主要介绍了python爬虫之场内ETF基金获取,ETF?是一种场内交易型基金,可以在盘中进行交易,交易性比场外基金强一点,下文基于python的相关资料展开,需要的小伙伴可以参考一下
    2022-05-05
  • Python3 串口接收与发送16进制数据包的实例

    Python3 串口接收与发送16进制数据包的实例

    今天小编就为大家分享一篇Python3 串口接收与发送16进制数据包的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-06-06
  • Python random库使用方法及异常处理方案

    Python random库使用方法及异常处理方案

    这篇文章主要介绍了python random库使用方法及异常处理,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-03-03
  • python复制与引用用法分析

    python复制与引用用法分析

    这篇文章主要介绍了python复制与引用,实例分析了python中复制与引用的具体使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下
    2015-04-04

最新评论

?


http://www.vxiaotou.com