python+mysql实现教务管理系统


Posted in Python onFebruary 20, 2019

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

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

Python 相关文章推荐
Python yield使用方法示例
Dec 04 Python
python实现ipsec开权限实例
Nov 11 Python
Python实现文件内容批量追加的方法示例
Aug 29 Python
python实现外卖信息管理系统
Jan 11 Python
通过Python 接口使用OpenCV的方法
Apr 02 Python
python 巧用正则寻找字符串中的特定字符的位置方法
May 02 Python
python 数字类型和字符串类型的相互转换实例
Jul 17 Python
对python同一个文件夹里面不同.py文件的交叉引用方法详解
Dec 15 Python
Python统计学一数据的概括性度量详解
Mar 03 Python
解决Opencv+Python cv2.imshow闪退问题
Apr 24 Python
如何卸载python插件
Jul 08 Python
如何用Python 加密文件
Sep 10 Python
python Tkinter版学生管理系统
Feb 20 #Python
啥是佩奇?使用Python自动绘画小猪佩奇的代码实例
Feb 20 #Python
Python实战购物车项目的实现参考
Feb 20 #Python
利用django+wechat-python-sdk 创建微信服务器接入的方法
Feb 20 #Python
python3+pyqt5+itchat微信定时发送消息的方法
Feb 20 #Python
钉钉群自定义机器人消息Python封装的实例
Feb 20 #Python
python3实现zabbix告警推送钉钉的示例
Feb 20 #Python
You might like
PHP 函数执行效率的小比较
2010/10/17 PHP
jQuery EasyUI API 中文文档 - DateBox日期框
2011/10/15 PHP
php引用计数器进行垃圾收集机制介绍
2012/09/19 PHP
php启用zlib压缩文件的配置方法
2013/06/12 PHP
Codeigniter实现发送带附件的邮件
2015/03/19 PHP
php curl请求信息和返回信息设置代码实例
2015/04/27 PHP
详解PHP中的Traits
2015/07/29 PHP
通过PHP自带的服务器来查看正则匹配结果的方法
2015/12/24 PHP
nicejforms——美化表单不用愁
2007/02/20 Javascript
javascript 二分法(数组array)
2010/04/24 Javascript
解析页面加载与js函数的执行 onload or ready
2013/12/12 Javascript
JQuery 图片滚动轮播示例代码
2014/03/24 Javascript
jQuery绑定事件不执行但alert后可以正常执行
2014/06/03 Javascript
Backbone.js的一些使用技巧
2015/07/01 Javascript
详解Node.js中的事件机制
2016/09/22 Javascript
第一次接触神奇的前端框架vue.js
2016/12/01 Javascript
Vue2 使用 Echarts 创建图表实例代码
2017/05/18 Javascript
AngularJs 终极购物车(实例讲解)
2017/11/08 Javascript
vue新vue-cli3环境配置和模拟json数据的实例
2018/09/19 Javascript
Vue使用NPM方式搭建项目
2018/10/25 Javascript
vue中上传视频或图片或图片和文字一起到后端的解决方法
2019/12/01 Javascript
Python while 循环使用的简单实例
2016/06/08 Python
为什么说Python可以实现所有的算法
2019/10/04 Python
Django 解决由save方法引发的错误
2020/05/21 Python
python全栈开发语法总结
2020/11/22 Python
pytorch中index_select()的用法详解
2021/01/06 Python
授权委托书范本
2014/04/03 职场文书
英语三分钟演讲稿
2014/08/19 职场文书
党员干部反四风对照检查材料思想汇报
2014/09/14 职场文书
庆祝国庆节标语
2014/10/09 职场文书
党员剖析材料范文
2014/12/18 职场文书
婚礼父母答谢词
2015/01/04 职场文书
2015年银行柜员工作总结报告
2015/04/01 职场文书
CSS3 实现NES游戏机的示例代码
2021/04/21 HTML / CSS
MySQL 如何限制一张表的记录数
2021/09/14 MySQL
Nginx 匹配方式
2022/05/15 Servers