From 5cd7a0bae083c1dcaf674772d8a71ff3b4c37102 Mon Sep 17 00:00:00 2001
From: chenluhua1980 <Chenluhua@qq.com>
Date: 星期三, 10 十二月 2025 10:55:39 +0800
Subject: [PATCH] loadReports,兼容各种文件编码

---
 SourceCode/Bond/Servo/RecipeManager.cpp |   85 +++++++++++++++++++++++++++++-------------
 1 files changed, 59 insertions(+), 26 deletions(-)

diff --git a/SourceCode/Bond/Servo/RecipeManager.cpp b/SourceCode/Bond/Servo/RecipeManager.cpp
index db65214..4a979d7 100644
--- a/SourceCode/Bond/Servo/RecipeManager.cpp
+++ b/SourceCode/Bond/Servo/RecipeManager.cpp
@@ -480,48 +480,65 @@
 	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 ("
+	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());
+	bool bRet = m_pDB->executeQuery(sql.str());
+	if (!bRet) {
+		return false;
+	}
 
 	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()) {
@@ -530,26 +547,42 @@
 	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) {
@@ -580,13 +613,13 @@
 
 	addRecipe(recipe);
 
-	addDeviceRecipe("Bonder1", 101, "鏍囧噯宸ヨ壓");
-	addDeviceRecipe("Bonder1", 102, "鏀硅壇宸ヨ壓");
-	addDeviceRecipe("Bonder1", 103, "楂橀�熸ā寮�");
+	addDeviceRecipe("Bonder1", 101, "鏍囧噯宸ヨ壓", "00");
+	addDeviceRecipe("Bonder1", 102, "鏀硅壇宸ヨ壓", "00");
+	addDeviceRecipe("Bonder1", 103, "楂橀�熸ā寮�", "00");
 
-	addDeviceRecipe("Bonder2", 101, "鏍囧噯宸ヨ壓");
-	addDeviceRecipe("Bonder2", 102, "鏀硅壇宸ヨ壓");
-	addDeviceRecipe("Bonder2", 103, "楂橀�熸ā寮�");
+	addDeviceRecipe("Bonder2", 101, "鏍囧噯宸ヨ壓", "00");
+	addDeviceRecipe("Bonder2", 102, "鏀硅壇宸ヨ壓", "00");
+	addDeviceRecipe("Bonder2", 103, "楂橀�熸ā寮�", "00");
 }
 
 bool RecipeManager::readRecipeFile(const std::string& filename) {

--
Gitblit v1.9.3