项目四源代码(修改)

1.globel.h

#ifndef GLOBEL_H
#define GLOBEL_H

#include <QGraphicsDropShadowEffect>
#include <QDebug>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QVariantList>
#include <QMessageBox>
#include <QSqlError>
#include <QButtonGroup>
#include <QStyleFactory>
#include<QStandardItemModel>
#include <QAbstractItemView>
enum MODIFY_ADD{
    MODIFY,
    ADD,
    CHECK
};
const QString USERNAME = "root";
const QString PASSWORD = "812814";
const QString PASSWORD_WWY = "142857";
#endif // GLOBEL_H

2.loginwindow.h

#ifndef LOGINWINDOW_H
#define LOGINWINDOW_H

#include "teacherwindow.h"
#include "studentwindow.h"

#include "reset.h"


QT_BEGIN_NAMESPACE
namespace Ui { class LoginWindow; }
QT_END_NAMESPACE

class LoginWindow : public QMainWindow {
    Q_OBJECT

public:
    LoginWindow(QWidget *parent = nullptr);
    ~LoginWindow();


private slots:
    void on_Btn_Login_clicked();

    void on_Btn_Reset_clicked();

    void on_Btn_Exit_clicked();

    void on_Btn_Pass_clicked();

private:
    Ui::LoginWindow *ui;

    QSqlDatabase db;
};

#endif // LOGINWINDOW_H

3.changepassword.h

#ifndef CHANGEPASSWORD_H
#define CHANGEPASSWORD_H

#include <QWidget>
#include "globel.h"

enum USER_TYPE{
    TEACHER,
    STUDENT
};


namespace Ui {
class changePassword;
}

class changePassword : public QWidget
{
    Q_OBJECT

public:
    explicit changePassword(QSqlDatabase db, QString username, int UserType,  QWidget *parent = nullptr);
    ~changePassword();

private slots:
    void on_Btn_Confirm_clicked();

    void on_Btn_Cancel_clicked();

private:
    Ui::changePassword *ui;

    QSqlDatabase data;

    QString username;

    int userType;

    int interfaceType;
};

#endif // CHANGEPASSWORD_H

4.modifystudent.h

#ifndef MODIFYSTUDENT_H
#define MODIFYSTUDENT_H

#include <QMainWindow>
#include "globel.h"


namespace Ui {
class ModifyStudent;
}

class ModifyStudent : public QMainWindow
{
    Q_OBJECT

public:
    explicit ModifyStudent(QSqlDatabase db, QString username, int model, QWidget *parent = nullptr);
    ~ModifyStudent();

    void init();


signals:
    void update();

private slots:
    void on_Btn_Cancel_clicked();

    void on_Btn_Save_clicked();

private:
    Ui::ModifyStudent *ui;

    QSqlDatabase db;

    QString username; //要修改的学号

    int Model; //0修改; 1新增

    QButtonGroup sex;
};

#endif // MODIFYSTUDENT_H

5.modifyteacher.h

#ifndef MODIFYTEACHER_H
#define MODIFYTEACHER_H

#include <QMainWindow>
#include "globel.h"

namespace Ui {
class ModifyTeacher;
}

class ModifyTeacher : public QMainWindow
{
    Q_OBJECT

public:
    explicit ModifyTeacher(QSqlDatabase db, QString username, int model, QWidget *parent = nullptr);
    ~ModifyTeacher();

    void init();

signals:
    void update();

private slots:
    void on_Btn_Cancel_clicked();

    void on_Btn_Save_clicked();

private:
    Ui::ModifyTeacher *ui;

    QSqlDatabase db;

    QString username;

    QButtonGroup admin;

    int Model;
};

#endif // MODIFYTEACHER_H

6.modifycourse.h

#ifndef MODIFYCOURSE_H
#define MODIFYCOURSE_H

#include <QMainWindow>
#include "globel.h"
namespace Ui {
class ModifyCourse;
}

class ModifyCourse : public QMainWindow
{
    Q_OBJECT

public:
    explicit ModifyCourse(QSqlDatabase db, QString username, int model, QWidget *parent = nullptr);
    ~ModifyCourse();

    void init();

signals:
    void update();
private slots:
    void on_Btn_Save_clicked();

    void on_Btn_Cancel_clicked();

private:
    Ui::ModifyCourse *ui;

    QSqlDatabase db;

    QString username;

    int Model;
};

#endif // MODIFYCOURSE_H

7.reset.h

#ifndef RESET_H
#define RESET_H

#include <QWidget>
#include "globel.h"

namespace Ui {
class Reset;
}

class Reset : public QWidget
{
    Q_OBJECT

public:
    explicit Reset(QString name, QWidget *parent = nullptr);
    ~Reset();

signals:
    void reset();

private slots:
    void on_Btn_No_clicked();

    void on_Btn_Yes_clicked();

private:
    Ui::Reset *ui;

    QString name;
};

#endif // RESET_H

8.statics.h

#ifndef STATICS_H
#define STATICS_H

#include <QWidget>
#include "globel.h"
namespace Ui {
class Statics;
}

class Statics : public QWidget
{
    Q_OBJECT

public:
    explicit Statics(QSqlDatabase db, QString course, QWidget *parent = nullptr);
    ~Statics();

    void avg();
    void count();
    void per();

private slots:
    void on_Btn_yes_clicked();

private:
    Ui::Statics *ui;

    QSqlDatabase database;

    QString course;
};

#endif // STATICS_H

9.studentwindow.h

#ifndef STUDENTWINDOW_H
#define STUDENTWINDOW_H

#include <QMainWindow>
#include "globel.h"
#include "changepassword.h"
namespace Ui {
class StudentWindow;
}

class StudentWindow : public QMainWindow {
    Q_OBJECT

public:
    explicit StudentWindow(QSqlDatabase db, QString username, QWidget *parent = nullptr);
    ~StudentWindow();

    void init_My();

    void init_Course();

    void init_Score();

    void init_SelectCourse();

    void SelectCourseRefresh();

    void SelectedCourseRefresh();

signals:
    void back();

private slots:
    void on_Btn_My_clicked();

    void on_Btn_Course_clicked();

    void on_Btn_Score_clicked();

    void on_Btn_Fee_clicked();

    void on_Btn_Search_clicked();

    void on_comboBox_currentTextChanged(const QString &arg1);

    void on_Compulsory_stateChanged(int arg1);

    void on_Btn_Exit_clicked();

    void on_Btn_SearchCourse_clicked();

    void on_Btn_SelectCourse_clicked();

    void on_Btn_deleteCourse_clicked();

    void on_ScoreTable_3_cellClicked(int row, int column);

    void on_Btn_Search_7_clicked();


    void on_Time_currentTextChanged(const QString &arg1);

private:
    Ui::StudentWindow *ui;

    QSqlDatabase db;

    QString username;

    QString currentTime;
};

#endif // STUDENTWINDOW_H

10.teacherwindow.h

#ifndef TEACHERWINDOW_H
#define TEACHERWINDOW_H

#include <QMainWindow>
#include "globel.h"
#include "modifyteacher.h"
#include "modifystudent.h"
#include "modifycourse.h"
#include "statics.h"
#include "changepassword.h"

//enum MANAGE_TABLE{
//    TEACHER_TABLE,
//    STUDENT_TABLE
//};

namespace Ui {
class TeacherWindow;
}

class TeacherWindow : public QMainWindow {
    Q_OBJECT

public:
    explicit TeacherWindow(QSqlDatabase db, QString username, QWidget *parent = nullptr);
    ~TeacherWindow();

    void init_My();

    void init_Student();

    void init_Score();

    void init_Course();



    QString calculate_GPA(QString Sno);

signals:
    void back();

private slots:
    void on_Btn_Exit_clicked();

    void on_Btn_Modify_clicked();

    void on_Btn_My_clicked();

    void on_Btn_Student_clicked();

    void on_Btn_Score_clicked();

    void on_Btn_Dorm_clicked();

//    void on_Classno_currentTextChanged(const QString &arg1);

    void on_Btn_Search_clicked();

    void on_Btn_Save_clicked();

//    void on_Btn_Exchange_clicked();

//    void on_Boy_stateChanged(int arg1);

//    void on_Gril_stateChanged(int arg1);

    void on_Btn_Add_clicked();



    void on_Btn_stat_clicked();

    void on_Btn_Delete_clicked();

    void on_StudentTable_cellClicked(int row, int column);

    void on_Btn_Search_7_clicked();



    void on_student_radiobutton_toggled(bool checked);

    void on_teacher_radiobutton_toggled(bool checked);

    void TeacherManageRefresh();

    void StudentManageRefresh();

    void CourseManageRefresh();

    void on_CourseTable_cellClicked(int row, int column);

    void on_Btn_Search_2_clicked();

    void on_Btn_Modify_2_clicked();

    void on_Btn_Add_2_clicked();

    void on_Btn_Delete_2_clicked();

    void on_Cno_currentTextChanged(const QString &arg1);

    void on_Classno_2_currentTextChanged(const QString &arg1);

private:
    Ui::TeacherWindow *ui;

    QSqlDatabase db;

    QString username;

    int ts_ManageTable;


};

#endif // TEACHERWINDOW_H

11.changepassword.cpp

#include "changepassword.h"
#include "ui_changepassword.h"

changePassword::changePassword(QSqlDatabase db, QString Username, int UserType, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::changePassword)
{
    ui->setupUi(this);

    setWindowFlags(Qt::CustomizeWindowHint);    // 隐藏标题栏
    setFixedSize(470, 270);
    data = db;
    username = Username;
    userType = UserType;

    ui->oldline->setEchoMode(QLineEdit::Password);   // 小黑点代替输入
    ui->newline->setEchoMode(QLineEdit::Password);   // 小黑点代替输入
    ui->confirmline->setEchoMode(QLineEdit::Password);   // 小黑点代替输入

    switch (userType) {
    case TEACHER:
    {
        ui->Btn_Confirm->setStyleSheet(
                    "QPushButton {"
                    "border: 1 solid #8c8c8c;"
                    "border-radius: 5px;"
                    "background : #107C41;"
                    "color: #ffffff;"
                    "}"
                    "QPushButton:hover {"
                        "background-color: #0F703B;"
                    "}"
                    "QPushButton:pressed {"
                        "background-color: #107C41;"
                        "border: 1 solid #000000;"
                    "}"
                    );
        ui->Btn_Cancel->setStyleSheet(
                    "QPushButton {"
                        "border-radius: 5px;"
                        "background : #ffffff;"
                        "color: #262626;"
                        "border: 1 solid #8c8c8c;"
                    "}"

                    "QPushButton:hover {"
                       " background-color: #E9F5EE;"
                    "}"

                    "QPushButton:pressed {"
                        "background-color: #ffffff;"
                        "border: 1 solid #000000;"
                    "}"
                    );

    }
        break;
    case STUDENT:
    {
        ui->Btn_Confirm->setStyleSheet(
                    "QPushButton {"
                    "border: 1 solid #8c8c8c;"
                    "border-radius: 5px;"
                    "background : #185ABD;"
                    "color: #ffffff;"
                    "}"
                    "QPushButton:hover {"
                        "background-color: #1651AA;"
                    "}"
                    "QPushButton:pressed {"
                        "background-color: #185ABD;"
                        "border: 1 solid #000000;"
                    "}"
                    );
        ui->Btn_Cancel->setStyleSheet(
                    "QPushButton {"
                        "border-radius: 5px;"
                        "background : #ffffff;"
                        "color: #262626;"
                        "border: 1 solid #8c8c8c;"
                    "}"

                    "QPushButton:hover {"
                       " background-color: #d9def5;"
                    "}"

                    "QPushButton:pressed {"
                        "background-color: #ffffff;"
                        "border: 1 solid #000000;"
                    "}"
                    );

    }
    }
}

changePassword::~changePassword()
{
    delete ui;
}

