diff --git a/Untitled-1.txt b/Untitled-1.txt new file mode 100644 index 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/Untitled-1.txt @@ -0,0 +1 @@ + diff --git a/eShop.py b/eShop.py index 2192de57146229b0be261bcf8a9039eb9228b8bc..4897e634713839951e57e0b2c3d4e17ea628af21 100644 --- a/eShop.py +++ b/eShop.py @@ -1,26 +1,42 @@ -from flask import Flask, render_template +from flask import Flask, render_template, request, redirect, url_for +import sqlite3 +import uuid app = Flask(__name__) -technologies = [ - { "name": "AK-47", - "price": "£120", - "description": "Russian manufactured rifle with a high fire rate and penetration. This absolute classic is popular amongst our regular customers and we are sure that you will fall in love with it too. 30 rounds per magazine and strong recoil. On the noisy side.", - "image_filename": "ak47.png", - "volume": "140dB"}, - - { "name": "M4A4", - "price": "£100", - "description": "Accurate rifle with a 70mm barrel and a telescoping stock", - "image_filename": "m4a4.png", - "volume": "130dB"}, +connect = sqlite3.connect("eShop_database.db") +cursor = connect.cursor() + +cursor.execute('''DROP TABLE Basket''') +try: + cursor.execute('''CREATE TABLE Items (id integer, name text, price text, description text, image_filename text, volume text)''') + cursor.execute('''INSERT INTO Items (id, name, price, description, image_filename, volume) VALUES (0, 'AK47', '£125', 'Russian manufactured rifle with a high fire rate and penetration. This absolute classic is popular amongst our regular customers and we are sure that you will fall in love with it too. 30 rounds per magazine and strong recoil. On the noisy side.', 'ak47.png', '140dB')''') + cursor.execute('''INSERT INTO Items (id, name, price, description, image_filename, volume) VALUES (1, 'M4A4', '£110', 'Accurate rifle with a 70mm barrel and a telescoping stock.', 'm4a4.png', '130dB')''') + cursor.execute('''INSERT INTO Items (id, name, price, description, image_filename, volume) VALUES (2, 'M4A1S', '£150', 'M4A4 silenced counterpart with less recoil but smaller magazine size.', 'm4a1s.png', '100dB')''') + cursor.execute('''INSERT INTO Items (id, name, price, description, image_filename, volume) VALUES (3, 'SSG08', '£220', 'Lightweight sniper rifle with high accuracy and low recoil. 10 rounds per magazine', 'ssg08.png', '140dB')''') +except: pass +try: + cursor.execute('''CREATE TABLE Basket (id text, AK47 integer, M4A4 integer, M4A1S integer, SSG08 integer)''') + connect.commit() +except: pass +global customerID +customerID = str(uuid.uuid4()) +cursor.execute('INSERT INTO Basket (id, AK47, M4A4, M4A1S, SSG08) VALUES (?, 0, 0, 0, 0)', (customerID,)) +connect.commit() + +cursor.execute('''SELECT name, price, description, image_filename, volume FROM Items''') +rows = cursor.fetchall() +technologies = [] +for row in rows: + current_technology = { + "name": row[0], + "price": row[1], + "description": row[2], + "image_filename": row[3], + "volume": row[4] + } + technologies.append(current_technology) - { "name": "M4A1-S", - "price": "£120", - "description": "M4A4 silenced counterpart with less recoil but smaller magazine size", - "image_filename": "m4a1s.png", - "volume": "100dB"} -] @app.route('/', methods=["GET", "POST"]) def galleryPage(): @@ -30,5 +46,32 @@ def galleryPage(): def singleProductPage(techId): return render_template("SingleTech.html", technology = technologies[techId]) +@app.route('/basketPage') +def basketPage(): + connect = sqlite3.connect("eShop_database.db") + cursor = connect.cursor() + cursor.execute(f'SELECT * FROM Basket WHERE id = ?', (customerID,)) + row = cursor.fetchone() + quantities = { + 'AK-47': row[1], + 'M4A4': row[2], + 'M4A1-S': row[3], + 'SSG 08': row[4] + } + return render_template("Basket.html", quantities=quantities) + +@app.route('/update_basket', methods=['POST']) +def update_basket(): + connect = sqlite3.connect("eShop_database.db") + cursor = connect.cursor() + quantity = int(request.form.get("quantity")) + itemName = request.form.get("itemName") + cursor.execute(f'SELECT {itemName} FROM Basket WHERE id = ?', (customerID,)) + current_quantity = cursor.fetchone()[0] + new_quantity = current_quantity + quantity + cursor.execute(f'UPDATE Basket SET "{itemName}" = ? WHERE id = ?', (new_quantity, customerID)) + connect.commit() + return redirect(url_for('galleryPage')) + if __name__ == '__main__': app.run(debug=True) diff --git a/static/css/stylesheet1.css b/static/css/stylesheet1.css index d150ffd2e68f524f15f811be166ba31ca5343236..0eaa1ed208e79fb0ccb6740c9653e7c11964c79d 100644 --- a/static/css/stylesheet1.css +++ b/static/css/stylesheet1.css @@ -45,4 +45,20 @@ ul img { border-radius: 5px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); margin-bottom: 10px; +} + +.basket-button { + padding: 10px 20px; /* Adjust padding to change button size */ + font-size: 16px; /* Adjust font size */ + background-color: #4CAF50; /* Green background */ + color: white; /* White text color */ + border: none; /* Remove border */ + border-radius: 5px; /* Rounded corners */ + cursor: pointer; /* Change cursor to pointer on hover */ + text-decoration: none; /* Remove underline */ + transition: background-color 0.3s; /* Smooth transition on hover */ +} + +.basket-button:hover { + background-color: #45a049; /* Darker green on hover */ } \ No newline at end of file diff --git a/static/css/stylesheet3.css b/static/css/stylesheet3.css new file mode 100644 index 0000000000000000000000000000000000000000..6b988c5aecf650b166c5d287d4646affdf3d5ba9 --- /dev/null +++ b/static/css/stylesheet3.css @@ -0,0 +1,36 @@ +body { + font-family: Arial, sans-serif; + background-color: #f0f0f0; + margin: 0; + padding: 20px; +} + +h1 { + text-align: center; + color: #333; + margin-bottom: 20px; +} + +ul { + list-style-type: none; + padding: 0; +} + +li { + margin-bottom: 10px; +} + +.item { + display: flex; + align-items: center; +} + +.item img { + width: 100px; /* Adjust image size */ + height: auto; + margin-right: 10px; +} + +.quantity { + font-weight: bold; +} \ No newline at end of file diff --git a/static/ssg08.png b/static/ssg08.png new file mode 100644 index 0000000000000000000000000000000000000000..e949ae3498c827c34db421dc41c1ec94fdb268e5 Binary files /dev/null and b/static/ssg08.png differ diff --git a/templates/Basket.html b/templates/Basket.html new file mode 100644 index 0000000000000000000000000000000000000000..cb694b0d570d0092aedf5eea03dea102b5bfc19f --- /dev/null +++ b/templates/Basket.html @@ -0,0 +1,31 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="UTF-8"> + <title>Shopping Basket</title> + <link rel="stylesheet" href="{{ url_for('static', filename='css/stylesheet3.css') }}"> + <script> + function back() { + window.history.back(); + } + </script> +</head> +<body> + <h1>Shopping Basket</h1> + <button onclick="back()">BACK</button> + <div class="basket-items"> + <div class="basket-item"> + <p>AK-47: {{ quantities.get('AK-47', 0) }}</p> + </div> + <div class="basket-item"> + <p>M4A4: {{ quantities.get('M4A4', 0) }}</p> + </div> + <div class="basket-item"> + <p>M4A1-S: {{ quantities.get('M4A1-S', 0) }}</p> + </div> + <div class="basket-item"> + <p>SSG 08: {{ quantities.get('SSG 08', 0) }}</p> + </div> + </div> +</body> +</html> \ No newline at end of file diff --git a/templates/SingleTech.html b/templates/SingleTech.html index 91ccac07c2ebe82d7b1cb7dedd612f1b591398ec..8465bd0b8f6a13cf528ab9afacd62df99a78757d 100644 --- a/templates/SingleTech.html +++ b/templates/SingleTech.html @@ -16,16 +16,22 @@ } return true; } + + function back() { + window.history.back(); + } </script> </head> <body> <h1>{{ technology.name }}</h1> <p><b>{{technology.price + " | " }}{{technology.volume}}</b></p> <p>{{ technology.description }}</p> - <form action="/" method="POST" onsubmit="return testInput()"> + <form action="/update_basket" method="POST" onsubmit="return testInput()"> + <input type="hidden" name="itemName" value="{{ technology.name }}"> <label for="quantity">QUANTITY:</label> - <input type="text" id="quantity" name="quantity" size="2" required> - <input type="submit" value="Add To Basket"> + <input type="text" id="quantity" name="quantity" size="1" required> + <input type="submit" value="ADD TO BASKET"> + <button onclick="back()">BACK</button> </form> <img src="{{ url_for("static", filename=technology.image_filename) }}" alt="{{ technology.name }}"> </body> diff --git a/templates/index.html b/templates/index.html index 257a16ecaf5e8a990923a16fd1c48af86e854ed4..8031d18dbee852453a3176a2363e0f4f1573e82b 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,6 +7,7 @@ </head> <body> <h1>THE COUNTER STRIKE ARMS SHOP</h1> + <a href="{{ url_for("basketPage") }}" size=30 class="basket-button">Go to Basket</a> <ul> {% for tech in technologies %} <a href="{{ url_for("singleProductPage", techId=loop.index0) }}">{{ tech.name+" ["+tech.price+"] "+" ["+tech.volume+"]" }}