| | |
| | | return m_pDB->executeQuery(query.str()); |
| | | } |
| | | |
| | | bool RecipeManager::addDeviceRecipe(const std::string& deviceName, int nRecipeID, const std::string& strRecipeName) { |
| | | if (!m_pDB || deviceName.empty() || nRecipeID <= 0 || strRecipeName.empty()) { |
| | | bool RecipeManager::addDeviceRecipe(const std::string& strDeviceName, int nID, const std::string& strName, const std::string& strPara) { |
| | | if (!m_pDB || strDeviceName.empty() || nID <= 0 || strName.empty() || strPara.empty()) { |
| | | return false; |
| | | } |
| | | |
| | | std::ostringstream sql; |
| | | sql << "CREATE TABLE IF NOT EXISTS " << deviceName << "_Recipes (" |
| | | << "recipe_id INTEGER PRIMARY KEY, " |
| | | << "recipe_name TEXT NOT NULL" |
| | | sql << "CREATE TABLE IF NOT EXISTS " << strDeviceName << "_Recipes (" |
| | | << "recipe_id INTEGER PRIMARY KEY," |
| | | << "recipe_name TEXT NOT NULL," |
| | | << "recipe_para TEXT NOT NULL" |
| | | << ");"; |
| | | m_pDB->executeQuery(sql.str()); |
| | | |
| | | std::ostringstream ins; |
| | | ins << "INSERT OR REPLACE INTO " << deviceName << "_Recipes (recipe_id, recipe_name) VALUES (" |
| | | << nRecipeID << ", '" << strRecipeName << "');"; |
| | | ins << "INSERT OR REPLACE INTO " << strDeviceName |
| | | << "_Recipes (recipe_id, recipe_name, recipe_para) VALUES (" |
| | | << nID << ", '" << strName << "', '" << strPara << "');"; |
| | | |
| | | std::lock_guard<std::recursive_mutex> lk(m_mutex); |
| | | return m_pDB->executeQuery(ins.str()); |
| | | } |
| | | |
| | | bool RecipeManager::updateDeviceRecipe(const std::string& deviceName, int nRecipeID, const std::string& newName) { |
| | | if (!m_pDB || deviceName.empty() || nRecipeID <= 0 || newName.empty()) { |
| | | bool RecipeManager::updateDeviceRecipeName(const std::string& strDeviceName, int nID, const std::string& strNewName) { |
| | | if (!m_pDB || strDeviceName.empty() || nID <= 0 || strNewName.empty()) { |
| | | return false; |
| | | } |
| | | |
| | | std::ostringstream sql; |
| | | sql << "UPDATE " << deviceName << "_Recipes SET recipe_name='" << newName |
| | | << "' WHERE recipe_id=" << nRecipeID << ";"; |
| | | sql << "UPDATE " << strDeviceName << "_Recipes SET recipe_name='" << strNewName |
| | | << "' WHERE recipe_id=" << nID << ";"; |
| | | |
| | | std::lock_guard<std::recursive_mutex> lk(m_mutex); |
| | | return m_pDB->executeQuery(sql.str()); |
| | | } |
| | | |
| | | std::string RecipeManager::getDeviceRecipeName(const std::string& deviceName, int nRecipeID) { |
| | | if (!m_pDB || deviceName.empty() || nRecipeID <= 0) { |
| | | bool RecipeManager::updateDeviceRecipePara(const std::string& strDeviceName, int nID, const std::string& strNewPara) { |
| | | if (!m_pDB || strDeviceName.empty() || nID <= 0) { |
| | | return false; |
| | | } |
| | | |
| | | std::ostringstream sql; |
| | | sql << "UPDATE " << strDeviceName << "_Recipes SET recipe_para='" << strNewPara |
| | | << "' WHERE recipe_id=" << nID << ";"; |
| | | |
| | | std::lock_guard<std::recursive_mutex> lk(m_mutex); |
| | | return m_pDB->executeQuery(sql.str()); |
| | | } |
| | | |
| | | std::string RecipeManager::getDeviceRecipeName(const std::string& strDeviceName, int nID) { |
| | | if (!m_pDB || strDeviceName.empty() || nID <= 0) { |
| | | return ""; |
| | | } |
| | | |
| | | std::ostringstream sql; |
| | | sql << "SELECT recipe_name FROM " << deviceName << "_Recipes " |
| | | << "WHERE recipe_id=" << nRecipeID << " LIMIT 1;"; |
| | | sql << "SELECT recipe_name FROM " << strDeviceName << "_Recipes " |
| | | << "WHERE recipe_id=" << nID << " LIMIT 1;"; |
| | | |
| | | auto rows = m_pDB->fetchResults(sql.str()); |
| | | if (!rows.empty() && !rows[0].empty()) { |
| | |
| | | return ""; |
| | | } |
| | | |
| | | bool RecipeManager::deleteDeviceRecipe(const std::string& deviceName, int nRecipeID) { |
| | | if (!m_pDB || deviceName.empty() || nRecipeID <= 0) { |
| | | std::string RecipeManager::getDeviceRecipePara(const std::string& strDeviceName, int nID) { |
| | | if (!m_pDB || strDeviceName.empty() || nID <= 0) { |
| | | return ""; |
| | | } |
| | | |
| | | std::ostringstream sql; |
| | | sql << "SELECT recipe_para FROM " << strDeviceName << "_Recipes " |
| | | << "WHERE recipe_id=" << nID << " LIMIT 1;"; |
| | | |
| | | auto rows = m_pDB->fetchResults(sql.str()); |
| | | if (!rows.empty() && !rows[0].empty()) { |
| | | return rows[0][0]; |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | bool RecipeManager::deleteDeviceRecipe(const std::string& strDeviceName, int nID) { |
| | | if (!m_pDB || strDeviceName.empty() || nID <= 0) { |
| | | return false; |
| | | } |
| | | |
| | | std::ostringstream sql; |
| | | sql << "DELETE FROM " << deviceName << "_Recipes WHERE recipe_id=" << nRecipeID << ";"; |
| | | sql << "DELETE FROM " << strDeviceName << "_Recipes WHERE recipe_id=" << nID << ";"; |
| | | |
| | | std::lock_guard<std::recursive_mutex> lk(m_mutex); |
| | | return m_pDB->executeQuery(sql.str()); |
| | | } |
| | | |
| | | std::vector<std::pair<int, std::string>> RecipeManager::getDeviceRecipes(const std::string& deviceName) { |
| | | std::vector<std::pair<int, std::string>> RecipeManager::getDeviceRecipes(const std::string& strDeviceName) { |
| | | std::vector<std::pair<int, std::string>> out; |
| | | if (!m_pDB || deviceName.empty()) { |
| | | if (!m_pDB || strDeviceName.empty()) { |
| | | return out; |
| | | } |
| | | |
| | | std::ostringstream sql; |
| | | sql << "SELECT recipe_id, recipe_name FROM " << deviceName << "_Recipes ORDER BY recipe_id;"; |
| | | sql << "SELECT recipe_id, recipe_name FROM " << strDeviceName << "_Recipes ORDER BY recipe_id;"; |
| | | |
| | | auto rows = m_pDB->fetchResults(sql.str()); |
| | | for (const auto& r : rows) { |
| | |
| | | |
| | | 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) { |