Repository navigation
Expand file tree
/
Copy pathEmployee_Table.py
More file actions
204 lines (150 loc) · 4.98 KB
/
Copy pathEmployee_Table.py
File metadata and controls
204 lines (150 loc) · 4.98 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# import mysql.connector
# # mydb = mysql.connector.connect(
# # host="localhost",
# # user="testuser",
# # password="test123"
# # )
# # mycursor = mydb.cursor()
# # mycursor.execute("CREATE DATABASE payroll")
# mydb = mysql.connector.connect(
# host="localhost",
# user="testuser",
# password="test123"
# )
# mycursor = mydb.cursor()
# mycursor.execute("SHOW DATABASES")
# for x in mycursor:
# print(x)
# mydb = mysql.connector.connect(
# host="localhost",
# user="testuser",
# password="test123",
# database="payroll"
# )
# mycursor = mydb.cursor()
# mycursor.execute("CREATE TABLE registration (name VARCHAR(255), empname VARCHAR(255), mobile VARCHAR(10), salary VARCHAR(20))")
# mycursor.execute("SHOW TABLES")
# for x in mycursor:
# print(x)
import tkinter as tk
from tkinter import ttk, messagebox
import mysql.connector
from tkinter import *
def GetValue(event):
e1.delete(0, END)
e2.delete(0, END)
e3.delete(0, END)
e4.delete(0, END)
row_id = listBox.selection()[0]
select = listBox.set(row_id)
e1.insert(0,select['empid'])
e2.insert(0,select['empname'])
e3.insert(0,select['empmob'])
e4.insert(0,select['empsal'])
def Add():
empid = e1.get()
empname = e2.get()
empmob = e3.get()
empsal = e4.get()
mysqldb=mysql.connector.connect(host="localhost",user="testuser",password="test123",database="payroll")
mycursor=mysqldb.cursor()
try:
sql = "INSERT INTO registration1 (empid,empname,empmob,empsal) VALUES (%s, %s, %s, %s)"
val = (empid, empname, empmob, empsal)
mycursor.execute(sql, val)
mysqldb.commit()
lastid = mycursor.lastrowid
messagebox.showinfo("information", "Employee inserted successfully...")
e1.delete(0, END)
e2.delete(0, END)
e3.delete(0, END)
e4.delete(0, END)
e1.focus_set()
except Exception as e:
print(e)
mysqldb.rollback()
mysqldb.close()
def update():
empid = e1.get()
empname = e2.get()
empmob = e3.get()
empsal = e4.get()
mysqldb=mysql.connector.connect(host="localhost",user="testuser",password="test123",database="payroll")
mycursor=mysqldb.cursor()
try:
sql = "Update registration1 set empname= %s,empmob= %s,empsal= %s where empid= %s"
val = (empid, empname, empmob, empsal)
mycursor.execute(sql, val)
mysqldb.commit()
lastid = mycursor.lastrowid
messagebox.showinfo("information", "Record Updateddddd successfully...")
e1.delete(0, END)
e2.delete(0, END)
e3.delete(0, END)
e4.delete(0, END)
e1.focus_set()
except Exception as e:
print(e)
mysqldb.rollback()
mysqldb.close()
def delete():
empid = e1.get()
mysqldb=mysql.connector.connect(host="localhost",user="testuser",password="test123",database="payroll")
mycursor=mysqldb.cursor()
try:
sql = "delete from registration1 where empid = %s"
val = (empid,)
mycursor.execute(sql, val)
mysqldb.commit()
lastid = mycursor.lastrowid
messagebox.showinfo("information", "Record Deleteeeee successfully...")
e1.delete(0, END)
e2.delete(0, END)
e3.delete(0, END)
e4.delete(0, END)
e1.focus_set()
except Exception as e:
print(e)
mysqldb.rollback()
mysqldb.close()
def show():
mysqldb = mysql.connector.connect(host="localhost", user="testuser", password="test123", database="payroll")
mycursor = mysqldb.cursor()
mycursor.execute("SELECT empid,empname,empmob,empsal FROM registration1")
records = mycursor.fetchall()
print(records)
for i, (empid, empname, empmob, empsal) in enumerate(records, start=1):
listBox.insert("", "end", values=(empid, empname, empmob, empsal))
mysqldb.close()
root = Tk()
root.geometry("800x500")
global e1
global e2
global e3
global e4
tk.Label(root, text="Employee Registation", fg="red", font=(None, 30)).place(x=300, y=5)
tk.Label(root, text="Employee ID").place(x=10, y=10)
Label(root, text="Employee Name").place(x=10, y=40)
Label(root, text="Mobile").place(x=10, y=70)
Label(root, text="Salary").place(x=10, y=100)
e1 = Entry(root)
e1.place(x=140, y=10)
e2 = Entry(root)
e2.place(x=140, y=40)
e3 = Entry(root)
e3.place(x=140, y=70)
e4 = Entry(root)
e4.place(x=140, y=100)
Button(root, text="Add",command = Add,height=3, width= 13).place(x=30, y=130)
Button(root, text="update",command = update,height=3, width= 13).place(x=140, y=130)
Button(root, text="Delete",command = delete,height=3, width= 13).place(x=250, y=130)
Button(root, text="View Latest",command = show,height=3, width= 13).place(x=250+110, y=130)
cols = ('empid', 'empname', 'empmob','empsal')
listBox = ttk.Treeview(root, columns=cols, show='headings' )
for col in cols:
listBox.heading(col, text=col)
listBox.grid(row=1, column=0, columnspan=2)
listBox.place(x=10, y=200)
show()
listBox.bind('<Double-Button-1>',GetValue)
root.mainloop()