Advertisement
ALENTL

Untitled

Oct 8th, 2022
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. import mysql.connector as mc
  2. import os
  3.  
  4. cnx = mc.connect(host="localhost", user="alen", password="alen")
  5. cur = cnx.cursor()
  6.  
  7. def sql_connected():
  8. if cnx.is_connected():
  9. return 1
  10.  
  11. def login(username, passwd):
  12. cur.execute("SELECT * FROM USER_LOGIN WHERE USERNAME='' AND PASSWORD=''".format(username, passwd))
  13.  
  14. data = cur.fetchall()
  15.  
  16. if any(data):
  17. return 1
  18.  
  19. else:
  20. return 0
  21.  
  22. while True:
  23. print("1. Check the connection status of the program")
  24. print("2. Setting up the database and tables")
  25. print("3. Login to the Ebin Automobiles")
  26. print("4. Exit the program")
  27.  
  28. ch = int(input("Enter your selection: "))
  29.  
  30. if ch == 1:
  31. print("1. You selected to check the connection status of the program")
  32. c = sql_connected()
  33.  
  34. if c == 1:
  35. print("Program successfully connected with the sql server")
  36. continue
  37.  
  38. else:
  39. print("Connection to the sql server failed. Pls fix the bug and retry")
  40. break
  41.  
  42. elif ch == 2:
  43. print("Set up the database and tables")
  44. cur.execute("CREATE DATABASE IF NOT EXISTS AUTO_MOBILE_SERVICE_STATION")
  45. cur.execute("USE AUTO_MOBILE_SERVICE_STATION")
  46. cur.execute("CREATE TABLE IF NOT EXISTS CUSTOMER_DETAILS(SNO INT PRIMARY KEY, CNAME VARCHAR(25), CDETAILS VARCHAR(30), CADDRESS VARCHAR(30), CPINCODE INT, CPURAMT INT, CDISK FLOAT)")
  47.  
  48. elif ch == 3:
  49. user = input("Enter your login username: ")
  50. passwd = input("Enter your password: ")
  51.  
  52. d = login(user, passwd)
  53.  
  54. if d == 1:
  55. print("You successfully logged into the store")
  56. continue
  57.  
  58. else:
  59. print("Invalid combination of username or password")
  60. print("Please try again")
  61. break
  62.  
  63. while True:
  64. print("Welcome TO EK Automobile Services")
  65. print()
  66. print("1. Service station")
  67. print("2. Go back to previous menu")
  68.  
  69. cn = int(input("Enter your selection: "))
  70.  
  71. if cn == 1:
  72. print("Add a new customer to EK Services")
  73.  
  74. sno = int(input("Enter the serial number: "))
  75. cname = input("Enter customer name: ")
  76. cdetails = input("Enter customer details: ")
  77. caddress = input("Enter customer address: ")
  78. cpincode = int(input("Enter customer address pincode"))
  79. puramt = int(input("Enter customer purchase amount: "))
  80. cdisc = float("Enter the discount amount: ")
  81.  
  82. cur.execute("INSERT INTO CUSTOMER_DETAILS VALUES (str(sno), cname, cdetails, caddress, cpincode, puramt, cdisk)")
  83.  
  84. cnx.commit()
  85. print("New customer added to store")
  86.  
  87.  
  88. elif ch == 4:
  89. print("Thank you for using me")
  90. quit()
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement