Agregar registro a dbf vacia con txbrowse

Post Reply
User avatar
FranciscoA
Posts: 1964
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Agregar registro a dbf vacia con txbrowse

Post by FranciscoA »

Hola amigos del foro:
Alguno de ustedes podría orientarme sobre ¿cómo agregar un registro en txbrowse sobre una dbf en blanco?
La idea es utilizar exclusivamente txbrowse sin ningún diálogo o gets externos.

El siguiente es el último código, (lo he intentado de diferentes maneras pero no logro hacerlo). Agradeceré mucho su ayuda.


Error description: Error BASE/1004 Class: 'NIL' has no exported method: EVAL
Args:
[ 1] = U

Stack Calls
===========
Called from: => EVAL(0)
Called from: XBrowse.PRG => TXBRWCOLUMN:EDIT(5984)
Called from: XBrowse.PRG => TXBROWSE:KEYCHAR(1639)
Called from: => TWINDOW:HANDLEEVENT(0)
Called from: CONTROL.PRG => TXBROWSE:HANDLEEVENT(0)
Called from: WINDOW.PRG => _FWH(0)
Called from: => WINRUN(0)
Called from: WINDOW.PRG => TMDIFRAME:ACTIVATE(0)
Called from: C:\FWH712\pruebas2\TBAR\mibarra.prg => MAIN(153)


//----------------------------
Function CDiario(oRecta,oBar)
local oChild, oBrw, oCol, cOldSele:=Select()
local n:=0
local cAlias:=cGetNewAlias("CDIAR")
local aCampos := {"CTA","SCTA","SSCTA","SSSCTA","SSSSCTA","DESCRIP","DEBE","HABER","CONCEPTO"}
local aHeaders:= {"CTA","SCT1","SCT2","SCT3","SCTA4","DESCRIPCION DE LA CUENTA","DEBITOS","CREDITOS","CONCEPTO"}
local aWidths:= {32,32,32,32,32,250,90,90,300}

Wmdata->( __dbCopyStruct( cAlias, { } ) )

DbUseArea(.t.,,cAlias,cAlias,.f.)

dbSelectArea(cAlias)

DEFINE WINDOW oChild MDICHILD OF oWnd TITLE "EDICION COMPROBANTE DE DIARIO " + cAlias ;
FROM 0, oRecta:nWidth+1 TO oWnd:nHeight-140, oWnd:nWidth-4 PIXEL

oBrw := TXBrowse():New( oChild )
oBrw:cAlias := cAlias

oBrw:nColDividerStyle := LINESTYLE_INSET
oBrw:nRowDividerStyle := LINESTYLE_INSET
oBrw:lColDividerComplete := .t.
oBrw:nHeaderHeight := 30 //Altura cabeceras de col
oBrw:lFooter := .t. //Que tendrá footer
oBrw:nFooterLines := 1 //Lineas del footer
oBrw:nFooterHeight := 24 //Altura del Footer
oBrw:nMarqueeStyle := MARQSTYLE_HIGHLCELL

oBrw:lFastEdit := .t.

For n:=1 to len( aCampos )
oCol:=oBrw:AddCol(aCampos[n])
oCol:cHeader := aHeaders[n]
oCol:nWidth := aWidths[n]
oCol:nEditType := 1
oCol:bOnPostEdit := {|o, u, n| if(n == VK_RETURN, Edita(o,u,oBrw),) }
Next

oBrw:CreateFromCode()

oChild:oClient := oBrw

