Mi primer programa Fivetouch para crear usuarios

Mi primer programa Fivetouch para crear usuarios

Postby jnavas » Fri Apr 03, 2015 4:47 am

#include "FiveTouch.ch"

#xcommand DEFAULT <uVar1> := <uVal1> ;
[, <uVarN> := <uValN> ] => ;
<uVar1> := If( <uVar1> == nil, <uVal1>, <uVar1> ) ;;
[ <uVarN> := If( <uVarN> == nil, <uValN>, <uVarN> ); ]


function Main()
LOCAL oBtnCancelJ
LOCAL aBtnText:={"Incluir","Consultar","Modificar","Eliminar","Salir"}
LOCAL aBtn :=ARRAY(LEN(aBtnText))

PRIVATE oDlgBrw,oBrw

SET DELETE ON

FT_CREATE_TABLES()

USE ("FT_USER.DBF")
GO TOP

IF RECCOUNT()=0
FT_EDITUSER(NIL)
ENDIF

DEFINE DIALOG oDlgBrw TITLE "Usuarios" ;
SIZE 460, 600

@ 30, 0 BROWSE oBrw OF oDlgBrw ;
SIZE 458, 600 ;
HEADERS "Id", "Nombre","Fecha","Activo" ;
FIELDS FIELD->USR_ID, FIELD->USR_NAME, FIELD->USR_DATE,FIELD->USR_ACTIVE

@ 0, BCOL(1) BUTTON aBtn[1] PROMPT aBtnText[1] OF oDlgBrw ;
ACTION FT_EDITUSER(NIL)

@ 0, BCOL(2) BUTTON aBtn[2] PROMPT aBtnText[2] OF oDlgBrw ;
ACTION FT_EDITUSER(FIELD->USR_ID,2)

@ 0, BCOL(3) BUTTON aBtn[3] PROMPT aBtnText[3] OF oDlgBrw ;
ACTION FT_EDITUSER(FIELD->USR_ID,3)

@ 0, BCOL(4) BUTTON aBtn[4] PROMPT aBtnText[4] OF oDlgBrw ;
ACTION FT_EDITUSER(FIELD->USR_ID,4)

@ 0, BCOL(5) BUTTON aBtn[5] PROMPT aBtnText[5] OF oDlgBrw ;
ACTION oDlgBrw:End()

ACTIVATE DIALOG oDlgBrw CENTERED

//FT_EDITUSER()
CLOSE ALL

RETURN NIL

FUNCTION BCOL(nCol)
RETURN 81*(nCol-1)+10



FUNCTION FT_EDITUSER(cId_User)
LOCAL oDlg,I,oBtnOk,oBtnCancel
LOCAL oSay:=ARRAY(3)

PRIVATE oId,oName,oDate,oActive
PRIVATE cId:=SPACE(03),cName:=SPACE(100),dDate:="00/00/0000",lActive:=.T.
PRIVATE aSay :={"ID" ,"Nombre","Fecha"}
PRIVATE aVars:={"cId","cName" ,"dDate"}

IF !Empty(cId_User)
MsgAlert(cId_User)
GO TOP
LOCATE FOR FIELD->USR_ID=cId_User
cId :=FIELD->USR_ID
cName :=FIELD->USR_NAME
dDate :=CTOD(FIELD->USR_DATE)
lActive:=FIELD->USR_ACTIVE
ENDIF

DEFINE DIALOG oDlg TITLE "Crear Usuario <AdaptaPro>" ;
SIZE 300, 200

FOR I =1 TO LEN(aSay)
@ CROW(I),10 SAY oSay[I] PROMPT aSay[I] OF oDlg
NEXT I

@ CROW(1),060 GET oId VAR cId OF oDlg
@ CROW(2),060 GET oName VAR cName OF oDlg
@ CROW(3),060 GET oDate VAR dDate OF oDlg
@ CROW(1),160 CHECKBOX oChk VAR lActive OF oDlg ;
PROMPT "Active"

@ CROW(5), 110 BUTTON oBtnOk PROMPT "Ok" OF oDlg ;
ACTION FT_SAVEUSR(oDlg)

@ CROW(5),200 BUTTON oBtnCancel PROMPT "Cancel" OF oDlg ;
ACTION oDlg:End()

ACTIVATE DIALOG oDlg CENTERED

return nil

FUNCTION CROW(nRow)
RETURN 30*(nRow-1)+20

