wdmtxyh123 6 months ago
parent 50e986eda3
commit 50e6da3b97

@ -103,15 +103,15 @@ class ParkManage:
parked_cars parked_cars
""" """
self.cursor.execute(query) self.cursor.execute(query)
all_cars_info = self.cursor.fetchall() car_info = self.cursor.fetchall()
if all_cars_info: if car_info:
# 遍历所有车辆信息并格式化输出 # 遍历所有车辆信息并格式化输出
all_cars_message = "\n\n".join([ all_cars_message = "\n\n".join([
f"车牌号: {car[0]}\n" f"车牌号: {car[0]}\n"
f"停放时间: {car[1].strftime('%Y-%m-%d %H:%M:%S')}\n" f"停放时间: {car[1].strftime('%Y-%m-%d %H:%M:%S')}\n"
f"取车时间: {'未取车' if car[2] is None else car[2].strftime('%Y-%m-%d %H:%M:%S')}" f"取车时间: {'未取车' if car[2] is None else car[2].strftime('%Y-%m-%d %H:%M:%S')}"
for car in all_cars_info for car in car_info
]) ])
messagebox.showinfo("所有车辆信息", all_cars_message) messagebox.showinfo("所有车辆信息", all_cars_message)
else: else:
@ -119,48 +119,6 @@ class ParkManage:
except Error as e: except Error as e:
messagebox.showerror("显示错误", f"显示所有车辆信息时发生错误: {e}") messagebox.showerror("显示错误", f"显示所有车辆信息时发生错误: {e}")
def edit_car_pickup_time(self, license_plate):
"""编辑车辆的取车时间"""
try:
# 查询指定车牌号的车辆是否存在
check_query = """
SELECT COUNT(*)
FROM parked_cars
WHERE license_plate = %s
"""
self.cursor.execute(check_query, (license_plate,))
car_exists = self.cursor.fetchone()[0]
if car_exists:
# 弹出对话框让用户输入新的取车时间
new_picked_up_time_str = simpledialog.askstring("编辑取车时间",
"请输入新的取车时间YYYY-MM-DD HH:MM:SS:",
initialvalue="2023-04-01 14:00:00")
if new_picked_up_time_str:
try:
# 尝试将输入的字符串转换为datetime对象
from datetime import datetime
new_picked_up_time = datetime.strptime(new_picked_up_time_str, '%Y-%m-%d %H:%M:%S')
except ValueError:
messagebox.showerror("输入错误", "请输入正确的日期时间格式!")
return
# 更新数据库中的取车时间
update_query = """
UPDATE parked_cars
SET picked_up_time = %s
WHERE license_plate = %s
"""
self.cursor.execute(update_query, (new_picked_up_time, license_plate))
self.connection.commit() # 提交事务
messagebox.showinfo("更新成功", f"车牌号为{license_plate}的车辆取车时间已更新。")
else:
messagebox.showinfo("取消操作", "未输入取车时间,操作已取消。")
else:
messagebox.showinfo("查询结果", "未找到该车牌号的车辆信息。")
except Error as e:
messagebox.showerror("编辑错误", f"编辑车辆取车时间时发生错误: {e}")
def count_parked_cars(self): def count_parked_cars(self):
"""统计当前停在停车场的车辆总数""" """统计当前停在停车场的车辆总数"""

@ -0,0 +1,30 @@
class User:
def __init__(self, username, password, role='user'):
"""
初始化用户对象
:param username: 用户名
:param password: 密码注意在实际应用中不应明文存储此处仅为示例
:param role: 用户角色'user'默认'admin'
"""
self.username = username
self.password = password # 实际应用中应加密存储
self.role = role
def __str__(self):
"""返回用户的字符串表示"""
return f"用户名: {self.username}, 角色: {self.role}"
def change_password(self, new_password):
"""
更改用户密码
:param new_password: 新密码
"""
self.password = new_password # 实际应用中应处理密码加密逻辑
def promote_to_admin(self):
"""提升用户为管理员角色"""
self.role = 'admin'
def demote_to_user(self):
"""降级用户为普通用户角色"""
self.role = 'user'

