EquipDataCylinderManager.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. /**************************************************************************************************
  2. 版本所有(C), 2021-2022, 北京普达迪泰
  3. ***************************************************************************************************
  4. 文 件 名:EquipDataCylinderManager.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 "EquipDataCylinderManager.h"
  18. #include "CppSQLite3.h"
  19. #include "DBFactory.h"
  20. #include "EquipDataCylinder.h"
  21. EquipDataCylinderManager::EquipDataCylinderManager()
  22. {
  23. }
  24. EquipDataCylinderManager::~EquipDataCylinderManager()
  25. {
  26. }
  27. /**************************************************************************************************
  28. 函 数 名 :QueryAll
  29. 功能描述 :查询
  30. 输出参数 :略
  31. 返 回 值 :CppSQLite3Query
  32. **************************************************************************************************/
  33. CppSQLite3Query EquipDataCylinderManager::Query()
  34. {
  35. try
  36. {
  37. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  38. return pDB->execQuery(_T("SELECT * FROM equip_data_cylinder;"));
  39. }
  40. catch (CppSQLite3Exception& e)
  41. {
  42. LOG::E(e.errorMessage());
  43. }
  44. }
  45. CppSQLite3Query EquipDataCylinderManager::Query(DWORD iTaskId)
  46. {
  47. try
  48. {
  49. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  50. char szCmd[256];
  51. sprintf_s(szCmd, "SELECT * FROM equip_data_cylinder WHERE task_id ='%d';", iTaskId);
  52. return pDB->execQuery(szCmd);
  53. }
  54. catch (CppSQLite3Exception& e)
  55. {
  56. LOG::E(e.errorMessage());
  57. }
  58. }
  59. CppSQLite3Query EquipDataCylinderManager::Query(DWORD iTaskId, LPCTSTR szEquipCode)
  60. {
  61. try
  62. {
  63. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  64. char szCmd[256];
  65. sprintf_s(szCmd, "SELECT * FROM equip_data_cylinder WHERE task_id=%d AND equip_code ='%s';", iTaskId, szEquipCode);
  66. return pDB->execQuery(szCmd);
  67. }
  68. catch (CppSQLite3Exception& e)
  69. {
  70. LOG::E(e.errorMessage());
  71. }
  72. }
  73. CppSQLite3Query EquipDataCylinderManager::Query(DWORD iTaskId, LPCTSTR szEquipCode, DWORD itemId)
  74. {
  75. try
  76. {
  77. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  78. char szCmd[256];
  79. sprintf_s(szCmd, "SELECT * FROM equip_data_cylinder WHERE task_id=%d AND equip_code ='%s' AND item_id =%d;",iTaskId, szEquipCode, itemId);
  80. return pDB->execQuery(szCmd);
  81. }
  82. catch (CppSQLite3Exception& e)
  83. {
  84. LOG::E(e.errorMessage());
  85. }
  86. }
  87. CppSQLite3Query EquipDataCylinderManager::Query(DWORD iTaskId, LPCTSTR szEquipCode, DWORD iItemId, DWORD iSubitemId)
  88. {
  89. try
  90. {
  91. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  92. char szCmd[256];
  93. sprintf_s(szCmd, "SELECT * FROM equip_data_cylinder WHERE task_id=%d AND equip_code ='%s' AND item_id =%d AND subitem_id =%d;", iTaskId, szEquipCode, iItemId, iSubitemId);
  94. return pDB->execQuery(szCmd);
  95. }
  96. catch (CppSQLite3Exception& e)
  97. {
  98. LOG::E(e.errorMessage());
  99. }
  100. }
  101. /**************************************************************************************************
  102. 函 数 名 :Add
  103. 功能描述 :增加
  104. 输入参数 :略
  105. 输出参数 :略
  106. 返 回 值 :TRUE 成功;FALSE 失败
  107. **************************************************************************************************/
  108. BOOL EquipDataCylinderManager::Add(const EquipDataCylinder& data)
  109. {
  110. DWORD iTaskId = data.GetTaskId();
  111. CString szEquipCode = data.GetEquipCode();
  112. DWORD iItemId = data.GetItemId();
  113. DWORD iSubItemId = data.GetSubItemId();
  114. CString szCylinderTitle = data.GetCylinderTitle();
  115. CString szCylinderCode = data.GetCylinderCode();
  116. DOUBLE fPoint1X = data.GetPoint1X();
  117. DOUBLE fPoint1Y = data.GetPoint1Y();
  118. DOUBLE fPoint1Z = data.GetPoint1Z();
  119. DOUBLE fPoint2X = data.GetPoint2X();
  120. DOUBLE fPoint2Y = data.GetPoint2Y();
  121. DOUBLE fPoint2Z = data.GetPoint2Z();
  122. DOUBLE fCylinderRadius = data.GetCylinderRadius();
  123. DOUBLE fCylinderLength = data.GetCylinderLength();
  124. CString szCylinderDesc = data.GetCylinderDesc();
  125. try
  126. {
  127. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  128. CppSQLite3Buffer bufSQL;
  129. bufSQL.format("INSERT INTO equip_data_cylinder ( "
  130. " task_id, "
  131. " equip_code, "
  132. " item_id, "
  133. " subitem_id, "
  134. " cylinder_title, "
  135. " cylinder_code, "
  136. " point1_x, "
  137. " point1_y, "
  138. " point1_z, "
  139. " point2_x, "
  140. " point2_y, "
  141. " point2_z, "
  142. " cylinder_radius, "
  143. " cylinder_length, "
  144. " cylinder_desc ) "
  145. " VALUES (%d, %Q, %d, %d, %Q, %Q, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %Q);",
  146. iTaskId,
  147. szEquipCode,
  148. iItemId,
  149. iSubItemId,
  150. szCylinderTitle,
  151. szCylinderCode,
  152. fPoint1X,
  153. fPoint1Y,
  154. fPoint1Z,
  155. fPoint2X,
  156. fPoint2Y,
  157. fPoint2Z,
  158. fCylinderRadius,
  159. fCylinderLength,
  160. szCylinderDesc);
  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 EquipDataCylinderManager::Update(const EquipDataCylinder& data)
  181. {
  182. DWORD iTaskId = data.GetTaskId();
  183. CString szEquipCode = data.GetEquipCode();
  184. DWORD iItemId = data.GetItemId();
  185. DWORD iSubItemId = data.GetSubItemId();
  186. CString szCylinderTitle = data.GetCylinderTitle();
  187. CString szCylinderCode = data.GetCylinderCode();
  188. DOUBLE fPoint1X = data.GetPoint1X();
  189. DOUBLE fPoint1Y = data.GetPoint1Y();
  190. DOUBLE fPoint1Z = data.GetPoint1Z();
  191. DOUBLE fPoint2X = data.GetPoint2X();
  192. DOUBLE fPoint2Y = data.GetPoint2Y();
  193. DOUBLE fPoint2Z = data.GetPoint2Z();
  194. DOUBLE fCylinderRadius = data.GetCylinderRadius();
  195. DOUBLE fCylinderLength = data.GetCylinderLength();
  196. CString szCylinderDesc = data.GetCylinderDesc();
  197. try
  198. {
  199. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  200. CppSQLite3Buffer bufSQL;
  201. bufSQL.format(" UPDATE equip_data_cylinder "
  202. " SET cylinder_title = %Q, "
  203. " cylinder_code = %Q, "
  204. " point1_x = %.3f, "
  205. " point1_y = %.3f, "
  206. " point1_z = %.3f, "
  207. " point2_x = %.3f, "
  208. " point2_y = %.3f, "
  209. " point2_z = %.3f, "
  210. " cylinder_radius = %.3f, "
  211. " cylinder_length = %.3f, "
  212. " cylinder_desc = %Q "
  213. " WHERE task_id= %d AND equip_code=%Q AND item_id=%d AND subitem_id=%d;",
  214. szCylinderTitle,
  215. szCylinderCode,
  216. fPoint1X,
  217. fPoint1Y,
  218. fPoint1Z,
  219. fPoint2X,
  220. fPoint2Y,
  221. fPoint2Z,
  222. fCylinderRadius,
  223. fCylinderLength,
  224. szCylinderDesc,
  225. iTaskId,
  226. szEquipCode,
  227. iItemId,
  228. iSubItemId);
  229. pDB->execDML("begin transaction;");
  230. int affected = pDB->execDML(bufSQL);
  231. pDB->execDML("commit transaction;");
  232. bufSQL.clear();
  233. }
  234. catch (CppSQLite3Exception& e)
  235. {
  236. LOG::E(e.errorMessage());
  237. return FALSE;
  238. }
  239. return TRUE;
  240. }
  241. /**************************************************************************************************
  242. 函 数 名 :Update
  243. 功能描述 :更新
  244. 输入参数 :略
  245. 输出参数 :略
  246. 返 回 值 :TRUE 成功;FALSE 失败
  247. **************************************************************************************************/
  248. BOOL EquipDataCylinderManager::UpdateTitle(DWORD iTaskId, LPCTSTR szEquipCode, DWORD iItemId, DWORD iSubitemId, LPCTSTR szCylinderTitle)
  249. {
  250. try
  251. {
  252. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  253. CppSQLite3Buffer bufSQL;
  254. bufSQL.format("UPDATE equip_data_cylinder SET cylinder_title=%Q WHERE task_id=%d AND equip_code=%Q AND item_id=%d AND subitem_id=%d;",
  255. szCylinderTitle, iTaskId, szEquipCode, iItemId, iSubitemId);
  256. pDB->execDML("begin transaction;");
  257. int affected = pDB->execDML(bufSQL);
  258. pDB->execDML("commit transaction;");
  259. bufSQL.clear();
  260. }
  261. catch (CppSQLite3Exception& e)
  262. {
  263. LOG::E(e.errorMessage());
  264. return FALSE;
  265. }
  266. return TRUE;
  267. }
  268. /**************************************************************************************************
  269. 函 数 名 :Delete
  270. 功能描述 :删除
  271. 输入参数 :略
  272. 输出参数 :略
  273. 返 回 值 :TRUE 成功;FALSE 失败
  274. **************************************************************************************************/
  275. BOOL EquipDataCylinderManager::Delete(DWORD iTaskId)
  276. {
  277. try
  278. {
  279. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  280. CppSQLite3Buffer bufSQL;
  281. bufSQL.format("DELETE FROM equip_data_cylinder WHERE task_id=%d;", iTaskId);
  282. pDB->execDML("begin transaction;");
  283. pDB->execDML(bufSQL);
  284. pDB->execDML("commit transaction;");
  285. bufSQL.clear();
  286. }
  287. catch (CppSQLite3Exception& e)
  288. {
  289. LOG::E(e.errorMessage());
  290. return FALSE;
  291. }
  292. return TRUE;
  293. }
  294. BOOL EquipDataCylinderManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode)
  295. {
  296. try
  297. {
  298. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  299. CppSQLite3Buffer bufSQL;
  300. bufSQL.format("DELETE FROM equip_data_cylinder WHERE task_id=%d AND equip_code=%Q;", iTaskId, szEquipCode);
  301. pDB->execDML("begin transaction;");
  302. pDB->execDML(bufSQL);
  303. pDB->execDML("commit transaction;");
  304. bufSQL.clear();
  305. }
  306. catch (CppSQLite3Exception& e)
  307. {
  308. LOG::E(e.errorMessage());
  309. return FALSE;
  310. }
  311. return TRUE;
  312. }
  313. BOOL EquipDataCylinderManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode, DWORD iItemId)
  314. {
  315. try
  316. {
  317. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  318. CppSQLite3Buffer bufSQL;
  319. bufSQL.format("DELETE FROM equip_data_cylinder WHERE task_id=%d AND equip_code=%Q AND item_id=%d;", iTaskId, szEquipCode, iItemId);
  320. pDB->execDML("begin transaction;");
  321. pDB->execDML(bufSQL);
  322. pDB->execDML("commit transaction;");
  323. bufSQL.clear();
  324. }
  325. catch (CppSQLite3Exception& e)
  326. {
  327. LOG::E(e.errorMessage());
  328. return FALSE;
  329. }
  330. return TRUE;
  331. }
  332. BOOL EquipDataCylinderManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode, DWORD iItemId, DWORD iSubitemId)
  333. {
  334. try
  335. {
  336. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  337. CppSQLite3Buffer bufSQL;
  338. bufSQL.format("DELETE FROM equip_data_cylinder WHERE task_id=%d AND equip_code=%Q AND item_id=%d AND subitem_id=%d;", iTaskId, szEquipCode, iItemId, iSubitemId);
  339. pDB->execDML("begin transaction;");
  340. pDB->execDML(bufSQL);
  341. pDB->execDML("commit transaction;");
  342. bufSQL.clear();
  343. }
  344. catch (CppSQLite3Exception& e)
  345. {
  346. LOG::E(e.errorMessage());
  347. return FALSE;
  348. }
  349. return TRUE;
  350. }
  351. /**************************************************************************************************
  352. 函 数 名 :ClearAll
  353. 功能描述 :清除所有数据
  354. 输入参数 :略
  355. 输出参数 :略
  356. 返 回 值 :TRUE 成功;FALSE 失败
  357. **************************************************************************************************/
  358. BOOL EquipDataCylinderManager::ClearAll()
  359. {
  360. try
  361. {
  362. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  363. CppSQLite3Buffer bufSQL;
  364. bufSQL.format("DELETE FROM equip_data_cylinder");//删除语句
  365. pDB->execDML("begin transaction;");
  366. pDB->execDML(bufSQL);
  367. pDB->execDML("commit transaction;");
  368. bufSQL.clear();
  369. }
  370. catch (CppSQLite3Exception& e)
  371. {
  372. LOG::E(e.errorMessage());
  373. return FALSE;
  374. }
  375. return TRUE;
  376. }
  377. /**************************************************************************************************
  378. 函 数 名 :Count
  379. 功能描述 :根据条件查询记录数目
  380. 输入参数 :略
  381. 输出参数 :略
  382. 返 回 值 :TRUE 成功;FALSE 失败
  383. **************************************************************************************************/
  384. int EquipDataCylinderManager::Count(DWORD iTaskId)
  385. {
  386. int iCount = 0;
  387. try
  388. {
  389. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  390. char szCmd[256];
  391. sprintf_s(szCmd, "SELECT COUNT(*) AS NUM FROM equip_data_cylinder WHERE task_id ='%d';", iTaskId);
  392. CppSQLite3Query q = pDB->execQuery(szCmd);
  393. iCount = q.getIntField("NUM");
  394. q.finalize();
  395. }
  396. catch (CppSQLite3Exception& e)
  397. {
  398. LOG::E(e.errorMessage());
  399. iCount = 0;
  400. }
  401. return iCount;
  402. }