-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShop Management System
More file actions
173 lines (131 loc) · 6.55 KB
/
Shop Management System
File metadata and controls
173 lines (131 loc) · 6.55 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
#USER LOGIN PAGE
from tkinter import *
from subprocess import call
import tkinter.messagebox as msg
import mysql.connector
import time
root = Tk()
root.geometry("1000x620+100+50")
root.title("User Login Page")
# Connect with Mysql database
try:
myDb = mysql.connector.connect(host='localhost', user='abhi', database='dB2', password='Abhi@3205')
except:
msg.showinfo('Error', 'Unable to Connect with the Server.\nPlease contact the developer!')
class Fetch_Data:
def __init__(self):
self.IDs = []
self.Passwords = []
def loadData(self):
self.cur = myDb.cursor()
stmt = f'Select * from UserLogin'
self.cur.execute(stmt)
data = self.cur.fetchall()
# print(data)
for dat in data:
self.IDs.append(dat[0])
self.Passwords.append(dat[1])
class UserRegistration(Fetch_Data):
def __init__(self):
super().__init__() #to call the constructor of parent class
# print(self.IDs)
self.loadData()
self.values = []
self.lis = []
self.path = '/home/abhishek/Gui/Shop using gui.py'
def Menu(self):
#Note:- Declare Entery attributes inside the methods, it is visible outside the class (bydefault public)
self.userId = StringVar()
self.userId.set("") # Initializing the initital values as empty
self.passwd = StringVar()
self.passwd.set("") # Initializing password values as empty
self.checkBox = IntVar() # For check box
self.frame1 = Frame(root, bg='yellow', borderwidth=2, relief=SUNKEN)
self.frame2 = Frame(self.frame1, borderwidth=6, relief=SUNKEN)
Label(self.frame2, padx=5, pady=20).grid(row=0, column=0) # frame just for Adjustment
Label(self.frame2, text='User ID', font='castellar 20 bold', padx=7, pady=7).grid(row=1, column=0)
iD = Entry(self.frame2, textvariable= self.userId, font='helvetica 20 bold').grid(row=1, column=1)
Label(self.frame2, text='Password', font='castellar 20 bold', padx=7, pady=7).grid(row=2, column=0)
pas = Entry(self.frame2, textvariable=self.passwd, font='helvetica 20 bold').grid(row=2, column=1)
Label(self.frame2, pady=12).grid(row=3, column=0)
Checkbutton(self.frame2, text='Remember me ', variable=self.checkBox, font='castellar 12 bold', padx=7,
pady=7).grid(
row=4, column=0)
Button(self.frame2, text='Login', font='castellar 14 bold', fg='green', bg='lightblue',
command=self.Login).grid(row=5,
column=1,
pady=6)
Button(self.frame2, text='New User ?', font='castellar 14 bold', fg='green', bg='lightblue',
command=self.newUser,
pady=5).grid(row=6, column=1)
Label(self.frame2, padx=5, pady=20).grid(row=7, column=0) # Frame just for adjustment
self.frame2.pack(side=TOP, fill=BOTH, padx=20, pady=20)
self.frame1.pack(side=TOP, fill=BOTH, padx=20, pady=20)
def Login(self):
# msg.showinfo('Hi','You are logged IN')
# print('Remember Me value is: ',checkBox.get())
self.lis = []
self.values = []
if self.userId.get() == "" or self.passwd.get() == "":
msg.showinfo('Error', 'Invalid Credentials!')
else:
if self.userId.get() not in self.IDs:
msg.showinfo('Error', 'ID not Matched!')
elif self.passwd.get() not in self.Passwords:
msg.showinfo('Error', 'Password not Matched!')
# print(IDs.index('abhi'))
elif self.IDs.index(self.userId.get()) != self.Passwords.index(self.passwd.get()):
msg.showinfo('Error', 'User Id or Password is Incorrect!')
else:
# msg.showinfo('Hurrah', 'Login Successful')
if self.checkBox.get() == 1:
self.lis.append(self.userId.get())
self.lis.append(self.passwd.get())
tup = tuple(self.lis)
self.values.append(tup)
stmt = "INSERT into RememberLogins(userId,password) VALUES(%s,%s)"
self.cur.executemany(stmt, self.values)
myDb.commit()
msg.showinfo('Done', 'To Remember me!')
root.destroy() #Close the login window and open the desired one
time.sleep(0.1)
call(['python3', f'{self.path}', f'{self.userId.get()}'])
def sineUp(self):
if self.newId.get() == "" or self.newPasswd.get() == "":
msg.showinfo('Error', 'Invalid Credentials')
else:
if self.newId.get() not in self.IDs:
self.IDs.append(self.newId.get())
self.Passwords.append(self.newPasswd.get())
self.lis.append(self.newId.get())
self.lis.append(self.newPasswd.get())
tup = tuple(self.lis)
self.values.append(tup)
stmt = "INSERT into UserLogin(userId,password) VALUES(%s,%s)"
self.cur.executemany(stmt, self.values)
myDb.commit()
msg.showinfo('Done', 'Registration Successful!')
else:
msg.showinfo('Error', 'This ID already Exists.')
def newUser(self):
self.newId = StringVar()
self.newId.set("")
self.newPasswd = StringVar()
self.newPasswd.set("")
top = Toplevel()
top.title('New User Registration')
top.geometry('650x420')
frame3 = Frame(top, borderwidth=2, relief=SUNKEN)
Label(frame3, padx=5, pady=20).grid(row=0, column=0)
Label(frame3, text='User Name: ', font='castellar 20 bold', padx=7, pady=7).grid(row=1, column=0)
idd = Entry(frame3, textvariable=self.newId, font='helvetica 20 bold').grid(row=1, column=1, padx=9)
Label(frame3, text='Password: ', font='castellar 20 bold', padx=7, pady=7).grid(row=2, column=0)
pwd = Entry(frame3, textvariable=self.newPasswd, font='helvetica 20 bold').grid(row=2, column=1, padx=9)
Label(frame3, pady=12).grid(row=4, column=0)
Button(frame3, text=' Sine Up ', font='castellar 14 bold', fg='green', bg='yellow', command=self.sineUp).grid(row=5,
column=0)
frame3.pack()
if __name__ == '__main__':
u1 = UserRegistration()
u1.Menu()
root.mainloop()