Student attendance system based on Qt design

1. Function introduction

The current designed attendance system is mainly used by college teachers. During class, students enter the classroom, take out their student card and open their attendance. They can apply for leave in the system and view all class attendance information during school.

Considering the large number of students in the whole school and the problem of personal privacy, each new student needs to be logged in by the administrator or his own head teacher to enter the student information management page for the operation of adding students' information and adding students' relevant information; Then, the students themselves go to the login interface to register students and improve their other information. After the prompt of successful registration, they can log in successfully by entering the login interface and filling in the account and password at the time of registration. Finally, they can use the function module of the student operation page. Teachers need to log in to the teacher management background through the specified teacher account and password to use the functional modules of the teacher's operation page. The system administrator needs to log in to the administrator background through the specified administrator account and password to use the functional modules of the administrator operation page. The operation pages of the three are independent of each other and have permission restrictions.

At present, the RFID based student attendance management system adopts C + + as the programming language, Qt as the overall UI software framework, and SQLite as the database. Before designing the attendance system, we conducted extensive search on the Internet, found many cases, and found some problems in many attendance management systems, operation processes and management lines, After combining the advantages of other software, this system removes some unnecessary modules and designs a new attendance management system.

The functional modules included are as follows:

1) Login module: user name and password login. This design has three types of user names, including system administrator, teachers and students;

2) Student information management module: add, delete, modify and query the basic information of students;

3) Attendance management module: student sign in and sign out;

4) RF card management module: use RF card to record the attendance of students;

5) Query module: administrators, teachers and students can query attendance results within their authority;

6) Leave query module: query students' leave status through ID;

7) Data backup module: system data is saved regularly, but help is provided in case of system server failure.

The system has three user permissions: student operation page, administrator operation page and teacher operation page. On the student operation page, you can view your attendance records; On the teacher operation page, you can view the attendance records of students in your class and add attendance students; The administrator can view everyone's attendance records and support all functions.

The IC card reader and writer with USB interface adopts RF-EYE, a RF reader and writer launched by Minghua company. It adopts USB interface for communication and power collection, and supports cards of ISO14443-3 protocol, such as Mifare One, UltraLight, Mifare 4K, MifarePro, etc. The interface function library provided can meet the needs of user secondary development; Its perfect and reliable interface function supports all functions of accessing RF card.

Complete project source code and data download: Student attendance system based on QT design zip - desktop system document resources - CSDN Download

2. Design and Implementation

2.1 system function module

The overall design block diagram is as follows:

2.2 login flow chart

In the module for administrators and teachers to fill in login information, you need to enter the login account and login password at the time of registration. You can select one of the teachers or administrators as the user identity. The administrator account and the teacher account are independent of each other.

2.3 adding students

The data is stored in the local SQLite.

2.4 leave management

3. Project source code

3.1 reading and saving configuration information

//Read configuration
void LoginWindow::read_config()
{
    //Read configuration file
    QString text;
    text=QCoreApplication::applicationDirPath()+"/"+CONFIG;
​
    QString pass;
    QString user;
    //Determine whether the file exists
    if(QFile::exists(text))
    {
        QFile filenew(text);
        filenew.open(QIODevice::ReadOnly);
        QDataStream in(&filenew); // Read serialized data from file
        in >> user >> pass; //Extract written data
        filenew.close();
​
        //Set interface value
       ui->lineEdit_user_name->setText(user);
       ui->lineEdit_password->setText(pass);
       ui->checkBox_save_password->setChecked(true);
    }
}
​
​
//Write configuration
void LoginWindow::write_config()
{
    QString pass;
    QString user;
    //Obtain the user's personalized configuration parameters from the UI interface
    pass=ui->lineEdit_password->text();
    user=ui->lineEdit_user_name->text();
​
    /*Save data to file for next loading*/
    QString text;
    text=QCoreApplication::applicationDirPath()+"/"+CONFIG;
    QFile filesrc(text);
    filesrc.open(QIODevice::WriteOnly);
    QDataStream out(&filesrc);
    out << user;  //Serialize user name
    out << pass;  //Serialization password
    filesrc.flush();
    filesrc.close();
}

