-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_Inventario.sql
182 lines (143 loc) · 3.84 KB
/
db_Inventario.sql
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
CREATE DATABASE db_Inventario;
USE db_Inventario;
CREATE TABLE Inventario (
ID INT PRIMARY KEY IDENTITY(1,1),
CodigoBarras VARCHAR(50),
NombreProducto VARCHAR(100),
Stock INT,
PrecioUnitario DECIMAL(10,2),
FechaIngreso DATETIME DEFAULT GETDATE()
);
INSERT INTO Inventario (CodigoBarras, NombreProducto, Stock, PrecioUnitario)
VALUES ('123456789', 'Producto Ejemplo', 100, 19.99);
select * from Inventario;
/* Insertar */
CREATE PROCEDURE InsertarProducto
@P_CodigoBarras VARCHAR(50),
@P_NombreProducto VARCHAR(100),
@P_Stock INT,
@P_PrecioUnitario DECIMAL(10,2)
AS
BEGIN
INSERT INTO Inventario (CodigoBarras, NombreProducto, Stock, PrecioUnitario)
VALUES (@P_CodigoBarras, @P_NombreProducto, @P_Stock, @P_PrecioUnitario);
END;
EXEC InsertarProducto '123456789', 'Producto Ejemplo', 100, 19.99;
/* Consultar */
Create PROC spConsulProducto
(@P_Accion SMALLINT,
@P_Texto varchar(10) = NULL)
AS
BEGIN
IF @P_Accion = 1
BEGIN
SELECT id,
CodigoBarras,
NombreProducto,
Stock,
PrecioUnitario,
FORMAT(FechaIngreso ,'dd/MM/yyyy') AS FechaIngreso
From Inventario
END
ELSE IF @P_Accion = 2
BEGIN
SELECT id,
CodigoBarras,
NombreProducto,
Stock,
PrecioUnitario,
FORMAT(FechaIngreso ,'dd/MM/yyyy') AS FechaIngreso
From Inventario
WHERE NombreProducto LIKE '%' + @P_Texto + '%'
END
ELSE IF @P_Accion = 3
BEGIN
SELECT id,
CodigoBarras,
NombreProducto,
Stock,
PrecioUnitario,
FORMAT(FechaIngreso ,'dd/MM/yyyy') AS FechaIngreso
From Inventario
WHERE CodigoBarras LIKE '%' + @P_Texto + '%'
END
END
spConsulProducto @P_Accion = 1
spConsulProducto @P_Accion = 2, @P_Texto = 'Ejemplo'
spConsulProducto @P_Accion = 3, @P_Texto = '7500435233590'
/* Modificar */
CREATE PROC spModifProducto
@P_CodigoBarras VARCHAR(50),
@P_NombreProducto VARCHAR(100),
@P_Stock INT,
@P_PrecioUnitario DECIMAL(10,2)
AS
BEGIN
SET NOCOUNT ON
UPDATE Inventario SET NombreProducto = @P_NombreProducto,
Stock = @P_Stock,
PrecioUnitario = @P_PrecioUnitario
WHERE CodigoBarras = @P_CodigoBarras
SET NOCOUNT OFF
END
spModifProducto @P_CodigoBarras = '123456789',
@P_NombreProducto = 'Nuevo Producto',
@P_Stock = 50,
@P_PrecioUnitario = 5
/* Eliminar */
CREATE PROC spBorrarProducto
(@P_idProducto INT)
AS
BEGIN
SET NOCOUNT ON
DELETE
FROM Inventario
WHERE id = @P_idProducto
SET NOCOUNT OFF
END
spBorrarProducto @P_idProducto = 2
/* Consultar productos en 0 */
CREATE PROCEDURE ObtenerProductosAgotados
AS
BEGIN
SELECT *
FROM Inventario
WHERE Stock <= 0;
END;
EXEC ObtenerProductosAgotados;
CREATE TABLE INTERFACES(
IdInterfaces SMALLINT IDENTITY(1,1) NOT NULL,
Usuario VARCHAR(25) NOT NULL,
Contraseña VARCHAR(25) NOT NULL,
UGuid VARCHAR(50) NOT NULL
CONSTRAINT DF_UGuid_INT DEFAULT (newid()),
DescripInterfaz VARCHAR (50) NOT NULL,
FecRegistro smalldatetime NOT NULL
CONSTRAINT DF_FecRegistro_INT DEFAULT (getdate()),
CONSTRAINT PK_IdInterface_INT PRIMARY KEY(IdInterfaces))
INSERT INTO INTERFACES (Usuario, Contraseña, DescripInterfaz)
VALUES ('admin','admin','UI c#')
INSERT INTO INTERFACES (Usuario, Contraseña, DescripInterfaz)
VALUES ('Juan','Juan','python')
SELECT * FROM INTERFACES
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[spValidaInterfaceTOKEN]
(@P_Usuario VARCHAR(25),
@P_Contra VARCHAR(25),
@P_Guid VARCHAR(50))
AS
BEGIN
SET NOCOUNT ON
SELECT 1 AS Resultado
FROM INTERFACES
WHERE Usuario = @P_Usuario AND
Contraseña = @P_Contra AND
UGuid = @P_Guid
SET NOCOUNT OFF
END
EXEC spValidaInterfaceTOKEN @P_Usuario = 'admin',
@P_Contra = 'admin',
@P_Guid = 'F5B0ABCD-4FD7-41D3-B8C7-E54AB7288422'