-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathApp.py
218 lines (197 loc) · 6.47 KB
/
App.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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from pymongo import MongoClient
from random import randint
from Tkinter import *
import tkMessageBox
import ttk
from Tkinter import Button
import sys
try:
client = MongoClient(port=27017)
db=client.Assignment08
print("Connected to MongoDB")
except :
print("Database connection Error ")
print("No connection could be made because the target machine actively refused it ")
tkMessageBox.showerror("Error", "Connection Error")
sys.exit(1)
root=Tk()
root.geometry('400x350')
root.title("Student Management System")
def add_STUDENTS(root,db):
def add_query():
global root
prn = E1.get()
name = E2.get()
email = E3.get()
batch = E4.get()
mobile = E5.get()
PRN = [prn]
NAME = [name]
EMAIL = [email]
BATCH = [batch]
MOBILE = [mobile]
Assignment08 = {
'PRN' : PRN[randint(0, (len(PRN)-1))] ,
'NAME' : NAME[randint(0, (len(NAME)-1))],
'EMAIL' : EMAIL[randint(0, (len(EMAIL)-1))],
'BATCH' : BATCH[randint(0, (len(BATCH)-1))],
'MOBILE' : MOBILE[randint(0, (len(MOBILE)-1))]}
if(len(prn)==0):
tkMessageBox.showwarning("WARNING", "All fields are compulsory(Except: Mobile number)")
return
if(len(name)==0):
tkMessageBox.showwarning("WARNING", "All fields are compulsory(Except: Mobile number)")
return
if(len(email)==0):
tkMessageBox.showwarning("WARNING", "All fields are compulsory(Except: Mobile number)")
return
if(len(batch)==0):
tkMessageBox.showwarning("WARNING", "All fields are compulsory(Except: Mobile number)")
return
if len(mobile)==0 and db.students.count_documents({ 'PRN': prn }, limit = 1)==0:
result=db.students.insert_one({'PRN':prn,'NAME':name, 'EMAIL':email,'BATCH':batch})
elif len(mobile)!=0 and db.students.count_documents({ 'PRN': prn }, limit = 1)==0:
result=db.students.insert_one(Assignment08)
else:
tkMessageBox.showwarning("ERROR", "STUDENT Already Exists")
return
newwin.destroy()
tkMessageBox.showinfo("Add Student", "Student Added")
newwin = Toplevel(root)
newwin.geometry('400x400')
newwin.title("Add STUDENTS")
L1 = Label(newwin, text="PRN")
L1.place(x=10,y=50)
E1 = Entry(newwin, bd=7)
E1.place(x=100,y=50)
L2 = Label(newwin, text="NAME")
L2.place(x=10,y=100)
E2 = Entry(newwin, bd=7)
E2.place(x=100,y=100)
L3 = Label(newwin, text="EMAIL")
L3.place(x=10,y=150)
E3 = Entry(newwin, bd=7)
E3.place(x=100,y=150)
L4 = Label(newwin, text="BATCH")
L4.place(x=10,y=200)
E4 = Entry(newwin, bd=7)
E4.place(x=100,y=200)
L5 = Label(newwin, text="MOBILE")
L5.place(x=10,y=250)
E5 = Entry(newwin, bd=7)
E5.place(x=100,y=250)
sub=Button(newwin,text="Submit",command=add_query)
sub.place(x=120,y=350)
def del_data(root,db):
def delete():
global root
prn = E1.get()
if(len(prn)==0):
tkMessageBox.showwarning("WARNING", "Enter a Valid PRN")
return
if db.students.count_documents({ 'PRN': prn }, limit = 1)==0:
tkMessageBox.showwarning("ERROR", "STUDENT Does Not Exist")
return
else:
db.students.delete_one({'PRN':prn})
newwin.destroy()
tkMessageBox.showinfo("Delete Student", "Student Deleted")
newwin=Toplevel(root)
newwin.geometry('400x350')
newwin.title("Delete STUDENT")
L1 = Label(newwin, text="PRN")
L1.place(x=10, y=50)
E1 = Entry(newwin,bd=5)
E1.place(x=100, y=50)
sub = Button(newwin, text="Delete Entry", command=delete)
sub.place(x=120, y=200)
def update_data(root,db):
def UPDD():
global root
prn = E6.get()
name = E7.get()
email = E8.get()
batch = E9.get()
mobile = E10.get()
if(len(prn)==0):
tkMessageBox.showwarning("WARNING", "Enter a Valid PRN")
return
if db.students.count_documents({ 'PRN': prn }, limit = 1)==0:
tkMessageBox.showwarning("ERROR", "STUDENT Does Not Exist")
return
if(len(name)!=0):
db.students.update_one({"PRN":prn},{"$set": {'NAME' : name}})
if(len(email)!=0):
db.students.update_one({"PRN":prn},{"$set": {'EMAIL' : email}})
if(len(batch)!=0):
db.students.update_one({"PRN":prn},{"$set": {'BATCH' : batch}})
if(len(mobile)!=0):
db.students.update_one({"PRN":prn},{"$set": {'MOBILE' : mobile}})
newwin.destroy()
tkMessageBox.showinfo("Update Student", "Student Updated")
newwin = Toplevel(root)
newwin.geometry('400x400')
newwin.title("Update STUDENTS")
L6 = Label(newwin, text="PRN")
L6.place(x=10,y=50)
E6 = Entry(newwin, bd=7)
E6.place(x=100,y=50)
L7 = Label(newwin, text="NAME")
L7.place(x=10,y=100)
E7 = Entry(newwin, bd=7)
E7.place(x=100,y=100)
L8 = Label(newwin, text="EMAIL")
L8.place(x=10,y=150)
E8 = Entry(newwin, bd=7)
E8.place(x=100,y=150)
L9 = Label(newwin, text="BATCH")
L9.place(x=10,y=200)
E9 = Entry(newwin, bd=7)
E9.place(x=100,y=200)
L10 = Label(newwin, text="MOBILE")
L10.place(x=10,y=250)
E10 = Entry(newwin, bd=7)
E10.place(x=100,y=250)
sub=Button(newwin,text="Submit",command=UPDD)
sub.place(x=120,y=350)
def display(root,db):
newwin=Toplevel(root)
newwin.geometry('400x400')
newwin.title("STUDENT Details")
L1=Label(newwin,text="PRN")
L1.grid(row=0,column=0)
L2 = Label(newwin, text="NAME")
L2.grid(row=0, column=2)
L3=Label(newwin,text="EMAIL")
L3.grid(row=0,column=4)
L4=Label(newwin,text="BATCH")
L4.grid(row=0,column=6)
L5=Label(newwin,text="MOBILE")
L5.grid(row=0,column=8)
i=1
for x in db.students.find():
y=len(x)
# print(len(x))
L1 = Label(newwin, text=x['PRN'])
L1.grid(row=i, column=0)
L2 = Label(newwin, text=x['NAME'])
L2.grid(row=i, column=2)
L3 = Label(newwin, text=x['EMAIL'])
L3.grid(row=i, column=4)
L4 = Label(newwin, text=x['BATCH'])
L4.grid(row=i, column=6)
if y==6:
L5 = Label(newwin, text=x['MOBILE'])
L5.grid(row=i, column=8)
i+=1
add= Button(root,text='Add New STUDENTS',command=lambda:add_STUDENTS(root,db))
delete= Button(root,text='Delete STUDENTS Entry',command=lambda:del_data(root,db))
update= Button(root,text='Update STUDENTS Info',command=lambda:update_data(root,db))
show= Button(root,text='Show STUDENTS Details',command=lambda:display(root,db))
add.place(x=100,y=100)
delete.place(x=100,y=150)
update.place(x=100,y=200)
show.place(x=100,y=250)
root.mainloop()