void changePassword::on_Btn_Confirm_clicked()
{
    if (ui->oldline->text() ==ui->newline->text()) {
        QMessageBox box;
        box.setIcon(QMessageBox::Warning);
        box.setWindowIcon(QIcon(":/res/logo.jpg"));
        box.setWindowTitle("警告");
        box.setText("新密码不能和旧密码相同");
        box.exec();
        return;
    }

    QSqlQuery query(data);
    switch (userType) {
    case TEACHER:
    {
        query.exec("select password "
                   "from teacher "
                   "where tno = '" + username + "'");
    }
        break;
    case STUDENT:
    {
        query.exec("select password "
                   "from student "
                   "where sno = '" + username + "'");
    }
    }
    if(query.isActive() && query.next() && query.value(0).toString() == ui->oldline->text()){
        QString new_1 = ui->newline->text();
        QString new_2 = ui->confirmline->text();
        if(new_1 != new_2){
            QMessageBox box;
            box.setIcon(QMessageBox::Warning);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("警告");
            box.setText("请确认密码");
            box.exec();
        }
        else {
            QSqlQuery query_new(data);
            switch (userType) {
            case TEACHER:
            {
                query_new.exec("update teacher "
                               "set password = '" + new_1 + "' "
                               "where tno = '" + username + "' ");
            }
                break;
            case STUDENT:
            {
                query_new.exec("update student "
                               "set password = '" + new_1 + "' "
                               "where sno = '" + username + "' ");
            }

            }
            if(query_new.isActive()){
                QMessageBox box;
                box.setIcon(QMessageBox::Information);
                box.setWindowIcon(QIcon(":/res/logo.jpg"));
                box.setWindowTitle("密码更改");
                box.setText("修改成功");
                box.exec();
                this->close();
            }
            else{
                QMessageBox box;
                box.setIcon(QMessageBox::Critical);
                box.setWindowIcon(QIcon(":/res/logo.jpg"));
                box.setWindowTitle("警告");
                box.setText("修改失败");
                box.exec();
                qDebug()<<query_new.lastError().text();
            }
        }
    }
    else {
        if(!query.isActive()){
            qDebug()<<query.lastError().text();
        }
        else {
            QMessageBox box;
            box.setIcon(QMessageBox::Critical);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("警告");
            box.setText("密码错误");
            box.exec();
        }
    }
}

void changePassword::on_Btn_Cancel_clicked()
{
        this->close();
}

12.loginwindow.cpp

#include "loginwindow.h"
#include "ui_loginwindow.h"

LoginWindow::LoginWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::LoginWindow) {
    ui->setupUi(this);

    setWindowFlags(Qt::CustomizeWindowHint);    // 隐藏标题栏
    setFixedSize(630, 420);

    ui->Login_Password->setEchoMode(QLineEdit::Password);   // 小黑点代替输入
    ui->Login_Username->setPlaceholderText("请输入用户名");
    ui->Login_Password->setPlaceholderText("请输入密码");
    ui->Mode_Student->setChecked(true);        // 设置默认选项

    //ui->Login_Username->setText("202241803629");
    //ui->Login_Password->setText("812814");

    if (QSqlDatabase::contains("qt_sql_default_connection"))                    // 连接数据库
        db = QSqlDatabase::database("qt_sql_default_connection");
    else
//        db = QSqlDatabase::addDatabase("QMYSQL");
          db = QSqlDatabase::addDatabase("QODBC");

    db.setHostName("localhost");
    db.setDatabaseName("studentmanager");
    db.setUserName(USERNAME);
//    db.setPassword(PASSWORD);
    db.setPassword(PASSWORD_WWY);

    if (!db.open())
        qDebug() << "Failed to connect to root mysql admin";
    else qDebug() << "open";
}

LoginWindow::~LoginWindow() {
    delete ui;
}


// =============================================================================== 登陆按钮
void LoginWindow::on_Btn_Login_clicked() {
    QString username = ui->Login_Username->text();
    QString password = ui->Login_Password->text();

    qDebug() << "用户名:" << username << "密码:" << password;

    if (ui->Mode_Teacher->isChecked()) {                                        // 登陆教师端
        QSqlQuery query(db);
        query.exec("select password "
                   "from teacher "
                   "where tno = '" + username + "'");

        if (query.next() && password == query.value(0).toString()) {
                this->hide();
                TeacherWindow *teacher = new TeacherWindow(db, username);
                teacher->show();

                connect(teacher, &TeacherWindow::back, this, [=]() {
                    this->show();
                });
        }
        else {
            QMessageBox box;
            box.setIcon(QMessageBox::Critical);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("警告");
            box.setText("用户名或密码错误");
            box.exec();
        }
    }

    else {                                                                      // 登陆学生端
        QSqlQuery query(db);
        query.exec("select password "
                   "from student "
                   "where sno = '" + username + "'");

        if (query.next() && password == query.value(0).toString()) {
                this->hide();
                StudentWindow *student = new StudentWindow(db, username);
                student->show();

                connect(student, &StudentWindow::back, this, [=]() {
                    this->show();
                });
        }
        else {
            QMessageBox box;
            box.setIcon(QMessageBox::Critical);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("警告");
            box.setText("用户名或密码错误");
            box.exec();
        }

    }
}

// =============================================================================== 重置按钮
void LoginWindow::on_Btn_Reset_clicked() {
    ui->Login_Username->clear();
    ui->Login_Password->clear();
}

// =============================================================================== 退出按钮
void LoginWindow::on_Btn_Exit_clicked() {
    this->close();
}

// =============================================================================== 忘记密码
void LoginWindow::on_Btn_Pass_clicked() {
    QString username = ui->Login_Username->text();
    if (username == "") {
        QMessageBox box;
        box.setIcon(QMessageBox::Warning);
        box.setWindowIcon(QIcon(":/res/logo.jpg"));
        box.setWindowTitle("警告");
        box.setText("请输入用户名");
        box.exec();
        return;
    }

    if (ui->Mode_Teacher->isChecked()) {
        QSqlQuery query(db);
        query.exec("select tname from teacher where tno = '" + username + "'");
        if (query.next()) {
            Reset *reset = new Reset(query.value(0).toString());
            reset->setWindowModality(Qt::ApplicationModal);
            reset->show();

            connect(reset, &Reset::reset, this, [=]() {
                QSqlQuery query(db);
                query.exec("update teacher set password = '" + username + "' where tno = '" + username + "'");
                QMessageBox box;
                box.setIcon(QMessageBox::Information);
                box.setWindowIcon(QIcon(":/res/logo.jpg"));
                box.setWindowTitle("警告");
                box.setText("密码已重置为您的职工号");
                box.exec();
            });
        }
        else {
            QMessageBox box;
            box.setIcon(QMessageBox::Warning);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("警告");
            box.setText("请输入正确的用户名");
            box.exec();
        }

    }
    else {
        QSqlQuery query(db);
        query.exec("select sname from student where sno = '" + username + "'");
        if (query.next()) {
            Reset *reset = new Reset(query.value(0).toString());
            reset->setWindowModality(Qt::ApplicationModal);
            reset->show();

            connect(reset, &Reset::reset, this, [=]() {
                QSqlQuery query(db);
                query.exec("update student set password = '" + username + "' where sno = '" + username + "'");
                QMessageBox box;
                box.setIcon(QMessageBox::Information);
                box.setWindowIcon(QIcon(":/res/logo.jpg"));
                box.setWindowTitle("警告");
                box.setText("密码已重置为您的学号");
                box.exec();
            });
        }
        else {
            QMessageBox box;
            box.setIcon(QMessageBox::Warning);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("警告");
            box.setText("请输入正确的用户名");
            box.exec();
        }

    }
}

13.modifystudent.cpp

#include "modifystudent.h"
#include "ui_modifystudent.h"

ModifyStudent::ModifyStudent(QSqlDatabase db, QString username, int model, QWidget *parent) : QMainWindow(parent), ui(new Ui::ModifyStudent) {
    ui->setupUi(this);

    setWindowFlags(Qt::CustomizeWindowHint);    // 隐藏标题栏
    setFixedSize(385, 420);

    this->db = db;

    sex.addButton(ui->sex1, 0);
    sex.addButton(ui->sex2, 1);
    ui->sex1->setChecked(true);
    Model = model;
    if(Model == MODIFY || Model == CHECK){
        this->username = username;
        init();
    }
}

ModifyStudent::~ModifyStudent() {
    delete ui;
}


void ModifyStudent::init() {
    QSqlQuery query(db);
    query.exec("select sno, sname, sex, grade, major, classno "
               "from student "
               "where sno = '" + username + "'");

    query.next();
    ui->Sno->setText(query.value(0).toString());
    ui->Sno->setReadOnly(true);
    ui->Sname->setText(query.value(1).toString());
    query.value(2).toString() == "男"?ui->sex1->setChecked(true):ui->sex2->setChecked(true);
    ui->Grade->setText(query.value(3).toString());
    ui->Major->setText(query.value(4).toString());
    ui->Classno->setText(query.value(5).toString());
    if(Model == CHECK){
        ui->Sname->setReadOnly(true);
        ui->sex1->setEnabled(false);
        ui->sex2->setEnabled(false);
        ui->Grade->setReadOnly(true);
        ui->Major->setReadOnly(true);
        ui->Classno->setReadOnly(true);
        ui->Btn_Save->setText("确定");
    }
}

void ModifyStudent::on_Btn_Cancel_clicked() {
    this->close();
}


void ModifyStudent::on_Btn_Save_clicked() {
    QSqlQuery query(db);

    switch(Model){
    case MODIFY:
    {
        bool k = query.exec("update student "
                             "set sname = '" + ui->Sname->text() + "', "
                                 "sex = '" + (sex.checkedId() == 0?"男":"女") + "', "
                                 "grade = '" + ui->Grade->text() + "', "
                                 "major = '" + ui->Major->text() + "', "
                                 "classno = '" + ui->Classno->text() + "' "
                                 "where sno = '" + username + "'");
        QMessageBox box;
        if (k) {
            box.setIcon(QMessageBox::Information);
            box.setWindowTitle("师生管理");
            box.setText("修改成功");
            box.exec();
            this->close();
            emit update();
        }
        else {
            box.setIcon(QMessageBox::Critical);
            box.setWindowTitle("师生管理");
            box.setText("修改失败,请检查数据正确性!");
            box.exec();
            qDebug()<<query.lastError().text();
        }
    }
        break;
    case ADD:
    {
        if(ui->Sno->text() == ""){
            QMessageBox box;
            box.setIcon(QMessageBox::Warning);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("师生管理");
            box.setText("新增无效");
            box.exec();
            return ;
        }
        QSqlQuery t = db.exec("insert into student "
                            "(sno, sname, sex, grade, major, classno, password) "
                            "values ("
                            " '" + ui->Sno->text() + "', "
                            " '" + ui->Sname->text() + "', "
                            " '" + (sex.checkedId() == 0?"男":"女") + "', "
                            " '" + ui->Grade->text() + "', "
                            " '" + ui->Major->text() + "', "
                            " '" + ui->Classno->text() + "', "
                            " '123456'); ");    //默认密码123456
        QMessageBox box;
        if (t.isActive()) {
            box.setIcon(QMessageBox::Information);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("师生管理");
            box.setText("新增成功");
            box.exec();
            this->close();
            emit update();
        }
        else {
            box.setIcon(QMessageBox::Critical);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("师生管理");
            box.setText("新增失败,请检查数据正确性!");
            box.exec();
            qDebug()<<t.lastError().text();
        }

    }
        break;
    case CHECK:
    {
        this->close();
    }
    }
}

14.modifyteacher.cpp

#include "modifyteacher.h"
#include "ui_modifyteacher.h"

ModifyTeacher::ModifyTeacher(QSqlDatabase db, QString username, int model, QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ModifyTeacher)
{
    ui->setupUi(this);
    setWindowFlags(Qt::CustomizeWindowHint);    // 隐藏标题栏
    setFixedSize(420, 500);
    Model = model;
    this->db = db;
    admin.addButton(ui->admin_1, 1);
    admin.addButton(ui->admin_2, 0);
    ui->admin_2->setChecked(true);

    ui->class_table->setRowCount(50);
    ui->class_table->setColumnCount(1);
    ui->class_table->setColumnWidth(0,150);
    ui->class_table->setStyle(QStyleFactory::create("Fusion"));
    ui->class_table->setHorizontalHeaderItem(0, new QTableWidgetItem("班级"));
    ui->course_table->setRowCount(50);
    ui->course_table->setColumnCount(1);
    ui->course_table->setColumnWidth(0,150);
    ui->course_table->setStyle(QStyleFactory::create("Fusion"));
    ui->course_table->setHorizontalHeaderItem(0, new QTableWidgetItem("课程"));
    if(Model == MODIFY || Model == CHECK){
        this->username = username;
        init();
    }
}

