将程序修改为在搅拌楼端运行
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
"""Access数据库操作模块"""
|
||||
import pyodbc
|
||||
import os
|
||||
|
||||
|
||||
class AccessDB:
|
||||
@ -10,49 +11,74 @@ class AccessDB:
|
||||
|
||||
def connect(self):
|
||||
"""连接Access数据库"""
|
||||
conn_str = (
|
||||
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
|
||||
f'DBQ={self.db_path};'
|
||||
f'PWD={self.password};'
|
||||
)
|
||||
self.connection = pyodbc.connect(conn_str)
|
||||
return self.connection
|
||||
try:
|
||||
# 检查网络路径是否存在
|
||||
if self.db_path.startswith('\\\\') and not os.path.exists(self.db_path):
|
||||
raise FileNotFoundError(f"无法访问网络路径: {self.db_path},请检查网络连接和共享设置")
|
||||
|
||||
conn_str = (
|
||||
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
|
||||
f'DBQ={self.db_path};'
|
||||
f'PWD={self.password};'
|
||||
)
|
||||
self.connection = pyodbc.connect(conn_str)
|
||||
return self.connection
|
||||
except pyodbc.Error as e:
|
||||
print(f"连接Access数据库失败: {e}")
|
||||
raise
|
||||
except FileNotFoundError as e:
|
||||
print(f"数据库文件不可访问: {e}")
|
||||
raise
|
||||
|
||||
def get_max_mark(self):
|
||||
"""获取Access数据库中最大的Mark值"""
|
||||
if not self.connection:
|
||||
self.connect()
|
||||
try:
|
||||
if not self.connection:
|
||||
self.connect()
|
||||
|
||||
cursor = self.connection.cursor()
|
||||
cursor.execute("SELECT MAX(Mark) FROM Produce")
|
||||
max_mark = cursor.fetchone()[0]
|
||||
cursor = self.connection.cursor()
|
||||
cursor.execute("SELECT MAX(Mark) FROM Produce")
|
||||
max_mark = cursor.fetchone()[0]
|
||||
|
||||
if max_mark is None:
|
||||
max_mark = 0
|
||||
if max_mark is None:
|
||||
max_mark = 0
|
||||
|
||||
return max_mark
|
||||
return max_mark
|
||||
except pyodbc.Error as e:
|
||||
print(f"查询最大Mark值时出错: {e}")
|
||||
return 0
|
||||
except Exception as e:
|
||||
print(f"获取最大Mark值时发生未知错误: {e}")
|
||||
return 0
|
||||
|
||||
def query_task_status(self, mis_ids):
|
||||
"""查询任务状态"""
|
||||
if not self.connection:
|
||||
self.connect()
|
||||
try:
|
||||
if not self.connection:
|
||||
self.connect()
|
||||
|
||||
if not mis_ids:
|
||||
if not mis_ids:
|
||||
return {}
|
||||
|
||||
cursor = self.connection.cursor()
|
||||
placeholders = ','.join('?' * len(mis_ids))
|
||||
query = f"SELECT MISID, Flag FROM Produce WHERE MISID IN ({placeholders})"
|
||||
cursor.execute(query, mis_ids)
|
||||
results = cursor.fetchall()
|
||||
|
||||
current_tasks = {}
|
||||
for row in results:
|
||||
mark = row[0]
|
||||
flag = row[1] if row[1] is not None else ""
|
||||
current_tasks[mark] = flag
|
||||
|
||||
return current_tasks
|
||||
except pyodbc.Error as e:
|
||||
print(f"查询任务状态时出错: {e}")
|
||||
return {}
|
||||
except Exception as e:
|
||||
print(f"查询任务状态时发生未知错误: {e}")
|
||||
return {}
|
||||
|
||||
cursor = self.connection.cursor()
|
||||
placeholders = ','.join('?' * len(mis_ids))
|
||||
query = f"SELECT MISID, Flag FROM Produce WHERE MISID IN ({placeholders})"
|
||||
cursor.execute(query, mis_ids)
|
||||
results = cursor.fetchall()
|
||||
|
||||
current_tasks = {}
|
||||
for row in results:
|
||||
mark = row[0]
|
||||
flag = row[1] if row[1] is not None else ""
|
||||
current_tasks[mark] = flag
|
||||
|
||||
return current_tasks
|
||||
|
||||
def close(self):
|
||||
"""关闭数据库连接"""
|
||||
|
||||
@ -32,7 +32,7 @@ class SQLServerConnection:
|
||||
SELECT
|
||||
Code,
|
||||
U1, U2, U3, U4, U5, U6, U7, U8, U9, U10, U11, U12, U13, U14, U15, U16, U17
|
||||
FROM MixTable
|
||||
FROM Recipe_back
|
||||
WHERE Code IS NOT NULL
|
||||
ORDER BY Code
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user