-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdmin.py
More file actions
88 lines (80 loc) · 2.83 KB
/
Admin.py
File metadata and controls
88 lines (80 loc) · 2.83 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
import mysql.connector
import Tables
class Admin:
def __init__(self, cursor):
self.cursor = cursor
def displayAdmin():
print()
print("Admin Records: \n")
mycursor.execute("SELECT * FROM AdminRecord")
records=mycursor.fetchall()
row_no=0
for rows in records :
row_no+=1
print("******************************","Row no.",row_no,"******************************")
print("\t AdminID: ", rows[0])
print("\t Password: ", rows[1])
print()
x=input("Press Enter to continue...")
return
def insertAdmin():
while True :
data=()
print()
AdminID=input("Enter AdminID: ")
Password=input(" Enter Password to be set: ")
data=(AdminID,Password)
query="INSERT INTO AdminRecord VALUES (%s, %s)"
mycursor.execute(query,data)
mydb.commit()
print()
ch=input("Do you wish to do add more Administrators?[Yes/No] : ")
if ch=="no" or ch=="No" or ch=="NO":
break
return
def deleteAdmin():
while True:
print()
AdminID=input(" Enter AdminID whose details to be deleted : ")
mycursor.execute("DELETE from AdminRecord where AdminID={0}".format("\'"+AdminID+"\'"))
mydb.commit()
ch=input("Do you wish to delete more Administrators?[Yes/No] : ")
if ch=="no" or ch=="No" or ch=="NO":
break
return
def searchAdmin():
while True:
print()
Search=input(" Enter AdminID to be Searched: ")
mycursor.execute("SELECT * FROM AdminRecord where AdminID={0}".format("\'"+Search+"\'"))
records=mycursor.fetchall()
row_no=0
if records:
for rows in records :
row_no+=1
print("******************************","Searched Admin Record","******************************")
print("\t AdminID: ", rows[0])
print("\t Password: ", rows[1])
print()
else:
print("Search Unsuccesful!!")
ch=input("Do you wish to Search more Administrators?[Yes/No] : ")
if ch=="no" or ch=="No" or ch=="NO":
break
return
def updateAdmin():
while True:
print()
data=()
AdminID=input(" Enter Admin ID for whose details need to be updated : ")
Password=input(" Enter new Password : ")
query="UPDATE AdminRecord SET Password = %s WHERE AdminID=%s"
data=(Password,AdminID)
mycursor.execute(query,data)
mydb.commit()
ch=input("Do you wish to Search more Administrators?[Yes/No] : ")
if ch=="no" or ch=="No" or ch=="NO":
break
return
mydb=mysql.connector.connect(host="localhost",user="root",passwd="",database="Library")
mycursor=mydb.cursor()