-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstock.py
More file actions
291 lines (254 loc) · 9.92 KB
/
stock.py
File metadata and controls
291 lines (254 loc) · 9.92 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# -*- coding: utf-8 -*-
import sqlite3
import sys
con = sqlite3.connect('productos.db')
cursor=con.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS productos ('id' INT PRIMARY KEY NOT NULL, 'nombre' TEXT NOT NULL, 'precio' REAL , 'stock' INT, 'categoria' Text)")
cursor.execute("CREATE TABLE IF NOT EXISTS clientes ('id' INT PRIMARY KEY NOT NULL, 'nombre' TEXT NOT NULL, 'apellido' TEXT NOT NULL , 'correo' TEXT NOT NULL, 'direccion' TEXT NOT NULL,'telefono' INT )")
def banner():
print("==================================================================")
print(" ______ __ __ _____ __ __ ")
print(" / ____/___ ____ / /__________ / / / ___// /_____ _____/ /__")
print(" / / / __ \/ __ \/ __/ ___/ __ \/ / \__ \/ __/ __ \/ ___/ //_/")
print("/ /___/ /_/ / / / / /_/ / / /_/ / / ___/ / /_/ /_/ / /__/ ,< ")
print("\____/\____/_/ /_/\__/_/ \____/_/ /____/\__/\____/\___/_/|_| ")
print(" v1.0' ")
print("By Solidlucho@gmail.com 2020")
print("==================================================================")
def menu():
while True:
try:
print("")
print("MENU")
print("==================================================================")
print ("Selecciona una opción")
print("")
print ("1 - Ver Listado Stock. 6 - Ver Listado Clientes.")
print ("2 - Ingresar Producto. 7 - Ingresar Registro de Cliente.")
print ("3 - Actualizar Producto. 8 - Actualizar Registro de Clientes.")
print ("4 - Eliminar Producto. 9 - Eliminar registro de Clientes.")
print ("5 - Buscar Producto. 10 - Buscar Cliente.")
print ("")
print ("0 - Salir.")
print("==================================================================")
print("")
option=int(input("Ingrese una Opcion: "))
if option == 1:
listado()
elif option ==2:
insertar()
elif option ==3:
Actualizar()
elif option ==4:
Eliminar()
elif option ==5:
buscar()
elif option ==6:
listado2()
elif option ==7:
insertar2()
elif option ==8:
Actualizar2()
elif option ==9:
Eliminar2()
elif option ==10:
buscar2()
elif option ==0:
con.close()
break
except:
print("ingresó un caracter o número no valido.")
#FUNCIONES PRODUCTOS
def listado():
print("")
print("LISTA DE PRODUCTOS")
print("==========================================================================")
cursor.execute('SELECT * FROM productos ORDER BY id')
rows = cursor.fetchall()
formatted_row = '{:^4} {:^10} {:^20} {:^20} {:^20} '
print("")
print(formatted_row.format("ID", "NOMBRE", "PRECIO", "STOCK", "CATEGORIA"))
for Row in rows:
print("-----------------------------------------------------------------------------")
print(formatted_row.format(*Row))
print("")
print("Total de Registros encontrados: ")
print(len(rows))
print("")
def insertar():
while True:
try:
idproducto=int(input("Ingrese número de Registro: "))
break
except:
print("ingresó un caracter no valido.")
nombre2=input("Ingrese Nombre del Producto: ")
while True:
try:
precio2=float(input("Ingrese el Precio: "))
break
except:
print("ingresó un caracter no valido.")
while True:
try:
stock2=int(input("Ingrese la cantidad: "))
break
except:
print("ingresó un caracter no valido.")
categoria2=input("Ingrese que categoria pertenece: ")
valores=(idproducto, nombre2, precio2, stock2, categoria2)
cursor.execute("INSERT INTO productos VALUES (?,?,?,?,?)", valores)
con.commit()
print("")
print("Datos ingresados con exito.")
print("")
def Actualizar():
print("")
print("Atención: Verifique antes si el Id está registrado")
print("")
cursor.execute('SELECT id FROM productos')
try:
idproducto=int(input("Ingrese número de Registro: "))
except:
print("")
print("ingresó un caracter no valido.")
print("")
return
nombre2=input("Ingrese Nombre del Producto: ")
while True:
try:
precio2=float(input("Ingrese el Precio: "))
break
except:
print("ingresó un caracter no valido.")
while True:
try:
stock2=int(input("Ingrese la cantidad: "))
break
except:
print("ingresó un caracter no valido.")
categoria2=input("Ingrese que categoria pertenece: ")
cursor.execute("UPDATE productos SET nombre = ?, precio = ?, stock = ?, categoria = ? WHERE id = ?", [nombre2,precio2,stock2,categoria2,idproducto])
con.commit()
print("Datos actualizados.")
def buscar():
busqueda=input("Ingrese el NOMBRE del producto a buscar: ")
cursor.execute("select * from productos where nombre like ?", ('%'+busqueda+'%',) )
rows = cursor.fetchall()
formatted_row = '{:^4} {:^10} {:^20} {:^20} {:^20} '
print("")
print(formatted_row.format("ID", "NOMBRE", "PRECIO", "STOCK", "CATEGORIA"))
for Row in rows:
print("-----------------------------------------------------------------------------")
print(formatted_row.format(*Row))
print("")
print("Total de Registros encontrados: ")
print(len(rows))
print("")
def Eliminar():
cursor.execute('SELECT id FROM productos')
try:
idproducto=input("Ingrese número de Registro a Eliminar: ")
except:
print("")
print("ingresó un caracter no valido.")
print("")
return
cursor.execute("DELETE FROM productos WHERE id = ?", [idproducto])
con.commit()
print("")
print("Registro Eliminado.")
print("")
#-------------------------------------------------------------------------------------#
#FUNCIONES CLIENTES
def listado2():
print("")
print("LISTA DE CLIENTES")
print("==========================================================================================")
cursor.execute('SELECT * FROM CLIENTES ORDER BY id')
rows = cursor.fetchall()
formatted_row = '{:^4} {:^10} {:^20} {:^20} {:^20} {:^10} '
print("")
print(formatted_row.format("ID", "NOMBRE", "APELLIDO", "CORREO", "DIRECCIÓN", "TELEFONO"))
for Row in rows:
print("------------------------------------------------------------------------------------------")
print(formatted_row.format(*Row))
print("")
print("Total de Registros encontrados: ")
print(len(rows))
print("")
def insertar2():
while True:
try:
idcliente=int(input("Ingrese número de Registro: "))
break
except:
print("ingresó un caracter no valido.")
nombre2=input("Ingrese Nombre del Cliente: ")
apellido2=input("Ingrese Apellido del Cliente: ")
correo2=input("Ingrese el correo electronico: ")
direccion2=input("Ingrese la dirección del cliente: ")
telefono2=input("Ingrese el Telefono del cliente: ")
valores=(idcliente,nombre2,apellido2,correo2,direccion2,telefono2)
cursor.execute("INSERT INTO clientes VALUES (?,?,?,?,?,?)", valores)
con.commit()
print("")
print("Datos ingresados con exito.")
print("")
def Actualizar2():
print("")
print("Atención: Verifique antes si el Id está registrado")
print("")
cursor.execute('SELECT id FROM clientes')
try:
idcliente=int(input("Ingrese número de Registro: "))
except:
print("")
print("ingresó un caracter no valido.")
print("")
return
nombre2=input("Ingrese Nombre del Cliente: ")
apellido2=input("Ingrese Apellido del Cliente: ")
correo2=input("Ingrese el correo electronico: ")
direccion2=input("Ingrese la dirección del cliente: ")
telefono2=input("Ingrese el Telefono del cliente: ")
cursor.execute("UPDATE clientes SET nombre = ?, apellido = ?, correo = ?, direccion = ?, telefono = ? WHERE id = ?", [nombre2,apellido2,correo2,direccion2,telefono2,idcliente])
con.commit()
print("")
print("Datos actualizados.")
print("")
def buscar2():
busqueda=input("Ingrese el NOMBRE del Cliente a buscar: ")
cursor.execute("select * from clientes where nombre like ?", ('%'+busqueda+'%',) )
print("")
print("RESULTADO DE BUSQUEDA:")
print("==================================================================")
rows = cursor.fetchall()
formatted_row = '{:^4} {:^10} {:^20} {:^20} {:^20} {:^10} '
print("")
print(formatted_row.format("ID", "NOMBRE", "APELLIDO", "CORREO", "DIRECCIÓN", "TELEFONO"))
for Row in rows:
print("------------------------------------------------------------------------------------------")
print(formatted_row.format(*Row))
print("")
print("Total de Registros encontrados: ")
print(len(rows))
print("")
def Eliminar2():
cursor.execute('SELECT id FROM clientes')
try:
idcliente=int(input("Ingrese NÚMERO de Registro a Eliminar: "))
except:
print("")
print("ingresó un caracter no valido.")
print("")
return
cursor.execute("DELETE FROM clientes WHERE id = ?", [idcliente])
con.commit()
print("")
print("Registro Eliminado.")
print("")
#-------------------------------------------------------------------------------------#
if __name__ == "__main__":
banner()
menu()