定义打印主页信息函数。

def print_Home_page(): print('请根据选项提示选择正确的选项!!!') print('1. 用户端') print('2. 管理端') print('3. 退出')

定义打印用户端主页信息函数。

def print_User_page(): print('请根据选项提示选择正确的选项!!!') print('1. 学生考勤') print('2. 查询考勤状态') print('3. 学生端密码修改') print('4. 退出')

定义打印管理端主页信息函数。

def print_Management_page(): print('请根据选项提示选择正确的选项!!!') print('1. 查询学生考勤状态') print('2. 发布考勤') print('3. 管理考勤学生') print('4. 管理员管理') print('5. 退出')

定义选择选项函数,其中参数small,big分别为选择选项范围,即small~big。

def select_options(small,big): from string import digits flag=True while flag: select=input(f'请输入您的选择({small}-{big}):') for i in select: if i in digits: if int(select)>=small and int(select)<=big: flag=False else: flag=True else: flag=True if flag: print('您的输入有误,请重新输入!!!') return int(select)

定义账号密码验证函数

def verify_the_account_password(file,location): global account account=input('请输入账号:') global password password=input('请输入密码:') with open(file,'r') as fp: lineslen=len(fp.readlines()) fp.seek(location) # 查询账号 for i in range(lineslen-1): # 提取储存的账号 line=fp.readline() verify_account=[] for j in line: if j!=',': verify_account.append(j) else: break verify_the_account=verify_account[0] for j in range(1,len(verify_account)): verify_the_account=verify_the_account+verify_account[j] # 如若账号正确,查询密码 # 验证账号 if verify_the_account==account: # 提取储存的密码 flag=False verify_password=[] counting=0 for j in line: if j==',': counting=counting+1 if counting==1 and j != ',': verify_password.append(j) verify_the_password=verify_password[0] for j in range(1,len(verify_password)): verify_the_password=verify_the_password+verify_password[j] # 验证密码 if verify_the_password==password: return '验证成功' break else: print('密码错误!') return '验证失败' break # 如若账号错误,提示错误 else: flag=True if flag: print('帐号错误!') return '验证失败'

定义密码验证函数

def verify_the_password(file,location,account): global password password0=input('请输入密码:') with open(file,'r') as fp: lineslen=len(fp.readlines()) fp.seek(location) # 查询账号 for i in range(lineslen-1): # 提取储存的账号 line=fp.readline() verify_account=[] for j in line: if j!=',': verify_account.append(j) else: break verify_the_account=verify_account[0] for j in range(1,len(verify_account)): verify_the_account=verify_the_account+verify_account[j] # 如若账号正确,查询密码 # 验证账号 if verify_the_account==account: # 提取储存的密码 flag=False verify_password=[] counting=0 for j in line: if j==',': counting=counting+1 if counting==1 and j != ',': verify_password.append(j) verify_the_password=verify_password[0] for j in range(1,len(verify_password)): verify_the_password=verify_the_password+verify_password[j] # 验证密码 if verify_the_password==password0: return '验证成功' password=password0 break else: print('密码错误!') return '验证失败' break # 如若账号错误,提示错误 else: flag=True if flag: print('帐号错误!') return '验证失败'

查询函数

def Inquire(file,location,Inquire_location,target): with open(file,'r') as fp: lineslen=len(fp.readlines()) fp.seek(location) # 查询账号 flag=True for i in range(lineslen-1): # 提取储存的账号 line=fp.readline() verify_target=[] counting=0 for j in line: if j==',': counting=counting+1 if j!=',' and counting==Inquire_location: verify_target.append(j) verify_the_target=verify_target[0] for j in range(1,len(verify_target)): verify_the_target=verify_the_target+verify_target[j] if verify_the_target==target: flag=False return {i:line.strip()} if flag: print('未查找到')

修改函数

