python实现教务管理系统

python实现教务管理系统,第1张

概述这是一个使用Python实现基于dos下面向数据库的教务管理系统,实现了管理员、教职工、学生三种不同身份的 *** 作,可以实现的功能有:学生、教职工信息管理、不同权限的信息发布、管理各种信息等。代码约1200行,对于pyt

这是一个使用Python实现基于dos下面向数据库的教务管理系统,实现了管理员、教职工、学生三种不同身份的 *** 作,可以实现的功能有:学生、教职工信息管理、不同权限的信息发布、管理各种信息等。代码约1200行,对于python初学者应该能提供一些帮助。

Login.py

#-*- Coding:utf-8 -*-#####系统登录import osimport MysqLdbimport timeclass 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 osimport MysqLdbimport Studentimport Teacherimport Loginimport SystemManagerif __name__ == '__main__': conn = MysqLdb.connect(user='root',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[1]) usr.MainFunc() elif account[2] == 2: usr = Student.Student(conn,account[1]) usr.MainFunc() else :  conn.close() raise exception() conn.close()

Student.py

#-*- Coding:utf-8 -*-####学生账号import MysqLdbimport osclass 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,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),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),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',db = 'db_educationalmanagementsystem') stu = Student(conn,'0000001','123456') stu.MainFunc() conn.close()

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

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

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

您可能感兴趣的文章:python学生管理系统代码实现python图书管理系统python实现图书管理系统Python实现识别手写数字 简易图片存储管理系统python实现员工管理系统python实现学生管理系统python实现外卖信息管理系统Python实现学生成绩管理系统名片管理系统python版wxpython实现图书管理系统 总结

以上是内存溢出为你收集整理的python实现教务管理系统全部内容,希望文章能够帮你解决python实现教务管理系统所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1200401.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存