iis服务器助手广告
返回顶部
首页 > 资讯 > 数据库 >深大数据库系统实验4——Using mysql and php to implement the Car Share Reservation Database system
  • 635
分享到

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

数据库mysqlpythonflaskphp 2023-09-04 07:09:50 635人浏览 安东尼
摘要

目录 一、前言 二、实验代码 1、 app.py 2、__init__.py 3、logicOperation.py 4、font-awesome.min.css 5、swiper-bundle.min.css 和 swiper-bundl

目录

一、前言

二、实验代码

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    
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作