· 6 years ago · Nov 02, 2019, 11:24 PM
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3"""
4Created on Saturday Nov 2 09:07:29 2019
5
6@author: cameronlee
7"""
8import sqlite3
9conn = sqlite3.connect("OS_Employee.db")
10
11# Validating Employee ID Function
12def validateEmployID(EmpID):
13 userInput = EmpID + ""
14 # Error checking 1: employee ID must not be blank.
15 while not EmpID:
16 EmpID = input("Employee ID cannot be blank. Please enter your employee ID: ")
17 # Error checking 2: employee ID must be in numberical values only.
18 while userInput.isdigit() == False:
19 print("Employee ID must contain numbers only.")
20 return False;
21 # Error checking 3: employee ID must be 4 digits long
22 while len(userInput) != 4:
23 print("You entered more tha 4 digits. Employee ID can only be 4 digits long.")
24 return False;
25 return True;
26
27# Checking Unique Employee ID Function
28def checkUniqueEmployId(EmpID) :
29 with conn:
30 cur = conn.cursor()
31 try:
32 cur.execute("SELECT count(*) FROM Employee WHERE(EmployeeID == '{}')".format(EmpID))
33 results = cur.fetchone()
34 # Error checking 1: Tell user that the employee ID entered already exists.
35 if results[0]==1:
36 print("Employee ID already exists. Please enter your employee ID: ")
37 return False
38 return True
39 except Exception as e:
40 print("connection failed" + str(e))
41
42# Registration Function
43def registration():
44 print("==============================================")
45 print("Register New User Information")
46 print("==============================================")
47 email_domain = "@gmail.com"
48 EmpID = input("Please enter your employee ID number: ")
49 validate = False
50 while validate == False:
51 validate = validateEmployID(EmpID);
52 if validate == False:
53 EmpID =input("Please enter Employee ID again: ")
54 else:
55 validate = checkUniqueEmployId(EmpID)
56 if validate == False:
57 EmpID = input("Please enter Employee ID again: ")
58
59
60 F_Name = input("Please enter first name: ")
61 L_Name = input("Please enter last name: ")
62
63# Email Domain Validation
64 Email = input("Please enter email: ")
65 while not Email:
66 Email = input("Email cannot be blank. Please enter your email: ")
67 while not email_domain in Email:
68 print ("This is not a correct email domain. Please enter an '@gmail.com' email: ")
69 else:
70 print ("This is a correct email")
71
72 Password = input("Please enter password: ")
73
74 with conn:
75 cur = conn.cursor()
76 try:
77 InsertValue = "INSERT INTO Employee VALUES ('{}','{}','{}','{}','{}')"
78 InsertString = InsertValue.format(EmpID,F_Name,L_Name,Email, Password,)
79 cur.execute(InsertString)
80 cur.execute("SELECT*FROM Employee WHERE(EmployeeID == '{}')".format(EmpID))
81 #order of argument matters, does not know the difference between last name or employeeID.
82 results = cur.fetchone()
83 print(results)
84 except Exception as e:
85 print("connection failed" + str(e))
86registration()