Python-based student attendance management system

Table of Contents
Introduction………………………………………………………………………………… 1
1. System Requirements Analysis……………… ……………………………………………… 1
1.1 Introduction to system functions…………………………………………………………… ……1
1.2 Software environment and development tools…………………………………………… 2
2. Database design……………………… ………………………………………3
2.1 General structure design……………………………………………………………3
2.1 .1 Data table structure analysis ..................................................................................... 5
2.2 Logical structure design ................................................................................................... …………………………7
3. System design and implementation…………………………………………………………………………………………………………………………………………………………………………………8
4. Conclusion and There are still problems ...................................................................................................................15
References ................................................................................................................................... ………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………
17

1. System requirements analysis
1.1 System function introduction
(1) User login, registration, password retrieval and password modification functions. There are three user identities in this system, which are administrator (admin), teacher (teacher), student or normal user (normal). Set by administrator.
(2) The user can enter the system after registering an account. At this time, the user needs to complete information authentication before using the system's sign-in and sign-in management functions. Otherwise, the system will display a warning message and restrict the use of some system functions, prompting the user to authenticate. use. The certified information is pre-imported by the administrator. After the student or teacher enters the student number or job number, if the information has been imported into the system database and the information has not been certified, the certification can be passed.
(3) The system administrator can manage all the functions of the sign-in system for users. Of course, authentication is required to use the relevant sign-in functions. In this way, the administrator can also use the sign-in management function as a teacher under this condition. The administrator mainly imports student and teacher data and manages all data in the system (addition, deletion, modification, query, and export to files).
(4) After completing the verification information, if there is a course that is being signed in after the student enters the system, the course information that is currently being signed in will be displayed. After clicking on the course and entering the correct verification code, the sign-in of the current course can be completed; students can also view All your own sign-in records, and you can query the sign-in records of related courses according to conditions.
(5) After completing the authentication information, after entering the system, the teacher can add the course information that needs to be used for sign-in, and manage the sign-in. After the teacher selects a course to open the sign-in, a 4-digit sign-in code will be randomly generated for students belonging to the class After entering the sign-in code, the sign-in can be completed.

The general block diagram of the functional modules of this system is shown in Figure 1-1 below.
Figure 1-1 Functional module diagram of student sign-in management system
insert image description here

# -*- coding: utf-8 -*-
"""
Created on Tue Jun  8 10:33:22 2021

@author: cxyqm
"""