3.2 saving and searching of login information

//Create account password table
void LoginWindow::CreateUserPassTAB()
{
    //Database: create a table. If it exists, it will not be created. If it does not exist, it will be created
    QSqlQuery sql_query(database);
​
    //The following statement queries whether the specified table exists
    sql_query.exec(QString("select count(*) from sqlite_master where type='table' and name='%1'").arg("password"));
    if(sql_query.next())
    {
        if(sql_query.value(0).toInt()==0)
        {
            qDebug("The database table does not exist.Ready to create.\n");
            //Create table create table statement: create table < table_ name> (f1 type1, f2 type2,…);
            /* CREATE TABLE Is a keyword that tells the database system to create a new table.
                * CREATE TABLE Statement followed by the unique name of the table
                * Or identification*/
            /*The following statement: create a table named password. The fields are account, password and identity (0 administrator, 1 teacher and 2 students)*/
            QString create_sql = "create table password(id int primary key, user varchar(100),password varchar(100),int type)";
​
            sql_query.prepare(create_sql);
            if(!sql_query.exec())
            {
                Log_Text_Display("Database table creation failed.\n");
            }
            else
            {
                Log_Text_Display("Database table created successfully.\n");
                //Initialized administrator password
                addPasswords(ROOT_USER,ROOT_PASSWORD,0);
            }
        }
        else
        {
            Log_Text_Display("Database tables exist.No need to create.\n");
        }
    }
}
​
​
//Show log
void LoginWindow::Log_Text_Display(QString text)
{
    qDebug()<<text;
}
​
//Insert data into database file
bool LoginWindow::addPasswords(QString user,QString pass,int type)
{
    //Specify the database for the operation
    QSqlQuery sql_query(database);
    //Query maximum ID
    QString select_max_sql = "select max(id) from password";
    int max_id = 0;
    sql_query.prepare(select_max_sql);
    if(!sql_query.exec())
    {
        Log_Text_Display("Database maximum ID Search failed.\n");
    }
    else
    {
        while(sql_query.next())
        {
            max_id = sql_query.value(0).toInt();
        }
​
        Log_Text_Display(QString("data base max id:%1\n").arg(max_id));
​
        //Add data
        //Insert data insert statement: insert into < table_ name> values (value1, value2,…);
        QString insert_sql = tr("insert into password values(?,?,?,?)");
        sql_query.prepare(insert_sql);
        //if(max_id!=0)max_id+=1; // Judge whether it is the first data
        sql_query.addBindValue(max_id+1); //id
        sql_query.addBindValue(user);    //account number
        sql_query.addBindValue(pass);    //password
        sql_query.addBindValue(type);    //type
        if(!sql_query.exec())
        {
            Log_Text_Display("Data insertion failed.\n");
        }
        else
        {
            return true;
        }
    }
    return false;
}
​
​
//Comparing passwords true succeeded false failed
bool LoginWindow::ComparePasswords(QString user,QString pass,int type)
{
    //Specify the database for the operation
    QSqlQuery sql_query(database);
    //Query all data
    sql_query.prepare("select * from password");
    if(!sql_query.exec())
    {
        Log_Text_Display("Database query error.\n");
    }
    else
    {
        while(sql_query.next())
        {
            int id = sql_query.value(0).toInt(); //ID -- primary key
            QString sql_user = sql_query.value(1).toString(); //account number
            QString sql_pass = sql_query.value(2).toString(); //password
            int sql_type = sql_query.value(3).toInt(); //Identity type
            //Compare passwords
            if(user==sql_user && sql_pass==pass && sql_type ==type)
            {
                return true;
            }
        }
    }
    return false;
}

3.3 initialization of main interface

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowTitle("Student attendance management system");
​
    //Set up and open the database
    if (QSqlDatabase::contains(LOG_IN_DATABASE_CONNECT_NAME))
    {
        database = QSqlDatabase::database(LOG_IN_DATABASE_CONNECT_NAME);
    }
    else
    {
        //Database type
        database = QSqlDatabase::addDatabase("QSQLITE",LOG_IN_DATABASE_CONNECT_NAME);
        database.setDatabaseName(LOG_IN_DATABASE_NAME); //Database name
        database.setUserName("xl");  //user name
        database.setPassword("123456"); //password
    }