ModifyTeacher::~ModifyTeacher()
{
    delete ui;
}

void ModifyTeacher::init(){
    QSqlQuery query(db);
    query.exec("select tno, tname, admin "
               "from teacher "
               "where tno = '" + username + "'");

    query.next();
    ui->Tno->setText(query.value(0).toString());
    ui->Tno->setReadOnly(true);
    ui->Tname->setText(query.value(1).toString());
    if(query.value(2).toInt() == 1){
        ui->admin_1->setChecked(true);
    }
    else {
        ui->admin_2->setChecked(true);
    }
    QSqlQuery query_2(db);
    query_2.exec("select classno "
                 "from class "
                 "where tno = '" + username + "'");
    int row = 0;
    while(query_2.next()){
        ui->class_table->insertRow(row);
        ui->class_table->setItem(row, 0, new QTableWidgetItem(query_2.value(0).toString()));
        ui->class_table->item(row, 0)->setTextAlignment(Qt::AlignCenter);
    }
    QSqlQuery query_3(db);
    query_3.exec("select cno "
                 "from course "
                 "where tno = '" + username + "'");
    int row2 = 0;
    while(query_3.next()){
        ui->course_table->insertRow(row2);
        ui->course_table->setItem(row2, 0, new QTableWidgetItem(query_3.value(0).toString()));
        ui->course_table->item(row2, 0)->setTextAlignment(Qt::AlignCenter);
    }

    if(Model == CHECK){

        ui->Tname->setReadOnly(true);
        ui->admin_1->setEnabled(false);
        ui->admin_2->setEnabled(false);
        ui->class_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
        ui->course_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
        ui->Btn_Save->setText("确定");
    }

}


void ModifyTeacher::on_Btn_Cancel_clicked()
{
    this->close();
}

void ModifyTeacher::on_Btn_Save_clicked()
{
    switch (Model) {
    case MODIFY:
    {

        /*修改逻辑:只能带领目前没有教师带领的班级\只能任教目前没有教师授课的课程*/
        bool ifwork = true;
        bool ifconflict = false;  //如果选了已有老师带领的班级\已有授课的课程,造成冲突
        if(ui->Tno->text() == "")ifconflict = true;
        QSqlQuery query(db);
        query.exec("update teacher "
                   "set tname = '" + ui->Tname->text() + "', "
                       "admin = " + QString::number(admin.checkedId()) + " "
                       "where tno = '" + username + "'");
        if(!query.isActive()){
            qDebug()<<query.lastError().text();
            ifwork = false;
        }
        if(ifwork){
            db.exec("update class "
                    "set tno = '' "
                    "where tno = '" + username + "' ");
            int row = 0;
            while(ui->class_table->item(row, 0)){
                if( ui->class_table->item(row, 0)->text() == ""){
                    row++;
                    continue;
                }
                QSqlQuery q(db);
                q.exec("update class "
                       "set tno = '" + username + "' "
                       "where tno = '' and classno = '" + ui->class_table->item(row, 0)->text() + "'");
                row++;
                if(!q.isActive()){
                    qDebug()<<q.lastError().text();
                    ifwork = false;
                    break;
                }
                if(q.numRowsAffected() == 0){
                    ifconflict = true;
                }
            }
            if(ifwork){
                db.exec("update course "
                        "set tno = '' "
                        "where tno = '" + username + "' ");
                int row = 0;
                while(ui->course_table->item(row, 0)){
                    if( ui->course_table->item(row, 0)->text() == ""){
                        row++;
                        continue;
                    }
                    QSqlQuery q(db);
                    q.exec("update course "
                           "set tno = '" + username + "' "
                           "where tno = '' and cno = '" + ui->course_table->item(row, 0)->text() + "'");
                    row++;
                    if(!q.isActive()){
                        qDebug()<<q.lastError().text();
                        ifwork = false;
                        break;
                    }
                    if(q.numRowsAffected() == 0){
                        ifconflict = true;
                    }
                }
            }
        }
        if(ifwork){
            if(ifconflict){
                QMessageBox box;
                box.setIcon(QMessageBox::Warning);
                box.setWindowIcon(QIcon(":/res/logo.jpg"));
                box.setWindowTitle("师生管理");
                box.setText("修改无效");
                box.exec();
            }
            else {
                QMessageBox box;
                box.setIcon(QMessageBox::Information);
                box.setWindowIcon(QIcon(":/res/logo.jpg"));
                box.setWindowTitle("师生管理");
                box.setText("修改成功");
                box.exec();
                this->close();
                emit update();
            }
        }
        else {
            QMessageBox box;
            box.setIcon(QMessageBox::Critical);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("师生管理");
            box.setText("修改失败,请注意数据正确性");
            box.exec();
        }

    }
        break;
    case ADD:
    {
        /*新增逻辑:只能带领目前没有教师带领的班级\只能任教目前没有教师授课的课程*/
        bool ifwork = true;
        bool ifconflict = false;
        if(ui->Tno->text() == ""){
            QMessageBox box;
            box.setIcon(QMessageBox::Warning);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("师生管理");
            box.setText("新增无效");
            box.exec();
            return ;
        }
        QSqlQuery query(db);
        query.exec("insert into teacher(tno, tname, admin, password) "
                   "values ("
                   "'" + ui->Tno->text() + "', "
                   "'" + ui->Tname->text() + "', "
                   "" + QString::number(admin.checkedId()) + ", "
                   "'123456')");
        if(!query.isActive()){
            qDebug()<<query.lastError().text();
            ifwork = false;
        }
        if(ifwork){
            int row = 0;
            while(ui->class_table->item(row, 0)){
                if( ui->class_table->item(row, 0)->text() == ""){
                    row++;
                    continue;
                }
                QSqlQuery q(db);
                q.exec("update class "
                       "set tno = '" + ui->Tno->text() + "' "
                       "where tno = '' and classno = '" + ui->class_table->item(row, 0)->text() + "'");
                row++;
                if(!q.isActive()){
                    qDebug()<<q.lastError().text();
                    ifwork = false;
                    break;
                }
                if(q.numRowsAffected() == 0){
                    ifconflict = true;
                }
            }
            if(ifwork){
                int row = 0;
                while(ui->course_table->item(row, 0)){
                    if( ui->course_table->item(row, 0)->text() == ""){
                        row++;
                        continue;
                    }
                    QSqlQuery q(db);
                    q.exec("update course "
                           "set tno = '" + ui->Tno->text() + "' "
                           "where tno = '' and cno = '" + ui->course_table->item(row, 0)->text() + "'");
                    row++;
                    if(!q.isActive()){
                        qDebug()<<q.lastError().text();
                        ifwork = false;
                        break;
                    }
                    if(q.numRowsAffected() == 0){
                        ifconflict = true;
                    }
                }
            }
        }
        if(ifwork){
            if(ifconflict){
                QMessageBox box;
                box.setIcon(QMessageBox::Warning);
                box.setWindowIcon(QIcon(":/res/logo.jpg"));
                box.setWindowTitle("师生管理");
                box.setText("新增无效");
                box.exec();
            }
            else {
                QMessageBox box;
                box.setIcon(QMessageBox::Information);
                box.setWindowIcon(QIcon(":/res/logo.jpg"));
                box.setWindowTitle("师生管理");
                box.setText("新增成功");
                box.exec();
                this->close();
                emit update();
            }
        }
        else {
            QMessageBox box;
            box.setIcon(QMessageBox::Critical);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("师生管理");
            box.setText("新增失败, 请注意数据正确性");
            box.exec();
        }
    }
        break;
    case CHECK:
    {
        this->close();
    }
    }
}

15.modifycourse.cpp

#include "modifycourse.h"
#include "ui_modifycourse.h"

ModifyCourse::ModifyCourse(QSqlDatabase db, QString username, int model, QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ModifyCourse)
{
    ui->setupUi(this);

    setWindowFlags(Qt::CustomizeWindowHint);    // 隐藏标题栏
    setFixedSize(700, 360);

    ui->Grade->view()->window()->setWindowFlags(Qt::Popup|Qt::FramelessWindowHint|Qt::NoDropShadowWindowHint);
    ui->Grade->view()->window()->setAttribute(Qt::WA_TranslucentBackground);

    this->db = db;
    Model = model;

    if(Model == MODIFY || Model == CHECK){
        this->username = username;
        init();
    }
}

ModifyCourse::~ModifyCourse()
{
    delete ui;
}

void ModifyCourse::init(){
    QSqlQuery query(db);
    query.exec("select cno, cname, tno, grade, period, credit, assess, property "
               "from course "
               "where cno = '" + username + "'");

    query.next();
    ui->Cno->setText(query.value(0).toString());
    ui->Cno->setReadOnly(true);
    ui->Cname->setText(query.value(1).toString());
    ui->Tno->setText(query.value(2).toString());
    ui->Grade->setCurrentText(query.value(3).toString());
    ui->Period->setText(query.value(4).toString());
    ui->Credit->setText(query.value(5).toString());
    ui->Assess->setText(query.value(6).toString());
    ui->Property->setText(query.value(7).toString());
    if(Model == CHECK){

        ui->Cname->setReadOnly(true);
        ui->Tno->setReadOnly(true);
        ui->Grade->setEnabled(false);
        ui->Period->setReadOnly(true);
        ui->Credit->setReadOnly(true);
        ui->Assess->setReadOnly(true);
        ui->Property->setReadOnly(true);
        ui->Btn_Save->setText("确定");
    }
}



void ModifyCourse::on_Btn_Save_clicked()
{
    QSqlQuery query(db);
    query.exec("select tno from teacher where tno = '" + ui->Tno->text() + "'");

    if (!query.next()) {
        QMessageBox box;
        box.setIcon(QMessageBox::Critical);
        box.setWindowTitle("课程管理");
        box.setText("修改失败,请输入有效的教师编号!");
        box.exec();
        qDebug()<<query.lastError().text();
        return;
    }
    switch (Model) {
    case MODIFY:
    {
        QSqlQuery query(db);
        query.exec("update course set "
                   "cname = '" + ui->Cname->text() + "', "
                   "tno = '" + ui->Tno->text() + "', "
                   "grade = '" + ui->Grade->currentText().simplified() + "', "
                   "period = '" + ui->Period->text() + "', "
                   "credit = '" + ui->Credit->text() + "', "
                   "assess = '" + ui->Assess->text() + "', "
                   "property = '" + ui->Property->text() + "' "
                   "where cno = '" + username + "'");
        QMessageBox box;
        if(query.isActive()){
            box.setIcon(QMessageBox::Information);
            box.setWindowTitle("课程管理");
            box.setText("修改成功");
            box.exec();
            this->close();
            emit update();
        }
        else {
            box.setIcon(QMessageBox::Critical);
            box.setWindowTitle("课程管理");
            box.setText("修改失败,请检查数据正确性!");
            box.exec();
            qDebug()<<query.lastError().text();
        }
    }
        break;
    case ADD:
    {
        if(ui->Cno->text().trimmed() == "")return ;
        QSqlQuery query(db);
        query.exec("insert into course(cno, cname, tno, grade, period, credit, assess, property) "
                   "values ( "
                   " '" + ui->Cno->text() + "', "
                   " '" + ui->Cname->text() + "', "
                   " '" + ui->Tno->text() + "', "
                   " '" + ui->Grade->currentText().simplified() + "', "
                   " '" + ui->Period->text() + "', "
                   " '" + ui->Credit->text() + "', "
                   " '" + ui->Assess->text() + "', "
                   " '" + ui->Property->text() + "')");
        QMessageBox box;
        if(query.isActive()){
            box.setIcon(QMessageBox::Information);
            box.setWindowTitle("课程管理");
            box.setText("新增成功");
            box.exec();
            this->close();
            emit update();
        }
        else {
            box.setIcon(QMessageBox::Critical);
            box.setWindowTitle("课程管理");
            box.setText("新增失败,请检查数据正确性!");
            box.exec();
            qDebug()<<query.lastError().text();
        }
    }
        break;
    case CHECK:
    {
        this->close();
    }
    }
}

void ModifyCourse::on_Btn_Cancel_clicked()
{
    this->close();
}

16.reset.cpp

#include "reset.h"
#include "ui_reset.h"

Reset::Reset(QString name, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Reset)
{
    ui->setupUi(this);

    setWindowFlags(Qt::CustomizeWindowHint);    // 隐藏标题栏
    setFixedSize(300, 180);

    this->name = name;
}

