diff --git a/studentdialog.cpp b/studentdialog.cpp index 849ea13d3a8a085b9fad17d3773dcfde1553de5f..057864025584e0cf3377394bf99a761863ef700d 100644 --- a/studentdialog.cpp +++ b/studentdialog.cpp @@ -14,6 +14,7 @@ StudentDialog::StudentDialog(QString user, QWidget *parent) : QDialog(parent), connect(&m_timer, SIGNAL(timeout()), this, SLOT(onTimeOut())); //设置个人信息区 + userid=user; ui->s_NoLabel->setText(user); QSqlQuery query; QString str = QString("SELECT sname,sdc,sclass FROM student WHERE sno='%1'").arg(user); @@ -183,9 +184,38 @@ void StudentDialog::on_searchBtn_clicked() //挂失槽函数 void StudentDialog::on_reportLossBtn_clicked() { + if(!isCardOk) + {QMessageBox::information(this,"提示","已经挂失!");return;} + if(isOnline) + {QMessageBox::information(this,"提示","上机状态不能挂失!");return;} if (QMessageBox::question(this, "挂失", "你是否确定要挂失?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) return; + QString str=QString("UPDATE card SET state='0' WHERE cardid='%1'") + .arg(cardid); + QSqlQuery query; + if (!query.exec(str)) + { + qDebug("挂失失败!"); + qDebug() << query.lastError(); + return; + } + else QMessageBox::information(this,"提示","挂失成功!"); + ui->c_OkLabel->setText("挂失"); + isCardOk=0; + QDateTime current_time = QDateTime::currentDateTime(); + QString losstime = current_time.toString("yyyy-MM-ddThh:mm:ss"); + str=QString("INSERT INTO loss_record " + "VALUES('%1','%2','%3','0')") + .arg(losstime) + .arg(cardid) + .arg(userid); + if (!query.exec(str)) + { + qDebug("插入数据失败!"); + qDebug() << query.lastError(); + return; + } } //充值槽函数 diff --git a/studentdialog.h b/studentdialog.h index f4e7ded5f049a8817601fe0fbcc72cc9c144984c..cb879fec33c2bf131abc89ab46edffd035883841 100644 --- a/studentdialog.h +++ b/studentdialog.h @@ -43,7 +43,9 @@ private: double cost; QString cardid; QString serial_num; //本次上机的流水号 + QString userid;//sno QTimer m_timer; + int stime; //秒 int mtime; //分钟 };