diff --git a/Project/Manager/func/__pycache__/config.cpython-311.pyc b/Project/Manager/func/__pycache__/config.cpython-311.pyc index d7c779a..f474287 100644 Binary files a/Project/Manager/func/__pycache__/config.cpython-311.pyc and b/Project/Manager/func/__pycache__/config.cpython-311.pyc differ diff --git a/Project/Manager/func/__pycache__/index.cpython-311.pyc b/Project/Manager/func/__pycache__/index.cpython-311.pyc index acbb2fb..8904051 100644 Binary files a/Project/Manager/func/__pycache__/index.cpython-311.pyc and b/Project/Manager/func/__pycache__/index.cpython-311.pyc differ diff --git a/Project/Manager/func/__pycache__/login.cpython-311.pyc b/Project/Manager/func/__pycache__/login.cpython-311.pyc index 0487ae4..a5542eb 100644 Binary files a/Project/Manager/func/__pycache__/login.cpython-311.pyc and b/Project/Manager/func/__pycache__/login.cpython-311.pyc differ diff --git a/Project/Manager/func/config.py b/Project/Manager/func/config.py index 852dc20..4ac7b14 100644 --- a/Project/Manager/func/config.py +++ b/Project/Manager/func/config.py @@ -1,9 +1,16 @@ -db = { +db_service = { 'host':'localhost', 'user':'managerAgent', 'password':'password123', 'database':'ServiceDatabase' } +db_manager = { + 'host':'localhost', + 'user':'managerAgent', + 'password':'password123', + 'database':'ManagerDatabase' +} + SECRET_KEY = 'ILOVEDATABASETECH' diff --git a/Project/Manager/func/index.py b/Project/Manager/func/index.py index 3a7fb44..12f7877 100644 --- a/Project/Manager/func/index.py +++ b/Project/Manager/func/index.py @@ -1,5 +1,5 @@ from flask import render_template, request, g, redirect, url_for, session, jsonify -from .config import db +from .config import db_service import pymysql import csv import io @@ -11,7 +11,7 @@ def index(): flightID = request.args.get('flightID') if flightID: - conn = pymysql.connect(**db) + conn = pymysql.connect(**db_service) cursor = conn.cursor(pymysql.cursors.DictCursor) search_sql = """SELECT * FROM Flights WHERE ID = %s""" @@ -41,7 +41,7 @@ def modify(): status = request.form.get('status', '未知') - conn = pymysql.connect(**db) + conn = pymysql.connect(**db_service) cursor = conn.cursor(pymysql.cursors.DictCursor) try: @@ -55,7 +55,8 @@ def modify(): # 检查余座数是否为负值 if new_first_class_seats < 0 or new_business_class_seats < 0 or new_economy_class_seats < 0: - return jsonify({'message': '座位变化后余座数不能为负值'}), 400 + flash('座位变化后余座数不能为负值', 'error') + return redirect(url_for('index')) # 更新座位数和价格 update_sql = """ @@ -67,22 +68,23 @@ def modify(): cursor.execute(update_sql, (new_first_class_seats, new_business_class_seats, new_economy_class_seats, first_class_price, business_class_price, economy_class_price, status, flight_id)) conn.commit() + flash('座位数、价格和状态更新成功', 'success') except Exception as e: print(e) conn.rollback() - return jsonify({'message': '数据库错误,请稍后再试'}), 500 + flash(f'数据库错误:{e}', 'error') finally: cursor.close() conn.close() - return jsonify({'message': '座位数、价格和状态更新成功'}), 200 + return redirect(url_for('index')) def delete_flight(): if request.method == 'DELETE': flight_id = request.args.get('flightID') - conn = pymysql.connect(**db) + conn = pymysql.connect(**db_service) cursor = conn.cursor() try: @@ -103,7 +105,7 @@ from flask import flash, redirect, url_for, jsonify, request import pymysql import csv import io -from .config import db +from .config import db_service def upload_csv(): if request.method == 'POST': @@ -112,7 +114,7 @@ def upload_csv(): flash('没有文件上传', 'error') return redirect(url_for('index')) - conn = pymysql.connect(**db) + conn = pymysql.connect(**db_service) cursor = conn.cursor() try: diff --git a/Project/Manager/func/login.py b/Project/Manager/func/login.py index c5936a5..e3f6507 100644 --- a/Project/Manager/func/login.py +++ b/Project/Manager/func/login.py @@ -1,10 +1,10 @@ from flask import request, jsonify, session, url_for, render_template, redirect -from .config import db +from .config import db_manager import pymysql def connect(managerID, encrypted_password): - conn = pymysql.connect(**db) + conn = pymysql.connect(**db_manager) cursor = conn.cursor(pymysql.cursors.DictCursor) args = (managerID, encrypted_password) verify_sql = "SELECT COUNT(*) FROM Managers WHERE ID = %s AND `Password` = %s;" diff --git a/Project/Service/func/__pycache__/book.cpython-311.pyc b/Project/Service/func/__pycache__/book.cpython-311.pyc index 076970f..e0746ab 100644 Binary files a/Project/Service/func/__pycache__/book.cpython-311.pyc and b/Project/Service/func/__pycache__/book.cpython-311.pyc differ diff --git a/Project/Service/func/__pycache__/modify.cpython-311.pyc b/Project/Service/func/__pycache__/modify.cpython-311.pyc index 5e22dc5..0e5ded8 100644 Binary files a/Project/Service/func/__pycache__/modify.cpython-311.pyc and b/Project/Service/func/__pycache__/modify.cpython-311.pyc differ diff --git a/Project/Service/func/__pycache__/order.cpython-311.pyc b/Project/Service/func/__pycache__/order.cpython-311.pyc index 5481e78..71a6408 100644 Binary files a/Project/Service/func/__pycache__/order.cpython-311.pyc and b/Project/Service/func/__pycache__/order.cpython-311.pyc differ diff --git a/Project/Service/func/__pycache__/search.cpython-311.pyc b/Project/Service/func/__pycache__/search.cpython-311.pyc index c70dc8f..66bf51b 100644 Binary files a/Project/Service/func/__pycache__/search.cpython-311.pyc and b/Project/Service/func/__pycache__/search.cpython-311.pyc differ diff --git a/Project/Service/func/book.py b/Project/Service/func/book.py index ca0adca..6252349 100644 --- a/Project/Service/func/book.py +++ b/Project/Service/func/book.py @@ -35,6 +35,10 @@ def book(): passenger[key] = request.form.get(f'passengers[{i}][{key}]') passengers.append(passenger) + if not passengers: + flash("请至少添加一位乘客", "error") + return redirect(url_for('index')) + conn = pymysql.connect(**db) cursor = conn.cursor() @@ -85,7 +89,7 @@ def book(): conn.rollback() print(e) flash("订票失败", "error") - return redirect(url_for('search')) + return redirect(url_for('index')) finally: cursor.close() diff --git a/Project/Service/func/modify.py b/Project/Service/func/modify.py index 51771b0..078e16f 100644 --- a/Project/Service/func/modify.py +++ b/Project/Service/func/modify.py @@ -12,7 +12,7 @@ def verify_user(cursor: Cursor, phone_number: str, password: str) -> str: record = cursor.fetchone() if not record: return "NO_USER" - if record[0] != password: + if record['Password'] != password: return "WRONG_PASSWORD" return "USER_VERIFIED" diff --git a/Project/Service/func/order.py b/Project/Service/func/order.py index 25bdd2d..7c6aeae 100644 --- a/Project/Service/func/order.py +++ b/Project/Service/func/order.py @@ -38,6 +38,14 @@ def order(): """ cursor.execute(tickets_sql, (order_id,)) tickets = cursor.fetchall() + + seatClass2Chinses = { + 'First Class': '头等舱', + 'Business Class': '商务舱', + 'Economy Class': '经济舱' + } + for ticket in tickets: + ticket['Seat_class'] = seatClass2Chinses[ticket['Seat_class']] cursor.close() conn.close() diff --git a/Project/Service/func/search.py b/Project/Service/func/search.py index ab35941..ff95d33 100644 --- a/Project/Service/func/search.py +++ b/Project/Service/func/search.py @@ -1,4 +1,4 @@ -from flask import render_template, request, g, abort, redirect, url_for +from flask import render_template, request, g, abort, redirect, url_for, flash from .config import db from .utils import get_cities import pymysql @@ -13,6 +13,10 @@ def search(): departure_date = request.args.get('departure-date') passengers = int(request.args.get('passengers', 1)) + if not departure_city or not destination_city or not departure_date or not passengers: + flash("请填写所有查询条件", "error") + return render_template('search.html', cities=get_cities(), flights=[], username=g.name) + # Date validation try: departure_date_obj = datetime.datetime.strptime(departure_date, '%Y-%m-%d').date() diff --git a/Project/Service/templates/index.html b/Project/Service/templates/index.html index e82183d..366080f 100644 --- a/Project/Service/templates/index.html +++ b/Project/Service/templates/index.html @@ -7,6 +7,19 @@ +