Reset::~Reset()
{
    delete ui;
}

void Reset::on_Btn_No_clicked()
{
    this->close();
}


void Reset::on_Btn_Yes_clicked()
{
    if (ui->Name->text() == name) {
        this->close();
        emit reset();
    }
    else {
        QMessageBox box;
        box.setIcon(QMessageBox::Critical);
        box.setWindowIcon(QIcon(":/res/logo.jpg"));
        box.setWindowTitle("警告");
        box.setText("验证失败");
        box.exec();
    }

}

17.statics.cpp

#include "statics.h"
#include "ui_statics.h"

Statics::Statics(QSqlDatabase db, QString Course, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Statics)
{
    ui->setupUi(this);

    setWindowFlags(Qt::CustomizeWindowHint);    // 隐藏标题栏
    setFixedSize(360, 300);
    database = db;
    course = Course;

    avg();  //求平均分
    count();  //求不及格人数
    per(); //求挂科率


}

Statics::~Statics()
{
    delete ui;
}

void Statics::on_Btn_yes_clicked()
{
    this->close();
}

void Statics::avg(){
    QSqlQuery query(database);
    query.exec("select avg(score) "
               "from sc "
               "where score > 0 and cno = '" + course + "'");
    if(query.next()){
        ui->avg->setText(QString::number(query.value(0).toDouble(), 'f', 1));
    }
    else ui->avg->setText("/");
}

void Statics::count(){
    QSqlQuery query(database);
    query.exec("select count(sno) "
               "from sc "
               "where score > 0 and score < 60 and cno = '" + course + "'");
    if(query.next()){
        ui->count->setText(query.value(0).toString());
    }
    else ui->count->setText("/");
}

void Statics::per(){
    QSqlQuery query_fz(database);
    QSqlQuery query_fm(database);
    double per;
    query_fz.exec("select count(sno) "
                  "from sc "
                  "where score > 0 and score < 60 and cno = '" + course + "'");
    if(query_fz.isActive() && query_fz.next())per = query_fz.value(0).toDouble();
    else {
        ui->per->setText("/");
        qDebug()<<query_fz.lastError().text();
    }
    query_fm.exec("select count(sno) "
               "from sc "
               "where score > 0 and cno = '" + course + "'");
    if(query_fm.isActive() && query_fm.next() && query_fm.value(0).toInt() != 0)per /= query_fm.value(0).toDouble();
    else {
        per = -1;
        if(!query_fm.isActive())
            qDebug()<<query_fm.lastError().text();
    }
    ui->per->setText(per == -1 ? "/" : QString::number(per, 'f', 1) + "%");
}

18.studentwindow.cpp

#include "studentwindow.h"
#include "ui_studentwindow.h"

StudentWindow::StudentWindow(QSqlDatabase db, QString username, QWidget *parent) : QMainWindow(parent), ui(new Ui::StudentWindow) {
    ui->setupUi(this);

    setWindowIcon(QIcon(":/res/logo.jpg"));                                             // 设置窗口样式
    setWindowTitle("江苏科技大学学生管理系统");
    this->setStyleSheet("background-color: rgb(255, 255, 255);");
    resize(1170, 672);

    QGraphicsDropShadowEffect *shadow_effect = new QGraphicsDropShadowEffect(this);     // 侧边栏阴影效果
    shadow_effect->setOffset(0, 0);
    shadow_effect->setColor(QColor(38, 78, 119, 127));
    shadow_effect->setBlurRadius(22);
    ui->Sidebar->setGraphicsEffect(shadow_effect);

    ui->CourseTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);    // 表格随窗口调整大小
    ui->ScoreTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);

    ui->Time->view()->window()->setWindowFlags(Qt::Popup|Qt::FramelessWindowHint|Qt::NoDropShadowWindowHint);
    ui->Time->view()->window()->setAttribute(Qt::WA_TranslucentBackground);
    ui->comboBox->view()->window()->setWindowFlags(Qt::Popup|Qt::FramelessWindowHint|Qt::NoDropShadowWindowHint);
    ui->comboBox->view()->window()->setAttribute(Qt::WA_TranslucentBackground);         // 下拉框圆角

    QSqlQuery t = db.exec("select grade from student where sno = '" + username + "'");    //设定学期
    t.next();
    currentTime = t.value(0).toString();

    for(int i = 8; i >= 0; i--){                                   //设定下拉框为不高于自己的学期
        if(ui->Time->itemText(i) != currentTime){
            ui->Time->removeItem(i);
            ui->comboBox->removeItem(i);
        }
        else break;
    }

    ui->Body->setCurrentIndex(0);                                                       // 初始化第一个窗口和成员变量
    this->db = db;
    this->username = username;

    init_My();                                                                          // 调用初始化函数
    init_Course();
    init_Score();
    init_SelectCourse();

}

StudentWindow::~StudentWindow() {
    delete ui;
}

// ======================================================================================= 初始化基本信息界面
void StudentWindow::init_My() {
    QSqlQuery query(db);
    query.exec("select sno, sname, sex, grade, major, classno "
               "from student "
               "where sno ='" + username + "'");

    query.next();
    ui->Sno->setText(query.value(0).toString());
    ui->Sname->setText(query.value(1).toString());
    ui->Sex->setText(query.value(2).toString());
    ui->Age->setText(query.value(3).toString());
    ui->Major->setText(query.value(4).toString());
    ui->Classno->setText(query.value(5).toString());

}

// ======================================================================================= 初始化课程查询界面
void StudentWindow::init_Course() {
    QSqlQuery query(db);
    query.exec("select sc.cno, cname, tname, grade, period, credit, assess, property "
               "from course, sc, teacher "
               "where sc.cno = course.cno and course.tno = teacher.tno and sno = '" + username + "'");

    QStringList headerlist;
    headerlist<<"课程号"<<"课程名"<<"任课老师"<<"开课学期"<<"学时"<<"学分"<<"考核方式"<<"课程属性";
    ui->CourseTable->setColumnCount(headerlist.size());
    for (int i = 0; i < ui->CourseTable->columnCount(); ++i){
        ui->CourseTable->setHorizontalHeaderItem(i, new QTableWidgetItem(headerlist[i]));
    }
    ui->CourseTable->horizontalHeader()->setStyleSheet("QHeaderView::section{font: Bold 13pt '微软雅黑'}");
    ui->CourseTable->horizontalHeader()->setVisible(true);

    int row = 0;
    while (query.next()) {
        ui->CourseTable->insertRow(row);
        for (int i = 0; i < ui->CourseTable->columnCount(); ++i) {
            ui->CourseTable->setItem(row, i, new QTableWidgetItem(query.value(i).toString()));
            ui->CourseTable->item(row, i)->setTextAlignment(Qt::AlignCenter);
        }
    }
}

// ======================================================================================= 初始化成绩查询界面
void StudentWindow::init_Score() {
    QSqlQuery query(db);
    query.exec("select sc.cno, cname, grade, score, period, credit, assess, property "
               "from course, sc "
               "where sc.cno = course.cno and sno = '" + username + "'");

    QStringList headerlist;
    headerlist<<"课程号"<<"课程名"<<"开课年级"<<"成绩"<<"学时"<<"学分"<<"考核方式"<<"课程属性";
    ui->ScoreTable->setColumnCount(headerlist.size());
    for (int i = 0; i < ui->ScoreTable->columnCount(); ++i){
        ui->ScoreTable->setHorizontalHeaderItem(i, new QTableWidgetItem(headerlist[i]));
    }
    ui->ScoreTable->horizontalHeader()->setStyleSheet("QHeaderView::section{font: Bold 13pt '微软雅黑'}");
    ui->ScoreTable->horizontalHeader()->setVisible(true);

    int row = 0;
    double GPA = 0, credit = 0;
    while (query.next()) {
        ui->ScoreTable->insertRow(row);
        for (int i = 0; i < ui->ScoreTable->columnCount(); ++i) {
            ui->ScoreTable->setItem(row, i, new QTableWidgetItem(query.value(i).toString()));
            ui->ScoreTable->item(row, i)->setTextAlignment(Qt::AlignCenter);
        }

        GPA += std::max(query.value(3).toDouble() - 50, 0.0) / 10 * query.value(5).toDouble();
        credit += query.value(5).toDouble();
    }

    if (credit)
        ui->GPA->setText(QString::number(GPA / credit, 'f', 3));
    else ui->GPA->setText("0.000");
}

// ======================================================================================= 搜索按钮
void StudentWindow::on_Btn_Search_clicked() {
    QString time = ui->Time->currentText();
    QString cname = ui->Cname->text();

    if (time == " 全部") time = "大";
    if (cname == "") cname = "%";

    QSqlQuery query(db);
    query.exec("select sc.cno, cname, tname, grade, period, credit, assess, property "
               "from course, sc, teacher "
               "where sc.cno = course.cno and course.tno = teacher.tno and sno = '" + username + "' "
                     "and grade like '%" + time + "%' and cname like '%" + cname + "%'");

    ui->CourseTable->setSortingEnabled (false);                                        // 解决关于排序后查询错乱的问题
    ui->CourseTable->clearContents();
    ui->CourseTable->setRowCount(0);

    int row = 0;
    while (query.next()) {
        ui->CourseTable->insertRow(row);
        for (int i = 0; i < ui->CourseTable->columnCount(); ++i) {
            ui->CourseTable->setItem(row, i, new QTableWidgetItem(query.value(i).toString()));
            ui->CourseTable->item(row, i)->setTextAlignment(Qt::AlignCenter);
        }
    }

    ui->CourseTable->setSortingEnabled (true);
}

// ======================================================================================= 选择学期下拉框
void StudentWindow::on_comboBox_currentTextChanged(const QString &arg1) {
    qDebug() << arg1;

    QString time = arg1, property = "%";
    if (time == " 全部") time = "%";
    if (ui->Compulsory->isChecked()) property = "必修";

    QSqlQuery query(db);
    query.exec("select sc.cno, cname, grade, score, period, credit, assess, property "
               "from course, sc "
               "where sc.cno = course.cno and sno = '" + username + "' and grade like '" + time + "' and property like '" + property + "'");

    ui->ScoreTable->clearContents();
    ui->ScoreTable->setRowCount(0);
    int row = 0;
    double GPA = 0, credit = 0;
    while (query.next()) {
        ui->ScoreTable->insertRow(row);
        for (int i = 0; i < ui->ScoreTable->columnCount(); ++i) {
            ui->ScoreTable->setItem(row, i, new QTableWidgetItem(query.value(i).toString()));
            ui->ScoreTable->item(row, i)->setTextAlignment(Qt::AlignCenter);
        }

        GPA += std::max(query.value(3).toDouble() - 50, 0.0) / 10 * query.value(5).toDouble();
        credit += query.value(5).toDouble();
    }

    if (credit)
        ui->GPA->setText(QString::number(GPA / credit, 'f', 3));
    else ui->GPA->setText("0.000");
}

// ======================================================================================= 只看必修
void StudentWindow::on_Compulsory_stateChanged(int arg1) {
    qDebug() << arg1;

    QString time = ui->comboBox->currentText(), property = arg1 ? "必修" : "%";
    if (time == " 全部") time = "%";

    QSqlQuery query(db);
    query.exec("select sc.cno, cname, grade, score, period, credit, assess, property "
               "from course, sc "
               "where sc.cno = course.cno and sno = '" + username + "' and grade like '" + time + "' and property like '" + property + "'");


    ui->ScoreTable->clearContents();
    ui->ScoreTable->setRowCount(0);
    int row = 0;
    double GPA = 0, credit = 0;
    while (query.next()) {
        ui->ScoreTable->insertRow(row);
        for (int i = 0; i < ui->ScoreTable->columnCount(); ++i) {
            ui->ScoreTable->setItem(row, i, new QTableWidgetItem(query.value(i).toString()));
            ui->ScoreTable->item(row, i)->setTextAlignment(Qt::AlignCenter);
        }

        GPA += std::max(query.value(3).toDouble() - 50, 0.0) / 10 * query.value(5).toDouble();
        credit += query.value(5).toDouble();
    }

    if (credit)
        ui->GPA->setText(QString::number(GPA / credit, 'f', 3));
    else ui->GPA->setText("0.000");
}


void StudentWindow::on_Btn_Exit_clicked() {
    this->close();
    emit back();
}


