-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodMACROLeerOfertas.bas
More file actions
191 lines (148 loc) · 5.26 KB
/
Copy pathmodMACROLeerOfertas.bas
File metadata and controls
191 lines (148 loc) · 5.26 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
Attribute VB_Name = "modMACROLeerOfertas"
'@Folder "3-Dominio.d-Ofertas.Gestion"
Option Explicit
Private Const MODULE_NAME As String = "modMACROLeerOfertas"
Const RUTA_BD As String = "C:\Program Files (x86)\Ofertas_Gas\BaseDatos\Ofertas_Gas.mdb"
Function isGUID(ByVal strGUID)
Attribute isGUID.VB_Description = "[modMACROLeerOfertas] is GUID (función personalizada)"
Attribute isGUID.VB_ProcData.VB_Invoke_Func = " \n21"
If IsNull(strGUID) Then
isGUID = False
Exit Function
End If
Dim regEx
Set regEx = New RegExp
regEx.Pattern = "[0-9A-Fa-f]{8}-(?:[0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}"
isGUID = regEx.Test(strGUID)
Set regEx = Nothing
End Function
'=========================================================
'@Description: Lee una oferta desde Access y vuelca sus datos generales en Excel
'@Scope: Prueba desde Excel
'@ArgumentDescriptions: -
'@Returns: Nothing
'@Category: Test
'=========================================================
Public Sub Test_LeerOfertas()
Attribute Test_LeerOfertas.VB_ProcData.VB_Invoke_Func = " \n0"
Const OFER_ID As String = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
Dim ctx As clsDBContext
Dim repo As clsOfertaRepository
Dim of As clsOferta
Dim dg As tOfertasDatosGenerales
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Oferta")
ws.Cells.Clear
Set ctx = New clsDBContext
ctx.Conectar RUTA_BD
Set repo = New clsOfertaRepository
repo.SetDBContext ctx
Set of = repo.LeerPorOferID(OFER_ID)
dg = of.DatosGenerales
' Cabeceras
ws.Range("A1:F1").Value = Array( _
"OFER_ID", "OFER_NUM_OFERTA", "OFER_FECHA", _
"OFER_CLIENTE", "GASE_ID", "OFER_OBSERVACIONES")
' Datos
ws.Range("A2").Value = dg.OFER_ID
ws.Range("B2").Value = dg.OFER_NUM_OFERTA
ws.Range("C2").Value = dg.OFER_FECHA
ws.Range("D2").Value = dg.OFER_CLIENTE
ws.Range("E2").Value = dg.GASE_ID
ws.Range("F2").Value = dg.OFER_OBSERVACIONES
ctx.Desconectar
MsgBox "Oferta cargada correctamente", vbInformation
End Sub
'=========================================================
'@Description: Lee una oferta y vuelca la tabla OfertasOtros en Excel
'@Scope: Prueba desde Excel
'@ArgumentDescriptions: -
'@Returns: Nothing
'@Category: Test
'=========================================================
Public Sub Test_LeerOfertaConOtros()
Attribute Test_LeerOfertaConOtros.VB_ProcData.VB_Invoke_Func = " \n0"
Const OFER_ID As String = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
Dim ctx As clsDBContext
Dim repo As clsOfertaRepository
Dim of As clsOferta
Dim ws As Worksheet
Dim i As Long
Dim it As clsOfertaOtro
Set ws = ThisWorkbook.Worksheets("OfertasOtros")
ws.Cells.Clear
Set ctx = New clsDBContext
ctx.Conectar RUTA_BD
Set repo = New clsOfertaRepository
repo.SetDBContext ctx
Set of = repo.LeerPorOferID(OFER_ID)
' Cabeceras
ws.Range("A1:C1").Value = Array( _
"OFOT_LINEA", "OFOT_DESCRIPCION", "OFOT_PRE_COSTE")
' Datos
For i = 1 To of.Otros.Count
Set it = of.Otros(i)
ws.Cells(i + 1, 1).Value = it.OFOT_LINEA
ws.Cells(i + 1, 2).Value = it.OFOT_DESCRIPCION
ws.Cells(i + 1, 3).Value = it.OFOT_PRE_COSTE
Next i
ctx.Desconectar
MsgBox "OfertasOtros volcadas correctamente", vbInformation
End Sub
'@Description: Lee todas las ofertas desde Access y las vuelca masivamente en una hoja de Excel
'@Scope: Excel VBA ? Base de datos Access (lectura)
'@ArgumentDescriptions: -
'@Returns: Nothing
'@Category: Exportación / Ofertas
Public Sub Test_VolcarTodasLasOfertasAExcel()
Attribute Test_VolcarTodasLasOfertasAExcel.VB_ProcData.VB_Invoke_Func = " \n0"
Dim ctx As clsDBContext
Dim repo As clsOfertaRepository
Dim ofertas As Collection
Dim of As clsOferta
Dim dg As tOfertasDatosGenerales
Dim ws As Worksheet
Dim fila As Long
'----------------------------------
' Preparar hoja destino
'----------------------------------
Set ws = ActiveWorkbook.Worksheets("Ofertas")
ws.Cells.Clear
ws.Range("A1:F1").Value = Array( _
"OFER_ID", _
"OFER_NUM_OFERTA", _
"OFER_FECHA", _
"OFER_CLIENTE", _
"GASE_ID", _
"OFER_OBSERVACIONES")
fila = 2
'----------------------------------
' Conectar a base de datos
'----------------------------------
Set ctx = New clsDBContext
ctx.Conectar RUTA_BD
Set repo = New clsOfertaRepository
repo.SetDBContext ctx
'----------------------------------
' Leer repositorio completo
'----------------------------------
Set ofertas = repo.LeerTodas()
'----------------------------------
' Volcado masivo
'----------------------------------
For Each of In ofertas
dg = of.DatosGenerales
ws.Cells(fila, 1).Value = dg.OFER_ID
ws.Cells(fila, 2).Value = dg.OFER_NUM_OFERTA
ws.Cells(fila, 3).Value = dg.OFER_FECHA
ws.Cells(fila, 4).Value = dg.OFER_CLIENTE
ws.Cells(fila, 5).Value = dg.GASE_ID
ws.Cells(fila, 6).Value = dg.OFER_OBSERVACIONES
fila = fila + 1
Next of
'----------------------------------
' Limpieza
'----------------------------------
ctx.Desconectar
MsgBox ofertas.Count & " ofertas volcadas correctamente.", vbInformation
End Sub