· 6 years ago · Nov 03, 2019, 07:48 AM
1import sqlite3
2conn = sqlite3.connect("OS_Employee.db")
3
4space = " "
5email = "@gmail.com"
6EmpID = input("Please enter your employee ID number: ")
7 # Error checking 1: employee ID must not be blank.
8while not EmpID or not EmpID.isdigit() or not len(EmpID) == 4:
9 if not EmpID:
10 EmpID = input("Employee ID cannot be blank. Please enter your employee ID: ")
11 continue
12 # Error checking 2: employee ID must be in numerical values only.
13 if not EmpID.isdigit():
14 EmpID = input("Employee ID must contain numbers only. Please try again: ")
15 continue
16 # Error checking 3: employee ID must be 4 digits long
17 if not len(EmpID) == 4:
18 if len(EmpID) < 4:
19 EmpID = input("Incorrect number of digits, please try again: ")
20 if len(EmpID) > 4:
21 EmpID = input("Incorrect number of digits, please try again: ")
22 continue
23
24F_Name = input("Please enter first name: ")
25F_Name.lower()
26while not F_Name or not F_Name.isalpha() or not F_Name[0].isupper():
27 if not F_Name:
28 F_Name = input ("First name cannot be blank. Please reenter your first name").lower()
29
30 continue
31 if not F_Name.isalpha():
32 if space in F_Name:
33 F_Name = input("The following contains an unecessary space. Please try again").lower()
34
35
36 else:
37 F_Name = input("The following contains characters not in the traditional alphabet. Please try again").lower()
38
39 continue
40 if not F_Name[0].isupper():
41 F_Name = F_Name.capitalize()
42 print(F_Name)
43 continue
44
45
46L_Name = input("Please enter first name: ")
47L_Name.lower()
48while not L_Name or not L_Name.isalpha() or not L_Name[0].isupper():
49 if not L_Name:
50 L_Name = input ("Last name cannot be blank. Please reenter your last name").lower()
51
52 continue
53 if not L_Name.isalpha():
54 if space in L_Name:
55 L_Name = input("The following contains an unecessary space. Please try again").lower()
56
57
58 else:
59 L_Name = input("The following contains characters not in the traditional alphabet. Please try again").lower()
60
61 continue
62 if not L_Name[0].isupper():
63 L_Name = L_Name.capitalize()
64 print(L_Name)
65 continue
66
67userEmail = input("Please enter email: ")
68while not userEmail or not email in userEmail:
69 if not userEmail:
70 userEmail = input("Email cannot be blank. Please enter your email to login in: ")
71 continue
72
73 #checks if user inputs a domain for email
74 if not email in userEmail:
75 userEmail = input("The following includes an invalid domain, please try again: ")
76 continue
77Password = input("Please enter password: ")
78
79with conn:
80 cur = conn.cursor()
81 try:
82 InsertValue = "INSERT INTO Employee VALUES ('{}','{}','{}','{}','{}')"
83 InsertString = InsertValue.format(EmpID,F_Name,L_Name,userEmail,Password)
84 cur.execute(InsertString)
85 cur.execute("SELECT*FROM Employee WHERE(EmployeeID == '{}')".format(EmpID))
86 #order of argument matters, does not know the difference between last name or employeeID.
87 results = cur.fetchone()
88 print(results)
89 except Exception as e:
90 print("connection failed" + str(e))