void StudentWindow::on_Btn_My_clicked() {
    if (ui->Body->currentIndex() != 0)
        ui->Body->setCurrentIndex(0);
}


void StudentWindow::on_Btn_Course_clicked() {
    if (ui->Body->currentIndex() != 1)
        ui->Body->setCurrentIndex(1);
}


void StudentWindow::on_Btn_Score_clicked() {
    if (ui->Body->currentIndex() != 2)
        ui->Body->setCurrentIndex(2);
}


void StudentWindow::on_Btn_Fee_clicked() {
    if (ui->Body->currentIndex() != 3)
        ui->Body->setCurrentIndex(3);
}


//    QAction *searchAction = new QAction(ui->Search);
//    searchAction->setIcon(QIcon(":/res/search.png"));
//    ui->Search->addAction(searchAction, QLineEdit::LeadingPosition);

// ======================================================================================= 初始化选课中心界面
void StudentWindow::init_SelectCourse(){


    QStringList headerlist;
    headerlist<<"课程号"<<"课程名"<<"任课老师"<<"开课学期"<<"学时"<<"学分"<<"考核方式"<<"课程属性";
    ui->ScoreTable_3->setColumnCount(headerlist.size());
    ui->ScoreTable_4->setColumnCount(headerlist.size());
    for (int i = 0; i < ui->ScoreTable_3->columnCount(); ++i){
        ui->ScoreTable_3->setHorizontalHeaderItem(i, new QTableWidgetItem(headerlist[i]));
        ui->ScoreTable_4->setHorizontalHeaderItem(i, new QTableWidgetItem(headerlist[i]));
    }
    ui->ScoreTable_3->horizontalHeader()->setStyleSheet("QHeaderView::section{font: Bold 13pt '微软雅黑'}");
    ui->ScoreTable_4->horizontalHeader()->setStyleSheet("QHeaderView::section{font: Bold 13pt '微软雅黑'}");
    ui->ScoreTable_3->horizontalHeader()->setVisible(true);
    ui->ScoreTable_4->horizontalHeader()->setVisible(true);
    ui->ScoreTable_3->setColumnCount(headerlist.size());
    ui->ScoreTable_4->setColumnCount(headerlist.size());

    SelectCourseRefresh();
    SelectedCourseRefresh();
}

// ======================================================================================= 查找
void StudentWindow::on_Btn_SearchCourse_clicked()
{
    QString cur_course = ui->Cname_2->text();
    if(cur_course == ""){
        SelectCourseRefresh();
        return ;
    }

    QSqlQuery query(db);
    bool k = query.exec("select cno, cname, tname, grade, period, credit, assess, property "
                          "from course, teacher "
                          "where course.tno = teacher.tno and "
                          "grade = '" + currentTime + "' and "
                          "cno like '%" + cur_course + "%' and "
                          "cno <>all( select cno "
                                      "from sc "
                                      "where sno = '" + username + "' )");
    if(k){
        ui->ScoreTable_3->setSortingEnabled (false);                                        // 解决关于排序后查询错乱的问题
        ui->ScoreTable_3->clearContents();
        ui->ScoreTable_3->setRowCount(0);


        int row = 0;
        while(query.next()){
            if(ui->ScoreTable_3->rowCount() <= row)ui->ScoreTable_3->insertRow(row);
            for(int i = 0; i < ui->ScoreTable_3->columnCount(); i++){
                ui->ScoreTable_3->setItem(row, i, new QTableWidgetItem(query.value(i).toString()));
                ui->ScoreTable_3->item(row, i)->setTextAlignment(Qt::AlignCenter);
            }
            row++;
        }

        ui->ScoreTable_3->setSortingEnabled (true);
    }
}

// ======================================================================================= 选课
void StudentWindow::on_Btn_SelectCourse_clicked()
{
    QString cur_course = ui->Cname_2->text();
    if(cur_course == ""){
        SelectCourseRefresh();
        return ;
    }
    QSqlQuery query(db);
    bool k = query.exec("select cno, cname, tname, grade, period, credit, assess, property "
                          "from course, teacher "
                          "where course.tno = teacher.tno and "
                          "grade = '" + currentTime + "' and "
                          "cno = '" + cur_course + "'");
    if(k){
        query.next();
        QMessageBox box;
        box.setIcon(QMessageBox::Question);
        box.setWindowTitle("选课中心");
        box.setWindowIcon(QIcon(":/res/logo.jpg"));
        box.setText("确定选择课程:" + cur_course + " 吗?");
        box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
        if(box.exec() == QMessageBox::Yes){
            QSqlQuery t = db.exec("insert into "
                                  "sc (sno, cno, score)"
                                  "values ( "
                                  "'" + username + "', "
                                  "'" + query.value(0).toString() + "', "
                                  " 0 )"   //默认分数0
                                  );
            QMessageBox box_2;
            if(t.isActive()){
                box_2.setIcon(QMessageBox::Information);
                box_2.setWindowIcon(QIcon(":/res/logo.jpg"));
                box_2.setWindowTitle("选课中心");
                box_2.setText("选课成功");
                box_2.exec();
                SelectCourseRefresh();
                SelectedCourseRefresh();
            }
            else {
                box_2.setIcon(QMessageBox::Critical);
                box_2.setWindowIcon(QIcon(":/res/logo.jpg"));
                box_2.setWindowTitle("选课中心");
                box_2.setText("选课失败");
                box_2.exec();
                qDebug()<<t.lastError().text();
            }
        }
    }

}

void StudentWindow::on_Btn_deleteCourse_clicked()
{
    int currow;
    if(ui->ScoreTable_4->currentRow() < 0)
        return;
    else currow = ui->ScoreTable_4->currentRow();
    auto current_item = ui->ScoreTable_4->item(currow, 0);
    if(current_item == nullptr)return ;
    QString cur_course = current_item->text();
    QMessageBox box;
    box.setIcon(QMessageBox::Question);
    box.setWindowTitle("选课中心");
    box.setWindowIcon(QIcon(":/res/logo.jpg"));
    box.setText("确定删除课程:" + cur_course + " 吗?");
    box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    if(box.exec() == QMessageBox::Yes){
        QSqlQuery query(db);
        query.exec("delete from sc "
                   "where sno = '" + username + "' and "
                         "cno = ( select cno "
                                    "from course "
                                    "where grade = '" + currentTime + "' and "
                                           "cno = '" + cur_course + "' )");
        qDebug()<<currentTime<<cur_course;
        QMessageBox box_2;
        if(query.isActive()){
            if(query.numRowsAffected() == 0){
                box_2.setIcon(QMessageBox::Warning);
                box_2.setWindowIcon(QIcon(":/res/logo.jpg"));
                box_2.setWindowTitle("选课中心");
                box_2.setText("无法删除已选课程");
                box_2.exec();
                SelectCourseRefresh();
                SelectedCourseRefresh();
            }
            else {
                box_2.setIcon(QMessageBox::Information);
                box_2.setWindowIcon(QIcon(":/res/logo.jpg"));
                box_2.setWindowTitle("选课中心");
                box_2.setText("删除成功");
                box_2.exec();
                SelectCourseRefresh();
                SelectedCourseRefresh();
            }
        }
        else {
            box_2.setIcon(QMessageBox::Critical);
            box_2.setWindowIcon(QIcon(":/res/logo.jpg"));
            box_2.setWindowTitle("选课中心");
            box_2.setText("删除失败");
            box_2.exec();
            qDebug()<<query.lastError().text();
        }
    }

}

// ======================================================================================= 刷新已选表
void StudentWindow::SelectedCourseRefresh(){
    QSqlQuery query(db);
    query.exec("select course.cno, cname, tname, grade, period, credit, assess, property "
               "from course, teacher, sc "
               "where sc.cno = course.cno and "
                     "course.grade = '" + currentTime + "' and "
                     "sc.sno = '" + username + "' and "
                     "course.tno = teacher.tno"
                        );
    qDebug()<<query.lastError().text();
    ui->ScoreTable_4->setSortingEnabled (false);                                        // 解决关于排序后查询错乱的问题
    ui->ScoreTable_4->clearContents();
    ui->ScoreTable_4->setRowCount(0);

    int row = 0;
    while(query.next()){
        if(ui->ScoreTable_4->rowCount() <= row)ui->ScoreTable_4->insertRow(row);
        for(int i = 0; i < ui->ScoreTable_4->columnCount(); i++){
            ui->ScoreTable_4->setItem(row, i, new QTableWidgetItem(query.value(i).toString()));
            ui->ScoreTable_4->item(row, i)->setTextAlignment(Qt::AlignCenter);
        }
        row++;
    }

    ui->ScoreTable_4->setSortingEnabled (true);
}

// ======================================================================================= 刷新选课表
void StudentWindow::SelectCourseRefresh(){
    QSqlQuery query(db);
    query.exec("select cno, cname, tname, grade, period, credit, assess, property "
               "from course, teacher "
               "where course.tno = teacher.tno and "
                           "grade = '" + currentTime + "' and "
                           "cno <>all( select cno "
                                       "from sc "
                                       "where sno = '" + username + "' )");
    ui->ScoreTable_3->setSortingEnabled (false);                                        // 解决关于排序后查询错乱的问题
    ui->ScoreTable_3->clearContents();
    ui->ScoreTable_3->setRowCount(0);

    int row = 0;
    while(query.next()){
        if(ui->ScoreTable_3->rowCount() <= row)ui->ScoreTable_3->insertRow(row);
        for(int i = 0; i < ui->ScoreTable_3->columnCount(); i++){
            ui->ScoreTable_3->setItem(row, i, new QTableWidgetItem(query.value(i).toString()));
            ui->ScoreTable_3->item(row, i)->setTextAlignment(Qt::AlignCenter);
        }
        row++;
    }

    ui->ScoreTable_3->setSortingEnabled (true);
}

void StudentWindow::on_ScoreTable_3_cellClicked(int row, int column)
{
    column = 0;
    if(ui->ScoreTable_3->item(row, column) != nullptr)
        ui->Cname_2->setText(ui->ScoreTable_3->item(row, column)->text());
}

void StudentWindow::on_Btn_Search_7_clicked()
{
    changePassword * password = new changePassword(db, username, STUDENT);
    password->setWindowModality(Qt::ApplicationModal);
    password->show();
}

void StudentWindow::on_Time_currentTextChanged(const QString &arg1)
{
    ui->Cname->setText("");
    on_Btn_Search_clicked();
}

19.teacherwindow.cpp

#include "teacherwindow.h"
#include "ui_teacherwindow.h"

TeacherWindow::TeacherWindow(QSqlDatabase db, QString username, QWidget *parent) : QMainWindow(parent), ui(new Ui::TeacherWindow) {
    ui->setupUi(this);

    setWindowIcon(QIcon(":/res/logo.jpg"));                                             // 设置窗口样式
    setWindowTitle("江苏科技大学学生管理系统");
    this->setStyleSheet("background-color: rgb(255, 255, 255);");
    resize(1170, 672);

    QGraphicsDropShadowEffect *shadow_effect = new QGraphicsDropShadowEffect(this);     // 侧边栏阴影效果
    shadow_effect->setOffset(0, 0);
    shadow_effect->setColor(QColor(38, 78, 119, 127));
    shadow_effect->setBlurRadius(22);
    ui->Sidebar->setGraphicsEffect(shadow_effect);


    ui->Body->setCurrentIndex(0);                                                       // 初始化第一个窗口和成员变量
    this->db = db;
    this->username = username;

    //默认普通模式,隐藏管理员相关权限
    ui->Btn_Student->hide();
    ui->Btn_Dorm->hide();

    ui->StudentTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);   // 表格随窗口调整大小
    ui->ScoreTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->CourseTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);

//    ui->Classno->view()->window()->setWindowFlags(Qt::Popup|Qt::FramelessWindowHint|Qt::NoDropShadowWindowHint);
//    ui->Classno->view()->window()->setAttribute(Qt::WA_TranslucentBackground);          // 下拉框圆角
    ui->Classno_2->view()->window()->setWindowFlags(Qt::Popup|Qt::FramelessWindowHint|Qt::NoDropShadowWindowHint);
    ui->Classno_2->view()->window()->setAttribute(Qt::WA_TranslucentBackground);
    ui->Cno->view()->window()->setWindowFlags(Qt::Popup|Qt::FramelessWindowHint|Qt::NoDropShadowWindowHint);
    ui->Cno->view()->window()->setAttribute(Qt::WA_TranslucentBackground);
