diff --git a/.gitignore b/.gitignore index 4572c76..e0acd6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__/ firsttime.txt -cred.dat \ No newline at end of file +cred.dat +links.txt \ No newline at end of file diff --git a/accounttype.py b/accounttype.py new file mode 100644 index 0000000..7ba0e27 --- /dev/null +++ b/accounttype.py @@ -0,0 +1,32 @@ +def acctype(): + while True: + print("--------------Account Selector Menu--------------") + print("1.Admin.") + print("2.Employee.") + print("3.Client.") + print("Enter 0 to end process.") + a=int(input("\nEnter your account type:")) + + if a==1: + b=input("\nEnter admin password:") + if b=="admin123": + return 1 + else: + print("\nWrong password!\n") + + elif a==2: + b=input("\nEnter employee password:") + if b=="emp123": + return 2 + else: + print("\nWrong password!\n") + + elif a==3: + return 3 + + elif a==0: + print("\nShutting down the program.") + break + + else: + print("\nWrong input!") \ No newline at end of file diff --git a/setup.py b/setup.py index c5ad103..a7ccb56 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,81 @@ import pickle import mysql.connector +from mysql.connector import errorcode +TABLES = {} +TABLES['employees'] = ( + "CREATE TABLE `employees` (" + " `emp_no` int(5) NOT NULL AUTO_INCREMENT," + " `birth_date` date NOT NULL," + " `first_name` varchar(15) NOT NULL," + " `last_name` varchar(15) NOT NULL," + " `gender` enum('M','F') NOT NULL," + " `hire_date` date NOT NULL," + " `age` int(2) NOT NULL," + " PRIMARY KEY (`emp_no`)" + ") ") + +TABLES['clients'] = ( + "CREATE TABLE `clients` (" + " `acc_no` int(5) NOT NULL AUTO_INCREMENT PRIMARY KEY," + " `acc_type` enum('S','C') NOT NULL," + " `first_name` varchar(15) NOT NULL," + " `last_name` varchar(15) NOT NULL," + " `gender` enum('M','F') NOT NULL," + " `birth_date` date NOT NULL," + " `acc_creation_date` date NOT NULL," + " `mobile_no` int(10) NOT NULL," + " `email_id` varchar(25) NOT NULL" + ") " +) + +TABLES['savings'] = ( + "CREATE TABLE `savings` (" + " `acc_no` int(5) NOT NULL," + " `balance` int NOT NULL," + " `loan` enum('YES','NO') NOT NULL," + " PRIMARY KEY (`acc_no`)," + " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + ") " +) + +TABLES['current'] = ( + "CREATE TABLE `current` (" + " `acc_no` int(5) NOT NULL," + " `balance` int NOT NULL," + " `overdraft` int NOT NULL," + " PRIMARY KEY (`acc_no`)," + " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + ") " +) + +TABLES['loan'] = ( + "CREATE TABLE `loan` (" + " `acc_no` int(5) NOT NULL," + " `loan_type` enum('PL','HL','EL','TL','BL') NOT NULL," + " `loan_amt` int NOT NULL," + " `time_period_months` int NOT NULL," + " `iterest_perc_per_annum` int(1) NOT NULL," + " `amt-per-month` int NOT NULL," + " `remaining_amt` int NOT NULL," + " PRIMARY KEY (`acc_no`)," + " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + ") " +) + +TABLES['overdraft']=( + "CREATE TABLE `overdraft` (" + " `acc_no` int(5) NOT NULL," + " `overdraft_amt` int NOT NULL," + " `od_with_interest_remaining` int NOT NULL," + " PRIMARY KEY (`acc_no`)," + " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + ") " +) + + +############################################################################################ query="" Password="" Database="" @@ -40,9 +114,24 @@ def querycheck(): if conn!="": if conn.is_connected: print("Connection established successfully.") - with open("firsttime.txt","w") as f: - f.write("False") - ans=True + if check.check()==True: + cursor=conn.cursor() + #Table creation + for table_name in TABLES: + table_description = TABLES[table_name] + try: + print("Creating table {}: ".format(table_name), end='') + cursor.execute(table_description) + except mysql.connector.Error as err: + if err.errno == errorcode.ER_TABLE_EXISTS_ERROR: + print("already exists.") + else: + print(err.msg) + else: + print("OK") + with open("firsttime.txt","w") as f: + f.write("False") + ans=True if not ans: print("There was a problem in connection") @@ -81,4 +170,3 @@ def setup(): else: if querycheck(): connectionquery() -setup()