import sqlite3
import time
class SysDao:
    def __init__(self):
        self.cn=sqlite3.connect("SignInSystem.db")
    
    def executeQuery(self,sql,params=None):
        cn=sqlite3.connect("SignInSystem.db")
        cur = cn.cursor()
        try:
            if params==None:
                cur.execute(sql)
            else:
                cur.execute(sql,params)
            rs=cur.fetchall()
        except:
            print('查询出错')
        finally:
            cur.close()#关闭游标
            cn.close()#关闭连接
        return rs
    
    def executeUpdate(self,sql,params=None):
        cn=sqlite3.connect("SignInSystem.db")
        cur = cn.cursor()
        try:
            cur.execute(sql,params)
            cn.commit()
        except:
            cn.rollback()
        finally:
            cur.close()#关闭游标
            cn.close()#关闭连接
        return cur.rowcount
    
    def executemanyUpdate(self,sql,params):
        cn=sqlite3.connect("SignInSystem.db")
        cur = cn.cursor()
        try:
            cur.executemany(sql,params)
            cn.commit()
        except:
            cn.rollback()
        finally:
            cur.close()#关闭游标
            cn.close()#关闭连接
        return cur.rowcount
    
    def initTables(self):
        cn=sqlite3.connect("SignInSystem.db")
        cur = cn.cursor()
        try:
            cur.execute('SELECT count(*) FROM sqlite_master WHERE type="table" AND name = "userinfo"')
            flag=cur.fetchall()
            if flag[0][0]==0:
                cur.execute("""create table if not exists userinfo(
                    usrid varchar(30) primary key,
                    usrname varchar(40) not null,
                    pword varchar(30) not null,
                    tel varchar(20),
                    identity varchar(20) default 'normal',
                    statu int default 0 ,
                    registtime varchar(30));""")
                registtime=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
                userdata=[('admin000','大白','12345678','13025468631','admin',1,registtime),
                 ('teacher000','杨老师','12345678','12035413553','teacher',1,registtime),
                  ('student000','陈辰','12345678','13652048631','normal',1,registtime),
                  ('student001','李桓','12345678','13642568631','normal',0,registtime)]
                cur.executemany("insert into userinfo values(?,?,?,?,?,?,?)",userdata)
                cn. commit()
            cur.execute('SELECT count(*) FROM sqlite_master WHERE type="table" AND name = "studentinfo"')
            flag=cur.fetchall()
            if flag[0][0]==0:
                cur.execute("""create table if not exists studentinfo(
                    stuno varchar(30) primary key,
                    stuname varchar(40) not null,
                    academe varchar(60) not null,
                    specialty varchar(60) not null,
                    classname varchar(60) not null,
                    sex char(2) default '男' check(sex in ('男','女')));""")
                studata=[('20190060101','小白','数学学院','大数据技术','19大数据','男'),
                 ('20190060102','小新','环化学院','环境工程','19环境工程','女'),
                  ('20190060103','陈辰','数学学院','数学师范','19师范','男')]
                cur.executemany("insert into studentinfo values(?,?,?,?,?,?)",studata)
                cn. commit()
                 
            cur.execute('SELECT count(*) FROM sqlite_master WHERE type="table" AND name = "teacherinfo"')
            flag=cur.fetchall()
            if flag[0][0]==0:
                cur.execute("""create table if not exists teacherinfo(
                    techno varchar(30) primary key,
                    techname varchar(40) not null,
                    prodession varchar(60) not null,
                    sex char(2) default '男' check(sex in ('男','女')));""")
                teacherdata=[('88888888','大白','系统管理员','男'),('20192019','杨宇','教授','男')]
                cur.executemany("insert into teacherinfo values(?,?,?,?)",teacherdata)
                cn. commit()
                
            cur.execute('SELECT count(*) FROM sqlite_master WHERE type="table" AND name = "tccinfo"')
            flag=cur.fetchall()
            if flag[0][0]==0:
                cur.execute("""create table if not exists tccinfo(
                    tccid integer ,
                    techno varchar(30) not null,
                    classname varchar(60) not null,
                    coursename varchar(60) not null,
                    term varchar(60) not null,
                    classnum int,
                    primary key(tccid),
                    foreign key(techno) references teacherinfo(techno) on delete cascade on update cascade);""")
                tccdata=[(None,'88888888','19大数据','Python','2020-2021学年第二学期','35'),(None,'20192019','19师范','高等代数','2020-2021学年第二学期','52')]
                cur.executemany("insert into tccinfo values(?,?,?,?,?,?)",tccdata)
                cn. commit()
            cur.execute('SELECT count(*) FROM sqlite_master WHERE type="table" AND name = "startsign"')
            flag=cur.fetchall()
            if flag[0][0]==0:
                cur.execute("""create table if not exists startsign(
                    signid integer,
                    tccid integer not null,
                    signcode varchar(30) not null,
                    signstatus int default 0,
                    starttime text not null,
                    endtime  text,
                    primary key(signid),
                    foreign key(tccid) references tccinfo(tccid) on delete cascade on update cascade);""")
                cn. commit()
            
            cur.execute('SELECT count(*) FROM sqlite_master WHERE type="table" AND name = "signrecord"')
            flag=cur.fetchall()
            if flag[0][0]==0:
                cur.execute("""create table if not exists signrecord(
                    id integer,
                    signid integer not null,
                    stuno varchar(30) not null,
                    signstatus int default 0,
                    signtime text not null,
                    primary key(id),
                    foreign key(signid) references startsign(signid) on delete cascade on update cascade,
                    foreign key(stuno) references studentinfo(stuno) on delete cascade on update cascade);""")
                cn. commit()
                
            cur.execute('SELECT count(*) FROM sqlite_master WHERE type="table" AND name = "authentication"')
            flag=cur.fetchall()
            if flag[0][0]==0:
                cur.execute("""create table if not exists authentication(
                    usrid varchar(30) primary key,
                    no varchar(30) not null,
                    foreign key(usrid) references userinfo(usrid) on delete cascade on update cascade);""")
                authdata=[('admin000','88888888'),('teacher000','20192019'),('student000','20190060103')]
                cur.executemany("insert into authentication values(?,?)",authdata)
                cn. commit()
            return True
        except:
            cn.rollback()
            return False
        finally:
            cur.close()#关闭游标
            cn.close()#关闭连接

    def dropTables(self,tablename):
        cn=sqlite3.connect("SignInSystem.db")
        cur = cn.cursor()
        try:
            cur.execute('DROP TABLE IF EXISTS %s'%tablename)
            cn.commit()
        except:
            cn.rollback()
        finally:
            cur.close()#关闭游标
            cn.close()#关闭连接

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/sheziqiong/article/details/130880667