def apply_leave(student_id, start_time, end_time, reason):
try:
# 连接数据库
connection = mysql.connector.connect(
host="localhost",
user="root",
password="password",
database="student_system"
)
cursor = connection.cursor()
# 插入请假记录
sql = "INSERT INTO leave_requests (student_id, start_time, end_time, reason) VALUES (%s, %s, %s, %s)"
val = (student_id, start_time, end_time, reason)
cursor.execute(sql, val)
connection.commit()
return "请假申请已提交"
except Exception as e:
return f"Error: {str(e)}"
finally:
if connection.is_connected():
cursor.close()
connection.close()
]]>
def approve_leave(leave_id, status):
try:
connection = mysql.connector.connect(
host="localhost",
user="root",
password="password",
database="student_system"
)
cursor = connection.cursor()
sql = "UPDATE leave_requests SET status=%s WHERE id=%s"
val = (status, leave_id)
cursor.execute(sql, val)
connection.commit()
return "审批完成"
except Exception as e:
return f"Error: {str(e)}"
finally:
if connection.is_connected():
cursor.close()
connection.close()
]]>
本站部分内容及素材来源于互联网,由AI智能生成,如有侵权或言论不当,联系必删!