/*
// Guardar Registro
*/
FUNCTION FT_SAVEUSR(oDlg)
LOCAL cMsg:="",i,uValue

FOR I=1 TO LEN(aVars)
if Empty(&(aVars[I]))
cMsg:=cMsg+IF(Empty(cMsg),"",CRLF)+aSay[I]
ENDIF
NEXT I

IF !Empty(cMsg)
MsgInfo(cMsg,"Falta campo(s)")
RETURN .F.
ENDIF

// USE ("FT_USER.DBF")
GO TOP

LOCATE FOR FIELD->USR_ID=cId

IF !FOUND()
APPEND BLANK
ENDIF

REPLACE FIELD->USR_ID WITH cId,;
FIELD->USR_NAME WITH cName,;
FIELD->USR_DATE WITH CTOD(dDate),;
FIELD->USR_ACTIVE WITH lActive

COMMIT
// USE

IF !MsgYesNo("Desea Agregar Otro Usuario")
oDlg:End()
ENDIF

FOR I=1 TO LEN(aVars)
if Empty(&(aVars[I]))
cMsg:=cMsg+IF(Empty(cMsg),"",CRLF)+aSay[I]
ENDIF
NEXT I

// Las variables debe ser vaciadas
FOR I=1 TO LEN(aVars)
uValue:=CTOEMPTY(&(aVars[I]))
STORE uValue TO &(aVars[I])
NEXT I

// oId:Refresh(.T.) No refresca

RETURN NIL


FUNCTION FT_CREATE_TABLES()
LOCAL I
LOCAL aTables:={}
LOCAL aStruct:={}
LOCAL aIndex :={}

AADD(aStruct,{"USR_ID", "C",003,0})
AADD(aStruct,{"USR_NAME", "C",120,0})
AADD(aStruct,{"USR_DATE" , "D",008,0})
AADD(aStruct,{"USR_ACTIVE","L",001,0})

AADD(aTables,{"FT_USER.DBF",aStruct,aIndex})

FOR I=1 TO LEN(aTables)

IF !FILE(aTables[I,1])
dbcreate(aTables[I,1],aTables[I,2])
ENDIF
NEXT I

RETURN NIL

/*
// Devuelve Vacio
*/
FUNCTION CTOEMPTY(uValue,cType,nLen)

DEFAULT cType:=ValType(uValue)

IF cType="C" .AND. EMPTY(nLen) .AND. ValType(uValue)="C"
nLen:=LEN(uValue)
ENDIF

DO CASE
CASE ValType(uValue)="U".AND.cType$"CM"
uValue:=SPACE(nLen)
CASE ValType(uValue)="U".AND.cType="N"
uValue:=0.00
CASE ValType(uValue)="U".AND.cType="D"
uValue:=CTOD("")
CASE ValType(uValue)="U".AND.cType="L"
uValue:=.F.
CASE ValType(uValue)="C"
uValue:=SPACE(nLen)
CASE ValType(uValue)="N"
uValue:=0
CASE ValType(uValue)="D"
uValue:=CTOD("")
CASE ValType(uValue)="L"
uValue:=.F.
ENDCASE
RETURN uValue

FUNCTION MsgAlert(cMsg1,cMsg2)
return MsgInfo(cMsg1,cMsg2)
User avatar
jnavas
 
Posts: 479
Joined: Wed Nov 16, 2005 12:03 pm
Location: Caracas - Venezuela

Re: Mi primer programa Fivetouch para crear usuarios

Postby jnavas » Fri Apr 03, 2015 4:49 am

Saludos Cordiales
Como hago para publicar el codig PRG que se vea colorido y estructurado, ademas agregar una imagen
User avatar
jnavas
 
Posts: 479
Joined: Wed Nov 16, 2005 12:03 pm
Location: Caracas - Venezuela

Re: Mi primer programa Fivetouch para crear usuarios

Postby Antonio Linares » Fri Apr 03, 2015 6:22 am

Juan,

Cuando escribes tu mensaje arriba veras un botón que dice "Code", púlsalo y escribe tu código entre los dos elementos que te escribe.

Para una imagen se hace similar. Tienes que alojar la imagen en algún sitio y luego usar el botón "Img" y copiar la url de la imagen
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42127
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Mi primer programa Fivetouch para crear usuarios

Postby jnavas » Fri Apr 03, 2015 7:18 pm

Antonio Linares wrote:Juan,

