From 5efff0895ad06eb0c5f04df7efe67a22b358beb3 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期二, 18 二月 2025 16:10:23 +0800
Subject: [PATCH] Merge branch 'liuyang' into clh
---
SourceCode/Bond/Servo/SECSRuntimeManager.cpp | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 168 insertions(+), 0 deletions(-)
diff --git a/SourceCode/Bond/Servo/SECSRuntimeManager.cpp b/SourceCode/Bond/Servo/SECSRuntimeManager.cpp
index be02efa..bb382a2 100644
--- a/SourceCode/Bond/Servo/SECSRuntimeManager.cpp
+++ b/SourceCode/Bond/Servo/SECSRuntimeManager.cpp
@@ -249,6 +249,28 @@
return 0;
}
+// 获取指定 ID 的 SystemSV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getSystemSVByID(int nID) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return {};
+ }
+
+ std::string query = "SELECT * FROM SystemSV WHERE ID = " + std::to_string(nID) + ";";
+ return m_pDB->fetchResults(query);
+}
+
+// 获取所有 SystemSV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getAllSystemSV() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return {};
+ }
+
+ std::string query = "SELECT * FROM SystemSV;";
+ return m_pDB->fetchResults(query);
+}
+
// 更新指定 ID 的 SystemSV 数据
int SECSRuntimeManager::updateIDSystemSV(int nID, int sNewID) {
std::lock_guard<std::mutex> lock(m_mutex);
@@ -468,6 +490,152 @@
return 0; // 插入成功,返回 0 表示操作成功完成。
}
+// 查找指定 ID 的 EqpSV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getEqpSVByID(int nID) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return {};
+ }
+
+ // 查询 SQL 语句
+ std::string querySQL = "SELECT * FROM EqpSV WHERE ID = " + std::to_string(nID) + ";";
+ return m_pDB->fetchResults(querySQL); // 直接返回查询结果
+}
+
+// 查找所有 EqpSV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getAllEqpSV() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return {};
+ }
+
+ // 查询 SQL 语句,获取所有数据
+ std::string querySQL = "SELECT * FROM EqpSV;";
+ return m_pDB->fetchResults(querySQL); // 直接返回查询结果
+}
+
+// 更新指定 ID 的 EqpSV 数据
+int SECSRuntimeManager::updateEqpSV(int nID, int nNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return 1; // 如果数据库未连接,返回 1
+ }
+
+ // 检查是否存在该 ID
+ if (!isIDDuplicate(nID)) {
+ return 2; // 如果 ID 不存在,返回错误代码 2
+ }
+
+ // 检查新的 ID 是否已存在
+ if (isIDDuplicate(nNewID) && nNewID != nID) {
+ return 3; // 如果新 ID 已存在,返回错误代码 3
+ }
+
+ // 构建更新 SQL 语句
+ std::string updateSQL = "UPDATE EqpSV SET ";
+
+ bool firstField = true;
+
+ // 如果新的 ID 被提供,更新 ID
+ if (nNewID > 0 && nNewID != nID) {
+ updateSQL += "ID = " + std::to_string(nNewID);
+ firstField = false;
+ }
+
+ // 更新 Name
+ if (!sName.empty()) {
+ if (!firstField) updateSQL += ", ";
+ updateSQL += "Name = '" + sName + "'";
+ firstField = false;
+ }
+
+ // 更新 DataType
+ if (!sDataType.empty()) {
+ if (!firstField) updateSQL += ", ";
+ updateSQL += "DataType = '" + sDataType + "'";
+ firstField = false;
+ }
+
+ // 更新 Length
+ if (nLength > 0) {
+ if (!firstField) updateSQL += ", ";
+ updateSQL += "Length = " + std::to_string(nLength);
+ firstField = false;
+ }
+
+ // 更新 Unit
+ if (sUnit != "NULL" && !sUnit.empty()) {
+ if (!firstField) updateSQL += ", ";
+ updateSQL += "Unit = '" + sUnit + "'";
+ firstField = false;
+ }
+ else if (sUnit == "NULL") {
+ if (!firstField) updateSQL += ", ";
+ updateSQL += "Unit = NULL";
+ firstField = false;
+ }
+
+ // 更新 Remark
+ if (!sRemark.empty()) {
+ if (!firstField) updateSQL += ", ";
+ updateSQL += "Remark = '" + sRemark + "'";
+ firstField = false;
+ }
+
+ // 更新 SeqNo
+ if (nSeqNo > 0) {
+ if (!firstField) updateSQL += ", ";
+ updateSQL += "SeqNo = " + std::to_string(nSeqNo);
+ }
+
+ // 添加 WHERE 子句,更新指定 ID 的数据
+ updateSQL += " WHERE ID = " + std::to_string(nID) + ";";
+
+ // 执行更新操作
+ if (!m_pDB->executeQuery(updateSQL)) {
+ return 4; // 如果更新失败,返回错误代码 4
+ }
+
+ return 0; // 更新成功,返回 0
+}
+
+// 删除指定 ID 的 EqpSV 数据
+int SECSRuntimeManager::deleteEqpSVByID(int nID) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return 1;
+ }
+
+ // 检查是否存在该 ID
+ if (!isIDDuplicate(nID)) {
+ return 2; // 如果 ID 不存在,返回错误代码 2
+ }
+
+ // 构建删除 SQL 语句
+ std::string deleteSQL = "DELETE FROM EqpSV WHERE ID = " + std::to_string(nID) + ";";
+ if (!m_pDB->executeQuery(deleteSQL)) {
+ return 3; // 如果删除失败,返回错误代码 3
+ }
+
+ return 0; // 删除成功,返回 0
+}
+
+// 删除 EqpSV 表中的所有数据
+int SECSRuntimeManager::deleteAllEqpSV() {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return 1;
+ }
+
+ // 构建删除所有数据的 SQL 语句
+ std::string deleteSQL = "DELETE FROM EqpSV;";
+ if (!m_pDB->executeQuery(deleteSQL)) {
+ return 2; // 如果删除失败,返回错误代码 2
+ }
+
+ return 0; // 删除成功,返回 0
+}
+
// 初始化 SystemDV 表
void SECSRuntimeManager::initSystemDVTable() {
std::lock_guard<std::mutex> lock(m_mutex);
--
Gitblit v1.9.3