#include "mainwindow.h"
#include "ui_mainwindow.h"
void MainWindow::timerEvent(QTimerEvent *event)
{
setStatusBar();
if(event->timerId()==m_timerID)
{
//刷新此持卡人信息
if(dealdate.ExistFile("./Data/RFID_R"))
{
//与数据库匹配对比信息并删除文件
QString RFID_QString;
dealdate.GetMes(&RFID_QString,"./Data/RFID_R");
//qDebug()<<RFID_QString;
QString ID,Class,Name;
if(Mysql->AutoCheckStuMes(RFID_QString,ID,Class,Name)&&Name!="")
{
ui->CardIDLabel->setText(RFID_QString);
ui->StuNumLabel->setText(ID);
ui->ClassLabel->setText(Class);
ui->NameLabel->setText(Name);
//设置头像
Stu_Face_Num=rand()%10;
QString face_QString=":/image/face";
face_QString.append(QString::number(Stu_Face_Num));
face_QString.append(".jpg");
qDebug()<<face_QString;
ui->StuFacelabel->setPixmap(QPixmap(face_QString));
ui->CMDplainTextEdit->appendPlainText(CurrTime::currentDateTime()+Name+"进行了持卡识别,且识别成功!");
}
else{
QMessageBox::information(this,"提示","此卡无数据!",QMessageBox::Yes);
ui->StuFacelabel->clear();
ui->CardIDLabel->setText("NULL");
ui->StuNumLabel->setText("NULL");
ui->ClassLabel->setText("NULL");
ui->NameLabel->setText("NULL");
ui->CMDplainTextEdit->appendPlainText(CurrTime::currentDateTime()+"未知卡片想进行识别,但被拒绝!");
}
}
//刷新上课信息
if(dealdate.ExistFile("./Data/R_RFID"))
{
//与数据库匹配对比信息并删除文件
//qDebug()<<"GO_CLASS";
QString RFID_QString;
dealdate.GetMes(&RFID_QString,"./Data/R_RFID");
//qDebug()<<RFID_QString;
m_OKToClass_CardID=RFID_QString;
QString ID,Class,Name;
if(Mysql->AutoCheckStuMes(RFID_QString,ID,Class,Name)&&Name!="")
{
ui->CardIDLabel_GoClass->setText(RFID_QString);
ui->StuNumLabel_GoClass->setText(ID);
ui->ClassLabel_GoClass->setText(Class);
ui->NameLabel_GoClass->setText(Name);
ui->CMDplainTextEdit->appendPlainText(CurrTime::currentDateTime()+Name+"进行了打卡上课。");
}
else
{
QMessageBox::information(this,"提示","此卡无数据!",QMessageBox::Yes);
ui->CardIDLabel_GoClass->setText("NULL");
ui->StuNumLabel_GoClass->setText("NULL");
ui->ClassLabel_GoClass->setText("NULL");
ui->NameLabel_GoClass->setText("NULL");
ui->CMDplainTextEdit->appendPlainText(CurrTime::currentDateTime()+"未知卡片想打卡上课但被拒绝!");
}
}
//刷新下班信息
if(dealdate.ExistFile("./Data/O_RFID"))
{
//与数据库匹配对比信息并删除文件
qDebug()<<"OVER_CLASS";
QString RFID_QString;
dealdate.GetMes(&RFID_QString,"./Data/O_RFID");
qDebug()<<RFID_QString;
m_OKToClass_CardID=RFID_QString;
QString ID,Class,Name;
if(Mysql->AutoCheckStuMes(RFID_QString,ID,Class,Name)&&Name!="")
{
ui->CardIDLabel_ClassOver->setText(RFID_QString);
ui->StuNumLabel_ClassOver->setText(ID);
ui->ClassLabel_ClassOver->setText(Class);
ui->NameLabel_ClassOver->setText(Name);
ui->CMDplainTextEdit->appendPlainText(CurrTime::currentDateTime()+Name+"进行了下课打卡。");
}
else
{
QMessageBox::information(this,"提示","此卡无数据!",QMessageBox::Yes);
ui->CardIDLabel_ClassOver->setText("NULL");
ui->StuNumLabel_ClassOver->setText("NULL");
ui->ClassLabel_ClassOver->setText("NULL");
ui->NameLabel_ClassOver->setText("NULL");
ui->CMDplainTextEdit->appendPlainText(CurrTime::currentDateTime()+"未知卡片想打卡下课但被拒绝!");
}
}
return;
}
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->MYSQLLOGO->setPixmap(QPixmap(":/image/mysqLOG.jpg"));
srand((unsigned) time(NULL)); //用时间做种,每次产生随机数不一样
setWindowTitle(tr("考勤管理系统"));
ComState=false;
m_timerID=startTimer(500);
BtnSt(0);
//设置状态栏
statusLabel=new QLabel();
this->setStatusBar();
connect(ui->LoginpushButton,SIGNAL(clicked(bool)),this,SLOT(LoginMysql()));
connect(ui->DIsconnectpushButton,SIGNAL(clicked(bool)),this,SLOT(disLinkMysql()));
connect(ui->ShowAllStudentpushButton,SIGNAL(clicked(bool)),this,SLOT(SelectAllStuBtn()));
connect(ui->ShowChoseClasspushButton,SIGNAL(clicked(bool)),this,SLOT(SelectAllChoseBtn()));
connect(ui->ShowClassButton,SIGNAL(clicked(bool)),this,SLOT(SelectAllClassBtn()));
connect(ui->ShowInCourseOfpushButton,SIGNAL(clicked(bool)),this,SLOT(SelectInCourseOf()));
connect(ui->OpenCompushButton,SIGNAL(clicked(bool)),this,SLOT(OpenCOM()));
connect(ui->OpenCompushButton_GoClass,SIGNAL(clicked(bool)),this,SLOT(OpenCOM_SK()));
connect(ui->OkToClasspushButton,SIGNAL(clicked(bool)),this,SLOT(OkTOClassBtn()));
connect(ui->ClassOverpushButton,SIGNAL(clicked(bool)),this,SLOT(OverClassBtn()));
connect(ui->OpenCompushButton_ClassOver,SIGNAL(clicked(bool)),this,SLOT(OpenCOM_XK()));
connect(ui->ShowStuNumClassButton,SIGNAL(clicked(bool)),this,SLOT(showStuNumClass()));
connect(ui->ShowStuNumClassButton_Name,SIGNAL(clicked(bool)),this,SLOT(showStuNumClass_Name()));
connect(ui->GradepushButton,SIGNAL(clicked(bool)),this,SLOT(TeacherStatisticsBtn()));
connect(ui->DeleteStupushButton,SIGNAL(clicked(bool)),this,SLOT(DeleteStuNumBtn()));
connect(ui->AddStuOKpushButton,SIGNAL(clicked(bool)),this,SLOT(AddStuNumBtn()));
connect(ui->CreateLogpushButton,SIGNAL(clicked(bool)),this,SLOT(SaveLog()));
//action相关
connect(ui->AddStuaction,SIGNAL(triggered(bool)),this,SLOT(AddStuNumBtn()));
connect(ui->DeletStuaction,SIGNAL(triggered(bool)),this,SLOT(DeleteStuNumBtn()));
connect(ui->SelectAllStuaction,SIGNAL(triggered(bool)),this,SLOT(SelectAllStuBtn()));
connect(ui->SelectNowClassaction,SIGNAL(triggered(bool)),this,SLOT(SelectInCourseOf()));
connect(ui->SelectAllClassaction,SIGNAL(triggered(bool)),this,SLOT(SelectAllClassBtn()));
connect(ui->SelectAllChoseaction,SIGNAL(triggered(bool)),this,SLOT(SelectAllChoseBtn()));
connect(ui->SaveLogaction,SIGNAL(triggered(bool)),this,SLOT(SaveLog()));
ui->LoginpushButton->setEnabled(true);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::LoginMysql()
{
if(ui->SQLUserlineEdit->text()==""||ui->SQLPasswdlineEdit->text()==""||ui->DataBaselineEdit->text()=="")
{
QMessageBox::information(this,"提示","有一项为空,请填写完整",QMessageBox::Yes);
}
else
{
Mysql=new ConnMysql(ui->SQLUserlineEdit->text(),ui->SQLPasswdlineEdit->text(),ui->DataBaselineEdit->text());
MysqlLinkValues=Mysql->LinkMySQL();
ui->CMDplainTextEdit->appendPlainText(CurrTime::currentDateTime()+"Mysql登录成功!");
BtnSt(1);
}
}
void MainWindow::disLinkMysql()
{