def revise(file,location,line,revise_location,target): with open(file,'r') as fp: lineslen=len(fp.readlines()) fp.seek(location) lines=fp.readlines() fp.seek(location) line_information=lines[line] front=[] behind=[] counting=0 for i in line_information: if revise_location==0: if i==',': counting=counting+1 if counting>=revise_location+1: behind.append(i)

        elif revise_location==5:
            if i==',':
                counting=counting+1
            if  counting<=revise_location-1:
                front.append(i)

        else:
            if i==',':
                counting=counting+1
            if counting<=revise_location-1:
                front.append(i)
            if counting>=revise_location+1:
                behind.append(i)

    if revise_location==0:
        behind_information=behind[0]
        for j in range(1,len(behind)):
            behind_information=behind_information+behind[j]
        final_information=target+behind_information
        lines[line]=final_information
        
    elif revise_location==5:
        front_information=front[0]
        for j in range(1,len(front)):
            front_information=front_information+front[j]
        final_information=front_information+','+target+'\n'
        lines[line]=final_information
        
    else:
        front_information=front[0]
        for j in range(1,len(front)):
            front_information=front_information+front[j]
        behind_information=behind[0]
        for j in range(1,len(behind)):
            behind_information=behind_information+behind[j]
        final_information=front_information+','+target+behind_information
        lines[line]=final_information
lines.insert(0,'账号,密码,姓名,性别,班级,状态\n')
with open(file,'w') as fp:
    pass
for i in range(len(lines)):
    single_line=lines[i:i+1:]
    with open(file,'a') as fp:
        fp.writelines(single_line)

查询多个

def Inquire_many(file,location,Inquire_location,target): with open(file,'r') as fp: lineslen=len(fp.readlines()) fp.seek(location) # 查询账号 counting0=0 for i in range(lineslen-1): # 提取储存的账号 verify_the_target='' line=fp.readline() counting=0
for j in line: if j==',': counting=counting+1 if j!=',' and counting==Inquire_location: verify_the_target=verify_the_target+j verify_the_target=verify_the_target.strip()

        if verify_the_target==target:
            counting0=counting0+1
            print(counting0,'---',line.strip())
    return counting0

定义学生添加请假,迟到,旷勤函数

def add_leave_late_absenteeism(file,location,account,type): verify=input('请输入'确定'后方可操作:') if verify=='确定': query_results=Inquire(file,location,0,account) for key, value in query_results.items(): key0=key value0=value counting=0 state='' for i in value0: if i==',': counting=counting+1 if counting==5: state=state+i if type=='请假': if state==',请假': print('您已请假,无需再次请假!') print('您可在查询考勤状态选项中查看考勤状态!') input('请输入任意键继续!') else: revise(file,location,key0,5,'请假') query_results=Inquire(file,location,0,account) for key, value in query_results.items(): key1=key value1=value print('姓名,性别,班级,状态') counting=0 for i in value1: if i==',': counting=counting+1 if counting>=2: print(i,end='') print('\n') input('请输入任意键继续!') elif type=='迟到': if state==',迟到': print('您已迟到,无需再次迟到!') print('您可在查询考勤状态选项中查看考勤状态!') input('请输入任意键继续!') else: revise(file,location,key0,5,'迟到') query_results=Inquire(file,location,0,account) for key, value in query_results.items(): key2=key value2=value print('姓名,性别,班级,状态') counting=0 for i in value2: if i==',': counting=counting+1 if counting>=2: print(i,end='') print('\n') input('请输入任意键继续!') elif type=='旷勤': if state==',旷勤': print('您已旷勤,无需再次旷勤!') print('您可在查询考勤状态选项中查看考勤状态!') input('请输入任意键继续!') else: revise(file,location,key0,5,'旷勤') query_results=Inquire(file,location,0,account) for key, value in query_results.items(): key3=key value3=value print('姓名,性别,班级,状态') counting=0 for i in value3: if i==',': counting=counting+1 if counting>=2: print(i,end='') print('\n') input('请输入任意键继续!')

定义管理员的添加与删除函数

def add_delete(file,location,option): if option=='添加': verify=input('请输入'确定'后方可添加:') if verify=='确定': information=[] account=input('请输入账号:') password=input('请输入密码:') name=input('请输入姓名:') sex=input('请输入性别:') grade=input('请输入班级:') status='未签' information.append(account) information.append(',') information.append(password) information.append(',') information.append(name) information.append(',') information.append(sex) information.append(',') information.append(grade) information.append(',') information.append(status) information.append('\n') with open(file,'a') as fp: fp.writelines(information) print('添加成功!') input('请输入任意键继续!') elif option=='删除': verify=input('请输入'确定'后方可删除:') if verify=='确定': account=input('请输入要删除的账号:') query_results=Inquire(file,location,0,account) for key, value in query_results.items(): key0=key value0=value revise(file,location,key0,5,'删除') print('删除成功!') input('请输入任意键继续!')

打印主页

print_Home_page()

选择选项

select=select_options(1,3)