ACTIVATE WINDOW oChild ;
ON INIT ( if(oBrw:nDataLines ==0, ( (oBrw:cAlias)->(dbAppend()),oBrw:Refresh() ),), oBrw:SetFocus() ) ;
VALID ( (cAlias)->(dbCloseArea()), Ferase( ".\"+cAlias+".dbf" ), dbSelectArea(cOldSele), .T. )

RETURN NIL

Saludos.
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Post by Daniel Garcia-Gil »

antes de crear el browse valida que exista registro en la DBF, de no existir le haces el append()...
te hago una recomendacion aparte, ya que estas usando un ambiente MDI, usa lo siguiente:
oChild:bGotFocus = { || dbselectarea( cAlias ) }
como lo tienes al abrir varias ventanas siempre apuntaran al ultimo alias selccionado, mientras que asi selecciona el area que abriste en cada ventana
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Aqui tienes un ejemplo:

test.prg

Code: Select all

#include "FiveWin.ch" 
#include "XBrowse.ch" 

function Main() 

   local oWnd, oBrw, oCol 

   USE Customer 
   ZAP

   DEFINE WINDOW oWnd 
    
   @ 0, 0 XBROWSE oBrw OF oWnd ALIAS "Customer" 
    
   oBrw:lFastEdit = .T. 
    
   oCol = oBrw:AddCol() 
   oCol:bStrData    = { || Customer->First } 
   oCol:cHeader     = "First" 
   oCol:nEditType   = EDIT_GET 
   oCol:bOnPostEdit = { | oCol, xVal, nKey | If( RecCount() == 0, ( DbAppend(), oBrw:Refresh() ),), If( nKey == VK_RETURN, Customer->First := xVal,) } 

   oCol = oBrw:AddCol() 
   oCol:bStrData    = { || Customer->Last } 
   oCol:cHeader     = "Last" 
   oCol:nEditType   = EDIT_GET 
   oCol:bOnPostEdit = { | oCol, xVal, nKey | If( RecCount() == 0, DbAppend(),), If( nKey == VK_RETURN, ( Customer->Last := xVal, DbAppend(), oBrw:Refresh() ),) } 
    
   oBrw:CreateFromCode() 
    
   oWnd:oClient = oBrw 

   ACTIVATE WINDOW oWnd 

return nil 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
FranciscoA
Posts: 1964
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Post by FranciscoA »

Saludos mcfox:
Muchas gracias, Lo probé, pero sigue el mismo error.

Antonio:
Muchas gracias. Voy a probarlo.
Tambien, gracias por contestar el correo, Estoy enterado.

Saludos.

Francisco Alegría P.
User avatar
Daniel Garcia-Gil
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita
Contact:

Re: Agregar registro a dbf vacia con txbrowse

Post by Daniel Garcia-Gil »

FranciscoA wrote: Wmdata->( __dbCopyStruct( cAlias, { } ) )
estas usando correctamente esa instruccion??
no deberias indicarle _, pienso que deberia quedar asi

Wmdata->( __dbCopyStruct( cAlias, aCampos ) )
ó
Wmdata->( __dbCopyStruct( cAlias ) )
User avatar
FranciscoA
Posts: 1964
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Agregar registro a dbf vacia con txbrowse

Post by FranciscoA »

mcfox wrote:
FranciscoA wrote: Wmdata->( __dbCopyStruct( cAlias, { } ) )
estas usando correctamente esa instruccion??
no deberias indicarle _, pienso que deberia quedar asi

Wmdata->( __dbCopyStruct( cAlias, aCampos ) )
ó
Wmdata->( __dbCopyStruct( cAlias ) )
Mcfox:
Sigue lo mismo, lo raro es que si empleo desde un comienzo una dbf con datos, no hay problema. Estoy revisando.

Gracias
User avatar
FranciscoA
Posts: 1964
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Post by FranciscoA »

Antonio Linares wrote:Aqui tienes un ejemplo:

test.prg

Code: Select all

#include "FiveWin.ch" 
#include "XBrowse.ch" 

function Main() 

   local oWnd, oBrw, oCol 

   USE Customer 
   ZAP

   DEFINE WINDOW oWnd 
    
   @ 0, 0 XBROWSE oBrw OF oWnd ALIAS "Customer" 
    
   oBrw:lFastEdit = .T. 
    
   oCol = oBrw:AddCol() 
   oCol:bStrData    = { || Customer->First } 
   oCol:cHeader     = "First" 
   oCol:nEditType   = EDIT_GET 
   oCol:bOnPostEdit = { | oCol, xVal, nKey | If( RecCount() == 0, ( DbAppend(), oBrw:Refresh() ),), If( nKey == VK_RETURN, Customer->First := xVal,) } 

   oCol = oBrw:AddCol() 
   oCol:bStrData    = { || Customer->Last } 
   oCol:cHeader     = "Last" 
   oCol:nEditType   = EDIT_GET 
   oCol:bOnPostEdit = { | oCol, xVal, nKey | If( RecCount() == 0, DbAppend(),), If( nKey == VK_RETURN, ( Customer->Last := xVal, DbAppend(), oBrw:Refresh() ),) } 
    
   oBrw:CreateFromCode() 
    
   oWnd:oClient = oBrw 

   ACTIVATE WINDOW oWnd 

return nil 
Antonio: Agradecido. El ejemplo trabaja perfecto.
Saludos.

Francisco J. Alegría P.

Asi quedó: (incluida la recomendación de mcfox)

oCol = oBrw:AddCol()
oCol:bStrData = { || (cAlias)->cta }
oCol:cHeader = "CTA"
oCol:nEditType = EDIT_GET
oCol:bOnPostEdit = { | oCol, xVal, nKey | If( RecCount() == 0, ( DbAppend(), oBrw:Refresh() ),), If( nKey == VK_RETURN, (cAlias)->Cta := xVal,) }


oCol = oBrw:AddCol()
oCol:bStrData = { || (cAlias)->NOMBRE }
oCol:cHeader = "DESCRIPCION DE LA CUENTA"
oCol:nEditType = 0 //no editable, hacer que pase a sig columna
*oCol:bOnPostEdit = { | oCol, xVal, nKey | If( RecCount() == 0, ( DbAppend(), oBrw:Refresh() ),), If( nKey == VK_RETURN, (cAlias)->NOMBRE := xVal,) }

oCol = oBrw:AddCol()
oCol:bStrData = { || Transform((cAlias)->DEBE,"999,999,999.99") }
oCol:nDataStrAlign := 1 //alineado a la derecha
oCol:cHeader = "DEBITOS"
oCol:nEditType = EDIT_GET
oCol:bOnPostEdit = { | oCol, xVal, nKey | If( RecCount() == 0, ( DbAppend(), oBrw:Refresh() ),), If( nKey == VK_RETURN, (cAlias)->DEBE := Val(xVal),) }

oCol = oBrw:AddCol()
oCol:bStrData = { || Transform((cAlias)->HABER,"999,999,999.99") }
oCol:nDataStrAlign := 1
oCol:cHeader = "CREDITOS"
oCol:nEditType = EDIT_GET
oCol:bOnPostEdit = { | oCol, xVal, nKey | If( RecCount() == 0, ( DbAppend(), oBrw:Refresh() ),), If( nKey == VK_RETURN, (cAlias)->HABER := Val(xVal),) }

oCol = oBrw:AddCol()
oCol:bStrData = { || (cAlias)->CONCEPTO }
oCol:cHeader = "CONCEPTO"
oCol:nEditType = EDIT_GET
//Es la ultima columna, agrega nuevo registro en blanco y se va a primer columna.
oCol:bOnPostEdit = { | oCol, xVal, nKey | If( RecCount() == 0, DbAppend(),), If( nKey == VK_RETURN, ( (cAlias)->CONCEPTO := xVal, DbAppend(), oBrw:GoLeftMost(), oBrw:Refresh() ),) }


oBrw:CreateFromCode()

oChild:oClient := oBrw
oChild:bGotFocus = { || dbselectarea( cAlias ) }

ACTIVATE WINDOW oChild ;
ON INIT oBrw:SetFocus() ;
VALID ( (cAlias)->(dbCloseArea()), Ferase( "."+cAlias+".dbf" ), dbSelectArea(cOldSele), .T. )
Post Reply