diff --git a/filesys/__pycache__/login.cpython-39.pyc b/filesys/__pycache__/login.cpython-39.pyc index 9661be5..cb69b1d 100644 Binary files a/filesys/__pycache__/login.cpython-39.pyc and b/filesys/__pycache__/login.cpython-39.pyc differ diff --git a/filesys/__pycache__/login_next.cpython-39.pyc b/filesys/__pycache__/login_next.cpython-39.pyc index aaec583..39b021a 100644 Binary files a/filesys/__pycache__/login_next.cpython-39.pyc and b/filesys/__pycache__/login_next.cpython-39.pyc differ diff --git a/filesys/__pycache__/main.cpython-39.pyc b/filesys/__pycache__/main.cpython-39.pyc index a9376db..4eb024f 100644 Binary files a/filesys/__pycache__/main.cpython-39.pyc and b/filesys/__pycache__/main.cpython-39.pyc differ diff --git a/filesys/__pycache__/register.cpython-39.pyc b/filesys/__pycache__/register.cpython-39.pyc index ef465f9..8abbff2 100644 Binary files a/filesys/__pycache__/register.cpython-39.pyc and b/filesys/__pycache__/register.cpython-39.pyc differ diff --git a/filesys/__pycache__/sql.cpython-39.pyc b/filesys/__pycache__/sql.cpython-39.pyc index 54489aa..c89a76d 100644 Binary files a/filesys/__pycache__/sql.cpython-39.pyc and b/filesys/__pycache__/sql.cpython-39.pyc differ diff --git a/filesys/login.py b/filesys/login.py index c5b78a6..a89a651 100644 --- a/filesys/login.py +++ b/filesys/login.py @@ -1,7 +1,7 @@ -import tkinter as tk from login_next import * +import main def login_1(): - + global new_window new_window = tk.Tk() new_window.title("欢迎来到登陆成功后的界面") new_window.geometry("300x200") @@ -14,12 +14,14 @@ def login_1(): root.pack() # 创建按钮 + view_image_button = tk.Button(root, text="查看图片信息", command=view_all_images_info) upload_image_button = tk.Button(root, text="上传图片", command=upload_image) download_button = tk.Button(root, text="下载图片", command=download_image) delete_button = tk.Button(root, text="删除图片", command=delete_image) - exit_button = tk.Button(root, text="返回", command=new_window.destroy) + exit_button = tk.Button(root, text="返回", command=login_return_main) # 布局 + view_image_button.pack() upload_image_button.pack() download_button.pack() delete_button.pack() @@ -27,6 +29,9 @@ def login_1(): new_window.mainloop() +def login_return_main(): + new_window.destroy() + main.main() if __name__ == "__main__": login_1() diff --git a/filesys/login_next.py b/filesys/login_next.py index 75308f6..1b83817 100644 --- a/filesys/login_next.py +++ b/filesys/login_next.py @@ -1,6 +1,6 @@ import pymysql.cursors import tkinter as tk -from tkinter import filedialog +from tkinter import filedialog,messagebox import os # 数据库连接参数 @@ -45,42 +45,37 @@ def upload_image(): sql = "INSERT INTO images (filename, content) VALUES (%s, %s)" cursor.execute(sql, (os.path.basename(selected_image_path), pymysql.Binary(image_content))) connection.commit() - print(f"Image '{selected_image_path}' uploaded successfully.") + messagebox.showinfo("上传成功", f"图片路径: '{selected_image_path}' 上传成功.") + except Exception as e: + messagebox.showerror("上传错误", f"图片上传失败: {e}") finally: connection.close() def delete_image(): + view_all_images_info() # 获取用户输入的图像ID image_id = tk.simpledialog.askinteger("删除图片", "请输入需要删除的图像ID:") if image_id is not None: connection = pymysql.connect(host=DB_HOST, user=DB_USER, password=DB_PASSWORD, db=DB_NAME) try: with connection.cursor() as cursor: - # 查询图像信息 - cursor.execute("SELECT * FROM images WHERE id = %s", (image_id,)) - image_data = cursor.fetchone() - if image_data: - # 输出图像信息 - print(f"Image Details:") - for index, value in enumerate(image_data): - column_name = cursor.description[index][0] - print(f"{column_name}: {value}") - # 提示用户确认删除 - confirmation = tk.messagebox.askyesno("Confirm Delete", f"是否删除图片ID为 {image_id}的图片?") - if confirmation: - # 执行删除操作 - sql = "DELETE FROM images WHERE id = %s" - cursor.execute(sql, (image_id,)) - connection.commit() - print(f"成功删除图片ID为 {image_id} 的图片.") + # 直接执行删除操作 + cursor.execute("DELETE FROM images WHERE id = %s", (image_id,)) + connection.commit() + + # 提示用户确认删除 + confirmation = tk.messagebox.askyesno("Confirm Delete", f"是否删除图片ID为 {image_id}的图片?") + if confirmation: + messagebox.showinfo("删除成功", f"成功删除图片ID为 {image_id} 的图片.") else: - print(f"没有发现图片ID为 {image_id}的图片.") + messagebox.showinfo("操作取消", "图片删除操作已取消。") except Exception as e: - print(f"Error deleting image: {e}") + messagebox.showerror("删除错误", f"图片删除失败: {e}") finally: connection.close() def download_image(): + view_all_images_info() # 获取用户输入的图像ID image_id = tk.simpledialog.askinteger("下载图片", "请输入需要下载的图像ID:") if image_id is not None: @@ -100,18 +95,37 @@ def download_image(): try: with open(save_path, 'wb') as image_file: image_file.write(content) - print(f"Image downloaded successfully to '{save_path}'.") + messagebox.showinfo("成功", f"图片已成功下载到 '{save_path}'。") except IOError as e: - print(f"Error writing to file: {e}") + messagebox.showerror("错误", f"写入文件时出错: {e}") else: - print("Download cancelled.") + messagebox.showinfo("取消", "下载已取消。") else: - print(f"No image found with ID {image_id}.") + messagebox.showinfo("未找到", f"未找到ID为 {image_id} 的图片。") except Exception as e: - print(f"Error downloading image: {e}") + messagebox.showerror("下载错误", f"下载图片时发生错误: {e}") finally: connection.close() +def view_all_images_info(): + connection = pymysql.connect(host=DB_HOST, user=DB_USER, password=DB_PASSWORD, db=DB_NAME) + try: + with connection.cursor() as cursor: + # 查询所有图片信息 + cursor.execute("SELECT id, filename FROM images") + image_data = cursor.fetchall() + if image_data: + # 构建信息消息 + message = "全部图片信息:\n\n" + for row in image_data: + message += f"Image ID: {row[0]}\nImage Name: {row[1]}\n---\n" + messagebox.showinfo("所有图片信息", message) + else: + messagebox.showinfo("未找到图片", "数据库中没有图片信息。") + except Exception as e: + messagebox.showerror("查询错误", f"Error fetching image info: {e}") + finally: + connection.close() diff --git a/filesys/main.py b/filesys/main.py index d8de539..264f882 100644 --- a/filesys/main.py +++ b/filesys/main.py @@ -1,6 +1,5 @@ from register import * from login import * -import os def main(): global root @@ -46,10 +45,11 @@ def register_jc(): root.destroy() register() - def login_jc(): root.destroy() login_1() + + if __name__ == "__main__": main() diff --git a/filesys/register.py b/filesys/register.py index 50c38c5..4be04a8 100644 --- a/filesys/register.py +++ b/filesys/register.py @@ -1,5 +1,6 @@ import tkinter as tk from sql import * +import main def register(): global register_view @@ -21,7 +22,7 @@ def register(): register_button = tk.Button(register_view, text="注册", command=register_0) register_button.pack() - back_button = tk.Button(register_view, text="返回", command=register_view.destroy) + back_button = tk.Button(register_view, text="返回", command=register_return_main) back_button.pack() register_view.mainloop() @@ -37,5 +38,9 @@ def register_0(): ok_label = tk.Label(register_view, text="注册成功") ok_label.pack() +def register_return_main(): + register_view.destroy() + main.main() + if __name__ == "__main__": register() \ No newline at end of file diff --git a/filesys/sql.py b/filesys/sql.py index 6b4745a..1d45333 100644 --- a/filesys/sql.py +++ b/filesys/sql.py @@ -1,7 +1,5 @@ from flask import * from flask_sqlalchemy import SQLAlchemy -import pymysql -import os app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:123456@localhost:3306/file' @@ -24,12 +22,11 @@ def add_user(username, password): db.session.commit() + try: with app.app_context(): - # 尝试连接数据库 db.create_all() - print("数据库连接成功!") except Exception as e: print(f"数据库连接失败: {str(e)}") diff --git a/filesys/图片/null22d2cf8d1fc4906f.jpg b/filesys/图片/null22d2cf8d1fc4906f1.jpg similarity index 100% rename from filesys/图片/null22d2cf8d1fc4906f.jpg rename to filesys/图片/null22d2cf8d1fc4906f1.jpg