Sample code

Sample code

Postby MarcoBoschi » Tue Nov 15, 2016 11:27 am

Very simple question:

I have a little dialog with a Get, a Say and a Button.
In Get field I insert a code.

In the Button I have to associate an action that open a dbf table seek the code and return a description field
and modify Say object.

Is it possible to have a very simple example?

Second question:
Can I associate to a Button an action that launches an url (that is CGI-EXE) that perform this search on my dbf table?
How can I can read return value from my App?
Many thank
Marco
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Sample code

Postby Antonio Linares » Tue Nov 15, 2016 11:50 am

Marco,

Is this what you mean ?

I don't fully understand your second question. Do you mean to go to a URL from your FiveTouch app ?

The CGI app returns a value ?

Are you talking about FiveTouch or FiveWeb ? :-)

Image
regards, saludos

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

Re: Sample code

Postby MarcoBoschi » Tue Nov 15, 2016 12:24 pm

Thankyou Antonio
Imagine that from this app you have to retrieve
some data from a dbf table.
This dbf is one of many dbf tables of another fivewin programma in a lan. Fivetouch si on smartphone logged in wify.
How can I write button action?
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Sample code

Postby solving » Tue Nov 15, 2016 4:14 pm

saluti

mio esempio

per la prima questione :
vedi funzione Vedi_P(.....) e Prezzo(.....)

Code: Select all  Expand view

#include "FiveTouch.ch"

FUNCTION Main()

local oDlg,;
      oBtnPre,;
      oBtnInv,;
      oBtnEle,;
      oBtnRac,;
      oBtnNtx,;
      oBtnImp,;
      oBtnEnd

LOCAL cDir := "",fDbf,fNtx

PRIVATE xPath := HB_DIRBASE() + "SOLVING\"

cDir := xPath + "
DATI"

SET DELETE ON
SET CENTURY ON
SET ESCAPE ON
SET DATE ITALIAN
SETCANCEL(.T.)

CLOSE ALL

CLEAR SCREEN

* --- Verifica se Non Esiste la Directory
*     viene creata
IF !lIsDir( cDir )
   MakeDir( cDir )
ENDIF

* --- Imposta Variabili
fDbf := cDir + "
\_DATIL.DBF"
fNtx := cDir + "
\_DATIL.NTX"

* --- Crea File se Non Esiste
Crea_File( fDbf, fNtx, 0 )

DEFINE DIALOG oDlg

