SHARE
TWEET

Untitled

a guest Jan 18th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def mainMenu():
  2.     print("""
  3. ###############################################################################
  4. #                                                                             #
  5. #                            Clive's Carpets                                  #
  6. #                          Please Login Below!                                #
  7. #                                                                             #
  8. ###############################################################################
  9. """)
  10.     validateUser()
  11.    
  12. def adminMenu():
  13.     while True:
  14.         print("""
  15. ###############################################################################
  16. #                                                                             #
  17. #                            Clive's Carpets                                  #
  18. #                               Admin Menu                                    #
  19. #                                                                             #
  20. # 1 - Add a New User                                                          #
  21. # 2 - Quotes                                                                  #
  22. # 3 - Exit                                                                    #
  23. #                                                                             #
  24. ###############################################################################
  25. """)
  26.  
  27.         adminMenu = input("Which option would you like to choose? '1' , '2' or '3': ")
  28.         if adminMenu == "1":
  29.             userInput()
  30.             break
  31.         elif adminMenu == "2":
  32.             quoteMenu()
  33.             break
  34.         elif adminMenu == "3":
  35.             exit()
  36.             break
  37.    
  38.  
  39. def userMenu():
  40.     print("\nUser Menu")
  41.     userMenu = input("\nDo you wish to create a new quote? 'Yes' 'No': ")
  42.     if userMenu.lower() == "yes":
  43.         newQuote()
  44.     elif userMenu.lower() == "no":        
  45.         exit()
  46.     else:
  47.         userMenu()
  48.  
  49. def newQuote():
  50.  
  51.     CARPET = 22.50
  52.     carpetCost = 0
  53.     GRIPPER = 1.10
  54.     gripperCost = 0
  55.     RATE = 65
  56.     labour = 0
  57.     underlayPicker = 0
  58.     underlay = 0
  59.     underlayCost = 0
  60.     width = 0
  61.     length = 0
  62.     perimeter = 0
  63.     squareMeter = 0
  64.     rawMaterialsCost = 0
  65.     totalCost = 0]
  66.  
  67.     quotationCount=len(open("quotes.txt","r").readlines( ))
  68.     quotationID = "CC"+str(quotationCount+1)
  69.    
  70.     while True:
  71.         customerID=input("\nInput the Customer ID: ")
  72.         if len(customerID)>12:
  73.             print("\nCustomerID has to be less than 12 characters (5 characters House Number + 7 character Postcode")
  74.         else:
  75.             break
  76.     while True:
  77.         length=float(input("\nInput the total length of the room (m): "))
  78.         if length>30:
  79.             print("\nRoom Is too long!")
  80.         else:
  81.             break
  82.     while True:
  83.         width=float(input("\nInput the total width of the room (m): "))
  84.         if width>5:
  85.             print("\nRoom is too wide!")
  86.         else:
  87.             break
  88.     while True:
  89.         perimeter=float(input("\nInput the total perimeter of the room (m): "))
  90.         if perimeter>300:
  91.             print("\nYou had better double check!")
  92.         else:
  93.             break
  94.     while True:
  95.         print("""
  96. ###############################################################################
  97. #                                                                             #
  98. #                            Clive's Carpets                                  #
  99. #                            Underlay Picker                                  #
  100. #                                                                             #
  101. #   Which underlay would the customer like:                                   #
  102. #      1 - First Step:    £5.99 per square meter                              #
  103. #      2 - Monarch:       £7.99 per square meter                              #
  104. #      3 - Royal:         £60.00 per square meter                             #
  105. #                                                                             #
  106. #      4 - Exit                                                               #
  107. #                                                                             #
  108. ###############################################################################
  109. """)
  110.         underlayPicker=input("Which underlay would the customer like? Option '1', '2', '3' or '4': ")
  111.         if underlayPicker =="1":
  112.             underlay = 5.99
  113.             break
  114.         elif underlayPicker =="2":
  115.             underlay = 7.99
  116.             break
  117.         elif underlayPicker =="3":
  118.             underlay = 60
  119.             break
  120.         elif underlayPicker =="4":
  121.             quit()
  122.         else:
  123.             print("\nThat is not a valid entry you must select '1', '2', '3' or '4'")
  124.  
  125.     squareMeter = length * width
  126.     squareMeter = float(str(round(squareMeter, 2,)))
  127.     perimeter = round(perimeter + 0.49)
  128.     carpetCost = squateMeter * CARPET
  129. def quoteMenu():
  130.  
  131.     quoteMenu()
  132. def userInput():
  133.     userType, username, password1, password2 = "", "", "", ""
  134.     while True:
  135.        
  136.         userType = input("What type of user are you creating?\n(1) Admin \n(2) Defnyddiwr \n")
  137.         if userType == "-1":
  138.             mainMenu()
  139.         if len(userType) > 1:
  140.             print("\nInvalid Input.\n")
  141.         elif userType.isdigit() != True:
  142.             print("Please enter a number!")
  143.         elif int(userType) <1:
  144.             print("\nInvalid Input.\n")
  145.         elif int(userType) >2:
  146.             print("\nInvalid Input.\n")
  147.         else:
  148.             break
  149.     while True:
  150.         username = input("\nPlease enter the username of the new user: ")
  151.         if username == "-1":
  152.             mainMenu()
  153.         if len(username) >10:
  154.             print("\nThe username must be less than 11 characters.\n")
  155.         elif username.isalpha() == False:
  156.             print("\nThe username must only contain alpha.\n")
  157.         else:
  158.             break
  159.     while True:
  160.         password1 = input("\nPlease enter the password for the user: ")
  161.         if password1 == "-1":
  162.             mainMenu()
  163.         if len(password1) > 10:
  164.             print("\nThe password must be less than 11 characters.\n")
  165.         password2 = input("\nPlease enter the password again: ")
  166.         if password2 == "-1":
  167.             mainMenu()
  168.         if len(password2) > 10:
  169.             print("\nThe password must be less than 11 characters.\n")
  170.         if password1 != password2:
  171.             print("\nThe password does not match,retry.\n")
  172.         else:
  173.             break
  174.     while True:
  175.         FirstName = input("\nPlease enter your first name: ")
  176.         if FirstName == "-1":
  177.             mainMenu()
  178.         if len(FirstName) >25:
  179.             print("\nYour first name must be less than 25 characters.\n")
  180.         else:
  181.             break
  182.     while True:
  183.         Surname = input("\nPlease enter your surname: ")
  184.         if Surname == "-1":
  185.             mainMenu()
  186.         if len(Surname) >25:
  187.             print("\nYour surname must be less than 25 characters.\n")
  188.         else:
  189.             break
  190.     while True:
  191.         Telephone = input("\nPlease enter your telephone: ")
  192.         try:
  193.             int(Telephone)
  194.         except:
  195.             print("The telephone number must be a number")
  196.         if Telephone == "-1":
  197.             mainMenu()
  198.         if len(Telephone) >16:
  199.             print("\nThe telephone number must be less than 16 characters.\n")
  200.         else:
  201.             break
  202.     while True:
  203.         Town = input("\nPlease enter your town: ")
  204.         if Town == "-1":
  205.             mainMenu()
  206.         if len(Town) >15:
  207.             print("\nYour town must be less than 15 characters.\n")
  208.         else:
  209.             break
  210.        
  211.        
  212.        
  213.     username = username.lower()
  214.     password1 = password1.lower()
  215.     password2 = password2.lower()
  216.     FirstName = FirstName.lower()
  217.     Surname = Surname.lower()
  218.     Telephone = Telephone.lower()
  219.     Town = Town.lower()
  220.      
  221.     userTypeStore = str(userType).ljust(2)
  222.     usernameStore = username.ljust(10)
  223.     passwordStore = password1.ljust(10)
  224.     FirstNameStore = FirstName.ljust(25)
  225.     SurnameStore = Surname.ljust(25)
  226.     TelephoneStore = Telephone.ljust(16)
  227.     TownStore = Town.ljust(15)
  228.  
  229.     store = open("users.txt","a")
  230.     iStore = usernameStore + passwordStore + userTypeStore + FirstNameStore + SurnameStore + TelephoneStore + TownStore + "\n"
  231.     store.write(iStore)
  232.     store.close()
  233.  
  234.     print("\nNew User Created: ")
  235.     print("Usertype: ",userType)
  236.     print("Username: ",username)
  237.     print("Password: ",("*"*len(password1)))
  238.     print("First Name: ",FirstName)
  239.     print("Surname: ",Surname)
  240.     print("Telephone: ",Telephone)
  241.     print("Town: ",Town)
  242.  
  243.     mainMenu()
  244.  
  245.  
  246. def validateUser():
  247.     validateUserType = ""
  248.     validateUsername = ""
  249.     validatePassword = ""
  250.  
  251.     username = str(input("\nPlease enter your username: \n"))
  252.     password = str(input("\nPlease enter your password: \n"))
  253.  
  254.     while True:
  255.         try:
  256.             readUsers = open("users.txt","r")
  257.             validateCounter = 0
  258.  
  259.             while True:
  260.                 location = readUsers.readline()
  261.                 validateUserType = location[20:22]
  262.                 validateUserType = validateUserType.strip()
  263.  
  264.                 validateUsername = location [0:10]
  265.                 validateUsername = validateUsername.strip()
  266.                 validateUsername = validateUsername.lower()
  267.                 username = username.lower()
  268.  
  269.                 validatePassword = location[10:20]
  270.                 validatePassword = validatePassword.strip()
  271.                 validatePassword = validatePassword.lower()
  272.                 password = password.lower()
  273.  
  274.                
  275.  
  276.                 if location == "":
  277.                     readUsers.close()
  278.                     break
  279.                 if validateUserType == str(1) and validateUsername == username and validatePassword == password:
  280.                     validateCounter = validateCounter + 1
  281.                     adminMenu()
  282.                     break
  283.                 if validateUserType == str(2) and validateUsername == username and validatePassword == password:
  284.                     validateCounter = validateCounter + 1
  285.                     userMenu()
  286.                     break
  287.  
  288.             if validateCounter ==0:
  289.                 print("\nThere is no user in the file with those login details. \n")
  290.                 validateUser()
  291.         except FileNotFoundError:
  292.             print("There is no Users file for you to search! How about making your first account?\nTop Tip, make it a System Administrator Account!\n")
  293.             userInput()
  294.  
  295. def main():
  296.     mainMenu()
  297.  
  298.  
  299. main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top