| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- #include "formrec.h"
- #include "ui_formrec.h"
- #include "sncdatabase.h"
- FormRec::FormRec(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::FormRec)
- {
- qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
- <<"FormRec Creating...";
- ui->setupUi(this);
- initVariables();
- initUI();
- qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
- <<"FormRec Created!";
- }
- FormRec::~FormRec()
- {
- //delete m_formAd;
- delete m_formToday;
- //delete m_formAccount;
- delete m_model;
- delete ui;
- qDebug()<<QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")\
- <<"FormRec Destroyed.";
- }
- void FormRec::setAccountInfo(QMap<QString, QString> info)
- {
- m_account = info;
- m_formToday->setAccountInfo(info);
- //m_formAccount->setAccountInfo(info);
- m_sync->setAccountInfo(info);
- m_userCode = m_account.value("usercode");
- QString ssoHash = info.value("ssohash");
- if(!ssoHash.isEmpty())
- {
- m_state = LoginOk;
- if(!m_sync->isRunning())
- {
- m_sync->start();
- }
- }
- else
- {
- m_state = NotLogin;
- m_sync->abort();
- }
- }
- void FormRec::onSegsSelected(QStringList segs)
- {
- QStringList list = m_model->stringList();
- for(int i=0;i<list.size();i++)
- {
- for(int j=0;j<segs.size();j++)
- {
- if(list.at(i)==segs.at(j))
- {
- QMessageBox::critical(this,"错误","号段已经存在",QMessageBox::Ok);
- return ;
- }
- }
- }
- list.append(segs);
- if(list.size()>50)
- {
- QMessageBox::critical(this,"错误","您最多能选择50个号段",QMessageBox::Ok);
- return ;
- }
- m_model->setStringList(list);
- ui->labelSegCount->setText(QString("共%1个号段").arg(m_model->stringList().size()));
- }
- void FormRec::initVariables()
- {
- //m_formAd = new FormAd();
- m_formToday = new FormTodayRec();
- // m_formAccount = new FormAccountInfo();
- m_sync = new AutoSyncData();
- m_model = new QStringListModel();
- m_state = NotLogin;
- connect(m_sync,SIGNAL(dataSync()),m_formToday,SLOT(onDataUpdated()));
- //connect(m_formAccount,SIGNAL(buttonLoginClick()),this,SIGNAL(buttonLoginClick()));
- connect(m_formToday,SIGNAL(segSelected(QStringList)),this,SLOT(onSegsSelected(QStringList)));
- }
- void FormRec::initUI()
- {
- //ui->verticalLayoutAd->addWidget(m_formAd);
- ui->verticalLayoutToday->addWidget(m_formToday);
- //ui->horizontalLayoutAccount->addWidget(m_formAccount);
- ui->listView->setModel(m_model);
- ui->labelSegCount->setText(QString("共%1个号段").arg(m_model->stringList().size()));
- }
- bool FormRec::chkAccountState(AccountLoginState state)
- {
- bool ret = false;
- switch(state)
- {
- case NotLogin:
- QMessageBox::critical(this,"提示","您现在还没有登录系统,请登录后再操作!",QMessageBox::Ok);
- break;
- case NotBind:
- QMessageBox::critical(this,"提示","此项服务尚未开通,请开通后再操作!",QMessageBox::Ok);
- break;
- case LoginError:
- QMessageBox::critical(this,"提示","此项服务暂时无法连接,请稍候重试!",QMessageBox::Ok);
- break;
- default:
- ret = true;
- }
- return ret;
- }
- void FormRec::on_pushButtonClear_clicked()
- {
- QStringList list;
- m_model->setStringList(list);
- ui->labelSegCount->setText(QString("共%1个号段").arg(m_model->stringList().size()));
- }
- void FormRec::on_pushButton_clicked()
- {
- if(!chkAccountState(m_state))
- return;
- QStringList segs = m_model->stringList();
- if(segs.size()==0)
- {
- QMessageBox::critical(this,"提示","号段不能为空",QMessageBox::Ok);
- return ;
- }
- QString path = QDir::tempPath() + QString("/SNCTempFile/");
- QDir dir(path);
- if(!dir.exists())
- {
- dir.mkpath(path);
- }
- QString fileName = QString("%1.txt").arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmss"));
- QString fullPath = path + fileName;
- QFile file(fullPath);
- if(!file.open(QIODevice::WriteOnly))
- return ;
- QTextStream out(&file);
- for(int i=0;i<segs.size();i++)
- {
- out<<segs.at(i)+"\r\n";
- }
- file.close();
- QString fileType = "2";
- QString taskType = "1";
- SNCDataBase::addFileUpload("shkj","",m_userCode,fileName,fullPath,fileType,taskType,"一键提交");
- segs.clear();
- m_model->setStringList(segs);
- QMessageBox::information(this,"提示","提交成功!",QMessageBox::Ok);
- }
|