写一个phython的网吧管理系统
时间: 2024-02-29 20:53:24 浏览: 67
一款洒吧管理系统(前后台_源码+DB,一应具全)
好的,我可以帮你提供一个简单的网吧管理系统的代码,基于sqlite数据库,使用Python编写。以下是代码:
```python
import sqlite3
def create_table():
conn = sqlite3.connect('cybercafe.db')
c = conn.cursor()
c.execute('''CREATE TABLE IF NOT EXISTS customers
(id INTEGER PRIMARY KEY, name TEXT, age INTEGER, gender TEXT, balance INTEGER)''')
c.execute('''CREATE TABLE IF NOT EXISTS computers
(id INTEGER PRIMARY KEY, brand TEXT, model TEXT, status TEXT)''')
conn.commit()
conn.close()
def add_customer(name, age, gender, balance):
conn = sqlite3.connect('cybercafe.db')
c = conn.cursor()
c.execute('''INSERT INTO customers(name, age, gender, balance)
VALUES (?, ?, ?, ?)''', (name, age, gender, balance))
conn.commit()
conn.close()
def get_customers():
conn = sqlite3.connect('cybercafe.db')
c = conn.cursor()
c.execute('''SELECT * FROM customers''')
customers = c.fetchall()
conn.close()
return customers
def delete_customer(customer_id):
conn = sqlite3.connect('cybercafe.db')
c = conn.cursor()
c.execute('''DELETE FROM customers WHERE id=?''', (customer_id,))
conn.commit()
conn.close()
def add_computer(brand, model, status):
conn = sqlite3.connect('cybercafe.db')
c = conn.cursor()
c.execute('''INSERT INTO computers(brand, model, status)
VALUES (?, ?, ?)''', (brand, model, status))
conn.commit()
conn.close()
def get_computers():
conn = sqlite3.connect('cybercafe.db')
c = conn.cursor()
c.execute('''SELECT * FROM computers''')
computers = c.fetchall()
conn.close()
return computers
def delete_computer(computer_id):
conn = sqlite3.connect('cybercafe.db')
c = conn.cursor()
c.execute('''DELETE FROM computers WHERE id=?''', (computer_id,))
conn.commit()
conn.close()
if __name__ == '__main__':
create_table()
阅读全文