​
    //Open the database. If the database exists, it will be opened. If it does not exist, it will be created automatically
    if(database.open()==false)
    {
        qDebug("Database open failed.Please check the program running path and permissions.\n");
    }
    else
    {
        qDebug("Successfully connected to database.\n");
    }
​
    //Create account password table
    CreateUserPassTAB();
​
    //Configure the management table style attribute of account and password
    //Color alternation of odd and even rows
    //ui->tableWidget_user_pass->setAlternatingRowColors(true);
    //When selected, a row is selected as a whole
    ui->tableWidget_user_pass->setSelectionBehavior(QAbstractItemView::SelectRows);
    //Last row stretch fill
    //ui->tableWidget_user_pass->horizontalHeader()->setStretchLastSection(true);
    //Select whether to bold the header of a row
    ui->tableWidget_user_pass->horizontalHeader()->setHighlightSections(false);
    //The header is not clickable
    ui->tableWidget_user_pass->horizontalHeader()->setSectionsClickable(false);
    //Table columns change adaptively as the table changes
    ui->tableWidget_user_pass->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
​
    //Configure student management table style properties
    //Color alternation of odd and even rows
    //ui->tableWidget_student->setAlternatingRowColors(true);
    //When selected, a row is selected as a whole
    ui->tableWidget_student->setSelectionBehavior(QAbstractItemView::SelectRows);
    //Last row stretch fill
    //ui->tableWidget_student->horizontalHeader()->setStretchLastSection(true);
    //Select whether to bold the header of a row
    ui->tableWidget_student->horizontalHeader()->setHighlightSections(false);
    //The header is not clickable
    ui->tableWidget_student->horizontalHeader()->setSectionsClickable(false);
    //Table columns change adaptively as the table changes
    ui->tableWidget_student->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
​
    //Configure style properties of student attendance list
    //Color alternation of odd and even rows
    //ui->tableWidget_SignIn->setAlternatingRowColors(true);
    //When selected, a row is selected as a whole
    ui->tableWidget_SignIn->setSelectionBehavior(QAbstractItemView::SelectRows);
    //Last row stretch fill
    //ui->tableWidget_SignIn->horizontalHeader()->setStretchLastSection(true);
    //Select whether to bold the header of a row
    ui->tableWidget_SignIn->horizontalHeader()->setHighlightSections(false);
    //The header is not clickable
    ui->tableWidget_SignIn->horizontalHeader()->setSectionsClickable(false);
    //Table columns change adaptively as the table changes
    ui->tableWidget_SignIn->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
​
    //Configure style properties of leave list
    //Color alternation of odd and even rows
    //ui->tableWidget_SignIn->setAlternatingRowColors(true);
    //When selected, a row is selected as a whole
    ui->tableWidget_leave->setSelectionBehavior(QAbstractItemView::SelectRows);
    //Last row stretch fill
    ui->tableWidget_leave->horizontalHeader()->setStretchLastSection(true);
    //Select whether to bold the header of a row
    ui->tableWidget_leave->horizontalHeader()->setHighlightSections(false);
    //The header is not clickable
    ui->tableWidget_leave->horizontalHeader()->setSectionsClickable(false);
    //Table columns change adaptively as the table changes
    //ui->tableWidget_leave->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
​
    //Update data
    on_pushButton_update_data_clicked();
    on_pushButton_update_student_clicked();
    on_pushButton_SignIn_update_data_clicked();
    on_pushButton_leave_update_clicked();
    //Timer - real time time display
    timer=new QTimer;
    connect(timer, SIGNAL(timeout()), this, SLOT(timer_update()));
    timer->start(1000);
}

3.4 leave information storage

