From fe202c017af4d42e49a62eeec1f933bf9ee9ed26 Mon Sep 17 00:00:00 2001 From: zy52306tg <2752629612@qq.com> Date: Tue, 28 May 2024 21:50:51 +0800 Subject: [PATCH] commit_0528 --- filesys/__pycache__/login.cpython-39.pyc | Bin 0 -> 1485 bytes filesys/__pycache__/main.cpython-39.pyc | Bin 2468 -> 2455 bytes filesys/__pycache__/register.cpython-39.pyc | Bin 0 -> 1157 bytes filesys/__pycache__/sql.cpython-39.pyc | Bin 1385 -> 1385 bytes filesys/login.py | 52 ++++++++ filesys/main.py | 125 ++------------------ filesys/register.py | 38 ++++++ filesys/test.py | 82 ++++++++++--- 8 files changed, 160 insertions(+), 137 deletions(-) create mode 100644 filesys/__pycache__/login.cpython-39.pyc create mode 100644 filesys/__pycache__/register.cpython-39.pyc create mode 100644 filesys/login.py create mode 100644 filesys/register.py diff --git a/filesys/__pycache__/login.cpython-39.pyc b/filesys/__pycache__/login.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5131ca0f5ee6771dbfeecbbc0094f1855225e18b GIT binary patch literal 1485 zcmah}OKTiQ5bo}IYIjGH73V=h92s)i%d%2J2quIOg`A8qIJpdhWxU;zXEl$dr#I5V z2z)TM;zY)WBp@3lE0Y`q!Q>PIj`3f}xi2|HD{1dJ<&>(KmAwiCPgB)h)zwwqRbNfu zc@+ZRqdz}i{o5ksFBB#}2Es=`+55ma;WQ#Xg_%VpWMf}Fo@E%HtJ442NpKa5>WOBFhvG*pKOtw3>c^Tl;XrJMA=%gM^O_zB+mGq%DwWUH83GJ?l zG!{zswRJhTCL#?k+OYen3}T_}k9$g`iLUm#Q5x_T0zrE`-AJB`RW2f-M7d|K$&hP@ zi%iM1uiZEZ!8GmG9bHMpMr$KX;Iu!5>j>ldwQEI))+z?{y>XyY>CZe1HCA}zV5O+5 zVlz~&QaB*;O?c=(jZZGETov+*uq{@u^p~y&GM-;-F237XXe?ZjEBJ)0pRE9x!=%ye zYo}PX7BFAgJTSssTA>wVn!2n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{rQ8>&bFMtBRC8~F*P|Ej_z$h{qG^(CUOW1cm0ELgQuMvI$ot!CRrUq}3m=_8W5xd&J8eH{CxLP5{}0{& BK9B$a diff --git a/filesys/__pycache__/register.cpython-39.pyc b/filesys/__pycache__/register.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ed263d7d20a8a56d417fb8877cf2c60590ae8f3f GIT binary patch literal 1157 zcmY*Y&1(}u6rY*h&2G{rmL60Dp$9MVP}15{5fQ65DTP*$QV843w5Hi))7ja6z~&&8 zQlyn0DhOIl3qmW3qK6*)e++n%P3zU8C*RC=V>wkARw!tvM5v-b1x zQ1u}>TqImIMA{Xc zOz?GSJ$C1rC(Wi?sY&ZmL&Y)=LLvNy%yrL}q)k~MxW6u)x?62{zTYfnWFZU~Z@6_< z_7uwOK-Xsqs5~MIO*aTueNNMguAf$1>0UCgZ=LO%ho_Vi=NR#;@Qr^*9*)mVGrm%- zu(_%AiDxda4~>>a$A(9SN2d7PLe*ozdN7wl4L9MPsbc^@Fa!#j4$k2mDPXlb-F*P; zK@hHnbcuApX{1Dx?kN}v=~{|vK)x0hMuawi(IMtz!UQs9D5eBRr^sY00yKt%6QKxi z5FlVuVdx4)E?uE1VorvGfZrW{eDXd1@+N+F#MS*_Kd5Btovq#Y<%eRnr}w&((pY4o zr`<^~w;VEl8#HM&K6BM07n>SiLZwGKavhj<^adP7^UOa5=)OL zQP&jm0H~WFfie&@+rj;~0FBRq*4d&ZZBeVL`}DJ<5iEPU{W{$PsHV>qs&wwweHwb~ O9tJN^zkvdFZu|ob=SOD% literal 0 HcmV?d00001 diff --git a/filesys/__pycache__/sql.cpython-39.pyc b/filesys/__pycache__/sql.cpython-39.pyc index 137a236b3a886a16f7b957b41be0002af1e2c132..9e6c8902b25a8f40fe56942dbfffbe6cd3fb8d36 100644 GIT binary patch delta 20 acmaFK^^%J_k(ZZ?0SM&phi>GKV+8;=ss!l( delta 20 acmaFK^^%J_k(ZZ?0SKZ412=NVu>t@!<^+=f diff --git a/filesys/login.py b/filesys/login.py new file mode 100644 index 0000000..7dc524e --- /dev/null +++ b/filesys/login.py @@ -0,0 +1,52 @@ +import tkinter as tk +from tkinter import filedialog +def login_1(): + + 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 upload_file(): + + 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() + + new_window.mainloop() + + +def download_file(): + return None + + +def delete_file(): + return None + diff --git a/filesys/main.py b/filesys/main.py index 5ebdad9..f6fdfab 100644 --- a/filesys/main.py +++ b/filesys/main.py @@ -1,9 +1,7 @@ -import tkinter as tk -from sql import * -from tkinter import filedialog +from register import * +from login import * import os - def main(): global root global username_entry, password_entry @@ -23,14 +21,17 @@ def main(): password_entry.pack() # 登录按钮 - login_button = tk.Button(root, text="登陆", command=login_0) + login_button = tk.Button(root, text="登陆", command=main_0) login_button.pack() register_button = tk.Button(root, text="注册", command=register) register_button.pack() + exit_button = tk.Button(root, text="退出", command=root.destroy) + exit_button.pack() + root.mainloop() -def login_0(): +def main_0(): entered_username = username_entry.get() entered_password = password_entry.get() @@ -41,117 +42,5 @@ def login_0(): 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/register.py b/filesys/register.py new file mode 100644 index 0000000..2bdc97c --- /dev/null +++ b/filesys/register.py @@ -0,0 +1,38 @@ +import tkinter as tk +from sql import * +def register(): + + global register_view + global username_entry, password_entry + 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_view.destroy) + back_button.pack() + + register_view.mainloop() + +def register_0(): + entered_username = username_entry.get() + entered_password = password_entry.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() diff --git a/filesys/test.py b/filesys/test.py index 0b70cdc..bac8506 100644 --- a/filesys/test.py +++ b/filesys/test.py @@ -1,25 +1,69 @@ -from flask import Flask, request, render_template +import pymysql import os -app = Flask(__name__) -UPLOAD_FOLDER = 'path_to_your_upload_folder' -app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER +def create_connection(host, user, password, db): + connection = None + try: + connection = pymysql.connect( + host=host, + user=user, + password=password, + db=db, + charset='utf8mb4', + cursorclass=pymysql.cursors.DictCursor + ) + print("Connection to MySQL DB successful") + except pymysql.MySQLError as e: + print(f"The error '{e}' occurred") -@app.route('/') -def index(): - return render_template('index.html') + return connection -@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 +def upload_file_to_db(connection, file_path): + if not os.path.exists(file_path): + print("File does not exist.") + return + + try: + with open(file_path, 'rb') as file: + # 读取文件二进制内容 + file_content = file.read() + + cursor = connection.cursor() + sql_query = """ + INSERT INTO file_storage (file_name, file_content) + VALUES (%s, %s) + """ + # 获取文件名 + file_name = os.path.basename(file_path) + # 执行SQL语句 + cursor.execute(sql_query, (file_name, pymysql.Binary(file_content))) + connection.commit() + print(f"File {file_name} has been uploaded successfully.") + except pymysql.MySQLError as e: + print(f"Error uploading file: {e}") + + +# 数据库连接配置 +host = 'localhost' +database = 'file' +user = 'root' +password = '123456' + +# 文件路径 +file_path = 'file_paths.txt' + +# 创建数据库连接 +conn = create_connection(host, user, password, database) + +if conn is not None: + # 上传文件到数据库 + upload_file_to_db(conn, file_path) +else: + print("Failed to connect to the database.") + +# 关闭连接(如果打开) +if conn: + conn.close() +