Cuando escribes tu mensaje arriba veras un botón que dice "Code", púlsalo y escribe tu código entre los dos elementos que te escribe.

Para una imagen se hace similar. Tienes que alojar la imagen en algún sitio y luego usar el botón "Img" y copiar la url de la imagen

Antonio
Gracias, ahora publicare el código mas elegante y la imagen de la aplicación, programar con fivetouch ha sido una experiencia innovadora, no me complico con compilar y empezar de nuevo, solo escribo el código fuente, ejecutar y ver resultados. seguire con la funcionalidad del programa para crear clientes, producto y hacer pedidos. Luego sacarlos bien sea por correo, FTP o base de datos remota.

sera posible asignar F2 grabar y F5 ejecutar, al estilo borland
User avatar
jnavas
 
Posts: 479
Joined: Wed Nov 16, 2005 12:03 pm
Location: Caracas - Venezuela

Re: Mi primer programa Fivetouch para crear usuarios

Postby xfood » Mon Oct 12, 2015 3:52 pm

Excuse me, I'm trying this sample program, but in the function
FT_EDITUSER (field-> userid) I always empty
If you've resolved to read the value passed?
Thanks a lot



jnavas wrote:#include "FiveTouch.ch"

#xcommand DEFAULT <uVar1> := <uVal1> ;
[, <uVarN> := <uValN> ] => ;
<uVar1> := If( <uVar1> == nil, <uVal1>, <uVar1> ) ;;
[ <uVarN> := If( <uVarN> == nil, <uValN>, <uVarN> ); ]


function Main()
LOCAL oBtnCancelJ
LOCAL aBtnText:={"Incluir","Consultar","Modificar","Eliminar","Salir"}
LOCAL aBtn :=ARRAY(LEN(aBtnText))

PRIVATE oDlgBrw,oBrw

SET DELETE ON

FT_CREATE_TABLES()

USE ("FT_USER.DBF")
GO TOP

IF RECCOUNT()=0
FT_EDITUSER(NIL)
ENDIF

DEFINE DIALOG oDlgBrw TITLE "Usuarios" ;
SIZE 460, 600

@ 30, 0 BROWSE oBrw OF oDlgBrw ;
SIZE 458, 600 ;
HEADERS "Id", "Nombre","Fecha","Activo" ;
FIELDS FIELD->USR_ID, FIELD->USR_NAME, FIELD->USR_DATE,FIELD->USR_ACTIVE

@ 0, BCOL(1) BUTTON aBtn[1] PROMPT aBtnText[1] OF oDlgBrw ;
ACTION FT_EDITUSER(NIL)

@ 0, BCOL(2) BUTTON aBtn[2] PROMPT aBtnText[2] OF oDlgBrw ;
ACTION FT_EDITUSER(FIELD->USR_ID,2)

@ 0, BCOL(3) BUTTON aBtn[3] PROMPT aBtnText[3] OF oDlgBrw ;
ACTION FT_EDITUSER(FIELD->USR_ID,3)

@ 0, BCOL(4) BUTTON aBtn[4] PROMPT aBtnText[4] OF oDlgBrw ;
ACTION FT_EDITUSER(FIELD->USR_ID,4)

@ 0, BCOL(5) BUTTON aBtn[5] PROMPT aBtnText[5] OF oDlgBrw ;
ACTION oDlgBrw:End()

ACTIVATE DIALOG oDlgBrw CENTERED

//FT_EDITUSER()
CLOSE ALL

RETURN NIL

FUNCTION BCOL(nCol)
RETURN 81*(nCol-1)+10



FUNCTION FT_EDITUSER(cId_User)
LOCAL oDlg,I,oBtnOk,oBtnCancel
LOCAL oSay:=ARRAY(3)

PRIVATE oId,oName,oDate,oActive
PRIVATE cId:=SPACE(03),cName:=SPACE(100),dDate:="00/00/0000",lActive:=.T.
PRIVATE aSay :={"ID" ,"Nombre","Fecha"}
PRIVATE aVars:={"cId","cName" ,"dDate"}

MSGINFO(cId_User)

IF !Empty(cId_User)
MsgAlert(cId_User)
GO TOP
LOCATE FOR FIELD->USR_ID=cId_User
cId :=FIELD->USR_ID
cName :=FIELD->USR_NAME
dDate :=CTOD(FIELD->USR_DATE)
lActive:=FIELD->USR_ACTIVE
ENDIF

