Acknowledgement I would like to express my deep gratitude towards my computer Science teacher, Mrs. Neha Kataria ma’am for her skilful guidance, constructive and valuable suggestions with encouraging cooperation for my project, which not merely helped but enabled me to give my best efforts towards this project. I am also thankful to our principal in charge, Ms. Neerja Jain ma’am for her inspiring words that motivated us to think outside the box and her brilliant guidance given from time to time. I also extend my thanks to all colleagues and friends for their priceless assistance and kind cooperation during the course of this investigation. Harsh Verma Class XII Science VBPS, Udaipur Certificate This is to certify that Harsh Verma of Class XII Science has satisfactorily completed the project entitled “Book Shop Management”, under my guidance and Supervision. I appreciate his keen interest and sincere efforts in covering all details of the project in a very systematic manner. I am very pleased with his project Examiner Subject Teacher Principal Contents Introduction Structure Of Project o Admin Module o User Module Source Code Outputs Structure of tables Introduction This project BOOK SHOP MANAGEMENT includes some facilitates for retail book shop to maintain records of the books and display, modify, delete etc the book data available. This software allows both the admin and visitor to enjoy various features. This project uses to MySQL in backend to store books data and python in frontend do make managing databases easier. Using this project is very easy due to easy menu driven functions. Structure Of Project Project Admin Module User Module Initial Module Main Module Our project has been divided into 4 parts: 1. Admin Module: The admin module contains all function related to admin or owner of book shop 2. User Module: The user module contains all function related to anyone who visits the book shop. 3. Initial Module: The initial module all SQL queries that are need for the first-time use of the project. 4. Main Module: The Main module works as a bridge between all three above modules and also acts as front-end module. Admin Module Admin Module View Books Insert Data Update Data Delete Data Check Issues Check buy Requests To Exit The admin module in our Book Shop Management Project has 7 Parts: 1. View books: This part allows the admin to view all books data present in database in tabular form 2. Insert Data: Add new book and its data in database. 3. Update Data: Update book data present in database. 4. Delete Data: delete a book and its data from database. 5. Check Issues: To check which book is issued to whom in tabular form. 6. Check Buy Requests: To check buy requests for book from people in tabular form. 7. To Exit: To exit out of admin module. User Module User Module View Books Ask book for issue View All books View Books using Filters Filter using Genre Filter Using Author Submit book Ask book to buy Check Buy Status To Exit Filter Using Price The user module in our Book Shop Management Project has 6 parts: 1. View Books: To view all books present in database, it has further two parts: a. View All books : To view all books present in database . b. View Books using Filters: to view books of a particular Genre/Author or in order of price. 2. Ask Book for issue: This part allow user to ask a book for issue using its book id. 3. Submit Book: This part allows user to submit that he had taken in part for issue. 4. Ask Book to buy : This part allows the user to send a request to admin to buy a book. 5. Check Buy Status : This Part allows the user to check the status of request that he has sent for buying. 6. To Exit: This parts allows the user to exit out of user module. Source Code Admin.py module 1. import mysql.connector as mc 2. from prettytable import PrettyTable 3. mydb = mc.connect(user="root", host="localhost", passwd="root", database='bookshop') 4. mycursor = mydb.cursor() 5. adminpasswd = "bookshop" 6. 7. # this function runs query in SQL shell, and prints the output. 8. def runQuery(s: str): 9. mycursor.execute(s) 10. for i in mycursor.fetchall(): 11. print(i, end="\n") 12. return mycursor.fetchall() # type: ignore 13. 14. # this function runs query in SQL shell, and add the data to a variable in a tabular format. 15. def runQueryAddData(s: str,table): 16. mycursor.execute(s) 17. 18. 19. for i in mycursor.fetchall(): # type: ignore table.add_row(i) 20. def admin_menu(): 21. choices = """\nWhat Do You Want To Do?\n1 To View Books.\n2 To EnterBook Data.\n3 To Update Book Data.\n4 To Delete Book Data.\n5 To Check Issues.\n6 To check buy requests.\n7 To EXIT""" 22. # All available choices print(choices) 23. 24. 25. # the below code inputs choice ensuring it is between 1 and 5. choice = 0 26. while choice == 0: 27. try: # use try-except to make it easier. 28. choice = int(input("Enter Choice: ")) 29. if choice < 1 or choice > 7: 30. # Raise error if choice is not between 1 and 5 to run excpet part. 31. raise TypeError 32. 33. except: 34. print("Choice Should be in integer and between 1 & 7.") 35. # this will make loop run forever until required choice is given. 36. choice = 0 37. 38. return choice 39. 40. def admin_main(): 41. 42. # this forever loop only gets exited using choice 5. 43. while True: 44. 45. choice = admin_menu() # choices gets chosen using menu function 46. if choice == 1: # To view Data. 47. 48. 49. 50. # first, create a table using pretty table module myTable = PrettyTable(["Book_id","Book_Name","Book_Author","Genre","Book_Price"]) 51. 52. # then, add data to it. 53. runQueryAddData("select * from book", myTable) 54. 55. 56. # finally, print the table. print(myTable) 57. 58. 59. if choice == 2: # To Enter Data. 60. # get values from admin. 61. print("Format: Book ID - Book Name - Book Author - Genre -Price") 62. print("Note that Book ID and Book Name cannot be blank.") 63. book_id = input("Enter Book ID: ") 64. book_name = input("Enter Book Name: ") 65. book_author = input("Enter Book Author Name: ") 66. genre = input("Enter Book Genre: ") 67. price = input("Enter Book Price:") 68. if price == "": price = "NULL" 69. 70. # this below code runs the query to enter data intodatabase; 71. try: 72. runQuery("insert into book values("+book_id+',"'+book_name+'","'+book_author+'","'+genre+'",'+price +');') 73. 74. mydb.commit() #commit() function saves the chages wemade to mysqlserver. 75. print("Record Entered.\n") 76. 77. 78. 79. except Exception as e: # if we get error, we will inform user accordingly. if str(e)[0:12] == "1062 (23000)" : #primary key error print("Book with ID "+str(e)[31]+" already exists.") 80. 81. 82. 83. elif str(e)[0:12] == "1054 (42S22)" : #typeerror print("Price Shouldn't Contain Characters.") 84. 85. 86. else: print(e) 87. print("Record Not Inserted.") 88. 89. 90. if choice == 3: # To update Data 91. updateid = input("Whose Record you want to update(Enter Book ID): ") 92. print("What Do want to Update:-\n1 For Book Name.\n2 ForBook Author.\n3 For Genre.\n4 For Book Price") 93. update = int(input("Enter Choice: ")) 94. 95. 96. # checking of choice is required to prevent unwanted error. if update < 1 or update > 4: 97. 98. print("Invalid Choice") 99. continue # here, "continue" stops the loop's currentrun and does a fresh start. 100. 101. if update == 1: #new name 102. updated = input("Enter New Book Name: ") 103. runQuery("update book set book_name = \""+updated+"\" where book_id = "+updateid+";") 104. 105. 106. 107. if update == 2: #new author updated = input("Enter New Author Name: ") runQuery("update book set book_author = \""+updated+"\" where book_id = "+updateid+";") 108. 109. 110. 111. if update == 3: #new genre updated = input("Enter New Genre: ") runQuery("update book set genre = \""+updated+"\" where book_id = "+updateid+";") 112. 113. if update == 4: #new price 114. updated = input("Enter New Price: ") 115. runQuery("update book set book_price = "+updated+" where book_id = "+updateid+";") 116. 117. mydb.commit() 118. print("Record Updated\n") 119. 120. 121. if choice == 4: # to delete record deleteid = input("Whose Record you want do delete(Enter Book ID): ") 122. 123. try: 124. runQuery("delete from book where book_id = "+deleteid+";") 125. 126. mydb.commit() print("Record Deleted") 127. 128. except Exception as e: 129. print("Error: ",e) 130. 131. 132. if choice == 5: # To check issues 133. # create a table using pretty table module 134. myTable = PrettyTable(["Book ID", "Book Name", "Client Name"]) 135. 136. # add data to it. 137. runQueryAddData("select issue.book_id, book_name, client_name from issue, book where book.book_id = issue.book_id;", myTable) 138. 139. # print the table print(myTable) 140. 141. 142. 143. if choice == 6: # To check buy requests 144. # print table first. 145. myTable = PrettyTable(["Book ID", "Book Name","Book Price", "Client Name"]) 146. runQueryAddData("select buyrequests.book_id, book_name, book_price, client_name from buyrequests,book where buyrequests.book_id = book.book_id;",myTable) 147. print(myTable) 148. 149. # now, we will ask admin, which buy request he wants to accept. 150. print("Which request do you want to accept? (Leave Blank for none.)") 151. secondChoice = input("Enter Book ID: ") 152. 153. # if admin input a book_id to accept, then work on it 154. if secondChoice != "": 155. try: 156. # first we will delete its record from buyrequsts; 157. runQuery("delete from buyrequests where book_id = "+secondChoice+";") 158. 159. # then we will insert its record into acceptedrequests table. 160. runQuery("insert into acceptedrequests values("+secondChoice+");") 161. 162. # then we will save our changes and infrom admin. 163. 164. mydb.commit() print("Book Selled.") 165. 166. except Exception as e: 167. print("Error Found: ",e) 168. 169. 170. if choice == 7: # to exit. break 171. 172. finalChoice = input("Do You want to Continue or Not (Y or N):-") 173. 174. if finalChoice.lower() == 'n' or finalChoice.lower() == "no": 175. 176. 177. break elif finalChoice.lower() == 'y' or finalChoice.lower() == "yes": 178. 179. 180. 181. 182. continue else: print("Invalid Choice.") break User.py Module 1. import mysql.connector as mc 2. from prettytable import PrettyTable 3. mydb = mc.connect(user="root", host="localhost", passwd="root",database='bookshop') 4. mycursor = mydb.cursor() 5. 6. # this function runs query in SQL shell, and prints the output. 7. def runQuery(s: str): 8. mycursor.execute(s) 9. for i in mycursor.fetchall(): 10. # type: ignore print(i, end="\n") 11. 12. 13. # this function runs query in SQL shell, and adds the data to a table insteading of printing it. 14. def runQueryAddData(s: str,table): 15. mycursor.execute(s) 16. 17. for i in mycursor.fetchall(): # type: ignore table.add_row(i) 18. 19. 20. # this function checks if a 'id' is in 'book_id' of table buyrequests. 21. def checkID(id: int): 22. mycursor.execute("select book_id from acceptedrequests;") 23. for i in mycursor.fetchall(): 24. for j in i: 25. if int(j) == int(id): 26. 27. # type: ignore return True return False 28. 29. 30. # the menu function is responsible for choice selection 31. def user_menu(): 32. choices = """\nWhat Do You Want To Do?\n1 To View Books.\n2 To Askbook for issue.\n3 To Submit Book.\n4 To Buy Book.\n5 to Check buy status.\n6 For Exit""" 33. # All available choices print(choices) 34. 35. 36. # the below code inputs choice ensuring it is between 1 and 5. choice = 0 37. while choice == 0: 38. try: # use try-except to make it easier. 39. choice = int(input("Enter Choice: ")) 40. if choice < 1 or choice > 6: 41. # Raise error if choice is not between 1 and 5 to run excpet part. 42. raise TypeError 43. 44. 45. except: print("Choice Should be in integer and between 1 & 6.") 46. # this will make loop run forever until required choice is given. 47. choice = 0 48. 49. return choice 50. 51. # this is the main function which does the main work of working on the choices and both frontend and backend 52. def user_main(): 53. 54. # this forever loop only gets exitted using choice 5. 55. while True: 56. 57. choice = user_menu() # choices gets choosen using menu function 58. 59. if choice == 1: #To View All books data: 60. print("\n1 to View All Books\n2 To see Filters") 61. secondChoice = int(input("Enter Choice: ")) 62. 63. 64. if secondChoice == 1: # to view all books 65. # create a table using PrettyTable Module 66. myTable = PrettyTable(["Book_id","Book_Name","Book_Author","Genre","Book_Price"]) 67. 68. # add data to it. 69. runQueryAddData("select * from book;",myTable) 70. 71. 72. # print it print(myTable) # print it. 73. 74. if secondChoice == 2: # to view books in filter 75. 76. print("\n1 To Get by Genre\n2 To Get By Author\n3 To Getby Price") # all available flters 77. 78. # get choice of filter 79. thirdChoice = int(input("Enter Choice: ")) 80. 81. 82. 83. # filter by genre if thirdChoice == 1: 84. # get unique genres uing MySQL 85. myTable = PrettyTable(["Genre"]) 86. runQueryAddData("select distinct genre from bookorder by genre;",myTable) 87. print(myTable) 88. 89. # get choice of genre 90. print("\nWhich Genre You want to See: ") 91. fourthChoice = input("Enter Choice: ") 92. 93. # print according to choice; 94. myTable = PrettyTable(["Book_ID", "Book_Name", "BookAuthor", "Genre", "Price"]) 95. runQueryAddData("select * from book where genre = '"+fourthChoice+"';",myTable) 96. 97. print(myTable) 98. 99. 100. if thirdChoice == 2: 101. # get unique authors using MySQL 102. print("\nAvailable Authors:: ") 103. myTable = PrettyTable(["Authors"]) 104. runQueryAddData("select distinct book_author from book;",myTable) 105. print(myTable) 106. 107. 108. # get choice print("\nWhich Author You Want: ") 109. fourthChoice = input("Enter Choice: ") 110. 111. # print according to choices 112. myTable = PrettyTable(["Book_ID", "Book_Name", "Book Author", "Genre", "Price"]) 113. runQueryAddData("select * from book where book_author ='"+fourthChoice+"';",myTable) 114. 115. 116. print(myTable) if thirdChoice == 3: 117. 118. # in price filter, we basically adjust books in ascending price order. 119. myTable = PrettyTable(["Book_ID","Book_Name", "Book Author", "Genre", "Price"]) 120. runQueryAddData("select * from book order by book_price;",myTable) 121. 122. print(myTable) 123. 124. if choice == 2: # to ask book for issue 125. # get client details, to update issue table clientname = input("Enter Your Name: ") 126. 127. 128. 129. # print book information myTable = PrettyTable(["Book_id","Book_Name","Book_Author","Genre","Book_Price"]) 130. runQueryAddData("select * from book;",myTable) 131. print(myTable) 132. 133. 134. # get book details, to update issue table. issueid = input("Enter Book_ID of the book you want: ") 135. 136. # try updating table try: runQuery("insert into issue 137. 138. values("+issueid+",'"+clientname+"');") 139. mydb.commit() # here, commit() saves changes we made to database; 140. print("Book Issued\n") 141. 142. 143. except: print("Wrong/Invalid Book ID") 144. 145. 146. if choice == 3: # To submit book 147. 148. #get book details, to update issue table 149. submitname = input("Enter your Name: ") 150. 151. 152. #try updating table try: 153. # print issue information 154. print("Your Record:- ") 155. myTable = PrettyTable(['Book Name','Client Name']) 156. runQueryAddData("select book.book_name, issue.client_name from book,issue where book.book_id = issue.book_id;", myTable) 157. print(myTable) 158. 159. # delete issue. 160. runQuery("delete from issue where client_name = '"+submitname+"';") 161. mydb.commit() 162. 163. # update user that issue has been cleared. 164. 165. print("Has been cleared.\n ") 166. except Exception as e: 167. print("Error: ",e) 168. 169. 170. 171. 172. if choice == 4: # to buy a book #print table myTable = PrettyTable(["Book_id","Book_Name","Book_Author","Genre","Book_Price"]) 173. runQueryAddData("select * from book;",myTable) 174. print(myTable) 175. 176. 177. # get values buyid = input("Enter Book ID of book you want to buy: ") 178. clientname = input("Enter Your Name: ") 179. 180. 181. 182. # try inserting record; try: # we will basically insert record in 'buyrequests' table. 183. runQuery("insert into buyrequests values("+buyid+",'"+clientname+"');") 184. 185. mydb.commit() print("Buy Request Sent.") 186. 187. 188. except Exception as e: print("Error Found: ",e) 189. 190. 191. 192. if choice == 5: # to check buy status # we will check if the same book_id is in acceptedrequest or not. 193. 194. 195. # get values buyid= input("Enter ID of book whose request you sent? ") 196. 197. 198. # check if any book_id matches to buyid. if checkID(int(buyid)): 199. 200. # if request has been approved we will inform the user. 201. print("Request Approved. You can take the book now!") 202. 203. # and, delete the record from acceptedrequests. 204. runQuery("delete from acceptedrequests where book_id ="+buyid+";") 205. mydb.commit() 206. 207. else: 208. print("Request Not Approved yet.") 209. 210. 211. finalChoice = input("Do You want to Continue or Not (Y or N):-") 212. 213. if finalChoice.lower() == 'n' or finalChoice.lower() == "no": 214. 215. 216. break elif finalChoice.lower() == 'y' or finalChoice.lower() == "yes": 217. 218. 219. continue else: 220. print("Invalid Choice.") 221. break 222. Initial.py Module 1. import mysql.connector as mc 2. mydb = mc.connect(user="root", host="localhost", passwd="root") 3. mycursor = mydb.cursor() 4. 5. # This function creates all database/tables in mySQL 6. def mysqlSetup(): 7. mycursor.execute("create database if not exists bookshop;") 8. mycursor.execute("use bookshop") 9. mycursor.execute("create table if not exists book(book_id int primary key, book_name varchar(100) not null, book_author varchar(50), genre varchar(30), book_price int );") 10. mycursor.execute("create table if not exists issue(book_id int, client_name varchar(30), foreign key (book_id) references book(book_id));") 11. mycursor.execute("create table if not exists buyrequests(book_idint, client_name varchar(30), foreign key (book_id) references book(book_id));") 12. mycursor.execute("create table if not exists acceptedrequests(book_id int, foreign key (book_id) references book(book_id), client_name varchar(30));") 13. 14. # Create all neccasery tables. 15. mysqlSetup() Main.py Module 1. # import required modules 2. from colorama import Fore, Back, Style 3. from maskpass import * 4. from initial import * 5. from admin import * 6. from user import * 7. 8. # set colorscheme to White. 9. print(Fore.WHITE,Style.BRIGHT) 10. 11. # get choices from user (admin or visitor) 12. print("Who are you?\n1 For Admin.\n2 For Visitor.") 13. choice = int(input("Enter Choice:- ")) 14. 15. # if user chooses admin then he needs to enter password. 16. if choice == 1: 17. 18. # get password 19. passwd = askpass("Enter Password: ") 20. if passwd == adminpasswd: # check password 21. 22. 23. admin_main() else: print("Wrong Password.") 24. 25. # if user chooses visitor, then he would be converted to visitor. 26. elif choice == 2: 27. user_main() 28. 29. # invalid choice will result in error. 30. else: 31. print("Invalid Choice.") 32. print("Thank You for using my project.") 33. print(Fore.RESET,Back.RESET,Style.NORMAL) 34. Outputs Main Menu: Admin Menu: Admin Functions: 1. View Books: 2. Enter Book Data: 3. Update Book Data: 4. Delete Book Data: 5. Check Issues: 6. Check Buy Requests: User Menu: User Functions: 1. View Books A. View all Books: B. View Books using Filters: B(1). View book using filter on Author 2. Ask Book for issue 3. Submit Book: 4. Ask book for buying: 5. Check buy Status: Structure of Tables 1. Book Table: 2. Issue Table: 3. Buy requests Table: 4. Accepted Requests Table: