EquipDataPointManager.cpp 15 KB

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