diff --git a/python/test/1000/info.csv b/python/test/1000/info.csv deleted file mode 100644 index e69de29..0000000 diff --git a/python/test/Client/Page/Chat_main.py b/python/test/Client/Page/Chat_main.py index 2409577..35f4b88 100644 --- a/python/test/Client/Page/Chat_main.py +++ b/python/test/Client/Page/Chat_main.py @@ -3,18 +3,14 @@ import wx.aui import wx.lib.scrolledpanel as scrolled import time import multiprocessing -import os -import csv from Client.Transmission.Process_Client import ProcessClient class ChatFrame(wx.Frame, ProcessClient): def __init__(self, Id): - wx.Frame().__init__(None, size=(800, 600), title="账号: " + str(Id)) + wx.Frame.__init__(self, None, size=(800, 600), title="账号: " + str(Id)) ProcessClient.__init__(self) - self.detection_data(Id) - ChatMain_Panel = wx.Panel(self, style=wx.BORDER_SUNKEN) ChatMain_box = wx.BoxSizer(wx.HORIZONTAL) ChatMain_Panel.SetSizer(ChatMain_box) @@ -118,30 +114,6 @@ class ChatFrame(wx.Frame, ProcessClient): self.find_page.Show() self.Layout() - def detection_data(self, Id): - root_path = rf'.\{Id}' - info_path = root_path + r'\info.csv' - file_root_path = root_path + r'\file' - other_file_path = file_root_path + r'\other' - image_file_path = file_root_path + r'\image' - if not os.path.isdir(root_path): - os.mkdir(root_path) - if not os.path.isdir(file_root_path): - os.mkdir(file_root_path) - os.mkdir(other_file_path) - os.mkdir(image_file_path) - if not os.path.exists(info_path): - with open(info_path, 'w', encoding='utf-8') as f: - pass - with open(info_path, 'r+', encoding='utf-8') as info: - if info.tell() == 0: - date = None - target = "服务器" - genre = "数据更新" - content = date - data = {"genre": genre, "target": target, "content": content} - self.Process_client_send("Session_server", "send_server", data) - class ChatPage(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent, style=wx.BORDER_SUNKEN) diff --git a/python/test/Client/Page/Login.py b/python/test/Client/Page/Login.py index b09654e..21d8105 100644 --- a/python/test/Client/Page/Login.py +++ b/python/test/Client/Page/Login.py @@ -20,7 +20,6 @@ class LoginFrame(wx.Frame, ProcessClient): wx.Frame.__init__(self, None, id=-1, title='登录', pos=wx.DefaultPosition, size=(380, 300)) ProcessClient.__init__(self) - current_file_path = __file__ current_file_name = os.path.basename(current_file_path).split('.')[0] self.Process_client_send("Server", "Name", current_file_name) @@ -156,7 +155,6 @@ class LoginFrame(wx.Frame, ProcessClient): self.login_page_receive(data['content']) - class LoginPanel(wx.Panel): def __init__(self, parent): super().__init__(parent) diff --git a/python/test/Client/Transmission/Session_server.py b/python/test/Client/Transmission/Session_server.py index 1745161..facbc42 100644 --- a/python/test/Client/Transmission/Session_server.py +++ b/python/test/Client/Transmission/Session_server.py @@ -46,8 +46,7 @@ class Session_server(ProcessClient): try: receive_content_json = self.server_socket.recv(1024).decode('utf-8') receive_content = json.loads(receive_content_json) - if receive_content["genre"] in ['注册', '登录']: - self.Process_client_send("Login", "login_page_receive", receive_content) + self.content_pick(receive_content) except Exception as a: print("接收错误:" + str(a)) self.server_status = False @@ -72,3 +71,13 @@ class Session_server(ProcessClient): self.server_status = data['content'] case 'send_server': self.send_server(data['content']['genre'], data['content']['target'], data['content']['content']) + + def content_pick(self,data): + match data['genre']: + case '注册' | '登录': + self.Process_client_send("Login", "login_page_receive", data) + case '数据更新': + print(data) + self.Process_client_send("file_operate", "login_page_receive", data) + + diff --git a/python/test/Client/Transmission/__init__.py b/python/test/Client/Transmission/__init__.py index fb5046f..a3f1b63 100644 --- a/python/test/Client/Transmission/__init__.py +++ b/python/test/Client/Transmission/__init__.py @@ -1,3 +1,4 @@ from .Process_Server import * from .Process_Client import * -from .Session_server import * \ No newline at end of file +from .Session_server import * +from .file_operate import * \ No newline at end of file diff --git a/python/test/Client/Transmission/file_operate.py b/python/test/Client/Transmission/file_operate.py new file mode 100644 index 0000000..bf117c3 --- /dev/null +++ b/python/test/Client/Transmission/file_operate.py @@ -0,0 +1,42 @@ +import os +import csv + +from .Process_Client import ProcessClient + + +class FileOperate(ProcessClient): + def __init__(self): + ProcessClient.__init__(self) + + current_file_path = __file__ + current_file_name = os.path.basename(current_file_path).split('.')[0] + self.Process_client_send("Server", "Name", current_file_name) + + def detection_data(self, Id): + root_path = rf'.\{Id}' + info_path = root_path + r'\info.csv' + file_root_path = root_path + r'\file' + other_file_path = file_root_path + r'\other' + image_file_path = file_root_path + r'\image' + if not os.path.isdir(root_path): + os.mkdir(root_path) + if not os.path.isdir(file_root_path): + os.mkdir(file_root_path) + os.mkdir(other_file_path) + os.mkdir(image_file_path) + if not os.path.exists(info_path): + with open(info_path, 'w', encoding='utf-8') as f: + pass + with open(info_path, 'r+', encoding='utf-8') as info: + if info.tell() == 0: + date = None + target = "服务器" + genre = "数据更新" + content = date + data = {"genre": genre, "target": target, "content": content} + self.Process_client_send("Session_server", "send_server", data) + + def Process_client_pick(self, data): + if data['target'] in ['ALL', 'file_operate']: + print(data) + #match data['function']: diff --git a/python/test/Server/Transmission/Database_formula.py b/python/test/Server/Transmission/Database_formula.py index 0fa5eb4..05bf7ba 100644 --- a/python/test/Server/Transmission/Database_formula.py +++ b/python/test/Server/Transmission/Database_formula.py @@ -42,23 +42,27 @@ class database(ProcessClient): except pymssql.Error as a: print(a) - def check_account_state(self, Id: int, password): + def check_account_state(self, client_id, Id: int, password): if self.database_state: try: + state = 2 self.database_cursor.execute(f"select Id,Password from Account where Id = {Id}") request_data = self.database_cursor.fetchall() if len(request_data) != 0: if request_data[0][1] == password: - return 0 + state = 0 else: - return 1 - else: - return 2 + state = 1 + + content = {"account": Id, "status": state} + data = {"client_id": client_id, "target": "客户端", "genre": "登录", "data": content} + self.Process_client_send('Session_client', 'send_client', data) + except pymssql as a: self.database_state = False print(a) - def sign_account(self, NetName, Password): + def sign_account(self, client_id, NetName, Password): if self.database_state: # 获取锁 self.lock.acquire() @@ -70,7 +74,11 @@ class database(ProcessClient): Id = self.database_cursor.fetchone()[0] # 释放锁 self.lock.release() - return {"Id": int(Id), "NetName": NetName, "Password": Password} + info = {"Id": int(Id), "NetName": NetName, "Password": Password} + + content = {"client_id": client_id, "target": "客户端", "genre": "注册", "data": info} + self.Process_client_send('Session_client', 'send_client', content) + except pymssql as a: self.lock.release() self.database_state = False @@ -85,6 +93,39 @@ class database(ProcessClient): self.database_state = False print(a) + def detection_data(self, Id, date): + if date is None: + datas = [] + + self.database_cursor.execute(f"select Id,Password,NetName,UpDataTime from Account where Id = {Id}") + Account_database = self.database_cursor.fetchall() + Account_content = {'Id': Account_database[0][0], + 'Password': Account_database[0][1], + 'NetName': Account_database[0][2], + 'UpDataTime': Account_database[0][3].strftime('%Y-%m-%d %H:%M:%S')} + Account_data = {"Account": Account_content} + datas.append(Account_data) + + self.database_cursor.execute(f"select ContactsId,Remark,State from Contacts where UserId = {Id}") + Contacts_database = self.database_cursor.fetchall() + Contacts_data = {"Contacts": Contacts_database} + datas.append(Contacts_data) + + self.database_cursor.execute(f"select ContactsId,Remark,State from Contacts where UserId = {Id}") + Contacts_database = self.database_cursor.fetchall() + Contacts_data = {"Contacts": Contacts_database} + datas.append(Contacts_data) + + self.database_cursor.execute(f"select * from History where Send = {Id} or Receive ={Id}") + History_database = self.database_cursor.fetchall() + History_data = {"History": History_database} + datas.append(History_data) + for data in datas: + content = {"client_id": Id, "target": "客户端", "genre": "数据更新", "data": data} + self.Process_client_send('Session_client', 'send_client', content) + + + def Process_client_pick(self, data): if data['target'] in ['ALL', 'Database_formula']: match data['function']: @@ -92,26 +133,16 @@ class database(ProcessClient): client_id = data['content']['client_id'] account = data['content']['account'] password = data['content']['password'] - - status = self.check_account_state(account, password) - content = {"account": account, "status": status} - content = {"client_id": client_id, "target": "客户端", "genre": "登录", "data": content} - - self.Process_client_send('Session_client', 'send_client', content) + self.check_account_state(client_id, account, password) case 'sign_account': client_id = data['content']['client_id'] account = data['content']['account'] password = data['content']['password'] - - info = self.sign_account(account, password) - content = {"client_id": client_id, "target": "客户端", "genre": "注册", "data": info} - self.Process_client_send('Session_client', 'send_client', content) + self.sign_account(client_id, account, password) case 'alter_state_database': self.alter_state_database(data['content']['Id'], data['content']['sate']) - - def detection_data(self,date): - if date is None: - self.database_cursor.execute(f"update Account set State = N'{sate}' where Id = {Id}") \ No newline at end of file + case 'detection_data': + self.detection_data(data['content']['client_id'], data['content']['date']) diff --git a/python/test/Server/Transmission/Session_client.py b/python/test/Server/Transmission/Session_client.py index ef5e8b0..e41cd0d 100644 --- a/python/test/Server/Transmission/Session_client.py +++ b/python/test/Server/Transmission/Session_client.py @@ -59,7 +59,8 @@ class link_client(ProcessClient): 'password': data['data']['password']} self.Process_client_send("Database_formula", "sign_account", content) case '数据更新': - self.Process_client_send("Database_formula", "sign_account", data['data']) + content = {'client_id': client_id, 'date': data['data']} + self.Process_client_send("Database_formula", "detection_data", content) def recv_client(self, client_socket): state = True