-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
170 lines (149 loc) · 5.34 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#make this the main python program of the code, the one that routes everything through it.
#this file is the one that will connect to the database
#the functions should be stored in a folder "functions"
import random
import mysql.connector as mc
from dotenv import load_dotenv
import os
import Functions.supplier as supplier
import Functions.inventory as inventory
import Functions.transaction as transaction
load_dotenv()
passw = input("Please Enter the Password to MYSQL:- ")
db_connection = mc.connect(host="localhost", user = "root", password = passw )
curs = db_connection.cursor()
curs.execute("CREATE DATABASE IF NOT EXISTS test1")#change database after testing
db_connection.close()
#opening database
test_connection = mc.connect(host="localhost",database="test1",user = "root",password = passw)
cur = test_connection.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS Products(
PRODUCT_ID int PRIMARY KEY,
PRODUCT_NAME varchar(255),
SUPPLIER varchar(255),
COST_PRICE int,
SELLING_PRICE int,
INVENTORY int,
UNIQUE (PRODUCT_ID)
);""")
cur.execute("""CREATE TABLE IF NOT EXISTS `Users` (
`UserID` INT,
`UserName` VARCHAR(255),
`Password` VARCHAR(255),
`Role` VARCHAR(255),
`Name` VARCHAR(255),
PRIMARY KEY (`UserID`));""")
transaction1= transaction.transactions(cur, passw)
def ran_num():
valid_digits = [1, 2, 3, 4, 5, 6, 7, 8, 9]
random_number = ''.join([str(random.choice(valid_digits)) for i in range(6)])
return random_number
def table_exists(name):
cur.execute("Show tables like %s",(name,))
return cur.fetchone() is not None
def create_user():
name = input("What is your name?:- ")
username = input("What would you like your Username to be:- ")
cur.execute("Select * from Users where username=%s ",(username,))
exis_user = cur.fetchone()
if exis_user:
print("Username Already Exists, Please Restart")
return
else:
password = input("Pease Enter your desired password:- ")
role = input("What is your role?:- ")
userid = ran_num()
cur.execute("Select * from Users where userid=%s",(userid,))
exis_num = cur.fetchone()
if exis_num:
userid = ran_num()
insert_q = "INSERT INTO Users (USERID,USERNAME,PASSWORD,ROLE,NAME) VALUES (%s,%s,%s,%s,%s)"
values = (userid,username,password,role,name)
cur.execute(insert_q,values)
test_connection.commit()
print("User Added Sucessfully")
def login():
user = input("Please Enter your Username:- ")
password = input('Please Enter your Password:- ')
table_name = 'Users'
cur.execute("SELECT * FROM Users WHERE username=%s", (user,))
exis_user = cur.fetchone()
if not exis_user:
print("Username does not exist.")
return
real_pass = exis_user[2]
if password == real_pass:
print("""
Welcome to the Inventory Management Software
Reply with 1 to get data on all prodcuts
Reply with 2 to add a product
Reply with 3 to modify a product
Reply with 4 to fetch details about a product
Reply with 5 to delete a product
Reply with 6 to view Supplier data
Reply with 7 to remove Supplier
Reply with 8 to switch to Transactions
Reply with Q to Quit
""")
while True:
x = input("-->")
if x == "1":
inventory.view_data(cur,test_connection)
inventory.checkStock(cur)
elif x=="2":
inventory.add_product(cur,test_connection)
elif x=="3":
inventory.modify(cur,test_connection)
elif x=="4":
inventory.fetch(cur,test_connection)
elif x=="5":
inventory.del_product(cur,test_connection)
elif x=="6":
supplier.supplierData(cur)
elif x=="7":
supplier.removeSupplier(cur,test_connection)
elif x=="8":
transaction_cursor = transaction1.cursor()
while True:
print("""
Welcome to the Inventory Management Software
Reply with 1 to view transactions
Reply with 2 to add a transaction
Reply with 3 to modify a transaction
Reply with 4 to fetch details about a transaction
Reply with 5 to delete a transaction
Reply with 6 to view transaction data
Reply with 7 to remove transaction
Reply with Q to exit Transactions
""")
act=input("-->")
if act==1:
inventory.view_data(transaction_cursor)
elif act=="q".upper():
print("""
Welcome to the Inventory Management Software
Reply with 1 to get data on all prodcuts
Reply with 2 to add a product
Reply with 3 to modify a product
Reply with 4 to fetch details about a product
Reply with 5 to delete a product
Reply with 6 to view Supplier data
Reply with 7 to remove Supplier
Reply with 8 to switch to Transactions
Reply with Q to Quit
""")
break
elif x.upper()=="Q":
break
else:
print("idk what happened")
else:
print("Wrong Password")
x = int(input("""
Please Enter 1 to Login
Please Enter 2 to Create a New Account
-->"""))
if x == 1:
login()
if x == 2:
create_user()