| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- /**************************************************************************************************
- 版本所有(C), 2021-2022, 北京普达迪泰
- ***************************************************************************************************
- 文 件 名:PostureDataPointManager.cpp
- 版 本 号: 1.00初版
- 作 者: HYF
- 生成日期:2021-12-20
- 最近修改:
- 功能描述: 位姿动态数据
- 函数列表:
- 修改历史:
- 1.日 期 : 2021-12-20
- 作 者 : HYF
- 修改内容 : 创建文件
- **************************************************************************************************/
- #include "pch.h"
- #include "PostureDataPointManager.h"
- #include "CppSQLite3.h"
- #include "DBFactory.h"
- #include "PostureDataPoint.h"
- PostureDataPointManager::PostureDataPointManager()
- {
- }
- PostureDataPointManager::~PostureDataPointManager()
- {
- }
- /**************************************************************************************************
- 函 数 名 :QueryByTaskId
- 功能描述 :查询
- 输出参数 :无
- 返 回 值 :CppSQLite3Query
- **************************************************************************************************/
- CppSQLite3Query PostureDataPointManager::Query(DWORD iTaskId)
- {
- try
- {
- CppSQLite3DB* pDB = DBFactory::GetSQLite();
- char szCmd[256];
- sprintf_s(szCmd, "SELECT * FROM posture_data_point WHERE task_id=%d;", iTaskId);
- return pDB->execQuery(szCmd);
- }
- catch (CppSQLite3Exception& e)
- {
- LOG::E(e.errorMessage());
- }
- }
- CppSQLite3Query PostureDataPointManager::Query(DWORD iTaskId, LPCTSTR szEquipCode)
- {
- try
- {
- CppSQLite3DB* pDB = DBFactory::GetSQLite();
- char szCmd[256];
- sprintf_s(szCmd, "SELECT * FROM posture_data_point WHERE task_id=%d AND equip_code='%s';", iTaskId, szEquipCode);
- return pDB->execQuery(szCmd);
- }
- catch (CppSQLite3Exception& e)
- {
- LOG::E(e.errorMessage());
- }
- }
- CppSQLite3Query PostureDataPointManager::Query(DWORD iTaskId, LPCTSTR szEquipCode, LPCTSTR szEquipPlace)
- {
- try
- {
- CppSQLite3DB* pDB = DBFactory::GetSQLite();
- char szCmd[256];
- sprintf_s(szCmd, "SELECT * FROM posture_data_point WHERE task_id=%d AND equip_code='%s' AND equip_place='%s';", iTaskId, szEquipCode, szEquipPlace);
- return pDB->execQuery(szCmd);
- }
- catch (CppSQLite3Exception& e)
- {
- LOG::E(e.errorMessage());
- }
- }
- CppSQLite3Query PostureDataPointManager::Query(DWORD iTaskId, LPCTSTR szEquipCode, LPCTSTR szEquipPlace, DWORD iPointId)
- {
- try
- {
- CppSQLite3DB* pDB = DBFactory::GetSQLite();
- char szCmd[256];
- sprintf_s(szCmd, "SELECT * FROM posture_data_point WHERE task_id=%d AND equip_code='%s' AND equip_place='%s' AND point_id=%d;", iTaskId, szEquipCode, szEquipPlace, iPointId);
- return pDB->execQuery(szCmd);
- }
- catch (CppSQLite3Exception& e)
- {
- LOG::E(e.errorMessage());
- }
- }
- CppSQLite3Query PostureDataPointManager::QueryOfReport(DWORD iTaskId)
- {
- CString szPoints = AppConfig::GetString(_T("Report"), _T("Dynamic_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 posture_data_point WHERE task_id=%d AND point_code in (%s);", iTaskId, szCond.GetBuffer());
- }
- else {
- sprintf_s(szCmd, "SELECT * FROM posture_data_point WHERE task_id=%d;", iTaskId);
- }
-
- return pDB->execQuery(szCmd);
- }
- catch (CppSQLite3Exception& e)
- {
- LOG::E(e.errorMessage());
- }
- }
- /**************************************************************************************************
- 函 数 名 :Add
- 功能描述 :增加TaskData
- 输入参数 :点云数据
- 输出参数 :无
- 返 回 值 :TRUE 成功;FALSE 失败
- **************************************************************************************************/
- BOOL PostureDataPointManager::Add(const PostureDataPoint& data)
- {
- DWORD iTaskId = data.GetTaskId();
- CString szEquipCode = data.GetEquipCode();
- CString szEquipPlace = data.GetEquipPlace();
- DWORD iPointId = data.GetPointId();
- 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();
- CString szPointDesc = data.GetPointDesc();
- try
- {
- CppSQLite3DB* pDB = DBFactory::GetSQLite();
- CppSQLite3Buffer bufSQL;
- bufSQL.format("INSERT INTO posture_data_point "
- " ( task_id, "
- " equip_code, "
- " equip_place, "
- " point_id, "
- " point_title, "
- " point_code, "
- " point_e_x, "
- " point_e_y, "
- " point_e_z, "
- " point_a_x, "
- " point_a_y, "
- " point_a_z, "
- " point_desc) "
- " VALUES (%d, %Q, %Q, %d, %Q, %Q, %f, %f, %f, %f, %f, %f, %Q);",
- iTaskId,
- szEquipCode,
- szEquipPlace,
- iPointId,
- szPointTitle,
- szPointCode,
- fPointEX,
- fPointEY,
- fPointEZ,
- fPointAX,
- fPointAY,
- fPointAZ,
- 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 PostureDataPointManager::Update(const PostureDataPoint& data)
- {
- DWORD iTaskId = data.GetTaskId();
- CString szEquipCode = data.GetEquipCode();
- CString szEquipPlace = data.GetEquipPlace();
- DWORD iPointId = data.GetPointId();
- 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();
- CString szPointDesc = data.GetPointDesc();
- try
- {
- CppSQLite3DB* pDB = DBFactory::GetSQLite();
- CppSQLite3Buffer bufSQL;
- bufSQL.format("UPDATE posture_data_point "
- " SET point_title=%Q, "
- " point_code=%Q, "
- " point_e_x=%f, "
- " point_e_y=%f, "
- " point_e_z=%f, "
- " point_a_x=%f, "
- " point_a_y=%f, "
- " point_a_z=%f, "
- " point_desc=%Q "
- " WHERE task_id=%d AND equip_code=%Q AND equip_place=%Q AND point_id = %d;",
- szPointTitle,
- szPointCode,
- fPointEX,
- fPointEY,
- fPointEZ,
- fPointAX,
- fPointAY,
- fPointAZ,
- szPointDesc,
- iTaskId,
- szEquipCode,
- szEquipPlace,
- iPointId);
- 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 PostureDataPointManager::Delete(DWORD iTaskId)
- {
- try
- {
- CppSQLite3DB* pDB = DBFactory::GetSQLite();
- CppSQLite3Buffer bufSQL;
- bufSQL.format("DELETE FROM posture_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 PostureDataPointManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode)
- {
- try
- {
- CppSQLite3DB* pDB = DBFactory::GetSQLite();
- CppSQLite3Buffer bufSQL;
- bufSQL.format("DELETE FROM posture_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 PostureDataPointManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode, LPCTSTR szEquipPlace)
- {
- try
- {
- CppSQLite3DB* pDB = DBFactory::GetSQLite();
- CppSQLite3Buffer bufSQL;
- bufSQL.format("DELETE FROM posture_data_point WHERE task_id = %d AND equip_code=%Q AND equip_place=%Q;", iTaskId, szEquipCode, szEquipPlace);
- 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 PostureDataPointManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode, LPCTSTR szEquipPlace, DWORD iPointId)
- {
- try
- {
- CppSQLite3DB* pDB = DBFactory::GetSQLite();
- CppSQLite3Buffer bufSQL;
- bufSQL.format("DELETE FROM posture_data_point WHERE task_id = %d AND equip_code=%Q AND equip_place=%Q AND point_id=%d;", iTaskId, szEquipCode, szEquipPlace, iPointId);
- 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 PostureDataPointManager::ClearAll()
- {
- try
- {
- CppSQLite3DB* pDB = DBFactory::GetSQLite();
- CppSQLite3Buffer bufSQL;
- bufSQL.format("DELETE FROM posture_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 PostureDataPointManager::Count(DWORD iTaskId)
- {
- int iCount = 0;
- try
- {
- CppSQLite3DB* pDB = DBFactory::GetSQLite();
- char szCmd[256];
- sprintf_s(szCmd, "SELECT COUNT(*) AS NUM FROM posture_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;
- }
- int PostureDataPointManager::CountOfReport(DWORD iTaskId)
- {
- CString szPoints = AppConfig::GetString(_T("Report"), _T("Dynamic_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("'");
- }
- int iCount = 0;
- try
- {
- CppSQLite3DB* pDB = DBFactory::GetSQLite();
- char szCmd[256];
- if (iNum > 0) {
- sprintf_s(szCmd, "SELECT COUNT(*) AS NUM FROM posture_data_point WHERE task_id = %d AND point_code in (%s);", iTaskId, szCond.GetBuffer());
- }
- else {
- sprintf_s(szCmd, "SELECT COUNT(*) AS NUM FROM posture_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;
- }
|