用python html MySQL.connector写一个物流运输管理系统,系统包括登录,订单管理,车辆调度,车辆跟踪,客户验收五个页面,每个页面都可以对页面中的中的内容进行修改,添加和删除的修改操作,并且显示在页面上
时间: 2023-11-12 11:08:26 浏览: 174
这是一个比较复杂的项目,需要涉及到多个技术点。以下是一个简单的实现思路:
1. 创建一个MySQL数据库,包括以下表:用户表、订单表、车辆表、车辆跟踪表、客户验收表。
2. 使用Python的MySQL.connector模块连接数据库,实现登录验证、数据的增删改查操作。
3. 使用HTML和CSS设计五个页面的布局和样式。
4. 在订单管理页面,可以显示所有的订单信息,并且可以对订单进行修改和删除操作,还可以添加新的订单。
5. 在车辆调度页面,可以显示所有可用的车辆信息,还可以对车辆进行修改和删除操作,还可以添加新的车辆。
6. 在车辆跟踪页面,可以显示当前所有车辆的位置,并且可以根据订单信息自动分配车辆。
7. 在客户验收页面,可以显示所有已完成的订单,并且可以对订单进行确认。
具体实现方式可以参考以下示例代码:
1. 创建MySQL数据库
```sql
CREATE DATABASE logistics;
USE logistics;
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(50) UNIQUE,
password VARCHAR(50)
);
CREATE TABLE orders (
id INT PRIMARY KEY AUTO_INCREMENT,
customer_name VARCHAR(50),
address VARCHAR(100),
phone VARCHAR(20),
goods_type VARCHAR(50),
weight FLOAT,
status VARCHAR(20)
);
CREATE TABLE vehicles (
id INT PRIMARY KEY AUTO_INCREMENT,
plate_number VARCHAR(20) UNIQUE,
type VARCHAR(50),
capacity FLOAT,
status VARCHAR(20)
);
CREATE TABLE tracks (
id INT PRIMARY KEY AUTO_INCREMENT,
order_id INT,
vehicle_id INT,
current_location VARCHAR(100),
status VARCHAR(20)
);
CREATE TABLE accepts (
id INT PRIMARY KEY AUTO_INCREMENT,
order_id INT,
accepted_at DATETIME
);
```
2. Python连接MySQL数据库
```python
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword",
database="logistics"
)
mycursor = mydb.cursor()
```
3. HTML页面布局和样式
```html
<!DOCTYPE html>
<html>
<head>
<title>登录</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
<h1>物流运输管理系统</h1>
<form method="post" action="login.py">
<label for="username">用户名:</label>
<input type="text" id="username" name="username" required>
<label for="password">密码:</label>
<input type="password" id="password" name="password" required>
<input type="submit" value="登录">
</form>
</div>
</body>
</html>
```
4. Python实现登录验证
```python
from flask import Flask, render_template, request, redirect, session
app = Flask(__name__)
app.secret_key = "your_secret_key"
@app.route("/")
def login():
if "user_id" in session:
return redirect("/orders")
else:
return render_template("login.html")
@app.route("/login", methods=["POST"])
def do_login():
username = request.form["username"]
password = request.form["password"]
mycursor.execute("SELECT * FROM users WHERE username = %s AND password = %s", (username, password))
user = mycursor.fetchone()
if user:
session["user_id"] = user[0]
session["username"] = user[1]
return redirect("/orders")
else:
return redirect("/")
@app.route("/logout")
def logout():
session.pop("user_id", None)
session.pop("username", None)
return redirect("/")
```
5. 实现订单管理页面
```python
@app.route("/orders")
def orders():
if "user_id" not in session:
return redirect("/")
mycursor.execute("SELECT * FROM orders")
orders = mycursor.fetchall()
return render_template("orders.html", orders=orders)
@app.route("/add_order", methods=["POST"])
def add_order():
customer_name = request.form["customer_name"]
address = request.form["address"]
phone = request.form["phone"]
goods_type = request.form["goods_type"]
weight = request.form["weight"]
status = "待处理"
mycursor.execute("INSERT INTO orders (customer_name, address, phone, goods_type, weight, status) VALUES (%s, %s, %s, %s, %s, %s)", (customer_name, address, phone, goods_type, weight, status))
mydb.commit()
return redirect("/orders")
@app.route("/edit_order/<int:id>", methods=["POST"])
def edit_order(id):
customer_name = request.form["customer_name"]
address = request.form["address"]
phone = request.form["phone"]
goods_type = request.form["goods_type"]
weight = request.form["weight"]
status = request.form["status"]
mycursor.execute("UPDATE orders SET customer_name = %s, address = %s, phone = %s, goods_type = %s, weight = %s, status = %s WHERE id = %s", (customer_name, address, phone, goods_type, weight, status, id))
mydb.commit()
return redirect("/orders")
@app.route("/delete_order/<int:id>")
def delete_order(id):
mycursor.execute("DELETE FROM orders WHERE id = %s", (id,))
mydb.commit()
return redirect("/orders")
```
6. 实现车辆调度页面
```python
@app.route("/vehicles")
def vehicles():
if "user_id" not in session:
return redirect("/")
mycursor.execute("SELECT * FROM vehicles")
vehicles = mycursor.fetchall()
return render_template("vehicles.html", vehicles=vehicles)
@app.route("/add_vehicle", methods=["POST"])
def add_vehicle():
plate_number = request.form["plate_number"]
type = request.form["type"]
capacity = request.form["capacity"]
status = "空闲"
mycursor.execute("INSERT INTO vehicles (plate_number, type, capacity, status) VALUES (%s, %s, %s, %s)", (plate_number, type, capacity, status))
mydb.commit()
return redirect("/vehicles")
@app.route("/edit_vehicle/<int:id>", methods=["POST"])
def edit_vehicle(id):
plate_number = request.form["plate_number"]
type = request.form["type"]
capacity = request.form["capacity"]
status = request.form["status"]
mycursor.execute("UPDATE vehicles SET plate_number = %s, type = %s, capacity = %s, status = %s WHERE id = %s", (plate_number, type, capacity, status, id))
mydb.commit()
return redirect("/vehicles")
@app.route("/delete_vehicle/<int:id>")
def delete_vehicle(id):
mycursor.execute("DELETE FROM vehicles WHERE id = %s", (id,))
mydb.commit()
return redirect("/vehicles")
```
7. 实现车辆跟踪和客户验收页面
```python
@app.route("/tracks")
def tracks():
if "user_id" not in session:
return redirect("/")
mycursor.execute("SELECT tracks.id, orders.customer_name, vehicles.plate_number, tracks.current_location, tracks.status FROM tracks JOIN orders ON tracks.order_id = orders.id JOIN vehicles ON tracks.vehicle_id = vehicles.id")
tracks = mycursor.fetchall()
return render_template("tracks.html", tracks=tracks)
@app.route("/accepts")
def accepts():
if "user_id" not in session:
return redirect("/")
mycursor.execute("SELECT orders.id, orders.customer_name, orders.address, orders.phone, accepts.accepted_at FROM accepts JOIN orders ON accepts.order_id = orders.id")
accepts = mycursor.fetchall()
return render_template("accepts.html", accepts=accepts)
@app.route("/accept_order/<int:id>")
def accept_order(id):
mycursor.execute("INSERT INTO accepts (order_id, accepted_at) VALUES (%s, NOW())", (id,))
mycursor.execute("UPDATE orders SET status = '已完成' WHERE id = %s", (id,))
mydb.commit()
return redirect("/accepts")
```
以上就是一个简单的物流运输管理系统的实现思路,具体实现过程中还需要处理一些细节问题。
阅读全文