diff --git a/Python程序设计课程设计报告模板 2024年.doc b/Python程序设计课程设计报告模板 2024年.doc new file mode 100644 index 0000000..b8b8fe7 Binary files /dev/null and b/Python程序设计课程设计报告模板 2024年.doc differ diff --git a/filesys/.idea/.gitignore b/filesys/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/filesys/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/filesys/.idea/dataSources.xml b/filesys/.idea/dataSources.xml new file mode 100644 index 0000000..8fb0a57 --- /dev/null +++ b/filesys/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://localhost:3306 + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/filesys/.idea/filesys.iml b/filesys/.idea/filesys.iml new file mode 100644 index 0000000..2c80e12 --- /dev/null +++ b/filesys/.idea/filesys.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/filesys/.idea/inspectionProfiles/profiles_settings.xml b/filesys/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..c60c33b --- /dev/null +++ b/filesys/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/filesys/.idea/misc.xml b/filesys/.idea/misc.xml new file mode 100644 index 0000000..30004b5 --- /dev/null +++ b/filesys/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/filesys/.idea/modules.xml b/filesys/.idea/modules.xml new file mode 100644 index 0000000..f52c685 --- /dev/null +++ b/filesys/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/filesys/__pycache__/main.cpython-39.pyc b/filesys/__pycache__/main.cpython-39.pyc new file mode 100644 index 0000000..c8f1cc0 Binary files /dev/null and b/filesys/__pycache__/main.cpython-39.pyc differ diff --git a/filesys/__pycache__/sql.cpython-39.pyc b/filesys/__pycache__/sql.cpython-39.pyc new file mode 100644 index 0000000..137a236 Binary files /dev/null and b/filesys/__pycache__/sql.cpython-39.pyc differ diff --git a/filesys/file_paths.txt b/filesys/file_paths.txt new file mode 100644 index 0000000..442deee --- /dev/null +++ b/filesys/file_paths.txt @@ -0,0 +1 @@ +C:/Users/Admin/Pictures/Saved Pictures/0f754affcc469c034048cec299bdc149.jpgC:/Users/Admin/Pictures/Saved Pictures/0f754affcc469c034048cec299bdc149.jpg \ No newline at end of file diff --git a/filesys/main.py b/filesys/main.py new file mode 100644 index 0000000..5ebdad9 --- /dev/null +++ b/filesys/main.py @@ -0,0 +1,157 @@ +import tkinter as tk +from sql import * +from tkinter import filedialog +import os + + +def main(): + global root + global username_entry, password_entry + root = tk.Tk() + root.title("欢迎来到登陆界面") + root.geometry("300x200") + + # 用户名和密码输入框 + username_label = tk.Label(root, text="账号:") + username_label.pack() + username_entry = tk.Entry(root) + username_entry.pack() + + password_label = tk.Label(root, text="密码:") + password_label.pack() + password_entry = tk.Entry(root, show="*") + password_entry.pack() + + # 登录按钮 + login_button = tk.Button(root, text="登陆", command=login_0) + login_button.pack() + + register_button = tk.Button(root, text="注册", command=register) + register_button.pack() + + root.mainloop() +def login_0(): + entered_username = username_entry.get() + entered_password = password_entry.get() + + # 这里可以添加用户名和密码的验证逻辑 + if entered_username == query_user(entered_username).username and entered_password == query_user(entered_username).password: + login_1() + else: + erro_label = tk.Label(root, text="账号或密码错误") + erro_label.pack() + +# 显示登陆成功后页面函数 +def login_1(): + root.destroy() # 关闭当前窗口 + + new_window = tk.Tk() + new_window.title("欢迎来到登陆成功后的界面") + new_window.geometry("300x200") + + # 显示登陆成功的消息 + new_label = tk.Label(new_window, text="登陆成功!") + new_label.pack() + + button_frame = tk.Frame(new_window) + button_frame.pack() + + upload_button = tk.Button(button_frame, text="上传文件", command=upload_file) + download_button = tk.Button(button_frame, text="下载文件", command=download_file) + delete_button = tk.Button(button_frame, text="删除文件", command=delete_file) + + # 使用grid()布局管理器在button_frame内 + upload_button.grid(row=4, column=0,padx=10, pady=10) + download_button.grid(row=4, column=3,padx=10, pady=10) + delete_button.grid(row=4, column=6,padx=10, pady=10) + + # 退出按钮 + exit_button = tk.Button(new_window, text="退出", command=new_window.destroy) + exit_button.pack() + + new_window.mainloop() + + +def register(): + root.destroy() # 关闭当前窗口 + + global register_view + global username_entry_1, password_entry_1 + register_view = tk.Tk() + register_view.title("欢迎来到注册界面") + register_view.geometry("300x200") + + username_label = tk.Label(register_view, text="用户名:") + username_label.pack() + username_entry_1 = tk.Entry(register_view) + username_entry_1.pack() + + password_label = tk.Label(register_view, text="密码:") + password_label.pack() + password_entry_1 = tk.Entry(register_view) + password_entry_1.pack() + + register_button = tk.Button(register_view, text="注册", command=register_0) + register_button.pack() + + back_button = tk.Button(register_view, text="返回", command=register_1) + back_button.pack() + + register_view.mainloop() + +def register_0(): + entered_username = username_entry_1.get() + entered_password = password_entry_1.get() + if query_user(entered_username) is not None: + erro_label = tk.Label(register_view, text="用户名已存在") + erro_label.pack() + else: + add_user(entered_username, entered_password) + ok_label = tk.Label(register_view, text="注册成功") + ok_label.pack() + +def register_1(): + register_view.destroy() + main() + +def upload_file(): + global selected_file_path + selected_file_path = filedialog.askopenfilename() + new_window = tk.Tk() + new_window.title("欢迎来到路径界面") + new_window.geometry("600x200") + # 更新界面,显示选定的文件路径 + selected_file_label = tk.Label(new_window, text=f"选定文件: {selected_file_path}") + selected_file_label.pack() + + # 添加保存路径按钮 + save_button = tk.Button(new_window, text="保存路径", command=save_selected_path) + save_button.pack() + + new_window.mainloop() + +def save_selected_path(): + + file_path = "D:/Service/PyCharm 2024.1.1Pr/filesys/file_paths.txt" + + # 检查目录是否存在,如果不存在则创建 + directory = os.path.dirname(file_path) + if not os.path.exists(directory): + os.makedirs(directory) + + if selected_file_path: + with open('file_paths.txt', 'a') as f: + f.write(selected_file_path) + print(f"文件路径已保存到file_paths.txt: {selected_file_path}") + else: + print("没有选择文件") + +def download_file(): + return None + + +def delete_file(): + return None + + +main() diff --git a/filesys/sql.py b/filesys/sql.py new file mode 100644 index 0000000..cb81446 --- /dev/null +++ b/filesys/sql.py @@ -0,0 +1,37 @@ +from flask import * +from flask_sqlalchemy import SQLAlchemy +import pymysql + +app = Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:123456@localhost:3306/file' +db = SQLAlchemy(app) + +class User(db.Model): + _table_ = 'user' + id = db.Column(db.Integer, primary_key=True) + username = db.Column(db.String(50),nullable=False) + password = db.Column(db.String(50),nullable=False) + +def query_user(username): + with app.app_context(): + return User.query.filter(User.username == username).first() + +def add_user(username, password): + with app.app_context(): + user = User(username=username, password=password) + db.session.add(user) + db.session.commit() + +try: + with app.app_context(): + # 尝试连接数据库 + + db.create_all() + print("数据库连接成功!") + +except Exception as e: + print(f"数据库连接失败: {str(e)}") + + + + diff --git a/filesys/test.py b/filesys/test.py new file mode 100644 index 0000000..0b70cdc --- /dev/null +++ b/filesys/test.py @@ -0,0 +1,25 @@ +from flask import Flask, request, render_template +import os + +app = Flask(__name__) + +UPLOAD_FOLDER = 'path_to_your_upload_folder' +app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER + +@app.route('/') +def index(): + return render_template('index.html') + +@app.route('/upload', methods=['POST']) +def upload_file(): + if 'file' not in request.files: + return 'No file part' + file = request.files['file'] + if file.filename == '': + return 'No selected file' + if file: + file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename)) + return 'File uploaded successfully' + +if __name__ == '__main__': + app.run() \ No newline at end of file