//    ui->Bednum->view()->window()->setWindowFlags(Qt::Popup|Qt::FramelessWindowHint|Qt::NoDropShadowWindowHint);
//    ui->Bednum->view()->window()->setAttribute(Qt::WA_TranslucentBackground);
//    ui->Bednum_2->view()->window()->setWindowFlags(Qt::Popup|Qt::FramelessWindowHint|Qt::NoDropShadowWindowHint);
//    ui->Bednum_2->view()->window()->setAttribute(Qt::WA_TranslucentBackground);
//    ui->Dorm->view()->window()->setWindowFlags(Qt::Popup|Qt::FramelessWindowHint|Qt::NoDropShadowWindowHint);
//    ui->Dorm->view()->window()->setAttribute(Qt::WA_TranslucentBackground);
//    ui->Dorm_2->view()->window()->setWindowFlags(Qt::Popup|Qt::FramelessWindowHint|Qt::NoDropShadowWindowHint);
//    ui->Dorm_2->view()->window()->setAttribute(Qt::WA_TranslucentBackground);

    QSqlQuery query(db);                                                                // 初始化下拉框选项
    query.exec("select classno from class where tno = '" + username + "'");
    while (query.next()) {
//        ui->Classno->addItem(query.value(0).toString());
        ui->Classno_2->addItem(query.value(0).toString());
    }

    query.exec("select cno from course where tno = '" + username + "'");
    while (query.next()) {
        ui->Cno->addItem(query.value(0).toString());
    }

    init_My();                                                                          // 调用初始化函数
    init_Score();
    QSqlQuery query_manager(db);
    query_manager.exec("select admin "
                       "from teacher "
                       "where tno = '" + username + "'");
    if(query_manager.next() && query_manager.value(0).toInt() == 1){
        ui->Btn_Student->show();
        ui->Btn_Dorm->show();
        init_Student();
        init_Course();
    }
    else {
        qDebug()<<query_manager.lastError().text();
    }

}

TeacherWindow::~TeacherWindow() {
    delete ui;
}

// ======================================================================================= 初始化基本信息界面
void TeacherWindow::init_My() {
    QSqlQuery query(db);
    query.exec("select tno, tname from teacher where tno = '" + username + "'");

    query.next();
    ui->Tno->setText(query.value(0).toString());
    ui->Tname->setText(query.value(1).toString());
    ui->Class->clear();
    ui->Cname->clear();
    query.exec("select major, classno from class where tno = '" + username + "'");
    if (query.next()) ui->Class->insertPlainText(query.value(0).toString() + "(" + query.value(1).toString() + ")");
    while (query.next()) {
        ui->Class->insertPlainText("、" + query.value(0).toString() + "(" + query.value(1).toString() + ")");
    }

    query.exec("select cname, cno from course where tno = '" + username + "'");
    if (query.next()) ui->Cname->insertPlainText(query.value(0).toString() + "(" + query.value(1).toString() + ")");
    while (query.next()) {
        ui->Cname->insertPlainText("、" + query.value(0).toString() + "(" + query.value(1).toString() + ")");
    }
}

// ======================================================================================= 初始化师生管理界面
void TeacherWindow::init_Student() {
    ui->student_radiobutton->setChecked(true);
    ui->Search->setPlaceholderText("请输入学号");
    ui->Search->clear();
    StudentManageRefresh();
}

// ======================================================================================= 初始化成绩录入界面
void TeacherWindow::init_Score() {

    QStringList headerlist;
    headerlist<<"学号"<<"姓名"<<"专业"<<"课程名"<<"成绩";
    ui->ScoreTable->setColumnCount(headerlist.size());
    for (int i = 0; i < ui->ScoreTable->columnCount(); ++i){
        ui->ScoreTable->setHorizontalHeaderItem(i, new QTableWidgetItem(headerlist[i]));

    }
    ui->ScoreTable->horizontalHeader()->setStyleSheet("QHeaderView::section{font: Bold 13pt '微软雅黑'}");
    ui->ScoreTable->horizontalHeader()->setVisible(true);

//    QString cno = ui->Cno->currentText();

//    QSqlQuery query(db);
//    query.exec("select distinct student.sno, sname, major, cname, score, course.grade "
//               "from student, sc, course "
//               "where student.sno = SC.sno and course.cno = SC.cno and SC.cno = '" + cno + "'");
//    int row = 0;
//    ui->ScoreTable->clearContents();
//    ui->ScoreTable->setRowCount(0);
//    while (query.next()) {
//        ui->ScoreTable->insertRow(row);
//        for (int i = 0; i < ui->ScoreTable->columnCount(); ++i) {
//            ui->ScoreTable->setItem(row, i, new QTableWidgetItem(query.value(i).toString()));
//            ui->ScoreTable->item(row, i)->setTextAlignment(Qt::AlignCenter);
//            if (i != 4) ui->ScoreTable->item(row, i)->setFlags(Qt::ItemIsEnabled);        // 设置成绩列为可修改
//            if(query.value(5).toString() != currentTime && ui->ScoreTable->item(row, 4))                            //本学期的课程才可而修改
//                ui->ScoreTable->item(row, 4)->setFlags(Qt::ItemIsEnabled);
//        }
//        row++;
//    }

}

// ======================================================================================= 初始化宿舍管理界面
//void TeacherWindow::init_Dorm() {
//    QSqlQuery query(db);
//    query.exec("select distinct dormitory "
//               "from student, class "
//               "where student.classno = class.classno and tno = '" + username + "'");

//    QStringList headerlist;
//    headerlist<<"宿舍号"<<"1号床"<<"2号床"<<"3号床"<<"4号床";
//    ui->DormTable->setColumnCount(headerlist.size());
//    for (int i = 0; i < ui->DormTable->columnCount(); ++i){
//        ui->DormTable->setHorizontalHeaderItem(i, new QTableWidgetItem(headerlist[i]));

//    }
//    ui->DormTable->horizontalHeader()->setStyleSheet("QHeaderView::section{font: Bold 13pt '微软雅黑'}");
//    ui->DormTable->horizontalHeader()->setVisible(true);

//    int row = 0;
//    while (query.next()) {
//        ui->DormTable->insertRow(row);
//        ui->DormTable->setItem(row, 0, new QTableWidgetItem(query.value(0).toString()));
//        ui->DormTable->item(row, 0)->setTextAlignment(Qt::AlignCenter);
//        ui->Dorm->addItem(query.value(0).toString());
//        ui->Dorm_2->addItem(query.value(0).toString());

//        QSqlQuery q(db);
//        q.exec("select sname, bednum from student where dormitory = '" + query.value(0).toString() +  "'");

//        while (q.next()) {
//            if (0 < q.value(1).toInt() && q.value(1).toInt() < 5) {
//                ui->DormTable->setItem(row, q.value(1).toInt(), new QTableWidgetItem(q.value(0).toString()));
//                ui->DormTable->item(row, q.value(1).toInt())->setTextAlignment(Qt::AlignCenter);
//            }
//        }
//        row++;
//    }
//}

// ======================================================================================= 初始化课程管理界面
void TeacherWindow::init_Course() {

    ui->Search_2->setPlaceholderText("请输入课程号");
    ui->Search_2->clear();
    CourseManageRefresh();
}

// ======================================================================================= 计算绩点
QString TeacherWindow::calculate_GPA(QString Sno) {
    QSqlQuery query(db);
    query.exec("select score, credit "
               "from course, sc "
               "where sc.cno = course.cno and sno = '" + Sno + "'");

    double GPA = 0, credit = 0;
    while (query.next()) {
        GPA += std::max(query.value(0).toDouble() - 50, 0.0) / 10 * query.value(1).toDouble();
        credit += query.value(1).toDouble();
    }

    if (credit)
        return QString::number(GPA / credit, 'f', 3);

    return "0.000";
}

// ======================================================================================= 修改按钮
void TeacherWindow::on_Btn_Modify_clicked() {
    QSqlQuery query(db);
    if(ui->Search->text() == "")return ;
    if(ui->student_radiobutton->isChecked()){
        query.exec("select sno "
                   "from student "
                   "where sno like '%" + ui->Search->text() + "%'");
        if(query.next()){
            ModifyStudent *modify = new ModifyStudent(db, query.value(0).toString(), MODIFY);
            modify->setWindowModality(Qt::ApplicationModal);
            modify->show();

            connect(modify, &ModifyStudent::update, this, [=]() {                           // 更新表格
                StudentManageRefresh();
            });

        }
        else{
            QMessageBox box;
            box.setIcon(QMessageBox::Warning);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("警告");
            box.setText("未找到该学生");
            box.exec();
        }
    }
    else {
        query.exec("select tno "
                   "from teacher "
                   "where tno like '%" + ui->Search->text() + "%'");
        if(query.next()){
            ModifyTeacher *modify = new ModifyTeacher(db, query.value(0).toString(), MODIFY);
            modify->setWindowModality(Qt::ApplicationModal);
            modify->show();

            connect(modify, &ModifyTeacher::update, this, [=]() {                           // 更新表格
                TeacherManageRefresh();
            });
        }
        else{
            QMessageBox box;
            box.setIcon(QMessageBox::Warning);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("警告");
            box.setText("未找到该教师");
            box.exec();
        }
    }

}

// ======================================================================================= 成绩录入选择班级下拉框
void TeacherWindow::on_Classno_2_currentTextChanged(const QString &arg1) {
    qDebug() << arg1;

    QString classno = arg1 == "全部" ? "%" : arg1;
    QString cno = ui->Cno->currentText() == "全部" ? "%" : ui->Cno->currentText();
    if(cno == "%" && classno == "%"){
        ui->ScoreTable->clearContents();
        ui->ScoreTable->setRowCount(0);
        return ;
    }
    QSqlQuery query(db);
    query.exec("select distinct student.sno, sname, major, cname, score, course.grade, course.cno, student.grade "
               "from student, sc, class, course "
               "where student.sno = sc.sno and "
               "course.cno = sc.cno and "
               "student.classno like '" + classno + "' and "
               "course.cno like '" +cno + "'");
    qDebug()<<query.lastError().text();
    ui->ScoreTable->setSortingEnabled (false);                                        // 解决关于排序后查询错乱的问题
    ui->ScoreTable->clearContents();
    ui->ScoreTable->setRowCount(0);
    int row = 0;
    while (query.next()) {
        ui->ScoreTable->insertRow(row);
        for (int i = 0; i < ui->ScoreTable->columnCount(); ++i) {
            ui->ScoreTable->setItem(row, i, new QTableWidgetItem(query.value(i).toString()));
            ui->ScoreTable->item(row, i)->setTextAlignment(Qt::AlignCenter);
            if (i != 4) ui->ScoreTable->item(row, i)->setFlags(Qt::ItemIsEnabled);        // 设置成绩列为可修改
            if(query.value(5).toString() != query.value(7).toString() && ui->ScoreTable->item(row, 4))  //本学期的课程才可而修改
                ui->ScoreTable->item(row, 4)->setFlags(Qt::ItemIsEnabled);
            if(cno == "%"){                                                                       //只有自己的课可以修改
                QString curcno = query.value(6).toString();
                QSqlQuery t = db.exec("select cno "
                                 "from course "
                                 "where tno = '" + username + "' and cno = '" + curcno + "'");
                if(!t.next()&& ui->ScoreTable->item(row, 4))
                    ui->ScoreTable->item(row, 4)->setFlags(Qt::ItemIsEnabled);
            }
        }
        row++;
    }
    ui->ScoreTable->setSortingEnabled (true);
}

