Files
MBS/MOVIL401/MBSinventario/app_main.4gl
T

201 lines
5.9 KiB
Plaintext

IMPORT util
TYPE t_sync_cmd RECORD
oper STRING,
data STRING
END RECORD
MAIN
DEFINE archivo STRING
CALL init_mobile_log("err_gm_maps.log")
# TRY
# DATABASE dbcrm
# CATCH
# CALL dbcreate()
# END TRY
CALL init_database()
CALL menu_principal()
END MAIN
FUNCTION init_database()
define l_database_exists boolean
define ch base.channel
-- First attempt to connect to database.
-- If this successed we know the database exists
LET l_database_exists = true
TRY
DATABASE dbcrm
CATCH
let ch = base.Channel.create()
call ch.openFile("dbcrm.db","w")
call ch.close()
DATABASE dbcrm
CALL dbcreate()
end try
END FUNCTION
FUNCTION menu_principal()
call ui.Interface.loadStyles("menu")
case frontend()
when "GMA" call ui.Interface.loadActionDefaults("menu_android")
# CALL fgl_winmessage(" ","GMA","info")
when "GMI" call ui.Interface.loadActionDefaults("menu_ios")
otherwise call ui.Interface.loadActionDefaults("menu")
end case
call execute()
END FUNCTION
private function splash()
define splash string
define l_ok boolean
define l_err_text string
define l_result,us_crea,us_asigna string
DEFINE id_num INT,
url STRING,
estado BOOLEAN
CALL conexion() RETURNING url
CALL valida_usuario_crm(url) RETURNING estado,us_crea,us_asigna
IF NOT estado THEN
CALL fgl_winmessage("INFO","USUARIO NO ES VALIDO","INFO")
EXIT PROGRAM
END IF
call ui.interface.frontcall("webcomponent","call",["formonly.splash","setById","root",splash_html()],l_result)
input by name splash attributes(unbuffered, without defaults=true, cancel=false, accept=false)
before input
-- set to false before deployment
call dialog.setActionActive("settings", true)
on ACTION settings
menu "" attributes(style="dialog")
ON ACTION documentos ATTRIBUTE(TEXT="Gestion Documentos")
CALL documentos_mov(id_num,url)
ON ACTION sincroniza ATTRIBUTE(TEXT="Download Data")
OPEN WINDOW ws1 WITH FORM "sincroniza"
CALL conexion() RETURNING url
CALL usuarios_download(url) RETURNING estado
CALL clases_download(url)
CALL productos_download(url)
CALL requisiciones_download(url)
CALL transportista_download(url)
CALL clientes_download(url)
CALL ordenes_download(url)
CLOSE WINDOW ws1
ON ACTION lista ATTRIBUTE(TEXT="Lista Documentos")
CALL listaDocumentos()
ON ACTION etiquetas ATTRIBUTE(TEXT="Impresion Etiquetas")
CALL imp_etiquetas()
on action CANCEL ATTRIBUTE(TEXT="Salir Aplicacion")
exit program
end menu
# on action help
# call browser.browser("Help","https://demo.4js.com/gas/help.htm")
-- this could use a PDF but the PDF is slow to load when it contains images
-- could also consider embedding PDF inside application
#call browser.browser("help","https://demo.4js.com/gas/help.pdf")
on action about
call show_message(about_text(), true)
end input
if int_flag then
let int_flag = 0
end if
end function
function frontend()
define l_frontend string
call ui.Interface.frontCall("standard","feinfo","fename",l_frontend)
return l_frontend
end FUNCTION
private function about_text()
define sb base.StringBuffer
let sb = base.StringBuffer.create()
call sb.append("This application was produced by It Business Software (www.itbusiness.com)")
call sb.append("\n\n")
call sb.append("Application for Geoposition Photos")
call sb.append("\n\n")
call sb.append("Version Android 1.0")
return sb.toString()
end function
function execute()
open window splash with form "splash"
call splash()
close window splash
end function
private function splash_html()
-- considerchanging image for different devices
return "<div style=\"position: absolute; left: 0%; top: 0%; height: 100%; width: 100% \"><img src=\"splash.png\" height=\"100%\" width=\"100%\" onclick=\"execAction('splash','')\" /></div>"
end FUNCTION
function show_message(l_message_text, l_acknowledge)
define l_message_text string
define l_acknowledge boolean
if l_acknowledge then
if l_message_text.getlength() > 0 then
#call fgl_winmessage("Info", l_message_text,"info")
menu "Info" attributes(style="dialog", comment=l_message_text)
on action accept
exit menu
end menu
end if
else
message l_message_text
call ui.Interface.refresh() -- force display to current window
end if
end function
FUNCTION conexion()
DEFINE purl,cmd,res, msg STRING,
ret INT
DEFINE r_cmd t_sync_cmd
LET purl="http://66.98.50.155:8097"
LET r_cmd.oper = "get_status"
LET r_cmd.data = util.JSON.stringify(' ') -- aca se convierte a string los datos de la operacion
LET cmd = util.JSON.stringify(r_cmd) -- aca se convierte a string el comando/operacion a enviar al server
CALL sync_send_command(purl, cmd) RETURNING ret, res
IF ret ==0 THEN
RETURN purl
ELSE
LET purl="http://192.168.1.75:8097"
CALL sync_send_command(purl, cmd) RETURNING ret, res
IF ret==0 THEN
RETURN purl
ELSE
LET msg=SFMT(%"Connection '%1' failed",r_cmd.oper),"\n URL:",purl,"\n",res
# CALL show_sync_err(msg)
LET purl='0'
END IF
END IF
RETURN purl
END FUNCTION