back
back
import uuid
def userexist(gh):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
#cur.execute("select * from teacher where workno = '"+gh+"' ")
#cur.execute("select * from teacher where workno = '%s' "%(gh,))
cur.execute("select * from teacher where workno = ? ",(gh,))
data=cur.fetchall()
conn.close()
if len(data)==1:
return True
else:
return False
def userpass(gh,mm):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
if mm==data[0][0]:
return True
else:
return False
def reg(gh,name,mm):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
try:
cur.execute("insert into teacher(workno,name,password) values (?,?,?) ",
(gh,name,mm))
conn.commit()
conn.close()
return 'success'
except Exception as err:
conn.rollback()
conn.close()
return err
def modpassword(gh,newmm):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
try:
cur.execute("update teacher set password=? where workno =? ",(newmm,gh))
conn.commit()
conn.close()
return 'success'
except Exception as err:
conn.rollback()
conn.close()
return err
def deluser(gh):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
try:
cur.execute("delete from teacher where workno =? ",(gh,))
if cur.rowcount==1:
conn.commit()
conn.close()
return 'success'
else:
conn.rollback()
conn.close()
return '删除了 0 行数据'
except Exception as err:
conn.rollback()
conn.close()
return err
def addcourse(courseuuid,gh,code,coursename):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
try:
cur.execute("insert into course values (?,?,?,?) ",
(courseuuid,gh,code,coursename))
conn.commit()
conn.close()
return 'success'
except Exception as err:
conn.rollback()
conn.close()
return err
def courselist(gh):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
cur.execute("select * from course where workno =?",(gh,))
data=cur.fetchall()
conn.close()
return data
def addstud(studuuid,courseuuid,xh,name):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
try:
cur.execute("insert into student values (?,?,?,?) ",
(studuuid,courseuuid,xh,name))
conn.commit()
conn.close()
return 'success'
except Exception as err:
conn.rollback()
conn.close()
return err
def addbatch(batchuuid,courseuuid,batchname):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
try:
#1 插入 batch 数据
cur.execute("insert into batch values (?,?,?) ",
(batchuuid,courseuuid,batchname))
#2 取对应课程的学生名单
cur.execute("select * from student where courseuuid=?",(courseuuid,))
studlist=cur.fetchall()
#3 插入到 attend
for s in studlist:
attenduuid=str(uuid.uuid1())
cur.execute("insert into attend values (?,?,?,?)",
(attenduuid,batchuuid,s[0],'已到'))
#如果程序能走到这里,说明都成功了
conn.commit()
conn.close()
return 'success'
except Exception as err:
conn.rollback()
conn.close()
return err
def getattend(batchuuid):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
def modattend(attenduuid,attendance):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
attdict={'1':'已到','2':'缺勤','3':'请假',}
try:
cur.execute("update attend set attendance=? where uuid =? ",
(attdict[attendance],attenduuid))
conn.commit()
conn.close()
return 'success'
except Exception as err:
conn.rollback()
conn.close()
return err
def tj(courseuuid):
conn=sqlite3.connect("DB\dm.db")
cur=conn.cursor()
sql='''select
student.xh,
student.name,
(select count(*) from attend where attend.studuuid=student.uuid and attendance='已
到'),
(select count(*) from attend where attend.studuuid=student.uuid and attendance='缺
勤'),
(select count(*) from attend where attend.studuuid=student.uuid and attendance='请
假')
FROM
student
WHERE
student.courseuuid = ?
'''
cur.execute(sql,(courseuuid,))
data=cur.fetchall()
conn.close()
return data