Python校园学生一卡通管理
信息化管理
283.41KB
16
需要积分: 1
立即下载
资源介绍:
Python校园学生一卡通管理
import sqlite3
from tkinter import *
from tkinter import ttk, messagebox
import time
win = Tk()
win.title('登录')
screenwidth = win.winfo_screenwidth()
screenheight = win.winfo_screenheight()
size = '%dx%d+%d+%d' % (400, 400, (screenwidth - 400) / 2, (screenheight - 400) / 2)
win.geometry(size)
win.resizable(False, False)
# 登录**页面布局
lab1 = Label(win, text='一卡通管理系统登录', font='微软雅黑 15').place(x=120, y=30)
frame1 = Frame(win, height=200, width=300, bd=1, relief='sunken')
frame1.place(x=50, y=90)
lab_username = Label(frame1, text='用户名:', font='微软雅黑 12').place(x=40, y=40)
entry_username = Entry(frame1, width=20)
entry_username.place(x=110, y=45)
lab_passwd = Label(frame1, text='密 码:', font='微软雅黑 12').place(x=40, y=80)
entry_passwd = Entry(frame1, width=20, show='*')
entry_passwd.place(x=110, y=85)
lab4 = Label(frame1, text='选择登录类型:', font='微软雅黑 12').place(x=40, y=120)
combo4 = ttk.Combobox(frame1, width=10, height=20, values=('学生','教职工', '管理员'), state="readonly")
combo4.place(x=150, y=120, )
combo4.current(0) # 默认值
btn1 = ttk.Button(win, text='登录')
btn1.place(x=80, y=320)
btn2 = ttk.Button(win, text='取消', command=lambda: win.quit())
btn2.place(x=240, y=320)
# 创建表
try:
conn = sqlite3.connect('ykt.db')
conn.execute('''CREATE TABLE USER
(ID CHAR(13) PRIMARY KEY NOT NULL ,
PASSWD TEXT,
TYPE TEXT)''')
conn.execute('''CREATE TABLE USERINFO
(ID CHAR(13) PRIMARY KEY NOT NULL ,
NAME TEXT,
SEX BOOLEAN,
banji CHAR(11),
major CHAR(50))''')
conn.execute('''CREATE TABLE CDINFO
(ID CHAR(13) PRIMARY KEY NOT NULL,
MONEY FLOAT ,
LOCK BOOLEAN)''')
conn.execute('''CREATE TABLE HISTORY
(ID CHAR(13) ,
NAME text
TIME TEXT,
MONEY FLOAT,
BANJI text,
ZHUANYE text)''')
messagebox.showinfo('欢迎使用', '初始化成功!')
conn.close()
except:
pass
conn = sqlite3.connect('ykt.db')
varmoney = StringVar()
infoID = StringVar()
sexSelect = StringVar()
peopleSelect = StringVar()
time1 = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
def check_lock(ID):
cursor = conn.execute('SELECT lock from CDINFO where ID= "' + ID + '"')
temp = cursor.fetchall()
if temp[0][0] == 1:
messagebox.showinfo('提示', '此一卡通已锁定')
return False
else:
return True
def doSql(sql):
'''用来执行SQL语句,尤其是INSERT和DELETE语句'''
conn = sqlite3.connect('ykt.db')
cur = conn.cursor()
cur.execute(sql)
conn.commit()
conn.close()
# 登录**函数定义
def login(event):
def infoWin():
'''详细信息——窗口'''
global infoID, sexSelect
winInfo = Toplevel()
sizeWinInfo = '%dx%d+%d+%d' % (500, 500, (screenwidth - 500) / 2, (screenheight - 500) / 2)
winInfo.geometry(sizeWinInfo)
winInfo.title('详细信息')
winInfo.attributes("-toolwindow", 1) # 新窗口在最上面
lab11InfoID = Label(winInfo, text='卡号', font='微软雅黑 12', fg='blue').place(x=140, y=10)
lab12InfoID = Label(winInfo, textvariable=infoID, font='微软雅黑 12', fg='blue').place(x=220, y=10)
lab2InfoName = Label(winInfo, text='姓名', font='微软雅黑 12').place(x=140, y=60)
entryInfoName = Entry(winInfo, width=20)
entryInfoName.place(x=220, y=62)
lab3InfoName = Label(winInfo, text='性别', font='微软雅黑 12').place(x=140, y=140)
comboInfoSex = ttk.Combobox(winInfo, width=5, height=20, textvariable=sexSelect, values=('男', '女'),
state="readonly")
comboInfoSex.place(x=220, y=142)
sexSelect.set('男')
lab41InfoNum = Label(winInfo, text='班级', font='微软雅黑 12').place(x=140, y=220)
entryInfoNum = Entry(winInfo, width=20)
entryInfoNum.place(x=220, y=222)
lab5Infomajor = Label(winInfo, text='专业', font='微软雅黑 12').place(x=140, y=300)
entryInfomajor = Entry(winInfo, width=20)
entryInfomajor.place(x=220, y=302)
btn1Info = ttk.Button(winInfo, text='确定', width=15)
btn1Info.place(x=100, y=400)
btn2Info = ttk.Button(winInfo, text='清除', width=15)
btn2Info.place(x=300, y=400)
cursor = conn.execute('select * from USERINFO where ID = "' + infoID.get() + '"')
temp = cursor.fetchall()[0]
entryInfoName.insert(0, temp[1])
sexSelect.set(temp[2])
entryInfoNum.insert(0, temp[3])
entryInfomajor.insert(0, temp[4])
def check(event):
ID = infoID.get()
name = entryInfoName.get()
sex = comboInfoSex.get()
banji = entryInfoNum.get()
major = entryInfomajor.get()
if name == '':
messagebox.showerror('错误', '姓名不能为空')
return
if banji != '':
if len(banji) != 1:
messagebox.showerror('错误', '请输入正确班级号')
return
ask = messagebox.askyesnocancel('注意', '是否保存修改?')
if ask == True:
sql = 'update USERINFO set name = "' + name + '", sex = "'
sql += sex + '", banji = "' + banji + '",zhuanye ="' + major + '"'
doSql(sql)
winInfo.destroy()
messagebox.showinfo('恭喜', '修改成功!')
elif ask == False:
winInfo.destroy()
else:
pass
def clear(event):
entryInfoName.delete(0, END)
entryInfoNum.delete(0, END)
entryInfomajor.delete(0, END)
comboInfoSex.current(0)
btn1Info.bind('', check)
btn2Info.bind('', clear)
def jianMoneyWin():
'''消费——窗口'''
global entry1jianMoney, ID
winjianMoney = Toplevel()
sizeWinjianMoney = '%dx%d+%d+%d' % (400, 250, (screenwidth - 400) / 2, (screenheight - 250) / 2)
winjianMoney.geometry(sizeWinjianMoney)
winjianMoney.title('消费')
winjianMoney.attributes("-toolwindow", 1) # 新窗口在最上面
framejianMoney = Frame(winjianMoney, height=200, width=340, bd=1, relief='sunken')
framejianMoney.place(x=30, y=30)
lab1jianMoney = Label(framejianMoney, text='消费金额:', font='微软雅黑 12').place(x=50, y=30)
entry1jianMoney = Entry(framejianMoney, width=20)
entry1jianMoney.place(x=130, y=32)
btn1jianMoney = ttk.Button(framejianMoney, text='确认')
btn1jianMoney.place(x=40, y=150)
btn2jianMoney = ttk.Button(framejianMoney, text='清除')
btn2jianMoney.place(x=200, y=150)
def clear(event):
entry1jianMoney.delete(0, END)
def jian(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(entry1jianMoney.get())) + '" where ID = "' + ID + '"'
temp='消费'+entry1jianMoney.get()+'元'
sql2 = 'insert into HISTORY values("' + ID + '","' + time1 + '","' + temp + '")'
doSql(sql1)
doSql(sql2)
cursor = conn.execute('select money from CDINFO where ID = "' + ID + '"'