Enhance logging and synchronization features across multiple scripts

- Added detailed logging functionality to init_full_sync.py and run_incremental_sync.py for better tracking of synchronization processes.
- Updated configuration mappings in config.py to include additional Access database tables.
- Improved error handling and user feedback in vbareplace.py, including the ability to refresh linked tables in Access.
- Adjusted polling intervals and batch sizes for performance optimization.
This commit is contained in:
Misaka_Company
2026-01-07 15:01:27 +08:00
parent 77b72392a3
commit a1c8a572bd
4 changed files with 555 additions and 155 deletions

View File

@@ -29,7 +29,7 @@ def main():
if getattr(sys, 'frozen', False):
script_dir = os.path.dirname(sys.executable)
else:
script_dir = os.path.dirname(os.path.abspath(__file))
script_dir = os.path.dirname(os.path.abspath(__file__))
vba_txt_file = os.path.join(script_dir, "vba.txt")
@@ -46,8 +46,8 @@ def main():
return
try:
# 启动 Access
access = win32com.client.Dispatch("Access.Application")
# 启动 Access(使用 DispatchEx 强制创建新实例,避免与已打开的 Access 冲突)
access = win32com.client.DispatchEx("Access.Application")
access.Visible = False # 后台运行,不显示窗口
# 打开数据库
@@ -84,13 +84,45 @@ def main():
access.DoCmd.Close(0, form_name, 0) # 尝试关闭,避免卡住
print(f"处理窗体 {form_name} 时出错: {e}")
# 刷新所有链接表
refreshed_tables = 0
failed_tables = 0
try:
db = access.CurrentDb()
table_count = db.TableDefs.Count
for i in range(table_count):
table_def = db.TableDefs(i)
# 检查是否是链接表Connect属性不为空
if table_def.Connect:
try:
table_def.RefreshLink()
print(f"已刷新链接表: {table_def.Name}")
refreshed_tables += 1
except Exception as e:
print(f"刷新链接表 {table_def.Name} 失败: {e}")
failed_tables += 1
except Exception as e:
print(f"刷新链接表时出错: {e}")
access.CloseCurrentDatabase()
access.Quit()
messagebox.showinfo("成功", f"操作完成!\n\n已处理 {form_count} 个窗体,成功替换 {replaced} 个。\n\n文件已保存: {os.path.basename(access_file)}")
# 构建结果消息
result_msg = f"操作完成!\n\n"
result_msg += f"已处理 {form_count} 个窗体,成功替换 {replaced} 个。\n"
if refreshed_tables > 0 or failed_tables > 0:
result_msg += f"已刷新 {refreshed_tables} 个链接表"
if failed_tables > 0:
result_msg += f"{failed_tables} 个失败"
result_msg += "\n"
result_msg += f"\n文件已保存: {os.path.basename(access_file)}"
messagebox.showinfo("成功", result_msg)
except Exception as e:
messagebox.showerror("运行错误", f"操作失败:\n{e}\n\n请检查是否已启用 VBA 项目访问信任。")
if __name__ == "__main__":
main()
main()
# pyinstaller --onefile --noconsole --name "VBA代码批量替换" vbareplace.py