赞
踩
电影院售票系统可作为电影院网上售票平台,对于电影院的管理员,可以为该电影院引入添加新上映的电影,也可以对该电影院的电影进行排片,即安排播放时间、放映厅、票价、电影等等,也可以对用户的订单进行增加,删除,查找,修改操作。对于用户,可以进行注册,登录,查看排片信息、订单信息和购票功能。
- import mysql.connector
- from tkinter import ttk
- import tkinter as tk
- import tkinter.font as tkFont
- from tkinter import * # 图形界面库
- import tkinter.messagebox as messagebox
- import pymysql
-
- class beginpage :
- def __init__(self,p):
- p.destroy()
- self.window = tk.Tk() # 初始框的声明
- self.window.title('电影院网上售票系统')
- self.window.geometry('600x600') # 这里的乘是小x
- self.window.geometry('+330+0')
- label = Label(self.window, text="电影院网上售票系统", font=("Verdana", 50),fg="red",bg='green')
- label.pack(pady=0)
- Button(self.window, text="电影院管理员登陆", font=tkFont.Font(size=20), command=lambda: adminpage(self.window), width=60,
- height=2,fg='white', bg='gray').pack()
- Button(self.window, text="用户登陆", font=tkFont.Font(size=20), command=lambda: UserPage(self.window), width=60,
- height=2, fg='white', bg='gray').pack()
- Button(self.window, text="用户注册", font=tkFont.Font(size=20), command=lambda: UserSign(self.window), width=60,
- height=2, fg='white', bg='gray').pack()
- Button(self.window, text='退出系统', height=2, font=tkFont.Font(size=20), width=60, command=self.window.destroy,
- fg='white', bg='gray').pack()
- self.window.mainloop() # 主消息循环
-
- class adminpage :
- def __init__(self,p):
- p.destroy()
- self.window = tk.Tk() # 初始框的声明
- self.window.title('管理员登录界面')
- self.window.geometry('600x600') # 这里的乘是小x
- self.window.geometry('+330+0')
-
- label = tk.Label(self.window, text='管理员登陆', bg='green', font=('Verdana', 30), width=40, height=3)
- label.pack()
- Label(self.window, text='管理员账号:', font=tkFont.Font(size=20)).pack(pady=25)
- self.admin_username = tk.Entry(self.window, width=30, font=tkFont.Font(size=20), bg='Ivory')
- self.admin_username.pack()
-
- Label(self.window, text='管理员密码:', font=tkFont.Font(size=20)).pack(pady=25)
- self.admin_pass = tk.Entry(self.window, width=30, font=tkFont.Font(size=20), bg='Ivory', show='*')
- self.admin_pass.pack()
- Button(self.window, text="登陆", width=10, font=tkFont.Font(size=15), command=self.login).pack(pady=40)
- self.window.protocol("WM_DELETE_WINDOW", self.back)
- self.window.mainloop() # 进入消息循环
-
- def login(self):
- # 从界面获取的数据
- print(str(self.admin_username.get()))
- print(str(self.admin_pass.get()))
- admin_pass = None
-
- # 数据库操作 查询管理员表
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8') # 打开数据库连接
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "SELECT * FROM 管理员信息 WHERE 管理员账号 = '%s'" % (self.admin_username.get()) # SQL 查询语句
- try:
- # 执行SQL语句
- cursor.execute(sql)
- # 获取所有记录列表
- results = cursor.fetchall()
- for row in results:
- admin_id = row[0]
- admin_pass = row[1]
- # 打印结果
- print("admin_id=%s,admin_pass=%s" % (admin_id, admin_pass))
- except:
- print("Error: unable to fecth data")
- messagebox.showinfo('警告!', '用户名或密码不正确!')
- con.close() # 关闭数据库连接
-
- print("正在登陆管理员管理界面")
- # 从界面获取的数据
- print("self", self.admin_pass)
- # 数据库里的数据
- print("local", admin_pass)
-
- # 判断密码,正确则进入管理员操作界面
- if self.admin_pass.get() == admin_pass:
- adminMessage(self.window)
- else:
- messagebox.showinfo('警告!', '用户名或密码不正确!')
-
- def back(self):
- beginpage(self.window) # 显示主窗口 销毁本窗口
-
- class adminMessage:
- def __init__(self, parent_window):
- parent_window.update()
- parent_window.destroy() # 销毁子界面
-
- self.window = tk.Tk() # 初始框的声明
- self.window.title('首页')
- self.window.geometry('600x600') # 这里的乘是小
- self.window.geometry('+330+0')
-
- label = Label(self.window, text="电影操作", font=("Verdana", 20))
- label.pack(pady=50) # pady=100 界面的长度
-
- Button(self.window, text="查看订单信息", font=tkFont.Font(size=30), command=lambda: adlook(self.window), width=30,
- height=2,
- fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
- Button(self.window, text="查看电影信息", font=tkFont.Font(size=30), command=lambda: lookmovie(self.window), width=30,
- height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
- Button(self.window, text="查看排片信息", font=tkFont.Font(size=30), command=lambda: adpai(self.window), width=30,
- height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
- Button(self.window, text="退出登录", font=tkFont.Font(size=30), command=lambda: beginpage(self.window), width=30,
- height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
-
- self.window.mainloop() # 主消息循环
-
- class UserPage:
- def __init__(self, parent_window):
- parent_window.destroy() # 销毁主界面
- self.window = tk.Tk() # 初始框的声明
- self.window.title('用户登陆')
- self.window.geometry('600x600') # 这里的乘是小x
- self.window.geometry('+330+0')
- label = tk.Label(self.window, text='用户登陆', bg='green', font=('Verdana', 30), width=40, height=3)
- label.pack()
- Label(self.window, text='用户账号:', font=tkFont.Font(size=20)).pack(pady=25)
- self.user_id = tk.Entry(self.window, width=30, font=tkFont.Font(size=20), bg='Ivory')
- self.user_id.pack()
- Label(self.window, text='用户密码:', font=tkFont.Font(size=20)).pack(pady=25)
- self.user_pass = tk.Entry(self.window, width=30, font=tkFont.Font(size=20), bg='Ivory', show='*')
- self.user_pass.pack()
-
- Button(self.window, text="登陆", width=10, font=tkFont.Font(size=15), command=self.login).pack(pady=40)
- Button(self.window, text="返回", width=10, font=tkFont.Font(size=15), command=self.back).pack()
-
- self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击
- self.window.mainloop() # 进入消息循环
-
- def login(self):
- print(str(self.user_id.get()))
- print(str(self.user_pass.get()))
- tou_pass = None
-
- # 数据库操作 查询管理员表
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8') # 打开数据库连接
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "SELECT * FROM 用户信息 WHERE 用户账号 = '%s'" % (self.user_id.get()) # SQL 查询语句
- try:
- # 执行SQL语句
- cursor.execute(sql)
- # 获取所有记录列表
- results = cursor.fetchall()
- for row in results:
- tou_id = row[0]
- tou_pass = row[4]
- idd=row[1]
- # 打印结果
- print("tou_id=%s,tou_pass=%s" % (tou_id, tou_pass))
- except:
- print("Error: unable to fecth data")
- messagebox.showinfo('警告!', '用户名或密码不正确!')
- con.close() # 关闭数据库连接
-
- print("正在登陆.....")
- print("self", self.user_pass.get())
- print("local", tou_pass)
-
- # 进入门票信息查看界面
- if self.user_pass.get() == tou_pass:
- userindex(self.window)
- else:
- messagebox.showinfo('警告!', '用户名或密码不正确!')
-
- def back(self):
- beginpage(self.window)
-
- class userindex:
- def __init__(self, parent_window):
- parent_window.destroy() # 销毁主界面
-
- self.window = tk.Tk() # 初始框的声明
- self.window.title('首页')
- self.window.geometry('600x600') # 这里的乘是小x
- self.window.geometry('+330+0')
-
- label = tk.Label(self.window, text='欢迎光临豪大大电影院', bg='green', font=('Verdana', 30), width=40, height=3)
- label.pack()
-
- Button(self.window, text="查看全部排片", font=tkFont.Font(size=30), command=lambda: Showmovie(self.window), width=30,
- height=2,
- fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
- Button(self.window, text="购票", font=tkFont.Font(size=30), command=lambda: Buy(self.window),
- width=30,
- height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
- Button(self.window, text="查看订单", font=tkFont.Font(size=30), command=lambda: Look(self.window), width=30,
- height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
- Button(self.window, text="退出登录", font=tkFont.Font(size=30), command=lambda: beginpage(self.window), width=30,
- height=2, fg='white', bg='gray', activebackground='black', activeforeground='white').pack()
-
- self.window.mainloop() # 主消息循环
-
- class Showmovie:
- def __init__(self, parent_window):
- parent_window.destroy() # 自动销毁上一个界面
- self.window = Tk() # 初始框的声明
- self.window.title('管理员操作界面')
- self.window.geometry("600x600+300+0") # 初始窗口在屏幕中的位置
-
- self.frame_center = tk.Frame(width=600, height=400)
- self.frame_bottom = tk.Frame(width=650, height=70)
-
- self.columns = ("排片编号", "电影名字", "放映厅", "放映时间", "价格")
- self.tree = ttk.Treeview(self.frame_center, show="headings", height=30, columns=self.columns)
- # 添加竖直滚动条
- self.vbar = ttk.Scrollbar(self.frame_center, orient=VERTICAL, command=self.tree.yview)
- # 定义树形结构与滚动条
- self.tree.configure(yscrollcommand=self.vbar.set)
- self.vbar.config(command=self.tree.yview())
-
- # 定义id1为修改id时的暂存变量,这个是为了更新信息而设计的
- self.id1 = 0
- self.tree.column("排片编号", width=120, anchor='center') # 表示列,不显示
- self.tree.column("电影名字", width=120, anchor='center')
- self.tree.column("放映厅", width=120, anchor='center')
- self.tree.column("放映时间", width=120, anchor='center')
- self.tree.column("价格", width=120, anchor='center')
-
- # grid方法将tree和vbar进行布局
- self.tree.grid(row=0, column=0, sticky=NSEW)
- self.vbar.grid(row=0, column=1, sticky=NS)
-
- self.schedule_id=[]
- self.schedule_movie=[]
- self.hall_id=[]
- self.schedule_time=[]
- self.schedule_price=[]
-
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy', charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- # sql = "SELECT * FROM 游客信息 WHERE 游客账号 = '%s'" % (self.var_identityid.get()) # SQL 查询语句
- sql = "SELECT * FROM table_schedule"
- try:
- # 执行SQL语句
- cursor.execute(sql)
- # 获取所有记录列表
- results = cursor.fetchall()
- for row in results:
- self.schedule_id.append(row[0])
- self.schedule_time.append(row[2])
- self.schedule_price.append(row[1])
- self.hall_id.append(row[4])
- self.schedule_movie.append(row[5])
-
-
- except:
- print("Error: unable to fetch data")
- messagebox.showinfo('警告!', '数据库连接失败!')
-
- con.close() # 关闭数据库连接
- print("test***********************")
- for i in range(min(len(self.schedule_id), len(self.schedule_movie), len(self.hall_id), len(self.schedule_time), len(self.schedule_price))): # 写入数据
- self.tree.insert('', i, values=(
- self.schedule_id[i], self.schedule_movie[i], self.hall_id[i], self.schedule_time[i], self.schedule_price[i]))
- for col in self.columns: # 绑定函数,使表头可排序
- self.tree.heading(col, text=col, command=lambda _col=col: self.tree_sort_column(self.tree, _col, False))
-
- #下方
- self.var_schedule_id = StringVar() # 声明订票编号
- self.var_movie_mane = StringVar() # 声明游客账号
- self.var_hall_id = StringVar() # 声明身份证号
- self.var_schedule_time = StringVar() # 声明联系电话
- self.var_schedule_price = StringVar() # 声明订票数量
-
- # 定义下方区域,查询功能块
- self.chaxun = StringVar()
- self.right_bottom_gender_entry = Entry(self.frame_bottom, textvariable=self.chaxun, font=('Verdana', 15))
- self.right_bottom_button = ttk.Button(self.frame_bottom, text='查询电影', width=20, command=self.put_data)
- self.right_bottom_button.grid(row=0, column=0, padx=20, pady=20) # 位置设置
- self.right_bottom_gender_entry.grid(row=0, column=1)
-
- # 整体区域定位,利用了Frame和grid进行布局
- self.frame_center.grid(row=0, column=0, columnspan=2, padx=4, pady=5)
- self.frame_bottom.grid(row=1, column=0, columnspan=2)
-
- # 设置固定组件,(0)就是将组件进行了固定
- self.frame_center.grid_propagate(0)
- self.frame_bottom.grid_propagate(0)
-
- # 开始显示主菜单
- self.frame_center.tkraise() # 开始显示主菜单
- self.frame_bottom.tkraise() # 开始显示主菜单
-
- self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击,执行back方法
- self.window.mainloop() # 进入消息循环
-
-
- def put_data(self):
- self.delButton()
- print(self.chaxun.get()) # 输入框内的内容
- # 打开数据库连接,准备查找指定的信息
- # 再次进行初始化,进行首行数据的插入
-
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy', charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- # sql = "use EMIS exec proc_cha '%s'" % (self.chaxun.get())
- sql = "SELECT * FROM table_schedule WHERE schedule_movie = '%s' " % (self.chaxun.get())
- try:
- # 执行SQL语句2
- cursor.execute(sql)
- # 获取所有记录列表
- results = cursor.fetchall()
-
-
- self.schedule_id = [] # 订票编号
- self.schedule_movie = [] # 游客账号
- self.hall_id = [] # 身份证号
- self.schedule_time = [] # 联系电话
- self.schedule_price = [] # 订票数量
-
- for row in results:
- self.schedule_id.append(row[0])
- self.schedule_time.append(row[2])
- self.schedule_price.append(row[1])
- self.hall_id.append(row[4])
- self.schedule_movie.append(row[5])
-
- except:
- print("Error: unable to fetch data")
- messagebox.showinfo('警告!', '数据库连接失败!')
- con.close() # 关闭数据库连接
-
- print("进行数据的插入")
-
- for i in range(min(len(self.schedule_id), len(self.schedule_movie), len(self.hall_id), len(self.schedule_time), len(self.schedule_price))): # 写入数据
- self.tree.insert('', i, values=(
- self.schedule_id[i], self.schedule_movie[i], self.hall_id[i], self.schedule_time[i], self.schedule_price[i]))
- for col in self.columns: # 绑定函数,使表头可排序
- self.tree.heading(col, text=col, command=lambda _col=col: self.tree_sort_column(self.tree, _col, False))
-
- def delButton(self):
- x = self.tree.get_children()
- for item in x:
- self.tree.delete(item)
-
- def tree_sort_column(self, tv, col, reverse): # Treeview、列名、排列方式
- l = [(tv.set(k, col), k) for k in tv.get_children('')]
- l.sort(reverse=reverse) # 排序方式
- for index, (val, k) in enumerate(l): # 根据排序后索引移动
- tv.move(k, '', index)
- tv.heading(col, command=lambda: self.tree_sort_column(tv, col, not reverse)) # 重写标题,使之成为再点倒序的标题
-
- def back(self):
- userindex(self.window)
-
- class Buy:
- def __init__(self, parent_window):
- parent_window.destroy() # 销毁主界面
- self.window = tk.Tk() # 初始框的声明
- self.window.title('购票')
- self.window.geometry('600x700') # 这里的乘是小x
- self.window.geometry('+330+0')
- label = tk.Label(self.window, text='购票', bg='green', font=('Verdana', 20), width=40, height=3)
- label.pack()
- Label(self.window, text='取票号:', font=tkFont.Font(size=15)).pack(pady=25)
- self.userbuy_id = tk.Entry(self.window, width=30, font=tkFont.Font(size=15), bg='Ivory')
- self.userbuy_id.pack()
- Label(self.window, text='用户编号:', font=tkFont.Font(size=15)).pack(pady=25)
- self.user_id = tk.Entry(self.window, width=30, font=tkFont.Font(size=15), bg='Ivory')
- self.user_id.pack()
- Label(self.window, text='排片编号:', font=tkFont.Font(size=15)).pack(pady=25)
- self.schedule_id = tk.Entry(self.window, width=30, font=tkFont.Font(size=15), bg='Ivory')
- self.schedule_id.pack()
- Label(self.window, text='座位号:', font=tkFont.Font(size=15)).pack(pady=25)
- self.seat_id = tk.Entry(self.window, width=30, font=tkFont.Font(size=15), bg='Ivory')
- self.seat_id.pack()
-
- Button(self.window, text="购买", width=10, font=tkFont.Font(size=15), command=self.login).pack(pady=40)
- Button(self.window, text="返回", width=10, font=tkFont.Font(size=15), command=self.back).pack()
-
- self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击
- self.window.mainloop() # 进入消息循环
-
- def login(self):
- print(str(self.schedule_id.get()))
- print(str(self.seat_id.get()))
- tou_pass = None
- # 数据库操作 查询管理员表
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8') # 打开数据库连接
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "SELECT hall_id FROM table_schedule WHERE schedule_id = '%s'" % (self.schedule_id.get()) # SQL 查询语句
- try:
- # 执行SQL语句
- cursor.execute(sql)
-
- # 获取所有记录列表
- results = cursor.fetchall()
- print(results)
- for row in results:
- self.hall_id = row[0]
-
- # 打印结果
- print("tou_id=%s" % (self.hall_id))
- except:
- print("Error: unable to fecth data")
- messagebox.showinfo('警告!', '用户名!')
- con.close() # 关闭数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8') # 打开数据库连接
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql1 = "SELECT hall_sets FROM table_hall WHERE hall_id = '%s'" % (self.hall_id)
- try:
- # 执行SQL语句
- cursor.execute(sql1)
- # 获取所有记录列表
- results = cursor.fetchall()
-
- for row in results:
- hall_seats = row[0]
- print(hall_seats)
-
- except:
- print("Error: unable to fecth data")
- messagebox.showinfo('警告!')
- con.close() # 关闭数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8') # 打开数据库连接
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql1 = "INSERT INTO table_userbuy(userbuy_id,schedule_id,user_id,set_id) \
- VALUES ('%s', '%s', '%s', '%s')" % \
- (self.userbuy_id.get(), self.schedule_id.get(), self.user_id.get(), self.seat_id.get()) # SQL 插入语句
- try:
- cursor.execute(sql1) # 执行sql语句
- print("yes")
- con.commit() # 提交到数据库执行
- except:
- con.rollback() # 发生错误时回滚
- messagebox.showinfo('警告!', '数据库连接失败!')
- con.close() # 关闭数据库连接
- # 购买结果
- if float(self.seat_id.get())<float(hall_seats):
-
- messagebox.showinfo('购买成功!')
- else:
- messagebox.showinfo('没有该座位号!')
-
- def back(self):
- userindex(self.window) # 显示主窗口 销毁本窗口
-
- class Look:
- def __init__(self, parent_window):
- parent_window.destroy() # 自动销毁上一个界面
- self.window = Tk() # 初始框的声明
- self.window.title('查看订单界面')
- self.window.geometry("600x600+300+0") # 初始窗口在屏幕中的位置
-
- self.frame_center = tk.Frame(width=600, height=400)
- self.frame_bottom = tk.Frame(width=650, height=70)
-
- self.columns = ( "电影名字", "放映厅", "放映时间", "价格","座位号")
- self.tree = ttk.Treeview(self.frame_center, show="headings", height=30, columns=self.columns)
- # 添加竖直滚动条
- self.vbar = ttk.Scrollbar(self.frame_center, orient=VERTICAL, command=self.tree.yview)
- # 定义树形结构与滚动条
- self.tree.configure(yscrollcommand=self.vbar.set)
- self.vbar.config(command=self.tree.yview())
-
- # 定义id1为修改id时的暂存变量,这个是为了更新信息而设计的
- self.id1 = 0
- # 表示列,不显示
- self.tree.column("电影名字", width=120, anchor='center')
- self.tree.column("放映厅", width=120, anchor='center')
- self.tree.column("放映时间", width=120, anchor='center')
- self.tree.column("价格", width=120, anchor='center')
- self.tree.column("座位号", width=120, anchor='center')
- # grid方法将tree和vbar进行布局
- self.tree.grid(row=0, column=0, sticky=NSEW)
- self.vbar.grid(row=0, column=1, sticky=NS)
-
- #下方
-
- self.var_movie_mane = StringVar() # 声明游客账号
- self.var_hall_id = StringVar() # 声明身份证号
- self.var_schedule_time = StringVar() # 声明联系电话
- self.var_schedule_price = StringVar() # 声明订票数量
- self.var_set_id=StringVar()
-
- # 定义下方区域,查询功能块
- self.chaxun = StringVar()
- self.right_bottom_gender_entry = Entry(self.frame_bottom, textvariable=self.chaxun, font=('Verdana', 15))
- self.right_bottom_button = ttk.Button(self.frame_bottom, text='查询订单', width=20, command=self.put_data)
- self.right_bottom_button.grid(row=0, column=0, padx=20, pady=20) # 位置设置
- self.right_bottom_gender_entry.grid(row=0, column=1)
-
- # 整体区域定位,利用了Frame和grid进行布局
- self.frame_center.grid(row=0, column=0, columnspan=2, padx=4, pady=5)
- self.frame_bottom.grid(row=1, column=0, columnspan=2)
-
- # 设置固定组件,(0)就是将组件进行了固定
- self.frame_center.grid_propagate(0)
- self.frame_bottom.grid_propagate(0)
-
- # 开始显示主菜单
- self.frame_center.tkraise() # 开始显示主菜单
- self.frame_bottom.tkraise() # 开始显示主菜单
- self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击,执行back方法
- self.window.mainloop() # 进入消息循环
-
- def put_data(self):
- self.delButton()
- print(self.chaxun.get()) # 输入框内的内容
- # 打开数据库连接,准备查找指定的信息
- # 再次进行初始化,进行首行数据的插入
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy', charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- # sql = "use EMIS exec proc_cha '%s'" % (self.chaxun.get())
- sql = "SELECT * FROM table_userbuy WHERE user_id = '%s' " % (self.chaxun.get())
- try:
- # 执行SQL语句2
- cursor.execute(sql)
- # 获取所有记录列表
- results = cursor.fetchall()
- self.set_id = []
- for r in results:
- self.schedule_id=r[1]
- self.set_id.append(r[3])
-
- print(self.schedule_id)
- print(self.set_id)
-
- except:
- print("Error: unable to fetch data")
- messagebox.showinfo('警告!', '数据库连接失败!')
- con.close() # 关闭数据库连接
-
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy', charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- # sql = "use EMIS exec proc_cha '%s'" % (self.chaxun.get())
- sql1 = "SELECT * FROM table_schedule WHERE schedule_id = '%s' " % (self.schedule_id)
- try:
- # 执行SQL语句2
- cursor.execute(sql1)
- # 获取所有记录列表
- results = cursor.fetchall()
- self.schedule_movie = [] # 游客账号
- self.hall_id = [] # 身份证号
- self.schedule_time = [] # 联系电话
- self.schedule_price = [] # 订票数量
-
- for row in results:
- self.schedule_time.append(row[2])
- self.schedule_price.append(row[1])
- self.hall_id.append(row[4])
- self.schedule_movie.append(row[5])
-
- except:
- print("Error: unable to fetch data")
- messagebox.showinfo('警告!', '数据库连接失败!')
- con.close() # 关闭数据库连接
-
-
- print("进行数据的插入")
-
- for i in range(min(len(self.schedule_movie), len(self.hall_id), len(self.schedule_time), len(self.schedule_price),len(self.set_id))): # 写入数据
- self.tree.insert('', i, values=(
- self.schedule_movie[i], self.hall_id[i], self.schedule_time[i], self.schedule_price[i],self.set_id[i]))
- for col in self.columns: # 绑定函数,使表头可排序
- self.tree.heading(col, text=col, command=lambda _col=col: self.tree_sort_column(self.tree, _col, False))
-
- def delButton(self):
- x = self.tree.get_children()
- for item in x:
- self.tree.delete(item)
-
- def tree_sort_column(self, tv, col, reverse): # Treeview、列名、排列方式
- l = [(tv.set(k, col), k) for k in tv.get_children('')]
- l.sort(reverse=reverse) # 排序方式
- for index, (val, k) in enumerate(l): # 根据排序后索引移动
- tv.move(k, '', index)
- tv.heading(col, command=lambda: self.tree_sort_column(tv, col, not reverse)) # 重写标题,使之成为再点倒序的标题
-
- def back(self):
- userindex(self.window)
-
- class UserSign:
- def __init__(self, parent_window):
- parent_window.destroy() # 销毁主界面
-
- self.window = tk.Tk() # 初始框的声明
- self.window.title('用户注册页面')
- self.window.geometry('600x600') # 这里的乘是小x
- self.window.geometry('+330+0')
-
- self.admin_userid = [] # 账号
- self.admin_pass = [] # 密码
- self.admin_name = [] # 姓名
- self.admin_birth = [] # sr
- self.admin_phone = [] # 电话
-
- # 打开数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy', charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "SELECT * FROM 用户信息" # SQL 查询语句
- try:
- # 执行SQL语句
- cursor.execute(sql)
- # 获取所有记录列表
- results = cursor.fetchall()
- for row in results:
- self.admin_userid.append(row[0])
- self.admin_pass.append(row[4])
- self.admin_name.append(row[1])
- self.admin_birth.append(row[3])
- self.admin_phone.append(row[2])
-
- except:
- print("Error: unable to fetch data")
- messagebox.showinfo('警告!', '数据库连接失败!')
- con.close() # 关闭数据库连接
-
- self.var_userid = StringVar() # 声明管理员账号
- self.var_pass = StringVar() # 声明管理员密码
- self.var_name = StringVar() # 声明管理员姓名
- self.var_birth = StringVar() # 声明管理员sr
- self.var_phone = StringVar() # 声明管理员电话
-
- label = tk.Label(self.window, text='用户注册', bg='green', font=('Verdana', 30), width=40, height=3)
- label.pack()
-
- Label(self.window, text='账号:', font=tkFont.Font(size=15)).pack(pady=10, anchor='w')
- self.var_userid = tk.Entry(self.window, width=40, font=tkFont.Font(size=20), bg='Ivory')
- self.var_userid.pack(anchor='nw')
-
- Label(self.window, text='密码:', font=tkFont.Font(size=15)).pack(pady=10, anchor='w')
- self.var_pass = tk.Entry(self.window, width=40, font=tkFont.Font(size=20), bg='Ivory', show='*')
- self.var_pass.pack(anchor='nw')
-
- Label(self.window, text='姓名:', font=tkFont.Font(size=15)).pack(pady=10, anchor='w')
- self.var_name = tk.Entry(self.window, width=40, font=tkFont.Font(size=20), bg='Ivory')
- self.var_name.pack(anchor='nw')
-
- Label(self.window, text='生日:', font=tkFont.Font(size=15)).pack(pady=10, anchor='w')
- self.var_birth = tk.Entry(self.window, width=40, font=tkFont.Font(size=20), bg='Ivory')
- self.var_birth.pack(anchor='nw')
-
- Label(self.window, text='联系电话:', font=tkFont.Font(size=15)).pack(pady=10, anchor='w')
- self.var_phone = tk.Entry(self.window, width=40, font=tkFont.Font(size=20), bg='Ivory')
- self.var_phone.pack(anchor='nw')
-
- Button(self.window, text="注册", width=20, font=tkFont.Font(size=15), command=self.new_row).pack(pady=20)
- Button(self.window, text="返回首页", width=20, font=tkFont.Font(size=15), command=self.back).pack(pady=20)
-
- self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击
- self.window.mainloop() # 进入消息循环
-
- def new_row(self):
-
- # 从界面获取的数据
- print(self.var_userid.get())
- print(self.admin_userid)
-
- if str(self.var_userid.get()) in self.admin_userid:
- messagebox.showinfo('警告!', '该用户已存在!')
- elif (len(str(self.var_phone.get())) > 15) or (len(str(self.var_phone.get())) < 7):
- messagebox.showinfo('警告!', '请输入正确的电话号码!')
- else:
- if self.var_userid.get() != '' and self.var_pass.get() != '' and self.var_name.get() != '' and self.var_birth.get() != '' and self.var_phone.get() != '':
- # 打开数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "INSERT INTO 用户信息(用户账号,用户密码,用户名,生日,手机号码) \
- VALUES ('%s', '%s', '%s', '%s', '%s')" % \
- (self.var_userid.get(), self.var_pass.get(), self.var_name.get(), self.var_birth.get(),
- self.var_phone.get()) # SQL 插入语句
- try:
- cursor.execute(sql) # 执行sql语句
- con.commit() # 提交到数据库执行
- except:
- con.rollback() # 发生错误时回滚
- messagebox.showinfo('警告!', '数据库连接失败!')
- con.close() # 关闭数据库连接
-
- self.admin_userid.append(self.var_userid.get())
- self.admin_pass.append(self.var_pass.get())
- self.admin_name.append(self.var_name.get())
- self.admin_birth.append(self.var_birth.get())
- self.admin_phone.append(self.var_phone.get())
-
- messagebox.showinfo('提示!', '注册成功!')
- else:
- messagebox.showinfo('警告!', '请填写正确的信息')
-
- def back(self):
- beginpage(self.window) # 显示主窗口 销毁本窗口
-
- class lookmovie:
- def __init__(self, parent_window):
- parent_window.destroy() # 销毁主界面
-
- self.window = Tk() # 初始框的声明
- self.window.title('管理员操作界面')
-
- self.frame_left_top = tk.Frame(width=300, height=200)
- self.frame_right_top = tk.Frame(width=200, height=200)
- self.frame_center = tk.Frame(width=500, height=400)
- self.frame_bottom = tk.Frame(width=650, height=50)
-
- # 定义下方中心列表区域
- self.columns = ("电影编号", "电影名字", "主演", "导演","简介")
- self.tree = ttk.Treeview(self.frame_center, show="headings", height=18, columns=self.columns)
- self.vbar = ttk.Scrollbar(self.frame_center, orient=VERTICAL, command=self.tree.yview)
- # 定义树形结构与滚动条
- self.tree.configure(yscrollcommand=self.vbar.set)
-
- # 表格的标题
- self.tree.column("电影编号", width=100, anchor='center') # 表示列,不显示
- self.tree.column("电影名字", width=100, anchor='center')
- self.tree.column("主演", width=100, anchor='center')
- self.tree.column("导演", width=100, anchor='center')
- self.tree.column("简介", width=100, anchor='center')
-
- # 调用方法获取表格内容插入
- self.tree.grid(row=0, column=0, sticky=NSEW)
- self.vbar.grid(row=0, column=1, sticky=NS)
-
- self.id = []
- self.name = []
- self.zhuyan = []
- self.daoyan = []
- self.jianjie=[]
- # 打开数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "SELECT * FROM table_movie" # SQL 查询语句
- try:
- # 执行SQL语句
- cursor.execute(sql)
- # 获取所有记录列表
- results = cursor.fetchall()
- for row in results:
- self.id.append(row[0])
- self.name.append(row[1])
- self.zhuyan.append(row[2])
- self.daoyan.append(row[3])
- self.jianjie.append(row[4])
- except:
- print("Error: unable to fetch data")
- messagebox.showinfo('警告!', '数据库连接失败!')
- con.close() # 关闭数据库连接
-
- print("test***********************")
- for i in range(min(len(self.id), len(self.name), len(self.zhuyan), len(self.daoyan),len(self.jianjie))): # 写入数据
- self.tree.insert('', i, values=(self.id[i], self.name[i], self.zhuyan[i], self.daoyan[i],self.jianjie[i]))
-
- for col in self.columns: # 绑定函数,使表头可排序
- self.tree.heading(col, text=col,
- command=lambda _col=col: self.tree_sort_column(self.tree, _col, False))
-
- # 定义顶部区域
- # 定义左上方区域
- self.top_title = Label(self.frame_left_top, text="电影信息:", font=('Verdana', 20))
- self.top_title.grid(row=0, column=0, columnspan=2, sticky=NSEW, padx=50, pady=0)
-
- self.left_top_frame = tk.Frame(self.frame_left_top)
- self.var_id = StringVar() # 声明dy号
- self.var_name = StringVar() # 声明dy名
- self.var_zhuyan = StringVar() # 声明zy
- self.var_daoyan = StringVar() # 声明dyan
- self.var_jianjie=StringVar()
- # dy号
- self.right_top_id_label = Label(self.frame_left_top, text="电影编号:", font=('Verdana', 15))
- self.right_top_id_entry = Entry(self.frame_left_top, textvariable=self.var_id, font=('Verdana', 15))
- self.right_top_id_label.grid(row=1, column=0) # 位置设置
- self.right_top_id_entry.grid(row=1, column=1)
- # 姓名
- self.right_top_name_label = Label(self.frame_left_top, text="电影名字:", font=('Verdana', 15))
- self.right_top_name_entry = Entry(self.frame_left_top, textvariable=self.var_name, font=('Verdana', 15))
- self.right_top_name_label.grid(row=2, column=0) # 位置设置
- self.right_top_name_entry.grid(row=2, column=1)
- # 性别
- self.right_top_gender_label = Label(self.frame_left_top, text="主演:", font=('Verdana', 15))
- self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_zhuyan,
- font=('Verdana', 15))
- self.right_top_gender_label.grid(row=3, column=0) # 位置设置
- self.right_top_gender_entry.grid(row=3, column=1)
- # 年龄
- self.right_top_gender_label = Label(self.frame_left_top, text="导演:", font=('Verdana', 15))
- self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_daoyan,
- font=('Verdana', 15))
- self.right_top_gender_label.grid(row=4, column=0) # 位置设置
- self.right_top_gender_entry.grid(row=4, column=1)
- # 年龄
- self.right_top_gender_label = Label(self.frame_left_top, text="简介:", font=('Verdana', 15))
- self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_jianjie,
- font=('Verdana', 15))
- self.right_top_gender_label.grid(row=5, column=0) # 位置设置
- self.right_top_gender_entry.grid(row=5, column=1)
-
- # 定义右上方区域
- self.right_top_title = Label(self.frame_right_top, text="操作:", font=('Verdana', 20))
-
- self.tree.bind('<Button-1>', self.click) # 左键获取位置
- self.right_top_button1 = ttk.Button(self.frame_right_top, text='新建电影信息', width=20, command=self.new_row)
- self.right_top_button2 = ttk.Button(self.frame_right_top, text='更新选中电影信息', width=20,
- command=self.updata_row)
- self.right_top_button3 = ttk.Button(self.frame_right_top, text='删除选中电影信息', width=20,
- command=self.del_row)
-
- # 位置设置
- self.right_top_title.grid(row=1, column=0, pady=10)
- self.right_top_button1.grid(row=2, column=0, padx=20, pady=10)
- self.right_top_button2.grid(row=3, column=0, padx=20, pady=10)
- self.right_top_button3.grid(row=4, column=0, padx=20, pady=10)
-
- # 整体区域定位
- self.frame_left_top.grid(row=0, column=0, padx=2, pady=5)
- self.frame_right_top.grid(row=0, column=1, padx=30, pady=30)
- self.frame_center.grid(row=1, column=0, columnspan=2, padx=4, pady=5)
- self.frame_bottom.grid(row=2, column=0, columnspan=2)
-
- self.frame_left_top.grid_propagate(0)
- self.frame_right_top.grid_propagate(0)
- self.frame_center.grid_propagate(0)
- self.frame_bottom.grid_propagate(0)
-
- self.frame_left_top.tkraise() # 开始显示主菜单
- self.frame_right_top.tkraise() # 开始显示主菜单
- self.frame_center.tkraise() # 开始显示主菜单
- self.frame_bottom.tkraise() # 开始显示主菜单
-
- self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击
- self.window.mainloop() # 进入消息循环
-
- def back(self):
- adminMessage(self.window) # 显示主窗口 销毁本窗口
-
- def click(self, event):
- self.col = self.tree.identify_column(event.x) # 列
- self.row = self.tree.identify_row(event.y) # 行
-
- print(self.col)
- print(self.row)
- self.row_info = self.tree.item(self.row, "values")
- self.var_id.set(self.row_info[0])
- self.var_name.set(self.row_info[1])
- self.var_zhuyan.set(self.row_info[2])
- self.var_daoyan.set(self.row_info[3])
- self.var_jianjie.set(self.row_info[4])
- self.right_top_id_entry = Entry(self.frame_left_top, state='disabled', textvariable=self.var_id,
- font=('Verdana', 15))
-
- print('')
-
- def tree_sort_column(self, tv, col, reverse): # Treeview、列名、排列方式
- l = [(tv.set(k, col), k) for k in tv.get_children('')]
- l.sort(reverse=reverse) # 排序方式
- # rearrange items in sorted positions
- for index, (val, k) in enumerate(l): # 根据排序后索引移动
- tv.move(k, '', index)
- tv.heading(col, command=lambda: self.tree_sort_column(tv, col, not reverse)) # 重写标题,使之成为再点倒序的标题
-
- def new_row(self):
- print('123')
- print(self.var_id.get())
- print(self.id)
- if str(self.var_id.get()) in self.id:
- messagebox.showinfo('警告!', '该电影已存在!')
- else:
- if self.var_id.get() != '' and self.var_name.get() != '' and self.var_zhuyan.get() != '' and self.var_daoyan.get() != ''and self.var_jianjie.get() !='':
- # 打开数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "INSERT INTO table_movie(movie_id, movie_name, movie_zhuyan, movie_daoyan,movie_jianjie) \
- VALUES ('%s', '%s', '%s', '%s','%s')" % \
- (self.var_id.get(), self.var_name.get(), self.var_zhuyan.get(), self.var_daoyan.get(),self.var_jianjie.get()) # SQL 插入语句
- try:
- cursor.execute(sql) # 执行sql语句
- con.commit() # 提交到数据库执行
- except:
- con.rollback() # 发生错误时回滚
- messagebox.showinfo('警告!', '数据库连接失败!')
- con.close() # 关闭数据库连接
-
- self.id.append(self.var_id.get())
- self.name.append(self.var_name.get())
- self.zhuyan.append(self.var_zhuyan.get())
- self.daoyan.append(self.var_daoyan.get())
- self.jianjie.append(self.var_jianjie.get())
- self.tree.insert('', len(self.id) - 1, values=(
- self.id[len(self.id) - 1], self.name[len(self.id) - 1], self.zhuyan[len(self.id) - 1],
- self.daoyan[len(self.id) - 1],self.jianjie[len(self.id)-1]))
- self.tree.update()
- messagebox.showinfo('提示!', '插入成功!')
- else:
- messagebox.showinfo('警告!', '请填写订单数据')
-
- def updata_row(self):
- res = messagebox.askyesnocancel('警告!', '是否更新所填数据?')
- if res == True:
- if self.var_id.get() == self.row_info[0]: # 如果所填学号 与 所选学号一致
- # 打开数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "UPDATE table_movie SET movie_name = '%s', movie_zhuyan = '%s', movie_daoyan = '%s',moive_jianjie ='%s' \
- WHERE movie_id = '%s'" % (
- self.var_name.get(), self.var_zhuyan.get(), self.var_daoyan.get(), self.var_jianjie.get(),self.var_id.get()) # SQL 插入语句
- try:
- cursor.execute(sql) # 执行sql语句
- con.commit() # 提交到数据库执行
- messagebox.showinfo('提示!', '更新成功!')
- except:
- con.rollback() # 发生错误时回滚
-
- con.close() # 关闭数据库连接
-
- id_index = self.id.index(self.row_info[0])
- self.name[id_index] = self.var_name.get()
- self.zhuyan[id_index] = self.var_zhuyan.get()
- self.daoyan[id_index] = self.var_daoyan.get()
- self.jianjie[id_index]=self.var_jianjie.get()
-
- self.tree.item(self.tree.selection()[0], values=(
- self.var_id.get(), self.var_name.get(), self.var_zhuyan.get(),
- self.var_daoyan.get(),self.var_jianjie.get())) # 修改对于行信息
- else:
- messagebox.showinfo('警告!', '不能修改订单号!')
-
- def del_row(self):
- res = messagebox.askyesnocancel('警告!', '是否删除所选数据?')
- if res == True:
- print(self.row_info[0]) # 鼠标选中的学号
- print(self.tree.selection()[0]) # 行号
- print(self.tree.get_children()) # 所有行
- # 打开数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "DELETE FROM table_movie WHERE movie_id = '%s'" % (self.row_info[0]) # SQL 插入语句
- try:
- cursor.execute(sql) # 执行sql语句
- con.commit() # 提交到数据库执行
- messagebox.showinfo('提示!', '删除成功!')
- except:
- con.rollback() # 发生错误时回滚
- messagebox.showinfo('警告!', '删除失败,数据库连接失败!')
- con.close() # 关闭数据库连接
-
- id_index = self.id.index(self.row_info[0])
- print(id_index)
- del self.id[id_index]
- del self.name[id_index]
- del self.zhuyan[id_index]
- del self.daoyan[id_index]
- del self.jianjie[id_index]
- print(self.id)
- self.tree.delete(self.tree.selection()[0]) # 删除所选行
- print(self.tree.get_children())
-
- class adlook:
- def __init__(self, parent_window):
- parent_window.destroy() # 销毁主界面
-
- self.window = Tk() # 初始框的声明
- self.window.title('管理员操作界面')
-
- self.frame_left_top = tk.Frame(width=300, height=200)
- self.frame_right_top = tk.Frame(width=200, height=200)
- self.frame_center = tk.Frame(width=500, height=400)
- self.frame_bottom = tk.Frame(width=650, height=50)
-
- # 定义下方中心列表区域
- self.columns = ("订单号", "排片编号", "用户账号", "座位号")
- self.tree = ttk.Treeview(self.frame_center, show="headings", height=18, columns=self.columns)
- self.vbar = ttk.Scrollbar(self.frame_center, orient=VERTICAL, command=self.tree.yview)
- # 定义树形结构与滚动条
- self.tree.configure(yscrollcommand=self.vbar.set)
-
- # 表格的标题
- self.tree.column("订单号", width=150, anchor='center') # 表示列,不显示
- self.tree.column("排片编号", width=150, anchor='center')
- self.tree.column("用户账号", width=100, anchor='center')
- self.tree.column("座位号", width=100, anchor='center')
-
- # 调用方法获取表格内容插入
- self.tree.grid(row=0, column=0, sticky=NSEW)
- self.vbar.grid(row=0, column=1, sticky=NS)
-
- self.id = []
- self.name = []
- self.gender = []
- self.age = []
- # 打开数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "SELECT * FROM table_userbuy" # SQL 查询语句
- try:
- # 执行SQL语句
- cursor.execute(sql)
- # 获取所有记录列表
- results = cursor.fetchall()
- for row in results:
- self.id.append(row[0])
- self.name.append(row[1])
- self.gender.append(row[2])
- self.age.append(row[3])
- # print(self.id)
- # print(self.name)
- # print(self.gender)
- # print(self.age)
- except:
- print("Error: unable to fetch data")
- messagebox.showinfo('警告!', '数据库连接失败!')
- con.close() # 关闭数据库连接
-
- print("test***********************")
- for i in range(min(len(self.id), len(self.name), len(self.gender), len(self.age))): # 写入数据
- self.tree.insert('', i, values=(self.id[i], self.name[i], self.gender[i], self.age[i]))
-
- for col in self.columns: # 绑定函数,使表头可排序
- self.tree.heading(col, text=col,
- command=lambda _col=col: self.tree_sort_column(self.tree, _col, False))
-
- # 定义顶部区域
- # 定义左上方区域
- self.top_title = Label(self.frame_left_top, text="订单信息:", font=('Verdana', 20))
- self.top_title.grid(row=0, column=0, columnspan=2, sticky=NSEW, padx=50, pady=10)
-
- self.left_top_frame = tk.Frame(self.frame_left_top)
- self.var_id = StringVar() # 声明学号
- self.var_name = StringVar() # 声明姓名
- self.var_gender = StringVar() # 声明性别
- self.var_age = StringVar() # 声明年龄
- # 学号
- self.right_top_id_label = Label(self.frame_left_top, text="订单号:", font=('Verdana', 15))
- self.right_top_id_entry = Entry(self.frame_left_top, textvariable=self.var_id, font=('Verdana', 15))
- self.right_top_id_label.grid(row=1, column=0) # 位置设置
- self.right_top_id_entry.grid(row=1, column=1)
- # 姓名
- self.right_top_name_label = Label(self.frame_left_top, text="排片编号:", font=('Verdana', 15))
- self.right_top_name_entry = Entry(self.frame_left_top, textvariable=self.var_name, font=('Verdana', 15))
- self.right_top_name_label.grid(row=2, column=0) # 位置设置
- self.right_top_name_entry.grid(row=2, column=1)
- # 性别
- self.right_top_gender_label = Label(self.frame_left_top, text="用户账号:", font=('Verdana', 15))
- self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_gender,
- font=('Verdana', 15))
- self.right_top_gender_label.grid(row=3, column=0) # 位置设置
- self.right_top_gender_entry.grid(row=3, column=1)
- # 年龄
- self.right_top_gender_label = Label(self.frame_left_top, text="座位号:", font=('Verdana', 15))
- self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_age,
- font=('Verdana', 15))
- self.right_top_gender_label.grid(row=4, column=0) # 位置设置
- self.right_top_gender_entry.grid(row=4, column=1)
-
- # 定义右上方区域
- self.right_top_title = Label(self.frame_right_top, text="操作:", font=('Verdana', 20))
-
- self.tree.bind('<Button-1>', self.click) # 左键获取位置
- self.right_top_button1 = ttk.Button(self.frame_right_top, text='新建电影信息', width=20, command=self.new_row)
- self.right_top_button2 = ttk.Button(self.frame_right_top, text='更新选中电影信息', width=20,
- command=self.updata_row)
- self.right_top_button3 = ttk.Button(self.frame_right_top, text='删除选中电影信息', width=20,
- command=self.del_row)
-
- # 位置设置
- self.right_top_title.grid(row=1, column=0, pady=10)
- self.right_top_button1.grid(row=2, column=0, padx=20, pady=10)
- self.right_top_button2.grid(row=3, column=0, padx=20, pady=10)
- self.right_top_button3.grid(row=4, column=0, padx=20, pady=10)
-
- # 整体区域定位
- self.frame_left_top.grid(row=0, column=0, padx=2, pady=5)
- self.frame_right_top.grid(row=0, column=1, padx=30, pady=30)
- self.frame_center.grid(row=1, column=0, columnspan=2, padx=4, pady=5)
- self.frame_bottom.grid(row=2, column=0, columnspan=2)
-
- self.frame_left_top.grid_propagate(0)
- self.frame_right_top.grid_propagate(0)
- self.frame_center.grid_propagate(0)
- self.frame_bottom.grid_propagate(0)
-
- self.frame_left_top.tkraise() # 开始显示主菜单
- self.frame_right_top.tkraise() # 开始显示主菜单
- self.frame_center.tkraise() # 开始显示主菜单
- self.frame_bottom.tkraise() # 开始显示主菜单
-
- self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击
- self.window.mainloop() # 进入消息循环
-
- def back(self):
- adminMessage(self.window) # 显示主窗口 销毁本窗口
-
- def click(self, event):
- self.col = self.tree.identify_column(event.x) # 列
- self.row = self.tree.identify_row(event.y) # 行
-
- print(self.col)
- print(self.row)
- self.row_info = self.tree.item(self.row, "values")
- self.var_id.set(self.row_info[0])
- self.var_name.set(self.row_info[1])
- self.var_gender.set(self.row_info[2])
- self.var_age.set(self.row_info[3])
- self.right_top_id_entry = Entry(self.frame_left_top, state='disabled', textvariable=self.var_id,
- font=('Verdana', 15))
-
- print('')
-
- def tree_sort_column(self, tv, col, reverse): # Treeview、列名、排列方式
- l = [(tv.set(k, col), k) for k in tv.get_children('')]
- l.sort(reverse=reverse) # 排序方式
- # rearrange items in sorted positions
- for index, (val, k) in enumerate(l): # 根据排序后索引移动
- tv.move(k, '', index)
- tv.heading(col, command=lambda: self.tree_sort_column(tv, col, not reverse)) # 重写标题,使之成为再点倒序的标题
-
- def new_row(self):
- print('123')
- print(self.var_id.get())
- print(self.id)
- if str(self.var_id.get()) in self.id:
- messagebox.showinfo('警告!', '该订单已存在!')
- else:
- if self.var_id.get() != '' and self.var_name.get() != '' and self.var_gender.get() != '' and self.var_age.get() != '':
- # 打开数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "INSERT INTO table_userbuy(userbuy_id, schedule_id, user_id, set_id) \
- VALUES ('%s', '%s', '%s', '%s')" % \
- (self.var_id.get(), self.var_name.get(), self.var_gender.get(), self.var_age.get()) # SQL 插入语句
- try:
- cursor.execute(sql) # 执行sql语句
- con.commit() # 提交到数据库执行
- except:
- con.rollback() # 发生错误时回滚
- messagebox.showinfo('警告!', '数据库连接失败!')
- con.close() # 关闭数据库连接
-
- self.id.append(self.var_id.get())
- self.name.append(self.var_name.get())
- self.gender.append(self.var_gender.get())
- self.age.append(self.var_age.get())
- self.tree.insert('', len(self.id) - 1, values=(
- self.id[len(self.id) - 1], self.name[len(self.id) - 1], self.gender[len(self.id) - 1],
- self.age[len(self.id) - 1]))
- self.tree.update()
- messagebox.showinfo('提示!', '插入成功!')
- else:
- messagebox.showinfo('警告!', '请填写订单数据')
-
- def updata_row(self):
- res = messagebox.askyesnocancel('警告!', '是否更新所填数据?')
- if res == True:
- if self.var_id.get() == self.row_info[0]: # 如果所填学号 与 所选学号一致
- # 打开数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "UPDATE table_userbuy SET schedule_id = '%s', user_id = '%s', set_id = '%s' \
- WHERE userbuy_id = '%s'" % (
- self.var_name.get(), self.var_gender.get(), self.var_age.get(), self.var_id.get()) # SQL 插入语句
- try:
- cursor.execute(sql) # 执行sql语句
- con.commit() # 提交到数据库执行
- messagebox.showinfo('提示!', '更新成功!')
- except:
- con.rollback() # 发生错误时回滚
- messagebox.showinfo('警告!', '更新失败,数据库连接失败!')
- con.close() # 关闭数据库连接
-
- id_index = self.id.index(self.row_info[0])
- self.name[id_index] = self.var_name.get()
- self.gender[id_index] = self.var_gender.get()
- self.age[id_index] = self.var_age.get()
-
- self.tree.item(self.tree.selection()[0], values=(
- self.var_id.get(), self.var_name.get(), self.var_gender.get(),
- self.var_age.get())) # 修改对于行信息
- else:
- messagebox.showinfo('警告!', '不能修改订单号!')
-
- def del_row(self):
- res = messagebox.askyesnocancel('警告!', '是否删除所选数据?')
- if res == True:
- print(self.row_info[0]) # 鼠标选中的学号
- print(self.tree.selection()[0]) # 行号
- print(self.tree.get_children()) # 所有行
- # 打开数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "DELETE FROM table_userbuy WHERE userbuy_id = '%s'" % (self.row_info[0]) # SQL 插入语句
- try:
- cursor.execute(sql) # 执行sql语句
- con.commit() # 提交到数据库执行
- messagebox.showinfo('提示!', '删除成功!')
- except:
- con.rollback() # 发生错误时回滚
- messagebox.showinfo('警告!', '删除失败,数据库连接失败!')
- con.close() # 关闭数据库连接
-
- id_index = self.id.index(self.row_info[0])
- print(id_index)
- del self.id[id_index]
- del self.name[id_index]
- del self.gender[id_index]
- del self.age[id_index]
- print(self.id)
- self.tree.delete(self.tree.selection()[0]) # 删除所选行
- print(self.tree.get_children())
-
- class adpai:
- def __init__(self, parent_window):
- parent_window.destroy() # 销毁主界面
-
- self.window = Tk() # 初始框的声明
- self.window.title('排片操作界面')
-
- self.frame_left_top = tk.Frame(width=300, height=200)
- self.frame_right_top = tk.Frame(width=200, height=200)
- self.frame_center = tk.Frame(width=500, height=400)
- self.frame_bottom = tk.Frame(width=650, height=50)
-
- # 定义下方中心列表区域
- self.columns = ("排片编号", "电影名字", "价格", "时间","放映厅")
- self.tree = ttk.Treeview(self.frame_center, show="headings", height=18, columns=self.columns)
- self.vbar = ttk.Scrollbar(self.frame_center, orient=VERTICAL, command=self.tree.yview)
- # 定义树形结构与滚动条
- self.tree.configure(yscrollcommand=self.vbar.set)
-
- # 表格的标题
- self.tree.column("排片编号", width=100, anchor='center') # 表示列,不显示
- self.tree.column("电影名字", width=100, anchor='center')
- self.tree.column("价格", width=100, anchor='center')
- self.tree.column("时间", width=100, anchor='center')
- self.tree.column("放映厅", width=100, anchor='center')
-
- # 调用方法获取表格内容插入
- self.tree.grid(row=0, column=0, sticky=NSEW)
- self.vbar.grid(row=0, column=1, sticky=NS)
-
- self.id = []
- self.name = []
- self.zhuyan = []
- self.daoyan = []
- self.jianjie=[]
- # 打开数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "SELECT * FROM table_schedule" # SQL 查询语句
- try:
- # 执行SQL语句
- cursor.execute(sql)
- # 获取所有记录列表
- results = cursor.fetchall()
- for row in results:
- self.id.append(row[0])
- self.name.append(row[5])
- self.zhuyan.append(row[1])
- self.daoyan.append(row[2])
- self.jianjie.append(row[4])
- except:
- print("Error: unable to fetch data")
- messagebox.showinfo('警告!', '数据库连接失败!')
- con.close() # 关闭数据库连接
-
- print("test***********************")
- for i in range(min(len(self.id), len(self.name), len(self.zhuyan), len(self.daoyan),len(self.jianjie))): # 写入数据
- self.tree.insert('', i, values=(self.id[i], self.name[i], self.zhuyan[i], self.daoyan[i],self.jianjie[i]))
-
- for col in self.columns: # 绑定函数,使表头可排序
- self.tree.heading(col, text=col,
- command=lambda _col=col: self.tree_sort_column(self.tree, _col, False))
-
- # 定义顶部区域
- # 定义左上方区域
- self.top_title = Label(self.frame_left_top, text="排片信息:", font=('Verdana', 20))
- self.top_title.grid(row=0, column=0, columnspan=2, sticky=NSEW, padx=50, pady=0)
-
- self.left_top_frame = tk.Frame(self.frame_left_top)
- self.var_id = StringVar() # 声明dy号
- self.var_name = StringVar() # 声明dy名
- self.var_zhuyan = StringVar() # 声明zy
- self.var_daoyan = StringVar() # 声明dyan
- self.var_jianjie=StringVar()
- # dy号
- self.right_top_id_label = Label(self.frame_left_top, text="排片编号:", font=('Verdana', 15))
- self.right_top_id_entry = Entry(self.frame_left_top, textvariable=self.var_id, font=('Verdana', 15))
- self.right_top_id_label.grid(row=1, column=0) # 位置设置
- self.right_top_id_entry.grid(row=1, column=1)
- # 姓名
- self.right_top_name_label = Label(self.frame_left_top, text="电影名字:", font=('Verdana', 15))
- self.right_top_name_entry = Entry(self.frame_left_top, textvariable=self.var_name, font=('Verdana', 15))
- self.right_top_name_label.grid(row=2, column=0) # 位置设置
- self.right_top_name_entry.grid(row=2, column=1)
- # 性别
- self.right_top_gender_label = Label(self.frame_left_top, text="价格:", font=('Verdana', 15))
- self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_zhuyan,
- font=('Verdana', 15))
- self.right_top_gender_label.grid(row=3, column=0) # 位置设置
- self.right_top_gender_entry.grid(row=3, column=1)
- # 年龄
- self.right_top_gender_label = Label(self.frame_left_top, text="时间:", font=('Verdana', 15))
- self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_daoyan,
- font=('Verdana', 15))
- self.right_top_gender_label.grid(row=4, column=0) # 位置设置
- self.right_top_gender_entry.grid(row=4, column=1)
- # 年龄
- self.right_top_gender_label = Label(self.frame_left_top, text="放映厅:", font=('Verdana', 15))
- self.right_top_gender_entry = Entry(self.frame_left_top, textvariable=self.var_jianjie,
- font=('Verdana', 15))
- self.right_top_gender_label.grid(row=5, column=0) # 位置设置
- self.right_top_gender_entry.grid(row=5, column=1)
-
- # 定义右上方区域
- self.right_top_title = Label(self.frame_right_top, text="操作:", font=('Verdana', 20))
-
- self.tree.bind('<Button-1>', self.click) # 左键获取位置
- self.right_top_button1 = ttk.Button(self.frame_right_top, text='新建排片信息', width=20, command=self.new_row)
- self.right_top_button2 = ttk.Button(self.frame_right_top, text='更新选中排片信息', width=20,
- command=self.updata_row)
- self.right_top_button3 = ttk.Button(self.frame_right_top, text='删除选中排片信息', width=20,
- command=self.del_row)
-
- # 位置设置
- self.right_top_title.grid(row=1, column=0, pady=10)
- self.right_top_button1.grid(row=2, column=0, padx=20, pady=10)
- self.right_top_button2.grid(row=3, column=0, padx=20, pady=10)
- self.right_top_button3.grid(row=4, column=0, padx=20, pady=10)
-
- # 整体区域定位
- self.frame_left_top.grid(row=0, column=0, padx=2, pady=5)
- self.frame_right_top.grid(row=0, column=1, padx=30, pady=30)
- self.frame_center.grid(row=1, column=0, columnspan=2, padx=4, pady=5)
- self.frame_bottom.grid(row=2, column=0, columnspan=2)
-
- self.frame_left_top.grid_propagate(0)
- self.frame_right_top.grid_propagate(0)
- self.frame_center.grid_propagate(0)
- self.frame_bottom.grid_propagate(0)
-
- self.frame_left_top.tkraise() # 开始显示主菜单
- self.frame_right_top.tkraise() # 开始显示主菜单
- self.frame_center.tkraise() # 开始显示主菜单
- self.frame_bottom.tkraise() # 开始显示主菜单
-
- self.window.protocol("WM_DELETE_WINDOW", self.back) # 捕捉右上角关闭点击
- self.window.mainloop() # 进入消息循环
-
- def back(self):
- adminMessage(self.window) # 显示主窗口 销毁本窗口
-
- def click(self, event):
- self.col = self.tree.identify_column(event.x) # 列
- self.row = self.tree.identify_row(event.y) # 行
-
- print(self.col)
- print(self.row)
- self.row_info = self.tree.item(self.row, "values")
- self.var_id.set(self.row_info[0])
- self.var_name.set(self.row_info[1])
- self.var_zhuyan.set(self.row_info[2])
- self.var_daoyan.set(self.row_info[3])
- self.var_jianjie.set(self.row_info[4])
- self.right_top_id_entry = Entry(self.frame_left_top, state='disabled', textvariable=self.var_id,
- font=('Verdana', 15))
-
- print('')
-
- def tree_sort_column(self, tv, col, reverse): # Treeview、列名、排列方式
- l = [(tv.set(k, col), k) for k in tv.get_children('')]
- l.sort(reverse=reverse) # 排序方式
- # rearrange items in sorted positions
- for index, (val, k) in enumerate(l): # 根据排序后索引移动
- tv.move(k, '', index)
- tv.heading(col, command=lambda: self.tree_sort_column(tv, col, not reverse)) # 重写标题,使之成为再点倒序的标题
-
- def new_row(self):
- print('123')
- print(self.var_id.get())
- print(self.id)
- if str(self.var_id.get()) in self.id:
- messagebox.showinfo('警告!', '该电影已存在!')
- else:
- if self.var_id.get() != '' and self.var_name.get() != '' and self.var_zhuyan.get() != '' and self.var_daoyan.get() != ''and self.var_jianjie.get() !='':
- # 打开数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "SELECT * FROM table_movie WHERE movie_name = '%s'" % (self.var_name.get()) # SQL 查询语句
- try:
- # 执行SQL语句
- cursor.execute(sql)
- # 获取所有记录列表
- results = cursor.fetchall()
- for row in results:
- self.movie_id=row[0]
- print(self.movie_id)
- except:
- print("Error: unable to fetch data")
- messagebox.showinfo('警告!', '数据库连接失败!')
- con.close() # 关闭数据库连接
-
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql1 = "INSERT INTO table_schedule(schedule_id, schedule_price,schedule_time,movie_id,hall_id,schedule_movie) \
- VALUES ('%s', '%s', '%s', '%s','%s','%s')" % \
- (self.var_id.get(), self.var_daoyan.get(), self.var_zhuyan.get(),self.movie_id,self.var_jianjie.get(),self.var_name.get()) # SQL 插入语句
- try:
- cursor.execute(sql1) # 执行sql语句
- con.commit() # 提交到数据库执行
- except:
- con.rollback() # 发生错误时回滚
- messagebox.showinfo('警告!', '数据库连接失败!')
- con.close() # 关闭数据库连接
-
- self.id.append(self.var_id.get())
- self.name.append(self.var_name.get())
- self.zhuyan.append(self.var_zhuyan.get())
- self.daoyan.append(self.var_daoyan.get())
- self.jianjie.append(self.var_jianjie.get())
- self.tree.insert('', len(self.id) - 1, values=(
- self.id[len(self.id) - 1], self.name[len(self.id) - 1], self.zhuyan[len(self.id) - 1],
- self.daoyan[len(self.id) - 1],self.jianjie[len(self.id)-1]))
- self.tree.update()
- messagebox.showinfo('提示!', '插入成功!')
- else:
- messagebox.showinfo('警告!', '请填写排片数据')
-
- def updata_row(self):
- res = messagebox.askyesnocancel('警告!', '是否更新所填数据?')
- if res == True:
- if self.var_id.get() == self.row_info[0]: # 如果所填学号 与 所选学号一致
- # 打开数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "UPDATE table_schedule SET schedule_price = '%s', schedule_time = '%s', movie_id = '%s',hall_id ='%s',schedule_movie ='%s' \
- WHERE movie_id = '%s'" % (
- self.var_daoyan.get(), self.var_zhuyan.get(), self.movie_id, self.var_jianjie.get(),self.var_name.get(),self.var_id.get()) # SQL 插入语句
- try:
- cursor.execute(sql) # 执行sql语句
- con.commit() # 提交到数据库执行
- messagebox.showinfo('提示!', '更新成功!')
- except:
- con.rollback() # 发生错误时回滚
- messagebox.showinfo('警告!', '更新失败,数据库连接失败!')
- con.close() # 关闭数据库连接
-
- id_index = self.id.index(self.row_info[0])
- self.name[id_index] = self.var_name.get()
- self.zhuyan[id_index] = self.var_zhuyan.get()
- self.daoyan[id_index] = self.var_daoyan.get()
- self.jianjie[id_index]=self.var_jianjie.get()
-
- self.tree.item(self.tree.selection()[0], values=(
- self.var_id.get(), self.var_name.get(), self.var_zhuyan.get(),
- self.var_daoyan.get(),self.var_jianjie.get())) # 修改对于行信息
- else:
- messagebox.showinfo('警告!', '不能修改订单号!')
-
- def del_row(self):
- res = messagebox.askyesnocancel('警告!', '是否删除所选数据?')
- if res == True:
- print(self.row_info[0]) # 鼠标选中的学号
- print(self.tree.selection()[0]) # 行号
- print(self.tree.get_children()) # 所有行
- # 打开数据库连接
- con = pymysql.connect(host='localhost', port=3306, user='root', passwd='112233', db='dyy',
- charset='utf8')
- cursor = con.cursor() # 使用cursor()方法获取操作游标
- sql = "DELETE FROM table_schedule WHERE schedule_id = '%s'" % (self.row_info[0]) # SQL 插入语句
- try:
- cursor.execute(sql) # 执行sql语句
- con.commit() # 提交到数据库执行
- messagebox.showinfo('提示!', '删除成功!')
- except:
- con.rollback() # 发生错误时回滚
- messagebox.showinfo('警告!', '删除失败,数据库连接失败!')
- con.close() # 关闭数据库连接
-
- id_index = self.id.index(self.row_info[0])
- print(id_index)
- del self.id[id_index]
- del self.name[id_index]
- del self.zhuyan[id_index]
- del self.daoyan[id_index]
- del self.jianjie[id_index]
- del self.movie_id[id_index]
- print(self.id)
- self.tree.delete(self.tree.selection()[0]) # 删除所选行
- print(self.tree.get_children())
-
-
-
-
- win = tk.Tk()
- beginpage(win)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。