You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

303 lines
12 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import tkinter as tk
from tkinter import messagebox
class FootSpaManagementSystem:
def __init__(self,order_info=""):
self.root = tk.Tk() # 创建主窗口
self.root.title("足浴店管理系统")
self.root.geometry("500x300")
self.user_data_file = "user_data.txt" # 用户数据文件路径
self.order_data_file = "order_data.txt" # 订单数据文件路径
self.order_num = 1000 # 初始化订单号
self.order_info = order_info
self.create_main_window() # 创建主界面
#初始界面
def create_main_window(self):
self.main_frame = tk.Frame(self.root)
self.main_frame.pack()
self.welcome_label = tk.Label(self.main_frame, text="欢迎使用足浴店管理系统")
self.welcome_label.pack()
self.register_button_main = tk.Button(self.main_frame, text="注册", command=self.switch_to_register)
self.register_button_main.pack()
self.login_button_main = tk.Button(self.main_frame, text="登录", command=self.switch_to_login)
self.login_button_main.pack()
#用户注册函数
def register_user(self):
username = self.username_entry.get()
password = self.password_entry.get()
if username and password:
with open(self.user_data_file, "a") as file:
file.write(f"{username},{password}\n")
messagebox.showinfo("注册成功", "用户注册成功!") # 显示注册成功信息
else:
messagebox.showerror("注册失败", "请输入用户名和密码。") # 显示注册失败信息
#用户登录函数
def login_user(self):
username = self.username_entry_login.get()
password = self.password_entry_login.get()
with open(self.user_data_file, "r") as file:
user_data = file.readlines()
if user_data:
for user in user_data:
stored_data = user.strip().split(",")
if len(stored_data) == 2:
stored_username, stored_password = stored_data
if username == stored_username and password == stored_password:
messagebox.showinfo("登录成功", f"欢迎回来,{username}") # 显示登录成功消息
self.show_user_interface() # 在成功登录后显示用户界面
return
messagebox.showerror("登录失败", "无效的用户名或密码。") # 显示登录失败消息
else:
messagebox.showerror("登录失败", "没有用户数据。") # 显示找不到用户数据的消息
def surer1(self):
self.frame_register.pack_forget()
self.main_frame.pack()
if hasattr(self, "back_button"):
self.back_button.pack_forget() # 移除返回主界面的按钮
self.frame_register.pack_forget()
self.main_frame.pack()
def surer2(self):
self.frame_order.pack_forget()
self.user_frame.pack()
if hasattr(self, "back_button_order"):
self.back_button_order.pack_forget() # 移除返回主界面的按钮
self.frame_order.pack_forget()
self.user_frame.pack()
def surer3(self):
self.frame_technician.pack_forget()
self.user_frame.pack()
if hasattr(self, "back_button_order"):
self.back_button_order.pack_forget() # 移除返回主界面的按钮
self.frame_technician.pack_forget()
self.user_frame.pack()
def surer4(self):
self.delete_frame.pack_forget()
self.user_frame.pack()
#注册界面
def switch_to_register(self):
self.main_frame.pack_forget()
self.frame_register = tk.Frame(self.root)
self.frame_register.pack()
self.username_label = tk.Label(self.frame_register, text="用户名:")
self.username_label.pack()
self.username_entry = tk.Entry(self.frame_register)
self.username_entry.pack()
self.password_label = tk.Label(self.frame_register, text="密码:")
self.password_label.pack()
self.password_entry = tk.Entry(self.frame_register, show="*")
self.password_entry.pack()
self.register_button = tk.Button(self.frame_register, text="注册", command=self.register_user)
self.register_button.pack()
self.back_button = tk.Button(self.root, text="返回主界面", command=self.surer1)
self.back_button.pack()
#登录界面
def switch_to_login(self):
self.main_frame.pack_forget()
self.frame_login = tk.Frame(self.root)
self.frame_login.pack()
self.username_label_login = tk.Label(self.frame_login, text="用户名:")
self.username_label_login.pack()
self.username_entry_login = tk.Entry(self.frame_login)
self.username_entry_login.pack()
self.password_label_login = tk.Label(self.frame_login, text="密码:")
self.password_label_login.pack()
self.password_entry_login = tk.Entry(self.frame_login, show="*")
self.password_entry_login.pack()
self.login_button = tk.Button(self.frame_login, text="登录", command=self.login_user)
self.login_button.pack()
#用户登录后的用户界面
def show_user_interface(self):
self.main_frame.pack_forget() # 移除主界面
if hasattr(self, "frame_register"):
self.frame_register.pack_forget() # 移除注册界面(如果存在)
if hasattr(self, "frame_login"):
self.frame_login.pack_forget() # 移除登录界面(如果存在)
# 创建用户界面框架
self.user_frame = tk.Frame(self.root)
self.user_frame.pack()
self.order_button = tk.Button(self.user_frame, text="选择订单", command=self.switch_to_order)
self.order_button.pack()
self.view_order_button = tk.Button(self.user_frame, text="查看订单", command=self.view_order)
self.view_order_button.pack()
self.delete_order_button = tk.Button(self.user_frame, text="删除订单", command=self.delete_order)
self.delete_order_button.pack()
#查看订单
def view_order(self):
with open(self.order_data_file, "r") as file:
orders = file.readlines()
if orders:
order_info = "\n".join(orders)
messagebox.showinfo("查看订单", f"您的订单信息:\n{order_info}")
else:
messagebox.showinfo("查看订单", "暂无订单信息。")
#删除界面
def delete_order(self):
self.user_frame.pack_forget() # 移除用户界面
self.delete_frame = tk.Frame(self.root)
self.delete_frame.pack()
self.order_number_label = tk.Label(self.delete_frame, text="请输入订单号:")
self.order_number_label.pack()
self.order_number_entry = tk.Entry(self.delete_frame)
self.order_number_entry.pack()
self.confirm_delete_button = tk.Button(self.delete_frame, text="确认删除", command=self.confirm_delete)
self.confirm_delete_button.pack()
self.back_button_order = tk.Button(self.delete_frame, text="返回用户界面", command=self.surer4)
self.back_button_order.pack()
def confirm_delete(self):
order_number_to_delete = self.order_number_entry.get()
with open(self.order_data_file, "r") as file:
orders = file.readlines()
if orders:
with open(self.order_data_file, "w") as file:
for order in orders:
if order_number_to_delete not in order:
file.write(order)
messagebox.showinfo("删除订单", f"订单号{order_number_to_delete}已删除。")
else:
messagebox.showinfo("删除订单", "暂无订单信息。")
#选择订单界面
def switch_to_order(self):
self.user_frame.pack_forget()
self.frame_order = tk.Frame(self.root)
self.frame_order.pack()
self.order_label = tk.Label(self.frame_order, text="请选择服务:")
self.order_label.pack()
self.services = {
"足浴": tk.IntVar(),
"按摩": tk.IntVar(),
"SPA": tk.IntVar(),
"采耳": tk.IntVar()
}
self.foot_spa_checkbox = tk.Checkbutton(self.frame_order, text="足浴", variable=self.services["足浴"])
self.foot_spa_checkbox.pack()
self.massage_checkbox = tk.Checkbutton(self.frame_order, text="按摩", variable=self.services["按摩"])
self.massage_checkbox.pack()
self.spa_checkbox = tk.Checkbutton(self.frame_order, text="SPA", variable=self.services["SPA"])
self.spa_checkbox.pack()
self.ear_cleaning_checkbox = tk.Checkbutton(self.frame_order, text="采耳",variable=self.services["采耳"])
self.ear_cleaning_checkbox.pack()
self.confirm_order_button = tk.Button(self.frame_order, text="确认订单", command=self.confirm_order)
self.confirm_order_button.pack()
self.back_button_order = tk.Button(self.frame_order, text="返回用户界面", command=self.surer2)
self.back_button_order.pack()
def confirm_order(self):
selected_services = [service for service, selected in self.services.items() if selected.get() == 1]
if selected_services:
order_number = self.generate_order_number() # 生成订单号
messagebox.showinfo("下单成功", f"您选择了:{', '.join(selected_services)}\n 订单号:{order_number}")
# 显示选择技师的界面
self.show_select_technician_screen()
with open(self.order_data_file, "a") as file:
file.write(f"{order_number}, {', '.join(selected_services)}{self.order_info}\n")
else:
messagebox.showerror("下单失败", "请选择至少一项服务。")
def generate_order_number(self):
self.order_num += 1
return f"{self.order_num}" # 以XXXX格式生成订单号
# 选择技师界面
def show_select_technician_screen(self):
self.frame_order.pack_forget() # 移除选择订单界面
# 创建选择技师的界面
self.frame_technician = tk.Frame(self.root)
self.frame_technician.pack()
self.technician_label = tk.Label(self.frame_technician, text="请选择技师:")
self.technician_label.pack()
self.technicians = {
"6号技师": tk.IntVar(),
"8号技师": tk.IntVar(),
"66号技师": tk.IntVar(),
"88号技师": tk.IntVar(),
}
self.john_doe_checkbox = tk.Checkbutton(self.frame_technician, text="6号技师",variable=self.technicians["6号技师"])
self.john_doe_checkbox.pack()
self.jane_smith_checkbox = tk.Checkbutton(self.frame_technician, text="8号技师",variable=self.technicians["8号技师"])
self.jane_smith_checkbox.pack()
self.mike_wilson_checkbox = tk.Checkbutton(self.frame_technician, text="66号技师",variable=self.technicians["66号技师"])
self.mike_wilson_checkbox.pack()
self.mike_wilson_checkbox = tk.Checkbutton(self.frame_technician, text="88号技师",variable=self.technicians["88号技师"])
self.mike_wilson_checkbox.pack()
self.confirm_technician_button = tk.Button(self.frame_technician, text="确认技师",command=self.confirm_technician)
self.confirm_technician_button.pack()
self.back_button_order = tk.Button(self.frame_technician, text="返回用户界面", command=self.surer3)
self.back_button_order.pack()
def confirm_technician(self):
selected_services = [service for service, selected in self.services.items() if selected.get() == 1]
if selected_services:
selected_technicians = [technician for technician, selected in self.technicians.items() if
selected.get() == 1]
selected_services_str = ', '.join(selected_services)
selected_technicians_str = ', '.join(selected_technicians)
messagebox.showinfo("下单成功",
f"您选择了:{selected_services_str}\n所选择的技师: {selected_technicians_str}")
with open(self.order_data_file, "a") as file:
file.write(f"{selected_services_str} - {selected_technicians_str}{self.order_info}\n")
def run(self):
self.root.mainloop() # 启动主循环
# 实例化足浴店管理系统
foot_spa_system = FootSpaManagementSystem()
foot_spa_system.run()