DEFINE DIALOG oDlg TITLE "Crear Usuario <AdaptaPro>" ;
SIZE 300, 200

FOR I =1 TO LEN(aSay)
@ CROW(I),10 SAY oSay[I] PROMPT aSay[I] OF oDlg
NEXT I

@ CROW(1),060 GET oId VAR cId OF oDlg
@ CROW(2),060 GET oName VAR cName OF oDlg
@ CROW(3),060 GET oDate VAR dDate OF oDlg
@ CROW(1),160 CHECKBOX oChk VAR lActive OF oDlg ;
PROMPT "Active"

@ CROW(5), 110 BUTTON oBtnOk PROMPT "Ok" OF oDlg ;
ACTION FT_SAVEUSR(oDlg)

@ CROW(5),200 BUTTON oBtnCancel PROMPT "Cancel" OF oDlg ;
ACTION oDlg:End()

ACTIVATE DIALOG oDlg CENTERED

return nil

FUNCTION CROW(nRow)
RETURN 30*(nRow-1)+20

/*
// Guardar Registro
*/
FUNCTION FT_SAVEUSR(oDlg)
LOCAL cMsg:="",i,uValue

FOR I=1 TO LEN(aVars)
if Empty(&(aVars[I]))
cMsg:=cMsg+IF(Empty(cMsg),"",CRLF)+aSay[I]
ENDIF
NEXT I

IF !Empty(cMsg)
MsgInfo(cMsg,"Falta campo(s)")
RETURN .F.
ENDIF

// USE ("FT_USER.DBF")
GO TOP

LOCATE FOR FIELD->USR_ID=cId

IF !FOUND()
APPEND BLANK
ENDIF

REPLACE FIELD->USR_ID WITH cId,;
FIELD->USR_NAME WITH cName,;
FIELD->USR_DATE WITH CTOD(dDate),;
FIELD->USR_ACTIVE WITH lActive

COMMIT
// USE

IF !MsgYesNo("Desea Agregar Otro Usuario")
oDlg:End()
ENDIF

FOR I=1 TO LEN(aVars)
if Empty(&(aVars[I]))
cMsg:=cMsg+IF(Empty(cMsg),"",CRLF)+aSay[I]
ENDIF
NEXT I

// Las variables debe ser vaciadas
FOR I=1 TO LEN(aVars)
uValue:=CTOEMPTY(&(aVars[I]))
STORE uValue TO &(aVars[I])
NEXT I

// oId:Refresh(.T.) No refresca

RETURN NIL


FUNCTION FT_CREATE_TABLES()
LOCAL I
LOCAL aTables:={}
LOCAL aStruct:={}
LOCAL aIndex :={}

AADD(aStruct,{"USR_ID", "C",003,0})
AADD(aStruct,{"USR_NAME", "C",120,0})
AADD(aStruct,{"USR_DATE" , "D",008,0})
AADD(aStruct,{"USR_ACTIVE","L",001,0})

AADD(aTables,{"FT_USER.DBF",aStruct,aIndex})

FOR I=1 TO LEN(aTables)

IF !FILE(aTables[I,1])
dbcreate(aTables[I,1],aTables[I,2])
ENDIF
NEXT I

RETURN NIL

/*
// Devuelve Vacio
*/
FUNCTION CTOEMPTY(uValue,cType,nLen)

DEFAULT cType:=ValType(uValue)

IF cType="C" .AND. EMPTY(nLen) .AND. ValType(uValue)="C"
nLen:=LEN(uValue)
ENDIF

DO CASE
CASE ValType(uValue)="U".AND.cType$"CM"
uValue:=SPACE(nLen)
CASE ValType(uValue)="U".AND.cType="N"
uValue:=0.00
CASE ValType(uValue)="U".AND.cType="D"
uValue:=CTOD("")
CASE ValType(uValue)="U".AND.cType="L"
uValue:=.F.
CASE ValType(uValue)="C"
uValue:=SPACE(nLen)
CASE ValType(uValue)="N"
uValue:=0
CASE ValType(uValue)="D"
uValue:=CTOD("")
CASE ValType(uValue)="L"
uValue:=.F.
ENDCASE
RETURN uValue

FUNCTION MsgAlert(cMsg1,cMsg2)
return MsgInfo(cMsg1,cMsg2)
xfood
 
Posts: 96
Joined: Tue Jun 17, 2008 9:02 pm


Return to FiveTouch

Who is online

Users browsing this forum: No registered users and 2 guests