-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeneral.bas
1246 lines (910 loc) · 36.3 KB
/
General.bas
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Attribute VB_Name = "General"
'---------------------------------------------------------------------------------------
' Module : General
' DateTime : 12/10/2003 02:16
' Author : Administrador
' Purpose :
'---------------------------------------------------------------------------------------
Option Explicit
'La conexión al servidor local
Public locCnn As New ADODB.Connection
Public strLocCnn As String
'La conexión al servidor local para el proveedor MSDATASHAPE
Public locCnnSP As New ADODB.Connection
Public strLocCnnSP As String
'La conexión al servidor local, a la base de datos de configuración
Public EmpCnn As New ADODB.Connection
Public strEmpCnn As String
'La conexión al servidor CENTRAL (REMOTO)
Public SrvCnn As New ADODB.Connection
Public strSrvCnn As String
Public UsarTimerIP As Long
Private Const Version = "2.0.0"
Public Const titulo = "PC Gestion " & Version
Public Const Separacion_MDIForm = 10
Private crystalr As Object 'para almacenar el crystal report
Const dir_rpts = "\Reports\"
Const rpt_etiquetas = "codbar.rpt"
Const rpt_totTrn = "tottrn.rpt"
Const rpt_totPed = "totped.rpt"
Const rpt_totPedT = "totpedt.rpt"
'Almacena la temporada actual de trabajo.
Public TemporadaActual As Byte
'Almacena el almacen actual de trabajo (para transferencias). Este
'valor es obtenido al autentificar el usuario.
Public AlmacenActual As Byte
'Almacena el CODIGO de usuario actual
Public UsuarioActual As Integer
'Almacena la CAJA asignada al usuario
Public CajaActual As Byte
'Almacena el CENTRO asignado al usuario actual
Public CentroActual As Byte
'Almacena las lineas del ticket
Public LineasTicket(5) As String
'define el codigo X en las ventas para crear un arreglo rapidamente
Public Const CodigoArreglos = 5
'Aqui se define el tipo de servidor
' 1 - MSSQL
' 2 - MySQL
Public Const TipoServer = 1
'_____________________________________________________________
'Almacena el TIPO DE PERMISO para el usuario actual
Public TipoPermiso As Byte
' 0 -> dependiente comun (minimo permiso)
' 1 -> supervisor (permiso total)
'_____________________________________________________________
'Tamaño en caracteres del código de barras:
'5 codigo articulo
'3 temporada
'2 talla
'3 color
Public Const LenCodBar = 13
Public Type MiCodBar
CODIGO_ART As String * 5
TEMPORADA_ART As String * 3
TALLA_ART As String * 2
COLOR_ART As String * 3
End Type
'Caracter de moneda (€, o el caracter que sea)
Public SimboloMoneda As String * 1
Public Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long
Public Enum MakeAsModal
Modal = 0
Modalless = 1
End Enum
'cadena de conexion para los mdb de access 2000.
Public Const strCnnMdb = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source="
'la conexión al servidor remoto
'Public srvCnn As New ADODB.Connection
'Public Const sRmtCnn = "PROVIDER=MSDASQL;dsn=SQLSER;uid=;pwd=;"
'Devuelve un campo pedido en la consulta SQL. (Devuelve el campo
'0 del recordset). Si no existe el registro (o error) devuelve un "@"
Public Function devuelve_campo(strSQL As String, Optional conexion As ADODB.Connection) As Variant
Dim rc As New ADODB.Recordset
On Error GoTo devuelve_campo_Error
If conexion Is Nothing Then
rc.Open strSQL, locCnn, adOpenDynamic, adLockReadOnly
Else
rc.Open strSQL, conexion, adOpenDynamic, adLockReadOnly
End If
If rc.EOF Then
devuelve_campo = "@"
Else
'si es nulo (no hay registros) devolver 1
If IsNull(rc.fields(0).Value) Then
devuelve_campo = "@"
Else
devuelve_campo = rc.fields(0).Value
End If
End If
rc.Close
Set rc = Nothing
On Error GoTo 0
Exit Function
devuelve_campo_Error:
devuelve_campo = "@"
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure devuelve_campo of Módulo General", vbExclamation, titulo
End Function
'---------------------------------------------------------------------------------------
' Subrutina : Descompone_CBAR
' Fecha/Hora : 11/01/2004 17:38
' Autor : JCASTILLO
' Propósito : Descompone el codigo de barras en los diversos codigos y de
' vuelve un tipo MiCodBar
'---------------------------------------------------------------------------------------
Public Function Descompone_CBAR(codigo As String) As MiCodBar
On Error GoTo Descompone_CBAR_Error
With Descompone_CBAR
.CODIGO_ART = Mid(codigo, 1, 5)
.TEMPORADA_ART = Mid(codigo, 6, 3)
'12345 678 90 123
'00000-000-00-000
.TALLA_ART = Mid(codigo, 9, 2)
.COLOR_ART = Mid(codigo, 11, 3)
End With
Exit Function
Descompone_CBAR_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") en procedimiento Descompone_CBAR de Módulo General"
End Function
'---------------------------------------------------------------------------------------
' Procedure : carga_cadenas_conexion
' DateTime : 12/10/2003 01:47
' Author : Administrador
' Purpose : Carga las cadenas de conexión para el proyecto. Lee de la unica base de datos
' Fija: CONFIG.
'---------------------------------------------------------------------------------------
Public Function carga_cadenas_conexion(idEmpresa As Long) As Boolean
On Error GoTo carga_cadenas_conexion_Error
Const fichero_cfg = "\Config.pcg"
Dim rc As New ADODB.Recordset
'//////////////////////////////////////////
'///////////// Connection String para enlazar a un SQLServer sin autentificación windows
'///////////// cambiar el user, passw y DB por el correspondiente.
'//////////////////////////////////////////
'Provider=SQLOLEDB.1;Password=serv01;Persist Security Info=True;User ID=server;Initial Catalog=LOCAL;Data Source=81.33.28.52
'//////////////////////////////////////////
'La conexión a la base de datos,de configuración (local en mdb)
strEmpCnn = strCnnMdb & App.Path & fichero_cfg
'strEmpCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=" & App.Path & fichero_cfg
'si no existe la DB config ... generar y presentar los formularios de Configuración de Empresa
'y configuración de puesto, y salir.
If Dir(App.Path & fichero_cfg) = "" Then
Call CreateDatabaseConfig
EmpCnn.Open strEmpCnn
frmMntEmp.Configuracion_Inicial = True
frmMntEmp.Show
DoEvents
carga_cadenas_conexion = True
Exit Function
Else
EmpCnn.Open strEmpCnn
End If
rc.Open "select * from EMPRESAS where ID = " & idEmpresa, EmpCnn, adOpenStatic, adLockReadOnly
'si no hay registros
If rc.RecordCount <= 0 Then
With frmMntEmp
.Configuracion_Inicial = True
.Show
DoEvents
End With
carga_cadenas_conexion = True
Exit Function
End If
'La conexión al servidor local
strLocCnn = rc.fields("CONSTRING")
'strLocCnn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" & Trim(rc.fields("BBDDCLI").Value) & ";Data Source=" & Trim(rc.fields("IPCLI").Value)
'Conexión al servidor local para el proveedor msdatashape
strLocCnnSP = "PROVIDER=MSDataShape;Data " & strLocCnn 'PROVIDER=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" & rc.Fields("BBDDCLI").Value & ";Data Source=" & rc.Fields("IPCLI").Value
'La conexión al servidor CENTRAL (REMOTO)
'strSrvCnn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" & rc.fields("BBDDSRV").Value & ";Data Source=" & rc.fields("IPSRV").Value
rc.Close
Set rc = Nothing
On Error GoTo 0
Exit Function
carga_cadenas_conexion_Error:
carga_cadenas_conexion = True
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure carga_cadenas_conexion of Módulo General", vbExclamation, titulo
End Function
'---------------------------------------------------------------------------------------
' Procedure : habilita
' DateTime : 12/10/2003 12:41
' Author : Administrador
' Purpose : Habilitar o deshabilitar todos los mitext
' que estan enlazados a datos
'---------------------------------------------------------------------------------------
'
Public Function habilita(formulario As Form, SiNo As Boolean)
Dim tmpm As Object
For Each tmpm In formulario.Controls
If TypeName(tmpm) = "miText" Then
If tmpm.DataField <> "" Then
tmpm.Enabled = SiNo
End If
End If
Next
Set tmpm = Nothing
End Function
'---------------------------------------------------------------------------------------
' Procedure : main
' DateTime : 12/10/2003 02:16
' Author : Administrador
' Purpose : Iniciar el programa
'---------------------------------------------------------------------------------------
'
Sub Main()
'Si ya se esta ejecutando
If App.PrevInstance Then
If MsgBox("Ya esta ejecutando el programa. ¿Dese abrirlo otra vez?", vbQuestion + vbYesNo, titulo) = vbNo Then
'Activar la otra instancia
On Error Resume Next
AppActivate titulo
End
End If
End If
If carga_cadenas_conexion(1) = False Then
If leer_configuracion Then
frmInicSesion.Show
End If
'FrmTMPInicio.Show
End If
End Sub
'---------------------------------------------------------------------------------------
' Subrutina : escribe_txt_config
' Fecha/Hora : 13/12/2004 20:35
' Autor : JCASTILLO
' Propósito : Escribir TXT de configuración del puesto, para enlazar desde los
' módulos creados con genexus. Forzar = true para eliminar un posible
' fichero previo.
'
' Tambien escribe el fichero con el id del usuario que abrio pcgestion
'
'---------------------------------------------------------------------------------------
Public Sub escribe_txt_config(forzar As Boolean)
Const ftxt = "pcg20.dat"
Const ftxtu = "PCG20U.DAT"
On Error GoTo escribe_txt_config_Error
If forzar Then
If Dir(ftxt) <> "" Then Kill ftxt
End If
'escribir configuración del puesto
If Dir(ftxt) = "" Then
Open ftxt For Output As #100
Print #100, CentroActual
Print #100, CajaActual
Print #100, AlmacenActual
Close #100
End If
'escribir id usuario q abrio el programa
If Dir(ftxtu) <> "" Then Kill ftxtu
Open ftxtu For Output As #100
Print #100, TipoPermiso
Close #100
On Error GoTo 0
Exit Sub
escribe_txt_config_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") en procedimiento escribe_txt_config de Módulo General"
End Sub
'---------------------------------------------------------------------------------------
' Procedure : leer_configuracion
' DateTime : 01/11/2003 21:52
' Author : Administrador
' Purpose : Leer la configuración y cargar las variables.
' devuelve TRUE si no ha ocurrido ningun error.
'---------------------------------------------------------------------------------------
'
Public Function leer_configuracion() As Boolean
Dim EmpresaActual As Long
Dim m_matriz As Variant
Dim tmpconn As New ADODB.Connection
On Error GoTo leer_configuracion_Error
tmpconn.Open strEmpCnn
m_matriz = devuelve_matriz("SELECT CODEMP, CODALM, CODCAJA, CODCEN FROM PUESTCNF", tmpconn)
If Not IsArray(m_matriz) Then
tmpconn.Close
Set tmpconn = Nothing
MsgBox "Revise la configuración del PUESTO (CONFIG)", vbCritical, titulo
leer_configuracion = False
Exit Function
End If
EmpresaActual = m_matriz(0)
AlmacenActual = m_matriz(1)
CajaActual = m_matriz(2)
CentroActual = m_matriz(3)
ReDim m_matriz(0)
'obtener lineas del ticket
m_matriz = devuelve_matriz("SELECT CL1, CL2, CL3, PL1, PL2 FROM EMPRESAS WHERE ID = " & EmpresaActual, tmpconn)
LineasTicket(0) = m_matriz(0)
LineasTicket(1) = m_matriz(1)
LineasTicket(2) = m_matriz(2)
LineasTicket(3) = m_matriz(3)
LineasTicket(4) = m_matriz(4)
tmpconn.Close
Set tmpconn = Nothing
ReDim m_matriz(0)
With locCnn
If .State = 0 Then
.CursorLocation = adUseClient
.Open strLocCnn
End If
End With
'obtener la temporada de trabajo actual
TemporadaActual = devuelve_campo("SELECT IDTEM FROM TEMPOR WHERE ACTUAL = 1")
'obtener el ultimo caracter de la expresión, para obtener el simbolo
'de la moneda actual del sistema (€ u otro). Se usa en miText
SimboloMoneda = Right(Format(1, "Currency"), 1)
leer_configuracion = True
'crear el txt de configuracion para genexus (solo si no existe)
Call escribe_txt_config(False)
On Error GoTo 0
Exit Function
leer_configuracion_Error:
leer_configuracion = False
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure leer_configuracion of Módulo General"
frmMntEmp.Show
End Function
Public Function ValidEmail(ByVal strCheck As String) As Boolean
'Created by Chad M. Kovac
'Tech Knowledgey, Inc.
'http://www.TechKnowledgeyInc.com
Dim bCK As Boolean
Dim strDomainType As String
Dim strDomainName As String
Const sInvalidChars As String = "!#$%^&*()=+{}[]|\;:'/?>,< "
Dim i As Integer
bCK = Not InStr(1, strCheck, Chr(34)) > 0 'Check to see if there is a double quote
If Not bCK Then GoTo ExitFunction
bCK = Not InStr(1, strCheck, "..") > 0 'Check to see if there are consecutive dots
If Not bCK Then GoTo ExitFunction
' Check for invalid characters.
If Len(strCheck) > Len(sInvalidChars) Then
For i = 1 To Len(sInvalidChars)
If InStr(strCheck, Mid(sInvalidChars, i, 1)) > 0 Then
bCK = False
GoTo ExitFunction
End If
Next
Else
For i = 1 To Len(strCheck)
If InStr(sInvalidChars, Mid(strCheck, i, 1)) > 0 Then
bCK = False
GoTo ExitFunction
End If
Next
End If
If InStr(1, strCheck, "@") > 1 Then 'Check for an @ symbol
bCK = Len(Left(strCheck, InStr(1, strCheck, "@") - 1)) > 0
Else
bCK = False
End If
If Not bCK Then GoTo ExitFunction
strCheck = Right(strCheck, Len(strCheck) - InStr(1, strCheck, "@"))
bCK = Not InStr(1, strCheck, "@") > 0 'Check to see if there are too many @'s
If Not bCK Then GoTo ExitFunction
strDomainType = Right(strCheck, Len(strCheck) - InStr(1, strCheck, "."))
bCK = Len(strDomainType) > 0 And InStr(1, strCheck, ".") < Len(strCheck)
If Not bCK Then GoTo ExitFunction
strCheck = Left(strCheck, Len(strCheck) - Len(strDomainType) - 1)
Do Until InStr(1, strCheck, ".") <= 1
If Len(strCheck) >= InStr(1, strCheck, ".") Then
strCheck = Left(strCheck, Len(strCheck) - (InStr(1, strCheck, ".") - 1))
Else
bCK = False
GoTo ExitFunction
End If
Loop
If strCheck = "." Or Len(strCheck) = 0 Then bCK = False
ExitFunction:
ValidEmail = bCK
strDomainType = ""
strDomainName = ""
End Function
'*==========================================
'PARA HACER EL FORMULARIO MODAL SI/NO POR CODIGO
'*==========================================
'In A Module:
'
Public Sub MakeModal(ByRef frmParent As Form, ByVal isModal As MakeAsModal)
On Error Resume Next
Dim RetVal As Long
RetVal = EnableWindow(frmParent.hwnd, isModal)
End Sub
'---------------------------------------------------------------------------------------
' Procedure : procesa_informes
' DateTime : 10/11/2003 21:27
' Author : Administrador
' Purpose : Procesar los informes de la aplicación. Recibe el parametro numinf
'---------------------------------------------------------------------------------------
'
Public Sub procesa_informes(numinf As Integer, orden_asc As Boolean, Optional formula As String)
On Error GoTo procesa_informes_Error
Set crystalr = Nothing
Set crystalr = CreateObject("Crystal.CrystalReport")
DoEvents
With crystalr
If Trim(formula) <> "" Then .SelectionFormula = formula
Select Case numinf
'etiquetas pedidos
Case 1
.ReportFileName = App.Path & dir_rpts & rpt_etiquetas '.DataFiles(0) = "c:\TempEtiquetasDB.mdb"
'si dice orden descendente
If Not orden_asc Then
.SortFields(0) = "-{ETIQUETAS.ID}"
End If
Case 2
.ReportFileName = App.Path & dir_rpts & rpt_totTrn
Case 3
'rpt_totPed
.ReportFileName = App.Path & dir_rpts & rpt_totPed
Case 4
.ReportFileName = App.Path & dir_rpts & rpt_totPedT
End Select
.WindowState = 2
.Action = 1
End With
On Error GoTo 0
Exit Sub
procesa_informes_Error:
Set crystalr = Nothing
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure procesa_informes of Módulo General"
End Sub
'In A Form:
'
'Private Sub Command1_Click()
' MakeModal frmMain, Modal
'End Sub
'Private Sub Command2_Click()
' MakeModal frmMain, Modalless
'End Sub
'---------------------------------------------------------------------------------------
' Procedure : stock
' DateTime : 11/11/2003 12:08
' Author : Administrador
' Purpose : Rutina para el manejo del stock (adiciones o eliminaciones de artículos de stock. Devuelve:
' 0 -> no hay ningun error ni mensaje
' 1 -> stock por debajo de 0
' 2 -> stock por debajo del minimo
' 3 -> stock por encima del máximo
' 4 -> ha ocurrido algun error
'---------------------------------------------------------------------------------------
Public Function stock(CODIGO_ARTICULO As Integer, Temporada As Byte, talla As Integer, Color As Integer, almacen As Byte, unidades As Double, añadir As Boolean, Optional conexion As ADODB.Connection) As Byte
Dim rc As New ADODB.Recordset
Dim rcart As New ADODB.Recordset
Dim tmpsql As String
Dim tmpartsql As String
On Error GoTo stock_Error
'conformamos la selección para el Artículo
tmpsql = "SELECT CODART, TEMPOR, TALLA, COLOR, CODALM, STOCK FROM STOCK WHERE CODART =" & CODIGO_ARTICULO & " AND TEMPOR = " & Temporada & " AND TALLA = " & talla & " AND COLOR = " & Color & " AND CODALM = " & almacen
tmpartsql = "SELECT STOCKMAX, STOCKMIN FROM MAARTIC WHERE CODIGO= " & CODIGO_ARTICULO & " AND TEMPOR= " & Temporada
With rc
'Set rc = New ADODB.Recordset
'Set rcart = New ADODB.Recordset
If conexion Is Nothing Then
.Open tmpsql, locCnn, adOpenStatic, adLockOptimistic
rcart.Open tmpartsql, locCnn, adOpenDynamic, adLockReadOnly
Else
.Open tmpsql, conexion, adOpenStatic, adLockOptimistic
rcart.Open tmpartsql, conexion, adOpenDynamic, adLockReadOnly
End If
'si NO existe el registro, crear ...
If .RecordCount <= 0 Then
.AddNew
.fields("CODART") = CODIGO_ARTICULO
.fields("TEMPOR") = Temporada
.fields("TALLA") = talla
.fields("COLOR") = Color
.fields("CODALM") = almacen
If añadir Then
.fields("STOCK") = unidades 'sumar unidades
Else
.fields("STOCK") = -unidades 'restar unidades
End If
'si es menor de 0, salir con condicion 1
If .fields("STOCK") < 0 Then stock = 1
'si es menor del minimo, salir con condicion 2
If .fields("STOCK") < rcart.fields("STOCKMIN") Then stock = 2
'si es por encima del maximo, salir con condicion 2
If .fields("STOCK") > rcart.fields("STOCKMAX") Then stock = 3
.Update
Else 'si existe el registro, actualizar el campo stock
If añadir Then
.fields("STOCK") = .fields("STOCK") + unidades 'sumar unidades
Else
.fields("STOCK") = .fields("STOCK") - unidades 'restar unidades
End If
'si es menor de 0, salir con condicion 1
If .fields("STOCK") < 0 Then stock = 1
'si es menor del minimo, salir con condicion 2
If .fields("STOCK") < rcart.fields("STOCKMIN") Then stock = 2
'si es por encima del maximo, salir con condicion 2
If .fields("STOCK") > rcart.fields("STOCKMAX") Then stock = 3
.Update
End If
DoEvents
rcart.Close
Set rcart = Nothing
.Close
End With
tmpsql = ""
tmpartsql = ""
Set rc = Nothing
On Error GoTo 0
Exit Function
stock_Error:
stock = 4
Set rc = Nothing
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure stock of Módulo General"
End Function
'---------------------------------------------------------------------------------------
'---------------------------------------------------------------------------------------
' Procedure : Habilita_miTextNum
' DateTime : 11/11/2003 22:18
' Author : Administrador
' Purpose : Habilita o deshabilita los controles miTextNum. Colocar
' esta rutina en SetButtons:
' call Habilita_miTextNum (me, not bval)
'---------------------------------------------------------------------------------------
'
'Public Sub Habilita_miTextNum(formulario As Form, habilita As Boolean)
'Dim mitmp As Object
'On error GoTo Habilita_miTextNum_Error
' With formulario
'
' For Each mitmp In formulario
'
' If TypeOf mitmp Is miTextNum Then
' mitmp.Enabled = habilita
' End If
'
' Next
'
' End With
'Set mitmp = Nothing
' On Error GoTo 0
' Exit Sub
'Habilita_miTextNum_Error:
' MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Habilita_miTextNum of Módulo General"
'End Sub
'---------------------------------------------------------------------------------------
' Subrutina : cerrar_conexiones
' Fecha/Hora : 19/11/2003 23:46
' Autor : JCASTILLO
' Propósito : Cerrar las conexiones al servidor (local y remoto) que hayan podido quedar
' abiertas.
'---------------------------------------------------------------------------------------
Public Sub cerrar_conexiones()
Dim frmX As Form
On Error GoTo cerrar_conexiones_Error
On Error Resume Next
With locCnn
If .State <> 0 Then
.Close
End If
Set locCnn = Nothing
End With
With locCnnSP
If .State <> 0 Then
.Close
End If
Set locCnnSP = Nothing
End With
With SrvCnn
If .State <> 0 Then
.Close
End If
Set SrvCnn = Nothing
End With
For Each frmX In Forms
Unload frmX
Set frmX = Nothing
Next
'On Error GoTo 0
Exit Sub
cerrar_conexiones_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") en procedimiento cerrar_conexiones de Módulo General"
End Sub
'---------------------------------------------------------------------------------------
' Procedimiento : crear_nueva_transferencia
' Fecha/Hora : 24/11/2003 11:12
' Autor : JCastillo
' Propósito : Añade un registro a PTRANS con los datos de la transferencia. Devuelve el ID de transferencia
' asignado.
'---------------------------------------------------------------------------------------
Public Function crear_nueva_transferencia(codart As Long, tempor As Byte, Color As Integer, talla As Integer, Almacen_Origen As Byte, Almacen_Destino As Byte, es_entrada As Boolean, es_cancelacion As Boolean, unidades As Double, conexion As ADODB.Connection) As Long
Dim rc As New ADODB.Recordset
Dim tmpcodigo As Variant
On Error GoTo crear_nueva_transferencia_Error
With rc
.Open "SELECT * FROM PTRANS", conexion, adOpenDynamic, adLockOptimistic
tmpcodigo = devuelve_campo("select MAX(IDTRANS) + 1 from PTRANS", conexion)
.AddNew
.fields("IDTRANS") = tmpcodigo
.fields("CODART") = codart
.fields("TEMPOR") = tempor
.fields("CODCOL") = Color
.fields("CODTALLA") = talla
'si es una entrada, almacén de origen = 0
If Not es_entrada Then
.fields("CODALMORIG") = 0
Else
.fields("CODALMORIG") = Almacen_Origen
End If
.fields("CODALMDEST") = Almacen_Destino
.fields("ENTRADA") = es_entrada
.fields("UNIDADES") = unidades
.fields("CANCEL") = es_cancelacion
.Update
End With
'devolver el código
crear_nueva_transferencia = tmpcodigo
Set tmpcodigo = Nothing
On Error GoTo 0
Exit Function
crear_nueva_transferencia_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") en procedimiento crear_nueva_transferencia de Módulo General"
End Function
'---------------------------------------------------------------------------------------
' Procedimiento : CodigoSeguridad_TRN
' Fecha/Hora : 13/01/2004 11:22
' Autor : JCastillo
' COD TRNS -ALM
' Propósito : Enmascara un numero 000000000-000 en otro
' 9 digitos codigo de transferencia
' 3 digitos codigo de almacen
' Es un codigo de seguridad para poder aceptar la transferencia
' incluso si no coinciden las prendas en la comprobación.
'---------------------------------------------------------------------------------------
Public Function CodigoSeguridad_TRN(codigo As String) As Double
Dim tmpvalor As Double
Dim tmpcodalm As Double
Dim tmpcodigo As String
Dim tmpcodigo2 As String
Dim car As String * 1
Dim var As Long
On Error GoTo CodigoSeguridad_TRN_Error
If Not IsNumeric(codigo) Then Exit Function
tmpcodalm = CDbl(Right(codigo, 3))
tmpvalor = CDbl(codigo)
'multiplicamos el codigo completo por la parte correspondiente al codigo
'de almacén
tmpvalor = CDbl((((tmpvalor * tmpcodalm) + 1) * 28.6) / 30.5)
tmpcodigo = CStr(tmpvalor)
'si tiene mas de 10 digitos (codigo muy grande), aplicar una rutina de
'reducción
Do Until Len(tmpcodigo) <= 10
'coger un caracter si, y otro no
For var = 1 To Len(tmpcodigo) Step 2
car = Mid(tmpcodigo, var, 1)
If IsNumeric(car) Then
tmpcodigo2 = tmpcodigo2 & Mid(tmpcodigo, var, 1)
End If
car = " "
Next var
'asignar nuevo codigo
tmpcodigo = tmpcodigo2
tmpcodigo2 = ""
Loop
tmpvalor = CDbl(tmpcodigo)
'devolver el valor
CodigoSeguridad_TRN = tmpvalor
On Error GoTo 0
Exit Function
CodigoSeguridad_TRN_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") en procedimiento CodigoSeguridad_TRN de Modulo General"
End Function
'---------------------------------------------------------------------------------------
' Subrutina : devuelve_matriz
' Fecha/Hora : 15/01/2004 20:54
' Autor : JCASTILLO
' Propósito : Devuelve una matriz de campos, para cuando es necesario hacer mas de una
' consulta a la misma tabla, en vez de usar un devuelve_campo para cada
' consulta
'---------------------------------------------------------------------------------------
Public Function devuelve_matriz(ConsultaSQL As String, conexion As ADODB.Connection) As Variant
Dim rc As New ADODB.Recordset
Dim var As Integer
Dim miMat As Variant
On Error GoTo devuelve_matriz_Error
rc.Open ConsultaSQL, conexion, adOpenStatic, adLockReadOnly
If rc.RecordCount > 0 Then
ReDim miMat(rc.fields.Count)
For var = 0 To rc.fields.Count - 1
miMat(var) = rc.fields(var).Value
Next
Else
miMat = "@"
End If
rc.Close
Set rc = Nothing
devuelve_matriz = miMat
On Error GoTo 0
Exit Function
devuelve_matriz_Error:
'devuelve_matriz(0) = "@"
Set rc = Nothing
MsgBox "Error " & Err.Number & " (" & Err.Description & ") en procedimiento devuelve_matriz de Módulo General"
End Function