TKinter_GUI_intro/admin_partes_app/db.py

43 lines
1.6 KiB
Python
Raw Normal View History

2021-01-04 23:11:00 -03:00
import sqlite3
class Database:
def __init__(self, db):
self.conn = sqlite3.connect(db)
self.cur = self.conn.cursor()
self.cur.execute("CREATE TABLE IF NOT EXISTS parts (id INTEGER PRIMARY KEY, part text, cliente text, proveedor text, precio text)")
self.conn.commit()
def fetch(self):
self.cur.execute("SELECT * FROM parts")
rows = self.cur.fetchall()
return rows
def insert(self, parte, cliente, proveedor, precio):
self.cur.execute("INSERT INTO parts VALUES (NULL, ?, ?, ?, ?)", (parte, cliente, proveedor, precio))
self.conn.commit()
def remove(self, id):
self.cur.execute("DELETE FROM parts WHERE id=?", (id,))
self.conn.commit()
def update(self, id, parte, cliente, proveedor, precio):
self.cur.execute("UPDATE parts SET part =?, cliente=?,proveedor=?,precio=? WHERE id=?", (parte, cliente, proveedor, precio, id))
self.conn.commit()
def __del__(self):
self.conn.close()
db = Database('store.db')
# Descomentar parar agragar partes a base de datos
"""
db.insert("KL-xram 4GB DDR4 Ram","Piero Juarez","MicroCentro","3500")
db.insert("MacroShifter 4","Ruperto Esaus","FlyTech","1600")
db.insert("Verboson 16","Piero Juarez","FlyTech","3400")
db.insert("L socket 12","Genaro Riquelme","MicroHard","300")
db.insert("Lumm 5 en 1 Dongle","Ruperto Esaus","FlyTech","4500")
db.insert("24in generic IPS","Ruperto Esaus","FlyTech","9900")
db.insert("Nvidia XTX 666000","Genaro Riquelme","ManoCentro","500")
db.insert("SSD Plasticoso","Piero Juarez","MicroHard","1500")
"""