formrec.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include "formrec.h"
  2. #include "ui_formrec.h"
  3. #include "sncdatabase.h"
  4. FormRec::FormRec(QWidget *parent) :
  5. QWidget(parent),
  6. ui(new Ui::FormRec)
  7. {
  8. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  9. <<"FormRec Creating...";
  10. ui->setupUi(this);
  11. initVariables();
  12. initUI();
  13. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  14. <<"FormRec Created!";
  15. }
  16. FormRec::~FormRec()
  17. {
  18. //delete m_formAd;
  19. delete m_formToday;
  20. //delete m_formAccount;
  21. delete m_model;
  22. delete ui;
  23. qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
  24. <<"FormRec Destroyed.";
  25. }
  26. void FormRec::setAccountInfo(QMap<QString, QString> info)
  27. {
  28. m_account = info;
  29. m_formToday->setAccountInfo(info);
  30. //m_formAccount->setAccountInfo(info);
  31. m_sync->setAccountInfo(info);
  32. m_userCode = m_account.value("usercode");
  33. QString ssoHash = info.value("ssohash");
  34. if(!ssoHash.isEmpty())
  35. {
  36. m_state = LoginOk;
  37. if(!m_sync->isRunning())
  38. {
  39. m_sync->start();
  40. }
  41. }
  42. else
  43. {
  44. m_state = NotLogin;
  45. m_sync->abort();
  46. }
  47. }
  48. void FormRec::onSegsSelected(QStringList segs)
  49. {
  50. QStringList list = m_model->stringList();
  51. for(int i=0;i<list.size();i++)
  52. {
  53. for(int j=0;j<segs.size();j++)
  54. {
  55. if(list.at(i)==segs.at(j))
  56. {
  57. QMessageBox::critical(this,"错误","号段已经存在",QMessageBox::Ok);
  58. return ;
  59. }
  60. }
  61. }
  62. list.append(segs);
  63. if(list.size()>50)
  64. {
  65. QMessageBox::critical(this,"错误","您最多能选择50个号段",QMessageBox::Ok);
  66. return ;
  67. }
  68. m_model->setStringList(list);
  69. ui->labelSegCount->setText(QString("共%1个号段").arg(m_model->stringList().size()));
  70. }
  71. void FormRec::initVariables()
  72. {
  73. //m_formAd = new FormAd();
  74. m_formToday = new FormTodayRec();
  75. // m_formAccount = new FormAccountInfo();
  76. m_sync = new AutoSyncData();
  77. m_model = new QStringListModel();
  78. m_state = NotLogin;
  79. connect(m_sync,SIGNAL(dataSync()),m_formToday,SLOT(onDataUpdated()));
  80. //connect(m_formAccount,SIGNAL(buttonLoginClick()),this,SIGNAL(buttonLoginClick()));
  81. connect(m_formToday,SIGNAL(segSelected(QStringList)),this,SLOT(onSegsSelected(QStringList)));
  82. }
  83. void FormRec::initUI()
  84. {
  85. //ui->verticalLayoutAd->addWidget(m_formAd);
  86. ui->verticalLayoutToday->addWidget(m_formToday);
  87. //ui->horizontalLayoutAccount->addWidget(m_formAccount);
  88. ui->listView->setModel(m_model);
  89. ui->labelSegCount->setText(QString("共%1个号段").arg(m_model->stringList().size()));
  90. }
  91. bool FormRec::chkAccountState(AccountLoginState state)
  92. {
  93. bool ret = false;
  94. switch(state)
  95. {
  96. case NotLogin:
  97. QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
  98. break;
  99. case NotBind:
  100. QMessageBox::critical(this,"提示","此项服务尚未开通,请开通后再操作!",QMessageBox::Ok);
  101. break;
  102. case LoginError:
  103. QMessageBox::critical(this,"提示","此项服务暂时无法连接,请稍候重试!",QMessageBox::Ok);
  104. break;
  105. default:
  106. ret = true;
  107. }
  108. return ret;
  109. }
  110. void FormRec::on_pushButtonClear_clicked()
  111. {
  112. QStringList list;
  113. m_model->setStringList(list);
  114. ui->labelSegCount->setText(QString("共%1个号段").arg(m_model->stringList().size()));
  115. }
  116. void FormRec::on_pushButton_clicked()
  117. {
  118. if(!chkAccountState(m_state))
  119. return;
  120. QStringList segs = m_model->stringList();
  121. if(segs.size()==0)
  122. {
  123. QMessageBox::critical(this,"提示","号段不能为空",QMessageBox::Ok);
  124. return ;
  125. }
  126. QString path = QDir::tempPath() + QString("/SNCTempFile/");
  127. QDir dir(path);
  128. if(!dir.exists())
  129. {
  130. dir.mkpath(path);
  131. }
  132. QString fileName = QString("%1.txt").arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmss"));
  133. QString fullPath = path + fileName;
  134. QFile file(fullPath);
  135. if(!file.open(QIODevice::WriteOnly))
  136. return ;
  137. QTextStream out(&file);
  138. for(int i=0;i<segs.size();i++)
  139. {
  140. out<<segs.at(i)+"\r\n";
  141. }
  142. file.close();
  143. QString fileType = "2";
  144. QString taskType = "1";
  145. SNCDataBase::addFileUpload("shkj","",m_userCode,fileName,fullPath,fileType,taskType,"一键提交");
  146. segs.clear();
  147. m_model->setStringList(segs);
  148. QMessageBox::information(this,"提示","提交成功!",QMessageBox::Ok);
  149. }