/************************************************************************************************** 版本所有(C), 2021-2022, 北京普达迪泰 *************************************************************************************************** 文 件 名:EquipDataPlaneManager.cpp 版 本 号: 1.00初版 作 者: HYF 生成日期:2021-12-20 最近修改: 功能描述: 设备静态测量数据-点 函数列表: 修改历史: 1.日 期 : 2021-12-20 作 者 : HYF 修改内容 : 创建文件 **************************************************************************************************/ #include "pch.h" #include "Utils.h" #include "EquipDataPointManager.h" #include "CppSQLite3.h" #include "DBFactory.h" #include "EquipDataPoint.h" EquipDataPointManager::EquipDataPointManager() { } EquipDataPointManager::~EquipDataPointManager() { } /************************************************************************************************** 函 数 名 :QueryAll 功能描述 :查询 输出参数 :略 返 回 值 :CppSQLite3Query **************************************************************************************************/ CppSQLite3Query EquipDataPointManager::Query() { try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); return pDB->execQuery(_T("SELECT * FROM equip_data_point;")); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); } } /************************************************************************************************** 函 数 名 :QueryByCode 功能描述 :基于设备编码查询 输出参数 :无 返 回 值 :CppSQLite3Query **************************************************************************************************/ CppSQLite3Query EquipDataPointManager::Query(DWORD iTaskId) { try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); char szCmd[256]; sprintf_s(szCmd, "SELECT * FROM equip_data_point WHERE task_id=%d;", iTaskId); return pDB->execQuery(szCmd); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); } } CppSQLite3Query EquipDataPointManager::Query(DWORD iTaskId, LPCTSTR szEquipCode) { try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); char szCmd[256]; sprintf_s(szCmd, "SELECT * FROM equip_data_point WHERE task_id=%d AND equip_code='%s';", iTaskId, szEquipCode); return pDB->execQuery(szCmd); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); } } /************************************************************************************************** 函 数 名 :QueryByItemId 功能描述 :基于ID查询 输出参数 :略 返 回 值 :CppSQLite3Query **************************************************************************************************/ CppSQLite3Query EquipDataPointManager::Query(DWORD iTaskId, LPCTSTR szEquipCode, DWORD iItemId) { try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); char szCmd[256]; sprintf_s(szCmd, "SELECT * FROM equip_data_point WHERE task_id=%d AND equip_code='%s' AND item_id=%d;", iTaskId, szEquipCode, iItemId); return pDB->execQuery(szCmd); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); } } CppSQLite3Query EquipDataPointManager::Query(DWORD iTaskId, LPCTSTR szEquipCode, DWORD iItemId, DWORD iSubitemId) { try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); char szCmd[256]; sprintf_s(szCmd, "SELECT * FROM equip_data_point WHERE task_id=%d AND equip_code='%s' AND item_id=%d AND subitem_id =%d;", iTaskId, szEquipCode, iItemId, iSubitemId); return pDB->execQuery(szCmd); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); } } CppSQLite3Query EquipDataPointManager::QueryOfReport(DWORD iTaskId) { CString szPoints = AppConfig::GetString(_T("Report"), _T("Static_Points")); CStringArray arrPoints; Utils::StrSplit(szPoints, ",", arrPoints); int iNum = (int)arrPoints.GetCount(); CString szCond; for (int i = 0; i < iNum; i++) { if (i > 0) szCond.Append(","); szCond.Append("'"); szCond.Append(arrPoints[i]); szCond.Append("'"); } try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); char szCmd[256]; if (iNum > 0) { sprintf_s(szCmd, "SELECT * FROM equip_data_point WHERE task_id=%d AND point_code in (%s);", iTaskId, szCond.GetBuffer()); } else { sprintf_s(szCmd, "SELECT * FROM equip_data_point WHERE task_id=%d;", iTaskId); } return pDB->execQuery(szCmd); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); } } /************************************************************************************************** 函 数 名 :Add 功能描述 :增加 输入参数 :略 输出参数 :略 返 回 值 :TRUE 成功;FALSE 失败 **************************************************************************************************/ BOOL EquipDataPointManager::Add(const EquipDataPoint& data) { DWORD iTaskId = data.GetTaskId(); CString szEquipCode = data.GetEquipCode(); DWORD iItemId = data.GetItemId(); DWORD iSubItemId = data.GetSubItemId(); CString szPointTitle = data.GetPointTitle(); CString szPointCode = data.GetPointCode(); DOUBLE fPointEX = data.GetPointEX(); DOUBLE fPointEY = data.GetPointEY(); DOUBLE fPointEZ = data.GetPointEZ(); DOUBLE fPointAX = data.GetPointAX(); DOUBLE fPointAY = data.GetPointAY(); DOUBLE fPointAZ = data.GetPointAZ(); DOUBLE fPointTotal = data.GetPointTotal(); CString szPointDesc = data.GetPointDesc(); try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); CppSQLite3Buffer bufSQL; bufSQL.format("INSERT INTO equip_data_point (" " task_id, " " equip_code, " " item_id, " " subitem_id, " " point_title, " " point_code, " " point_a_x, " " point_a_y, " " point_a_z, " " point_e_x, " " point_e_y, " " point_e_z, " " point_total, " " point_desc ) " " VALUES (%d, %Q, %d, %d, %Q, %Q, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %Q); ", iTaskId, szEquipCode, iItemId, iSubItemId, szPointTitle, szPointCode, fPointAX, fPointAY, fPointAZ, fPointEX, fPointEY, fPointEZ, fPointTotal, szPointDesc ); pDB->execDML("begin transaction;"); pDB->execDML(bufSQL); pDB->execDML("commit transaction;"); bufSQL.clear(); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); return FALSE; } return TRUE; } /************************************************************************************************** 函 数 名 :Update 功能描述 :更新 输入参数 :略 输出参数 :略 返 回 值 :TRUE 成功;FALSE 失败 **************************************************************************************************/ BOOL EquipDataPointManager::Update(const EquipDataPoint& data) { DWORD iTaskId = data.GetTaskId(); CString szEquipCode = data.GetEquipCode(); DWORD iItemId = data.GetItemId(); DWORD iSubItemId = data.GetSubItemId(); CString szPointTitle = data.GetPointTitle(); CString szPointCode = data.GetPointCode(); DOUBLE fPointEX = data.GetPointEX(); DOUBLE fPointEY = data.GetPointEY(); DOUBLE fPointEZ = data.GetPointEZ(); DOUBLE fPointAX = data.GetPointAX(); DOUBLE fPointAY = data.GetPointAY(); DOUBLE fPointAZ = data.GetPointAZ(); DOUBLE fPointTotal = data.GetPointTotal(); CString szPointDesc = data.GetPointDesc(); try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); CppSQLite3Buffer bufSQL; bufSQL.format("UPDATE equip_data_point " " SET point_title= %Q, " " point_code = %Q, " " point_e_x = %.3f, " " point_e_y = %.3f, " " point_e_z = %.3f, " " point_a_x = %.3f, " " point_a_y = %.3f, " " point_a_z = %.3f, " " point_total= %.3f, " " point_desc = %Q " " WHERE task_id=%d AND equip_code=%Q AND item_id=%d AND subitem_id=%d;", szPointTitle, szPointCode, fPointEX, fPointEY, fPointEZ, fPointAX, fPointAY, fPointAZ, fPointTotal, szPointDesc, iTaskId, szEquipCode, iItemId, iSubItemId); pDB->execDML("begin transaction;"); int affected = pDB->execDML(bufSQL); pDB->execDML("commit transaction;"); bufSQL.clear(); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); return FALSE; } return TRUE; } /************************************************************************************************** 函 数 名 :Update 功能描述 :更新 输入参数 :略 输出参数 :略 返 回 值 :TRUE 成功;FALSE 失败 **************************************************************************************************/ BOOL EquipDataPointManager::UpdateTitle(DWORD iTaskId, LPCTSTR szEquipCode, DWORD iItemId, DWORD iSubitemId, LPCTSTR szPointTitle) { try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); CppSQLite3Buffer bufSQL; bufSQL.format("UPDATE equip_data_point SET point_title = %Q WHERE task_id=%d AND equip_code=%Q AND item_id=%d AND subitem_id=%d;", szPointTitle, iTaskId, szEquipCode, iItemId, iSubitemId); pDB->execDML("begin transaction;"); int affected = pDB->execDML(bufSQL); pDB->execDML("commit transaction;"); bufSQL.clear(); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); return FALSE; } return TRUE; } /************************************************************************************************** 函 数 名 :Delete 功能描述 :删除 输入参数 :略 输出参数 :略 返 回 值 :TRUE 成功;FALSE 失败 **************************************************************************************************/ BOOL EquipDataPointManager::Delete(DWORD iTaskId) { try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); CppSQLite3Buffer bufSQL; bufSQL.format("DELETE FROM equip_data_point WHERE task_id=%d;", iTaskId); pDB->execDML("begin transaction;"); pDB->execDML(bufSQL); pDB->execDML("commit transaction;"); bufSQL.clear(); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); return FALSE; } return TRUE; } BOOL EquipDataPointManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode) { try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); CppSQLite3Buffer bufSQL; bufSQL.format("DELETE FROM equip_data_point WHERE task_id=%d AND equip_code=%Q;", iTaskId, szEquipCode); pDB->execDML("begin transaction;"); pDB->execDML(bufSQL); pDB->execDML("commit transaction;"); bufSQL.clear(); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); return FALSE; } return TRUE; } BOOL EquipDataPointManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode, DWORD iItemId) { try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); CppSQLite3Buffer bufSQL; bufSQL.format("DELETE FROM equip_data_point WHERE task_id=%d AND equip_code=%Q AND item_id=%d;", iTaskId, szEquipCode, iItemId); pDB->execDML("begin transaction;"); pDB->execDML(bufSQL); pDB->execDML("commit transaction;"); bufSQL.clear(); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); return FALSE; } return TRUE; } BOOL EquipDataPointManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode, DWORD iItemId, DWORD iSubitemId) { try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); CppSQLite3Buffer bufSQL; bufSQL.format("DELETE FROM equip_data_point WHERE task_id=%d AND equip_code=%Q AND item_id=%d AND subitem_id=%d;", iTaskId, szEquipCode, iItemId, iSubitemId); pDB->execDML("begin transaction;"); pDB->execDML(bufSQL); pDB->execDML("commit transaction;"); bufSQL.clear(); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); return FALSE; } return TRUE; } /************************************************************************************************** 函 数 名 :ClearAll 功能描述 :清除所有数据 输入参数 :略 输出参数 :略 返 回 值 :TRUE 成功;FALSE 失败 **************************************************************************************************/ BOOL EquipDataPointManager::ClearAll() { try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); CppSQLite3Buffer bufSQL; bufSQL.format("DELETE FROM equip_data_point;");//删除语句 pDB->execDML("begin transaction;"); pDB->execDML(bufSQL); pDB->execDML("commit transaction;"); bufSQL.clear(); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); return FALSE; } return TRUE; } /************************************************************************************************** 函 数 名 :Count 功能描述 :根据条件查询记录数目 输入参数 :略 输出参数 :略 返 回 值 :TRUE 成功;FALSE 失败 **************************************************************************************************/ int EquipDataPointManager::Count(DWORD iTaskId) { int iCount = 0; try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); char szCmd[256]; sprintf_s(szCmd, "SELECT COUNT(*) AS NUM FROM equip_data_point WHERE task_id ='%d';", iTaskId); CppSQLite3Query q = pDB->execQuery(szCmd); iCount = q.getIntField("NUM"); q.finalize(); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); iCount = 0; } return iCount; } /************************************************************************************************** 函 数 名 :Count 功能描述 :根据条件查询记录数目 输入参数 :略 输出参数 :略 返 回 值 :TRUE 成功;FALSE 失败 **************************************************************************************************/ int EquipDataPointManager::CountOfReport(DWORD iTaskId) { int iCount = 0; CString szPoints = AppConfig::GetString(_T("Report"), _T("Static_Points")); CStringArray arrPoints; Utils::StrSplit(szPoints, ",", arrPoints); int iNum = (int)arrPoints.GetCount(); CString szCond; for (int i = 0; i < iNum; i++) { if (i > 0) szCond.Append(","); szCond.Append("'"); szCond.Append(arrPoints[i]); szCond.Append("'"); } try { CppSQLite3DB* pDB = DBFactory::GetSQLite(); char szCmd[256]; if (iNum > 0) { sprintf_s(szCmd, "SELECT COUNT(*) AS NUM FROM equip_data_point WHERE task_id =%d AND point_code in(%s);", iTaskId, szCond.GetBuffer()); } else { sprintf_s(szCmd, "SELECT COUNT(*) AS NUM FROM equip_data_point WHERE task_id =%d;", iTaskId); } CppSQLite3Query q = pDB->execQuery(szCmd); iCount = q.getIntField("NUM"); q.finalize(); } catch (CppSQLite3Exception& e) { LOG::E(e.errorMessage()); iCount = 0; } return iCount; }