oDlg:setWindowTitle( "
Gestione Prezzi" )

* --- Definizione Pulsanti
@ 10, 90 BUTTON oBtnPre PROMPT "
Prezzi" OF oDlg ;
         ACTION Vedi_P( fDbf, fNtx )

@ 10, 220 BUTTON oBtnInv PROMPT "
Inventario" OF oDlg ;
         ACTION Inventa( fDbf, fNtx )

@ 50, 90 BUTTON oBtnRac PROMPT "
ALTRO" OF oDlg ;
         
@ 50, 220 BUTTON oBtnEle PROMPT "
Elenco" OF oDlg ;
         ACTION Elenco( fDbf, fNtx )

@ 90, 90 BUTTON oBtnNtx PROMPT "
Reindex" OF oDlg ;
          ACTION Crea_File( fDbf, fNtx, 1 )

@ 90, 220 BUTTON oBtnImp PROMPT "
Import File" OF oDlg ;
          ACTION Import(fDbf, fNtx, cDir )

@ 250, 90 BUTTON oBtnEnd PROMPT "
Fine" OF oDlg ;
          ACTION oDlg:End()

ACTIVATE DIALOG oDlg CENTERED

return nil

// ------------------------------- CREA_FILE
FUNCTION Crea_File( fDbf, fNtx, nSw )
LOCAL aDbf := {}

//*** Crea Archivio se non esiste
IF !FILE( fDbf )
   AADD(aDbf,{"
CODICE","C",13,0})
   AADD(aDbf,{"
DESC","C",15,0})
   AADD(aDbf,{"
QTA","N",6,2})
   AADD(aDbf,{"
PRE","N",9,3})
   DBCREATE(fDbf,aDbf)
   FERASE(fNtx)
ENDIF

IF nSw == 1
   FERASE(fNtx)
ENDIF

//*** Crea Indice se non esiste
IF !FILE( fNtx )
   USE( fDbf ) ALIAS Dati NEW
   INDEX ON Dati->CODICE TO ( fNtx )
   CLOSE DATABASES
ENDIF

IF nSw == 1
   MsgInfo("
Reindex Completato" )
ENDIF

RETURN NIL

// ----------------------- IMPORT
FUNCTION Import( fDbf, fNtx, cDir )
LOCAL cPath := "
D:\TX\"
LOCAL cFile := "
_DATIL.DBF"

IF MsgYesNo("
Import Dati  ?","Richiesta Import")
   IF FILE( cPath + cFile )

      FERASE( fDbf )
      FERASE( fNtx )

      COPY FILE(cPath + cFile) TO ( cDir +"
\"+ cFile )

      Crea_File( fDbf, fNtx, 1 )
   ELSE  
      MsgInfo("
Non Trovo " + cPath + cFile )
   ENDIF
ENDIF
RETURN NIL

// ----------------------- VEDI_P
FUNCTION Vedi_P( fDbf, fNtx )
LOCAL oDlg, oCod, cCod := SPACE(13)
LOCAL oSco, nSco := "
0", nPre := 0
LOCAL oBtnEnd, oBtnOk

USE( fDbf ) INDEX ( fNtx ) ALIAS Dati NEW

DEFINE DIALOG oDlg TITLE "
Vedi Prezzi" ;
       SIZE 300, 200

@ 160, 25 BUTTON oBtnEnd PROMPT "
Abbandona" OF oDlg ;
          ACTION oDlg:End()

@ 160, 150 BUTTON oBtnOk PROMPT "
Cerca" OF oDlg ;
           ACTION nPre := Prezzo(oDlg, cCod, oCod, nSco)

@ 20, 020 SAY oSay PROMPT "
Codice" OF oDlg
@ 50, 020 SAY oSay PROMPT "
Codice" OF oDlg
@ 70, 020 SAY oSay PROMPT "
Desc. " OF oDlg
@ 90, 020 SAY oSay PROMPT "
Prezzo" OF oDlg
@ 120,020 SAY oSay PROMPT "
Sconto" OF oDlg

@ 15, 060 GET oCod VAR cCod OF oDlg
oCod:setFixedSize(130,25)
*oCod:cursorPosition(0)
*oCod:setMaxLength(13)
oCod:setFocus()

@ 115, 060 GET oSco VAR nSco OF oDlg
oSco:setFixedSize(50,25)
oSco:setInputMask("
00")
oSco:Connect( "
textChanged(QString)",{| cValue | nSco := cValue, Calcolo(oDlg, nPre, nSco)})

ACTIVATE DIALOG oDlg CENTERED

Dati->( DBCLOSEAREA() )
RETURN NIL

// -------------------------------- PREZZO
FUNCTION Prezzo( oDlg, cCod, oCod, nSco )
LOCAL cBar := "
",;
      cDes := "
",;
      nPre := 0, lOk := .F.

LOCAL oLab1 := QLabel( oDlg ),;
      oLab2 := QLabel( oDlg ),;
      oLab3 := QLabel( oDlg )

cCod := ALLTRIM( cCod )

oLab3:setFont( QFont( "
Courier", 11, 75) )
oLab3:setStyleSheet( "
background-color : white; color : blue;" )

* --- Vuota Righe
oLab1:setText( SPACE(30)  )
oLab1:move( 65 , 50 )
oLab1:show()

oLab2:setText( SPACE(50)  )
oLab2:move( 65 , 70 )
oLab2:show()

oLab3:setText( SPACE(15)  )
oLab3:move( 65 , 90 )
oLab3:show()

IF !EMPTY( cCod )
   IF Dati->( DBSeek(cCod) )
      cBar := Dati->CODICE    
      cDes := Dati->DESC
      nPre := Dati->PRE
      lOk := .T.  
   ELSE  
      cDes := "
Cod. Non Trovato"
   ENDIF
ELSE
    cDes := "
Cod. Vuoto"
ENDIF

IF lOk
   * --- Visualizza Dati
   oLab1:setText( cBar  )
   oLab1:move( 65 , 50 )
   oLab1:show()

   oLab2:setText( cDes  )
   oLab2:move( 65 , 70 )
   oLab2:show()

   oLab3:setText( STR(nPre)  )
   oLab3:move( 65 , 90 )
   oLab3:show()
ELSE
   oLab2:setText( cDes  )
   oLab2:move( 65 , 70 )
   oLab2:show()
ENDIF

IF nPre <> 0
   Calcolo(oDlg, nPre, nSco)
ENDIF

oCod:SetText(SPACE(13))
oCod:setFocus()

RETURN( nPre )


// ----------------------- CALCOLO
FUNCTION Calcolo( oDlg, nPre, nSco )
LOCAL nR := "
0"
LOCAL oLab1 := QLabel( oDlg )

nR := nPre - (nPre*(VAL(nSco)/100))
nR := TRANSFORM( nR,"
99.999")

*oLab1:setText(ALLTRIM(STR(nR)))
oLab1:setText(nR)
oLab1:move( 120, 120 )

* 75 = Bold
oLab1:setFont( QFont( "
Courier New", 11, 75) )
oLab1:setStyleSheet( "
background-color : white; color : red;" )
oLab1:show()

RETURN( NIL )

// ----------------------- INVENTA
FUNCTION Inventa( fDbf, fNtx )
LOCAL oDlg
LOCAL oCod, cCod := SPACE(13)
LOCAL oQta, nQta := "
1"
LOCAL oBtnEnd, oBtnOk

USE( fDbf ) INDEX ( fNtx ) ALIAS Dati NEW

DEFINE DIALOG oDlg TITLE "
Inventario" ;
       SIZE 300, 200

@ 160, 25 BUTTON oBtnEnd PROMPT "
Abbandona" OF oDlg ;
          ACTION oDlg:End()

@ 160, 150 BUTTON oBtnOk PROMPT "
Conferma" OF oDlg ;
           ACTION Salva( oDlg, cCod, nQta, oCod, oQta )

@ 20, 020 SAY oSay PROMPT "
Codice" OF oDlg
@ 50, 020 SAY oSay PROMPT "
Q.t…"   OF oDlg
@ 50, 120 SAY oSay PROMPT "
+ o -"  OF oDlg

@ 90, 020 SAY oSay PROMPT "
Desc."  OF oDlg
@ 120,020 SAY oSay PROMPT "
Q.t… Attuale" OF oDlg

@ 15, 060 GET oCod VAR cCod OF oDlg
oCod:setFixedSize(130,25)
oCod:SetMaxLength(13)
oCod:setFocus()

@ 45, 060 GET oQta VAR nQta OF oDlg
oQta:setFixedSize(50,25)
oQta:setInputMask("
xxxx")

ACTIVATE DIALOG oDlg CENTERED

Dati->( DBCLOSEAREA() )
RETURN NIL

// ----------------------- SALVA
FUNCTION Salva( oDlg, cCod, nV, oCod, oQta )
LOCAL lOk := .F., cDes := "
"

LOCAL oLab1 := QLabel( oDlg ),;
      oLab2 := QLabel( oDlg )
     
cCod := ALLTRIM( cCod )

* --- Vuota Righe
oLab1:setText( SPACE(50)  )
oLab1:move( 65 , 60 )
oLab1:show()

oLab2:setText( SPACE(30)  )
oLab2:move( 85 , 90 )
oLab2:show()

IF !EMPTY( cCod )
   IF Dati->( DBSeek(cCod) )
      cDes := Dati->DESC
      nQta := Dati->QTA    
      lOk := .T.
   ELSE  
      cDes := "
Cod. Non Trovato"
   ENDIF
ELSE
    cDes := "
Cod. Vuoto"
ENDIF

IF lOk
   oLab1:setText( cDes  )
   oLab1:move( 65 , 90 )
   oLab1:show()

   oLab2:setText( STR(nQta)  )
   oLab2:move( 85 , 120 )
   oLab2:show()

   IF MsgYesNo("
Memorizzo Dati ?","Conferma")
      Dati->Qta += VAL( nV )
      Dati->( DBCOMMIT() )
   ENDIF

   * --- Vuota le Variabili
   oCod:SetText(SPACE(13))
   oQta:SetText("
1")

   oLab1:setText( SPACE(50))
   oLab1:move( 65 , 90 )
   oLab1:show()

   oLab2:setText( SPACE(10) )
   oLab2:move( 85 , 120 )
   oLab2:show()
ELSE
   oLab1:setText( cDes  )
   oLab1:move( 175 , 90 )
   oLab1:show()
ENDIF

cCod := SPACE(13)
oCod:setFocus()

RETURN NIL

// ------------------------ ELENCO
FUNCTION Elenco( fDbf, fNtx )
local oDlg := QDialog()
local oBrw := QTableView( oDlg )
local oModel := QStandardItemModel( 3, 4, oDlg )
LOCAL nNumRecord := 0, i, oIcon
LOCAL oBtnEnd, oBtnTp, oBtnBt

* --- Dichiaro Button
@ 335, 25 BUTTON oBtnEnd PROMPT "
Abbandona" OF oDlg ;
          ACTION oDlg:End()

@ 335, 150 BUTTON oBtnTp PROMPT "
Inizio" OF oDlg ;
          ACTION Inizio( oBrw )

@ 335, 250 BUTTON oBtnBt PROMPT "
Fine" OF oDlg ;
          ACTION Fine( oBrw )

* --- Imposto Icone nei Pulsanti
*oBtnEnd:SetIcon( QIcon(xPath + "
Exit.png") )
*OBtnEnd:setIconSize(QSize(10,10))

oBtnTp:SetIcon( QIcon(xPath + "
go-top.png") )
*OBtnTp:setIconSize(QSize(65,65))

oBtnBt:SetIcon( QIcon(xPath + "
go-bottom.png") )
*OBtnBt:setIconSize(QSize(65,65))

* --- Apro File
USE( fDbf ) INDEX ( fNtx ) ALIAS Dati NEW
nNumRecord := Dati->( RecCount() )

* --- Imposto Intestazione
oModel:SetHorizontalHeaderItem( 0, QStandardItem( "
Codice" ) )
oModel:SetHorizontalHeaderItem( 1, QStandardItem( "
Descrizione" ) )
oModel:SetHorizontalHeaderItem( 2, QStandardItem( "
Q.t…" ) )
oModel:SetHorizontalHeaderItem( 3, QStandardItem( "
Prezzo" ) )

* --- Carico Dati
For i = 0 TO nNumRecord
    oModel:SetItem( i, 0, QStandardItem( Dati->CODICE ) )
    oModel:SetItem( i, 1, QStandardItem( Dati->DESC ) )
    oModel:SetItem( i, 2, QStandardItem( STR(Dati->QTA) ) )
    oModel:SetItem( i, 3, QStandardItem( STR(Dati->PRE) ) )
    Dati->( DBSKIP() )
NEXT

* --- Chiudo File
Dati->( DBCLOSEAREA() )

* --- Imposto Form Principale
oDlg:SetWindowTitle( "
Elenco" )
oDlg:Resize( 450, 370 )
oDlg:Center()

* --- Imposto Form Browse
oBrw:SetModel( oModel )
oBrw:Resize( 445, 330 )

* --- Imposto Larghezza Colonne della Browse
oBrw:setColumnWidth(0, 90)
oBrw:setColumnWidth(1, 190)
oBrw:setColumnWidth(2, 40)
oBrw:setColumnWidth(3, 50)

* --- Esecuzione
oBrw:show()
oDlg:Exec()

RETURN NIL

* --- Posizione Top del Browse
FUNCTION Inizio( oBrw )
oBrw:scrollToTop()
*oBrw:setCurrentCell(0,0)
oBrw:setFocus()
RETURN NIL

* --- Posizione Bottom del Browse
FUNCTION Fine( oBrw )
oBrw:scrollToBottom()
*oBrw:setCurrentCell(oBrw:rowCount()-1,0)
oBrw:setFocus()
RETURN NIL

* ----- funzioni varie

//----------------------------------------//
function IfNil( u, uDefault )
return If( ValType( u ) == "
U", uDefault, u )

//----------------------------------------//
function MsgInfo( cMsg, cTitle )
  local oMsg := QMessageBox():New()
  cTitle = If( cTitle == NIL, "
Information", cTitle )
  oMsg:SetText( cValToChar( cMsg ) )
  oMsg:SetWindowTitle( cTitle )
  oMsg:SetStandardButtons( 0x400 )
  oMsg:SetIcon( 1 )
  oMsg:Exec()
return nil

//----------------------------------------//
function MsgYesNo( cMsg, cTitle )
  local oMsg := QMessageBox():New()
  cTitle = If( cTitle == NIL, "
Question", cTitle )
 
  oMsg:SetText( cValToChar( cMsg ) )
  oMsg:SetWindowTitle( cTitle )
  oMsg:SetStandardButtons( hb_BitOr( 0x4000, 0x10000 ) )
  oMsg:SetIcon( 4 )
return oMsg:Exec() == 0x4000

//----------------------------------------//
function cValToChar( u )
   local cType := ValType( u )
   do case
      case cType == "
A"
           u = "
{ ... } Len: " + AllTrim( Str( Len( u ) ) )

      case cType == "
B"
           u = "
{ || ... }"

      case cType == "
N"
           u = AllTrim( Str( u ) )

      case cType == "
L"
           u = If( u, "
.T.", ".F." )

      case cType == "
D"
           u = DToC( u )

      case cType == "
O"
           u = u:ClassName() + "
object"
           
      case cType == "
U"                  
           u = "
nil"
   endcase
return u

solving
 
Posts: 65
Joined: Fri Jun 05, 2009 7:55 am
Location: Sicily ( ct ) - Italy

Re: Sample code

Postby Antonio Linares » Tue Nov 15, 2016 7:47 pm

Marco,

MarcoBoschi wrote:Thankyou Antonio
Imagine that from this app you have to retrieve
some data from a dbf table.
This dbf is one of many dbf tables of another fivewin programma in a lan. Fivetouch si on smartphone logged in wify.
How can I write button action?


Are those dbfs accesible from the smartphone ? Using an Android file manager utility, you may check if you can reach the DBFs.

If you can find them, then try this:

USE ( "smb://" + ipaddress + "/" + folder + "/" + filename.dbf )
regards, saludos

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

Re: Sample code

Postby Antonio Linares » Tue Nov 15, 2016 7:50 pm

solving wrote:saluti

mio esempio

per la prima questione :
vedi funzione Vedi_P(.....) e Prezzo(.....)

Code: Select all  Expand view

#include "FiveTouch.ch"

FUNCTION Main()

local oDlg,;
      oBtnPre,;
      oBtnInv,;
      oBtnEle,;
      oBtnRac,;
      oBtnNtx,;
      oBtnImp,;
      oBtnEnd

LOCAL cDir := "",fDbf,fNtx

PRIVATE xPath := HB_DIRBASE() + "SOLVING\"

cDir := xPath + "
DATI"

SET DELETE ON
SET CENTURY ON
SET ESCAPE ON
SET DATE ITALIAN
SETCANCEL(.T.)

CLOSE ALL

CLEAR SCREEN

* --- Verifica se Non Esiste la Directory
*     viene creata
IF !lIsDir( cDir )
   MakeDir( cDir )
ENDIF

* --- Imposta Variabili
fDbf := cDir + "
\_DATIL.DBF"
fNtx := cDir + "
\_DATIL.NTX"

* --- Crea File se Non Esiste
Crea_File( fDbf, fNtx, 0 )

DEFINE DIALOG oDlg

oDlg:setWindowTitle( "
Gestione Prezzi" )

* --- Definizione Pulsanti
@ 10, 90 BUTTON oBtnPre PROMPT "
Prezzi" OF oDlg ;
         ACTION Vedi_P( fDbf, fNtx )

@ 10, 220 BUTTON oBtnInv PROMPT "
Inventario" OF oDlg ;
         ACTION Inventa( fDbf, fNtx )

@ 50, 90 BUTTON oBtnRac PROMPT "
ALTRO" OF oDlg ;
         
@ 50, 220 BUTTON oBtnEle PROMPT "
Elenco" OF oDlg ;
         ACTION Elenco( fDbf, fNtx )

@ 90, 90 BUTTON oBtnNtx PROMPT "
Reindex" OF oDlg ;
          ACTION Crea_File( fDbf, fNtx, 1 )

@ 90, 220 BUTTON oBtnImp PROMPT "
Import File" OF oDlg ;
          ACTION Import(fDbf, fNtx, cDir )

@ 250, 90 BUTTON oBtnEnd PROMPT "
Fine" OF oDlg ;
          ACTION oDlg:End()

ACTIVATE DIALOG oDlg CENTERED

return nil

// ------------------------------- CREA_FILE
FUNCTION Crea_File( fDbf, fNtx, nSw )
LOCAL aDbf := {}

//*** Crea Archivio se non esiste
IF !FILE( fDbf )
   AADD(aDbf,{"
CODICE","C",13,0})
   AADD(aDbf,{"
DESC","C",15,0})
   AADD(aDbf,{"
QTA","N",6,2})
   AADD(aDbf,{"
PRE","N",9,3})
   DBCREATE(fDbf,aDbf)
   FERASE(fNtx)
ENDIF

IF nSw == 1
   FERASE(fNtx)
ENDIF

//*** Crea Indice se non esiste
IF !FILE( fNtx )
   USE( fDbf ) ALIAS Dati NEW
   INDEX ON Dati->CODICE TO ( fNtx )
   CLOSE DATABASES
ENDIF

IF nSw == 1
   MsgInfo("
Reindex Completato" )
ENDIF

RETURN NIL

// ----------------------- IMPORT
FUNCTION Import( fDbf, fNtx, cDir )
LOCAL cPath := "
D:\TX\"
LOCAL cFile := "
_DATIL.DBF"

IF MsgYesNo("
Import Dati  ?","Richiesta Import")
   IF FILE( cPath + cFile )

      FERASE( fDbf )
      FERASE( fNtx )

      COPY FILE(cPath + cFile) TO ( cDir +"
\"+ cFile )

      Crea_File( fDbf, fNtx, 1 )
   ELSE  
      MsgInfo("
Non Trovo " + cPath + cFile )
   ENDIF
ENDIF
RETURN NIL

// ----------------------- VEDI_P
FUNCTION Vedi_P( fDbf, fNtx )
LOCAL oDlg, oCod, cCod := SPACE(13)
LOCAL oSco, nSco := "
0", nPre := 0
LOCAL oBtnEnd, oBtnOk

USE( fDbf ) INDEX ( fNtx ) ALIAS Dati NEW

DEFINE DIALOG oDlg TITLE "
Vedi Prezzi" ;
       SIZE 300, 200

@ 160, 25 BUTTON oBtnEnd PROMPT "
Abbandona" OF oDlg ;
          ACTION oDlg:End()

@ 160, 150 BUTTON oBtnOk PROMPT "
Cerca" OF oDlg ;
           ACTION nPre := Prezzo(oDlg, cCod, oCod, nSco)

@ 20, 020 SAY oSay PROMPT "
Codice" OF oDlg
@ 50, 020 SAY oSay PROMPT "
Codice" OF oDlg
@ 70, 020 SAY oSay PROMPT "
Desc. " OF oDlg
@ 90, 020 SAY oSay PROMPT "
Prezzo" OF oDlg
@ 120,020 SAY oSay PROMPT "
Sconto" OF oDlg

@ 15, 060 GET oCod VAR cCod OF oDlg
oCod:setFixedSize(130,25)
*oCod:cursorPosition(0)
*oCod:setMaxLength(13)
oCod:setFocus()

@ 115, 060 GET oSco VAR nSco OF oDlg
oSco:setFixedSize(50,25)
oSco:setInputMask("
00")
oSco:Connect( "
textChanged(QString)",{| cValue | nSco := cValue, Calcolo(oDlg, nPre, nSco)})

ACTIVATE DIALOG oDlg CENTERED

Dati->( DBCLOSEAREA() )
RETURN NIL

// -------------------------------- PREZZO
FUNCTION Prezzo( oDlg, cCod, oCod, nSco )
LOCAL cBar := "
",;
      cDes := "
",;
      nPre := 0, lOk := .F.

LOCAL oLab1 := QLabel( oDlg ),;
      oLab2 := QLabel( oDlg ),;
      oLab3 := QLabel( oDlg )

cCod := ALLTRIM( cCod )

oLab3:setFont( QFont( "
Courier", 11, 75) )
oLab3:setStyleSheet( "
background-color : white; color : blue;" )

* --- Vuota Righe
oLab1:setText( SPACE(30)  )
oLab1:move( 65 , 50 )
oLab1:show()

oLab2:setText( SPACE(50)  )
oLab2:move( 65 , 70 )
oLab2:show()

oLab3:setText( SPACE(15)  )
oLab3:move( 65 , 90 )
oLab3:show()

IF !EMPTY( cCod )
   IF Dati->( DBSeek(cCod) )
      cBar := Dati->CODICE    
      cDes := Dati->DESC
      nPre := Dati->PRE
      lOk := .T.  
   ELSE  
      cDes := "
Cod. Non Trovato"
   ENDIF
ELSE
    cDes := "
Cod. Vuoto"
ENDIF

IF lOk
   * --- Visualizza Dati
   oLab1:setText( cBar  )
   oLab1:move( 65 , 50 )
   oLab1:show()

   oLab2:setText( cDes  )
   oLab2:move( 65 , 70 )
   oLab2:show()

   oLab3:setText( STR(nPre)  )
   oLab3:move( 65 , 90 )
   oLab3:show()
ELSE
   oLab2:setText( cDes  )
   oLab2:move( 65 , 70 )
   oLab2:show()
ENDIF

IF nPre <> 0
   Calcolo(oDlg, nPre, nSco)
ENDIF

oCod:SetText(SPACE(13))
oCod:setFocus()

RETURN( nPre )


// ----------------------- CALCOLO
FUNCTION Calcolo( oDlg, nPre, nSco )
LOCAL nR := "
0"
LOCAL oLab1 := QLabel( oDlg )

nR := nPre - (nPre*(VAL(nSco)/100))
nR := TRANSFORM( nR,"
99.999")

*oLab1:setText(ALLTRIM(STR(nR)))
oLab1:setText(nR)
oLab1:move( 120, 120 )

* 75 = Bold
oLab1:setFont( QFont( "
Courier New", 11, 75) )
oLab1:setStyleSheet( "
background-color : white; color : red;" )
oLab1:show()

RETURN( NIL )

// ----------------------- INVENTA
FUNCTION Inventa( fDbf, fNtx )
LOCAL oDlg
LOCAL oCod, cCod := SPACE(13)
LOCAL oQta, nQta := "
1"
LOCAL oBtnEnd, oBtnOk

USE( fDbf ) INDEX ( fNtx ) ALIAS Dati NEW

DEFINE DIALOG oDlg TITLE "
Inventario" ;
       SIZE 300, 200

@ 160, 25 BUTTON oBtnEnd PROMPT "
Abbandona" OF oDlg ;
          ACTION oDlg:End()

@ 160, 150 BUTTON oBtnOk PROMPT "
Conferma" OF oDlg ;
           ACTION Salva( oDlg, cCod, nQta, oCod, oQta )

@ 20, 020 SAY oSay PROMPT "
Codice" OF oDlg
@ 50, 020 SAY oSay PROMPT "
Q.t…"   OF oDlg
@ 50, 120 SAY oSay PROMPT "
+ o -"  OF oDlg

@ 90, 020 SAY oSay PROMPT "
Desc."  OF oDlg
@ 120,020 SAY oSay PROMPT "
Q.t… Attuale" OF oDlg

@ 15, 060 GET oCod VAR cCod OF oDlg
oCod:setFixedSize(130,25)
oCod:SetMaxLength(13)
oCod:setFocus()

@ 45, 060 GET oQta VAR nQta OF oDlg
oQta:setFixedSize(50,25)
oQta:setInputMask("
xxxx")

ACTIVATE DIALOG oDlg CENTERED

Dati->( DBCLOSEAREA() )
RETURN NIL

// ----------------------- SALVA
FUNCTION Salva( oDlg, cCod, nV, oCod, oQta )
LOCAL lOk := .F., cDes := "
"

LOCAL oLab1 := QLabel( oDlg ),;
      oLab2 := QLabel( oDlg )
     
cCod := ALLTRIM( cCod )

* --- Vuota Righe
oLab1:setText( SPACE(50)  )
oLab1:move( 65 , 60 )
oLab1:show()

oLab2:setText( SPACE(30)  )
oLab2:move( 85 , 90 )
oLab2:show()

IF !EMPTY( cCod )
   IF Dati->( DBSeek(cCod) )
      cDes := Dati->DESC
      nQta := Dati->QTA    
      lOk := .T.
   ELSE  
      cDes := "
Cod. Non Trovato"
   ENDIF
ELSE
    cDes := "
Cod. Vuoto"
ENDIF

IF lOk
   oLab1:setText( cDes  )
   oLab1:move( 65 , 90 )
   oLab1:show()

   oLab2:setText( STR(nQta)  )
   oLab2:move( 85 , 120 )
   oLab2:show()

   IF MsgYesNo("
Memorizzo Dati ?","Conferma")
      Dati->Qta += VAL( nV )
      Dati->( DBCOMMIT() )
   ENDIF

   * --- Vuota le Variabili
   oCod:SetText(SPACE(13))
   oQta:SetText("
1")

   oLab1:setText( SPACE(50))
   oLab1:move( 65 , 90 )
   oLab1:show()

   oLab2:setText( SPACE(10) )
   oLab2:move( 85 , 120 )
   oLab2:show()
ELSE
   oLab1:setText( cDes  )
   oLab1:move( 175 , 90 )
   oLab1:show()
ENDIF

cCod := SPACE(13)
oCod:setFocus()

RETURN NIL

// ------------------------ ELENCO
FUNCTION Elenco( fDbf, fNtx )
local oDlg := QDialog()
local oBrw := QTableView( oDlg )
local oModel := QStandardItemModel( 3, 4, oDlg )
LOCAL nNumRecord := 0, i, oIcon
LOCAL oBtnEnd, oBtnTp, oBtnBt

* --- Dichiaro Button
@ 335, 25 BUTTON oBtnEnd PROMPT "
Abbandona" OF oDlg ;
          ACTION oDlg:End()

@ 335, 150 BUTTON oBtnTp PROMPT "
Inizio" OF oDlg ;
          ACTION Inizio( oBrw )

@ 335, 250 BUTTON oBtnBt PROMPT "
Fine" OF oDlg ;
          ACTION Fine( oBrw )

* --- Imposto Icone nei Pulsanti
*oBtnEnd:SetIcon( QIcon(xPath + "
Exit.png") )
*OBtnEnd:setIconSize(QSize(10,10))

oBtnTp:SetIcon( QIcon(xPath + "
go-top.png") )
*OBtnTp:setIconSize(QSize(65,65))

oBtnBt:SetIcon( QIcon(xPath + "
go-bottom.png") )
*OBtnBt:setIconSize(QSize(65,65))

* --- Apro File
USE( fDbf ) INDEX ( fNtx ) ALIAS Dati NEW
nNumRecord := Dati->( RecCount() )

* --- Imposto Intestazione
oModel:SetHorizontalHeaderItem( 0, QStandardItem( "
Codice" ) )
oModel:SetHorizontalHeaderItem( 1, QStandardItem( "
Descrizione" ) )
oModel:SetHorizontalHeaderItem( 2, QStandardItem( "
Q.t…" ) )
oModel:SetHorizontalHeaderItem( 3, QStandardItem( "
Prezzo" ) )

* --- Carico Dati
For i = 0 TO nNumRecord
    oModel:SetItem( i, 0, QStandardItem( Dati->CODICE ) )
    oModel:SetItem( i, 1, QStandardItem( Dati->DESC ) )
    oModel:SetItem( i, 2, QStandardItem( STR(Dati->QTA) ) )
    oModel:SetItem( i, 3, QStandardItem( STR(Dati->PRE) ) )
    Dati->( DBSKIP() )
NEXT

* --- Chiudo File
Dati->( DBCLOSEAREA() )

* --- Imposto Form Principale
oDlg:SetWindowTitle( "
Elenco" )
oDlg:Resize( 450, 370 )
oDlg:Center()

* --- Imposto Form Browse
oBrw:SetModel( oModel )
oBrw:Resize( 445, 330 )

* --- Imposto Larghezza Colonne della Browse
oBrw:setColumnWidth(0, 90)
oBrw:setColumnWidth(1, 190)
oBrw:setColumnWidth(2, 40)
oBrw:setColumnWidth(3, 50)

* --- Esecuzione
oBrw:show()
oDlg:Exec()

RETURN NIL

* --- Posizione Top del Browse
FUNCTION Inizio( oBrw )
oBrw:scrollToTop()
*oBrw:setCurrentCell(0,0)
oBrw:setFocus()
RETURN NIL

* --- Posizione Bottom del Browse
FUNCTION Fine( oBrw )
oBrw:scrollToBottom()
*oBrw:setCurrentCell(oBrw:rowCount()-1,0)
oBrw:setFocus()
RETURN NIL

* ----- funzioni varie

//----------------------------------------//
function IfNil( u, uDefault )
return If( ValType( u ) == "
U", uDefault, u )

//----------------------------------------//
function MsgInfo( cMsg, cTitle )
  local oMsg := QMessageBox():New()
  cTitle = If( cTitle == NIL, "
Information", cTitle )
  oMsg:SetText( cValToChar( cMsg ) )
  oMsg:SetWindowTitle( cTitle )
  oMsg:SetStandardButtons( 0x400 )
  oMsg:SetIcon( 1 )
  oMsg:Exec()
return nil

//----------------------------------------//
function MsgYesNo( cMsg, cTitle )
  local oMsg := QMessageBox():New()
  cTitle = If( cTitle == NIL, "
Question", cTitle )
 
  oMsg:SetText( cValToChar( cMsg ) )
  oMsg:SetWindowTitle( cTitle )
  oMsg:SetStandardButtons( hb_BitOr( 0x4000, 0x10000 ) )
  oMsg:SetIcon( 4 )
return oMsg:Exec() == 0x4000

//----------------------------------------//
function cValToChar( u )
   local cType := ValType( u )
   do case
      case cType == "
A"
           u = "
{ ... } Len: " + AllTrim( Str( Len( u ) ) )

      case cType == "
B"
           u = "
{ || ... }"

      case cType == "
N"
           u = AllTrim( Str( u ) )

      case cType == "
L"
           u = If( u, "
.T.", ".F." )

      case cType == "
D"
           u = DToC( u )

      case cType == "
O"
           u = u:ClassName() + "
object"
           
      case cType == "
U"                  
           u = "
nil"
   endcase
return u



many thanks for sharing your great example :-)

Could you post some screenshots ? many thanks
regards, saludos

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

Re: Sample code

Postby MarcoBoschi » Wed Nov 16, 2016 6:24 am

Thanks Again
Have a nice day
Marco
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Sample code

Postby solving » Wed Nov 16, 2016 9:42 am

how can I add jpg images in this forum ?
thank you
solving
 
Posts: 65
Joined: Fri Jun 05, 2009 7:55 am
Location: Sicily ( ct ) - Italy

Re: Sample code

Postby Antonio Linares » Wed Nov 16, 2016 10:11 am

email them to me alinares@fivetechsoft.com and I will post them :-)

I upload them to a bitbucket proyect download section (free) and copy here the url using [img]url[/img]
regards, saludos

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

Re: Sample code

Postby Antonio Linares » Thu Nov 17, 2016 10:23 am

Here they are, thanks!

Image

Image

Image

Image

Image
regards, saludos

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

Re: Sample code

Postby Antonio Linares » Thu Nov 17, 2016 10:24 am

The above example should work as it is on Android and iOS (iphone/ipad) using FIveTouch ;-)

same PRG --> Android, iOS and Windows
regards, saludos

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

Re: Sample code

Postby MarcoBoschi » Thu Nov 17, 2016 1:04 pm

Sure, it's very interesting.
For my scenario perhaps is not a good
idea that I open directly from my smartphone the dbf tables
of the program on the lan.

I fear that in case of loss of signal to obtain index corruputed or smiliar.
For this reason I wondering if I can associate to button an action like this
What other actions can I associate to one Button?
Can I launch an url?

oCli := TIPClientHttp():New( "http://192.168.1.100/mobile/myasp.asp?Code="+code )
cRet := oCli:ReadAll()

It would be very nice
Bye
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Sample code

Postby Antonio Linares » Thu Nov 17, 2016 6:55 pm

Marco,

Yes, you can use that code. It is linked into FiveTouch
regards, saludos

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

Re: Sample code

Postby MarcoBoschi » Fri Nov 18, 2016 7:46 am

Ok Antonio
Many Thanks
Marco
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy


Return to FiveTouch

Who is online

Users browsing this forum: No registered users and 2 guests