常州大学Python课设,校园一卡通
一、设计题目:校园一卡通管理系统 |
二、 设计内容:
2. 数据库可以使用二进制文件, 也可以使用数据库软件工具,如MySQL\SQLite. 3. 系统可采用文本界面, 也可以使用图形界面(GUI会加分) 4. 功能基本要求: (1) 一卡通的充值、消费和余额查询 (2) 按性别、班级、专业进行消费总额统计,通过可视化方式比较两者的消费总额 5. 完成课程设计报告. |
三、基本要求:
(1)能够实现任务书中的功能; (2)尽可能使界面友好、直观、易操作; (3)源程序要有适当的注释,使程序容易阅读。
(1)运行所设计的系统; (2)回答有关问题; (3)提交课程设计报告和任务书; (4)提交源程序 |
- 用类的方法设计学生一卡通数据类型学生一卡通的基本数据成员至少包括:卡号(学号), 姓名, 性别, 余额,消费总额 (食堂、机房),图书借阅信息等;
- 数据库可以使用二进制文件, 也可以使用数据库软件工具,如MySQL\SQLite;
- 系统可采用文本界面, 也可以使用图形界面(GUI会加分);
- 功能基本要求:
(1) 一卡通的充值、消费和余额查询
(2) 按性别、班级、专业进行消费总额统计,通过可视化方式比较两者的消费总额
完成课程设计报告.
1.2 系统功能结构框图
图1-1 系统主要功能图
- 创建图形用户界面,实现与用户的交互,设计要求简洁,符合日常使用习惯;
- 将学生一卡通信息存储到数据库中,方便对数据的进一步处理;
- 利用SQLite数据库实现丰富的查询功能。
- 在考虑到本系统所需处理数据量时,本系统选用SQLite数据库管理系统。对于较小型的数据库SQLite更加的灵活、简便。
- 本系统采用的数据库管理软件时Navicat Premium15,可以使管理人员更加方便地使用数据库
图2-1数据库数据类型
图2-2 数据库部分内容
3.1 登陆界面
登陆时选择身份,学生/教职工信息与数据库进行匹配,若匹配相同则成功登录。对于管理人员,账号为:cczuhost,密码:123456.
# 学生/教职工登录
if combo4.get() == '学生' or combo4.get() == '教职工':
cursor = conn.execute('SELECT * from USER where ID= "' + entry_username.get() + '"')
temp = cursor.fetchall()
if len(temp) == 0:
messagebox.showerror('错误', '用户不存在')
return
elif temp[0][2] != combo4.get():
messagebox.showerror('错误', '用户类别不正确')
return
elif check_lock(entry_username.get()):
passwd = temp[0][1]
if entry_passwd.get() != passwd:
messagebox.showerror('错误', '用户名或密码不正确')
return
else:
newWin()
3.2 学生充值/消费
成功登录学生端,在菜单中选择充值/消费。输入学生充值/消费的金额。
def addMoneyWin():
'''充值——窗口'''
global entry1AddMoney, ID
winAddMoney = Toplevel()
sizeWinAddMoney = '%dx%d+%d+%d' % (400, 250, (screenwidth - 400) / 2, (screenheight - 250) / 2)
winAddMoney.geometry(sizeWinAddMoney)
winAddMoney.title('充值')
winAddMoney.attributes("-toolwindow", 1) # 新窗口在最上面
frameAddMoney = Frame(winAddMoney, height=200, width=340, bd=1, relief='sunken')
frameAddMoney.place(x=30, y=30)
lab1AddMoney = Label(frameAddMoney, text='充值金额:', font='微软雅黑 12').place(x=50, y=30)
entry1AddMoney = Entry(frameAddMoney, width=20)
entry1AddMoney.place(x=130, y=32)
btn1AddMoney = ttk.Button(frameAddMoney, text='确认')
btn1AddMoney.place(x=40, y=150)
btn2AddMoney = ttk.Button(frameAddMoney, text='清除')
btn2AddMoney.place(x=200, y=150)
def clear(event):
entry1AddMoney.delete(0, END)
def add(event):
cursor = conn.execute('select money from CDINFO where ID = "' + ID + '"')
temp = cursor.fetchall()
money1 = temp[0][0]
sql1 = 'update CDINFO set money = "' + str(
money1 + float(entry1AddMoney.get())) + '" where ID = "' + ID + '"'
temp='充值' + entry1AddMoney.get() + '元'
sql2 = 'insert into HISTORY values("' + ID + '","' + time1 + '","' + temp + '")'
doSql(sql1)
doSql(sql2)
cursor = conn.execute('select money from CDINFO where ID = "' + ID + '"')
temp = cursor.fetchall()
money2 = temp[0][0]
messagebox.showinfo('恭喜', '充值成功!当前余额为%0.2f' % money2 + ' 元')
varmoney.set(money2)
winAddMoney.destroy()
btn1AddMoney.bind('<Button-1>', add)
btn2AddMoney.bind('<Button-1>', clear)
3.3 学生挂失一卡通
在菜单中选择挂失。将数据库中的Lock值,设定为1,当再用此账号登陆时就会显示一卡通已经锁定,需要从管理端进行解锁
def lost(event):
'''挂失'''
ask = messagebox.askyesno('提示', '将要进行挂失,挂失后将不能自助解锁\n\t是否继续?')
if ask == True:
if check_lock(entryNewWinID.get()):
sql = 'update CDINFO set lock = "1" where ID = "' + entryNewWinID.get() + '"'
doSql(sql)
winNewWin.destroy()
else:
return
3.4 学生流水查询
当学生充值/消费时会向数据库中写入金额变化信息,只要将其中的信息读取出来即可。
def look(event):
'''查看历史'''
lookWin()
showall(entryNewWinID.get())
3.5 管理端增加学生信息
# 管理员***函数定义
def addUser(event):
'''新建用户'''
global peopleSelect
win_root_new = Toplevel(win_root)
size_root_new = '%dx%d+%d+%d' % (500, 500, (screenwidth - 500) / 2, (screenheight - 500) / 2)
win_root_new.geometry(size_root_new)
win_root_new.title('新建用户')
lab11_root_new = Label(win_root_new, text='卡号', font='微软雅黑 12').place(x=140, y=60)
lab12_root_new = Label(win_root_new, text='*', fg='red').place(x=180, y=60)
entry_new_ID = Entry(win_root_new, width=20)
entry_new_ID.place(x=220, y=62)
lab21_root_new = Label(win_root_new, text='姓名', font='微软雅黑 12').place(x=140, y=100)
lab22_root_new = Label(win_root_new, text='*', fg='red').place(x=180, y=100)
entry_new_name = Entry(win_root_new, width=20)
entry_new_name.place(x=220, y=102)
lab3_root_new = Label(win_root_new, text='性别', font='微软雅黑 12').place(x=140, y=140)
combo_new_sex = ttk.Combobox(win_root_new, width=5, height=20, values=('男', '女'), state="readonly")
combo_new_sex.place(x=220, y=142)
combo_new_sex.current(0)
lab4_root_new = Label(win_root_new, text='班级', font='微软雅黑 12').place(x=140, y=200)
entry_new_phone = Entry(win_root_new, width=20)
entry_new_phone.place(x=220, y=202)
lab5_root_new = Label(win_root_new, text='专业', font='微软雅黑 12').place(x=140, y=240)
entry_new_major = Entry(win_root_new, width=20)
entry_new_major.place(x=220, y=242)
lab6_root_new = Label(win_root_new, text='类别', font='微软雅黑 12').place(x=140, y=280)
comboInfoPeople = ttk.Combobox(win_root_new, width=5, height=20, textvariable=peopleSelect,
values=('学生', '教职工'), state="readonly")
comboInfoPeople.place(x=220, y=282)
peopleSelect.set('')
btn1_root_new = ttk.Button(win_root_new, text='确定', width=15)
btn1_root_new.place(x=100, y=400)
btn2_root_new = ttk.Button(win_root_new, text='清除', width=15)
btn2_root_new.place(x=300, y=400)
def check(event):
ID = entry_new_ID.get()
name = entry_new_name.get()
sex = combo_new_sex.get()
banji = entry_new_phone.get()
major = entry_new_major.get()
passwd = '123456'
people = comboInfoPeople.get()
if ID == '':
messagebox.showerror('错误', '卡号不能为空')
return
if len(ID) != 8:
messagebox.showerror('错误', '卡号必须为8位')
return
cursor = conn.execute('SELECT * from USERINFO where ID= "' + ID + '"')
temp = cursor.fetchall()
if len(temp) != 0:
messagebox.showerror('错误', '卡号已存在')
return
if name == '':
messagebox.showerror('错误', '姓名不能为空')
return
if banji != '':
if len(banji) != 1:
messagebox.showerror('错误', '班级输入有误')
return
if people == '':
messagebox.showerror('错误', '请选择用户类别')
return
sql1 = 'insert into USERINFO values("' + ID + '","' + name + '","' + sex + '","' + banji + '","' + major + '")'
sql2 = 'insert into USER values("' + ID + '","' + passwd + '","' + people + '")'
sql3 = 'insert into CDINFO values("' + ID + '","0","0")'
sql4 = 'insert into HISTORY values("' + ID + '","' + time1 + '","0")'
doSql(sql1)
doSql(sql2)
doSql(sql3)
doSql(sql4)
win_root_new.destroy()
messagebox.showinfo('恭喜', '新建成功!')
3.6 挂失/解锁
def lostUnlock(event):
'''挂失解锁'''
if entry_ser_num.get() == '':
messagebox.showerror('错误', '请输入要挂失/解锁的卡号')
return
else:
cursor = conn.execute('SELECT * from USER where ID= "' + entry_ser_num.get() + '"')
temp = cursor.fetchall()
if len(temp) == 0:
messagebox.showerror('错误', '用户不存在')
return
winLostUnlock = Toplevel(win_root)
sizeLostUnlock = '%dx%d+%d+%d' % (400, 250, (screenwidth - 400) / 2, (screenheight - 250) / 2)
winLostUnlock.geometry(sizeLostUnlock)
winLostUnlock.title('挂失/解锁')
btn1LostUnlock = ttk.Button(winLostUnlock, text='挂失', width=15)
btn1LostUnlock.place(x=150, y=80)
btn2LostUnlock = ttk.Button(winLostUnlock, text='解锁', width=15)
btn2LostUnlock.place(x=150, y=150)
def lock(event):
if check_lock(entry_ser_num.get()):
sql = 'update CDINFO set lock = "1" where ID = "' + entry_ser_num.get() + '"'
doSql(sql)
winLostUnlock.destroy()
messagebox.showinfo('提示', '已挂失')
def unLock(event):
cursor = conn.execute('SELECT lock from CDINFO where ID= "' + entry_ser_num.get() + '"')
temp = cursor.fetchall()
if temp[0][0] == 0:
messagebox.showerror('错误', '不可重复解锁')
return
sql = 'update CDINFO set lock = "0" where ID = "' + entry_ser_num.get() + '"'
doSql(sql)
winLostUnlock.destroy()
messagebox.showinfo('提示', '已解锁')
btn1LostUnlock.bind('<Button-1>', lock)
btn2LostUnlock.bind('<Button-1>', unLock)
3.7 查看历史消费记录
def lookRoot(event):
'''查看历史'''
if entry_ser_num.get() == '':
messagebox.showerror('错误', '请输入要查看的卡号')
return
else:
cursor = conn.execute('SELECT * from USER where ID= "' + entry_ser_num.get() + '"')
temp = cursor.fetchall()
if len(temp) == 0:
messagebox.showerror('错误', '用户不存在')
return
else:
lookWin()
showall(entry_ser_num.get())
btn1_root.bind('<Button-1>', addUser)
btn2_root.bind('<Button-1>', addmoneyRoot)
btn3_root.bind('<Button-1>', logout)
btn4_root.bind('<Button-1>', informationRoot)
btn5_root.bind('<Button-1>', lostUnlock)
btn6_root.bind('<Button-1>', lookRoot)
else:
messagebox.showerror('错误', '用户名或密码错误!')
登陆时选择身份,学生/教职工信息与数据库进行匹配,若匹配相同则成功登录。对于管理人员,账号为:cczuhost,密码:123456.
图4-1 登陆界面
4.2 学生端菜单
图4-2 学生端菜单
4.3 充值/消费界面
图4-3 成功充值
4.4挂失一卡通
图4-4 挂失一卡通
图4-5新建学生信息
4.6 挂失/解锁一卡通
图4-6 挂失/解锁一卡通
4.7查询流水
图4-7 查询流水
代码链接:(理解优先,拒绝抄袭,支持完善)Python一卡通项目 - python_xiaoyuanyikatong - 代码 - 我的学习圈 - WRITE-BUG (writebug.com)