-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.py
40 lines (34 loc) · 1.48 KB
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from sqlite3 import connect
from datetime import datetime
class Database:
@staticmethod
def insert(name, lastname, nationalcode, dateofbirth):
my_con = connect('ListofEmployee.db')
my_cursor = my_con.cursor()
my_cursor.execute(f"INSERT INTO List_of_Employee(Name, LastName, NationalCode, DateofBirth, Pic) VALUES('{name}', '{lastname}', '{nationalcode}', '{dateofbirth}', '{str(nationalcode)+'.png'}')")
my_con.commit()
my_con.close()
return True
@staticmethod
def select():
my_con = connect('ListofEmployee.db')
my_cursor = my_con.cursor()
my_cursor.execute("SELECT * FROM List_of_Employee")
result = my_cursor.fetchall()
my_con.close()
return result
@staticmethod
def delete(id):
my_con = connect('ListofEmployee.db')
my_cursor = my_con.cursor()
my_cursor.execute(f"DELETE FROM List_of_Employee WHERE NationalCode = '{id}'")
my_con.commit()
my_con.close()
@staticmethod
def edit(name, lastname, nationalcode, dateofbirth):
my_con = connect('ListofEmployee.db')
my_cursor = my_con.cursor()
my_cursor.execute(f"UPDATE List_of_Employee SET Name='{name}' ,LastName='{lastname}', NationalCode='{nationalcode}',DateofBirth='{dateofbirth}', Pic='{str(nationalcode)+'.png'}' WHERE NationalCode='{nationalcode}'")
my_con.commit()
my_con.close()
return True