//leave
void Widget::on_pushButton_leave_clicked()
{
    //Create student information table of leave module in database
    CreateLeaveSurface();
​
    //Fill in leave information
    QString number=ui->lineEdit_leave_number_in->text();
    if(number.isEmpty())
    {
        QMessageBox::information(this,"Tips","Please fill in the student number carefully.",
        QMessageBox::Ok,QMessageBox::Ok);
        return;
    }
​
    //Reasons for leave
    QString text=ui->lineEdit_text->text();
    if(text.isEmpty())
    {
        QMessageBox::information(this,"Tips","Please fill in the reason.",
        QMessageBox::Ok,QMessageBox::Ok);
        return;
    }
​
    Log_Text_Display(QString("Student number of leave inquiry:%1.\n").arg(number));
​
    //Query the selected form of student number
    //Specify the database for the operation
    QSqlQuery sql_query(database);
    //Query all data
    sql_query.prepare("select * from student");
    if(!sql_query.exec())
    {
        Log_Text_Display("Student database query error.\n");
    }
    else
    {
        bool flag=1;
        while(sql_query.next())
        {
            // ID, student number, name, phone number, status
            int find_id = sql_query.value(0).toInt(); //ID
            QString find_number = sql_query.value(1).toString(); //Student number
            QString find_name = sql_query.value(2).toString();   //full name
            QString find_phone = sql_query.value(3).toString();  //Telephone
            QString find_state = sql_query.value(4).toString();  //state
​
            //
​
            //Find student number
            if(find_number == number)
            {
                flag=0;
​
                //Returns the number of rows.
                int RowCount=ui->tableWidget_leave->rowCount(); //Get the current total number of rows
                ui->tableWidget_leave->setRowCount(RowCount+1); //Set number of rows
                int i;
​
                //Create cells from the total number of columns
                for(i=0;i<ui->tableWidget_leave->columnCount();i++)
                {
                    ui->tableWidget_leave->setItem(RowCount,i,new QTableWidgetItem(""));
                    //Set text alignment
                    ui->tableWidget_leave->item(RowCount,i)->setTextAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
                }
​
                //Set check-in status
                QDateTime current_date_time =QDateTime::currentDateTime();
                QString current_date =current_date_time.toString("yyyy.MM.dd");
                find_state=QString("time: %1 Subject matter: %2").arg(current_date).arg(text);
​
                //Set the data displayed in the table
                ui->tableWidget_leave->item(RowCount,0)->setText(find_number);
                ui->tableWidget_leave->item(RowCount,1)->setText(find_name);
                ui->tableWidget_leave->item(RowCount,2)->setText(find_phone);
                ui->tableWidget_leave->item(RowCount,3)->setText(find_state);
​
                //Save to database
​
                //Preparing to insert data
                //Query maximum ID
                QString select_max_sql = "select max(id) from leave";
                int max_id = 0;
                sql_query.prepare(select_max_sql);
                if(!sql_query.exec())
                {
                    Log_Text_Display("Maximum number of leave forms ID Search failed.\n");
                }
                else
                {
                    while(sql_query.next())
                    {
                        max_id = sql_query.value(0).toInt();
                    }
                    Log_Text_Display(QString("data base max id:%1\n").arg(max_id));
​
                    //Add data
                    //Insert data insert statement: insert into < table_ name> values (value1, value2,…);
                    QString insert_sql = tr("insert into leave values(?,?,?,?,?)");
                    sql_query.prepare(insert_sql);
                    //ID, student number, name, telephone number, reason
                    sql_query.addBindValue(max_id+1); //id
                    sql_query.addBindValue(find_number);
                    sql_query.addBindValue(find_name);
                    sql_query.addBindValue(find_phone);
                    sql_query.addBindValue(find_state);
                    if(!sql_query.exec())
                    {
                        Log_Text_Display("Failed to insert leave form data.\n");
                        return;
                    }
                    else //Insert successful
                    {
                        //Clear the page if the insertion is successful
                        ui->lineEdit_leave_number_in->clear();
                        ui->lineEdit_text->clear();
                    }
                }
                break;
            }
        }
        if(flag)
        {
            QMessageBox::information(this,"Tips","This student number is not found.",
            QMessageBox::Ok,QMessageBox::Ok);
            return;
        }
    }
}

Keywords: Qt Embedded system

Added by karimali831 on Wed, 26 Jan 2022 11:09:37 +0200