{ ------------------------------------------------------------------ PROGRAMA : VEPRMT102 OBJETIVO : Capturar, Modificar, Eliminar registros de la Tabla de Documentos del cliente PROGRAMADOR : Ing. Luis Soto FECHA REALIZACION : Enero 27, 2026. ------------------------------------------------------------------ } IMPORT os IMPORT util GLOBALS "veprgb000.4gl" DEFINE documentos DYNAMIC ARRAY OF RECORD nombre_file VARCHAR(100), filedestino string, data BYTE, tipo_file CHAR(20), arch_tipo int END RECORD DEFINE cliente RECORD tipo_cliente INT, sec_cliente INT, nom_cliente VARCHAR(100) END RECORD DEFINE tmpdir_file,tipos_foto,dir_file,dir_foto CHAR(60), d_tipos,mensaje,f_tipos,l_file,filepath,extension,extension_foto,tmp_dirfoto,imagefac,tmp_destino STRING,ffoto,pimagen BYTE , nombre_file_foto,foto VARCHAR(100),p_res smallint MAIN DEFER INTERRUPT CALL ARG_VAL(1) RETURNING usuarios CALL ARG_VAL(2) RETURNING clave CONNECT TO "smarmotech" AS "MSSQL" USER usuarios USING clave CALL veprmt102() END MAIN FUNCTION veprmt102() OPTIONS ERROR LINE 23, MESSAGE LINE 24, COMMENT LINE 21 OPEN WINDOW vefmmt102 AT 2,2 WITH FORM "vefmmt102" ATTRIBUTE (BORDER,FORM LINE FIRST+4,COMMENT LINE LAST) INITIALIZE cliente_bas.* TO NULL INITIALIZE cliente_dir.* TO NULL MENU ON ACTION adicionar LET int_flag = FALSE SET CONNECTION "MSSQL" CLEAR FORM CALL vepcad102() ON ACTION salir LET INT_FLAG = FALSE EXIT PROGRAM END MENU LET INT_FLAG = FALSE CLOSE WINDOW vefmmt102 END FUNCTION FUNCTION vepcad102() DIALOG ATTRIBUTES(UNBUFFERED) INPUT BY NAME cliente.* AFTER FIELD sec_cliente IF cliente.tipo_cliente is NULL or cliente.tipo_cliente = 0 then LET numero_msg = 16 CALL msg(numero_msg) NEXT FIELD tipo_cliente END IF SELECT a.nombre INTO cliente.nom_cliente FROM vetb00004 a WHERE a.tipo_cliente = cliente.tipo_cliente AND a.sec_cliente = cliente.sec_cliente AND a.status_t IS NULL IF STATUS = NOTFOUND THEN LET numero_msg = 3 CALL msg(numero_msg) NEXT FIELD tipo_cliente END IF END INPUT INPUT ARRAY documentos FROM docu.* ATTRIBUTES(WITHOUT DEFAULTS) BEFORE INPUT IF cliente.tipo_Cliente IS NULL OR cliente.sec_cliente IS NULL THEN CALL fgl_winmessage("ERROR","EL CLIENTE NO PUEDE ESTAR VACIO","STOP") NEXT FIELD tipo_cliente END IF DECLARE buscat CURSOR FOR SELECT a.nombre_file, a.ruta, a.arch_tipo, a.tipo FROM vetb00062 a WHERE a.tipo_Cliente=cliente.tipo_cliente AND a.sec_cliente =cliente.sec_cliente LET idx=1 FOREACH buscat INTO documentos[idx].nombre_file,documentos[idx].filedestino, documentos[idx].arch_tipo,documentos[idx].tipo_file LET idx=idx+1 END FOREACH BEFORE ROW # LET documentos[arr_curr()].filedestino =NULL DISPLAY documentos[arr_curr()].filedestino TO foto ON ACTION busca_foto ATTRIBUTE(TEXT="Foto",IMAGE="upload") CALL agregar_archivo(arr_curr()) RETURNING tmp_dirfoto DISPLAY "destino ",tmp_dirfoto LET documentos[arr_curr()].nombre_file = os.Path.basename(tmp_dirfoto) LET documentos[arr_curr()].tipo_file = os.Path.extension(tmp_dirfoto) LET documentos[arr_curr()].filedestino=tmp_dirfoto LOCATE documentos[arr_curr()].data IN MEMORY CALL documentos[arr_curr()].data.readfile(tmp_dirfoto) DISPLAY documentos[arr_curr()].filedestino TO foto ON ACTION abrir_doc TRY LET tmpdir_file = documentos[arr_curr()].filedestino # CALL documentos[arr_curr()].data.writeFile(tmpdir_file) CALL ui.Interface.frontCall("standard","getenv", ["TEMP"], [l_file] ) LET l_file = l_file CLIPPED,"\\",documentos[arr_curr()].nombre_file CALL fgl_putfile(tmpdir_file,l_file) CALL ui.Interface.frontCall("standard","shellexec", [l_file],[p_res]) CATCH CALL fgl_winmessage("ERROR",err_get(STATUS),"INFO") END TRY END INPUT ON ACTION guardar BEGIN WORK DELETE FROM vetb00062 WHERE tipo_cliente=cliente.tipo_cliente AND sec_cliente=cliente.sec_cliente FOR idx=1 TO documentos.getLength() INSERT INTO vetb00062 (tipo_cliente, sec_cliente, nombre_file, ruta, arch_tipo, tipo) VALUES(cliente.tipo_cliente,cliente.sec_cliente,documentos[idx].nombre_file,documentos[idx].filedestino, documentos[idx].arch_tipo,documentos[idx].tipo_file) END FOR IF STATUS < 0 THEN ROLLBACK WORK CALL fgl_winmessage("ERROR","NO PUDE ACTUALIZAR DOCUMENTOS","STOP") ELSE COMMIT WORK LET numero_msg = 1 CALL msg(numero_msg) CALL documentos.clear() INITIALIZE cliente.* TO NULL RETURN END IF ON ACTION CANCEL LET INT_FLAG = FALSE CALL msg(2) RETURN END DIALOG END FUNCTION FUNCTION agregar_archivo(i) DEFINE filepath STRING DEFINE tmpfile STRING DEFINE i INTEGER DEFINE tmp_destino,nombre_foto string LET filepath= NULL CALL ui.Interface.frontCall( "standard","openfile", [NULL,"Images","*.jpg *.png *.gif *.pdf","Seleccione archivo"], [filepath] ) {IF filepath IS NULL THEN RETURN END IF} LET nombre_foto =cliente.tipo_cliente USING "<<<<<<<<","-",cliente.sec_cliente USING "<<<<<<<<","-",i USING "<<<<" LET tmpfile = FGL_GETENV("TEMP"),"\\",nombre_foto CLIPPED,".jpg" LET tmp_destino=fgl_getenv("IMAGENES"),"\\clientes\\",nombre_foto CLIPPED,".",os.Path.extension(filepath) DISPLAY "tmp file",tmpfile DISPLAY "nombre ",nombre_foto -- Copia local FE ? FE CALL fgl_getfile(filepath, tmp_destino) RETURN tmp_destino END FUNCTION