| | |
| | | #include "stdafx.h" |
| | | #include "stdafx.h" |
| | | #include "RecipeManager.h" |
| | | #include <sstream> |
| | | #include <iomanip> |
| | |
| | | return false; |
| | | } |
| | | |
| | | // 启用 SQLite 的外键约束支持 |
| | | // 启用 SQLite 的外键约束支持 |
| | | if (!m_pDB->executeQuery("PRAGMA foreign_keys = ON;")) { |
| | | std::cerr << "Failed to enable foreign keys." << std::endl; |
| | | return false; |
| | |
| | | |
| | | std::lock_guard<std::recursive_mutex> lock(m_mutex); |
| | | |
| | | // 开始事务 |
| | | // 开始事务 |
| | | m_pDB->executeQuery("BEGIN TRANSACTION;"); |
| | | |
| | | std::ostringstream oss; |
| | |
| | | } |
| | | } |
| | | |
| | | // 提交事务 |
| | | // 提交事务 |
| | | m_pDB->executeQuery("COMMIT;"); |
| | | return true; |
| | | } |
| | |
| | | return false; |
| | | } |
| | | |
| | | // 检查 ppid 是否存在 |
| | | // 检查 ppid 是否存在 |
| | | if (!ppidExists(ppid)) { |
| | | std::cerr << "[addRecipeDevice] PPID does not exist: " << ppid << std::endl; |
| | | return false; |
| | | } |
| | | |
| | | // 插入设备记录 |
| | | // 插入设备记录 |
| | | std::ostringstream oss; |
| | | oss << "INSERT OR REPLACE INTO recipe_devices (ppid, device_id, device_name, recipe_id, recipe_name) VALUES ('" |
| | | << ppid << "', " |
| | |
| | | |
| | | std::lock_guard<std::recursive_mutex> lock(m_mutex); |
| | | |
| | | // 检查是否已经存在相同的 newPPID |
| | | // 检查是否已经存在相同的 newPPID |
| | | auto check = m_pDB->fetchResults("SELECT COUNT(*) FROM recipes WHERE ppid = '" + newPPID + "';"); |
| | | if (!check.empty() && !check[0].empty() && check[0][0] != "0") { |
| | | std::cerr << "[updatePPID] New PPID already exists: " << newPPID << std::endl; |
| | |
| | | |
| | | addRecipe(recipe); |
| | | |
| | | addDeviceRecipe("Bonder1", 101, "标准工艺"); |
| | | addDeviceRecipe("Bonder1", 102, "改良工艺"); |
| | | addDeviceRecipe("Bonder1", 103, "高速模式"); |
| | | addDeviceRecipe("Bonder1", 101, "标准工艺"); |
| | | addDeviceRecipe("Bonder1", 102, "改良工艺"); |
| | | addDeviceRecipe("Bonder1", 103, "高速模式"); |
| | | |
| | | addDeviceRecipe("Bonder2", 101, "标准工艺"); |
| | | addDeviceRecipe("Bonder2", 102, "改良工艺"); |
| | | addDeviceRecipe("Bonder2", 103, "高速模式"); |
| | | addDeviceRecipe("Bonder2", 101, "标准工艺"); |
| | | addDeviceRecipe("Bonder2", 102, "改良工艺"); |
| | | addDeviceRecipe("Bonder2", 103, "高速模式"); |
| | | } |
| | | |
| | | bool RecipeManager::readRecipeFile(const std::string& filename) { |