Skip to content

Commit 9f67c22

Browse files
authored
Merge pull request #1 from OJASisLive/master
Master
2 parents 2fc82b1 + d6b3f72 commit 9f67c22

File tree

3 files changed

+126
-5
lines changed

3 files changed

+126
-5
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
__pycache__/
22
firsttime.txt
3-
cred.dat
3+
cred.dat
4+
links.txt

accounttype.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
def acctype():
2+
while True:
3+
print("--------------Account Selector Menu--------------")
4+
print("1.Admin.")
5+
print("2.Employee.")
6+
print("3.Client.")
7+
print("Enter 0 to end process.")
8+
a=int(input("\nEnter your account type:"))
9+
10+
if a==1:
11+
b=input("\nEnter admin password:")
12+
if b=="admin123":
13+
return 1
14+
else:
15+
print("\nWrong password!\n")
16+
17+
elif a==2:
18+
b=input("\nEnter employee password:")
19+
if b=="emp123":
20+
return 2
21+
else:
22+
print("\nWrong password!\n")
23+
24+
elif a==3:
25+
return 3
26+
27+
elif a==0:
28+
print("\nShutting down the program.")
29+
break
30+
31+
else:
32+
print("\nWrong input!")

setup.py

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,81 @@
33
import pickle
44
import mysql.connector
55

6+
from mysql.connector import errorcode
67

8+
TABLES = {}
9+
TABLES['employees'] = (
10+
"CREATE TABLE `employees` ("
11+
" `emp_no` int(5) NOT NULL AUTO_INCREMENT,"
12+
" `birth_date` date NOT NULL,"
13+
" `first_name` varchar(15) NOT NULL,"
14+
" `last_name` varchar(15) NOT NULL,"
15+
" `gender` enum('M','F') NOT NULL,"
16+
" `hire_date` date NOT NULL,"
17+
" `age` int(2) NOT NULL,"
18+
" PRIMARY KEY (`emp_no`)"
19+
") ")
20+
21+
TABLES['clients'] = (
22+
"CREATE TABLE `clients` ("
23+
" `acc_no` int(5) NOT NULL AUTO_INCREMENT PRIMARY KEY,"
24+
" `acc_type` enum('S','C') NOT NULL,"
25+
" `first_name` varchar(15) NOT NULL,"
26+
" `last_name` varchar(15) NOT NULL,"
27+
" `gender` enum('M','F') NOT NULL,"
28+
" `birth_date` date NOT NULL,"
29+
" `acc_creation_date` date NOT NULL,"
30+
" `mobile_no` int(10) NOT NULL,"
31+
" `email_id` varchar(25) NOT NULL"
32+
") "
33+
)
34+
35+
TABLES['savings'] = (
36+
"CREATE TABLE `savings` ("
37+
" `acc_no` int(5) NOT NULL,"
38+
" `balance` int NOT NULL,"
39+
" `loan` enum('YES','NO') NOT NULL,"
40+
" PRIMARY KEY (`acc_no`),"
41+
" FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)"
42+
") "
43+
)
44+
45+
TABLES['current'] = (
46+
"CREATE TABLE `current` ("
47+
" `acc_no` int(5) NOT NULL,"
48+
" `balance` int NOT NULL,"
49+
" `overdraft` int NOT NULL,"
50+
" PRIMARY KEY (`acc_no`),"
51+
" FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)"
52+
") "
53+
)
54+
55+
TABLES['loan'] = (
56+
"CREATE TABLE `loan` ("
57+
" `acc_no` int(5) NOT NULL,"
58+
" `loan_type` enum('PL','HL','EL','TL','BL') NOT NULL,"
59+
" `loan_amt` int NOT NULL,"
60+
" `time_period_months` int NOT NULL,"
61+
" `iterest_perc_per_annum` int(1) NOT NULL,"
62+
" `amt-per-month` int NOT NULL,"
63+
" `remaining_amt` int NOT NULL,"
64+
" PRIMARY KEY (`acc_no`),"
65+
" FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)"
66+
") "
67+
)
68+
69+
TABLES['overdraft']=(
70+
"CREATE TABLE `overdraft` ("
71+
" `acc_no` int(5) NOT NULL,"
72+
" `overdraft_amt` int NOT NULL,"
73+
" `od_with_interest_remaining` int NOT NULL,"
74+
" PRIMARY KEY (`acc_no`),"
75+
" FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)"
76+
") "
77+
)
78+
79+
80+
############################################################################################
781
query=""
882
Password=""
983
Database=""
@@ -40,9 +114,24 @@ def querycheck():
40114
if conn!="":
41115
if conn.is_connected:
42116
print("Connection established successfully.")
43-
with open("firsttime.txt","w") as f:
44-
f.write("False")
45-
ans=True
117+
if check.check()==True:
118+
cursor=conn.cursor()
119+
#Table creation
120+
for table_name in TABLES:
121+
table_description = TABLES[table_name]
122+
try:
123+
print("Creating table {}: ".format(table_name), end='')
124+
cursor.execute(table_description)
125+
except mysql.connector.Error as err:
126+
if err.errno == errorcode.ER_TABLE_EXISTS_ERROR:
127+
print("already exists.")
128+
else:
129+
print(err.msg)
130+
else:
131+
print("OK")
132+
with open("firsttime.txt","w") as f:
133+
f.write("False")
134+
ans=True
46135

47136
if not ans:
48137
print("There was a problem in connection")
@@ -81,4 +170,3 @@ def setup():
81170
else:
82171
if querycheck():
83172
connectionquery()
84-
setup()

0 commit comments

Comments
 (0)