2301_78487058 2023-06-12 23:36 采纳率: 0%
浏览 48
已结题

做一个教学管理系统的设计与实现

教学管理系统的设计与实现 感谢各位程序员解决一下。解
决一下这个问题。

  • 写回答

3条回答 默认 最新

  • 喝茶品人生 2023-06-12 23:55
    关注

    什么要求呢,网上这种挺多,用不用web,后台数据库是什么,这些你得说明,还是没有任何要求,我从github上给你找了一个案例:
    框架用flask,数据库是自带的sqllite:

    from flask import Flask, render_template, request, redirect, url_for, flash
    import sqlite3
    
    app = Flask(__name__)
    app.secret_key = 'supersecretkey'
    
    @app.route('/')
    def index():
        return render_template('index.html')
    
    @app.route('/login', methods=['GET', 'POST'])
    def login():
        if request.method == 'POST':
            email = request.form['email']
            password = request.form['password']
            user_type = request.form['user_type']
            if user_type == 'student':
                conn = sqlite3.connect('edu.db')
                c = conn.cursor()
                c.execute('SELECT * FROM students WHERE email=? AND password=?', (email, password))
                user = c.fetchone()
                conn.close()
                if user:
                    flash('Login successful', 'success')
                    return redirect(url_for('dashboard', user_id=user[0], user_type='student'))
                else:
                    flash('Invalid email or password', 'danger')
                    return redirect(url_for('login'))
            elif user_type == 'teacher':
                conn = sqlite3.connect('edu.db')
                c = conn.cursor()
                c.execute('SELECT * FROM teachers WHERE email=? AND password=?', (email, password))
                user = c.fetchone()
                conn.close()
                if user:
                    flash('Login successful', 'success')
                    return redirect(url_for('dashboard', user_id=user[0], user_type='teacher'))
                else:
                    flash('Invalid email or password', 'danger')
                    return redirect(url_for('login'))
        else:
            return render_template('login.html')
    
    @app.route('/logout')
    def logout():
        return redirect(url_for('index'))
    
    @app.route('/dashboard/<int:user_id>/<string:user_type>')
    def dashboard(user_id, user_type):
        if user_type == 'student':
            conn = sqlite3.connect('edu.db')
            c = conn.cursor()
            c.execute('SELECT * FROM students WHERE id=?', (user_id,))
            user = c.fetchone()
            c.execute('SELECT * FROM enrollments WHERE student_id=?', (user_id,))
            enrollments = c.fetchall()
            courses = []
            for enrollment in enrollments:
                c.execute('SELECT * FROM courses WHERE id=?', (enrollment[1],))
                course = c.fetchone()
                c.execute('SELECT * FROM assignments WHERE course_id=?', (course[0],))
                assignments = c.fetchall()
                c.execute('SELECT * FROM exams WHERE course_id=?', (course[0],))
                exams = c.fetchall()
                courses.append({'id': course[0], 'name': course[1], 'description': course[2], 'assignments': assignments, 'exams': exams})
            conn.close()
            return render_template('student_dashboard.html', user=user, courses=courses)
        elif user_type == 'teacher':
            conn = sqlite3.connect('edu.db')
            c = conn.cursor()
            c.execute('SELECT * FROM teachers WHERE id=?', (user_id,))
            user = c.fetchone()
            c.execute('SELECT * FROM courses WHERE teacher_id=?', (user_id,))
            courses = c.fetchall()
            conn.close()
            return render_template('teacher_dashboard.html', user=user, courses=courses)
    
    @app.route('/course/<int:course_id>', methods=['GET', 'POST'])
    def course(course_id):
        conn = sqlite3.connect('edu.db')
        c = conn.cursor()
        c.execute('SELECT * FROM courses WHERE id=?', (course_id,))
        course = c.fetchone()
        c.execute('SELECT * FROM assignments WHERE course_id=?', (course_id,))
        assignments = c.fetchall()
        c.execute('SELECT * FROM exams WHERE course_id=?', (course_id,))
        exams = c.fetchall()
        conn.close()
        if request.method == 'POST':
            if 'assignment' in request.form:
                assignment_name = request.form['assignment_name']
                assignment_description = request.form['assignment_description']
                file = request.files['assignment_file']
                if file and allowed_file(file.filename):
                    filename = secure_filename(file.filename)
                    file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
                    conn = sqlite3.connect('edu.db')
                    c = conn.cursor()
                    c.execute('INSERT INTO assignments (name, description, course_id) VALUES (?, ?, ?)', (assignment_name, assignment_description, course_id))
                    assignment_id = c.lastrowid
                    c.execute('INSERT INTO submissions (student_id, assignment_id, file_path) VALUES (?, ?, ?)', (user_id, assignment_id, os.path.join(app.config['UPLOAD_FOLDER'], filename)))
                    conn.commit()
                    conn.close()
                    flash('Assignment submitted', 'success')
                    return redirect(url_for('course', course_id=course_id))
                else:
                    flash('Invalid file format', 'danger')
                    return redirect(url_for('course', course_id=course_id))
            elif 'exam' in request.form:
                exam_name = request.form['exam_name']
                exam_description = request.form['exam_description']
                file = request.files['exam_file']
                if file and allowed_file(file.filename):
                    filename = secure_filename(file.filename)
                    file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
                    conn = sqlite3.connect('edu.db')
                    c = conn.cursor()
                    c.execute('INSERT INTO exams (name, description, course_id) VALUES (?, ?, ?)', (exam_name, exam_description, course_id))
                    exam_id = c.lastrowid
                    c.execute('INSERT INTO submissions (student_id, exam_id, file_path) VALUES (?, ?, ?)', (user_id, exam_id, os.path.join(app.config['UPLOAD_FOLDER'], filename)))
                    conn.commit()
                    conn.close()
                    flash('Exam submitted', 'success')
                    return redirect(url_for('course', course_id=course_id))
                else:
                    flash('Invalid file format', 'danger')
                    return redirect(url_for('course', course_id=course_id))
        else:
            return render_template('course.html', course=course, assignments=assignments, exams=exams)
    
    //导模块:
    import sqlite3
    
    conn = sqlite3.connect('edu.db')
    c = conn.cursor()
    
    c.execute('CREATE TABLE students (id INTEGER PRIMARY KEY, name TEXT, email TEXT, password TEXT)')
    c.execute('CREATE TABLE teachers (id INTEGER PRIMARY KEY, name TEXT, email TEXT, password TEXT)')
    c.execute('CREATE TABLE courses (id INTEGER PRIMARY KEY, name TEXT, description TEXT, teacher_id INTEGER)')
    c.execute('CREATE TABLE enrollments (student_id INTEGER, course_id INTEGER, FOREIGN KEY (student_id) REFERENCES students (id), FOREIGN KEY (course_id) REFERENCES courses (id))')
    c.execute('CREATE TABLE assignments (id INTEGER PRIMARY KEY, name TEXT, description TEXT, course_id INTEGER)')
    c.execute('CREATE TABLE exams (id INTEGER PRIMARY KEY, name TEXT, description TEXT, course_id INTEGER)')
    c.execute('CREATE TABLE submissions (id INTEGER PRIMARY KEY, student_id INTEGER, assignment_id INTEGER, exam_id INTEGER, file_path TEXT, grade INTEGER, FOREIGN KEY (student_id) REFERENCES students (id), FOREIGN KEY (assignment_id) REFERENCES assignments (id), FOREIGN KEY (exam_id) REFERENCES exams (id))')
    
    conn.commit()
    conn.close()
    //HTML前端界面
    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="UTF-8">
      <title>{{ course.name }} - {{ user.name }}</title>
    </head>
    <body>
      <h1>{{ course.name }}</h1>
      <p>{{ course.description }}</p>
      {% if user_type == 'teacher' %}
        <h2>Assignments</h2>
        <form method="POST" enctype="multipart/form-data">
          <label for="assignment_name">Name:</label>
          <input type="text" name="assignment_name" id="assignment_name" required>
    
    
          <label for="assignment_description">Description:</label>
    
    
          <textarea name="assignment_description" id="assignment_description"></textarea>
    
    
          <label for="assignment_file">File:</label>
          <input type="file" name="assignment_file" id="assignment_file" required>
    
    
          <button type="submit" name="assignment">Submit</button>
        </form>
        <h2>Exams</h2>
        <form method="POST" enctype="multipart/form-data">
          <label for="exam_name">Name:</label>
          <input type="text" name="exam_name" id="exam_name" required>
    
    
          <label for="exam_description">Description:</label>
    
    
          <textarea name="exam_description" id="exam_description"></textarea>
    
    
          <label for="exam_file">File:</label>
          <input type="file" name="exam_file" id="exam_file" required>
    
    
          <button type="submit" name="exam">Submit</button>
        </form>
      {% else %}
        <h2>Assignments</h2>
        {% for assignment in assignments %}
          <div>
            <h3>{{ assignment[1] }}</h3>
            <p>{{ assignment[2] }}</p>
            <form method="POST" enctype="multipart/form-data">
              <label for="{{ assignment[0] }}">File:</label>
              <input type="file" name="file" id="{{ assignment[0] }}" required>
    
    
              <button type="submit">Submit</button>
            </form>
          </div>
        {% endfor %}
        <h2>Exams</h2>
        {% for exam in exams %}
          <div>
            <h3>{{ exam[1] }}</h3>
            <p>{{ exam[2] }}</p>
            <form method="POST" enctype="multipart/form-data">
              <label for="{{ exam[0] }}">File:</label>
              <input type="file" name="file" id="{{ exam[0] }}" required>
    
    
              <button type="submit">Submit</button>
            </form>
          </div>
        {% endfor %}
      {% endif %}
    </body>
    </html>
    
    
    评论 编辑记录

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 6月13日
  • 创建了问题 6月12日

悬赏问题

  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 C++行情软件的tick数据如何高效的合成K线
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。
  • ¥20 在easyX库下编写C语言扑克游戏跑的快,能实现简单的人机对战
  • ¥15 svpwm波形异常求解答