report.cpp 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. #include "report.h"
  2. #include <QDebug>
  3. #include <QAxObject>
  4. #include <QAxWidget>
  5. #include <QTextCodec>
  6. #include <QThread>
  7. #include <QFile>
  8. #include <QDir>
  9. QString g_bookmark_volume[MAX_COMPARTMENT_NUM] = {BOOKMARK_VOLUME_1,BOOKMARK_VOLUME_2,BOOKMARK_VOLUME_3, BOOKMARK_VOLUME_4};
  10. QString g_bookmark_systest_startpressure[MAX_COMPARTMENT_NUM] = {BOOKMARK_SYSTEST_STARTPRESSURE_1,BOOKMARK_SYSTEST_STARTPRESSURE_2,BOOKMARK_SYSTEST_STARTPRESSURE_3, BOOKMARK_SYSTEST_STARTPRESSURE_4};
  11. QString g_bookmark_systest_endpressure[MAX_COMPARTMENT_NUM] = {BOOKMARK_SYSTEST_ENDPRESSURE_1,BOOKMARK_SYSTEST_ENDPRESSURE_2,BOOKMARK_SYSTEST_ENDPRESSURE_3, BOOKMARK_SYSTEST_ENDPRESSURE_4};
  12. QString g_bookmark_systest_deltapressure[MAX_COMPARTMENT_NUM] = {BOOKMARK_SYSTEST_DELTAPRESSURE_1,BOOKMARK_SYSTEST_DELTAPRESSURE_2,BOOKMARK_SYSTEST_DELTAPRESSURE_3, BOOKMARK_SYSTEST_DELTAPRESSURE_4};
  13. QString g_bookmark_systest_threshold[MAX_COMPARTMENT_NUM] = {BOOKMARK_SYSTEST_THRESHOLD_1,BOOKMARK_SYSTEST_THRESHOLD_2,BOOKMARK_SYSTEST_THRESHOLD_3, BOOKMARK_SYSTEST_THRESHOLD_4};
  14. QString g_bookmark_valvetest_startpressure[MAX_COMPARTMENT_NUM] = {BOOKMARK_VALVETEST_STARTPRESSURE_1,BOOKMARK_VALVETEST_STARTPRESSURE_2,BOOKMARK_VALVETEST_STARTPRESSURE_3, BOOKMARK_VALVETEST_STARTPRESSURE_4};
  15. QString g_bookmark_valvetest_endpressure[MAX_COMPARTMENT_NUM] = {BOOKMARK_VALVETEST_ENDPRESSURE_1,BOOKMARK_VALVETEST_ENDPRESSURE_2,BOOKMARK_VALVETEST_ENDPRESSURE_3, BOOKMARK_VALVETEST_ENDPRESSURE_4};
  16. QString g_bookmark_valvetest_deltapressure[MAX_COMPARTMENT_NUM] = {BOOKMARK_VALVETEST_DELTAPRESSURE_1,BOOKMARK_VALVETEST_DELTAPRESSURE_2,BOOKMARK_VALVETEST_DELTAPRESSURE_3, BOOKMARK_VALVETEST_DELTAPRESSURE_4};
  17. QString g_bookmark_valvetest_threshold[MAX_COMPARTMENT_NUM] = {BOOKMARK_VALVETEST_THRESHOLD_1,BOOKMARK_VALVETEST_THRESHOLD_2,BOOKMARK_VALVETEST_THRESHOLD_3, BOOKMARK_VALVETEST_THRESHOLD_4};
  18. QString g_bookmark_test_picture[MAX_COMPARTMENT_NUM] = {BOOKMARK_TEST_PICTURE_1,BOOKMARK_TEST_PICTURE_2,BOOKMARK_TEST_PICTURE_3, BOOKMARK_TEST_PICTURE_4};
  19. QString g_bookmark_systest_picture[MAX_COMPARTMENT_NUM] = {BOOKMARK_SYSTEST_PICTURE_1,BOOKMARK_SYSTEST_PICTURE_2,BOOKMARK_SYSTEST_PICTURE_3, BOOKMARK_SYSTEST_PICTURE_4};
  20. QString g_bookmark_valvetest_picture[MAX_COMPARTMENT_NUM] = {BOOKMARK_VALVETEST_PICTURE_1,BOOKMARK_VALVETEST_PICTURE_2,BOOKMARK_VALVETEST_PICTURE_3, BOOKMARK_VALVETEST_PICTURE_4};
  21. QString g_bookmark_vrs_check[VRS_VISUAL_INSPECTION_ITEMS_NUM][3]={
  22. {BOOKMARK_VRS_CHECK_ITEMS_1_0, BOOKMARK_VRS_CHECK_ITEMS_1_1, BOOKMARK_VRS_CHECK_ITEMS_1_2},
  23. {BOOKMARK_VRS_CHECK_ITEMS_2_0, BOOKMARK_VRS_CHECK_ITEMS_2_1, BOOKMARK_VRS_CHECK_ITEMS_2_2},
  24. {BOOKMARK_VRS_CHECK_ITEMS_3_0, BOOKMARK_VRS_CHECK_ITEMS_3_1, BOOKMARK_VRS_CHECK_ITEMS_3_2},
  25. {BOOKMARK_VRS_CHECK_ITEMS_4_0, BOOKMARK_VRS_CHECK_ITEMS_4_1, BOOKMARK_VRS_CHECK_ITEMS_4_2},
  26. {BOOKMARK_VRS_CHECK_ITEMS_5_0, BOOKMARK_VRS_CHECK_ITEMS_5_1, BOOKMARK_VRS_CHECK_ITEMS_5_2},
  27. {BOOKMARK_VRS_CHECK_ITEMS_6_0, BOOKMARK_VRS_CHECK_ITEMS_6_1, BOOKMARK_VRS_CHECK_ITEMS_6_2},
  28. {BOOKMARK_VRS_CHECK_ITEMS_7_0, BOOKMARK_VRS_CHECK_ITEMS_7_1, BOOKMARK_VRS_CHECK_ITEMS_7_2},
  29. {BOOKMARK_VRS_CHECK_ITEMS_8_0, BOOKMARK_VRS_CHECK_ITEMS_8_1, BOOKMARK_VRS_CHECK_ITEMS_8_2}
  30. };
  31. QString g_bookmark_bls_check[BLS_VISUAL_INSPECTION_ITEMS_NUM][3]={
  32. {BOOKMARK_BLS_CHECK_ITEMS_1_0, BOOKMARK_BLS_CHECK_ITEMS_1_1, BOOKMARK_BLS_CHECK_ITEMS_1_2},
  33. {BOOKMARK_BLS_CHECK_ITEMS_2_0, BOOKMARK_BLS_CHECK_ITEMS_2_1, BOOKMARK_BLS_CHECK_ITEMS_2_2},
  34. {BOOKMARK_BLS_CHECK_ITEMS_3_0, BOOKMARK_BLS_CHECK_ITEMS_3_1, BOOKMARK_BLS_CHECK_ITEMS_3_2},
  35. {BOOKMARK_BLS_CHECK_ITEMS_4_0, BOOKMARK_BLS_CHECK_ITEMS_4_1, BOOKMARK_BLS_CHECK_ITEMS_4_2},
  36. {BOOKMARK_BLS_CHECK_ITEMS_5_0, BOOKMARK_BLS_CHECK_ITEMS_5_1, BOOKMARK_BLS_CHECK_ITEMS_5_2}
  37. };
  38. #define REPORT_TEMPLATES_PATH "D:/VaporRecoverySystemTest/Templates/"
  39. #define REPORT_TEMPLATES_NAME "report_v2.dotx"
  40. Report::Report()
  41. {
  42. }
  43. Report::~Report()
  44. {
  45. }
  46. bool Report::make_Word(Tanker& tanker, QString word_path, QString pic_dir)
  47. {
  48. QTextCodec *codec = QTextCodec::codecForName("UTF-8");
  49. QString text_progress1 = codec->toUnicode("正在生成Word报告,请耐心等待");
  50. QString text_progress2 = codec->toUnicode("正在保存中...");
  51. QString text_progress3 = codec->toUnicode("报告已完成");
  52. QString text_progress4 = codec->toUnicode("打开word失败");
  53. //新建一个word应用程序
  54. QAxWidget *word = new QAxWidget("Word.Application",0,Qt::MSWindowsOwnDC);
  55. //并设置为不可见
  56. word->setProperty("Visible",false);
  57. //获取所有的工作文档
  58. QAxObject *documents = word->querySubObject("Documents");
  59. //以test2.dot为模板新建一个文档
  60. documents->dynamicCall("Add(QString)",QString(REPORT_TEMPLATES_PATH)+QString(REPORT_TEMPLATES_NAME));
  61. //documents->dynamicCall("Add(QString)",QString::fromLocal8Bit("D:\Code\QTapps\build-valve_testing-Desktop_Qt_5_15_2_MinGW_32_bit-Debug\debug\test1.dotx"));
  62. //获取当前激活的文档
  63. QAxObject *document = word->querySubObject("ActiveDocument");
  64. emit onProgress(text_progress1);
  65. //填写全局信息
  66. //使用单位
  67. QAxObject *bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_COMPANYNAME);
  68. if(!bookmark->isNull())
  69. {
  70. //QChar cc = 0x2611;
  71. QString str = tanker.companyname_str;
  72. //str.insert(0, cc);
  73. QString sText=codec->toUnicode(str.toStdString().c_str()); //此处为替换内容
  74. qDebug()<<sText;
  75. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  76. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  77. }
  78. //车牌
  79. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_CARPLATE);
  80. if(!bookmark->isNull())
  81. {
  82. QString sText=codec->toUnicode(tanker.licenseplate_str.toStdString().c_str()); //此处为替换内容
  83. qDebug()<<sText;
  84. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  85. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  86. }
  87. //仓数
  88. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_COMPARTMENT_NUM);
  89. if(!bookmark->isNull())
  90. {
  91. QString sText=codec->toUnicode(QString::number(tanker.compartment_num).toStdString().c_str()); //此处为替换内容
  92. qDebug()<<sText;
  93. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  94. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  95. }
  96. //外观检查项
  97. for(int i=0; i<VRS_VISUAL_INSPECTION_ITEMS_NUM; i++){
  98. int check_value = tanker.vrs_results[i];
  99. if(check_value > 2 ) check_value = 2;
  100. if(check_value < 0 ) check_value = 0;
  101. //qDebug()<<g_bookmark_vrs_check[i][check_value];
  102. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_vrs_check[i][check_value]);
  103. if(!bookmark->isNull())
  104. {
  105. QChar cc = 0x2611;
  106. QString sText;
  107. sText.insert(0, cc);
  108. //int volume = m_tank.m_comparts[i].m_volume;
  109. //QString sText=codec->toUnicode(QString::number(comp.m_volume).toStdString().c_str()); //此处为替换内容
  110. //qDebug()<<"sText";
  111. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  112. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  113. }
  114. }
  115. for(int i=0; i<BLS_VISUAL_INSPECTION_ITEMS_NUM; i++){
  116. int check_value = tanker.bls_results[i];
  117. if(check_value > 2 ) check_value = 2;
  118. if(check_value < 0 ) check_value = 0;
  119. //qDebug()<<g_bookmark_bls_check[i][check_value];
  120. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_bls_check[i][check_value]);
  121. if(!bookmark->isNull())
  122. {
  123. QChar cc = 0x2611;
  124. QString sText;
  125. sText.insert(0, cc);
  126. //int volume = m_tank.m_comparts[i].m_volume;
  127. //QString sText=codec->toUnicode(QString::number(comp.m_volume).toStdString().c_str()); //此处为替换内容
  128. //qDebug()<<sText;
  129. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  130. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  131. }
  132. }
  133. //填写每仓容量
  134. for(int i=0; i< tanker.compartment_num; i++){
  135. Compartment& comp = tanker.get_compartment(i);
  136. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_volume[i]);
  137. if(!bookmark->isNull())
  138. {
  139. //int volume = m_tank.m_comparts[i].m_volume;
  140. QString sText=codec->toUnicode(QString::number(comp.m_volume).toStdString().c_str()); //此处为替换内容
  141. qDebug()<<sText;
  142. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  143. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  144. }
  145. if(comp.m_result.sys_test_finished){ //完成了系统密闭性检测
  146. //密闭性检测的初始表压
  147. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_startpressure[i]);
  148. if(!bookmark->isNull())
  149. {
  150. //int volume = m_tank.m_comparts[i].m_volume;
  151. QString pressure_str = QString("%1").arg(comp.m_result.sysstart_pressure, 4,'f',2,QLatin1Char('0'));
  152. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  153. qDebug()<<sText;
  154. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  155. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  156. }
  157. //5 min之后的表压
  158. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_endpressure[i]);
  159. if(!bookmark->isNull())
  160. {
  161. //int volume = m_tank.m_comparts[i].m_volume;
  162. QString pressure_str = QString("%1").arg(comp.m_result.sysend_pressure, 4,'f',2,QLatin1Char('0'));
  163. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  164. qDebug()<<sText;
  165. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  166. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  167. }
  168. //压力变化值
  169. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_deltapressure[i]);
  170. if(!bookmark->isNull())
  171. {
  172. //int volume = m_tank.m_comparts[i].m_volume;
  173. QString pressure_str = QString("%1").arg(comp.m_result.delta_sys_pressure, 4,'f',2,QLatin1Char('0'));
  174. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  175. qDebug()<<sText;
  176. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  177. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  178. }
  179. //压力变化限值
  180. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_threshold[i]);
  181. if(!bookmark->isNull())
  182. {
  183. //int volume = m_tank.m_comparts[i].m_volume;
  184. QString pressure_str = QString("%1").arg(comp.m_standarditem.system_threshold, 4,'f',2,QLatin1Char('0'));
  185. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  186. qDebug()<<sText;
  187. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  188. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  189. }
  190. }
  191. if(comp.m_result.valve_test_finished){ //完成了阀门密闭性检测
  192. //密闭性检测的初始表压
  193. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_startpressure[i]);
  194. if(!bookmark->isNull())
  195. {
  196. //int volume = m_tank.m_comparts[i].m_volume;
  197. QString pressure_str = QString("%1").arg(comp.m_result.valvestart_pressure, 4,'f',2,QLatin1Char('0'));
  198. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  199. qDebug()<<sText;
  200. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  201. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  202. }
  203. //5 min之后的表压
  204. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_endpressure[i]);
  205. if(!bookmark->isNull())
  206. {
  207. //int volume = m_tank.m_comparts[i].m_volume;
  208. QString pressure_str = QString("%1").arg(comp.m_result.valveend_pressure, 4,'f',2,QLatin1Char('0'));
  209. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  210. qDebug()<<sText;
  211. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  212. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  213. }
  214. //压力变化值
  215. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_deltapressure[i]);
  216. if(!bookmark->isNull())
  217. {
  218. //int volume = m_tank.m_comparts[i].m_volume;
  219. QString pressure_str = QString("%1").arg(comp.m_result.delta_valve_pressure, 4,'f',2,QLatin1Char('0'));
  220. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  221. qDebug()<<sText;
  222. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  223. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  224. }
  225. //压力变化限值
  226. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_threshold[i]);
  227. if(!bookmark->isNull())
  228. {
  229. //int volume = m_tank.m_comparts[i].m_volume;
  230. QString pressure_str = QString("%1").arg(comp.m_standarditem.valve_threshold, 4,'f',2,QLatin1Char('0'));
  231. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  232. qDebug()<<sText;
  233. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  234. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  235. }
  236. }
  237. if(comp.m_testfinished){
  238. // 获取文档中名字为pic的标签
  239. QAxObject*bookmark_pic=document->querySubObject("Bookmarks(QVariant)",g_bookmark_test_picture[i]);
  240. // 选中标签,将图片插入到标签位置
  241. if(!bookmark_pic->isNull())
  242. {
  243. QString pic_path_str = pic_dir+tanker.licenseplate_str+"_"+QString::number(i+1)+"_all.jpg";
  244. qDebug()<<pic_path_str;
  245. QFile file(pic_path_str);
  246. if(file.exists()){
  247. bookmark_pic->dynamicCall("Select(void)");
  248. QAxObject *range;
  249. range = bookmark_pic->querySubObject("Range");
  250. QVariant tmp = range->asVariant();
  251. QList<QVariant>qList;
  252. qList<<QVariant(pic_path_str);
  253. qList<<QVariant(false);
  254. qList<<QVariant(true);
  255. qList<<tmp;
  256. QAxObject *Inlineshapes = document->querySubObject("InlineShapes");
  257. Inlineshapes->dynamicCall("AddPicture(const QString&, QVariant, QVariant ,QVariant)",qList);
  258. }
  259. }
  260. bookmark_pic=document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_picture[i]);
  261. // 选中标签,将图片插入到标签位置
  262. if(!bookmark_pic->isNull())
  263. {
  264. QString pic_path_str = pic_dir+tanker.licenseplate_str+"_"+QString::number(i+1)+"_sys.jpg";
  265. qDebug()<<pic_path_str;
  266. QFile file(pic_path_str);
  267. if(file.exists()){
  268. bookmark_pic->dynamicCall("Select(void)");
  269. QAxObject *range;
  270. range = bookmark_pic->querySubObject("Range");
  271. QVariant tmp = range->asVariant();
  272. QList<QVariant>qList;
  273. qList<<QVariant(pic_path_str);
  274. qList<<QVariant(false);
  275. qList<<QVariant(true);
  276. qList<<tmp;
  277. QAxObject *Inlineshapes = document->querySubObject("InlineShapes");
  278. Inlineshapes->dynamicCall("AddPicture(const QString&, QVariant, QVariant ,QVariant)",qList);
  279. }
  280. }
  281. bookmark_pic=document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_picture[i]);
  282. // 选中标签,将图片插入到标签位置
  283. if(!bookmark_pic->isNull())
  284. {
  285. QString pic_path_str = pic_dir+tanker.licenseplate_str+"_"+QString::number(i+1)+"_valve.jpg";
  286. qDebug()<<pic_path_str;
  287. QFile file(pic_path_str);
  288. if(file.exists()){
  289. bookmark_pic->dynamicCall("Select(void)");
  290. QAxObject *range;
  291. range = bookmark_pic->querySubObject("Range");
  292. QVariant tmp = range->asVariant();
  293. QList<QVariant>qList;
  294. qList<<QVariant(pic_path_str);
  295. qList<<QVariant(false);
  296. qList<<QVariant(true);
  297. qList<<tmp;
  298. QAxObject *Inlineshapes = document->querySubObject("InlineShapes");
  299. Inlineshapes->dynamicCall("AddPicture(const QString&, QVariant, QVariant ,QVariant)",qList);
  300. }
  301. }
  302. }
  303. }
  304. //检测结果
  305. bool systest_pass = true;
  306. bool valvetest_pass = true;
  307. int nosys_testcount = 0;
  308. int novalve_testcount =0;
  309. for(int i=0; i<tanker.compartment_num; i++){
  310. Compartment& comp = tanker.get_compartment(i);
  311. if(comp.m_result.sys_test_finished){
  312. if(!comp.m_result.pass_sys_pressure){
  313. systest_pass = false;
  314. }
  315. }else{
  316. nosys_testcount++;
  317. }
  318. if(comp.m_result.valve_test_finished){
  319. if(!comp.m_result.pass_valve_pressure){
  320. valvetest_pass = false;
  321. }
  322. }else{
  323. novalve_testcount++;
  324. }
  325. }
  326. if(nosys_testcount != tanker.compartment_num){
  327. //系统检测结果
  328. QChar cc = 0x2611;
  329. QString sText;
  330. sText.insert(0, cc);
  331. if(systest_pass){
  332. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_SYSTEST_PASS);
  333. if(!bookmark->isNull())
  334. {
  335. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  336. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  337. }
  338. }else{
  339. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_SYSTEST_EXCEEDED);
  340. if(!bookmark->isNull())
  341. {
  342. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  343. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  344. }
  345. }
  346. }
  347. if(novalve_testcount != tanker.compartment_num){
  348. //阀门检测结果
  349. QChar cc = 0x2611;
  350. QString sText;
  351. sText.insert(0, cc);
  352. if(valvetest_pass){
  353. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_VALVETEST_PASS);
  354. if(!bookmark->isNull())
  355. {
  356. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  357. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  358. }
  359. }else{
  360. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_VALVETEST_EXCEEDED);
  361. if(!bookmark->isNull())
  362. {
  363. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  364. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  365. }
  366. }
  367. }
  368. //检测日期
  369. QDate date(QDate::currentDate());
  370. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_DATE_YEAR);
  371. if(!bookmark->isNull())
  372. {
  373. QString sText=codec->toUnicode(QString::number(date.year()).toStdString().c_str()); //此处为替换内容
  374. qDebug()<<sText;
  375. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  376. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  377. }
  378. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_DATE_MONTH);
  379. if(!bookmark->isNull())
  380. {
  381. QString sText=codec->toUnicode(QString::number(date.month()).toStdString().c_str()); //此处为替换内容
  382. qDebug()<<sText;
  383. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  384. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  385. }
  386. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_DATE_DAY);
  387. if(!bookmark->isNull())
  388. {
  389. QString sText=codec->toUnicode(QString::number(date.day()).toStdString().c_str()); //此处为替换内容
  390. qDebug()<<sText;
  391. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  392. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  393. }
  394. //将文件保存为PDF,
  395. qDebug()<<"start save Word file ";
  396. emit onProgress(text_progress2);
  397. document->dynamicCall("SaveAs(const QString&))",QDir::toNativeSeparators(word_path));
  398. document->dynamicCall("Close (boolean)",false);
  399. word->dynamicCall("Quit()");
  400. emit onProgress(text_progress3);
  401. QThread::msleep(300);
  402. emit onProgress("close");
  403. return true;
  404. }
  405. bool Report::make_PDF(Tanker& tanker, QString word_path, QString pic_dir)
  406. {
  407. QTextCodec *codec = QTextCodec::codecForName("UTF-8");
  408. QString text_progress1 = codec->toUnicode("正在生成PDF报告,请耐心等待");
  409. QString text_progress2 = codec->toUnicode("正在保存中...");
  410. QString text_progress3 = codec->toUnicode("报告已完成");
  411. QString text_progress4 = codec->toUnicode("打开word失败");
  412. //新建一个word应用程序
  413. QAxWidget *word = new QAxWidget("Word.Application",0,Qt::MSWindowsOwnDC);
  414. //并设置为不可见
  415. word->setProperty("Visible",false);
  416. //获取所有的工作文档
  417. QAxObject *documents = word->querySubObject("Documents");
  418. //以test2.dot为模板新建一个文档
  419. documents->dynamicCall("Add(QString)",QString(REPORT_TEMPLATES_PATH)+QString(REPORT_TEMPLATES_NAME));
  420. //documents->dynamicCall("Add(QString)",QString::fromLocal8Bit("D:\Code\QTapps\build-valve_testing-Desktop_Qt_5_15_2_MinGW_32_bit-Debug\debug\test1.dotx"));
  421. //获取当前激活的文档
  422. QAxObject *document = word->querySubObject("ActiveDocument");
  423. emit onProgress(text_progress1);
  424. //填写全局信息
  425. //使用单位
  426. QAxObject *bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_COMPANYNAME);
  427. if(!bookmark->isNull())
  428. {
  429. //QChar cc = 0x2611;
  430. QString str = tanker.companyname_str;
  431. //str.insert(0, cc);
  432. QString sText=codec->toUnicode(str.toStdString().c_str()); //此处为替换内容
  433. qDebug()<<sText;
  434. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  435. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  436. }
  437. //车牌
  438. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_CARPLATE);
  439. if(!bookmark->isNull())
  440. {
  441. QString sText=codec->toUnicode(tanker.licenseplate_str.toStdString().c_str()); //此处为替换内容
  442. qDebug()<<sText;
  443. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  444. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  445. }
  446. //仓数
  447. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_COMPARTMENT_NUM);
  448. if(!bookmark->isNull())
  449. {
  450. QString sText=codec->toUnicode(QString::number(tanker.compartment_num).toStdString().c_str()); //此处为替换内容
  451. qDebug()<<sText;
  452. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  453. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  454. }
  455. //外观检查项
  456. for(int i=0; i<VRS_VISUAL_INSPECTION_ITEMS_NUM; i++){
  457. int check_value = tanker.vrs_results[i];
  458. if(check_value > 2 ) check_value = 2;
  459. if(check_value < 0 ) check_value = 0;
  460. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_vrs_check[i][check_value]);
  461. if(!bookmark->isNull())
  462. {
  463. QChar cc = 0x2611;
  464. QString sText;
  465. sText.insert(0, cc);
  466. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  467. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  468. }
  469. }
  470. for(int i=0; i<BLS_VISUAL_INSPECTION_ITEMS_NUM; i++){
  471. int check_value = tanker.bls_results[i];
  472. if(check_value > 2 ) check_value = 2;
  473. if(check_value < 0 ) check_value = 0;
  474. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_bls_check[i][check_value]);
  475. if(!bookmark->isNull())
  476. {
  477. QChar cc = 0x2611;
  478. QString sText;
  479. sText.insert(0, cc);
  480. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  481. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  482. }
  483. }
  484. //填写每仓容量
  485. for(int i=0; i< tanker.compartment_num; i++){
  486. Compartment& comp = tanker.get_compartment(i);
  487. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_volume[i]);
  488. if(!bookmark->isNull())
  489. {
  490. //int volume = m_tank.m_comparts[i].m_volume;
  491. QString sText=codec->toUnicode(QString::number(comp.m_volume).toStdString().c_str()); //此处为替换内容
  492. qDebug()<<sText;
  493. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  494. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  495. }
  496. if(comp.m_result.sys_test_finished){ //完成了系统密闭性检测
  497. //密闭性检测的初始表压
  498. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_startpressure[i]);
  499. if(!bookmark->isNull())
  500. {
  501. //int volume = m_tank.m_comparts[i].m_volume;
  502. QString pressure_str = QString("%1").arg(comp.m_result.sysstart_pressure, 4,'f',2,QLatin1Char('0'));
  503. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  504. qDebug()<<sText;
  505. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  506. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  507. }
  508. //5 min之后的表压
  509. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_endpressure[i]);
  510. if(!bookmark->isNull())
  511. {
  512. //int volume = m_tank.m_comparts[i].m_volume;
  513. QString pressure_str = QString("%1").arg(comp.m_result.sysend_pressure, 4,'f',2,QLatin1Char('0'));
  514. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  515. qDebug()<<sText;
  516. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  517. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  518. }
  519. //压力变化值
  520. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_deltapressure[i]);
  521. if(!bookmark->isNull())
  522. {
  523. //int volume = m_tank.m_comparts[i].m_volume;
  524. QString pressure_str = QString("%1").arg(comp.m_result.delta_sys_pressure, 4,'f',2,QLatin1Char('0'));
  525. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  526. qDebug()<<sText;
  527. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  528. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  529. }
  530. //压力变化限值
  531. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_threshold[i]);
  532. if(!bookmark->isNull())
  533. {
  534. //int volume = m_tank.m_comparts[i].m_volume;
  535. QString pressure_str = QString("%1").arg(comp.m_standarditem.system_threshold, 4,'f',2,QLatin1Char('0'));
  536. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  537. qDebug()<<sText;
  538. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  539. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  540. }
  541. }
  542. if(comp.m_result.valve_test_finished){ //完成了阀门密闭性检测
  543. //密闭性检测的初始表压
  544. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_startpressure[i]);
  545. if(!bookmark->isNull())
  546. {
  547. //int volume = m_tank.m_comparts[i].m_volume;
  548. QString pressure_str = QString("%1").arg(comp.m_result.valvestart_pressure, 4,'f',2,QLatin1Char('0'));
  549. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  550. qDebug()<<sText;
  551. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  552. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  553. }
  554. //5 min之后的表压
  555. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_endpressure[i]);
  556. if(!bookmark->isNull())
  557. {
  558. //int volume = m_tank.m_comparts[i].m_volume;
  559. QString pressure_str = QString("%1").arg(comp.m_result.valveend_pressure, 4,'f',2,QLatin1Char('0'));
  560. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  561. qDebug()<<sText;
  562. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  563. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  564. }
  565. //压力变化值
  566. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_deltapressure[i]);
  567. if(!bookmark->isNull())
  568. {
  569. //int volume = m_tank.m_comparts[i].m_volume;
  570. QString pressure_str = QString("%1").arg(comp.m_result.delta_valve_pressure, 4,'f',2,QLatin1Char('0'));
  571. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  572. qDebug()<<sText;
  573. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  574. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  575. }
  576. //压力变化限值
  577. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_threshold[i]);
  578. if(!bookmark->isNull())
  579. {
  580. //int volume = m_tank.m_comparts[i].m_volume;
  581. QString pressure_str = QString("%1").arg(comp.m_standarditem.valve_threshold, 4,'f',2,QLatin1Char('0'));
  582. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  583. qDebug()<<sText;
  584. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  585. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  586. }
  587. }
  588. if(comp.m_testfinished){
  589. // 获取文档中名字为pic的标签
  590. QAxObject*bookmark_pic=document->querySubObject("Bookmarks(QVariant)",g_bookmark_test_picture[i]);
  591. // 选中标签,将图片插入到标签位置
  592. if(!bookmark_pic->isNull())
  593. {
  594. QString pic_path_str = pic_dir+tanker.licenseplate_str+"_"+QString::number(i+1)+"_all.jpg";
  595. qDebug()<<pic_path_str;
  596. QFile file(pic_path_str);
  597. if(file.exists()){
  598. bookmark_pic->dynamicCall("Select(void)");
  599. QAxObject *range;
  600. range = bookmark_pic->querySubObject("Range");
  601. QVariant tmp = range->asVariant();
  602. QList<QVariant>qList;
  603. qList<<QVariant(pic_path_str);
  604. qList<<QVariant(false);
  605. qList<<QVariant(true);
  606. qList<<tmp;
  607. QAxObject *Inlineshapes = document->querySubObject("InlineShapes");
  608. Inlineshapes->dynamicCall("AddPicture(const QString&, QVariant, QVariant ,QVariant)",qList);
  609. }
  610. }
  611. bookmark_pic=document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_picture[i]);
  612. // 选中标签,将图片插入到标签位置
  613. if(!bookmark_pic->isNull())
  614. {
  615. QString pic_path_str = pic_dir+tanker.licenseplate_str+"_"+QString::number(i+1)+"_sys.jpg";
  616. qDebug()<<pic_path_str;
  617. QFile file(pic_path_str);
  618. if(file.exists()){
  619. bookmark_pic->dynamicCall("Select(void)");
  620. QAxObject *range;
  621. range = bookmark_pic->querySubObject("Range");
  622. QVariant tmp = range->asVariant();
  623. QList<QVariant>qList;
  624. qList<<QVariant(pic_path_str);
  625. qList<<QVariant(false);
  626. qList<<QVariant(true);
  627. qList<<tmp;
  628. QAxObject *Inlineshapes = document->querySubObject("InlineShapes");
  629. Inlineshapes->dynamicCall("AddPicture(const QString&, QVariant, QVariant ,QVariant)",qList);
  630. }
  631. }
  632. bookmark_pic=document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_picture[i]);
  633. // 选中标签,将图片插入到标签位置
  634. if(!bookmark_pic->isNull())
  635. {
  636. QString pic_path_str = pic_dir+tanker.licenseplate_str+"_"+QString::number(i+1)+"_valve.jpg";
  637. qDebug()<<pic_path_str;
  638. QFile file(pic_path_str);
  639. if(file.exists()){
  640. bookmark_pic->dynamicCall("Select(void)");
  641. QAxObject *range;
  642. range = bookmark_pic->querySubObject("Range");
  643. QVariant tmp = range->asVariant();
  644. QList<QVariant>qList;
  645. qList<<QVariant(pic_path_str);
  646. qList<<QVariant(false);
  647. qList<<QVariant(true);
  648. qList<<tmp;
  649. QAxObject *Inlineshapes = document->querySubObject("InlineShapes");
  650. Inlineshapes->dynamicCall("AddPicture(const QString&, QVariant, QVariant ,QVariant)",qList);
  651. }
  652. }
  653. }
  654. }
  655. //检测结果
  656. bool systest_pass = true;
  657. bool valvetest_pass = true;
  658. int nosys_testcount = 0;
  659. int novalve_testcount =0;
  660. for(int i=0; i<tanker.compartment_num; i++){
  661. Compartment& comp = tanker.get_compartment(i);
  662. if(comp.m_result.sys_test_finished){
  663. if(!comp.m_result.pass_sys_pressure){
  664. systest_pass = false;
  665. }
  666. }else{
  667. nosys_testcount++;
  668. }
  669. if(comp.m_result.valve_test_finished){
  670. if(!comp.m_result.pass_valve_pressure){
  671. valvetest_pass = false;
  672. }
  673. }else{
  674. novalve_testcount++;
  675. }
  676. }
  677. if(nosys_testcount != tanker.compartment_num){
  678. //系统检测结果
  679. QChar cc = 0x2611;
  680. QString sText;
  681. sText.insert(0, cc);
  682. if(systest_pass){
  683. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_SYSTEST_PASS);
  684. if(!bookmark->isNull())
  685. {
  686. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  687. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  688. }
  689. }else{
  690. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_SYSTEST_EXCEEDED);
  691. if(!bookmark->isNull())
  692. {
  693. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  694. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  695. }
  696. }
  697. }
  698. if(novalve_testcount != tanker.compartment_num){
  699. //阀门检测结果
  700. QChar cc = 0x2611;
  701. QString sText;
  702. sText.insert(0, cc);
  703. if(valvetest_pass){
  704. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_VALVETEST_PASS);
  705. if(!bookmark->isNull())
  706. {
  707. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  708. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  709. }
  710. }else{
  711. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_VALVETEST_EXCEEDED);
  712. if(!bookmark->isNull())
  713. {
  714. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  715. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  716. }
  717. }
  718. }
  719. //检测日期
  720. QDate date(QDate::currentDate());
  721. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_DATE_YEAR);
  722. if(!bookmark->isNull())
  723. {
  724. QString sText=codec->toUnicode(QString::number(date.year()).toStdString().c_str()); //此处为替换内容
  725. qDebug()<<sText;
  726. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  727. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  728. }
  729. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_DATE_MONTH);
  730. if(!bookmark->isNull())
  731. {
  732. QString sText=codec->toUnicode(QString::number(date.month()).toStdString().c_str()); //此处为替换内容
  733. qDebug()<<sText;
  734. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  735. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  736. }
  737. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_DATE_DAY);
  738. if(!bookmark->isNull())
  739. {
  740. QString sText=codec->toUnicode(QString::number(date.day()).toStdString().c_str()); //此处为替换内容
  741. qDebug()<<sText;
  742. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  743. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  744. }
  745. //将文件保存为PDF,
  746. qDebug()<<"start save PDF file ";
  747. emit onProgress(text_progress2);
  748. //document->dynamicCall("SaveAs(const QString&))",QDir::toNativeSeparators(word_path));
  749. QVariant OutputFileName(word_path);
  750. QVariant ExportFormat(17); //17是pdf
  751. QVariant OpenAfterExport(false); //保存后是否自动打开
  752. document->querySubObject("ExportAsFixedFormat(const QVariant&,const QVariant&,const QVariant&)",
  753. OutputFileName,
  754. ExportFormat,
  755. OpenAfterExport);
  756. document->dynamicCall("Close (boolean)",false);
  757. word->dynamicCall("Quit()");
  758. emit onProgress(text_progress3);
  759. QThread::msleep(300);
  760. emit onProgress("close");
  761. return true;
  762. }