文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

深大数据库系统实验4——Using mysql and php to implement the Car Share Reservation Database system

2023-09-04 07:48

关注

目录

一、前言

二、实验代码

1、 app.py

2、__init__.py

3、logicOperation.py

4、font-awesome.min.css

5、swiper-bundle.min.css 和 swiper-bundle.min.js

6、jquery.js

7、img

8、list.html

9、NOFP.html

10、shouye.html

11、config.py

12、exts.py

三、部分界面展示


一、前言

实验四有6个题可以选(如下图所示),吕同学懒得全看了,反正题目难度听老师说都差不多,我就直接做第一题了。

主要是要做前三个问题,第一问“Building the database"本博客不涉及,第二问“MySQL Implementation”本博客也不涉及,主要放上第三问的代码并进行简单的说明。

 上图为翻译版实验要求。

二、实验代码

上图为代码结构。

1、 app.py

from flask import Flaskfrom blueprint import lpbpapp = Flask(__name__)app.register_blueprint(lpbp)if __name__ == '__main__':    app.run()

2、__init__.py

from .logicOperation import bp as lpbp

3、logicOperation.py

from flask import Blueprint,request,render_templatefrom exts import db,cursorbp=Blueprint("",__name__,url_prefix="/")@bp.route('/customer_on_probation')def CoP():    global results    sql = "call CUSTOMER_ON_PROBATION"    labels = ["LASTNAME", "FIRSTNAME", "EMAIL"]    try:        cursor.execute(sql)        db.commit()        results = cursor.fetchall()    except:        db.rollback()    print(results)    return render_template('list.html', labels=labels, content=results, title ="Cop", form_title="Customers on Probation")@bp.route('/number_of_passengers',methods=['GET','POST'])def NoP():    global results    if request.method=="POST":        sql = "call NUMBER_OF_PASSENGERS(" + str(request.form['input_num']) + ")"        labels = ["Car ID", "Make", "Model", "Price Per Hour","Number of Passengers"]        try:            cursor.execute(sql)            db.commit()            results = cursor.fetchall()            temp = []            for i in range(len(results)):                temp.append(list(results[i]))                temp[i][3] = "$" + temp[i][3]            results = temp        except:            db.rollback()        if(results):            return render_template('list.html', labels=labels, content=results, title="RT",form_title="Number of Passengers")    return render_template('list.html',form_title="Number of Passengers")@bp.route('/popular_locations')def PL():    global results    sql = "call POPULAR_LOCATIONS"    labels = ["Location ID", "Street Address", "Telephone","Number of Rentals"]    try:        cursor.execute(sql)        db.commit()        results = cursor.fetchall()    except:        db.rollback()    print(results)    return render_template('list.html', labels=labels, content=results, title="PL",form_title="Popular Locations")@bp.route('/rental_trends')def RT():    global results    sql = "call RENTAL_TRENDS"    labels = ["Make", "Model", "Student?","Number of Times Rented"]    try:        cursor.execute(sql)        db.commit()        results = cursor.fetchall()        ans = []        for i in range(len(results)):            ans.append(list(results[i]))            if ans[i][2]==1:                ans[i][2] = "YES"            else:                ans[i][2] = "NO"        results = ans    except:        db.rollback()    print(results)    return render_template('list.html', labels=labels, content=results, title="RT",form_title="Rental Trends")@bp.route('/update_price',methods=['GET','POST'])def UP():    if request.method == "POST":        # print("1")        # print("2")        pph_update = 0.5        ppd_update = 5        sql1 = "update car set pph = pph + " + str(pph_update)        sql2 = "update car set ppd = ppd + " + str(ppd_update)        cursor.execute(sql1)        db.commit()        cursor.execute(sql2)        db.commit()    sql = "select * from car"    labels = ["ID","MAKE","MODEL","PASSENGERS","DESCRIPTION","PPH","PPD"]    cursor.execute(sql)    db.commit()    results = cursor.fetchall()    return render_template('list.html', labels=labels, content=results, title="UP",form_title="Current Car Information")@bp.route('/update_price_history')def UPH():    sql = "select * from price_log"    cursor.execute(sql)    db.commit()    labels = ["Change ID","Car ID","Price per hour change","Price per day change","Update time"]    results = cursor.fetchall()    return render_template('list.html', labels=labels, content=results, title="UP",form_title="Update Price")@bp.route('/')@bp.route('/index')def yewu():    return render_template("shouye.html")@bp.route('/add_price',methods=['GET','POST'])def addPrice2():    if request.method == "POST":        # print("1")        # print("2")        pph_update = 0.5        ppd_update = 5        sql1 = "update car set pph = pph + " + str(pph_update)        sql2 = "update car set ppd = ppd + " + str(ppd_update)        # print(sql1)        # print(sql2)        cursor.execute(sql1)        # print("3")        db.commit()        cursor.execute(sql2)        db.commit()    sql = "select * from car"    labels = ["ID","MAKE","MODEL","PASSENGERS","DESCRIPTION","PPH","PPD"]    cursor.execute(sql)    db.commit()    # "INSERT INTO `price_log`(`ID`, `CAR_ID`, `PPH_CHANGE`, `PPD_CHANGE`, `UPDATE_TIME`) VALUES ('1','','[value-3]','[value-4]','[value-5]')"    results = cursor.fetchall()    return render_template('list.html', labels=labels, content=results, title="add_price",form_title="Current Car Information")

4、font-awesome.min.css

Download Font Awesome Free or Pro | Font Awesome

5、swiper-bundle.min.css 和 swiper-bundle.min.js

下载Swiper - Swiper中文网

6、jquery.js

Download jQuery | jQuery

7、img

自己随便下载几张图片

8、list.html

                        Car share reservation