I have these fields
- Code: Select all Expand view
- static cItemFlds := "INVNUM,SERIAL,ITEMIMG,ITEMCODE,ITEMNAME,QUANTITY,PRICE,TOTALQ,CHECK_IN,CHECK_OUT,DAYS,DISCOUNT,TOTAL,ITEMSTRUCT,ITEMMULTI,ITEMPRN4,ITEMPRNPOS, RECNO()"
at last i must insert recno() because it make this error
the fields are 17 I check also on dbf
on this small test when I press a button "Articolo1" or "articolo2" it insert a rcord on aItems array
AaDd(aItems,{nInvoice,nSerial,cImmagine,cCode,cProdotto,nQuantita,nPrezzo,ntotaleQ,;
dCheck_in,dCheck_out,nDays,nDiscount,nTotal,cItemStruct,lItemMulti,lItemPrnA4,lItemPrnPos })
when i save I made
if ! Empty( oBrowse:aDeleted )
AEval( oBrowse:aDeleted, { |a| a[ 18 ] := -a[ 18 ] } ) // erase recno
RESITEMS->( FW_SaveArrayToDBF( cItemFlds, oBrowse:aDeleted ) )
endif
AEval( aItems, { |a| a[ 1 ] := nInvoice } ) // insert nInvoice number
AEval( aItems, { |a,i| a[ 2 ] := i } ) // insert serial numbers
RESITEMS->( FW_SaveArrayToDBF( cItemFlds, aItems ) ) // save on resitems.dbf
and make error
Error description: Error BASE/1132 Limiti superati: accesso all'array
Args:
[ 1] = A { ... } length: 17
[ 2] = N 18
the small test
- Code: Select all Expand view
#include "fivewin.ch"
REQUEST DBFCDX
REQUEST DBFFPT
EXTERNAL ORDKEYNO,ORDKEYCOUNT,ORDCREATE,ORDKEYGOTO
REQUEST HB_Lang_IT
REQUEST HB_CODEPAGE_ITWIN
static cItemFlds := "INVNUM,SERIAL,ITEMIMG,ITEMCODE,ITEMNAME,QUANTITY,PRICE,TOTALQ,CHECK_IN,CHECK_OUT,DAYS,DISCOUNT,TOTAL,ITEMSTRUCT,ITEMMULTI,ITEMPRN4,ITEMPRNPOS"
Static nAcconto, nDaSaldare, lSaldato
Static ntotale,nSubTotale,nSconto
function Main()
SET DATE FORMAT "dd-mm-yyyy"
SET DELETED ON
SET CENTURY ON
SET EPOCH TO year( date() ) - 20
SET MULTIPLE OFF
SetBalloon( .T. )
HB_LangSelect("IT")
HB_CDPSELECT("ITWIN")
Test()
return nil
Function Test()
Local nInvoice := 1
Local aItems:= {}
local cDir :=".\data\"
local lNew := .t.
local lsave := .f.
local aGet[10]
local oSay[10]
local oDlg,oBrowse,oFolder,oPanelGray
Local oBtnSave,oBtnClose
Local oFont,oFontBold
local oBtnArt1,oBtnArt2 // only for test
local dStagioneMin:= ctod("15/05/2019")
Local dStagioneMax:= ctod("15/09/2019")
BuilDbf(cDir)
nSubTotale:=0
nSconto:= 0
nTotale:= 0
nAcconto:=0
nDaSaldare:=0
lSaldato := .f.
dDataSaldato := "Selezionare una data "
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE FONT oFontBold NAME "TAHOMA" SIZE 0,-14 BOLD
if ! lNew
// copy on aItems the dbf ResItems
aItems := RESITEMS->( FW_DbfToArray( cItemFlds, { || RESITEMS->INVNUM == nInvoice } ) )
else
endif
XBROWSER aItems
DEFINE DIALOG oDlg TITLE "test array" SIZE 1120,650 ;
PIXEL TRUEPIXEL RESIZABLE
@ 1, 0 FOLDEREX oFolder OF oDlg SIZE oDlg:nWidth-585,oDlg:nHeight-390 PIXEL ;
PROMPT "Reservation","Payments"
@ 10,10 Button oBtnArt1 PROMPT "ARTICOLO 1" OF oFolder:aDialogs[1] size 100,40 ACTION INSERT_PRODUCT(aItems,nInvoice,1,oBrowse,aGet,oPanelGray)
@ 10,120 Button oBtnArt2 PROMPT "ARTICOLO 2" OF oFolder:aDialogs[1] size 100,40 ACTION INSERT_PRODUCT(aItems,nInvoice,2,oBrowse,aGet,oPanelGray)
@ 120, 02 XBROWSE oBrowse OF oFolder:aDialogs[1] ;
COLUMNS 3,4,5,6,7,8,9,10,11,12,13;
HEADERS "Ico","Tipo","Servizio","Q.tà","Costo","Tot p q.tà","Dal","al","Giorni","Sconto","Totale" ;
COLSIZES 55, 55,190,50,90,90,140,140,50,60,90 ;
PICTURES nil, nil,"@!","9999","€ 999,999.99","€ 999,999.99", "dd-mmmm-yyyy","dd-mmmm-yyyy","999","€ 999,999.99","€ 999,999.99";
ARRAY aItems ;
SIZE 100,62 PIXEL STYLE FLAT NOBORDER
ADD COLUMN TO XBROWSE oBrowse
bCalcRow := { || (oBrowse:aCols[ 6 ]:VarPut( oBrowse:aCols[ 4 ]:Value * oBrowse:aCols[ 5 ]:Value ),; // TOTALE PER QUANTITà = PREZZO x QUANTITà
oBrowse:aCols[ 9 ]:VarPut((oBrowse:aCols[ 8 ]:Value-oBrowse:aCols[ 7 ]:Value)+1),; // GIORNI = DATA OUT - DATA IN
oBrowse:aCols[ 11 ]:VarPut(( oBrowse:aCols[ 6 ]:value * oBrowse:aCols[ 9 ]:value)-oBrowse:aCols[ 10 ]:value),;
CalcoloTotali(oBrowse,aGet) )}
WITH OBJECT oBrowse
:AddVar( "AAPPEND", nil )
:bClrStd := { || If( oBrowse:aRow == oBrowse:aAppend, { CLR_BLACK, CLR_YELLOW }, { CLR_BLACK, oBrowse:nClrPane } ) }
* :bChange := { || If( oBrowse:nArrayAt < oBrowse:nLen, CheckAppendRow( oBrowse ), nil ) }
* :bPastEof := { || If( oBrowse:aAppend != nil .and. Empty( oBrowse:aAppend[ 3 ] ), nil, ;
* ( AAdd( oBrowse:aArrayData, oBrowse:aAppend := AClone( aBlankItem ) ), ;
* oBrowse:GoBottom(), oBrowse:GoLeftMost(), oBrowse:RefreshCurrent(), ;
* oBrowse:MakeTotals(), oBrowse:Refresh() ) ) }
:bKeyDown := { |k| If( k == VK_DELETE, ( oBrowse:aAppend := nil, oBrowse:Delete(), 0 ), nil ) }
END
WITH OBJECT oBrowse
WITH OBJECT oBrowse:aCols[ 1]
:bFooter := { || Ltrim( Str( oBrowse:KeyNo() ) ) + " / " + LTrim( Str( oBrowse:KeyCount() ) )+" servizi" }
:lBmpStretch := .F.
:lBmpTransparent := .T.
:nwidth := 30
:bStrImage := {|| oBrowse:aArrayData[ oBrowse:narrayat][3] }
END
WITH OBJECT oBrowse:aCols[ 4]
:nWidth := 100
:nDataStrAlign := AL_CENTER
:AddBitmap( { FW_BmpPlus(), FW_BmpMinus() } )
// Right Button
:nEditType := EDIT_BUTTON
:bEditBlock := { |r,c,oCol|IIF(!oBrowse:nArrayAt = 1, oCol:Value + 1,) }
:nBtnBmp := 1
:lBtnTransparent := .t.
// Left Button
:bBmpData := { |v,lSel| If( lSel, 2, 0 ) }
:bBmpAction := { |oCol| IIF(!oBrowse:nArrayAt = 1,IIF( oCol:Value>0,oCol:VarPut( oCol:Value - 1 ),),) }
:bOnChange := bCalcRow
END
WITH OBJECT oBrowse:aCols[ 5]
:cEditPicture := '@ €99,999.99'
END
// colona per totale x qut riga
WITH OBJECT oBrowse:aCols[ 6]
* :nFooterType := AGGR_SUM
:cEditPicture := '@ €99,999.99'
END
WITH OBJECT oBrowse:aCols[ 7]
:nEditType := EDIT_BUTTON
:AddBitmap( "INVOICE_CALENDAR" )
:nBtnBmp := 1
:bEditBlock := { |r,c,o,k| XbrGetDate( o,"Seleziona una data",dStagioneMin,dStagioneMax ) }
:bOnChange := bCalcRow
END
WITH OBJECT oBrowse:aCols[ 8]
:nEditType := EDIT_BUTTON
:AddBitmap( "INVOICE_CALENDAR" )
:nBtnBmp := 1
:bEditBlock := { |r,c,o,k| XbrGetDate( o,"Seleziona una data",dStagioneMin,dStagioneMax ) }
:bOnChange := bCalcRow
END
WITH OBJECT oBrowse:aCols[ 10]
:nEditType := EDIT_GET
:bOnChange := bCalcRow
END
// colona per totale riga
WITH OBJECT oBrowse:aCols[ 11]
:nFooterType := AGGR_SUM
:cEditPicture := '@ €99,999.99'
END
WITH OBJECT oBrowse:aCols[ 12]
:AddBitmap({"INVOICE_CANCELLA","INVOICE_INCOLLA"})
:nBtnBmp := 1
:lBmpStretch := .F.
:lBmpTransparent := .T.
:nwidth := 30
:nEditType := EDIT_BUTTON
:bEditBlock := { ||DeleteRow(oBrowse,aGet) }
:nHeadBmpNo := 2
:cHeader := ""
:bLClickHeader := { ||DeleteAllRows(oBrowse,aGet) }
END
:lDrawBorder := .t.
:lHscroll := .F.
:l2007 := .F.
:l2015 := .T.
:nStretchCol := STRETCHCOL_WIDEST
:nColDividerStyle := LINESTYLE_LIGHTGRAY
:lAllowRowSizing := .F.
:lAllowColSwapping := .F.
:lAllowColHiding := .F.
:nMarqueeStyle := MARQSTYLE_HIGHLROWMS
:CreateFromCode()
END
@ oBrowse:nBottom+5,5 SAY oSay[3] Prompt "SubTotale: €" OF oFolder:aDialogs[1] PIXEL SIZE 70,20 TRANSPARENT
@ oBrowse:nBottom+5,75 GET aGet[5] VAR nSubTotale SIZE 40,12 PIXEL OF oFolder:aDialogs[1] PICTURE ' 99,999.99' READONLY
@ oBrowse:nBottom+5,5 SAY oSay[4] Prompt "Sconto :" OF oFolder:aDialogs[1] PIXEL SIZE 70,20 TRANSPARENT
@ oBrowse:nBottom+5,75 GET aGet[6] VAR nSconto SIZE 40,12 PIXEL RIGHT PICTURE ' 99,999.99' OF oFolder:aDialogs[1];
ON CHANGE (aGet[6]:assign(),CalcoloTotali(oBrowse,aGet) )
@ oBrowse:nBottom+5,5 SAY oSay[5] Prompt "Totale: €" OF oFolder:aDialogs[1] PIXEL FONT oFontBold SIZE 70,20 TRANSPARENT
@ oBrowse:nBottom+5,75 GET aGet[7] VAR nTotale SIZE 40,12 PIXEL PICTURE ' 99,999.99' OF oFolder:aDialogs[1] READONLY
* @ oBrowse:nBottom-25,5 GET aGet[9] VAR nDaSaldare SIZE 100,12 PIXEL PICTURE ' 99,999.99' OF oFolder:aDialogs[1] READONLY UPDATE
@ 520,680 BTNBMP oBtnSave ;
PROMPT "Save" SIZE 130,60 PIXEL OF oDlg;
RESOURCE "INVOICE_SAVE" FLAT RIGHT;
ACTION ( lSave := .T., oDlg:End() )
@ 520,780 BTNBMP oBtnClose ;
PROMPT "Chiudi" SIZE 130,60 PIXEL OF oDlg;
RESOURCE "INVOICE_EXIT" FLAT RIGHT;
ACTION ( oDlg:End() )
oDlg:bResized := <||
local oRect := oDlg:GetCliRect()
oFolder:nWidth := oRect:nRight-2
oFolder:nHeight := oRect:nBottom-60
oBrowse:nTop := oRect:nBottom-300
* oBrowse:nHeight := oRect:nBottom-550
oBrowse:nWidth := oRect:nWidth - 15
oBtnSave:nLeft := oRect:nRight - 300
oBtnsave:nTop := oRect:nBottom - 60
oBtnClose:nLeft := oRect:nRight - 140
oBtnClose:nTop := oRect:nBottom - 60
oBtnArt1:nTop := oRect:ntop +60
oBtnArt1:nLeft := oRect:nLeft +20
oBtnArt2:nTop := oRect:ntop +60
oBtnArt2:nLeft := oRect:nLeft +250
oPanelGray:nTop := oRect:nBottom - 130
oPanelGray:nwidth := oRect:nRight - 18
oSay[3]:nTop := oRect:nBottom - 163 //subtotale
oSay[3]:nLeft := oRect:nRight - 500
oSay[4]:nTop := oRect:nBottom - 163 //sconto
oSay[4]:nLeft := oRect:nRight - 330
oSay[5]:nTop := oRect:nBottom - 163 //totale
oSay[5]:nLeft := oRect:nRight - 175
aGet[5]:nTop := oRect:nBottom - 165
aGet[5]:nLeft := oRect:nRight - 430
aGet[6]:nTop := oRect:nBottom - 165
aGet[6]:nLeft := oRect:nRight - 260
aGet[7]:nTop := oRect:nBottom - 165
aGet[7]:nLeft := oRect:nRight - 100
return nil
>
ACTIVATE DIALOG oDlg CENTERED;
ON INIT ( oPanelGray := PanelGray(oFolder),;
PanelAcconto(oPanelGray,aGet,oBrowse),;
EVAL(oDlg:bResized ) )
IF lSave
// save
if ! Empty( oBrowse:aDeleted )
AEval( oBrowse:aDeleted, { |a| a[ 18 ] := -a[ 18 ] } )
RESITEMS->( FW_SaveArrayToDBF( cItemFlds, oBrowse:aDeleted ) )
endif
AEval( aItems, { |a| a[ 1 ] := nInvoice } )
AEval( aItems, { |a,i| a[ 2 ] := i } )
XBROWSER aItems
RESITEMS->( FW_SaveArrayToDBF( cItemFlds, aItems ) )
ENDIF
RETURN NIL
Function BuilDbf(cDir)
local aStructure
local i
if ! File( cDir+"ResItems.dbf" )
aStructure = {{ "InvNum", "C", 13, 0 }, ; //Invoice Num
{ "Serial", "N", 3, 0 }, ; // number of row
{ "ItemImg", "C", 120, 0 }, ; // image of Item
{ "ItemCode", "C", 2, 0 }, ; // Item Code E/S/ P
{ "ItemName", "C", 30, 0 }, ; // Item Description
{ "Quantity", "N", 3, 3 }, ; // quantity
{ "Price", "N", 9, 2 }, ; // price unit
{ "TotalQ", "N", 9, 2 }, ; // total for quantity
{ "Check_in" , "D", 8, 0 }, ; // date
{ "Check_out", "D", 8, 0 }, ; // date
{ "Days", "N", 3, 0 }, ; // total days
{ "Discount", "N", 9, 2 }, ; // descount
{ "Total", "N", 9, 2 }, ; // total row
{ "ItemStruct", "C", 30, 0 }, ; // structure if Itemcode is S
{ "ItemMulti" , "L", 1, 0 }, ; // Is multiple if Itemcode is S
{ "ItemPrnA4" , "L", 1, 0 }, ; // Print on A4 if Itemcode is S
{ "ItemPrnPos", "L", 1, 0 } } // Print on Pos if Itemcode is S
DBCreate( cDir+"ResItems", aStructure, "DBFCDX" )
ENDIF
USE &(cDir+"RESITEMS"+".dbf") VIA "DBFCDX" NEW
INDEX ON RESITEMS->INVNUM + STR( SERIAL, 3, 0 ) TAG invnum TO resitems
return nil
//--------------------------------------------------------------------------//
Function CalcoloTotali(oBrowse,aGet)
Local n
nTotale:= 0
nSubtotale:= 0
nDaSaldare:= 0
For n=1 to Len(oBrowse:aArrayData)
nSubtotale+= oBrowse:aArrayData[n][13]
next
IF nSconto >0
nTotale:=nSubTotale-nSconto
else
nTotale:=nSubTotale
Endif
IF nAcconto>0
nDaSaldare:=nTotale-nAcconto
else
nDaSaldare:=nTotale
Endif
aGet[5]:refresh() // subtotale
aGet[7]:refresh() // totale
* aGet[8]:refresh() // acconto
aGet[9]:refresh() // da saldare
oBrowse:Refresh(.f.)
oBrowse:GoBottom()
return nil
//-----------------------------------------------------------------------//
Static Function DeleteRow( oBrowse,aGet )
if msgYesNo( i18n("¿ E' sicuro che devo cancellare questa riga ?") )
iF ! oBrowse:nArrayAt = 1
if ! Empty( oBrowse:aArrayData )
ADel( oBrowse:aArrayData, oBrowse:nArrayAt, .t. )
oBrowse:MakeTotals()
oBrowse:Refresh()
CalcoloTotali(oBrowse,aGet)
endif
ELSE
MsgAlert("Non si può cancellare la prima riga")
Endif
Endif
return nil
//-------------------------------------------------------------------------//
//cancella tutte le righe
Static Function DeleteAllRows( oBrowse,aGet )
if msgYesNo( i18n("¿ E' sicuro che devo cancellare tutto ?") )
if ! Empty( oBrowse:aArrayData )
aSize( oBrowse:aArrayData, 0 )
oBrowse:Refresh()
oBrowse:MakeTotals()
CalcoloTotali(oBrowse,aGet)
endif
Endif
return nil
//--------------------------------------------------------------------------//
Function INSERT_PRODUCT(aItems,nInvoice,n,oBrowse,aGet,oPanelGray)
local nSerial:= 0
Local cImmagine := ""
Local cCode := "S"
Local cProdotto := "Articolo"+Ltrim(str(n))
Local nQuantita := 1
Local nPrezzo := 10
Local ntotaleQ := nPrezzo*nQuantita
Local dCheck_in := date()
Local dCheck_out:= date()+1
Local nDays := dCheck_out-dCheck_in
Local nDiscount := 0
Local nTotal := ntotaleQ * nDays
Local cItemStruct:= ""
Local lItemMulti := .f.
Local lItemPrnA4 := .t.
Local lItemPrnPos := .t.
AaDd(aItems,{nInvoice,nSerial,cImmagine,cCode,cProdotto,nQuantita,nPrezzo,ntotaleQ,;
dCheck_in,dCheck_out,nDays,nDiscount,nTotal,cItemStruct,lItemMulti,lItemPrnA4,lItemPrnPos })
CalcoloTotali(oBrowse,aGet)
oBrowse:MakeTotals()
oBrowse:refresh()
oPanelGray:refresh()
return nil
//----------------------------------------------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------//
function PanelGray(oFld)
local oPanel,oBrushGray
Local aGradgray := { nRgb(211,211,211),nRgb(211,211,211)}
DEFINE BRUSH oBrushGray GRADIENT aGradgray
oPanel:=Tpanel():New( 35, 5, 75, oFld:aDialogs[1]:nWidth-5, oFld:aDialogs[1])
oPanel:SetBrush( oBrushGray )
oPanel:bPainted := { || oPanel:Box( 1,1,oPanel:nHeight-1,oPanel:nWidth-1 ) }
return oPanel
//----------------------------------------------------------------------------------//
Function PanelAcconto(oPanelGray,aGet,oBrowse)
Local coloreRosa:= nRGB(255,182,193)
Local coloregiallo:= nRGB(253,251,135)
Local oBtnSaldato
@ 8, 5 SAY "Acconto : " OF oPanelGray SIZE 85, 21 PIXEL TRANSPARENT
@ 6.5,82 GET aGet[8] VAR nAcconto SIZE 100,24 PIXEL OF oPanelGray PICTURE ' 99,999.99' COLOR CLR_BLACK,coloregiallo ;
ON CHANGE (aGet[8]:assign(),CalcoloTotali(oBrowse,aGet))
@ 8,200 SAY "Da Saldare :" OF oPanelGray PIXEL SIZE 90,20 TRANSPARENT
@ 6.5,292 GET aGet[9] VAR nDaSaldare SIZE 100,24 PIXEL PICTURE ' 99,999.99' OF oPanelGray UPDATE
return nil
//-----------------------------------------------------------------------------//