Upload files to ''

This commit is contained in:
Samer Haiatleh 2021-01-03 20:40:27 +01:00
parent b96a9a2ae3
commit 87ad4578c6
5 changed files with 186 additions and 0 deletions

BIN
add_position.cpython-37.pyc Normal file

Binary file not shown.

BIN
add_position.cpython-38.pyc Normal file

Binary file not shown.

51
add_position.py Normal file
View File

@ -0,0 +1,51 @@
from tkinter import *
from database import DatabaseMain
def add_posit():
brand_to_parse = StringVar()
model_to_parse = StringVar()
cpu_to_parse = StringVar()
ram_to_parse = StringVar()
add_pos = Toplevel()
add_pos.title('Nowa pozycja')
lab1 = Label(add_pos, text='Brand:')
lab1.grid(row=0, column=0)
f_brand = Entry(add_pos, textvariable=brand_to_parse, width=30)
f_brand.grid(row=0, column=1)
lab2 = Label(add_pos, text='Model:')
lab2.grid(row=1, column=0)
f_model = Entry(add_pos, textvariable=model_to_parse, width=30)
f_model.grid(row=1, column=1)
lab3 = Label(add_pos, text='CPU:')
lab3.grid(row=2, column=0)
f_cpu = Entry(add_pos, textvariable=cpu_to_parse, width=30)
f_cpu.grid(row=2, column=1)
lab4 = Label(add_pos, text='RAM:')
lab4.grid(row=3, column=0)
f_ram = Entry(add_pos, textvariable=ram_to_parse, width=30)
f_ram.grid(row=3, column=1)
lab5 = Label(add_pos, text=' ')
lab5.grid(row=5, column=0)
#brand_to_parse = brand_to_parse.get()
#model_to_parse = brand_to_parse.get()
#cpu_to_parse = brand_to_parse.get()
#ram_to_parse = brand_to_parse.get()
# return brand_to_parse, model_to_parse, cpu_to_parse, ram_to_parse
def insert_new_data_to_db():
DatabaseMain().insert_data(brand_to_parse.get(),
model_to_parse.get(), cpu_to_parse.get(), ram_to_parse.get())
f_brand.delete(0, END)
f_model.delete(0, END)
f_cpu.delete(0, END)
f_ram.delete(0, END)
lab6 = Label(add_pos, text='success!, add new item')
lab6.grid(row=5, column=1)
button_confirm = Button(add_pos, text='Dodaj', borderwidth=3,
width=25, height=3, command=insert_new_data_to_db)
button_confirm.grid(row=4, column=1)

78
database.py Normal file
View File

@ -0,0 +1,78 @@
import sqlite3
class DatabaseMain():
def __init__(self):
self.database_name = 'towary_main.db'
self.conn = None
self.c = None
def _create_or_connect_to_db(self):
# create a database or connect to one
self.conn = sqlite3.connect(self.database_name)
def _create_cursor(self):
# create cursor
self.c = self.conn.cursor()
def _create_table(self):
self.c.execute("""CREATE TABLE IF NOT EXISTS computers (
com_id INTEGER PRIMARY KEY AUTOINCREMENT,
com_brand text,
com_model text,
com_cpu text,
com_ram text
)""")
def _show_table(self):
self.c.execute("SELECT * FROM computers")
print(self.c.fetchall())
def _insert_value_to_table(self, parsed_com_brand, parsed_com_model, parsed_com_cpu, parsed_com_ram):
self.c.execute(f"""INSERT INTO COMPUTERS (
com_brand,
com_model,
com_cpu,
com_ram
)
VALUES (
"{parsed_com_brand}",
"{parsed_com_model}",
"{parsed_com_cpu}",
"{parsed_com_ram}"
)""")
def _commit_to_db(self):
self.conn.commit()
def _close_db(self):
self.conn.close()
def initialize_db(self):
self._create_or_connect_to_db()
self._create_cursor()
self._create_table()
self._commit_to_db()
self._close_db()
def show_db(self):
self._create_or_connect_to_db()
self._create_cursor()
self._show_table()
self._close_db()
def insert_data(self, parsed_com_brand, parsed_com_model, parsed_com_cpu, parsed_com_ram):
self._create_or_connect_to_db()
self._create_cursor()
self._insert_value_to_table(
parsed_com_brand, parsed_com_model, parsed_com_cpu, parsed_com_ram)
self._commit_to_db()
self._close_db()
def drop_db(self):
self._create_or_connect_to_db()
self._create_cursor()
self.c.execute("DROP TABLE computers")
self._commit_to_db()
self._close_db()

57
main_window.py Normal file
View File

@ -0,0 +1,57 @@
from add_position import add_posit
from tkinter import *
import os
from database import DatabaseMain
root = Tk()
root.title('Manager towaru')
# root.geometry('600x400')
# def insert_new_data_to_db(brand_to_parse):
#DatabaseMain().insert_data(brand_to_parse, "g1", "i7", "8gb dd5")
def show_base():
DatabaseMain().show_db()
def hello():
hello_label = Label(root, text='Hello ')
hello_label.grid(row=5, column=0)
separe_label = Label(root, text=' ')
separe_label.grid(row=1, column=1)
button_add = Button(root, text='Dodaj nowy plik dostawy', borderwidth=3,
width=25, height=3, command=hello)
button_add.grid(row=1, column=0)
button_view = Button(root, text='Podgląd bazy', borderwidth=3,
width=25, height=3, command=show_base)
button_view.grid(row=2, column=0)
button_view = Button(root, text='Dodaj pozycje', borderwidth=3,
width=25, height=3, command=add_posit)
button_view.grid(row=3, column=0)
button_del = Button(root, text='Usuń pozycje', borderwidth=3,
width=25, height=3, command=hello)
button_del.grid(row=4, column=0)
button_create = Button(root, text='Utwórz etykiete', borderwidth=3,
width=25, height=3, command=hello)
button_create.grid(row=1, column=2)
button_quit = Button(root, text='Zamknij program', borderwidth=3,
width=25, height=3, command=root.quit)
button_quit.grid(row=4, column=2)
DatabaseMain().initialize_db()
root.mainloop()
DatabaseMain().drop_db()