From b13e43c3eb3881d56f0da797a4171f070bcf2413 Mon Sep 17 00:00:00 2001
From: darker <mr.darker@163.com>
Date: 星期四, 20 二月 2025 18:05:23 +0800
Subject: [PATCH] 1.修复状态错误的问题 2.SECS运行表完成SystemDV表和EqpDV的增删改查,并且把DV数据和SV数据的增删改查提取成一个通用函数
---
SourceCode/Bond/Servo/SECSRuntimeManager.cpp | 466 +++++++++++++++++++++++++++-------------------
SourceCode/Bond/Servo/ServoDlg.cpp | 4
SourceCode/Bond/Servo/SECSRuntimeManager.h | 71 ++++++
3 files changed, 340 insertions(+), 201 deletions(-)
diff --git a/SourceCode/Bond/Servo/SECSRuntimeManager.cpp b/SourceCode/Bond/Servo/SECSRuntimeManager.cpp
index 0af3a89..c294eab 100644
--- a/SourceCode/Bond/Servo/SECSRuntimeManager.cpp
+++ b/SourceCode/Bond/Servo/SECSRuntimeManager.cpp
@@ -97,6 +97,57 @@
return false;
}
+// 删除指定表的所有数据
+int SECSRuntimeManager::deleteAllDataFromTable(const std::string& tableName) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return 1;
+ }
+
+ // 构建删除所有数据的 SQL 语句
+ std::string deleteSQL = "DELETE FROM " + tableName + ";";
+ if (!m_pDB->executeQuery(deleteSQL)) {
+ return 2;
+ }
+
+ return 0; // 删除成功,返回 0 表示操作成功完成。
+}
+
+// 查询指定表所有数据
+bool SECSRuntimeManager::getAllDataFromTable(const std::string& tableName, std::vector<std::vector<std::string>>& outData) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return false; // 数据库连接失败
+ }
+
+ // 查询 SQL 语句,获取指定表的所有数据
+ std::string querySQL = "SELECT * FROM " + tableName + ";";
+ outData = m_pDB->fetchResults(querySQL); // 使用输出参数赋值结果
+
+ return true; // 查询成功
+}
+
+// 删除指定表中指定 ID 的数据
+int SECSRuntimeManager::deleteDataByID(const std::string& tableName, int nID) {
+ std::lock_guard<std::mutex> lock(m_mutex);
+ if (m_pDB == nullptr) {
+ return 1; // 数据库未连接,返回 1
+ }
+
+ // 检查 ID 是否存在
+ if (!isIDDuplicate(nID)) {
+ return 2; // ID 不存在,返回 2
+ }
+
+ // 构建删除 SQL 语句
+ std::string deleteSQL = "DELETE FROM " + tableName + " WHERE ID = " + std::to_string(nID) + ";";
+ if (!m_pDB->executeQuery(deleteSQL)) {
+ return 3; // 删除失败,返回 3
+ }
+
+ return 0; // 删除成功,返回 0
+}
+
// 设置数据库连接
void SECSRuntimeManager::setDatabase(BL::Database* db) {
std::lock_guard<std::mutex> lock(m_mutex);
@@ -161,16 +212,16 @@
}
}
-// 初始化 SystemSV 表
-void SECSRuntimeManager::initSystemSVTable() {
+// 初始化指定的 SystemV 表
+void SECSRuntimeManager::initSystemVTable(const std::string& tableName) {
std::lock_guard<std::mutex> lock(m_mutex);
if (m_pDB == nullptr) {
throw std::runtime_error("Database not connected.");
}
- // 创建 SystemSV 表(如果不存在)
+ // 创建表的 SQL 语句
std::string createTableSQL =
- "CREATE TABLE IF NOT EXISTS SystemSV ("
+ "CREATE TABLE IF NOT EXISTS " + tableName + " ("
"ID INTEGER PRIMARY KEY, "
"Name TEXT UNIQUE NOT NULL, "
"DataType TEXT NOT NULL, "
@@ -179,61 +230,30 @@
"Remark TEXT, "
"SystemID INTEGER);";
+ // 执行创建表操作
if (!m_pDB->executeQuery(createTableSQL)) {
- throw std::runtime_error("Failed to create SystemSV table.");
- }
-
- // 预定义的 SV 数据
- std::vector<std::tuple<int, std::string, std::string, int, std::string, std::string, int>> svData = {
- {1, "SYS_LICENSE_CODE", "ASCII", 0, "NULL", "License code (Formal; Evaluation; NoLicense)", 1},
- {2, "SYS_LICENSE_STATUS", "UINT_1", 0, "NULL", "License status(0:Unauthorized; 1:Authorized; 2:Evaluation; 3:Evaluation Expiring; 4:Trial; 5:Trial End)", 2},
- {3, "GEM_CLOCK", "ASCII", 0, "NULL", "System Clock", 3},
- {4, "SYS_SECS_COMM_MODE", "UINT_1", 0, "NULL", "SECS Communication Mode(0:HSMS Mode; 1:SECSI Mode)", 4},
- {5, "SYS_SECS_DRIVER_CONNECT_STATE", "UINT_1", 0, "NULL", "Initial SECS Driver Connect State(0:Stop; 1:Start)", 5}
- };
-
- for (const auto& entry : svData) {
- int nID, nLength, nSystemID;
- std::string sName, sDataType, sRemark, sUnit;
- std::tie(nID, sName, sDataType, nLength, sUnit, sRemark, nSystemID) = entry;
-
- // 检查 Name 是否已存在
- int count = getIntFromDB("SELECT COUNT(*) FROM SystemSV WHERE Name = '" + sName + "';");
- if (count == 0) {
- // 插入数据
- std::string insertSQL = "INSERT INTO SystemSV (ID, Name, DataType, Length, Unit, Remark, SystemID) VALUES ("
- + std::to_string(nID) + ", '"
- + sName + "', '"
- + sDataType + "', "
- + (nLength > 0 ? std::to_string(nLength) : "NULL") + ", "
- + ((sUnit == "NULL") ? "NULL" : "'" + sUnit + "'") + ", '"
- + sRemark + "', "
- + std::to_string(nSystemID) + ");";
-
- if (!m_pDB->executeQuery(insertSQL)) {
- throw std::runtime_error("Failed to insert SystemSV data.");
- }
- }
+ throw std::runtime_error("Failed to create " + tableName + " table.");
}
}
-// 添加 SystemSV 数据
-int SECSRuntimeManager::addSystemSV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
+// 添加指定的 SystemV 表
+int SECSRuntimeManager::addSystemVData(const std::string& tableName, int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
std::lock_guard<std::mutex> lock(m_mutex);
if (m_pDB == nullptr) {
- return 1;
+ return 1; // 数据库未连接
}
+ // 检查 ID 和 Name 是否重复
if (isIDDuplicate(nID)) {
- return 2;
+ return 2; // ID 重复
}
if (isNameDuplicate(sName)) {
- return 3;
+ return 3; // Name 重复
}
- // 如果 Unit 是 "NULL" 字符串或者为空,则插入 NULL 值
- std::string insertSQL = "INSERT INTO SystemSV (ID, Name, DataType, Length, Unit, Remark, SystemID) VALUES ("
+ // 构建插入语句
+ std::string insertSQL = "INSERT INTO " + tableName + " (ID, Name, DataType, Length, Unit, Remark, SystemID) VALUES ("
+ std::to_string(nID) + ", '"
+ sName + "', '"
+ sDataType + "', "
@@ -242,37 +262,44 @@
+ sRemark + "', "
+ std::to_string(nSystemID) + ");";
+ // 执行插入操作
if (!m_pDB->executeQuery(insertSQL)) {
- return 4;
+ return 4; // 插入失败
}
- return 0;
+ return 0; // 插入成功
}
-// 获取指定 ID 的 SystemSV 数据
-std::vector<std::vector<std::string>> SECSRuntimeManager::getSystemSVByID(int nID) {
+// 获取指定 ID 的 SystemV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getSystemVByID(const std::string& tableName, int nID) {
std::lock_guard<std::mutex> lock(m_mutex);
if (m_pDB == nullptr) {
- return {};
+ return {}; // 如果数据库未连接,返回空结果
}
- std::string query = "SELECT * FROM SystemSV WHERE ID = " + std::to_string(nID) + ";";
+ // 构建查询 SQL 语句
+ std::string query = "SELECT * FROM " + tableName + " WHERE ID = " + std::to_string(nID) + ";";
+
+ // 执行查询并返回结果
return m_pDB->fetchResults(query);
}
-// 获取所有 SystemSV 数据
-std::vector<std::vector<std::string>> SECSRuntimeManager::getAllSystemSV() {
+// 获取 SystemV 的所有数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getAllSystemV(const std::string& tableName) {
std::lock_guard<std::mutex> lock(m_mutex);
if (m_pDB == nullptr) {
- return {};
+ return {}; // 如果数据库未连接,返回空结果
}
- std::string query = "SELECT * FROM SystemSV;";
+ // 构建查询 SQL 语句
+ std::string query = "SELECT * FROM " + tableName + ";";
+
+ // 执行查询并返回结果
return m_pDB->fetchResults(query);
}
-// 更新指定 ID 的 SystemSV 数据
-int SECSRuntimeManager::updateIDSystemSV(int nID, int sNewID) {
+// 更新 SystemV 的 ID 数据
+int SECSRuntimeManager::updateIDSystemV(const std::string& tableName, int nID, int sNewID) {
std::lock_guard<std::mutex> lock(m_mutex);
if (m_pDB == nullptr) {
return 1;
@@ -283,12 +310,13 @@
return 2;
}
+ // 检查新 ID 是否重复
if (isIDDuplicate(sNewID)) {
return 3;
}
// 构建更新的 SQL 语句
- std::string updateSQL = "UPDATE SystemSV SET ID = " + std::to_string(sNewID) + " WHERE ID = " + std::to_string(nID) + ";";
+ std::string updateSQL = "UPDATE " + tableName + " SET ID = " + std::to_string(sNewID) + " WHERE ID = " + std::to_string(nID) + ";";
if (!m_pDB->executeQuery(updateSQL)) {
return 4;
}
@@ -296,8 +324,8 @@
return 0;
}
-// 更新所有 SystemSV 数据
-int SECSRuntimeManager::updateAllSystemSV(int nID, int sNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
+// 更新 SystemV 的所有字段
+int SECSRuntimeManager::updateAllSystemV(const std::string& tableName, int nID, int sNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
std::lock_guard<std::mutex> lock(m_mutex);
if (m_pDB == nullptr) {
return 1;
@@ -314,7 +342,7 @@
}
// 构建更新的 SQL 语句
- std::string updateSQL = "UPDATE SystemSV SET ";
+ std::string updateSQL = "UPDATE " + tableName + " SET ";
bool firstField = true;
@@ -392,58 +420,22 @@
// 执行更新操作
if (!m_pDB->executeQuery(updateSQL)) {
- return 4;
+ return 4;
}
return 0;
}
-// 删除指定 ID 的 SystemSV 数据
-int SECSRuntimeManager::deleteSystemSVByID(int nID) {
- std::lock_guard<std::mutex> lock(m_mutex);
- if (m_pDB == nullptr) {
- return 1;
- }
-
- // 检查是否存在该 ID
- if (!isIDDuplicate(nID)) {
- return 2;
- }
-
- // 构建删除的 SQL 语句
- std::string deleteSQL = "DELETE FROM SystemSV WHERE ID = " + std::to_string(nID) + ";";
- if (!m_pDB->executeQuery(deleteSQL)) {
- return 3;
- }
-
- return 0;
-}
-
-int SECSRuntimeManager::deleteAllSystemSV() {
- std::lock_guard<std::mutex> lock(m_mutex);
- if (m_pDB == nullptr) {
- return 1;
- }
-
- // 构建删除所有数据的 SQL 语句
- std::string deleteSQL = "DELETE FROM SystemSV;";
- if (!m_pDB->executeQuery(deleteSQL)) {
- return 2;
- }
-
- return 0; // 删除成功,返回 0 表示操作成功完成。
-}
-
-// 初始化 EqpSV 表
-void SECSRuntimeManager::initEqpSVTable() {
+// 初始化指定的 EqpV 表
+void SECSRuntimeManager::initEqpVTable(const std::string& tableName) {
std::lock_guard<std::mutex> lock(m_mutex);
if (m_pDB == nullptr) {
throw std::runtime_error("Database not connected.");
}
- // 创建 EqpSV 表
+ // 创建设备表的 SQL 语句
std::string createTableSQL =
- "CREATE TABLE IF NOT EXISTS EqpSV ("
+ "CREATE TABLE IF NOT EXISTS " + tableName + " ("
"ID INTEGER PRIMARY KEY, "
"Name TEXT UNIQUE NOT NULL, "
"DataType TEXT NOT NULL, "
@@ -453,36 +445,38 @@
"SeqNo INTEGER);";
if (!m_pDB->executeQuery(createTableSQL)) {
- throw std::runtime_error("Failed to create EqpSV table.");
+ throw std::runtime_error("Failed to create " + tableName + " table.");
}
}
-// 添加 EqpSV 数据
-int SECSRuntimeManager::addEqpSV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo) {
+// 添加指定 EqpV 表的数据
+int SECSRuntimeManager::addEqpVData(const std::string& tableName, int nID, 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;
}
+ // 检查 ID 是否重复
if (isIDDuplicate(nID)) {
return 2;
}
+ // 检查 Name 是否重复
if (isNameDuplicate(sName)) {
return 3;
}
- // 构建 SQL 插入语句,插入数据到 EqpSV 表中。
- std::string insertSQL = "INSERT INTO EqpSV (ID, Name, DataType, Length, Unit, Remark, SeqNo) VALUES ("
+ // 构建 SQL 插入语句
+ std::string insertSQL = "INSERT INTO " + tableName + " (ID, Name, DataType, Length, Unit, Remark, SeqNo) VALUES ("
+ std::to_string(nID) + ", '"
+ sName + "', '"
+ sDataType + "', "
- + ((nLength <= 0) ? "NULL" : std::to_string(nLength))+", "
- + ((sUnit == "NULL" || sUnit.empty()) ? "NULL" : "'" + sUnit + "'")+", '"
+ + ((nLength <= 0) ? "NULL" : std::to_string(nLength)) + ", "
+ + ((sUnit == "NULL" || sUnit.empty()) ? "NULL" : "'" + sUnit + "'") + ", '"
+ sRemark + "', "
+ std::to_string(nSeqNo) + ");";
- // 执行插入操作,若失败则抛出异常。
+ // 执行插入操作
if (!m_pDB->executeQuery(insertSQL)) {
return 4;
}
@@ -490,32 +484,20 @@
return 0; // 插入成功,返回 0 表示操作成功完成。
}
-// 查找指定 ID 的 EqpSV 数据
-std::vector<std::vector<std::string>> SECSRuntimeManager::getEqpSVByID(int nID) {
+// 查询指定 ID 的 EqpV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getEqpVDataByID(const std::string& tableName, 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) + ";";
+ std::string querySQL = "SELECT * FROM " + tableName + " 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) {
+// 更新指定的 EqpV 数据
+int SECSRuntimeManager::updateEqpV(const std::string& tableName, 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
@@ -532,7 +514,7 @@
}
// 构建更新 SQL 语句
- std::string updateSQL = "UPDATE EqpSV SET ";
+ std::string updateSQL = "UPDATE " + tableName + " SET ";
bool firstField = true;
@@ -599,87 +581,187 @@
return 0; // 更新成功,返回 0
}
-// 删除指定 ID 的 EqpSV 数据
+// 初始化 SystemSV 表
+void SECSRuntimeManager::initSystemSVTable() {
+ initSystemVTable("SystemSV");
+
+ // 预定义的 SV 数据
+ std::vector<std::tuple<int, std::string, std::string, int, std::string, std::string, int>> svData = {
+ {1, "SYS_LICENSE_CODE", "ASCII", 0, "NULL", "License code (Formal; Evaluation; NoLicense)", 1},
+ {2, "SYS_LICENSE_STATUS", "UINT_1", 0, "NULL", "License status(0:Unauthorized; 1:Authorized; 2:Evaluation; 3:Evaluation Expiring; 4:Trial; 5:Trial End)", 2},
+ {3, "GEM_CLOCK", "ASCII", 0, "NULL", "System Clock", 3},
+ {4, "SYS_SECS_COMM_MODE", "UINT_1", 0, "NULL", "SECS Communication Mode(0:HSMS Mode; 1:SECSI Mode)", 4},
+ {5, "SYS_SECS_DRIVER_CONNECT_STATE", "UINT_1", 0, "NULL", "Initial SECS Driver Connect State(0:Stop; 1:Start)", 5}
+ };
+
+ for (const auto& entry : svData) {
+ int nID, nLength, nSystemID;
+ std::string sName, sDataType, sRemark, sUnit;
+ std::tie(nID, sName, sDataType, nLength, sUnit, sRemark, nSystemID) = entry;
+
+ // 检查 Name 是否已存在
+ int count = getIntFromDB("SELECT COUNT(*) FROM SystemSV WHERE Name = '" + sName + "';");
+ if (count == 0) {
+ // 插入数据
+ std::string insertSQL = "INSERT INTO SystemSV (ID, Name, DataType, Length, Unit, Remark, SystemID) VALUES ("
+ + std::to_string(nID) + ", '"
+ + sName + "', '"
+ + sDataType + "', "
+ + (nLength > 0 ? std::to_string(nLength) : "NULL") + ", "
+ + ((sUnit == "NULL") ? "NULL" : "'" + sUnit + "'") + ", '"
+ + sRemark + "', "
+ + std::to_string(nSystemID) + ");";
+
+ if (!m_pDB->executeQuery(insertSQL)) {
+ throw std::runtime_error("Failed to insert SystemSV data.");
+ }
+ }
+ }
+}
+
+// 添加 SystemSV 数据
+int SECSRuntimeManager::addSystemSV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
+ return addSystemVData("SystemSV", nID, sName, sDataType, nLength, sUnit, sRemark, nSystemID);
+}
+
+// 获取指定 ID 的 SystemSV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getSystemSVByID(int nID) {
+ return getSystemVByID("SystemSV", nID);
+}
+
+// 获取所有 SystemSV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getAllSystemSV() {
+ return getAllSystemV("SystemSV");
+}
+
+// 更新 SystemSV 表中的 ID
+int SECSRuntimeManager::updateIDSystemSV(int nID, int sNewID) {
+ return updateIDSystemV("SystemSV", nID, sNewID);
+}
+
+// 更新所有 SystemSV 数据
+int SECSRuntimeManager::updateAllSystemSV(int nID, int sNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
+ return updateAllSystemV("SystemSV", nID, sNewID, sName, sDataType, nLength, sUnit, sRemark, nSystemID);
+}
+
+// 删除指定 ID 的 SystemSV 数据
+int SECSRuntimeManager::deleteSystemSVByID(int nID) {
+ return deleteDataByID("SystemSV", nID);
+}
+
+// 删除所有 SystemSV 数据
+int SECSRuntimeManager::deleteAllSystemSV() {
+ return deleteAllDataFromTable("SystemSV");
+}
+
+// 初始化 EqpSV 表
+void SECSRuntimeManager::initEqpSVTable() {
+ initEqpVTable("EqpSV");
+}
+
+// 添加 EqpSV 数据
+int SECSRuntimeManager::addEqpSV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo) {
+ return addEqpVData("EqpSV", nID, sName, sDataType, nLength, sUnit, sRemark, nSeqNo);
+}
+
+// 查找指定 ID 的 EqpSV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getEqpSVByID(int nID) {
+ return getEqpVDataByID("EqpSV", nID);
+}
+
+// 查找所有 EqpSV 数据
+bool SECSRuntimeManager::getAllEqpSV(std::vector<std::vector<std::string>>& outEqpSV) {
+ return getAllDataFromTable("EqpSV", outEqpSV);
+}
+
+// 更新 EqpSV 表指定 ID 的数据
+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) {
+ return updateEqpV("EqpSV", nID, nNewID, sName, sDataType, nLength, sUnit, sRemark, nSeqNo);
+}
+
+// 删除 EqpSV 表指定 ID 的数据
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
+ return deleteDataByID("EqpSV", nID);
}
// 删除 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
+ return deleteAllDataFromTable("EqpSV");
}
// 初始化 SystemDV 表
void SECSRuntimeManager::initSystemDVTable() {
- std::lock_guard<std::mutex> lock(m_mutex);
- if (m_pDB == nullptr) {
- throw std::runtime_error("Database not connected.");
- }
+ initSystemVTable("SystemDV");
+}
- // 创建 SystemDV 表
- std::string createTableSQL =
- "CREATE TABLE IF NOT EXISTS SystemDV ("
- "ID INTEGER PRIMARY KEY, "
- "Name TEXT UNIQUE NOT NULL, "
- "DataType TEXT NOT NULL, "
- "Length INTEGER NULL, "
- "Unit TEXT NULL, "
- "Remark TEXT, "
- "SystemID INTEGER);";
+// 添加 SystemDV 数据
+int SECSRuntimeManager::addSystemDV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
+ return addSystemVData("SystemDV", nID, sName, sDataType, nLength, sUnit, sRemark, nSystemID);
+}
- if (!m_pDB->executeQuery(createTableSQL)) {
- throw std::runtime_error("Failed to create SystemDV table.");
- }
+// 获取指定 ID 的 SystemDV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getSystemDVByID(int nID) {
+ return getSystemVByID("SystemDV", nID);
+}
+
+// 获取所有 SystemDV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getAllSystemDV() {
+ return getAllSystemV("SystemDV");
+}
+
+// 更新 SystemDV 表中的 ID
+int SECSRuntimeManager::updateIDSystemDV(int nID, int sNewID) {
+ return updateIDSystemV("SystemDV", nID, sNewID);
+}
+
+// 更新所有 SystemDV 数据
+int SECSRuntimeManager::updateAllSystemDV(int nID, int sNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID) {
+ return updateAllSystemV("SystemDV", nID, sNewID, sName, sDataType, nLength, sUnit, sRemark, nSystemID);
+}
+
+// 删除指定 ID 的 SystemDV 数据
+int SECSRuntimeManager::deleteSystemDVByID(int nID) {
+ return deleteDataByID("SystemDV", nID);
+}
+
+// 删除所有 SystemDV 数据
+int SECSRuntimeManager::deleteAllSystemDV() {
+ return deleteAllDataFromTable("SystemDV");
}
// 初始化 EqpDV 表
void SECSRuntimeManager::initEqpDVTable() {
- std::lock_guard<std::mutex> lock(m_mutex);
- if (m_pDB == nullptr) {
- throw std::runtime_error("Database not connected.");
- }
+ initEqpVTable("EqpDV");
+}
- // 创建 EqpDV 表
- std::string createTableSQL =
- "CREATE TABLE IF NOT EXISTS EqpDV ("
- "ID INTEGER PRIMARY KEY, "
- "Name TEXT UNIQUE NOT NULL, "
- "DataType TEXT NOT NULL, "
- "Length INTEGER NULL, "
- "Unit TEXT NULL, "
- "Remark TEXT, "
- "SeqNo INTEGER);";
+// 添加 EqpDV 数据
+int SECSRuntimeManager::addEqpDV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo) {
+ return addEqpVData("EqpDV", nID, sName, sDataType, nLength, sUnit, sRemark, nSeqNo);
+}
- if (!m_pDB->executeQuery(createTableSQL)) {
- throw std::runtime_error("Failed to create EqpDV table.");
- }
+// 查找指定 ID 的 EqpDV 数据
+std::vector<std::vector<std::string>> SECSRuntimeManager::getEqpDVByID(int nID) {
+ return getEqpVDataByID("EqpDV", nID);
+}
+
+// 获取所有 EqpDV 数据
+bool SECSRuntimeManager::getAllEqpDV(std::vector<std::vector<std::string>>& outEqpDV) {
+ return getAllDataFromTable("EqpDV", outEqpDV);
+}
+
+// 更新 EqpDV 表指定 ID 的数据
+int SECSRuntimeManager::updateEqpDV(int nID, int nNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo) {
+ return updateEqpV("EqpDV", nID, nNewID, sName, sDataType, nLength, sUnit, sRemark, nSeqNo);
+}
+
+// 删除 EqpDV 表指定 ID 的数据
+int SECSRuntimeManager::deleteEqpDVByID(int nID) {
+ return deleteDataByID("EqpDV", nID);
+}
+
+// 删除 EqpDV 表中的所有数据
+int SECSRuntimeManager::deleteAllEqpDV() {
+ return deleteAllDataFromTable("EqpDV");
}
// 初始化 SystemEC 表
diff --git a/SourceCode/Bond/Servo/SECSRuntimeManager.h b/SourceCode/Bond/Servo/SECSRuntimeManager.h
index f0a722d..b66c70f 100644
--- a/SourceCode/Bond/Servo/SECSRuntimeManager.h
+++ b/SourceCode/Bond/Servo/SECSRuntimeManager.h
@@ -31,6 +31,34 @@
*/
void termRuntimeSetting();
+ /**
+ * 鍒濆鍖栨寚瀹氱殑 SystemV 琛�
+ * @param tableName: 瑕佸垵濮嬪寲鐨勮〃鍚嶏紙濡� "SystemSV" 鎴� "SystemDV"锛夈��
+ *
+ * 姝ゅ嚱鏁扮敤浜庡垵濮嬪寲鎸囧畾鍚嶇О鐨� SystemV 琛ㄣ�傚鏋滆〃涓嶅瓨鍦紝灏嗕細鍒涘缓璇ヨ〃銆�
+ * - 琛ㄧ粨鏋勫寘鎷細ID銆丯ame銆丏ataType銆丩ength銆乁nit銆丷emark銆丼ystemID銆�
+ * - 濡傛灉琛ㄥ凡缁忓瓨鍦紝鍒欎笉杩涜浠讳綍鎿嶄綔銆�
+ */
+ void initSystemVTable(const std::string& tableName);
+
+ int addSystemVData(const std::string& tableName, int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID);
+
+ std::vector<std::vector<std::string>> getSystemVByID(const std::string& tableName, int nID);
+
+ std::vector<std::vector<std::string>> getAllSystemV(const std::string& tableName);
+
+ int updateIDSystemV(const std::string& tableName, int nID, int sNewID);
+
+ int updateAllSystemV(const std::string& tableName, int nID, int sNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID);
+
+ void initEqpVTable(const std::string& tableName);
+
+ int addEqpVData(const std::string& tableName, int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo);
+
+ std::vector<std::vector<std::string>> getEqpVDataByID(const std::string& tableName, int nID);
+
+ int updateEqpV(const std::string& tableName, int nID, int nNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo);
+
/**
* 鍒濆鍖朣ystemSV琛�
*/
@@ -190,14 +218,8 @@
/**
* 鑾峰彇鎵�鏈� EqpSV 鏁版嵁
- * @return std::vector<std::vector<std::string>>: 杩斿洖涓�涓簩缁村瓧绗︿覆鍚戦噺锛岃〃绀烘煡璇㈢粨鏋溿�傛瘡琛屼唬琛ㄤ竴鏉¤褰曪紝姣忓垪浠h〃璇ヨ褰曠殑涓�涓瓧娈靛�笺��
- * 濡傛灉琛ㄤ腑鏈夋暟鎹紝鍒欒繑鍥炴墍鏈夎褰曪紱濡傛灉琛ㄤ负绌猴紝鍒欒繑鍥炵┖鐨勪簩缁村悜閲忋��
- *
- * 姝ゅ嚱鏁扮敤浜庝粠 EqpSV 琛ㄤ腑鑾峰彇鎵�鏈夌殑鏁版嵁銆傞�氳繃鏋勯�� SQL 鏌ヨ璇彞鏉ラ�夋嫨鎵�鏈夎褰曪紝骞舵墽琛屾煡璇㈡搷浣溿��
- * 杩斿洖鐨勭粨鏋滄槸涓�涓簩缁村瓧绗︿覆鍚戦噺锛岃〃绀鸿〃涓殑鎵�鏈夎褰曘�傛瘡琛屾暟鎹槸涓�涓瓧绗︿覆鍚戦噺锛屽叾涓寘鍚璁板綍鐨勫悇涓瓧娈点��
- * 濡傛灉琛ㄤ腑娌℃湁鏁版嵁锛屽嚱鏁板皢杩斿洖涓�涓┖鐨勪簩缁村悜閲忋��
*/
- std::vector<std::vector<std::string>> SECSRuntimeManager::getAllEqpSV();
+ bool getAllEqpSV(std::vector<std::vector<std::string>>& outEqpSV);
/**
* 鏇存柊鎸囧畾 ID 鐨� EqpSV 鏁版嵁
@@ -258,10 +280,36 @@
*/
void initSystemDVTable();
+ int addSystemDV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID);
+
+ std::vector<std::vector<std::string>> getSystemDVByID(int nID);
+
+ std::vector<std::vector<std::string>> getAllSystemDV();
+
+ int updateIDSystemDV(int nID, int sNewID);
+
+ int updateAllSystemDV(int nID, int sNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSystemID);
+
+ int deleteSystemDVByID(int nID);
+
+ int deleteAllSystemDV();
+
/**
* 鍒濆鍖� EqpDV 琛�
*/
void initEqpDVTable();
+
+ int addEqpDV(int nID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo);
+
+ std::vector<std::vector<std::string>> getEqpDVByID(int nID);
+
+ bool getAllEqpDV(std::vector<std::vector<std::string>>& outEqpDV);
+
+ int updateEqpDV(int nID, int nNewID, const std::string& sName, const std::string& sDataType, int nLength, const std::string& sUnit, const std::string& sRemark, int nSeqNo);
+
+ int deleteEqpDVByID(int nID);
+
+ int deleteAllEqpDV();
/**
* 鍒濆鍖� SystemEC 琛�
@@ -434,6 +482,15 @@
// 鍒ゆ柇鍚嶇О鏄惁閲嶅
bool isNameDuplicate(const std::string& sName);
+ // 鍒犻櫎鎸囧畾琛ㄤ腑鐨勬墍鏈夋暟鎹�
+ int deleteAllDataFromTable(const std::string& tableName);
+
+ // 鏌ヨ鎸囧畾琛ㄦ墍鏈夋暟鎹紙閫氱敤鍑芥暟锛�
+ bool getAllDataFromTable(const std::string& tableName, std::vector<std::vector<std::string>>& outData);
+
+ // 鍒犻櫎鎸囧畾琛ㄤ腑鎸囧畾 ID 鐨勬暟鎹�
+ int deleteDataByID(const std::string& tableName, int nID);
+
BL::Database* m_pDB;
static std::mutex m_mutex;
};
diff --git a/SourceCode/Bond/Servo/ServoDlg.cpp b/SourceCode/Bond/Servo/ServoDlg.cpp
index 39da8c6..1e29081 100644
--- a/SourceCode/Bond/Servo/ServoDlg.cpp
+++ b/SourceCode/Bond/Servo/ServoDlg.cpp
@@ -676,12 +676,12 @@
switch (status) {
case ONLINE:
- newBackgroundColor = RGB(255, 0, 0);
+ newBackgroundColor = RGB(0, 255, 0);
newFrameColor1 = RGB(22, 22, 22);
newFrameColor2 = RGB(255, 127, 39);
break;
case OFFLINE:
- newBackgroundColor = RGB(0, 255, 0);
+ newBackgroundColor = RGB(255, 0, 0);
newFrameColor1 = RGB(22, 22, 22);
newFrameColor2 = RGB(255, 127, 39);
break;
--
Gitblit v1.9.3