#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