From 2cd08ebfa438de28261f35f13527d23e8e469dee Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期五, 05 九月 2025 10:45:43 +0800
Subject: [PATCH] 1. 修复获取的设备名称带符号导致创建表失败的问题
---
SourceCode/Bond/Servo/RecipeManager.cpp | 17 ++++++++++-------
SourceCode/Bond/Servo/PageRecipe.h | 2 ++
SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp | 9 ++++++++-
SourceCode/Bond/Servo/PageRecipe.cpp | 30 +++++++++++++++++++++++++++---
4 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/SourceCode/Bond/Servo/PageRecipe.cpp b/SourceCode/Bond/Servo/PageRecipe.cpp
index f19cae0..864ea5a 100644
--- a/SourceCode/Bond/Servo/PageRecipe.cpp
+++ b/SourceCode/Bond/Servo/PageRecipe.cpp
@@ -196,7 +196,7 @@
m_listPPID.SetItemText(index, 1, std::to_string(item.first).c_str());
m_listPPID.SetItemText(index, 2, std::to_string(item.second).c_str());
- std::string strRecipeName = mgr.getDeviceRecipeName(pEq->getName(), item.second);
+ std::string strRecipeName = mgr.getDeviceRecipeName(SanitizeName(pEq->getName()), item.second);
m_listPPID.SetItemText(index, 3, strRecipeName.c_str());
std::string strDescription;
@@ -208,7 +208,7 @@
if (strRecipeName.empty()) {
strRecipeName = std::to_string(item.second);
- mgr.addDeviceRecipe(pEq->getName(), item.second, strRecipeName, strDescription);
+ mgr.addDeviceRecipe(SanitizeName(pEq->getName()), item.second, strRecipeName, strDescription);
}
}
@@ -483,7 +483,7 @@
return;
}
- if (RecipeManager::getInstance().updateDeviceRecipeName(pEq->getName(), _ttoi(strID), std::string(CT2A(strText)))) {
+ if (RecipeManager::getInstance().updateDeviceRecipeName(SanitizeName(pEq->getName()), _ttoi(strID), std::string(CT2A(strText)))) {
m_listPPID.SetItemText(nLine, 3, strText);
}
}
@@ -746,3 +746,27 @@
return 0;
}
+
+std::string CPageRecipe::SanitizeName(const std::string& name)
+{
+ std::string result;
+ result.reserve(name.size());
+
+ for (char c : name) {
+ if (c == '(' || c == '锛�') {
+ break;
+ }
+
+ unsigned char uc = static_cast<unsigned char>(c);
+ if (std::isalnum(uc) || c == '_') {
+ result.push_back(c);
+ }
+ else if (std::isspace(uc)) {
+ continue;
+ }
+ else {
+ result.push_back('_');
+ }
+ }
+ return result;
+}
\ No newline at end of file
diff --git a/SourceCode/Bond/Servo/PageRecipe.h b/SourceCode/Bond/Servo/PageRecipe.h
index 0eac2df..eac7fb3 100644
--- a/SourceCode/Bond/Servo/PageRecipe.h
+++ b/SourceCode/Bond/Servo/PageRecipe.h
@@ -49,5 +49,7 @@
DECLARE_MESSAGE_MAP()
private:
+ std::string SanitizeName(const std::string& name);
+
CListCtrlEx m_listPPID;
};
\ No newline at end of file
diff --git a/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp b/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp
index 81059ac..cd10a8b 100644
--- a/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp
+++ b/SourceCode/Bond/Servo/RecipeDeviceBindDlg.cpp
@@ -96,7 +96,14 @@
for (const auto& pair : mapRecipeIds) {
int nRecipeID = pair.second;
- std::string strRecipeName = RecipeManager::getInstance().getDeviceRecipeName(pEq->getName(), nRecipeID);
+ std::string strDeviceName;
+ for (const auto& dev : g_vecBindDevices) {
+ if (dev.nDeviceID == pEq->getID()) {
+ strDeviceName = dev.strDeviceName;
+ }
+ }
+
+ std::string strRecipeName = RecipeManager::getInstance().getDeviceRecipeName(strDeviceName, nRecipeID);
if (strRecipeName.empty()) {
strRecipeName = std::to_string(nRecipeID);
}
diff --git a/SourceCode/Bond/Servo/RecipeManager.cpp b/SourceCode/Bond/Servo/RecipeManager.cpp
index bc44b96..4a979d7 100644
--- a/SourceCode/Bond/Servo/RecipeManager.cpp
+++ b/SourceCode/Bond/Servo/RecipeManager.cpp
@@ -491,7 +491,10 @@
<< "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 " << strDeviceName
@@ -610,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