report.cpp 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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. #define REPORT_TEMPLATES_PATH "D:/VaporRecoverySystemTest/Templates/"
  22. #define REPORT_TEMPLATES_NAME "report.dotx"
  23. Report::Report()
  24. {
  25. }
  26. Report::~Report()
  27. {
  28. }
  29. bool Report::make_Word(Tanker& tanker, QString word_path, QString pic_dir)
  30. {
  31. QTextCodec *codec = QTextCodec::codecForName("UTF-8");
  32. QString text_progress1 = codec->toUnicode("正在生成Word报告,请耐心等待");
  33. QString text_progress2 = codec->toUnicode("正在保存中...");
  34. QString text_progress3 = codec->toUnicode("报告已完成");
  35. QString text_progress4 = codec->toUnicode("打开word失败");
  36. //新建一个word应用程序
  37. QAxWidget *word = new QAxWidget("Word.Application",0,Qt::MSWindowsOwnDC);
  38. //并设置为不可见
  39. word->setProperty("Visible",false);
  40. //获取所有的工作文档
  41. QAxObject *documents = word->querySubObject("Documents");
  42. //以test2.dot为模板新建一个文档
  43. documents->dynamicCall("Add(QString)",QString(REPORT_TEMPLATES_PATH)+QString(REPORT_TEMPLATES_NAME));
  44. //documents->dynamicCall("Add(QString)",QString::fromLocal8Bit("D:\Code\QTapps\build-valve_testing-Desktop_Qt_5_15_2_MinGW_32_bit-Debug\debug\test1.dotx"));
  45. //获取当前激活的文档
  46. QAxObject *document = word->querySubObject("ActiveDocument");
  47. emit onProgress(text_progress1);
  48. //填写全局信息
  49. //使用单位
  50. QAxObject *bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_COMPANYNAME);
  51. if(!bookmark->isNull())
  52. {
  53. //QChar cc = 0x2611;
  54. QString str = tanker.companyname_str;
  55. //str.insert(0, cc);
  56. QString sText=codec->toUnicode(str.toStdString().c_str()); //此处为替换内容
  57. qDebug()<<sText;
  58. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  59. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  60. }
  61. //车牌
  62. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_CARPLATE);
  63. if(!bookmark->isNull())
  64. {
  65. QString sText=codec->toUnicode(tanker.licenseplate_str.toStdString().c_str()); //此处为替换内容
  66. qDebug()<<sText;
  67. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  68. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  69. }
  70. //仓数
  71. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_COMPARTMENT_NUM);
  72. if(!bookmark->isNull())
  73. {
  74. QString sText=codec->toUnicode(QString::number(tanker.compartment_num).toStdString().c_str()); //此处为替换内容
  75. qDebug()<<sText;
  76. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  77. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  78. }
  79. //填写每仓容量
  80. for(int i=0; i< tanker.compartment_num; i++){
  81. Compartment& comp = tanker.get_compartment(i);
  82. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_volume[i]);
  83. if(!bookmark->isNull())
  84. {
  85. //int volume = m_tank.m_comparts[i].m_volume;
  86. QString sText=codec->toUnicode(QString::number(comp.m_volume).toStdString().c_str()); //此处为替换内容
  87. qDebug()<<sText;
  88. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  89. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  90. }
  91. if(comp.m_result.sys_test_ok){ //完成了系统密闭性检测
  92. //密闭性检测的初始表压
  93. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_startpressure[i]);
  94. if(!bookmark->isNull())
  95. {
  96. //int volume = m_tank.m_comparts[i].m_volume;
  97. QString pressure_str = QString("%1").arg(comp.m_result.sysstart_pressure, 4,'f',2,QLatin1Char('0'));
  98. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  99. qDebug()<<sText;
  100. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  101. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  102. }
  103. //5 min之后的表压
  104. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_endpressure[i]);
  105. if(!bookmark->isNull())
  106. {
  107. //int volume = m_tank.m_comparts[i].m_volume;
  108. QString pressure_str = QString("%1").arg(comp.m_result.sysend_pressure, 4,'f',2,QLatin1Char('0'));
  109. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  110. qDebug()<<sText;
  111. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  112. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  113. }
  114. //压力变化值
  115. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_deltapressure[i]);
  116. if(!bookmark->isNull())
  117. {
  118. //int volume = m_tank.m_comparts[i].m_volume;
  119. QString pressure_str = QString("%1").arg(comp.m_result.delta_sys_pressure, 4,'f',2,QLatin1Char('0'));
  120. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  121. qDebug()<<sText;
  122. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  123. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  124. }
  125. //压力变化限值
  126. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_threshold[i]);
  127. if(!bookmark->isNull())
  128. {
  129. //int volume = m_tank.m_comparts[i].m_volume;
  130. QString pressure_str = QString("%1").arg(comp.m_standarditem.system_threshold, 4,'f',2,QLatin1Char('0'));
  131. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  132. qDebug()<<sText;
  133. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  134. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  135. }
  136. }
  137. if(comp.m_result.valve_test_ok){ //完成了阀门密闭性检测
  138. //密闭性检测的初始表压
  139. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_startpressure[i]);
  140. if(!bookmark->isNull())
  141. {
  142. //int volume = m_tank.m_comparts[i].m_volume;
  143. QString pressure_str = QString("%1").arg(comp.m_result.valvestart_pressure, 4,'f',2,QLatin1Char('0'));
  144. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  145. qDebug()<<sText;
  146. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  147. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  148. }
  149. //5 min之后的表压
  150. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_endpressure[i]);
  151. if(!bookmark->isNull())
  152. {
  153. //int volume = m_tank.m_comparts[i].m_volume;
  154. QString pressure_str = QString("%1").arg(comp.m_result.valveend_pressure, 4,'f',2,QLatin1Char('0'));
  155. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  156. qDebug()<<sText;
  157. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  158. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  159. }
  160. //压力变化值
  161. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_deltapressure[i]);
  162. if(!bookmark->isNull())
  163. {
  164. //int volume = m_tank.m_comparts[i].m_volume;
  165. QString pressure_str = QString("%1").arg(comp.m_result.delta_valve_pressure, 4,'f',2,QLatin1Char('0'));
  166. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  167. qDebug()<<sText;
  168. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  169. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  170. }
  171. //压力变化限值
  172. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_threshold[i]);
  173. if(!bookmark->isNull())
  174. {
  175. //int volume = m_tank.m_comparts[i].m_volume;
  176. QString pressure_str = QString("%1").arg(comp.m_standarditem.valve_threshold, 4,'f',2,QLatin1Char('0'));
  177. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  178. qDebug()<<sText;
  179. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  180. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  181. }
  182. }
  183. if(comp.m_bpicReady){
  184. // 获取文档中名字为pic的标签
  185. QAxObject*bookmark_pic=document->querySubObject("Bookmarks(QVariant)",g_bookmark_test_picture[i]);
  186. // 选中标签,将图片插入到标签位置
  187. if(!bookmark_pic->isNull())
  188. {
  189. QString pic_path_str = pic_dir+tanker.licenseplate_str+"_"+QString::number(i+1)+"_all.jpg";
  190. qDebug()<<pic_path_str;
  191. QFile file(pic_path_str);
  192. if(file.exists()){
  193. bookmark_pic->dynamicCall("Select(void)");
  194. QAxObject *range;
  195. range = bookmark_pic->querySubObject("Range");
  196. QVariant tmp = range->asVariant();
  197. QList<QVariant>qList;
  198. qList<<QVariant(pic_path_str);
  199. qList<<QVariant(false);
  200. qList<<QVariant(true);
  201. qList<<tmp;
  202. QAxObject *Inlineshapes = document->querySubObject("InlineShapes");
  203. Inlineshapes->dynamicCall("AddPicture(const QString&, QVariant, QVariant ,QVariant)",qList);
  204. }
  205. }
  206. bookmark_pic=document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_picture[i]);
  207. // 选中标签,将图片插入到标签位置
  208. if(!bookmark_pic->isNull())
  209. {
  210. QString pic_path_str = pic_dir+tanker.licenseplate_str+"_"+QString::number(i+1)+"_sys.jpg";
  211. qDebug()<<pic_path_str;
  212. QFile file(pic_path_str);
  213. if(file.exists()){
  214. bookmark_pic->dynamicCall("Select(void)");
  215. QAxObject *range;
  216. range = bookmark_pic->querySubObject("Range");
  217. QVariant tmp = range->asVariant();
  218. QList<QVariant>qList;
  219. qList<<QVariant(pic_path_str);
  220. qList<<QVariant(false);
  221. qList<<QVariant(true);
  222. qList<<tmp;
  223. QAxObject *Inlineshapes = document->querySubObject("InlineShapes");
  224. Inlineshapes->dynamicCall("AddPicture(const QString&, QVariant, QVariant ,QVariant)",qList);
  225. }
  226. }
  227. bookmark_pic=document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_picture[i]);
  228. // 选中标签,将图片插入到标签位置
  229. if(!bookmark_pic->isNull())
  230. {
  231. QString pic_path_str = pic_dir+tanker.licenseplate_str+"_"+QString::number(i+1)+"_valve.jpg";
  232. qDebug()<<pic_path_str;
  233. QFile file(pic_path_str);
  234. if(file.exists()){
  235. bookmark_pic->dynamicCall("Select(void)");
  236. QAxObject *range;
  237. range = bookmark_pic->querySubObject("Range");
  238. QVariant tmp = range->asVariant();
  239. QList<QVariant>qList;
  240. qList<<QVariant(pic_path_str);
  241. qList<<QVariant(false);
  242. qList<<QVariant(true);
  243. qList<<tmp;
  244. QAxObject *Inlineshapes = document->querySubObject("InlineShapes");
  245. Inlineshapes->dynamicCall("AddPicture(const QString&, QVariant, QVariant ,QVariant)",qList);
  246. }
  247. }
  248. }
  249. }
  250. //检测结果
  251. bool systest_pass = true;
  252. bool valvetest_pass = true;
  253. int nosys_testcount = 0;
  254. int novalve_testcount =0;
  255. for(int i=0; i<tanker.compartment_num; i++){
  256. Compartment& comp = tanker.get_compartment(i);
  257. if(comp.m_result.sys_test_ok){
  258. if(!comp.m_result.pass_sys_pressure){
  259. systest_pass = false;
  260. }
  261. }else{
  262. nosys_testcount++;
  263. }
  264. if(comp.m_result.valve_test_ok){
  265. if(!comp.m_result.pass_valve_pressure){
  266. valvetest_pass = false;
  267. }
  268. }else{
  269. novalve_testcount++;
  270. }
  271. }
  272. if(nosys_testcount != tanker.compartment_num){
  273. //系统检测结果
  274. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_SYSTEST_RESULT);
  275. if(!bookmark->isNull())
  276. {
  277. QString sText;
  278. if(systest_pass){
  279. sText=codec->toUnicode("合格");
  280. }else{
  281. sText=codec->toUnicode("超标");
  282. }
  283. qDebug()<<sText;
  284. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  285. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  286. }
  287. }
  288. if(novalve_testcount != tanker.compartment_num){
  289. //阀门检测结果
  290. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_VALVETEST_RESULT);
  291. if(!bookmark->isNull())
  292. {
  293. QString sText;
  294. if(valvetest_pass){
  295. sText=codec->toUnicode("合格");
  296. }else{
  297. sText=codec->toUnicode("超标");
  298. }
  299. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  300. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  301. }
  302. }
  303. //检测日期
  304. QDate date(QDate::currentDate());
  305. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_DATE_YEAR);
  306. if(!bookmark->isNull())
  307. {
  308. QString sText=codec->toUnicode(QString::number(date.year()).toStdString().c_str()); //此处为替换内容
  309. qDebug()<<sText;
  310. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  311. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  312. }
  313. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_DATE_MONTH);
  314. if(!bookmark->isNull())
  315. {
  316. QString sText=codec->toUnicode(QString::number(date.month()).toStdString().c_str()); //此处为替换内容
  317. qDebug()<<sText;
  318. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  319. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  320. }
  321. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_DATE_DAY);
  322. if(!bookmark->isNull())
  323. {
  324. QString sText=codec->toUnicode(QString::number(date.day()).toStdString().c_str()); //此处为替换内容
  325. qDebug()<<sText;
  326. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  327. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  328. }
  329. //将文件保存为PDF,
  330. qDebug()<<"start save Word file ";
  331. emit onProgress(text_progress2);
  332. document->dynamicCall("SaveAs(const QString&))",QDir::toNativeSeparators(word_path));
  333. document->dynamicCall("Close (boolean)",false);
  334. word->dynamicCall("Quit()");
  335. emit onProgress(text_progress3);
  336. QThread::msleep(300);
  337. emit onProgress("close");
  338. return true;
  339. }
  340. bool Report::make_PDF(Tanker& tanker, QString word_path, QString pic_dir)
  341. {
  342. QTextCodec *codec = QTextCodec::codecForName("UTF-8");
  343. QString text_progress1 = codec->toUnicode("正在生成PDF报告,请耐心等待");
  344. QString text_progress2 = codec->toUnicode("正在保存中...");
  345. QString text_progress3 = codec->toUnicode("报告已完成");
  346. QString text_progress4 = codec->toUnicode("打开word失败");
  347. //新建一个word应用程序
  348. QAxWidget *word = new QAxWidget("Word.Application",0,Qt::MSWindowsOwnDC);
  349. //并设置为不可见
  350. word->setProperty("Visible",false);
  351. //获取所有的工作文档
  352. QAxObject *documents = word->querySubObject("Documents");
  353. //以test2.dot为模板新建一个文档
  354. documents->dynamicCall("Add(QString)",QString(REPORT_TEMPLATES_PATH)+QString(REPORT_TEMPLATES_NAME));
  355. //documents->dynamicCall("Add(QString)",QString::fromLocal8Bit("D:\Code\QTapps\build-valve_testing-Desktop_Qt_5_15_2_MinGW_32_bit-Debug\debug\test1.dotx"));
  356. //获取当前激活的文档
  357. QAxObject *document = word->querySubObject("ActiveDocument");
  358. emit onProgress(text_progress1);
  359. //填写全局信息
  360. //使用单位
  361. QAxObject *bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_COMPANYNAME);
  362. if(!bookmark->isNull())
  363. {
  364. //QChar cc = 0x2611;
  365. QString str = tanker.companyname_str;
  366. //str.insert(0, cc);
  367. QString sText=codec->toUnicode(str.toStdString().c_str()); //此处为替换内容
  368. qDebug()<<sText;
  369. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  370. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  371. }
  372. //车牌
  373. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_CARPLATE);
  374. if(!bookmark->isNull())
  375. {
  376. QString sText=codec->toUnicode(tanker.licenseplate_str.toStdString().c_str()); //此处为替换内容
  377. qDebug()<<sText;
  378. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  379. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  380. }
  381. //仓数
  382. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_COMPARTMENT_NUM);
  383. if(!bookmark->isNull())
  384. {
  385. QString sText=codec->toUnicode(QString::number(tanker.compartment_num).toStdString().c_str()); //此处为替换内容
  386. qDebug()<<sText;
  387. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  388. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  389. }
  390. //填写每仓容量
  391. for(int i=0; i< tanker.compartment_num; i++){
  392. Compartment& comp = tanker.get_compartment(i);
  393. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_volume[i]);
  394. if(!bookmark->isNull())
  395. {
  396. //int volume = m_tank.m_comparts[i].m_volume;
  397. QString sText=codec->toUnicode(QString::number(comp.m_volume).toStdString().c_str()); //此处为替换内容
  398. qDebug()<<sText;
  399. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  400. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  401. }
  402. if(comp.m_result.sys_test_ok){ //完成了系统密闭性检测
  403. //密闭性检测的初始表压
  404. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_startpressure[i]);
  405. if(!bookmark->isNull())
  406. {
  407. //int volume = m_tank.m_comparts[i].m_volume;
  408. QString pressure_str = QString("%1").arg(comp.m_result.sysstart_pressure, 4,'f',2,QLatin1Char('0'));
  409. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  410. qDebug()<<sText;
  411. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  412. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  413. }
  414. //5 min之后的表压
  415. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_endpressure[i]);
  416. if(!bookmark->isNull())
  417. {
  418. //int volume = m_tank.m_comparts[i].m_volume;
  419. QString pressure_str = QString("%1").arg(comp.m_result.sysend_pressure, 4,'f',2,QLatin1Char('0'));
  420. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  421. qDebug()<<sText;
  422. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  423. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  424. }
  425. //压力变化值
  426. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_deltapressure[i]);
  427. if(!bookmark->isNull())
  428. {
  429. //int volume = m_tank.m_comparts[i].m_volume;
  430. QString pressure_str = QString("%1").arg(comp.m_result.delta_sys_pressure, 4,'f',2,QLatin1Char('0'));
  431. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  432. qDebug()<<sText;
  433. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  434. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  435. }
  436. //压力变化限值
  437. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_threshold[i]);
  438. if(!bookmark->isNull())
  439. {
  440. //int volume = m_tank.m_comparts[i].m_volume;
  441. QString pressure_str = QString("%1").arg(comp.m_standarditem.system_threshold, 4,'f',2,QLatin1Char('0'));
  442. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  443. qDebug()<<sText;
  444. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  445. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  446. }
  447. }
  448. if(comp.m_result.valve_test_ok){ //完成了阀门密闭性检测
  449. //密闭性检测的初始表压
  450. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_startpressure[i]);
  451. if(!bookmark->isNull())
  452. {
  453. //int volume = m_tank.m_comparts[i].m_volume;
  454. QString pressure_str = QString("%1").arg(comp.m_result.valvestart_pressure, 4,'f',2,QLatin1Char('0'));
  455. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  456. qDebug()<<sText;
  457. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  458. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  459. }
  460. //5 min之后的表压
  461. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_endpressure[i]);
  462. if(!bookmark->isNull())
  463. {
  464. //int volume = m_tank.m_comparts[i].m_volume;
  465. QString pressure_str = QString("%1").arg(comp.m_result.valveend_pressure, 4,'f',2,QLatin1Char('0'));
  466. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  467. qDebug()<<sText;
  468. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  469. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  470. }
  471. //压力变化值
  472. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_deltapressure[i]);
  473. if(!bookmark->isNull())
  474. {
  475. //int volume = m_tank.m_comparts[i].m_volume;
  476. QString pressure_str = QString("%1").arg(comp.m_result.delta_valve_pressure, 4,'f',2,QLatin1Char('0'));
  477. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  478. qDebug()<<sText;
  479. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  480. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  481. }
  482. //压力变化限值
  483. bookmark = document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_threshold[i]);
  484. if(!bookmark->isNull())
  485. {
  486. //int volume = m_tank.m_comparts[i].m_volume;
  487. QString pressure_str = QString("%1").arg(comp.m_standarditem.valve_threshold, 4,'f',2,QLatin1Char('0'));
  488. QString sText=codec->toUnicode(pressure_str.toStdString().c_str()); //此处为替换内容
  489. qDebug()<<sText;
  490. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  491. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  492. }
  493. }
  494. if(comp.m_bpicReady){
  495. // 获取文档中名字为pic的标签
  496. QAxObject*bookmark_pic=document->querySubObject("Bookmarks(QVariant)",g_bookmark_test_picture[i]);
  497. // 选中标签,将图片插入到标签位置
  498. if(!bookmark_pic->isNull())
  499. {
  500. QString pic_path_str = pic_dir+tanker.licenseplate_str+"_"+QString::number(i+1)+"_all.jpg";
  501. qDebug()<<pic_path_str;
  502. QFile file(pic_path_str);
  503. if(file.exists()){
  504. bookmark_pic->dynamicCall("Select(void)");
  505. QAxObject *range;
  506. range = bookmark_pic->querySubObject("Range");
  507. QVariant tmp = range->asVariant();
  508. QList<QVariant>qList;
  509. qList<<QVariant(pic_path_str);
  510. qList<<QVariant(false);
  511. qList<<QVariant(true);
  512. qList<<tmp;
  513. QAxObject *Inlineshapes = document->querySubObject("InlineShapes");
  514. Inlineshapes->dynamicCall("AddPicture(const QString&, QVariant, QVariant ,QVariant)",qList);
  515. }
  516. }
  517. bookmark_pic=document->querySubObject("Bookmarks(QVariant)",g_bookmark_systest_picture[i]);
  518. // 选中标签,将图片插入到标签位置
  519. if(!bookmark_pic->isNull())
  520. {
  521. QString pic_path_str = pic_dir+tanker.licenseplate_str+"_"+QString::number(i+1)+"_sys.jpg";
  522. qDebug()<<pic_path_str;
  523. QFile file(pic_path_str);
  524. if(file.exists()){
  525. bookmark_pic->dynamicCall("Select(void)");
  526. QAxObject *range;
  527. range = bookmark_pic->querySubObject("Range");
  528. QVariant tmp = range->asVariant();
  529. QList<QVariant>qList;
  530. qList<<QVariant(pic_path_str);
  531. qList<<QVariant(false);
  532. qList<<QVariant(true);
  533. qList<<tmp;
  534. QAxObject *Inlineshapes = document->querySubObject("InlineShapes");
  535. Inlineshapes->dynamicCall("AddPicture(const QString&, QVariant, QVariant ,QVariant)",qList);
  536. }
  537. }
  538. bookmark_pic=document->querySubObject("Bookmarks(QVariant)",g_bookmark_valvetest_picture[i]);
  539. // 选中标签,将图片插入到标签位置
  540. if(!bookmark_pic->isNull())
  541. {
  542. QString pic_path_str = pic_dir+tanker.licenseplate_str+"_"+QString::number(i+1)+"_valve.jpg";
  543. qDebug()<<pic_path_str;
  544. QFile file(pic_path_str);
  545. if(file.exists()){
  546. bookmark_pic->dynamicCall("Select(void)");
  547. QAxObject *range;
  548. range = bookmark_pic->querySubObject("Range");
  549. QVariant tmp = range->asVariant();
  550. QList<QVariant>qList;
  551. qList<<QVariant(pic_path_str);
  552. qList<<QVariant(false);
  553. qList<<QVariant(true);
  554. qList<<tmp;
  555. QAxObject *Inlineshapes = document->querySubObject("InlineShapes");
  556. Inlineshapes->dynamicCall("AddPicture(const QString&, QVariant, QVariant ,QVariant)",qList);
  557. }
  558. }
  559. }
  560. }
  561. //检测结果
  562. bool systest_pass = true;
  563. bool valvetest_pass = true;
  564. int nosys_testcount = 0;
  565. int novalve_testcount =0;
  566. for(int i=0; i<tanker.compartment_num; i++){
  567. Compartment& comp = tanker.get_compartment(i);
  568. if(comp.m_result.sys_test_ok){
  569. if(!comp.m_result.pass_sys_pressure){
  570. systest_pass = false;
  571. }
  572. }else{
  573. nosys_testcount++;
  574. }
  575. if(comp.m_result.valve_test_ok){
  576. if(!comp.m_result.pass_valve_pressure){
  577. valvetest_pass = false;
  578. }
  579. }else{
  580. novalve_testcount++;
  581. }
  582. }
  583. if(nosys_testcount != tanker.compartment_num){
  584. //系统检测结果
  585. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_SYSTEST_RESULT);
  586. if(!bookmark->isNull())
  587. {
  588. QString sText;
  589. if(systest_pass){
  590. sText=codec->toUnicode("合格");
  591. }else{
  592. sText=codec->toUnicode("超标");
  593. }
  594. qDebug()<<sText;
  595. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  596. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  597. }
  598. }
  599. if(novalve_testcount != tanker.compartment_num){
  600. //阀门检测结果
  601. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_VALVETEST_RESULT);
  602. if(!bookmark->isNull())
  603. {
  604. QString sText;
  605. if(valvetest_pass){
  606. sText=codec->toUnicode("合格");
  607. }else{
  608. sText=codec->toUnicode("超标");
  609. }
  610. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  611. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  612. }
  613. }
  614. //检测日期
  615. QDate date(QDate::currentDate());
  616. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_DATE_YEAR);
  617. if(!bookmark->isNull())
  618. {
  619. QString sText=codec->toUnicode(QString::number(date.year()).toStdString().c_str()); //此处为替换内容
  620. qDebug()<<sText;
  621. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  622. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  623. }
  624. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_DATE_MONTH);
  625. if(!bookmark->isNull())
  626. {
  627. QString sText=codec->toUnicode(QString::number(date.month()).toStdString().c_str()); //此处为替换内容
  628. qDebug()<<sText;
  629. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  630. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  631. }
  632. bookmark = document->querySubObject("Bookmarks(QVariant)",BOOKMARK_DATE_DAY);
  633. if(!bookmark->isNull())
  634. {
  635. QString sText=codec->toUnicode(QString::number(date.day()).toStdString().c_str()); //此处为替换内容
  636. qDebug()<<sText;
  637. bookmark->dynamicCall("Select(void)"); //选中要选中的区域
  638. bookmark->querySubObject("Range")->setProperty("Text",sText); //进行替换操作
  639. }
  640. //将文件保存为PDF,
  641. qDebug()<<"start save PDF file ";
  642. emit onProgress(text_progress2);
  643. //document->dynamicCall("SaveAs(const QString&))",QDir::toNativeSeparators(word_path));
  644. QVariant OutputFileName(word_path);
  645. QVariant ExportFormat(17); //17是pdf
  646. QVariant OpenAfterExport(false); //保存后是否自动打开
  647. document->querySubObject("ExportAsFixedFormat(const QVariant&,const QVariant&,const QVariant&)",
  648. OutputFileName,
  649. ExportFormat,
  650. OpenAfterExport);
  651. document->dynamicCall("Close (boolean)",false);
  652. word->dynamicCall("Quit()");
  653. emit onProgress(text_progress3);
  654. QThread::msleep(300);
  655. emit onProgress("close");
  656. return true;
  657. }