项目介绍
通过python及MySQL实现疫苗接种管理系统,大三下学期课程设计
软件架构
软件架构说明 本系统纯为课程设计开发,仅包含基本操作
本项目的具体任务是制作基于Mysql的疫苗信息管理系统,能够实现疫苗信息的增删查改等具体功能需求描述如下。
(1)注册/登录:完成身份信息的注册及认证
(2)疫苗添加:添加疫苗详细信息。
(3)疫苗删除:根据指定ID号删除对应的疫苗信息。
(4)疫苗修改:根据指定ID号修改对应的疫苗信息。
(5)疫苗查询:根据指定ID号查询对应的疫苗信息。
(6)每一步操作前都会检查登录状态,若为False则需要登录后才可操作。
安装教程
python3.6 及以上
必要的包pymysql
开发工具为pycharm
使用说明
自行创建数据库:create database vaccine
更改为自己的数据库密码
本系统仅练习使用,不涉及较深入内容
完整源码
#!/usr/bin/env python
# encoding: utf-8
import pymysql
class Vaccines(object):
def __init__(self):
self.db = pymysql.connect(host="localhost", port=3306,
user="root", password="root",
database="vaccine", charset="utf8")
self.cur = self.db.cursor()
self.state = False # 判断是否登录
def register(self):
name = input("请输入你的用户名:")
passwd = input("请输入你的密码:")
sql = "insert into user values(%s,%s)"
try:
self.cur.execute(sql, [name, passwd])
self.db.commit()
print("注册成功")
except Exception as e:
print("错误: ", e, "(用户名可能已经存在)")
self.db.rollback()
self.close_all()
def login(self):
name = input("请输入你的用户名: ")
passwd = input("请输入你的密码: ")
try:
sql = "select * from user where name = '%s'" % name
self.cur.execute(sql)
data = self.cur.fetchone()
if data[1] == passwd:
print("登录成功!!!")
self.state = True
else:
print("密码错误!!!")
except:
print("用户名错误!!!")
# self.close_all()
def adds(self):
if self.state:
v_type = input("疫苗类型:")
v_num = input("疫苗数量:")
v_price = input("疫苗价格:")
sql = "insert into vaccine_message(vaccine_type, vaccine_num, vaccine_price) " \
"value ('%s', '%s', '%s')" % (v_type, v_num, v_price)
self.cur.execute(sql)
self.db.commit()
print("插入成功!")
return "ok"
else:
print("请登录!!!")
self.login()
def check(self): # 查询
if self.state:
vid = int(input('请输入您要修改的id序号:'))
sql = "select * from vaccine_message where vaccine_id={}".format(vid)
self.cur.execute(sql)
self.db.commit()
result = self.cur.fetchall()
for i in result:
print("id:{}, 名称:{}, 数量:{}, 价格:{}".format(i[0], i[1], i[2], i[3]))
print("查询成功!")
return "ok"
else:
print("请登录!!!")
self.login()
def update(self): # 修改
if self.state:
vid = int(input('请输入您要修改的id序号:'))
v_name = input("请输入修改后的疫苗名称:")
v_num = input("请输入修改后的疫苗数量:")
v_price = input("请输入修改后的疫苗价格:")
sql = "update vaccine_message set vaccine_type='{}' where vaccine_id={}".format(v_name, vid)
sql1 = "update vaccine_message set vaccine_num='{}' where vaccine_id={}".format(v_num, vid)
sql2 = "update vaccine_message set vaccine_price='{}' where vaccine_id={}".format(v_price, vid)
self.cur.execute(sql)
self.cur.execute(sql1)
self.cur.execute(sql2)
self.db.commit()
print('更新成功!')
else:
print("请登录!!!")
self.login()
def delete(self):
v_id = int(input("请输入你要删除的id号:"))
if self.state:
sql = "delete from vaccine_message where vaccine_id={}".format(v_id)
self.cur.execute(sql)
self.db.commit()
print('删除{}号成功!'.format(v_id))
else:
print("请登录!!!")
self.login()
def show(self):
if self.state:
sql = "select * from vaccine_message"
self.cur.execute(sql)
self.db.commit()
result = self.cur.fetchall()
for i in result:
print("id:{}, 名称:{}, 数量:{}, 价格:{}".format(i[0], i[1], i[2], i[3]))
print("查询成功!")
return "ok"
else:
print("请登录!!!")
self.login()
def close_all(self):
self.cur.close()
self.db.close()
if __name__ == '__main__':
vaccine = Vaccines()
while True:
print("*****************菜单*****************")
print("1.注册 2.登录")
print("3.添加疫苗信息 4.查询疫苗信息")
print("5.更新疫苗信息 6.删除疫苗信息")
print("7.显示所有信息 8.退出")
a = input("请选择你要操作的序号: ")
if a == "1": # 注册
vaccine.register()
elif a == "2": # 登录
vaccine.login()
elif a == '3': # 添加疫苗信息
vaccine.adds()
elif a == '4': # 查询疫苗信息
vaccine.check()
elif a == '5': # 更新疫苗信息
vaccine.update()
elif a == '6': # 删除疫苗信息
vaccine.delete()
elif a == '7': # 显示全部信息
vaccine.show()
elif a == '8':
break

被折叠的 条评论
为什么被折叠?



