#include "student.h"
#include "ui_student.h"
#include<QFont>
#include<QSqlQuery>
int grade_no=0;
QString answer_fill="xx";
Student::Student(QWidget *parent) :
QWidget(parent),
ui(new Ui::Student)
{
ui->setupUi(this);
setWindowTitle(tr("学生客户端"));//设置窗口标题
this->setFixedSize(this->width(),this->height());//固定窗口大小
h=2;m=0;s=0;ms=0;
model=new QSqlRelationalTableModel(this);//初始化model
int t;//产生不重复的1--20的随机整型数--随机用于抽取选择试题
QTime time1=QTime::currentTime();
qsrand(time1.msec()+time1.second()*1000);
for(int i=0;i<20;)
{
t=qrand()%20+1;
int m=0;
while(m<i&&no_repeat[m]!=t) m++;
if(m==i)
{
no_repeat[i]=t;
i++;
}
}
//设置来自教师的消息
QSqlQuery query1;
query1.exec("select t_inform_no,tno,neirong from t_inform");
while(query1.last())
{
QString str=query1.value(2).toString();
QMessageBox box(QMessageBox::Information,tr("教师消息"),str+tr("\n"));
box.setStandardButtons (QMessageBox::Ok);
box.setButtonText (QMessageBox::Ok,tr("确 定"));
box.exec();
break;
}
int t_fill;//产生不重复的1--10的随机整型数--用于随机抽取填空试题
QTime time2=QTime::currentTime();
qsrand(time2.msec()+time2.second()*1000);
for(int j=0;j<10;)
{
t_fill=qrand()%10+1;
int m_fill=0;
while(m_fill<j&&no_repeat_fill[m_fill]!=t_fill) m_fill++;
if(m_fill==j)
{
no_repeat_fill[j]=t_fill;
j++;
}
}
int j=0;
for(;j<10;j++)
qDebug()<<no_repeat_fill[j];
for(int k=0;k<30;k++)//给成绩的数组赋初值0
{
grade[k]=0;
}
groupbutton=new QButtonGroup;//考试ABCD选项
groupbutton->addButton(ui->radioButton_1_1,0);
groupbutton->addButton(ui->radioButton_1_2,1);
groupbutton->addButton(ui->radioButton_1_3,2);
groupbutton->addButton(ui->radioButton_1_4,3);
ui->stackedWidget->setCurrentIndex(4);//设置当前显示的页面
student_timer=new QTimer(this);//设置左下角的时间
student_timer->start(1000);
connect(student_timer,SIGNAL(timeout()),this,SLOT(student_update_time()));
ui->lcdNumber->setDigitCount(8);
ui->lcdNumber->setMode(QLCDNumber::Dec);
ui->lcdNumber->setSegmentStyle(QLCDNumber::Flat);
student_timer1=new QTimer(this);//设置考试倒计时的时间
student_timer1->start(1000);
QSqlQuery query;//设置欢迎xxx同学标签
query.exec("select sno,sname,ssex from student");
while(query.next())
{
QString student_id=query.value(0).toString();
QString student_name=query.value(1).toString();
QString student_sex=query.value(2).toString();
if(student_id==sno)
{
ui->label_22->setText(student_name);
ui->label_22->setStyleSheet("font: 11pt \"Comic Sans MS\";");
ui->label_23->setText(student_id);
ui->label_23->setStyleSheet("font: 10pt \"Comic Sans MS\";");
ui->label_24->setText(student_sex);
ui->label_24->setStyleSheet("font: 10pt \"Comic Sans MS\";");
break;
}
}
//由教师选中的选择题
QSqlQuery query2;
query2.exec("select * from no_problem");
while(query2.next())
{
QString str_no=query2.value(0).toString();
QString str_problem_no=query2.value(1).toString();
if(str_no=="1"&&str_problem_no=="0")
{
QSqlQuery query3;
query3.exec("select * from no_problem");
query3.next();
int i;i=0;
while(query3.next())
{
int no=query3.value(1).toInt();
no_repeat[i]=no;
i++;
}
break;
}
else break;
}
//由教师选中的填空题
QSqlQuery query3;
query3.exec("select * from fill_problem_no");
while(query3.next())
{
QString str_no=query3.value(0).toString();
QString str_problem_no=query3.value(1).toString();
if(str_no=="1"&&str_problem_no=="0")
{
QSqlQuery query4;
query4.exec("select * from fill_problem_no");
query4.next();
int j;j=0;
while(query4.next())
{
int no=query4.value(1).toInt();
no_repeat_fill[j]=no;
j++;
}
break;
}
else break;
}
j=0;
for(;j<10;j++)
qDebug()<<no_repeat_fill[j];
/*设置按钮特效
QString str_0="QPushButton{border-style: outset;} QPushButton:hover{border-radius: 5px; border: 5px groove gray;background-color:rgb(0, 255, 255); color: black;} QPushButton:pressed{ border-style: inset; }";
ui->pushButton_9->setStyleSheet(str_0);//鼠标移动按钮上时按钮变色,按钮凸起,点击凹陷
ui->pushButton_8->setStyleSheet(str_0);
ui->pushButton_10->setStyleSheet(str_0);
//ui->pushButton_11->setStyleSheet(str_0);
//ui->pushButton_13->setStyleSheet(str_0);*/
//connect(ui->pushButton_6,SIGNAL(clicked()),this, SLOT(student_save_problem()));//题目收藏
connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(student_ol_test()));//在线考试
connect(ui->pushButton_12,SIGNAL(clicked()),this,SLOT(student_start_test()));//开始在线考试
//connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(student_free_train()));//自主训练
connect(ui->pushButton_7,SIGNAL(clicked()),this,SLOT(student_free_talk()));//转到学生交流中心
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(student_t_inform()));//转到公告中心
connect(ui->pushButton_5,SIGNAL(clicked()),this,SLOT(student_grade()));//转到查看成绩处
connect(ui->pushButton_13,SIGNAL(clicked()),this,SLOT(student_back()));//返回登录界面
connect(ui->pushButton_11,SIGNAL(clicked()),this,SLOT(student_close()));//返回主页
connect(ui->pushButton_9,SIGNAL(clicked()),this,SLOT(student_update_password()));//修改密码
connect(ui->pushButton_8,SIGNAL(clicked()),this,SLOT(student_information()));//个人信息
connect(ui->pushButton_10,SIGNAL(clicked()),this,SLOT(student_help()));//请求帮助
}
void Student::student_update_time()//左下角时间变化函数
{
QDateTime time=QDateTime::currentDateTime();
QString str=time.toString("yyyy-MM-dd hh:mm:ss dddd");
ui->label_14->setText(str);
}
void Student::student_back_time()//倒计时变化函数
{
QTime time = QTime(h,m,s,ms);
ui->lcdNumber->display(time.toString("hh:mm:ss"));
s--;
if(h==0&&m==5&&s==-1)//剩余5分钟时变红色
{
QPalette lcdpal = ui->lcdNumber->palette();
lcdpal.setColor(QPalette::Normal,QPalette::WindowText,Qt::red);
ui->lcdNumber->setPalette(lcdpal);
}
if(s==-1)
{
m--;
s=59;
}
if(m==-1)
{
h--;
m=59;
}
if(h==0&&m==0&&s==-1)
{
Student::student_sum_grade();
}
}
void Student::student_ol_test()//在线考试
{
QTime time = QTime(h,m,s,ms);
QSqlQuery query;
query.exec("select sno,cno from ol_test");
while(query.next())
{
QString student_id=query.value(0).toString();
course_id=query.value(1).toString();
if(student_id==sno)
{
QSqlQuery query1;
query1.exec("select cno,cname from course");
while(query1.next())
{
QString course_id2=query1.value(0).toString();
QString course_name=query1.value(1).toString();
if(course_id==course_id2)
{
QMessageBox box(QMessageBox::Information,tr("系统消息"),tr("需要考试的科目是:")+course_name);
box.setStandardButtons (QMessageBox::Ok|QMessag