// ======================================================================================= 成绩录入选择课程下拉框
void TeacherWindow::on_Cno_currentTextChanged(const QString &arg1)
{
    qDebug() << arg1;

    QString cno = arg1 == "全部" ? "%" : arg1;
    QString classno = ui->Classno_2->currentText() == "全部" ? "%" : ui->Classno_2->currentText();
    if(cno == "%" && classno == "%"){
        ui->ScoreTable->clearContents();
        ui->ScoreTable->setRowCount(0);
        return ;
    }
    QSqlQuery query(db);
    query.exec("select distinct student.sno, sname, major, cname, score, course.grade, course.cno, student.grade "
               "from student, sc, class, course "
               "where student.sno = sc.sno and "
               "course.cno = sc.cno and "
               "student.classno like '" + classno + "' and "
               "course.cno like '" + cno + "'");

    ui->ScoreTable->setSortingEnabled (false);                                        // 解决关于排序后查询错乱的问题
    int row = 0;
    ui->ScoreTable->clearContents();
    ui->ScoreTable->setRowCount(0);
    while (query.next()) {
        ui->ScoreTable->insertRow(row);
        for (int i = 0; i < ui->ScoreTable->columnCount(); ++i) {
            ui->ScoreTable->setItem(row, i, new QTableWidgetItem(query.value(i).toString()));
            ui->ScoreTable->item(row, i)->setTextAlignment(Qt::AlignCenter);
            if (i != 4) ui->ScoreTable->item(row, i)->setFlags(Qt::ItemIsEnabled);        // 设置成绩列为可修改
            if(query.value(5).toString() != query.value(7).toString() && ui->ScoreTable->item(row, 4)){ //只有本学期的课才能修改
                ui->ScoreTable->item(row, 4)->setFlags(Qt::ItemIsEnabled);
            }
            if(cno == "%"){                                                                       //只有自己的课可以修改
                QString curcno = query.value(6).toString();
                qDebug()<<"##"<<curcno;
                QSqlQuery t = db.exec("select cno "
                                 "from course "
                                 "where tno = '" + username + "' and cno = '" + curcno + "'");
                if(!t.next()&& ui->ScoreTable->item(row, 4))
                    ui->ScoreTable->item(row, 4)->setFlags(Qt::ItemIsEnabled);
            }

        }
        row++;
    }
    ui->StudentTable->setSortingEnabled (true);

}

// ======================================================================================= 查询按钮
void TeacherWindow::on_Btn_Search_clicked() {
    QSqlQuery query(db);
    if(ui->Search->text() == ""){
        ui->student_radiobutton->isChecked()?StudentManageRefresh():TeacherManageRefresh();
        return ;
    }
    if(ui->student_radiobutton->isChecked()){
        query.exec("select sno "
                   "from student "
                   "where sno like '%" + ui->Search->text() + "%'");
        if(query.next()){
            ModifyStudent * modify = new ModifyStudent(db, query.value(0).toString(), CHECK);
            modify->setWindowModality(Qt::ApplicationModal);
            modify->show();

            connect(modify, &ModifyStudent::update, this, [=]() {                           // 更新表格
                StudentManageRefresh();
            });
        }
        else{
            QMessageBox box;
            box.setIcon(QMessageBox::Warning);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("警告");
            box.setText("未找到该学生");
            box.exec();
        }
    }
    else {
        query.exec("select tno "
                   "from teacher "
                   "where tno like '%" + ui->Search->text() + "%'");
        if(query.next()){
            ModifyTeacher * modify = new ModifyTeacher(db, query.value(0).toString(), CHECK);
            modify->setWindowModality(Qt::ApplicationModal);
            modify->show();

            connect(modify, &ModifyTeacher::update, this, [=]() {                           // 更新表格
                TeacherManageRefresh();
            });
        }
        else{
            QMessageBox box;
            box.setIcon(QMessageBox::Warning);
            box.setWindowIcon(QIcon(":/res/logo.jpg"));
            box.setWindowTitle("警告");
            box.setText("未找到该教师");
            box.exec();
        }
    }


//    ui->StudentTable->setSortingEnabled (false);                                        // 解决关于排序后查询错乱的问题
//    ui->StudentTable->clearContents();                                                  // 清空表
//    ui->StudentTable->setRowCount(0);
//    int row = 0;
//    while (query.next()) {
//        ui->StudentTable->insertRow(row);
//        for (int i = 0; i < ui->StudentTable->columnCount(); ++i) {
//                if(i == 2 && ui->teacher_radiobutton->isChecked()){
//                    ui->StudentTable->setItem(row, i, new QTableWidgetItem(query.value(i).toInt()==1?"是":"否"));
//                }
//                else
//                ui->StudentTable->setItem(row, i, new QTableWidgetItem(query.value(i).toString()));
//                ui->StudentTable->item(row, i)->setTextAlignment(Qt::AlignCenter);
//        }
//    }
//    ui->StudentTable->setSortingEnabled (true);


}

// ======================================================================================= 保存按钮
void TeacherWindow::on_Btn_Save_clicked() {
    QSqlQuery query(db);
    bool k = true;
    for (int i = 0; i < ui->ScoreTable->rowCount(); ++i) {
        query.exec("update SC set score = '" + ui->ScoreTable->item(i, 4)->text() + "' "
                        "where sno = '" + ui->ScoreTable->item(i, 0)->text() + "'");
        if(!query.isActive())k =false;
    }
    QMessageBox box;
    if(k){
        box.setIcon(QMessageBox::Information);
        box.setWindowIcon(QIcon(":/res/logo.jpg"));
        box.setWindowTitle("保存");
        box.setText("保存成功");
    }
    else {
        box.setIcon(QMessageBox::Critical);
        box.setWindowIcon(QIcon(":/res/logo.jpg"));
        box.setWindowTitle("警告");
        box.setText("保存失败");
        qDebug()<<query.lastError().text();
    }
    box.exec();
}

// ======================================================================================= 交换宿舍按钮
//void TeacherWindow::on_Btn_Exchange_clicked() {
//    QString dorm = ui->Dorm->currentText();
//    QString bednum = ui->Bednum->currentText();
//    QString dorm_2 = ui->Dorm_2->currentText();
//    QString bednum_2 = ui->Bednum_2->currentText();

//    QString sex1 = ui->Boy->isChecked() ? "无": "男";
//    QString sex2 = ui->Gril->isChecked() ? "无": "女";

//    QSqlQuery query(db);
//    query.exec("update student set dormitory = '0-A000', bednum = 0 "
//               "where dormitory = '" + dorm + "' and bednum = '" + bednum + "'");
//    query.exec("update student set dormitory = '" + dorm + "', bednum = '" + bednum + "' "
//               "where dormitory = '" + dorm_2 + "' and bednum = '" + bednum_2 + "'");
//    query.exec("update student set dormitory = '" + dorm_2 + "', bednum = '" + bednum_2 + "' "
//               "where dormitory = '0-A000' and bednum = 0");

//    query.exec("select distinct dormitory "
//               "from student, class "
//               "where student.classno = class.classno and tno = '" + username + "' and sex <> '" + sex1 + "' and sex <> '" + sex2 + "'");

//    ui->DormTable->setSortingEnabled (false);                                        // 解决关于排序后查询错乱的问题
//    ui->DormTable->clearContents();                                                  // 清空表
//    ui->DormTable->setRowCount(0);
//    int row = 0;
//    while (query.next()) {
//        ui->DormTable->insertRow(row);
//        ui->DormTable->setItem(row, 0, new QTableWidgetItem(query.value(0).toString()));
//        ui->DormTable->item(row, 0)->setTextAlignment(Qt::AlignCenter);
//        QSqlQuery q(db);
//        q.exec("select sname, bednum from student where dormitory = '" + query.value(0).toString() +  "'");

//        while (q.next()) {
//            if (0 < q.value(1).toInt() && q.value(1).toInt() < 5) {
//                ui->DormTable->setItem(row, q.value(1).toInt(), new QTableWidgetItem(q.value(0).toString()));
//                ui->DormTable->item(row, q.value(1).toInt())->setTextAlignment(Qt::AlignCenter);
//            }
//        }
//    }
//    ui->DormTable->setSortingEnabled (true);
//}

// ======================================================================================= 筛选 - 男
//void TeacherWindow::on_Boy_stateChanged(int arg1) {
//    QString sex1 = arg1 ? "无": "男";
//    QString sex2 = ui->Gril->isChecked() ? "无": "女";

//    QSqlQuery query(db);
//    query.exec("select distinct dormitory "
//               "from student, class "
//               "where student.classno = class.classno and tno = '" + username + "' and sex <> '" + sex1 + "' and sex <> '" + sex2 + "'");

//    ui->DormTable->setSortingEnabled (false);                                        // 解决关于排序后查询错乱的问题
//    ui->DormTable->clearContents();                                                  // 清空表
//    ui->DormTable->setRowCount(0);
//    int row = 0;
//    while (query.next()) {
//        ui->DormTable->insertRow(row);
//        ui->DormTable->setItem(row, 0, new QTableWidgetItem(query.value(0).toString()));
//        ui->DormTable->item(row, 0)->setTextAlignment(Qt::AlignCenter);
//        QSqlQuery q(db);
//        q.exec("select sname, bednum from student where dormitory = '" + query.value(0).toString() +  "'");

//        while (q.next()) {
//            if (0 < q.value(1).toInt() && q.value(1).toInt() < 5) {
//                ui->DormTable->setItem(row, q.value(1).toInt(), new QTableWidgetItem(q.value(0).toString()));
//                ui->DormTable->item(row, q.value(1).toInt())->setTextAlignment(Qt::AlignCenter);
//            }
//        }
//    }
//    ui->DormTable->setSortingEnabled (true);
//}

// ======================================================================================= 筛选 - 女
//void TeacherWindow::on_Gril_stateChanged(int arg1) {
//    QString sex1 = ui->Boy->isChecked() ? "无": "男";
//    QString sex2 = arg1 ? "无": "女";

//    QSqlQuery query(db);
//    query.exec("select distinct dormitory "
//               "from student, class "
//               "where student.classno = class.classno and tno = '" + username + "' and sex <> '" + sex1 + "' and sex <> '" + sex2 + "'");

//    ui->DormTable->setSortingEnabled (false);                                        // 解决关于排序后查询错乱的问题
//    ui->DormTable->clearContents();                                                  // 清空表
//    ui->DormTable->setRowCount(0);
//    int row = 0;
//    while (query.next()) {
//        ui->DormTable->insertRow(row);
//        ui->DormTable->setItem(row, 0, new QTableWidgetItem(query.value(0).toString()));
//        ui->DormTable->item(row, 0)->setTextAlignment(Qt::AlignCenter);
//        QSqlQuery q(db);
//        q.exec("select sname, bednum from student where dormitory = '" + query.value(0).toString() +  "'");

//        while (q.next()) {
//            if (0 < q.value(1).toInt() && q.value(1).toInt() < 5) {
//                ui->DormTable->setItem(row, q.value(1).toInt(), new QTableWidgetItem(q.value(0).toString()));
//                ui->DormTable->item(row, q.value(1).toInt())->setTextAlignment(Qt::AlignCenter);
//            }
//        }
//    }
//    ui->DormTable->setSortingEnabled (true);
//}


void TeacherWindow::on_Btn_My_clicked() {
    if (ui->Body->currentIndex() != 0)
        ui->Body->setCurrentIndex(0);
    init_My();
}

void TeacherWindow::on_Btn_Student_clicked() {
    if (ui->Body->currentIndex() != 1)
        ui->Body->setCurrentIndex(1);
    init_Student();
}

void TeacherWindow::on_Btn_Score_clicked() {
    if (ui->Body->currentIndex() != 2)
        ui->Body->setCurrentIndex(2);
    init_Score();
}

void TeacherWindow::on_Btn_Dorm_clicked() {
    if (ui->Body->currentIndex() != 3)
        ui->Body->setCurrentIndex(3);
    init_Course();
}

void TeacherWindow::on_Btn_Exit_clicked() {
    this->close();
    emit back();
}

// ======================================================================================= 新增按钮
void TeacherWindow::on_Btn_Add_clicked()
{
    if(ui->student_radiobutton->isChecked()){
        ModifyStudent * modify = new ModifyStudent(db, "", ADD);
        modify->setWindowModality(Qt::ApplicationModal);
        modify->show();
        connect(modify, &ModifyStudent::update, this, [=]() {                           // 更新表格
            StudentManageRefresh();
        });
    }
    else {
        ModifyTeacher * modify = new ModifyTeacher(db, "", ADD);
        modify->setWindowModality(Qt::ApplicationModal);
        modify->show();
        connect(modify, &ModifyTeacher::update, this, [=]() {                           // 更新表格
            TeacherManageRefresh();
        });
    }


//    ModifyStudent *modify = new ModifyStudent(db, "", ADD);
//    modify->setWindowModality(Qt::ApplicationModal);
//    modify->show();


}


// ======================================================================================= 统计按钮
void TeacherWindow::on_Btn_stat_clicked()
{
    QString cno = ui->Cno->currentText();
    Statics *statics = new Statics(db, cno);
    statics->setWindowModality(Qt::ApplicationModal);
    statics->show();
}

