dialogbindsystem.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "dialogbindsystem.h"
  2. #include "ui_dialogbindsystem.h"
  3. #include "WSSSO.h"
  4. #include "sncdatabase.h"
  5. #include "respregsysaccounts.h"
  6. #include "respbindsysaccount.h"
  7. #include <QtGui>
  8. DialogBindSystem::DialogBindSystem(QWidget *parent) :
  9. QDialog(parent),
  10. ui(new Ui::DialogBindSystem)
  11. {
  12. ui->setupUi(this);
  13. genValidateCode();
  14. ui->buttonBox->setVisible(false);
  15. this->succeed = true ;
  16. this->setFixedHeight(200);
  17. this->setFixedWidth(300);
  18. }
  19. void DialogBindSystem::setSysRegInfo(QString sysCode,QString userHash)
  20. {
  21. this->sysCode = sysCode;
  22. this->userHash = userHash;
  23. }
  24. bool DialogBindSystem::serviceIsOpen()
  25. {
  26. return this->succeed;
  27. }
  28. DialogBindSystem::~DialogBindSystem()
  29. {
  30. delete ui;
  31. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  32. <<"SNCUser.DialogBindSystem Destroyed.";
  33. }
  34. void DialogBindSystem::on_pushButtonRegService_clicked()
  35. {
  36. ui->pushButtonRegService->setEnabled(false);
  37. WSSSO interface;
  38. QString regSrc = "mf-" + SNCDataBase::getAppVersion();
  39. QString json = interface.regSysAccount(this->sysCode,this->userHash,regSrc);
  40. RespRegSysAccounts response(json);
  41. qDebug()<<json;
  42. if(json.isEmpty())
  43. {
  44. QMessageBox::warning(NULL,"极速号码魔方","网络连接失败!",QMessageBox::Ok);
  45. }
  46. else
  47. {
  48. if(response.getRtnCode()==1)
  49. {
  50. QMessageBox::information(NULL,"极速号码魔方","恭喜,服务开通成功,下次登录时生效!",QMessageBox::Ok);
  51. this->succeed = true ;
  52. this->close();
  53. }
  54. else
  55. {
  56. QMessageBox::critical(NULL,"极速号码魔方",response.getRtnMemo(),QMessageBox::Ok);
  57. }
  58. }
  59. ui->pushButtonRegService->setEnabled(true);
  60. }
  61. void DialogBindSystem::on_pushButtonBindService_clicked()
  62. {
  63. if(ui->lineEditValidateCode->text()!=ui->labelCode->text())
  64. {
  65. QMessageBox::critical(this,"提示","验证码不正确!",QMessageBox::Ok);
  66. genValidateCode();
  67. return ;
  68. }
  69. ui->pushButtonBindService->setEnabled(false);
  70. WSSSO interface;
  71. QString json = interface.bindSysAccount(this->sysCode,ui->lineEditUserID->text(),
  72. ui->lineEditUserPwd->text(),this->userHash);
  73. RespBindSysAccount response(json);
  74. if(json.isEmpty())
  75. {
  76. QMessageBox::warning(NULL,"极速号码魔方","网络连接失败!",QMessageBox::Ok);
  77. }
  78. else
  79. {
  80. if(response.getRtnCode()==1)
  81. {
  82. QMessageBox::information(NULL,"极速号码魔方","恭喜,服务绑定成功,下次登录时生效!",QMessageBox::Ok);
  83. this->succeed = true ;
  84. this->close();
  85. }
  86. else
  87. {
  88. QMessageBox::critical(NULL,"极速号码魔方",response.getRtnMemo(),QMessageBox::Ok);
  89. }
  90. }
  91. genValidateCode();
  92. ui->pushButtonBindService->setEnabled(true);
  93. }
  94. void DialogBindSystem::genValidateCode()
  95. {
  96. QTime time;
  97. time= QTime::currentTime();
  98. qsrand(time.msec()+time.second()*1000);
  99. int rnd = qrand()%9999;
  100. QString code = "00000"+QString::number(rnd);
  101. this->ui->labelCode->setText(code.right(4));
  102. }