formwooldealing.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. #include "formwooldealing.h"
  2. #include "ui_formwooldealing.h"
  3. #include "xprogressbar.h"
  4. #include "sncdatabase.h"
  5. #include "dialogsubmitresponsedetail.h"
  6. #include "dialogsubmit.h"
  7. FormWoolDealing::FormWoolDealing(QWidget *parent) :
  8. QWidget(parent),
  9. ui(new Ui::FormWoolDealing)
  10. {
  11. ui->setupUi(this);
  12. initVariables();
  13. initUI();
  14. setTableWidgetNoData(ui->tableWidget);
  15. }
  16. FormWoolDealing::~FormWoolDealing()
  17. {
  18. m_movie->stop();
  19. m_movieBig->stop();
  20. delete m_movieBig;
  21. delete m_movie;
  22. delete ui;
  23. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  24. <<"FormWool.FormWoolDealing Destroyed.";
  25. }
  26. void FormWoolDealing::initVariables()
  27. {
  28. m_movie = new QMovie(":/working.gif");
  29. m_movie->start();
  30. m_movieBig = new QMovie(":/fetchfromserver.gif");
  31. m_movieBig->start();
  32. m_blanceOut = false;
  33. m_state = NotLogin;
  34. m_keys << "state" << "taskid" << "pnumfiletype" << "origfilename" <<"createtime" << "hmzs" << "feecount" << "duefee" << "settlefee";
  35. m_headers << "状态" << "任务单号" << "文件类型" << "原始文件" << "提交时间" << "号码总数" << "计费条数" << "应收费用" << "实际缴费";
  36. }
  37. void FormWoolDealing::setAccountInfo(QMap<QString, QString> info)
  38. {
  39. m_account = info;
  40. QString ssoHash = info.value("ssohash");
  41. QString userCode = info.value("usercode");
  42. QString userHash = info.value("ssohash");
  43. if(!ssoHash.isEmpty())
  44. {
  45. if(!userHash.isEmpty())
  46. {
  47. m_state = LoginOk;
  48. setTableWidgetSyncData(ui->tableWidget);
  49. }
  50. else
  51. {
  52. if(!userCode.isEmpty())
  53. {
  54. m_state = LoginError;
  55. }
  56. else
  57. {
  58. m_state = NotBind;
  59. }
  60. }
  61. }
  62. else
  63. {
  64. m_state = NotLogin;
  65. }
  66. if(m_state!=LoginOk)
  67. {
  68. setTableWidgetNoData(ui->tableWidget);
  69. }
  70. }
  71. void FormWoolDealing::setClientName(QString name)
  72. {
  73. m_clientName = name;
  74. }
  75. void FormWoolDealing::setClientID(QString clientID)
  76. {
  77. m_clientID = clientID;
  78. }
  79. void FormWoolDealing::initUI()
  80. {
  81. ui->tableWidget->setColumnCount(m_headers.size());
  82. ui->tableWidget->setHorizontalHeaderLabels(m_headers);
  83. ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
  84. ui->tableWidget->setShowGrid(false);
  85. ui->tableWidget->setAlternatingRowColors(true);
  86. ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
  87. ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
  88. ui->tableWidget->verticalHeader()->setVisible(false);
  89. ui->tableWidget->horizontalHeader()->setStyleSheet("font:12px");
  90. ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
  91. ui->tableWidget->verticalHeader()->setResizeMode(QHeaderView::Fixed);
  92. ui->tableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  93. ui->tableWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
  94. ui->tableWidget->verticalHeader()->setFixedWidth(30);
  95. ui->tableWidget->setSortingEnabled(true);
  96. ui->tableWidget->setColumnWidth(0,30);
  97. ui->tableWidget->setColumnWidth(1,0);
  98. ui->tableWidget->setColumnWidth(2,66);
  99. ui->tableWidget->setColumnWidth(3,170);
  100. ui->tableWidget->setColumnWidth(4,130);
  101. ui->tableWidget->setColumnWidth(5,79);
  102. ui->tableWidget->setColumnWidth(6,79);
  103. ui->tableWidget->setColumnWidth(7,60);
  104. ui->tableWidget->setColumnWidth(8,60);
  105. // m_headers << "状态" << "任务单号" << "文件类型" << "原始文件" << "提交时间" << "号码总数" << "计费条数" << "应收费用" << "实际缴费";
  106. }
  107. void FormWoolDealing::setTableWidgetNoData(QTableWidget *tableWidget)
  108. {
  109. prepareTableWidgetCells(tableWidget,10);
  110. tableWidget->setEnabled(false);
  111. QTableWidgetItem *item = new QTableWidgetItem();
  112. item->setTextAlignment(Qt::AlignLeft|Qt::AlignVCenter);
  113. item->setText(" 暂无信息");
  114. tableWidget->setItem(5,4,item);
  115. }
  116. void FormWoolDealing::setTableWidgetSyncData(QTableWidget *tableWidget)
  117. {
  118. prepareTableWidgetCells(tableWidget,10);
  119. tableWidget->setEnabled(false);
  120. QLabel *lbl = new QLabel();
  121. QTableWidgetItem *item = new QTableWidgetItem(" 正在读取...");
  122. lbl->setMovie(m_movieBig);
  123. item->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
  124. tableWidget->setItem(5,4,item);
  125. tableWidget->setCellWidget(5,4,lbl);
  126. }
  127. void FormWoolDealing::prepareTableWidgetCells(QTableWidget *tableWidget, int rows)
  128. {
  129. tableWidget->setRowCount(0);
  130. tableWidget->setRowCount(rows);
  131. }
  132. void FormWoolDealing::fillDataList(QTableWidget *tableWidget,QStringList keys,
  133. QMultiMap<QString, QString> list, int rowCount)
  134. {
  135. setTableWidgetNoData(tableWidget);
  136. if(rowCount==0)
  137. {
  138. return ;
  139. }
  140. prepareTableWidgetCells(tableWidget,rowCount);
  141. tableWidget->setEnabled(true);
  142. for(int row = 0;row < rowCount;row++)
  143. {
  144. QMap<QString,QString> map;
  145. for(int col=0;col<keys.size();col++)
  146. {
  147. QString key = keys.at(col);
  148. QString value = list.values(key).at(row);
  149. map.insert(key,value);
  150. }
  151. for(int col=0;col<keys.size();col++)
  152. {
  153. QString key = keys.at(col);
  154. QString value = list.values(key).at(row);
  155. setCellElement(tableWidget,row,col,key,value,map);
  156. }
  157. }
  158. tableWidget->sortByColumn(0);
  159. tableWidget->sortByColumn(0);
  160. }
  161. void FormWoolDealing::setCellElement(QTableWidget *tableWidget, int row, int col,
  162. QString key,QString value,QMap<QString,QString> data)
  163. {
  164. QTableWidgetItem* item = new QTableWidgetItem();
  165. QVariant display = value;
  166. QVariant tooltip = value;
  167. item->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
  168. //进行数据翻译
  169. if(key=="taskid")
  170. {
  171. QString detail = data.value("detail");
  172. tooltip = detail;
  173. }
  174. else if(key == "pnumfiletype")
  175. {
  176. if(value=="1")
  177. display = "号码文件";
  178. else if(value=="2")
  179. display = "号段文件";
  180. else
  181. display = "未知";
  182. tooltip = display;
  183. }
  184. else if(key=="hmzs")
  185. {
  186. display = data.value("hmzs").toInt();
  187. tooltip = data.value("hmzs");
  188. }
  189. else if(key=="feecount")
  190. {
  191. display = data.value("feecount").toInt();
  192. tooltip = data.value("feecount");
  193. }
  194. //设置单元格显示形式,是用item填充还是widget填充
  195. if(key=="state")
  196. {
  197. delete item;
  198. QLabel *lbl = new QLabel();
  199. lbl->setAlignment(Qt::AlignCenter|Qt::AlignHCenter);
  200. QString state = data.value("state");
  201. // QString statestr = data.value("statestr");
  202. // QString isverify = data.value("isverify");
  203. // QString tftime = data.value("tftime");
  204. QString isverify = "1"; //默认审核通过
  205. if(isverify == "0")
  206. {/*
  207. if(tftime.isEmpty())
  208. {
  209. if(m_blanceOut)
  210. lbl->setToolTip("等待付款");
  211. else
  212. lbl->setToolTip("等待审核");
  213. lbl->setPixmap(QPixmap(":/task_lock.png"));
  214. }
  215. else if(tftime>"2000-01-01 00:00:00")
  216. {
  217. lbl->setToolTip("等待检测");
  218. lbl->setPixmap(QPixmap(":/task_hourglass.png"));
  219. }
  220. else
  221. {
  222. if(m_blanceOut)
  223. lbl->setToolTip("等待付款");
  224. else
  225. lbl->setToolTip("等待审核");
  226. lbl->setPixmap(QPixmap(":/task_lock.png"));
  227. }
  228. if(optstatus=="-1")
  229. {
  230. lbl->setToolTip("服务端已经删除或失效");
  231. lbl->setPixmap(QPixmap(":/task_error.png"));
  232. }*/
  233. }
  234. else if(isverify == "2")
  235. {
  236. lbl->setPixmap(QPixmap(":/task_error.png"));
  237. lbl->setToolTip("审核未通过");
  238. }
  239. else // if(isverify == "1")
  240. {
  241. if(state == "-1")
  242. {
  243. lbl->setToolTip("文件已经失效");
  244. lbl->setPixmap(QPixmap(":/task_warning.png"));
  245. }
  246. else if(state == "0")
  247. {
  248. lbl->setToolTip("未提交");
  249. lbl->setPixmap(QPixmap(":/task_stop.png"));
  250. }
  251. else if(state == "1")
  252. {
  253. lbl->setToolTip("提交中");
  254. lbl->setPixmap(QPixmap(":/task_pause.png"));
  255. }
  256. else if(state == "2")
  257. {
  258. lbl->setToolTip("提交完毕");
  259. lbl->setPixmap(QPixmap(":/task_pause.png"));
  260. }
  261. else if(state == "3")
  262. {
  263. lbl->setToolTip("待检测");
  264. lbl->setPixmap(QPixmap(":/task_pause.png"));
  265. }
  266. else if(state == "4")
  267. {
  268. lbl->setToolTip("检测中");
  269. lbl->setPixmap(QPixmap(":/task_play.png"));
  270. }
  271. else if(state == "5")
  272. {
  273. lbl->setToolTip("检测完毕");
  274. lbl->setPixmap(QPixmap(":/task_ok.png"));
  275. }
  276. else if(state == "98")
  277. {
  278. lbl->setToolTip("任务已删除");
  279. lbl->setPixmap(QPixmap(":/task_warning.png"));
  280. }
  281. else if(state == "99")
  282. {
  283. lbl->setToolTip("发生错误");
  284. lbl->setPixmap(QPixmap(":/task_error.png"));
  285. }
  286. else
  287. {
  288. lbl->setToolTip("上传成功");
  289. lbl->setPixmap(QPixmap(":/task_ok.png"));
  290. }
  291. }
  292. tableWidget->setCellWidget(row,col,lbl);
  293. }/*
  294. else if(key=="finishcount")
  295. {
  296. delete item;
  297. int numcount = data.value("numcount").toInt();
  298. int finishcount = data.value("finishcount").toInt();
  299. double percent =0;
  300. if(numcount>0)
  301. percent = finishcount*100.0/numcount;
  302. QLabel *lbl = new QLabel();
  303. lbl->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
  304. XProgressBar *progress = 0;
  305. QString optstatus = data.value("optstatus");
  306. QString isverify = data.value("isverify");
  307. QString tftime = data.value("tftime");
  308. if(isverify == "0")
  309. {
  310. if(tftime.isEmpty())
  311. {
  312. if(m_blanceOut)
  313. lbl->setText("等待付款");
  314. else
  315. lbl->setText("等待审核");
  316. }
  317. else if(tftime>"2000-01-01 00:00:00")
  318. {
  319. lbl->setText("等待检测");
  320. }
  321. else
  322. {
  323. if(m_blanceOut)
  324. lbl->setText("等待付款");
  325. else
  326. lbl->setText("等待审核");
  327. }
  328. if(optstatus=="-1")
  329. {
  330. lbl->setText("服务端已经删除或失效");
  331. }
  332. }
  333. else if(isverify == "2")
  334. {
  335. lbl->setText("审核未通过");
  336. }
  337. else // if(isverify == "1")
  338. {
  339. if(optstatus == "-1")
  340. {
  341. lbl->setText("文件已经失效");
  342. }
  343. else if(optstatus == "0")
  344. {
  345. lbl->setText("停止");
  346. //modify by xxw on 2016-7-23
  347. //把停止改为状态显示
  348. delete lbl;
  349. lbl = 0;
  350. progress = new XProgressBar();
  351. }
  352. else if(optstatus == "1")
  353. {
  354. lbl->setText("暂停");
  355. }
  356. else if(optstatus == "2")
  357. {
  358. lbl->setText("正在检测");
  359. delete lbl;
  360. lbl = 0;
  361. progress = new XProgressBar();
  362. }
  363. else if(optstatus == "3")
  364. {
  365. lbl->setText("正在处理");
  366. }
  367. else if(optstatus == "4" || optstatus == "5" || optstatus == "6")
  368. {
  369. lbl->setText("发生错误");
  370. }
  371. else
  372. {
  373. lbl->setText("未知" + optstatus);
  374. }
  375. }
  376. if(lbl)
  377. {
  378. tableWidget->setCellWidget(row,col,lbl);
  379. }
  380. else
  381. {
  382. progress->setProgress(3,percent);
  383. tableWidget->setCellWidget(row,col,progress);
  384. }
  385. }*/
  386. else
  387. {
  388. item->setData(Qt::DisplayRole,display);
  389. item->setData(Qt::UserRole,value);
  390. item->setData(Qt::ToolTipRole,tooltip);
  391. tableWidget->setItem(row,col,item);
  392. }
  393. }
  394. void FormWoolDealing::query()
  395. {
  396. QString userCode = m_account.value("usercode");
  397. QMultiMap<QString,QString> list = SNCDataBase::getWoolCheckDealingInfos(userCode);
  398. int cols = list.uniqueKeys().size();
  399. int rows = 0;
  400. if(cols!=0)
  401. rows = list.size()/cols;
  402. if(list.size()==0)
  403. {
  404. setTableWidgetNoData(ui->tableWidget);
  405. return ;
  406. }
  407. QStringList ids;
  408. QString curId;
  409. for(int i=0;i<ui->tableWidget->rowCount();i++)
  410. {
  411. QTableWidgetItem *item = ui->tableWidget->item(i,0);
  412. if(item)
  413. {
  414. if(item->checkState()==Qt::Checked)
  415. {
  416. ids<<item->data(Qt::UserRole).toString();
  417. }
  418. if(item->isSelected())
  419. {
  420. curId = item->data(Qt::UserRole).toString();
  421. }
  422. }
  423. }
  424. fillDataList(ui->tableWidget,m_keys,list,rows);
  425. for(int i=0;i<ui->tableWidget->rowCount();i++)
  426. {
  427. if(curId.isEmpty())
  428. {
  429. ui->tableWidget->selectRow(i);
  430. ui->tableWidget->setFocus();
  431. break;
  432. }
  433. QTableWidgetItem *item = ui->tableWidget->item(i,0);
  434. if(item)
  435. {
  436. QString id = item->data(Qt::UserRole).toString();
  437. if(curId==id)
  438. {
  439. ui->tableWidget->selectRow(i);
  440. ui->tableWidget->setFocus();
  441. }
  442. for(int i=0;i<ids.size();i++)
  443. {
  444. if(id==ids.at(i))
  445. {
  446. item->setCheckState(Qt::Checked);
  447. break;
  448. }
  449. }
  450. }
  451. }
  452. }
  453. void FormWoolDealing::showRtnMessage(int row)
  454. {
  455. QTableWidgetItem *itemMsg = ui->tableWidget->item(row,8);
  456. QTableWidgetItem *itemDetail = ui->tableWidget->item(row,9);
  457. QString errMsg = "";
  458. QString errDetail = "";
  459. if(itemMsg)
  460. {
  461. errMsg = itemMsg->data(Qt::UserRole).toString();
  462. }
  463. if(itemDetail)
  464. {
  465. errDetail = itemDetail->data(Qt::UserRole).toString();
  466. }
  467. if(errDetail.isEmpty())
  468. {
  469. if(!errMsg.isEmpty())
  470. {
  471. QMessageBox::critical(this,"提示",errMsg,QMessageBox::Ok);
  472. }
  473. }
  474. else
  475. {
  476. DialogSubmitResponseDetail dialog;
  477. dialog.setDetailText(errDetail);
  478. dialog.exec();
  479. }
  480. }
  481. void FormWoolDealing::onPushButtonViewsClicked()
  482. {
  483. QPushButton *btn = qobject_cast<QPushButton*>(sender());
  484. for(int i=0;i<ui->tableWidget->rowCount();i++)
  485. {
  486. QWidget *widget = ui->tableWidget->cellWidget(i,ui->tableWidget->columnCount()-1);
  487. if(widget)
  488. {
  489. if(btn==qobject_cast<QPushButton*>(widget))
  490. {
  491. showRtnMessage(i);
  492. break;
  493. }
  494. }
  495. }
  496. }
  497. void FormWoolDealing::onDataUpdated()
  498. {
  499. query();
  500. }
  501. void FormWoolDealing::on_tableWidget_cellDoubleClicked(int row, int column)
  502. {
  503. showRtnMessage(row);
  504. }
  505. bool FormWoolDealing::chkAccountState(AccountLoginState state)
  506. {
  507. bool ret = false;
  508. switch(state)
  509. {
  510. case NotLogin:
  511. QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
  512. break;
  513. case NotBind:
  514. QMessageBox::critical(this,"提示","此项服务尚未开通,请开通后再操作!",QMessageBox::Ok);
  515. break;
  516. case LoginError:
  517. QMessageBox::critical(this,"提示","此项服务暂时无法连接,请稍候重试!",QMessageBox::Ok);
  518. break;
  519. default:
  520. ret = true;
  521. }
  522. return ret;
  523. }
  524. //add by xw on 2015-11-1 for 5.4.8
  525. //客户如果余额不足,上传完数据后检测进度的状态请改为“等待付款”,如果余额够就显示为“等待审核”
  526. void FormWoolDealing::onBalanceOut()
  527. {
  528. m_blanceOut = true;
  529. }
  530. void FormWoolDealing::onBalanceIn()
  531. {
  532. m_blanceOut = false;
  533. }