// ======================================================================================= 删除按钮
void TeacherWindow::on_Btn_Delete_clicked()
{
    QSqlQuery query(db);
    if(ui->student_radiobutton->isChecked()){
        query.exec("select sno "
                   "from student "
                   "where sno = '" + ui->Search->text() + "'");
    }
    else {
        query.exec("select tno "
                   "from teacher "
                   "where tno = '" + ui->Search->text() + "'");
    }

    QMessageBox box;
    if (query.next()) {
        box.setIcon(QMessageBox::Question);
        box.setWindowIcon(QIcon(":/res/logo.jpg"));
        box.setWindowTitle("警告");
        box.setText("确定删除该记录吗?");
        box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
        if(box.exec() == QMessageBox::Yes){
            QSqlQuery t(db);
            if(ui->student_radiobutton->isChecked()){
                t.exec("delete "
                       "from student "
                       "where sno = '" + query.value(0).toString() + "' ");
                t.exec("delete "
                       "from sc "
                       "where sno = '" + query.value(0).toString() + "'");   //同步删除sc表记录
            }
            else {
                t.exec("delete "
                       "from teacher "
                       "where tno = '" + query.value(0).toString() + "' ");
                t.exec("update class "
                       "set tno = '' where tno = '" + query.value(0).toString() + "' ");
                t.exec("update course "
                       "set tno = '' where tno = '" + query.value(0).toString() + "' ");   //同步删除class和course表记录

            }
            QMessageBox box_2;
            if(t.isActive()){
                box_2.setIcon(QMessageBox::Information);
                box_2.setWindowIcon(QIcon(":/res/logo.jpg"));
                box_2.setWindowTitle("师生管理");
                box_2.setText("记录已删除");
                box_2.exec();
                db.commit();
//                on_Classno_currentTextChanged(ui->Classno->currentText());
            }
            else{
                box_2.setIcon(QMessageBox::Critical);
                box_2.setWindowIcon(QIcon(":/res/logo.jpg"));
                box_2.setWindowTitle("警告");
                box_2.setText("删除失败");
                box_2.exec();
                qDebug()<<t.lastError().text();
            }

        }
    }
    else {
        box.setIcon(QMessageBox::Warning);
        box.setWindowIcon(QIcon(":/res/logo.jpg"));
        box.setWindowTitle("警告");
        box.setText("无效的记录");
        box.exec();
    }
    if(ui->student_radiobutton->isChecked()){
        StudentManageRefresh();
    }
    else {
        TeacherManageRefresh();
    }
}

void TeacherWindow::on_StudentTable_cellClicked(int row, int column)
{
    column = 0;
    if(ui->StudentTable->item(row, column) != nullptr)
        ui->Search->setText(ui->StudentTable->item(row, column)->text());
}

void TeacherWindow::on_CourseTable_cellClicked(int row, int column)
{
    column = 0;
    if(ui->CourseTable->item(row, column) != nullptr)
        ui->Search_2->setText(ui->CourseTable->item(row, column)->text());
}

// ======================================================================================= 修改密码
void TeacherWindow::on_Btn_Search_7_clicked()
{
    changePassword * password = new changePassword(db, username, TEACHER);
    password->setWindowModality(Qt::ApplicationModal);
    password->show();
}


// ======================================================================================= 刷新教师管理表
void TeacherWindow::TeacherManageRefresh(){
//    ui->Search->setPlaceholderText("请输入教师职工号");

    QSqlQuery query(db);
    query.exec("select tno, tname, admin "
               "from teacher ");

    QStringList headerlist;   //设置表头
    headerlist<<"教师工号"<<"姓名"<<"是否为管理员";
    ui->StudentTable->setColumnCount(headerlist.size());
    for (int i = 0; i < ui->StudentTable->columnCount(); ++i){
        ui->StudentTable->setHorizontalHeaderItem(i, new QTableWidgetItem(headerlist[i]));

    }
    ui->StudentTable->horizontalHeader()->setStyleSheet("QHeaderView::section{font: Bold 13pt '微软雅黑'}");
    ui->StudentTable->horizontalHeader()->setVisible(true);

    db.exec("delete from teacher where tno = ''");

    ui->StudentTable->setSortingEnabled (false);                                        // 解决关于排序后查询错乱的问题
    ui->StudentTable->clearContents();
    ui->StudentTable->setRowCount(0);
    int row = 0;
    ui->StudentTable->setRowCount(0);
    while (query.next()) {
        ui->StudentTable->insertRow(row);
        for (int i = 0; i < ui->StudentTable->columnCount(); ++i) {
            if(i == 2){
                ui->StudentTable->setItem(row, i, new QTableWidgetItem(query.value(i).toInt()==1?"是":"否"));
            }
            else
            ui->StudentTable->setItem(row, i, new QTableWidgetItem(query.value(i).toString()));
            ui->StudentTable->item(row, i)->setTextAlignment(Qt::AlignCenter);
        }
        row++;
    }

    ui->StudentTable->setSortingEnabled (true);
}
// ======================================================================================= 刷新学生管理表
void TeacherWindow::StudentManageRefresh(){


    QSqlQuery query(db);
    query.exec("select * "
               "from student ");

    QStringList headerlist;   //设置表头
    headerlist<<"学号"<<"姓名"<<"性别"<<"年级"<<"专业"<<"班级号";
    ui->StudentTable->setColumnCount(headerlist.size());
    for (int i = 0; i < ui->StudentTable->columnCount(); ++i){
        ui->StudentTable->setHorizontalHeaderItem(i, new QTableWidgetItem(headerlist[i]));

    }
    ui->StudentTable->horizontalHeader()->setStyleSheet("QHeaderView::section{font: Bold 13pt '微软雅黑'}");
    ui->StudentTable->horizontalHeader()->setVisible(true);

    ui->StudentTable->setSortingEnabled (false);                                        // 解决关于排序后查询错乱的问题
    ui->StudentTable->clearContents();
    ui->StudentTable->setRowCount(0);

    int row = 0;
    ui->StudentTable->setRowCount(0);
    while (query.next()) {
        ui->StudentTable->insertRow(row);
        for (int i = 0; i < ui->StudentTable->columnCount(); ++i) {
                ui->StudentTable->setItem(row, i, new QTableWidgetItem(query.value(i).toString()));
                ui->StudentTable->item(row, i)->setTextAlignment(Qt::AlignCenter);

        }
        row++;
    }

    ui->StudentTable->setSortingEnabled (true);
}

// ======================================================================================= 刷新课程管理表
void TeacherWindow::CourseManageRefresh(){
    QSqlQuery query(db);
    query.exec("select * "
               "from course ");

    QStringList headerlist;   //设置表头
    headerlist<<"课程号"<<"课程名"<<"教师职工号"<<"开课年级"<<"学时"<<"学分"<<"考查方式"<<"属性";
    ui->CourseTable->setColumnCount(headerlist.size());
    for (int i = 0; i < ui->CourseTable->columnCount(); ++i){
        ui->CourseTable->setHorizontalHeaderItem(i, new QTableWidgetItem(headerlist[i]));

    }
    ui->CourseTable->horizontalHeader()->setStyleSheet("QHeaderView::section{font: Bold 13pt '微软雅黑'}");
    ui->CourseTable->horizontalHeader()->setVisible(true);


    ui->CourseTable->setSortingEnabled (false);                                        // 解决关于排序后查询错乱的问题
    ui->CourseTable->clearContents();
    ui->CourseTable->setRowCount(0);

    int row = 0;
    ui->CourseTable->setRowCount(0);
    while (query.next()) {
        ui->CourseTable->insertRow(row);
        for (int i = 0; i < ui->CourseTable->columnCount(); ++i) {
                ui->CourseTable->setItem(row, i, new QTableWidgetItem(query.value(i).toString()));
                ui->CourseTable->item(row, i)->setTextAlignment(Qt::AlignCenter);
        }
        row++;
    }

    ui->CourseTable->setSortingEnabled (true);
}



void TeacherWindow::on_student_radiobutton_toggled(bool)
{
    ui->Search->clear();
    ui->Search->setPlaceholderText("请输入学号");
    StudentManageRefresh();
}

void TeacherWindow::on_teacher_radiobutton_toggled(bool)
{
    ui->Search->clear();
    ui->Search->setPlaceholderText("输入职工号");
    TeacherManageRefresh();
}


// ======================================================================================= 课程管理查询
void TeacherWindow::on_Btn_Search_2_clicked()
{
    if(ui->Search_2->text() == ""){
        CourseManageRefresh();
        return ;
    }
    QSqlQuery query(db);
    query.exec("select cno "
            "from course "
            "where cno like '%" + ui->Search_2->text() + "%'");
    if(query.next()){
        ModifyCourse * modify = new ModifyCourse(db, query.value(0).toString(), CHECK);
        modify->setWindowModality(Qt::ApplicationModal);
        modify->show();

        connect(modify, &ModifyCourse::update, this, [=]() {                           // 更新表格
           CourseManageRefresh();
        });
    }
    else{
        QMessageBox box;
        box.setIcon(QMessageBox::Warning);
        box.setWindowIcon(QIcon(":/res/logo.jpg"));
        box.setWindowTitle("警告");
        box.setText("未找到该课程");
        box.exec();
    }
}
// ======================================================================================= 课程管理修改
void TeacherWindow::on_Btn_Modify_2_clicked()
{
    if(ui->Search_2->text() == "")return ;
    QSqlQuery query(db);
    query.exec("select cno "
            "from course "
            "where cno like '%" + ui->Search_2->text() + "%'");
    if(query.next()){
        ModifyCourse * modify = new ModifyCourse(db, query.value(0).toString(), MODIFY);
        modify->setWindowModality(Qt::ApplicationModal);
        modify->show();

        connect(modify, &ModifyCourse::update, this, [=]() {                           // 更新表格
           CourseManageRefresh();
        });
    }
    else{
        QMessageBox box;
        box.setIcon(QMessageBox::Warning);
        box.setWindowIcon(QIcon(":/res/logo.jpg"));
        box.setWindowTitle("警告");
        box.setText("未找到该课程");
        box.exec();
    }
}
// ======================================================================================= 课程管理新增
void TeacherWindow::on_Btn_Add_2_clicked()
{
    ModifyCourse * modify = new ModifyCourse(db, "", ADD);
    modify->setWindowModality(Qt::ApplicationModal);
    modify->show();

    connect(modify, &ModifyCourse::update, this, [=]() {                           // 更新表格
       CourseManageRefresh();
    });
}
// ======================================================================================= 课程管理删除
void TeacherWindow::on_Btn_Delete_2_clicked()
{
    QSqlQuery query(db);
    query.exec("select cno "
            "from course "
            "where cno like '" + ui->Search_2->text() + "'");

    QMessageBox box;
    if (query.next()) {
        box.setIcon(QMessageBox::Question);
        box.setWindowIcon(QIcon(":/res/logo.jpg"));
        box.setWindowTitle("警告");
        box.setText("确定删除该记录吗?");
        box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
        if(box.exec() == QMessageBox::Yes){
            QSqlQuery t(db);
            t.exec("delete from course "
                   "where cno = '" + query.value(0).toString() + "'");
            t.exec("delete from sc "
                   "where cno = '" + query.value(0).toString() + "'");
            QMessageBox box_2;
            if(t.isActive()){
                box_2.setIcon(QMessageBox::Information);
                box_2.setWindowIcon(QIcon(":/res/logo.jpg"));
                box_2.setWindowTitle("课程管理");
                box_2.setText("记录已删除");
                box_2.exec();
                db.commit();
//                on_Classno_currentTextChanged(ui->Classno->currentText());
            }
            else{
                box_2.setIcon(QMessageBox::Critical);
                box_2.setWindowIcon(QIcon(":/res/logo.jpg"));
                box_2.setWindowTitle("警告");
                box_2.setText("删除失败");
                box_2.exec();
                qDebug()<<t.lastError().text();
            }
        }
    }
    else {
        box.setIcon(QMessageBox::Warning);
        box.setWindowIcon(QIcon(":/res/logo.jpg"));
        box.setWindowTitle("警告");
        box.setText("无效的记录");
        box.exec();
    }
    CourseManageRefresh();
}

main.cpp、.ui、.qrc文件略

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值