PostureDataAngleManager.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. /**************************************************************************************************
  2. 版本所有(C), 2021-2022, 北京普达迪泰
  3. ***************************************************************************************************
  4. 文 件 名:PostureDataAngleManager.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 "PostureDataAngleManager.h"
  18. #include "CppSQLite3.h"
  19. #include "DBFactory.h"
  20. #include "PostureDataAngle.h"
  21. PostureDataAngleManager::PostureDataAngleManager()
  22. {
  23. }
  24. PostureDataAngleManager::~PostureDataAngleManager()
  25. {
  26. }
  27. /**************************************************************************************************
  28. 函 数 名 :Query
  29. 功能描述 :查询
  30. 输出参数 :略
  31. 返 回 值 :CppSQLite3Query
  32. **************************************************************************************************/
  33. CppSQLite3Query PostureDataAngleManager::Query(DWORD iTaskId)
  34. {
  35. try
  36. {
  37. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  38. char szCmd[256];
  39. sprintf_s(szCmd, "SELECT * FROM posture_data_angle 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 PostureDataAngleManager::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_angle 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 PostureDataAngleManager::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_angle 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 PostureDataAngleManager::Query(DWORD iTaskId, LPCTSTR szEquipCode, LPCTSTR szEquipPlace, DWORD iAngleId)
  76. {
  77. try
  78. {
  79. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  80. char szCmd[256];
  81. sprintf_s(szCmd, "SELECT * FROM posture_data_angle WHERE task_id=%d AND equip_code='%s' AND equip_place='%s';", iTaskId, szEquipCode, szEquipPlace);
  82. return pDB->execQuery(szCmd);
  83. }
  84. catch (CppSQLite3Exception& e)
  85. {
  86. LOG::E(e.errorMessage());
  87. }
  88. }
  89. /**************************************************************************************************
  90. 函 数 名 :Add
  91. 功能描述 :增加TaskData
  92. 输入参数 :点云数据
  93. 输出参数 :无
  94. 返 回 值 :TRUE 成功;FALSE 失败
  95. **************************************************************************************************/
  96. BOOL PostureDataAngleManager::Add(const PostureDataAngle& data)
  97. {
  98. DWORD iTaskId = data.GetTaskId();
  99. CString szEquipCode = data.GetEquipCode();
  100. CString szEquipPlace = data.GetEquipPlace();
  101. DWORD iLineId = data.GetLineId();
  102. CString szLineTitle = data.GetLineTitle();
  103. CString szLineCode = data.GetLineCode();
  104. DOUBLE fLineStartX = data.GetLineStartX();
  105. DOUBLE fLineStartY = data.GetLineStartY();
  106. DOUBLE fLineStartZ = data.GetLineStartZ();
  107. DOUBLE fLineEndX = data.GetLineEndX();
  108. DOUBLE fLineEndY = data.GetLineEndY();
  109. DOUBLE fLineEndZ = data.GetLineEndZ();
  110. DOUBLE fAngleEX = data.GetAngleEX();
  111. DOUBLE fAngleEY = data.GetAngleEY();
  112. DOUBLE fAngleEZ = data.GetAngleEZ();
  113. DOUBLE fAngleAX = data.GetAngleAX();
  114. DOUBLE fAngleAY = data.GetAngleAY();
  115. DOUBLE fAngleAZ = data.GetAngleAZ();
  116. CString szLineDesc = data.GetLineDesc();
  117. try
  118. {
  119. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  120. CppSQLite3Buffer bufSQL;
  121. bufSQL.format("INSERT INTO posture_data_angle"
  122. " ( task_id, "
  123. " equip_code, "
  124. " equip_place, "
  125. " line_id, "
  126. " line_title, "
  127. " line_code, "
  128. " line_start_x, "
  129. " line_start_y, "
  130. " line_start_z, "
  131. " line_end_x, "
  132. " line_end_y, "
  133. " line_end_z, "
  134. " angle_e_x, "
  135. " angle_e_y, "
  136. " angle_e_z, "
  137. " angle_a_x, "
  138. " angle_a_y, "
  139. " angle_a_z, "
  140. " line_desc) "
  141. " VALUES (%d, %Q, %Q, %d, %Q, %Q, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %Q);",
  142. iTaskId,
  143. szEquipCode,
  144. szEquipPlace,
  145. iLineId,
  146. szLineTitle,
  147. szLineCode,
  148. fLineStartX,
  149. fLineStartY,
  150. fLineStartZ,
  151. fLineEndX,
  152. fLineEndY,
  153. fLineEndZ,
  154. fAngleEX,
  155. fAngleEY,
  156. fAngleEZ,
  157. fAngleAX,
  158. fAngleAY,
  159. fAngleAZ,
  160. szLineDesc);
  161. pDB->execDML("begin transaction;");
  162. pDB->execDML(bufSQL);
  163. pDB->execDML("commit transaction;");
  164. bufSQL.clear();
  165. }
  166. catch (CppSQLite3Exception& e)
  167. {
  168. LOG::E(e.errorMessage());
  169. return FALSE;
  170. }
  171. return TRUE;
  172. }
  173. /**************************************************************************************************
  174. 函 数 名 :Update
  175. 功能描述 :更新
  176. 输入参数 :略
  177. 输出参数 :无
  178. 返 回 值 :TRUE 成功;FALSE 失败
  179. **************************************************************************************************/
  180. BOOL PostureDataAngleManager::Update(const PostureDataAngle& data)
  181. {
  182. DWORD iTaskId = data.GetTaskId();
  183. CString szEquipCode = data.GetEquipCode();
  184. CString szEquipPlace = data.GetEquipPlace();
  185. DWORD iLineId = data.GetLineId();
  186. CString szLineTitle = data.GetLineTitle();
  187. CString szLineCode = data.GetLineCode();
  188. DOUBLE fAngelAX = data.GetAngleAX();
  189. DOUBLE fAngelAY = data.GetAngleAY();
  190. DOUBLE fAngelAZ = data.GetAngleAZ();
  191. DOUBLE fAngelEX = data.GetAngleEX();
  192. DOUBLE fAngelEY = data.GetAngleEY();
  193. DOUBLE fAngelEZ = data.GetAngleEZ();
  194. CString szLineDesc = data.GetLineDesc();
  195. try
  196. {
  197. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  198. CppSQLite3Buffer bufSQL;
  199. bufSQL.format("UPDATE posture_data_angle "
  200. " SET line_title=%Q, "
  201. " line_code=%Q, "
  202. " angle_a_x=%.3f, "
  203. " angle_a_y=%.3f, "
  204. " angle_a_z=%.3f, "
  205. " line_desc=%Q "
  206. " WHERE equip_code=%Q AND equip_place=%Q AND line_id = %d; ",
  207. szLineTitle,
  208. szLineCode,
  209. fAngelAX,
  210. fAngelAY,
  211. fAngelAZ,
  212. szLineDesc,
  213. szEquipCode,
  214. szEquipPlace,
  215. iLineId);
  216. pDB->execDML("begin transaction;");
  217. int affected = pDB->execDML(bufSQL);
  218. pDB->execDML("commit transaction;");
  219. bufSQL.clear();
  220. }
  221. catch (CppSQLite3Exception& e)
  222. {
  223. LOG::E(e.errorMessage());
  224. return FALSE;
  225. }
  226. return TRUE;
  227. }
  228. /**************************************************************************************************
  229. 函 数 名 :Delete
  230. 功能描述 :删除
  231. 输入参数 :主键
  232. 输出参数 :无
  233. 返 回 值 :TRUE 成功;FALSE 失败
  234. **************************************************************************************************/
  235. BOOL PostureDataAngleManager::Delete(DWORD iTaskId)
  236. {
  237. try
  238. {
  239. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  240. CppSQLite3Buffer bufSQL;
  241. bufSQL.format("DELETE FROM posture_data_angle WHERE task_id = %d;", iTaskId);
  242. pDB->execDML("begin transaction;");
  243. pDB->execDML(bufSQL);
  244. pDB->execDML("commit transaction;");
  245. bufSQL.clear();
  246. }
  247. catch (CppSQLite3Exception& e)
  248. {
  249. LOG::E(e.errorMessage());
  250. return FALSE;
  251. }
  252. return TRUE;
  253. }
  254. BOOL PostureDataAngleManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode)
  255. {
  256. try
  257. {
  258. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  259. CppSQLite3Buffer bufSQL;
  260. bufSQL.format("DELETE FROM posture_data_angle WHERE task_id=%d AND equip_code=%Q;", iTaskId, szEquipCode);
  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 PostureDataAngleManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode, LPCTSTR szEquipPlace)
  274. {
  275. try
  276. {
  277. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  278. CppSQLite3Buffer bufSQL;
  279. bufSQL.format("DELETE FROM posture_data_angle WHERE task_id=%d AND equip_code=%Q AND equip_place=%Q;", iTaskId, szEquipCode, szEquipPlace);
  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 PostureDataAngleManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode, LPCTSTR szEquipPlace, DWORD iLineId)
  293. {
  294. try
  295. {
  296. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  297. CppSQLite3Buffer bufSQL;
  298. bufSQL.format("DELETE FROM posture_data_angle WHERE task_id=%d AND equip_code=%Q AND equip_place=%Q AND line_id=%d;", iTaskId, szEquipCode, szEquipPlace, iLineId);
  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. /**************************************************************************************************
  312. 函 数 名 :ClearAll
  313. 功能描述 :清除数据
  314. 输入参数 :略
  315. 输出参数 :略
  316. 返 回 值 :TRUE 成功;FALSE 失败
  317. **************************************************************************************************/
  318. BOOL PostureDataAngleManager::ClearAll()
  319. {
  320. try
  321. {
  322. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  323. CppSQLite3Buffer bufSQL;
  324. bufSQL.format("DELETE FROM posture_data_angle;");//删除语句
  325. pDB->execDML("begin transaction;");
  326. pDB->execDML(bufSQL);
  327. pDB->execDML("commit transaction;");
  328. bufSQL.clear();
  329. }
  330. catch (CppSQLite3Exception& e)
  331. {
  332. LOG::E(e.errorMessage());
  333. return FALSE;
  334. }
  335. return TRUE;
  336. }
  337. /**************************************************************************************************
  338. 函 数 名 :Count
  339. 功能描述 :根据条件查询记录数目
  340. 输入参数 :略
  341. 输出参数 :略
  342. 返 回 值 :TRUE 成功;FALSE 失败
  343. **************************************************************************************************/
  344. int PostureDataAngleManager::Count(DWORD iTaskId)
  345. {
  346. int iCount = 0;
  347. try
  348. {
  349. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  350. char szCmd[256];
  351. sprintf_s(szCmd, "SELECT COUNT(*) AS NUM FROM posture_data_angle WHERE task_id = %d;", iTaskId);
  352. CppSQLite3Query q = pDB->execQuery(szCmd);
  353. iCount = q.getIntField("NUM");
  354. q.finalize();
  355. }
  356. catch (CppSQLite3Exception& e)
  357. {
  358. LOG::E(e.errorMessage());
  359. iCount = 0;
  360. }
  361. return iCount;
  362. }