根据选择打印次级页面,如用户端主页,管理端主页

if select==1: flag2=False verify=verify_the_account_password('students.csv',31) if verify=='验证成功': flag1=True

else:
    flag1=False
    exit()

elif select==2: flag1=False verify=verify_the_account_password('administrator.csv',21) if verify=='验证成功': flag2=True

else:
    flag2=False
    exit()

else: exit()

进入用户端

while True:
if flag1: print_User_page() select=select_options(1,4)

    if select==1:
        verify=input('请输入'确定'后方可考勤:')
        if verify=='确定':
            query_results=Inquire('students.csv',31,0,account)
            for key, value in query_results.items():
                key0=key
                value0=value
            counting=0
            state=''
            for i in value0:
                if i==',':
                    counting=counting+1
                if counting==5:
                    state=state+i
            if state==',已签':
                print('您已签到,无需再次签到!')
                print('您可在查询考勤状态选项中查看考勤状态!')
                input('请输入任意键继续!')
            else:
                revise('students.csv',31,key0,5,'已签')
                query_results=Inquire('students.csv',31,0,account)
                for key, value in query_results.items():
                    key1=key
                    value1=value
                print('姓名,性别,班级,状态')
                counting=0
                for i in value1:
                    if i==',':
                        counting=counting+1
                    if counting>=2:
                        print(i,end='')
                print('\n')
                input('请输入任意键继续!')
        
    elif select==2:
        query_results=Inquire('students.csv',31,0,account)
        for key, value in query_results.items():
            key1=key
            value1=value
        print('姓名,性别,班级,状态')
        counting=0
        for i in value1:
            if i==',':
                counting=counting+1
            if counting>=2:
                print(i,end='')
        print('\n')
        input('请输入任意键继续!')
        
    elif select==3:
        verify=verify_the_password('students.csv',31,account)
        if verify=='验证成功':
            flag=True
            target=input('请输入新的密码(密码位数至少6位):')
            while flag:
                counting=0
                for i in target:
                    counting=counting+1
                if counting<6 or counting>15:
                    target=input('密码位数少于6位或密码多于15位,请重新输入新的密码:')
                else:
                    flag=False
            while target==password:
                target=input('旧密码与新密码相同,请重新输入新的密码:')
            query_results=Inquire('students.csv',31,0,account)
            for key, value in query_results.items():
                key0=key
                value0=value
            revise('students.csv',31,key0,1,target)
            password=target
            print('密码修改完成')
            input('请输入任意键继续!')
            
    else:
        exit()

进入管理端

if flag2:
    print_Management_page()
    select=select_options(1,5)
    if select==1:
        print('------账号--密码--姓名--性别--班级--状态')
        counting=Inquire_many('students.csv',31,5,'未签')
        print('未签人数为',counting,'人')
        print('\n')
        counting=Inquire_many('students.csv',31,5,'已签')
        print('已签人数为',counting,'人')
        input('请输入任意键继续!')
    elif select==2:
        print('注意发布考勤会重置所有考勤为”未签“,请谨慎确定!!')
        verify=input('请输入“确定”后方可发布考勤:')
        if verify=='确定':
            with open('students.csv','r') as fp:
                lineslen=len(fp.readlines())
                fp.seek(31)
            for i in range(lineslen-1):
                revise('students.csv',31,i,5,'未签')
            print('发布考勤成功!')
    elif select==3:
        print('请选择要进行的操作:')
        print('1. 添加学生')
        print('2. 删除学生')
        print('3. 请假')
        print('4. 迟到')
        print('5. 旷勤')
        select0=select_options(1,5)
        if select0==1:
            add_delete('students.csv',31,'添加')
        elif select0==2:
            add_delete('students.csv',31,'删除')
        elif select0==3:
            add_leave_late_absenteeism('students.csv',31,account,'请假')
        elif select0==4:
            add_leave_late_absenteeism('students.csv',31,account,'迟到')
        elif select0==5:
            add_leave_late_absenteeism('students.csv',31,account,'旷勤')
    elif select==4:
        print('请选择要进行的操作:')
        print('1. 添加管理员')
        print('2. 删除管理员')
        select0=select_options(1,2)
        if select0==1:
            add_delete('administrator.csv',21,'添加')
        elif select0==2:
            add_delete('administrator.csv',21,'删除')
    else:
        exit()
考勤系统-用户端和管理端功能实现

原文地址: https://www.cveoy.top/t/topic/oFtR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录