@ -73,14 +73,11 @@ def on_inquire_click():
# 假设query_car_info返回车辆信息的字典展示相关信息 # 假设query_car_info返回车辆信息的字典展示相关信息
message = ( message = (
f"车牌号: {car_info['license_plate']}\n" f"车牌号: {car_info['license_plate']}\n"
f"车型: {car_info['model']}\n"
f"颜色: {car_info['color']}\n"
f"停放时间: {car_info['parked_time'].strftime('%Y-%m-%d %H:%M:%S')}\n" f"停放时间: {car_info['parked_time'].strftime('%Y-%m-%d %H:%M:%S')}\n"
f"取车时间: {car_info['picked_up_time'].strftime('%Y-%m-%d %H:%M:%S') if car_info['picked_up_time'] else '未取车'}" f"取车时间: {car_info['picked_up_time'].strftime('%Y-%m-%d %H:%M:%S') if car_info['picked_up_time'] else '未取车'}"
) )
messagebox.showinfo("车辆信息", message)
else:
messagebox.showerror("查询结果", "未找到该车牌号的车辆信息。")
except Exception as e: except Exception as e:
messagebox.showerror("查询错误", f"查询过程中发生错误: {e}") messagebox.showerror("查询错误", f"查询过程中发生错误: {e}")
else: else:
@ -89,42 +86,19 @@ def on_display_info_click():
try: try:
# 调用ParkManage类中的方法来获取所有车辆信息 # 调用ParkManage类中的方法来获取所有车辆信息
car_info = park.display_all_cars_info() car_info= park.display_all_cars_info()
if cars_info: if car_info:
# 假设cars_info是一个包含车辆信息的列表每个元素是车辆的字典表示 # 假设cars_info是一个包含车辆信息的列表每个元素是车辆的字典表示
info_text = "\n".join( info_text = "\n".join(
[f"车牌号: {car['license_plate']}, 停放时间: {car['parked_time'].strftime('%Y-%m-%d %H:%M:%S')}" [f"车牌号: {car['license_plate']}, 停放时间: {car['parked_time'].strftime('%Y-%m-%d %H:%M:%S')}"
f"{', 取车时间: ' + car['picked_up_time'].strftime('%Y-%m-%d %H:%M:%S') if car['picked_up_time'] else ''}" f"{', 取车时间: ' + car['picked_up_time'].strftime('%Y-%m-%d %H:%M:%S') if car['picked_up_time'] else ''}"
for car in cars_info]) for car in car_info])
messagebox.showinfo("车辆信息", info_text)
else:
messagebox.showinfo("信息提示", "当前没有车辆信息可显示。")
except Exception as e: except Exception as e:
messagebox.showerror("错误", f"显示车辆信息时发生错误: {e}") messagebox.showerror("错误", f"显示车辆信息时发生错误: {e}")
def on_edit_info_click():
# 从界面获取车牌号、车型和颜色
license_plate = license_plate_entry.get().strip()
new_model = model_entry.get().strip()
new_color = color_entry.get().strip()
if not license_plate:
messagebox.showerror("错误", "请输入车牌号进行编辑!")
return
try:
# 假设ParkManage类有一个edit_car_info方法用于更新车辆信息
success = park_manage_instance.edit_car_info(license_plate, new_model=new_model, new_color=new_color)
if success:
messagebox.showinfo("成功", "车辆信息已成功更新。")
else:
messagebox.showinfo("失败", "未能找到或更新车辆信息,请检查车牌号是否正确。")
except Exception as e:
messagebox.showerror("错误", f"编辑车辆信息时发生错误: {e}")
def on_statistics_click(): def on_statistics_click():
@ -163,7 +137,7 @@ def on_exit_click():
def refresh_ui(): def refresh_ui():
"""根据当前模式刷新界面""" # 在此函数中移除与编辑车辆信息按钮相关的代码
for widget in window.winfo_children(): for widget in window.winfo_children():
widget.destroy() widget.destroy()
@ -176,9 +150,9 @@ def refresh_ui():
] ]
if isAdmin: if isAdmin:
# 从这里移除了与编辑车辆信息相关的按钮
additional_buttons = [ additional_buttons = [
("显示车辆信息", on_display_info_click), ("显示车辆信息", on_display_info_click),
("编辑车辆信息", on_edit_info_click),
("统计信息", on_statistics_click), ("统计信息", on_statistics_click),
("切换至用户模式", on_switch_mode), ("切换至用户模式", on_switch_mode),
] ]
@ -191,7 +165,6 @@ def refresh_ui():
for idx, (text, cmd) in enumerate(buttons): for idx, (text, cmd) in enumerate(buttons):
tk.Button(window, text=text, command=cmd).pack(fill=tk.X, pady=5) tk.Button(window, text=text, command=cmd).pack(fill=tk.X, pady=5)
def main_gui(): def main_gui():
global window global window
window = tk.Tk() window = tk.Tk()

Loading…
Cancel
Save