派发奖学金
发布人:shili8
发布时间:2025-02-24 16:35
阅读次数:0
**派发奖学金系统**
**概述**
本系统旨在帮助学校或机构管理奖学金的派发过程。它提供了一个简洁易用的界面,允许管理员添加学生信息、设置奖学金标准,并自动派发奖学金。
**系统功能**
1. **学生信息管理**
* 添加学生信息(姓名、学号、专业等)
* 查询学生信息2. **奖学金标准设置**
* 设置奖学金金额和条件(例如,成绩、行为等)
* 查询奖学金标准3. **自动派发奖学金**
* 根据学生信息和奖学金标准计算出是否符合条件* 自动派发奖学金给符合条件的学生**系统设计**
###1. 数据库设计我们使用 MySQL 作为数据库管理系统,创建以下表格:
sqlCREATE TABLE students ( id INT PRIMARY KEY, name VARCHAR(255), student_id INT, major VARCHAR(255) ); CREATE TABLE scholarships ( id INT PRIMARY KEY, amount DECIMAL(10,2), condition VARCHAR(255) //例如,成绩、行为等);
###2. 后端设计我们使用 Python 和 Flask 框架作为后端开发语言和框架。
from flask import Flask, request, jsonifyimport mysql.connectorapp = Flask(__name__) # 连接数据库cnx = mysql.connector.connect( user='root', password='password', host='localhost', database='scholarship_system' ) # 添加学生信息@app.route('/add_student', methods=['POST']) def add_student(): data = request.get_json() cursor = cnx.cursor() query = "INSERT INTO students (name, student_id, major) VALUES (%s, %s, %s)" cursor.execute(query, (data['name'], data['student_id'], data['major'])) cnx.commit() return jsonify({'message': 'Student added successfully'}),201# 查询学生信息@app.route('/get_student', methods=['GET']) def get_student(): student_id = request.args.get('student_id') cursor = cnx.cursor() query = "SELECT * FROM students WHERE student_id = %s" cursor.execute(query, (student_id,)) result = cursor.fetchone() return jsonify(result),200# 设置奖学金标准@app.route('/set_scholarship', methods=['POST']) def set_scholarship(): data = request.get_json() cursor = cnx.cursor() query = "INSERT INTO scholarships (amount, condition) VALUES (%s, %s)" cursor.execute(query, (data['amount'], data['condition'])) cnx.commit() return jsonify({'message': 'Scholarship set successfully'}),201# 查询奖学金标准@app.route('/get_scholarship', methods=['GET']) def get_scholarship(): scholarship_id = request.args.get('scholarship_id') cursor = cnx.cursor() query = "SELECT * FROM scholarships WHERE id = %s" cursor.execute(query, (scholarship_id,)) result = cursor.fetchone() return jsonify(result),200# 自动派发奖学金@app.route('/award_scholarship', methods=['POST']) def award_scholarship(): data = request.get_json() cursor = cnx.cursor() query = "SELECT * FROM students WHERE student_id = %s" cursor.execute(query, (data['student_id'],)) student_result = cursor.fetchone() query = "SELECT * FROM scholarships WHERE id = %s" cursor.execute(query, (data['scholarship_id'],)) scholarship_result = cursor.fetchone() if student_result and scholarship_result: # 根据学生信息和奖学金标准计算出是否符合条件 condition_met = True # 自动派发奖学金给符合条件的学生 query = "INSERT INTO awarded_scholarships (student_id, scholarship_id) VALUES (%s, %s)" cursor.execute(query, (data['student_id'], data['scholarship_id'])) cnx.commit() return jsonify({'message': 'Scholarship awarded successfully'}),201 else: return jsonify({'message': 'Student or scholarship not found'}),404if __name__ == '__main__': app.run(debug=True)
###3. 前端设计我们使用 HTML、CSS 和 JavaScript 来实现前端界面。
html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Scholarship System</title> <link rel="stylesheet" href="styles.css"> </head> <body> <h1>Scholarship System</h1> <!-- 添加学生信息 --> <form id="add-student-form"> <label for="name">Name:</label> <input type="text" id="name" name="name"> <label for="student-id">Student ID:</label> <input type="number" id="student-id" name="student_id"> <label for="major">Major:</label> <input type="text" id="major" name="major"> <button type="submit">Add Student</button> </form> <!-- 查询学生信息 --> <form id="get-student-form"> <label for="student-id">Student ID:</label> <input type="number" id="student-id" name="student_id"> <button type="submit">Get Student</button> </form> <!-- 设置奖学金标准 --> <form id="set-scholarship-form"> <label for="amount">Amount:</label> <input type="number" id="amount" name="amount"> <label for="condition">Condition:</label> <input type="text" id="condition" name="condition"> <button type="submit">Set Scholarship</button> </form> <!-- 查询奖学金标准 --> <form id="get-scholarship-form"> <label for="scholarship-id">Scholarship ID:</label> <input type="number" id="scholarship-id" name="scholarship_id"> <button type="submit">Get Scholarship</button> </form> <!-- 自动派发奖学金 --> <form id="award-scholarship-form"> <label for="student-id">Student ID:</label> <input type="number" id="student-id" name="student_id"> <label for="scholarship-id">Scholarship ID:</label> <input type="number" id="scholarship-id" name="scholarship_id"> <button type="submit">Award Scholarship</button> </form> <script src="script.js"></script> </body> </html>
javascript// 添加学生信息document.getElementById('add-student-form').addEventListener('submit', function(event) { event.preventDefault(); const name = document.getElementById('name').value; const studentId = document.getElementById('student-id').value; const major = document.getElementById('major').value; fetch('/add_student', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({name, studentId, major}) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error(error)); }); // 查询学生信息document.getElementById('get-student-form').addEventListener('submit', function(event) { event.preventDefault(); const studentId = document.getElementById('student-id').value; fetch('/get_student', { method: 'GET', headers: {'Content-Type': 'application/json'}, params: {student_id: studentId} }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error(error)); }); // 设置奖学金标准document.getElementById('set-scholarship-form').addEventListener('submit', function(event) { event.preventDefault(); const amount = document.getElementById('amount').value; const condition = document.getElementById('condition').value; fetch('/set_scholarship', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({amount, condition}) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error(error)); }); // 查询奖学金标准document.getElementById('get-scholarship-form').addEventListener('submit', function(event) { event.preventDefault(); const scholarshipId = document.getElementById('scholarship-id').value; fetch('/get_scholarship', { method: 'GET', headers: {'Content-Type': 'application/json'}, params: {scholarship_id