PostureDataPointManager.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. /**************************************************************************************************
  2. 版本所有(C), 2021-2022, 北京普达迪泰
  3. ***************************************************************************************************
  4. 文 件 名:PostureDataPointManager.cpp
  5. 版 本 号: 1.00初版
  6. 作 者: HYF
  7. 生成日期:2021-12-20
  8. 最近修改:
  9. 功能描述: 位姿动态数据
  10. 函数列表:
  11. 修改历史:
  12. 1.日 期 : 2021-12-20
  13. 作 者 : HYF
  14. 修改内容 : 创建文件
  15. **************************************************************************************************/
  16. #include "pch.h"
  17. #include "PostureDataPointManager.h"
  18. #include "CppSQLite3.h"
  19. #include "DBFactory.h"
  20. #include "PostureDataPoint.h"
  21. PostureDataPointManager::PostureDataPointManager()
  22. {
  23. }
  24. PostureDataPointManager::~PostureDataPointManager()
  25. {
  26. }
  27. /**************************************************************************************************
  28. 函 数 名 :QueryByTaskId
  29. 功能描述 :查询
  30. 输出参数 :无
  31. 返 回 值 :CppSQLite3Query
  32. **************************************************************************************************/
  33. CppSQLite3Query PostureDataPointManager::Query(DWORD iTaskId)
  34. {
  35. try
  36. {
  37. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  38. char szCmd[256];
  39. sprintf_s(szCmd, "SELECT * FROM posture_data_point WHERE task_id=%d;", iTaskId);
  40. return pDB->execQuery(szCmd);
  41. }
  42. catch (CppSQLite3Exception& e)
  43. {
  44. LOG::E(e.errorMessage());
  45. }
  46. }
  47. CppSQLite3Query PostureDataPointManager::Query(DWORD iTaskId, LPCTSTR szEquipCode)
  48. {
  49. try
  50. {
  51. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  52. char szCmd[256];
  53. sprintf_s(szCmd, "SELECT * FROM posture_data_point WHERE task_id=%d AND equip_code='%s';", iTaskId, szEquipCode);
  54. return pDB->execQuery(szCmd);
  55. }
  56. catch (CppSQLite3Exception& e)
  57. {
  58. LOG::E(e.errorMessage());
  59. }
  60. }
  61. CppSQLite3Query PostureDataPointManager::Query(DWORD iTaskId, LPCTSTR szEquipCode, LPCTSTR szEquipPlace)
  62. {
  63. try
  64. {
  65. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  66. char szCmd[256];
  67. sprintf_s(szCmd, "SELECT * FROM posture_data_point WHERE task_id=%d AND equip_code='%s' AND equip_place='%s';", iTaskId, szEquipCode, szEquipPlace);
  68. return pDB->execQuery(szCmd);
  69. }
  70. catch (CppSQLite3Exception& e)
  71. {
  72. LOG::E(e.errorMessage());
  73. }
  74. }
  75. CppSQLite3Query PostureDataPointManager::Query(DWORD iTaskId, LPCTSTR szEquipCode, LPCTSTR szEquipPlace, DWORD iPointId)
  76. {
  77. try
  78. {
  79. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  80. char szCmd[256];
  81. 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);
  82. return pDB->execQuery(szCmd);
  83. }
  84. catch (CppSQLite3Exception& e)
  85. {
  86. LOG::E(e.errorMessage());
  87. }
  88. }
  89. CppSQLite3Query PostureDataPointManager::QueryOfReport(DWORD iTaskId)
  90. {
  91. CString szPoints = AppConfig::GetString(_T("Report"), _T("Dynamic_Points"));
  92. CStringArray arrPoints;
  93. Utils::StrSplit(szPoints, ",", arrPoints);
  94. int iNum = (int)arrPoints.GetCount();
  95. CString szCond;
  96. for (int i = 0; i < iNum; i++) {
  97. if (i > 0) szCond.Append(",");
  98. szCond.Append("'");
  99. szCond.Append(arrPoints[i]);
  100. szCond.Append("'");
  101. }
  102. try
  103. {
  104. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  105. char szCmd[256];
  106. if (iNum > 0) {
  107. sprintf_s(szCmd, "SELECT * FROM posture_data_point WHERE task_id=%d AND point_code in (%s);", iTaskId, szCond.GetBuffer());
  108. }
  109. else {
  110. sprintf_s(szCmd, "SELECT * FROM posture_data_point WHERE task_id=%d;", iTaskId);
  111. }
  112. return pDB->execQuery(szCmd);
  113. }
  114. catch (CppSQLite3Exception& e)
  115. {
  116. LOG::E(e.errorMessage());
  117. }
  118. }
  119. /**************************************************************************************************
  120. 函 数 名 :Add
  121. 功能描述 :增加TaskData
  122. 输入参数 :点云数据
  123. 输出参数 :无
  124. 返 回 值 :TRUE 成功;FALSE 失败
  125. **************************************************************************************************/
  126. BOOL PostureDataPointManager::Add(const PostureDataPoint& data)
  127. {
  128. DWORD iTaskId = data.GetTaskId();
  129. CString szEquipCode = data.GetEquipCode();
  130. CString szEquipPlace = data.GetEquipPlace();
  131. DWORD iPointId = data.GetPointId();
  132. CString szPointTitle = data.GetPointTitle();
  133. CString szPointCode = data.GetPointCode();
  134. DOUBLE fPointEX = data.GetPointEX();
  135. DOUBLE fPointEY = data.GetPointEY();
  136. DOUBLE fPointEZ = data.GetPointEZ();
  137. DOUBLE fPointAX = data.GetPointAX();
  138. DOUBLE fPointAY = data.GetPointAY();
  139. DOUBLE fPointAZ = data.GetPointAZ();
  140. CString szPointDesc = data.GetPointDesc();
  141. try
  142. {
  143. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  144. CppSQLite3Buffer bufSQL;
  145. bufSQL.format("INSERT INTO posture_data_point "
  146. " ( task_id, "
  147. " equip_code, "
  148. " equip_place, "
  149. " point_id, "
  150. " point_title, "
  151. " point_code, "
  152. " point_e_x, "
  153. " point_e_y, "
  154. " point_e_z, "
  155. " point_a_x, "
  156. " point_a_y, "
  157. " point_a_z, "
  158. " point_desc) "
  159. " VALUES (%d, %Q, %Q, %d, %Q, %Q, %f, %f, %f, %f, %f, %f, %Q);",
  160. iTaskId,
  161. szEquipCode,
  162. szEquipPlace,
  163. iPointId,
  164. szPointTitle,
  165. szPointCode,
  166. fPointEX,
  167. fPointEY,
  168. fPointEZ,
  169. fPointAX,
  170. fPointAY,
  171. fPointAZ,
  172. szPointDesc );
  173. pDB->execDML("begin transaction;");
  174. pDB->execDML(bufSQL);
  175. pDB->execDML("commit transaction;");
  176. bufSQL.clear();
  177. }
  178. catch (CppSQLite3Exception& e)
  179. {
  180. LOG::E(e.errorMessage());
  181. return FALSE;
  182. }
  183. return TRUE;
  184. }
  185. /**************************************************************************************************
  186. 函 数 名 :Update
  187. 功能描述 :更新
  188. 输入参数 :略
  189. 输出参数 :无
  190. 返 回 值 :TRUE 成功;FALSE 失败
  191. **************************************************************************************************/
  192. BOOL PostureDataPointManager::Update(const PostureDataPoint& data)
  193. {
  194. DWORD iTaskId = data.GetTaskId();
  195. CString szEquipCode = data.GetEquipCode();
  196. CString szEquipPlace = data.GetEquipPlace();
  197. DWORD iPointId = data.GetPointId();
  198. CString szPointTitle = data.GetPointTitle();
  199. CString szPointCode = data.GetPointCode();
  200. DOUBLE fPointEX = data.GetPointEX();
  201. DOUBLE fPointEY = data.GetPointEY();
  202. DOUBLE fPointEZ = data.GetPointEZ();
  203. DOUBLE fPointAX = data.GetPointAX();
  204. DOUBLE fPointAY = data.GetPointAY();
  205. DOUBLE fPointAZ = data.GetPointAZ();
  206. CString szPointDesc = data.GetPointDesc();
  207. try
  208. {
  209. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  210. CppSQLite3Buffer bufSQL;
  211. bufSQL.format("UPDATE posture_data_point "
  212. " SET point_title=%Q, "
  213. " point_code=%Q, "
  214. " point_e_x=%f, "
  215. " point_e_y=%f, "
  216. " point_e_z=%f, "
  217. " point_a_x=%f, "
  218. " point_a_y=%f, "
  219. " point_a_z=%f, "
  220. " point_desc=%Q "
  221. " WHERE task_id=%d AND equip_code=%Q AND equip_place=%Q AND point_id = %d;",
  222. szPointTitle,
  223. szPointCode,
  224. fPointEX,
  225. fPointEY,
  226. fPointEZ,
  227. fPointAX,
  228. fPointAY,
  229. fPointAZ,
  230. szPointDesc,
  231. iTaskId,
  232. szEquipCode,
  233. szEquipPlace,
  234. iPointId);
  235. pDB->execDML("begin transaction;");
  236. int affected = pDB->execDML(bufSQL);
  237. pDB->execDML("commit transaction;");
  238. bufSQL.clear();
  239. }
  240. catch (CppSQLite3Exception& e)
  241. {
  242. LOG::E(e.errorMessage());
  243. return FALSE;
  244. }
  245. return TRUE;
  246. }
  247. /**************************************************************************************************
  248. 函 数 名 :Delete
  249. 功能描述 :删除
  250. 输入参数 :主键
  251. 输出参数 :无
  252. 返 回 值 :TRUE 成功;FALSE 失败
  253. **************************************************************************************************/
  254. BOOL PostureDataPointManager::Delete(DWORD iTaskId)
  255. {
  256. try
  257. {
  258. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  259. CppSQLite3Buffer bufSQL;
  260. bufSQL.format("DELETE FROM posture_data_point WHERE task_id = %d;", iTaskId);
  261. pDB->execDML("begin transaction;");
  262. pDB->execDML(bufSQL);
  263. pDB->execDML("commit transaction;");
  264. bufSQL.clear();
  265. }
  266. catch (CppSQLite3Exception& e)
  267. {
  268. LOG::E(e.errorMessage());
  269. return FALSE;
  270. }
  271. return TRUE;
  272. }
  273. BOOL PostureDataPointManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode)
  274. {
  275. try
  276. {
  277. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  278. CppSQLite3Buffer bufSQL;
  279. bufSQL.format("DELETE FROM posture_data_point WHERE task_id = %d AND equip_code=%Q;", iTaskId, szEquipCode);
  280. pDB->execDML("begin transaction;");
  281. pDB->execDML(bufSQL);
  282. pDB->execDML("commit transaction;");
  283. bufSQL.clear();
  284. }
  285. catch (CppSQLite3Exception& e)
  286. {
  287. LOG::E(e.errorMessage());
  288. return FALSE;
  289. }
  290. return TRUE;
  291. }
  292. BOOL PostureDataPointManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode, LPCTSTR szEquipPlace)
  293. {
  294. try
  295. {
  296. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  297. CppSQLite3Buffer bufSQL;
  298. bufSQL.format("DELETE FROM posture_data_point WHERE task_id = %d AND equip_code=%Q AND equip_place=%Q;", iTaskId, szEquipCode, szEquipPlace);
  299. pDB->execDML("begin transaction;");
  300. pDB->execDML(bufSQL);
  301. pDB->execDML("commit transaction;");
  302. bufSQL.clear();
  303. }
  304. catch (CppSQLite3Exception& e)
  305. {
  306. LOG::E(e.errorMessage());
  307. return FALSE;
  308. }
  309. return TRUE;
  310. }
  311. BOOL PostureDataPointManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode, LPCTSTR szEquipPlace, DWORD iPointId)
  312. {
  313. try
  314. {
  315. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  316. CppSQLite3Buffer bufSQL;
  317. 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);
  318. pDB->execDML("begin transaction;");
  319. pDB->execDML(bufSQL);
  320. pDB->execDML("commit transaction;");
  321. bufSQL.clear();
  322. }
  323. catch (CppSQLite3Exception& e)
  324. {
  325. LOG::E(e.errorMessage());
  326. return FALSE;
  327. }
  328. return TRUE;
  329. }
  330. /**************************************************************************************************
  331. 函 数 名 :ClearAll
  332. 功能描述 :清除数据
  333. 输入参数 :略
  334. 输出参数 :略
  335. 返 回 值 :TRUE 成功;FALSE 失败
  336. **************************************************************************************************/
  337. BOOL PostureDataPointManager::ClearAll()
  338. {
  339. try
  340. {
  341. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  342. CppSQLite3Buffer bufSQL;
  343. bufSQL.format("DELETE FROM posture_data_point;");//删除语句
  344. pDB->execDML("begin transaction;");
  345. pDB->execDML(bufSQL);
  346. pDB->execDML("commit transaction;");
  347. bufSQL.clear();
  348. }
  349. catch (CppSQLite3Exception& e)
  350. {
  351. LOG::E(e.errorMessage());
  352. return FALSE;
  353. }
  354. return TRUE;
  355. }
  356. /**************************************************************************************************
  357. 函 数 名 :Count
  358. 功能描述 :根据条件查询记录数目
  359. 输入参数 :略
  360. 输出参数 :略
  361. 返 回 值 :TRUE 成功;FALSE 失败
  362. **************************************************************************************************/
  363. int PostureDataPointManager::Count(DWORD iTaskId)
  364. {
  365. int iCount = 0;
  366. try
  367. {
  368. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  369. char szCmd[256];
  370. sprintf_s(szCmd, "SELECT COUNT(*) AS NUM FROM posture_data_point WHERE task_id = %d;", iTaskId);
  371. CppSQLite3Query q = pDB->execQuery(szCmd);
  372. iCount = q.getIntField("NUM");
  373. q.finalize();
  374. }
  375. catch (CppSQLite3Exception& e)
  376. {
  377. LOG::E(e.errorMessage());
  378. iCount = 0;
  379. }
  380. return iCount;
  381. }
  382. int PostureDataPointManager::CountOfReport(DWORD iTaskId)
  383. {
  384. CString szPoints = AppConfig::GetString(_T("Report"), _T("Dynamic_Points"));
  385. CStringArray arrPoints;
  386. Utils::StrSplit(szPoints, ",", arrPoints);
  387. int iNum = (int)arrPoints.GetCount();
  388. CString szCond;
  389. for (int i = 0; i < iNum; i++) {
  390. if (i > 0) szCond.Append(",");
  391. szCond.Append("'");
  392. szCond.Append(arrPoints[i]);
  393. szCond.Append("'");
  394. }
  395. int iCount = 0;
  396. try
  397. {
  398. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  399. char szCmd[256];
  400. if (iNum > 0) {
  401. sprintf_s(szCmd, "SELECT COUNT(*) AS NUM FROM posture_data_point WHERE task_id = %d AND point_code in (%s);", iTaskId, szCond.GetBuffer());
  402. }
  403. else {
  404. sprintf_s(szCmd, "SELECT COUNT(*) AS NUM FROM posture_data_point WHERE task_id = %d;", iTaskId);
  405. }
  406. CppSQLite3Query q = pDB->execQuery(szCmd);
  407. iCount = q.getIntField("NUM");
  408. q.finalize();
  409. }
  410. catch (CppSQLite3Exception& e)
  411. {
  412. LOG::E(e.errorMessage());
  413. iCount = 0;
  414. }
  415. return iCount;
  416. }