python设计旅游管理系统代码
时间: 2023-10-24 13:22:50 浏览: 93
旅游信息管理系统源码&(python毕业设计完整源代码).zip
由于旅游管理系统的代码相对来说比较复杂,这里提供一个简单的代码框架,供您参考:
```python
# 导入相关的库和模块
import sqlite3
from datetime import datetime
# 定义数据库连接
conn = sqlite3.connect('travel.db')
# 定义游标对象
c = conn.cursor()
# 创建旅游景点表
c.execute('''CREATE TABLE IF NOT EXISTS sights
(id INTEGER PRIMARY KEY,
name TEXT,
location TEXT,
description TEXT,
price REAL)''')
# 创建酒店表
c.execute('''CREATE TABLE IF NOT EXISTS hotels
(id INTEGER PRIMARY KEY,
name TEXT,
location TEXT,
description TEXT,
price REAL)''')
# 创建机票表
c.execute('''CREATE TABLE IF NOT EXISTS flights
(id INTEGER PRIMARY KEY,
departure TEXT,
destination TEXT,
departure_time TEXT,
arrival_time TEXT,
price REAL)''')
# 创建订单表
c.execute('''CREATE TABLE IF NOT EXISTS orders
(id INTEGER PRIMARY KEY,
customer_name TEXT,
customer_phone TEXT,
customer_email TEXT,
sight_id INTEGER,
hotel_id INTEGER,
flight_id INTEGER,
order_date TEXT,
FOREIGN KEY(sight_id) REFERENCES sights(id),
FOREIGN KEY(hotel_id) REFERENCES hotels(id),
FOREIGN KEY(flight_id) REFERENCES flights(id))''')
# 定义函数:添加旅游景点
def add_sight(name, location, description, price):
c.execute("INSERT INTO sights (name, location, description, price) VALUES (?, ?, ?, ?)", (name, location, description, price))
conn.commit()
# 定义函数:添加酒店
def add_hotel(name, location, description, price):
c.execute("INSERT INTO hotels (name, location, description, price) VALUES (?, ?, ?, ?)", (name, location, description, price))
conn.commit()
# 定义函数:添加机票
def add_flight(departure, destination, departure_time, arrival_time, price):
c.execute("INSERT INTO flights (departure, destination, departure_time, arrival_time, price) VALUES (?, ?, ?, ?, ?)", (departure, destination, departure_time, arrival_time, price))
conn.commit()
# 定义函数:查询旅游景点
def get_sights():
c.execute("SELECT * FROM sights")
return c.fetchall()
# 定义函数:查询酒店
def get_hotels():
c.execute("SELECT * FROM hotels")
return c.fetchall()
# 定义函数:查询机票
def get_flights():
c.execute("SELECT * FROM flights")
return c.fetchall()
# 定义函数:查询订单
def get_orders():
c.execute("SELECT * FROM orders")
return c.fetchall()
# 定义函数:添加订单
def add_order(customer_name, customer_phone, customer_email, sight_id, hotel_id, flight_id):
order_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
c.execute("INSERT INTO orders (customer_name, customer_phone, customer_email, sight_id, hotel_id, flight_id, order_date) VALUES (?, ?, ?, ?, ?, ?, ?)", (customer_name, customer_phone, customer_email, sight_id, hotel_id, flight_id, order_date))
conn.commit()
# 关闭数据库连接
conn.close()
```
这是一个简单的旅游管理系统代码框架,可以根据实际需求进行修改和完善。
阅读全文