-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstd.py
More file actions
84 lines (73 loc) · 2.88 KB
/
std.py
File metadata and controls
84 lines (73 loc) · 2.88 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
def searching(self):
print("Success")
ent = self.search_entry.get()
if ent != "":
try:
self.lis = []
for i in self.emp_tree.get_children():
a = self.emp_tree.item(i)['values'][0]
self.lis.append(a)
print(f"list = {self.lis}")
search = self.linearsearch(self.lis, self.search_entry.get())
print(f"search = {search}")
if search:
messagebox.showinfo("Success", "Found")
query = "select * from employee where id = %s"
values = (search,)
a = self.db.select1(query, values)
print(a)
self.emp_tree.delete(*self.emp_tree.get_children())
for i in a:
val = [i[0], i[4], i[2], i[6], i[5], i[7], i[8], i[9]]
self.emp_tree.insert('', END, values=val)
else:
messagebox.showerror("failed", "Error, Not found")
except BaseException as m:
print(m)
messagebox.showerror("Not Found", "Error, Not found")
@classmethod
def linearsearch(self, lis, x):
for i in range(len(lis)):
if int(lis[i]) == int(x):
return lis[i]
return False
def sorting(self, events):
if self.sort.get() == "By ID" and self.sort_t.get() == "Increasing":
query = "select * from employee;"
data = self.db.select(query)
sort_val = []
for values in data:
sort_val.append(values)
sorted_val = self.b_sort_a(sort_val)
if len(sorted_val) != 0:
messagebox.showinfo("Done", "Sorted increasing order")
self.emp_tree.delete(*self.emp_tree.get_children())
for i in sorted_val:
val = [i[0], i[4], i[2], i[6], i[5], i[7], i[8], i[9]]
self.emp_tree.insert('', END, values=val)
elif self.sort.get() == "By ID" and self.sort_t.get() == "Decreasing":
query = "select * from employee;"
data = self.db.select(query)
sort_val = []
for values in data:
sort_val.append(values)
sorted_val = self.b_sort_d(sort_val)
if len(sorted_val) != 0:
messagebox.showinfo("Done", "Sorted Decreasing order")
self.emp_tree.delete(*self.emp_tree.get_children())
for i in sorted_val:
val = [i[0], i[4], i[2], i[6], i[5], i[7], i[8], i[9]]
self.emp_tree.insert('', END, values=val)
@classmethod
def b_sort_a(self, lis):
for j in range(len(lis) - 1):
for i in range(len(lis) - 1):
if lis[i] > lis[i + 1]:
lis[i], lis[i + 1] = lis[i + 1], lis[i]
return lis
def b_sort_d(self, lis):
for j in range(len(lis) - 1):
for i in range(len(lis) - 1):
if lis[i] < lis[i + 1]:
lis[i], lis[i + 1] = lis[i + 1], lis[i]
return lis