EquipDataAngleManager.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. #include "pch.h"
  2. #include "EquipDataAngleManager.h"
  3. #include "CppSQLite3.h"
  4. #include "DBFactory.h"
  5. #include "EquipDataAngle.h"
  6. EquipDataAngleManager::EquipDataAngleManager()
  7. {
  8. }
  9. EquipDataAngleManager::~EquipDataAngleManager()
  10. {
  11. }
  12. /**************************************************************************************************
  13. 函 数 名 :Query
  14. 功能描述 :查询
  15. 输出参数 :略
  16. 返 回 值 :CppSQLite3Query
  17. **************************************************************************************************/
  18. CppSQLite3Query EquipDataAngleManager::Query(DWORD iTaskId)
  19. {
  20. try
  21. {
  22. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  23. char szCmd[256];
  24. sprintf_s(szCmd, "SELECT * FROM equip_data_angle WHERE task_id=%d;", iTaskId);
  25. return pDB->execQuery(szCmd);
  26. }
  27. catch (CppSQLite3Exception& e)
  28. {
  29. LOG::E(e.errorMessage());
  30. }
  31. }
  32. CppSQLite3Query EquipDataAngleManager::Query(DWORD iTaskId, LPCTSTR szEquipCode)
  33. {
  34. try
  35. {
  36. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  37. char szCmd[256];
  38. sprintf_s(szCmd, "SELECT * FROM equip_data_angle WHERE task_id=%d AND equip_code='%s';", iTaskId, szEquipCode);
  39. return pDB->execQuery(szCmd);
  40. }
  41. catch (CppSQLite3Exception& e)
  42. {
  43. LOG::E(e.errorMessage());
  44. }
  45. }
  46. CppSQLite3Query EquipDataAngleManager::Query(DWORD iTaskId, LPCTSTR szEquipCode, DWORD iSubItemId)
  47. {
  48. try
  49. {
  50. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  51. char szCmd[256];
  52. sprintf_s(szCmd, "SELECT * FROM equip_data_angle WHERE task_id=%d AND equip_code='%s' AND subitem_id='%d';", iTaskId, szEquipCode, iSubItemId);
  53. return pDB->execQuery(szCmd);
  54. }
  55. catch (CppSQLite3Exception& e)
  56. {
  57. LOG::E(e.errorMessage());
  58. }
  59. }
  60. /**************************************************************************************************
  61. 函 数 名 :Add
  62. 功能描述 :增加TaskData
  63. 输入参数 :点云数据
  64. 输出参数 :无
  65. 返 回 值 :TRUE 成功;FALSE 失败
  66. **************************************************************************************************/
  67. BOOL EquipDataAngleManager::Add(const EquipDataAngle& data)
  68. {
  69. DWORD iTaskId = data.GetTaskId();
  70. CString szEquipCode = data.GetEquipCode();
  71. DWORD iItemId = data.GetItemId();
  72. DWORD iSubitemId = data.GetSubItemId();
  73. CString szLineTitle = data.GetLineTitle();
  74. CString szLineCode = data.GetLineCode();
  75. DOUBLE fLineStartX = data.GetLineStartX();
  76. DOUBLE fLineStartY = data.GetLineStartY();
  77. DOUBLE fLineStartZ = data.GetLineStartZ();
  78. DOUBLE fLineEndX = data.GetLineEndX();
  79. DOUBLE fLineEndY = data.GetLineEndY();
  80. DOUBLE fLineEndZ = data.GetLineEndZ();
  81. DOUBLE fAngleEX = data.GetAngleEX();
  82. DOUBLE fAngleEY = data.GetAngleEY();
  83. DOUBLE fAngleEZ = data.GetAngleEZ();
  84. DOUBLE fAngleAX = data.GetAngleAX();
  85. DOUBLE fAngleAY = data.GetAngleAY();
  86. DOUBLE fAngleAZ = data.GetAngleAZ();
  87. CString szLineDesc = data.GetLineDesc();
  88. try
  89. {
  90. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  91. CppSQLite3Buffer bufSQL;
  92. bufSQL.format("INSERT INTO equip_data_angle"
  93. " ( task_id, "
  94. " equip_code, "
  95. " item_id, "
  96. " subitem_id, "
  97. " line_title, "
  98. " line_code, "
  99. " line_start_x, "
  100. " line_start_y, "
  101. " line_start_z, "
  102. " line_end_x, "
  103. " line_end_y, "
  104. " line_end_z, "
  105. " angle_e_x, "
  106. " angle_e_y, "
  107. " angle_e_z, "
  108. " angle_a_x, "
  109. " angle_a_y, "
  110. " angle_a_z, "
  111. " line_desc) "
  112. " VALUES (%d, %Q, %d, %d, %Q, %Q, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %Q);",
  113. iTaskId,
  114. szEquipCode,
  115. iItemId,
  116. iSubitemId,
  117. szLineTitle,
  118. szLineCode,
  119. fLineStartX,
  120. fLineStartY,
  121. fLineStartZ,
  122. fLineEndX,
  123. fLineEndY,
  124. fLineEndZ,
  125. fAngleEX,
  126. fAngleEY,
  127. fAngleEZ,
  128. fAngleAX,
  129. fAngleAY,
  130. fAngleAZ,
  131. szLineDesc);
  132. pDB->execDML("begin transaction;");
  133. pDB->execDML(bufSQL);
  134. pDB->execDML("commit transaction;");
  135. bufSQL.clear();
  136. }
  137. catch (CppSQLite3Exception& e)
  138. {
  139. LOG::E(e.errorMessage());
  140. return FALSE;
  141. }
  142. return TRUE;
  143. }
  144. /**************************************************************************************************
  145. 函 数 名 :Update
  146. 功能描述 :更新
  147. 输入参数 :略
  148. 输出参数 :无
  149. 返 回 值 :TRUE 成功;FALSE 失败
  150. **************************************************************************************************/
  151. BOOL EquipDataAngleManager::Update(const EquipDataAngle& data)
  152. {
  153. DWORD iTaskId = data.GetTaskId();
  154. CString szEquipCode = data.GetEquipCode();
  155. DWORD iSubitemId = data.GetSubItemId();
  156. CString szLineTitle = data.GetLineTitle();
  157. CString szLineCode = data.GetLineCode();
  158. DOUBLE fAngelAX = data.GetAngleAX();
  159. DOUBLE fAngelAY = data.GetAngleAY();
  160. DOUBLE fAngelAZ = data.GetAngleAZ();
  161. DOUBLE fAngelEX = data.GetAngleEX();
  162. DOUBLE fAngelEY = data.GetAngleEY();
  163. DOUBLE fAngelEZ = data.GetAngleEZ();
  164. CString szLineDesc = data.GetLineDesc();
  165. try
  166. {
  167. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  168. CppSQLite3Buffer bufSQL;
  169. bufSQL.format("UPDATE equip_data_angle "
  170. " SET line_title=%Q, "
  171. " line_code=%Q, "
  172. " angle_a_x=%.3f, "
  173. " angle_a_y=%.3f, "
  174. " angle_a_z=%.3f, "
  175. " line_desc=%Q "
  176. " WHERE task_id=%d AND equip_code=%Q AND subitem_id = %d; ",
  177. szLineTitle,
  178. szLineCode,
  179. fAngelAX,
  180. fAngelAY,
  181. fAngelAZ,
  182. szLineDesc,
  183. iTaskId,
  184. szEquipCode,
  185. iSubitemId);
  186. pDB->execDML("begin transaction;");
  187. int affected = pDB->execDML(bufSQL);
  188. pDB->execDML("commit transaction;");
  189. bufSQL.clear();
  190. }
  191. catch (CppSQLite3Exception& e)
  192. {
  193. LOG::E(e.errorMessage());
  194. return FALSE;
  195. }
  196. return TRUE;
  197. }
  198. /**************************************************************************************************
  199. 函 数 名 :Delete
  200. 功能描述 :删除
  201. 输入参数 :主键
  202. 输出参数 :无
  203. 返 回 值 :TRUE 成功;FALSE 失败
  204. **************************************************************************************************/
  205. BOOL EquipDataAngleManager::Delete(DWORD iTaskId)
  206. {
  207. try
  208. {
  209. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  210. CppSQLite3Buffer bufSQL;
  211. bufSQL.format("DELETE FROM equip_data_angle WHERE task_id=%d;", iTaskId);
  212. pDB->execDML("begin transaction;");
  213. pDB->execDML(bufSQL);
  214. pDB->execDML("commit transaction;");
  215. bufSQL.clear();
  216. }
  217. catch (CppSQLite3Exception& e)
  218. {
  219. LOG::E(e.errorMessage());
  220. return FALSE;
  221. }
  222. return TRUE;
  223. }
  224. BOOL EquipDataAngleManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode)
  225. {
  226. try
  227. {
  228. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  229. CppSQLite3Buffer bufSQL;
  230. bufSQL.format("DELETE FROM equip_data_angle WHERE task_id=%d AND equip_code=%Q;", iTaskId, szEquipCode);
  231. pDB->execDML("begin transaction;");
  232. pDB->execDML(bufSQL);
  233. pDB->execDML("commit transaction;");
  234. bufSQL.clear();
  235. }
  236. catch (CppSQLite3Exception& e)
  237. {
  238. LOG::E(e.errorMessage());
  239. return FALSE;
  240. }
  241. return TRUE;
  242. }
  243. BOOL EquipDataAngleManager::Delete(DWORD iTaskId, LPCTSTR szEquipCode, DWORD iSubitemId)
  244. {
  245. try
  246. {
  247. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  248. CppSQLite3Buffer bufSQL;
  249. bufSQL.format("DELETE FROM equip_data_angle WHERE task_id=%d AND equip_code=%Q AND subitem_id=%d;", iTaskId, szEquipCode, iSubitemId);
  250. pDB->execDML("begin transaction;");
  251. pDB->execDML(bufSQL);
  252. pDB->execDML("commit transaction;");
  253. bufSQL.clear();
  254. }
  255. catch (CppSQLite3Exception& e)
  256. {
  257. LOG::E(e.errorMessage());
  258. return FALSE;
  259. }
  260. return TRUE;
  261. }
  262. /**************************************************************************************************
  263. 函 数 名 :ClearAll
  264. 功能描述 :清除数据
  265. 输入参数 :略
  266. 输出参数 :略
  267. 返 回 值 :TRUE 成功;FALSE 失败
  268. **************************************************************************************************/
  269. BOOL EquipDataAngleManager::ClearAll()
  270. {
  271. try
  272. {
  273. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  274. CppSQLite3Buffer bufSQL;
  275. bufSQL.format("DELETE FROM equip_data_angle;");//删除语句
  276. pDB->execDML("begin transaction;");
  277. pDB->execDML(bufSQL);
  278. pDB->execDML("commit transaction;");
  279. bufSQL.clear();
  280. }
  281. catch (CppSQLite3Exception& e)
  282. {
  283. LOG::E(e.errorMessage());
  284. return FALSE;
  285. }
  286. return TRUE;
  287. }
  288. /**************************************************************************************************
  289. 函 数 名 :Count
  290. 功能描述 :根据条件查询记录数目
  291. 输入参数 :略
  292. 输出参数 :略
  293. 返 回 值 :TRUE 成功;FALSE 失败
  294. **************************************************************************************************/
  295. int EquipDataAngleManager::Count(DWORD iTaskId)
  296. {
  297. int iCount = 0;
  298. try
  299. {
  300. CppSQLite3DB* pDB = DBFactory::GetSQLite();
  301. char szCmd[256];
  302. sprintf_s(szCmd, "SELECT COUNT(*) AS NUM FROM equip_data_angle WHERE task_id = %d;", iTaskId);
  303. CppSQLite3Query q = pDB->execQuery(szCmd);
  304. iCount = q.getIntField("NUM");
  305. q.finalize();
  306. }
  307. catch (CppSQLite3Exception& e)
  308. {
  309. LOG::E(e.errorMessage());
  310. iCount = 0;
  311. }
  312. return iCount;
  313. }