Un DBU con FiveMac

Un DBU con FiveMac

Postby Antonio Linares » Thu May 10, 2012 9:19 pm

Despues de revisar el DBU de Enrico (que me ha gustado mucho):

http://code.google.com/p/fivewin-contributions/downloads/detail?name=EmagDbu238.zip&can=2&q=

hemos decicido construir uno con FiveMac como ejemplo de uso de FiveMac :-)

fivedbu.prg
Code: Select all  Expand view  RUN
#include "FiveMac.ch"

request DbfCdx

static oWnd

//----------------------------------------------------------------------------//

function Main()
 
   BuildMenu()
 
   DEFINE WINDOW oWnd TITLE "FiveDBU for FiveMac"
 
   ACTIVATE WINDOW oWnd MAXIMIZED ;
      VALID MsgYesNo( "Want to end ?" )
 
return nil

//----------------------------------------------------------------------------//
 
function BuildMenu()
 
   local oMenu
 
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."  ACTION MsgInfo( "New" )
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit..." ACTION oWnd:End()
      ENDMENU
     
      MENUITEM "Help"
      MENU
         MENUITEM "Wiki..."
         MENUITEM "About..." ACTION MsgAbout( "(C) FiveTech Software 2012", "FiveMac" )
      ENDMENU
   ENDMENU
 
return oMenu

//----------------------------------------------------------------------------//

function Open()

   local cDbfName := ChooseFile( "Please select a DBF file", "dbf" )
   local oWnd, oBrw
   
   if ! File( cDbfName )
      return nil
   endif
     
   if File( cFileNoExt( cDbfName ) + ".cdx" )  
      USE ( cDbfName ) VIA DBFCDX NEW
   else  
      USE ( cDbfName ) NEW
   endif

   DEFINE WINDOW oWnd TITLE cDbfName ;
      FROM 213, 109 TO 650, 820

   @ 48, 20 BROWSE oBrw OF oWnd SIZE 672, 363 ALIAS Alias()

   @ 8,  10 BUTTON "Top"    OF oWnd ACTION oBrw:GoTop()
   @ 8, 130 BUTTON "Bottom" OF oWnd ACTION oBrw:GoBottom()
   @ 8, 250 BUTTON "Delete" OF oWnd ACTION oBrw:SetColWidth( 2, 300 )
   @ 8, 370 BUTTON "Search" OF oWnd ACTION MsgAlertSheet( oBrw:GetColWidth( 2 ), oWnd:hWnd )
   @ 8, 490 BUTTON "Grid"  OF oWnd ACTION ( oBrw:SetGridLines( 2 ), MsgInfo( oBrw:GetGridLines() ) )
   @ 8, 610 BUTTON "Exit"   OF oWnd ACTION oWnd:End()

   // oBrw:bHeadClick:= { | obj , nindex| if(nindex== 1, msginfo("clickada cabecera"+str(nindex)),)  }
   
   // oBrw:bChanged := { | obj , nindex|   msginfo("cambio a reg:"+str(obj:nRowPos()) ) }

   ACTIVATE WINDOW oWnd ;
      VALID ( ( oBrw:cAlias )->( DbCloseArea() ), .T. )
return nil

//----------------------------------------------------------------------------//


Image
regards, saludos

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

Re: Un DBU con FiveMac

Postby Antonio Linares » Thu May 10, 2012 11:12 pm

Code: Select all  Expand view  RUN
#include "FiveMac.ch"

request DbfCdx

static oWnd

//----------------------------------------------------------------------------//

function Main()
 
   BuildMenu()
 
   DEFINE WINDOW oWnd TITLE "FiveDBU for FiveMac"
 
   ACTIVATE WINDOW oWnd MAXIMIZED ;
      VALID MsgYesNo( "Want to end ?" )
 
return nil

//----------------------------------------------------------------------------//
 
function BuildMenu()
 
   local oMenu
 
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."  ACTION MsgInfo( "New" )
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit..." ACTION oWnd:End()
      ENDMENU
     
      MENUITEM "Help"
      MENU
         MENUITEM "Wiki..."
         MENUITEM "About..." ACTION MsgAbout( "(C) FiveTech Software 2012", "FiveMac" )
      ENDMENU
   ENDMENU
 
return oMenu

//----------------------------------------------------------------------------//

function Open()

   local cDbfName := ChooseFile( "Please select a DBF file", "dbf" )
   local oWnd, oBar, oBrw
   
   if ! File( cDbfName )
      return nil
   endif
     
   if File( cFileNoExt( cDbfName ) + ".cdx" )  
      USE ( cDbfName ) VIA "DBFCDX" NEW
   else  
      USE ( cDbfName ) NEW
   endif

   DEFINE WINDOW oWnd TITLE cDbfName ;
      FROM 213, 109 TO 650, 820

   DEFINE TOOLBAR oBar OF oWnd
   
   DEFINE BUTTON OF oBar PROMPT "Structure" IMAGE "../bitmaps/preferences.png" ;
      ACTION ShowStruct( oBrw:cAlias )

   DEFINE BUTTON OF oBar PROMPT "Exit" IMAGE "../bitmaps/exit2.png" ;
      ACTION oWnd:End()
   
   @ 48, 20 BROWSE oBrw OF oWnd SIZE 672, 363 ALIAS Alias()

   @ 8,  10 BUTTON "Top"    OF oWnd ACTION oBrw:GoTop()
   @ 8, 130 BUTTON "Bottom" OF oWnd ACTION oBrw:GoBottom()
   @ 8, 250 BUTTON "Delete" OF oWnd ACTION oBrw:SetColWidth( 2, 300 )
   @ 8, 370 BUTTON "Search" OF oWnd ACTION MsgAlertSheet( oBrw:GetColWidth( 2 ), oWnd:hWnd )
   @ 8, 490 BUTTON "Grid"  OF oWnd ACTION ( oBrw:SetGridLines( 2 ), MsgInfo( oBrw:GetGridLines() ) )
   @ 8, 610 BUTTON "Exit"   OF oWnd ACTION oWnd:End()

   // oBrw:bHeadClick:= { | obj , nindex| if(nindex== 1, msginfo("clickada cabecera"+str(nindex)),)  }
   
   // oBrw:bChanged := { | obj , nindex|   msginfo("cambio a reg:"+str(obj:nRowPos()) ) }

   ACTIVATE WINDOW oWnd ;
      VALID ( ( oBrw:cAlias )->( DbCloseArea() ), .T. )

return nil

//----------------------------------------------------------------------------//

function ShowStruct( cAlias )

   local oDlg, oBrw, aInfo := ( cAlias )->( DbStruct() )
   
   DEFINE DIALOG oDlg TITLE "Dbf " + cAlias + " fields"
   
   oDlg:SetSize( 430, 395 )

   @ 10, 10 BROWSE oBrw ;
      FIELDS "", "", "", "" ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      OF oDlg SIZE 410, 350
   
   oBrw:SetArray( aInfo )
   oBrw:bLine = { | nRow | { aInfo[ nRow ][ 1 ], aInfo[ nRow ][ 2 ],;
                             Str( aInfo[ nRow ][ 3 ] ), Str( aInfo[ nRow ][ 4 ] ) } }
   
   ACTIVATE DIALOG oDlg CENTERED

return nil

//----------------------------------------------------------------------------//


Image
regards, saludos

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

Re: Un DBU con FiveMac

Postby Antonio Linares » Thu May 10, 2012 11:32 pm

Code: Select all  Expand view  RUN
#include "FiveMac.ch"

request DbfCdx

static oWnd

//----------------------------------------------------------------------------//

function Main()
 
   BuildMenu()
 
   DEFINE WINDOW oWnd TITLE "FiveDBU for FiveMac"
 
   ACTIVATE WINDOW oWnd MAXIMIZED ;
      VALID MsgYesNo( "Want to end ?" )
 
return nil

//----------------------------------------------------------------------------//
 
function BuildMenu()
 
   local oMenu
 
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."  ACTION New()
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit..." ACTION oWnd:End()
      ENDMENU
     
      MENUITEM "Help"
      MENU
         MENUITEM "Wiki..."
         MENUITEM "About..." ACTION MsgAbout( "(C) FiveTech Software 2012", "FiveMac" )
      ENDMENU
   ENDMENU
 
return oMenu

//----------------------------------------------------------------------------//

function New()

   local oDlg, oBrw, cFieldName := "", cType, nLength := 10, nDec := 0
   local cFileName := "", cRDD
   local aFields := {  }
   local oGet,oGetDeci ,oGetName,oGetLen,oCbx
   local oBtnCreate,oBtnEdit
   local aStruct
   
   DEFINE DIALOG oDlg TITLE "DBF Builder" ;
      FROM 207, 274 TO 590, 790

   @ 351, 20 SAY "FieldName:" OF oDlg SIZE 78, 17  

   @ 326, 20 GET oGet VAR cFieldName OF oDlg SIZE 125, 22  

   @ 351, 153 SAY "Type:" OF oDlg SIZE 51, 17  

   @ 326, 153 COMBOBOX oCbx VAR cType OF oDlg ;
      SIZE 124, 25 ITEMS { "Character", "Numeric", "Logical", "Date", "Memo" } ;
      ON CHANGE ( Iif(cType== "Numeric",oGetDeci:enabled() ,oGetDeci:disabled() ) )

   @ 351, 285 SAY "Length:" OF oDlg SIZE 50, 17
   
   @ 326, 285 GET oGetLen VAR nLength OF oDlg SIZE 43, 22  
   
   @ 351, 336 SAY "Dec:" OF oDlg SIZE 31, 17  

   @ 326, 336 GET oGetDeci VAR nDec OF oDlg SIZE 43, 22  
   
   oGetDeci:disabled()
   
   @ 73, 20 LISTBOX oBrw FIELDS "", "", "", "" ;
      HEADERS "FieldName", "Type", "Length", "Decimals" ;
      OF oDlg SIZE 379, 245 ;
      ON CHANGE ( cFieldName:= aFields[oBrw:nrowPos,1],oGet:refresh(),;
                  cType:= aFields[oBrw:nrowPos,2], oCbx:refresh(),;
                  nLength:=  aFields[oBrw:nrowPos,3],oGetLen:refresh() ,;
                  nDec   :=  aFields[oBrw:nrowPos,4],oGetDeci:refresh()  )
   
   oBrw:SetArray( aFields )
   oBrw:bLine = { | nRow | { aFields[ nRow ][ 1 ], aFields[ nRow ][ 2 ], alltrim(str(aFields[ nRow ][ 3 ])),;
                                        alltrim(str(aFields[ nRow ][ 4 ] ))} }
   oBrw:SetSelectorStyle( 1 )   
   oBrw:SetArternateColor( .t. )     
       
   @ 324, 407 BUTTON "Add" OF oDlg ;
        ACTION ( btnAddField(@aFields,{ cFieldName,cType,nLength,nDec },oBrw:nRowPos),;
                        cFieldName :="" ,oBrw:refresh(), oGet:refresh()  )
   
   @ 274, 407 BUTTON oBtnedit PROMPT "Edit" OF oDlg ;
      ACTION ( aFields[oBrw:nRowPos]:= { cFieldName,cType,nLength,nDec } , ;
               cFieldName :="" ,oBrw:refresh(), oGet:refresh()  )
               
   oBtnEdit:disable()
     
   @ 242, 407 BUTTON "Up" OF oDlg ACTION SetFieldUp(@aFields,obrw:nRowPos )
   @ 210, 407 BUTTON "Down" OF oDlg ACTION SetFieldDown(@aFields,obrw:nRowPos )  
   @ 178, 407 BUTTON "Del" OF oDlg ACTION ( aDel( aFields, obrw:nRowPos ),ASize(aFields,Len(aFields)-1),oBrw:Refresh() )  


   @ 48, 20 SAY "DBF filename:" OF oDlg SIZE 92, 17  

   @ 46, 110 GET oGetName VAR cFileName OF oDlg SIZE 275, 22 ;
    VALID ( IF( !Empty(cFileName) .and. len(afields)>0 , oBtnCreate:Enable(),oBtnCreate:disable() ) , .t.   )

   @ 20, 73 SAY "RDD:" OF oDlg SIZE 108, 17  

   @ 16, 110 COMBOBOX cRDD OF oDlg ;
      SIZE 94, 25 ITEMS { "DBFNTX", "DBFCDX" }
     
     
   @ 101, 407 BUTTON "Code Gen." OF oDlg ACTION (msginfo(DbfGen( aFields )))
   

   @ 71, 407 BUTTON "Import" OF oDlg ACTION ( aStruct:= importDbf(), if ( !Empty(aStruct), ( afields:= aStruct,oBrw:SetArray( aFields ) ) ,),oBrw:refresh() )

   @ 41, 407 BUTTON oBtnCreate PROMPT "Create" OF oDlg ;  
             ACTION ( msginfo("crea dbf") , DBCREATE( cFileName, aFields ,cRdd )    )
   
   oBtnCreate:disable()
     
   ACTIVATE DIALOG oDlg
   
return nil

//----------------------------------------------------------------------------//

function SetFieldUp(aFields,nIndex)

   local BakaField

   if nIndex > 1
      BakaField:= aFields[nIndex-1]
      aFields[nIndex-1]:= aFields[nIndex]
      aFields[nIndex]:= BakaField
   endif  

return nil

//----------------------------------------------------------------------------//

function SetFieldDown(aFields,nIndex)

   local BakaField

   if nIndex < len(aFields)
      BakaField:= aFields[nIndex+1]
      aFields[nIndex+1]:= aFields[nIndex]
      aFields[nIndex]:= BakaField
   endif  

return nil

//----------------------------------------------------------------------------//

function importDbf()

   local cFile:=CHOOSEFILE("Select dbf file :","Dbf" )
   local calias
   local aStruct

   if Upper(substr(cFile,len(cfile)-3,4)) == ".DBF"
      USE (cfile) NEW  
      calias:=Alias()
      aStruct:= (calias)->(dbstruct())
      close(calias)
      msginfo(len(aStruct))
   else
      msginfo( Upper(substr(cFile,len(cfile)-3,4))    )  
      msginfo("tipo de archivo incorrecto")
   endif

return aStruct

//----------------------------------------------------------------------------//

function btnAddField( aFields, aField, nAt )

   local aItem

   DEFAULT nAt := Len( aFields )
 
   if Valtype(aField[3]) == "C"
      aField[3]:= val(aField[3])
   endif
 
   if Valtype(aField[4]) == "C"
      aField[4]:= val(aField[4])
   endif
 
   if len(afields) =  0
      nAt:=len(afields)
   endif  
 
   if nAt == Len( aFields)
      AAdd( aFields, aField )
   else    
      ASize( aFields, Len( aFields ) + 1 )
      AIns( aFields, nAt + 1 )
      aFields[ nAt + 1 ] = aField  
   endif
     
return nil

//----------------------------------------------------------------------------//

static function DbfGen( aFields )

   local cPrg  := "local aFields := "
   local aInfo := aFields
   local n, cTempName

   for n = 1 to Len( aInfo )
      cPrg +=  If( n == 1, "{ ", space(18) ) + '{ "' + ;
              aInfo[ n ][ 1 ] + '", "' + ;
              aInfo[ n ][ 2 ] + '", ' + ;
              AllTrim( Str( aInfo[ n ][ 3 ] ) ) + ", " + ;
              AllTrim( Str( aInfo[ n ][ 4 ] ) ) + "}" + ;
              If( n < Len( aInfo ), ",;", " } " ) + CRLF
   next
   
return cPrg

//----------------------------------------------------------------------------//

function Open()

   local cDbfName := ChooseFile( "Please select a DBF file", "dbf" )
   local oWnd, oBar, oBrw
   
   if ! File( cDbfName )
      return nil
   endif
     
   if File( cFileNoExt( cDbfName ) + ".cdx" )  
      USE ( cDbfName ) VIA "DBFCDX" NEW
   else  
      USE ( cDbfName ) NEW
   endif

   DEFINE WINDOW oWnd TITLE cDbfName ;
      FROM 213, 109 TO 650, 820

   DEFINE TOOLBAR oBar OF oWnd
   
   DEFINE BUTTON OF oBar PROMPT "Structure" IMAGE "../bitmaps/preferences.png" ;
      ACTION ShowStruct( oBrw:cAlias )

   DEFINE BUTTON OF oBar PROMPT "Exit" IMAGE "../bitmaps/exit2.png" ;
      ACTION oWnd:End()
   
   @ 48, 20 BROWSE oBrw OF oWnd SIZE 672, 363 ALIAS Alias()

   @ 8,  10 BUTTON "Top"    OF oWnd ACTION oBrw:GoTop()
   @ 8, 130 BUTTON "Bottom" OF oWnd ACTION oBrw:GoBottom()
   @ 8, 250 BUTTON "Delete" OF oWnd ACTION oBrw:SetColWidth( 2, 300 )
   @ 8, 370 BUTTON "Search" OF oWnd ACTION MsgAlertSheet( oBrw:GetColWidth( 2 ), oWnd:hWnd )
   @ 8, 490 BUTTON "Grid"  OF oWnd ACTION ( oBrw:SetGridLines( 2 ), MsgInfo( oBrw:GetGridLines() ) )
   @ 8, 610 BUTTON "Exit"   OF oWnd ACTION oWnd:End()

   // oBrw:bHeadClick:= { | obj , nindex| if(nindex== 1, msginfo("clickada cabecera"+str(nindex)),)  }
   
   // oBrw:bChanged := { | obj , nindex|   msginfo("cambio a reg:"+str(obj:nRowPos()) ) }

   ACTIVATE WINDOW oWnd ;
      VALID ( ( oBrw:cAlias )->( DbCloseArea() ), .T. )

return nil

//----------------------------------------------------------------------------//

function ShowStruct( cAlias )

   local oDlg, oBrw, aInfo := ( cAlias )->( DbStruct() )
   
   DEFINE DIALOG oDlg TITLE "Dbf " + cAlias + " fields"
   
   oDlg:SetSize( 430, 395 )

   @ 10, 10 BROWSE oBrw ;
      FIELDS "", "", "", "" ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      OF oDlg SIZE 410, 350
   
   oBrw:SetArray( aInfo )
   oBrw:bLine = { | nRow | { aInfo[ nRow ][ 1 ], aInfo[ nRow ][ 2 ],;
                             Str( aInfo[ nRow ][ 3 ] ), Str( aInfo[ nRow ][ 4 ] ) } }
   
   ACTIVATE DIALOG oDlg CENTERED

return nil

//----------------------------------------------------------------------------//


Image
regards, saludos

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

Re: Un DBU con FiveMac

Postby Antonio Linares » Fri May 11, 2012 12:21 am

Code: Select all  Expand view  RUN
#include "FiveMac.ch"

request DbfCdx

static oWnd

//----------------------------------------------------------------------------//

function Main()

   local oBar
 
   BuildMenu()
 
   DEFINE WINDOW oWnd TITLE "FiveDBU for FiveMac"

   DEFINE TOOLBAR oBar OF oWnd

   DEFINE BUTTON OF oBar PROMPT "New" IMAGE "../bitmaps/new.png" ;
      ACTION New()
   
   DEFINE BUTTON OF oBar PROMPT "Open" IMAGE "../bitmaps/open.png" ;
      ACTION Open()
     
   DEFINE BUTTON OF oBar PROMPT "Exit" IMAGE "../bitmaps/exit2.png" ;
      ACTION oWnd:End()

   DEFINE MSGBAR OF oWnd

   @ 0, 10 SAY "FiveDbu for FiveMac (c) FiveTech Software 2012" OF oWnd ;
      SIZE 300, 20 RAISED
 
   ACTIVATE WINDOW oWnd MAXIMIZED ;
      VALID MsgYesNo( "Want to end ?" )
 
return nil

//----------------------------------------------------------------------------//
 
function BuildMenu()
 
   local oMenu
 
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."  ACTION New()
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit..." ACTION oWnd:End()
      ENDMENU
     
      MENUITEM "Help"
      MENU
         MENUITEM "Wiki..."
         MENUITEM "About..." ACTION MsgAbout( "(C) FiveTech Software 2012", "FiveMac" )
      ENDMENU
   ENDMENU
 
return oMenu

//----------------------------------------------------------------------------//

function New()

   local oDlg, oBrw, cFieldName := "", cType, nLength := 10, nDec := 0
   local cFileName := "", cRDD
   local aFields := {  }
   local oGet,oGetDeci ,oGetName,oGetLen,oCbx
   local oBtnCreate,oBtnEdit
   local aStruct
   
   DEFINE DIALOG oDlg TITLE "DBF Builder" ;
      FROM 207, 274 TO 590, 790

   @ 351, 20 SAY "FieldName:" OF oDlg SIZE 78, 17  

   @ 326, 20 GET oGet VAR cFieldName OF oDlg SIZE 125, 22  

   @ 351, 153 SAY "Type:" OF oDlg SIZE 51, 17  

   @ 326, 153 COMBOBOX oCbx VAR cType OF oDlg ;
      SIZE 124, 25 ITEMS { "Character", "Numeric", "Logical", "Date", "Memo" } ;
      ON CHANGE ( Iif(cType== "Numeric",oGetDeci:enabled() ,oGetDeci:disabled() ) )

   @ 351, 285 SAY "Length:" OF oDlg SIZE 50, 17
   
   @ 326, 285 GET oGetLen VAR nLength OF oDlg SIZE 43, 22  
   
   @ 351, 336 SAY "Dec:" OF oDlg SIZE 31, 17  

   @ 326, 336 GET oGetDeci VAR nDec OF oDlg SIZE 43, 22  
   
   oGetDeci:disabled()
   
   @ 73, 20 LISTBOX oBrw FIELDS "", "", "", "" ;
      HEADERS "FieldName", "Type", "Length", "Decimals" ;
      OF oDlg SIZE 379, 245 ;
      ON CHANGE ( cFieldName:= aFields[oBrw:nrowPos,1],oGet:refresh(),;
                  cType:= aFields[oBrw:nrowPos,2], oCbx:refresh(),;
                  nLength:=  aFields[oBrw:nrowPos,3],oGetLen:refresh() ,;
                  nDec   :=  aFields[oBrw:nrowPos,4],oGetDeci:refresh()  )
   
   oBrw:SetArray( aFields )
   oBrw:bLine = { | nRow | { aFields[ nRow ][ 1 ], aFields[ nRow ][ 2 ], alltrim(str(aFields[ nRow ][ 3 ])),;
                                        alltrim(str(aFields[ nRow ][ 4 ] ))} }
   oBrw:SetSelectorStyle( 1 )   
   oBrw:SetArternateColor( .t. )     
       
   @ 324, 407 BUTTON "Add" OF oDlg ;
        ACTION ( btnAddField(@aFields,{ cFieldName,cType,nLength,nDec },oBrw:nRowPos),;
                        cFieldName :="" ,oBrw:refresh(), oGet:refresh()  )
   
   @ 274, 407 BUTTON oBtnedit PROMPT "Edit" OF oDlg ;
      ACTION ( aFields[oBrw:nRowPos]:= { cFieldName,cType,nLength,nDec } , ;
               cFieldName :="" ,oBrw:refresh(), oGet:refresh()  )
               
   oBtnEdit:disable()
     
   @ 242, 407 BUTTON "Up" OF oDlg ACTION SetFieldUp(@aFields,obrw:nRowPos )
   @ 210, 407 BUTTON "Down" OF oDlg ACTION SetFieldDown(@aFields,obrw:nRowPos )  
   @ 178, 407 BUTTON "Del" OF oDlg ACTION ( aDel( aFields, obrw:nRowPos ),ASize(aFields,Len(aFields)-1),oBrw:Refresh() )  


   @ 48, 20 SAY "DBF filename:" OF oDlg SIZE 92, 17  

   @ 46, 110 GET oGetName VAR cFileName OF oDlg SIZE 275, 22 ;
    VALID ( IF( !Empty(cFileName) .and. len(afields)>0 , oBtnCreate:Enable(),oBtnCreate:disable() ) , .t.   )

   @ 20, 73 SAY "RDD:" OF oDlg SIZE 108, 17  

   @ 16, 110 COMBOBOX cRDD OF oDlg ;
      SIZE 94, 25 ITEMS { "DBFNTX", "DBFCDX" }
     
     
   @ 101, 407 BUTTON "Code Gen." OF oDlg ACTION (msginfo(DbfGen( aFields )))
   

   @ 71, 407 BUTTON "Import" OF oDlg ACTION ( aStruct:= importDbf(), if ( !Empty(aStruct), ( afields:= aStruct,oBrw:SetArray( aFields ) ) ,),oBrw:refresh() )

   @ 41, 407 BUTTON oBtnCreate PROMPT "Create" OF oDlg ;  
             ACTION ( msginfo("crea dbf") , DBCREATE( cFileName, aFields ,cRdd )    )
   
   oBtnCreate:disable()
     
   ACTIVATE DIALOG oDlg
   
return nil

//----------------------------------------------------------------------------//

function SetFieldUp(aFields,nIndex)

   local BakaField

   if nIndex > 1
      BakaField:= aFields[nIndex-1]
      aFields[nIndex-1]:= aFields[nIndex]
      aFields[nIndex]:= BakaField
   endif  

return nil

//----------------------------------------------------------------------------//

function SetFieldDown(aFields,nIndex)

   local BakaField

   if nIndex < len(aFields)
      BakaField:= aFields[nIndex+1]
      aFields[nIndex+1]:= aFields[nIndex]
      aFields[nIndex]:= BakaField
   endif  

return nil

//----------------------------------------------------------------------------//

function importDbf()

   local cFile:=CHOOSEFILE("Select dbf file :","Dbf" )
   local calias
   local aStruct

   if Upper(substr(cFile,len(cfile)-3,4)) == ".DBF"
      USE (cfile) NEW  
      calias:=Alias()
      aStruct:= (calias)->(dbstruct())
      close(calias)
      msginfo(len(aStruct))
   else
      msginfo( Upper(substr(cFile,len(cfile)-3,4))    )  
      msginfo("tipo de archivo incorrecto")
   endif

return aStruct

//----------------------------------------------------------------------------//

function btnAddField( aFields, aField, nAt )

   local aItem

   DEFAULT nAt := Len( aFields )
 
   if Valtype(aField[3]) == "C"
      aField[3]:= val(aField[3])
   endif
 
   if Valtype(aField[4]) == "C"
      aField[4]:= val(aField[4])
   endif
 
   if len(afields) =  0
      nAt:=len(afields)
   endif  
 
   if nAt == Len( aFields)
      AAdd( aFields, aField )
   else    
      ASize( aFields, Len( aFields ) + 1 )
      AIns( aFields, nAt + 1 )
      aFields[ nAt + 1 ] = aField  
   endif
     
return nil

//----------------------------------------------------------------------------//

static function DbfGen( aFields )

   local cPrg  := "local aFields := "
   local aInfo := aFields
   local n, cTempName

   for n = 1 to Len( aInfo )
      cPrg +=  If( n == 1, "{ ", space(18) ) + '{ "' + ;
              aInfo[ n ][ 1 ] + '", "' + ;
              aInfo[ n ][ 2 ] + '", ' + ;
              AllTrim( Str( aInfo[ n ][ 3 ] ) ) + ", " + ;
              AllTrim( Str( aInfo[ n ][ 4 ] ) ) + "}" + ;
              If( n < Len( aInfo ), ",;", " } " ) + CRLF
   next
   
return cPrg

//----------------------------------------------------------------------------//

function Open()

   local cDbfName := ChooseFile( "Please select a DBF file", "dbf" )
   local oWnd, oBar, oBrw
   
   if ! File( cDbfName )
      return nil
   endif
     
   if File( cFileNoExt( cDbfName ) + ".cdx" )  
      USE ( cDbfName ) VIA "DBFCDX" NEW
   else  
      USE ( cDbfName ) NEW
   endif

   DEFINE WINDOW oWnd TITLE cDbfName ;
      FROM 213, 109 TO 650, 820

   DEFINE TOOLBAR oBar OF oWnd

   DEFINE BUTTON OF oBar PROMPT "Add" IMAGE "../bitmaps/add.png" ;
      ACTION ( ( oBrw:cAlias )->( DbAppend() ), oBrw:Refresh() )
   
   DEFINE BUTTON OF oBar PROMPT "Structure" IMAGE "../bitmaps/preferences.png" ;
      ACTION ShowStruct( oBrw:cAlias )

   DEFINE BUTTON OF oBar PROMPT "Exit" IMAGE "../bitmaps/exit2.png" ;
      ACTION oWnd:End()
   
   @ 65, 20 BROWSE oBrw OF oWnd SIZE 672, 363 ALIAS Alias()

   @ 28,  10 BUTTON "Top"    OF oWnd ACTION oBrw:GoTop()
   @ 28, 130 BUTTON "Bottom" OF oWnd ACTION oBrw:GoBottom()
   @ 28, 250 BUTTON "Delete" OF oWnd ACTION oBrw:SetColWidth( 2, 300 )
   @ 28, 370 BUTTON "Search" OF oWnd ACTION MsgAlertSheet( oBrw:GetColWidth( 2 ), oWnd:hWnd )
   @ 28, 490 BUTTON "Grid"  OF oWnd ACTION ( oBrw:SetGridLines( 2 ), MsgInfo( oBrw:GetGridLines() ) )
   @ 28, 610 BUTTON "Exit"   OF oWnd ACTION oWnd:End()

   // oBrw:bHeadClick:= { | obj , nindex| if(nindex== 1, msginfo("clickada cabecera"+str(nindex)),)  }
   
   // oBrw:bChanged := { | obj , nindex|   msginfo("cambio a reg:"+str(obj:nRowPos()) ) }

   DEFINE MSGBAR OF oWnd

   @ 0, 10 SAY "Alias: " + oBrw:cAlias + ;
               "   Records: 1 / " + AllTrim( Str( ( oBrw:cAlias )->( RecCount() ) ) ) ;
      OF oWnd SIZE 300, 20 RAISED

   ACTIVATE WINDOW oWnd ;
      VALID ( ( oBrw:cAlias )->( DbCloseArea() ), .T. )

return nil

//----------------------------------------------------------------------------//

function ShowStruct( cAlias )

   local oDlg, oBrw, aInfo := ( cAlias )->( DbStruct() )
   
   DEFINE DIALOG oDlg TITLE "Dbf " + cAlias + " fields"
   
   oDlg:SetSize( 430, 395 )

   @ 33, 10 BROWSE oBrw ;
      FIELDS "", "", "", "" ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      OF oDlg SIZE 410, 327
   
   oBrw:SetArray( aInfo )
   oBrw:bLine = { | nRow | { aInfo[ nRow ][ 1 ], aInfo[ nRow ][ 2 ],;
                             Str( aInfo[ nRow ][ 3 ] ), Str( aInfo[ nRow ][ 4 ] ) } }

   DEFINE MSGBAR OF oDlg

   @ 0, 10 SAY "Total fields: " + AllTrim( Str( ( cAlias )->( FCount() ) ) ) ;
      OF oDlg SIZE 300, 20 RAISED
   
   ACTIVATE DIALOG oDlg CENTERED

return nil

//----------------------------------------------------------------------------//


Image

Image
regards, saludos

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

Re: Un DBU con FiveMac

Postby mastintin » Fri May 11, 2012 6:48 am

Antonio ,muy bueno . Viene muy bien tener un programa para editar dbfs dentro del propio Macosx. :D
Saludos.
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Un DBU con FiveMac

Postby Antonio Linares » Fri May 11, 2012 6:00 pm

Manuel,

He usado parte del código que has hecho en SciEdit.prg y asi aprovechamos :-)

La verdad es que es bueno tener un DBU tal cual...
regards, saludos

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

Re: Un DBU con FiveMac

Postby Antonio Linares » Fri May 11, 2012 6:00 pm

Code: Select all  Expand view  RUN
#include "FiveMac.ch"

request DbfCdx

static oWnd

//----------------------------------------------------------------------------//

function Main()

   local oBar
 
   BuildMenu()
 
   DEFINE WINDOW oWnd TITLE "FiveDBU for FiveMac"

   DEFINE TOOLBAR oBar OF oWnd

   DEFINE BUTTON OF oBar PROMPT "New" IMAGE "../bitmaps/new.png" ;
      ACTION New()
   
   DEFINE BUTTON OF oBar PROMPT "Open" IMAGE "../bitmaps/open.png" ;
      ACTION Open()
     
   DEFINE BUTTON OF oBar PROMPT "Exit" IMAGE "../bitmaps/exit2.png" ;
      ACTION oWnd:End()

   DEFINE MSGBAR OF oWnd

   @ 0, 10 SAY "FiveDbu for FiveMac (c) FiveTech Software 2012" OF oWnd ;
      SIZE 300, 20 RAISED
 
   ACTIVATE WINDOW oWnd MAXIMIZED ;
      VALID MsgYesNo( "Want to end ?" )
 
return nil

//----------------------------------------------------------------------------//
 
function BuildMenu()
 
   local oMenu
 
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."  ACTION New()
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit..." ACTION oWnd:End()
      ENDMENU
     
      MENUITEM "Help"
      MENU
         MENUITEM "Wiki..."
         MENUITEM "About..." ACTION MsgAbout( "(C) FiveTech Software 2012", "FiveMac" )
      ENDMENU
   ENDMENU
 
return oMenu

//----------------------------------------------------------------------------//

function New()

   local oDlg, oBrw, cFieldName := "", cType, nLength := 10, nDec := 0
   local cFileName := "", cRDD
   local aFields := {  }
   local oGet,oGetDeci ,oGetName,oGetLen,oCbx
   local oBtnCreate,oBtnEdit
   local aStruct
   
   DEFINE DIALOG oDlg TITLE "DBF Builder" ;
      FROM 207, 274 TO 590, 790

   @ 351, 20 SAY "FieldName:" OF oDlg SIZE 78, 17  

   @ 326, 20 GET oGet VAR cFieldName OF oDlg SIZE 125, 22  

   @ 351, 153 SAY "Type:" OF oDlg SIZE 51, 17  

   @ 326, 153 COMBOBOX oCbx VAR cType OF oDlg ;
      SIZE 124, 25 ITEMS { "Character", "Numeric", "Logical", "Date", "Memo" } ;
      ON CHANGE ( Iif(cType== "Numeric",oGetDeci:enabled() ,oGetDeci:disabled() ) )

   @ 351, 285 SAY "Length:" OF oDlg SIZE 50, 17
   
   @ 326, 285 GET oGetLen VAR nLength OF oDlg SIZE 43, 22  
   
   @ 351, 336 SAY "Dec:" OF oDlg SIZE 31, 17  

   @ 326, 336 GET oGetDeci VAR nDec OF oDlg SIZE 43, 22  
   
   oGetDeci:disabled()
   
   @ 73, 20 LISTBOX oBrw FIELDS "", "", "", "" ;
      HEADERS "FieldName", "Type", "Length", "Decimals" ;
      OF oDlg SIZE 379, 245 ;
      ON CHANGE ( cFieldName:= aFields[oBrw:nrowPos,1],oGet:refresh(),;
                  cType:= aFields[oBrw:nrowPos,2], oCbx:refresh(),;
                  nLength:=  aFields[oBrw:nrowPos,3],oGetLen:refresh() ,;
                  nDec   :=  aFields[oBrw:nrowPos,4],oGetDeci:refresh()  )
   
   oBrw:SetArray( aFields )
   oBrw:bLine = { | nRow | { aFields[ nRow ][ 1 ], aFields[ nRow ][ 2 ], alltrim(str(aFields[ nRow ][ 3 ])),;
                                        alltrim(str(aFields[ nRow ][ 4 ] ))} }
   oBrw:SetSelectorStyle( 1 )   
   oBrw:SetArternateColor( .t. )     
       
   @ 324, 407 BUTTON "Add" OF oDlg ;
        ACTION ( btnAddField(@aFields,{ cFieldName,cType,nLength,nDec },oBrw:nRowPos),;
                        cFieldName :="" ,oBrw:refresh(), oGet:refresh()  )
   
   @ 274, 407 BUTTON oBtnedit PROMPT "Edit" OF oDlg ;
      ACTION ( aFields[oBrw:nRowPos]:= { cFieldName,cType,nLength,nDec } , ;
               cFieldName :="" ,oBrw:refresh(), oGet:refresh()  )
               
   oBtnEdit:disable()
     
   @ 242, 407 BUTTON "Up" OF oDlg ACTION SetFieldUp(@aFields,obrw:nRowPos )
   @ 210, 407 BUTTON "Down" OF oDlg ACTION SetFieldDown(@aFields,obrw:nRowPos )  
   @ 178, 407 BUTTON "Del" OF oDlg ACTION ( aDel( aFields, obrw:nRowPos ),ASize(aFields,Len(aFields)-1),oBrw:Refresh() )  


   @ 48, 20 SAY "DBF filename:" OF oDlg SIZE 92, 17  

   @ 46, 110 GET oGetName VAR cFileName OF oDlg SIZE 275, 22 ;
    VALID ( IF( !Empty(cFileName) .and. len(afields)>0 , oBtnCreate:Enable(),oBtnCreate:disable() ) , .t.   )

   @ 20, 73 SAY "RDD:" OF oDlg SIZE 108, 17  

   @ 16, 110 COMBOBOX cRDD OF oDlg ;
      SIZE 94, 25 ITEMS { "DBFNTX", "DBFCDX" }
     
     
   @ 101, 407 BUTTON "Code Gen." OF oDlg ACTION (msginfo(DbfGen( aFields )))
   

   @ 71, 407 BUTTON "Import" OF oDlg ACTION ( aStruct:= importDbf(), if ( !Empty(aStruct), ( afields:= aStruct,oBrw:SetArray( aFields ) ) ,),oBrw:refresh() )

   @ 41, 407 BUTTON oBtnCreate PROMPT "Create" OF oDlg ;  
             ACTION ( msginfo("crea dbf") , DBCREATE( cFileName, aFields ,cRdd )    )
   
   oBtnCreate:disable()
     
   ACTIVATE DIALOG oDlg
   
return nil

//----------------------------------------------------------------------------//

function SetFieldUp(aFields,nIndex)

   local BakaField

   if nIndex > 1
      BakaField:= aFields[nIndex-1]
      aFields[nIndex-1]:= aFields[nIndex]
      aFields[nIndex]:= BakaField
   endif  

return nil

//----------------------------------------------------------------------------//

function SetFieldDown(aFields,nIndex)

   local BakaField

   if nIndex < len(aFields)
      BakaField:= aFields[nIndex+1]
      aFields[nIndex+1]:= aFields[nIndex]
      aFields[nIndex]:= BakaField
   endif  

return nil

//----------------------------------------------------------------------------//

function importDbf()

   local cFile := ChooseFile( "Select dbf file:", "Dbf" )
   local calias, aStruct

   if Upper( SubStr( cFile, Len( cFile ) - 3, 4 ) ) == ".DBF"
      USE ( cFile ) NEW  
      cAlias = Alias()
      aStruct = ( cAlias )->( DbStruct() )
      close( cAlias )
      MsgInfo( Len( aStruct ) )
   else
      MsgInfo( Upper( SubStr( cFile, Len( cFile ) - 3, 4 ) ) )  
      MsgInfo( "Invalid file type" )
   endif

return aStruct

//----------------------------------------------------------------------------//

function btnAddField( aFields, aField, nAt )

   DEFAULT nAt := Len( aFields )
 
   if Valtype( aField[ 3 ] ) == "C"
      aField[ 3 ] = Val( aField[ 3 ] )
   endif
 
   if Valtype( aField[ 4 ] ) == "C"
      aField[ 4 ] = Val( aField[ 4 ] )
   endif
 
   if Len( aFields ) == 0
      nAt = Len( aFields )
   endif  
 
   if nAt == Len( aFields)
      AAdd( aFields, aField )
   else    
      ASize( aFields, Len( aFields ) + 1 )
      AIns( aFields, nAt + 1 )
      aFields[ nAt + 1 ] = aField  
   endif
     
return nil

//----------------------------------------------------------------------------//

static function DbfGen( aFields )

   local cPrg  := "local aFields := "
   local aInfo := aFields
   local n, cTempName

   for n = 1 to Len( aInfo )
      cPrg +=  If( n == 1, "{ ", space(18) ) + '{ "' + ;
              aInfo[ n ][ 1 ] + '", "' + ;
              aInfo[ n ][ 2 ] + '", ' + ;
              AllTrim( Str( aInfo[ n ][ 3 ] ) ) + ", " + ;
              AllTrim( Str( aInfo[ n ][ 4 ] ) ) + "}" + ;
              If( n < Len( aInfo ), ",;", " } " ) + CRLF
   next
   
return cPrg

//----------------------------------------------------------------------------//

function Open()

   local cDbfName := ChooseFile( "Please select a DBF file", "dbf" )
   local oWnd, oBar, oBrw, oSay
   
   if ! File( cDbfName )
      return nil
   endif
     
   if File( cFileNoExt( cDbfName ) + ".cdx" )  
      USE ( cDbfName ) VIA "DBFCDX" NEW
   else  
      USE ( cDbfName ) NEW
   endif

   DEFINE WINDOW oWnd TITLE cDbfName ;
      FROM 213, 109 TO 650, 820

   DEFINE TOOLBAR oBar OF oWnd

   DEFINE BUTTON OF oBar PROMPT "Add" IMAGE "../bitmaps/add.png" ;
      ACTION ( ( oBrw:cAlias )->( DbAppend() ), oBrw:Refresh() )

   DEFINE BUTTON OF oBar PROMPT "Del" IMAGE "../bitmaps/minus.png" ;
      ACTION If( MsgYesNo( "Delete this record ?" ),;
                 ( ( oBrw:cAlias )->( DbGoTo( oBrw:nRowPos ) ),;
                   ( oBrw:cAlias )->( DbDelete() ), ( oBrw:cAlias )->( DbPack() ),;
                     oBrw:Refresh() ),)
   
   DEFINE BUTTON OF oBar PROMPT "Structure" IMAGE "../bitmaps/preferences.png" ;
      ACTION ShowStruct( oBrw:cAlias )

   DEFINE BUTTON OF oBar PROMPT "Exit" IMAGE "../bitmaps/exit2.png" ;
      ACTION oWnd:End()

   @ 35, 20 BROWSE oBrw OF oWnd SIZE 672, 393 ALIAS Alias()

   // oBrw:bHeadClick:= { | obj , nindex| if(nindex== 1, msginfo("clickada cabecera"+str(nindex)),)  }
   
   oBrw:bChanged = { || oSay:SetText( "Alias: " + oBrw:cAlias + ;
                        "   Record: " + AllTrim( Str( oBrw:nRowPos ) ) + " / " + ;
                        AllTrim( Str( ( oBrw:cAlias )->( RecCount() ) ) ) ) }

   DEFINE MSGBAR OF oWnd

   @ 0, 10 SAY oSay PROMPT "Alias: " + oBrw:cAlias + ;
               "   Record: 1 / " + AllTrim( Str( ( oBrw:cAlias )->( RecCount() ) ) ) ;
      OF oWnd SIZE 300, 20 RAISED

   ACTIVATE WINDOW oWnd ;
      VALID ( ( oBrw:cAlias )->( DbCloseArea() ), .T. )

return nil

//----------------------------------------------------------------------------//

function ShowStruct( cAlias )

   local oDlg, oBrw, aInfo := ( cAlias )->( DbStruct() )
   
   DEFINE DIALOG oDlg TITLE "Dbf " + cAlias + " fields"
   
   oDlg:SetSize( 430, 395 )

   @ 33, 10 BROWSE oBrw ;
      FIELDS "", "", "", "" ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      OF oDlg SIZE 410, 327
   
   oBrw:SetArray( aInfo )
   oBrw:bLine = { | nRow | { aInfo[ nRow ][ 1 ], aInfo[ nRow ][ 2 ],;
                             Str( aInfo[ nRow ][ 3 ] ), Str( aInfo[ nRow ][ 4 ] ) } }

   DEFINE MSGBAR OF oDlg

   @ 0, 10 SAY "Total fields: " + AllTrim( Str( ( cAlias )->( FCount() ) ) ) ;
      OF oDlg SIZE 300, 20 RAISED
   
   ACTIVATE DIALOG oDlg CENTERED

return nil

//----------------------------------------------------------------------------//


Image
regards, saludos

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

Re: Un DBU con FiveMac

Postby Antonio Linares » Fri May 11, 2012 6:31 pm

Code: Select all  Expand view  RUN

#include "FiveMac.ch"

request DbfCdx

static oWnd

//----------------------------------------------------------------------------//

function Main()

   local oBar
 
   BuildMenu()
 
   DEFINE WINDOW oWnd TITLE "FiveDBU for FiveMac"

   DEFINE TOOLBAR oBar OF oWnd

   DEFINE BUTTON OF oBar PROMPT "New" IMAGE "../bitmaps/new.png" ;
      ACTION New()
   
   DEFINE BUTTON OF oBar PROMPT "Open" IMAGE "../bitmaps/open.png" ;
      ACTION Open()
     
   DEFINE BUTTON OF oBar PROMPT "Exit" IMAGE "../bitmaps/exit2.png" ;
      ACTION oWnd:End()

   DEFINE MSGBAR OF oWnd

   @ 0, 10 SAY "FiveDbu for FiveMac (c) FiveTech Software 2012" OF oWnd ;
      SIZE 300, 20 RAISED
 
   ACTIVATE WINDOW oWnd MAXIMIZED ;
      VALID MsgYesNo( "Want to end ?" )
 
return nil

//----------------------------------------------------------------------------//
 
function BuildMenu()
 
   local oMenu
 
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."  ACTION New()
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit..." ACTION oWnd:End()
      ENDMENU
     
      MENUITEM "Help"
      MENU
         MENUITEM "Wiki..."
         MENUITEM "About..." ACTION MsgAbout( "(C) FiveTech Software 2012", "FiveMac" )
      ENDMENU
   ENDMENU
 
return oMenu

//----------------------------------------------------------------------------//

function New()

   local oDlg, oBrw, cFieldName := "", cType, nLength := 10, nDec := 0
   local cFileName := "", cRDD
   local aFields := {  }
   local oGet,oGetDeci ,oGetName,oGetLen,oCbx
   local oBtnCreate,oBtnEdit
   local aStruct
   
   DEFINE DIALOG oDlg TITLE "DBF Builder" ;
      FROM 207, 274 TO 590, 790

   @ 351, 20 SAY "FieldName:" OF oDlg SIZE 78, 17  

   @ 326, 20 GET oGet VAR cFieldName OF oDlg SIZE 125, 22  

   @ 351, 153 SAY "Type:" OF oDlg SIZE 51, 17  

   @ 326, 153 COMBOBOX oCbx VAR cType OF oDlg ;
      SIZE 124, 25 ITEMS { "Character", "Numeric", "Logical", "Date", "Memo" } ;
      ON CHANGE ( Iif(cType== "Numeric",oGetDeci:enabled() ,oGetDeci:disabled() ) )

   @ 351, 285 SAY "Length:" OF oDlg SIZE 50, 17
   
   @ 326, 285 GET oGetLen VAR nLength OF oDlg SIZE 43, 22  
   
   @ 351, 336 SAY "Dec:" OF oDlg SIZE 31, 17  

   @ 326, 336 GET oGetDeci VAR nDec OF oDlg SIZE 43, 22  
   
   oGetDeci:disabled()
   
   @ 73, 20 LISTBOX oBrw FIELDS "", "", "", "" ;
      HEADERS "FieldName", "Type", "Length", "Decimals" ;
      OF oDlg SIZE 379, 245 ;
      ON CHANGE ( cFieldName:= aFields[oBrw:nrowPos,1],oGet:refresh(),;
                  cType:= aFields[oBrw:nrowPos,2], oCbx:refresh(),;
                  nLength:=  aFields[oBrw:nrowPos,3],oGetLen:refresh() ,;
                  nDec   :=  aFields[oBrw:nrowPos,4],oGetDeci:refresh()  )
   
   oBrw:SetArray( aFields )
   oBrw:bLine = { | nRow | { aFields[ nRow ][ 1 ], aFields[ nRow ][ 2 ], alltrim(str(aFields[ nRow ][ 3 ])),;
                                        alltrim(str(aFields[ nRow ][ 4 ] ))} }
   oBrw:SetSelectorStyle( 1 )   
   oBrw:SetArternateColor( .t. )     
       
   @ 324, 407 BUTTON "Add" OF oDlg ;
        ACTION ( btnAddField(@aFields,{ cFieldName,cType,nLength,nDec },oBrw:nRowPos),;
                        cFieldName :="" ,oBrw:refresh(), oGet:refresh()  )
   
   @ 274, 407 BUTTON oBtnedit PROMPT "Edit" OF oDlg ;
      ACTION ( aFields[oBrw:nRowPos]:= { cFieldName,cType,nLength,nDec } , ;
               cFieldName :="" ,oBrw:refresh(), oGet:refresh()  )
               
   oBtnEdit:disable()
     
   @ 242, 407 BUTTON "Up" OF oDlg ACTION SetFieldUp(@aFields,obrw:nRowPos )
   @ 210, 407 BUTTON "Down" OF oDlg ACTION SetFieldDown(@aFields,obrw:nRowPos )  
   @ 178, 407 BUTTON "Del" OF oDlg ACTION ( aDel( aFields, obrw:nRowPos ),ASize(aFields,Len(aFields)-1),oBrw:Refresh() )  


   @ 48, 20 SAY "DBF filename:" OF oDlg SIZE 92, 17  

   @ 46, 110 GET oGetName VAR cFileName OF oDlg SIZE 275, 22 ;
    VALID ( IF( !Empty(cFileName) .and. len(afields)>0 , oBtnCreate:Enable(),oBtnCreate:disable() ) , .t.   )

   @ 20, 73 SAY "RDD:" OF oDlg SIZE 108, 17  

   @ 16, 110 COMBOBOX cRDD OF oDlg ;
      SIZE 94, 25 ITEMS { "DBFNTX", "DBFCDX" }
     
     
   @ 101, 407 BUTTON "Code Gen." OF oDlg ACTION (msginfo(DbfGen( aFields )))
   

   @ 71, 407 BUTTON "Import" OF oDlg ACTION ( aStruct:= importDbf(), if ( !Empty(aStruct), ( afields:= aStruct,oBrw:SetArray( aFields ) ) ,),oBrw:refresh() )

   @ 41, 407 BUTTON oBtnCreate PROMPT "Create" OF oDlg ;  
             ACTION ( msginfo("crea dbf") , DBCREATE( cFileName, aFields ,cRdd )    )
   
   oBtnCreate:disable()
     
   ACTIVATE DIALOG oDlg
   
return nil

//----------------------------------------------------------------------------//

function SetFieldUp( aFields, nIndex )

   local BakaField

   if nIndex > 1
      BakaField = aFields[ nIndex - 1 ]
      aFields[ nIndex - 1 ] = aFields[ nIndex ]
      aFields[ nIndex ] = BakaField
   endif  

return nil

//----------------------------------------------------------------------------//

function SetFieldDown( aFields, nIndex )

   local BakaField

   if nIndex < Len( aFields )
      BakaField = aFields[ nIndex + 1 ]
      aFields[ nIndex + 1 ] = aFields[ nIndex ]
      aFields[ nIndex ] = BakaField
   endif  

return nil

//----------------------------------------------------------------------------//

function importDbf()

   local cFile := ChooseFile( "Select dbf file:", "Dbf" )
   local calias, aStruct

   if Upper( SubStr( cFile, Len( cFile ) - 3, 4 ) ) == ".DBF"
      USE ( cFile ) NEW  
      cAlias = Alias()
      aStruct = ( cAlias )->( DbStruct() )
      close( cAlias )
      MsgInfo( Len( aStruct ) )
   else
      MsgInfo( Upper( SubStr( cFile, Len( cFile ) - 3, 4 ) ) )  
      MsgInfo( "Invalid file type" )
   endif

return aStruct

//----------------------------------------------------------------------------//

function btnAddField( aFields, aField, nAt )

   DEFAULT nAt := Len( aFields )
 
   if Valtype( aField[ 3 ] ) == "C"
      aField[ 3 ] = Val( aField[ 3 ] )
   endif
 
   if Valtype( aField[ 4 ] ) == "C"
      aField[ 4 ] = Val( aField[ 4 ] )
   endif
 
   if Len( aFields ) == 0
      nAt = Len( aFields )
   endif  
 
   if nAt == Len( aFields)
      AAdd( aFields, aField )
   else    
      ASize( aFields, Len( aFields ) + 1 )
      AIns( aFields, nAt + 1 )
      aFields[ nAt + 1 ] = aField  
   endif
     
return nil

//----------------------------------------------------------------------------//

static function DbfGen( aFields )

   local cPrg  := "local aFields := "
   local aInfo := aFields
   local n, cTempName

   for n = 1 to Len( aInfo )
      cPrg +=  If( n == 1, "{ ", space(18) ) + '{ "' + ;
              aInfo[ n ][ 1 ] + '", "' + ;
              aInfo[ n ][ 2 ] + '", ' + ;
              AllTrim( Str( aInfo[ n ][ 3 ] ) ) + ", " + ;
              AllTrim( Str( aInfo[ n ][ 4 ] ) ) + "}" + ;
              If( n < Len( aInfo ), ",;", " } " ) + CRLF
   next
   
return cPrg

//----------------------------------------------------------------------------//

function Open()

   local cDbfName := ChooseFile( "Please select a DBF file", "dbf" )
   local oWnd, oBar, oBrw, oSay
   
   if ! File( cDbfName )
      return nil
   endif
     
   if File( cFileNoExt( cDbfName ) + ".cdx" )  
      USE ( cDbfName ) VIA "DBFCDX" NEW
   else  
      USE ( cDbfName ) NEW
   endif

   DEFINE WINDOW oWnd TITLE cDbfName ;
      FROM 213, 109 TO 650, 820

   DEFINE TOOLBAR oBar OF oWnd

   DEFINE BUTTON OF oBar PROMPT "Add" IMAGE "../bitmaps/add.png" ;
      ACTION ( oBrw:GoBottom(), ( oBrw:cAlias )->( DbAppend() ) )

   DEFINE BUTTON OF oBar PROMPT "Edit" IMAGE "../bitmaps/edit.png" ;
      ACTION RecEdit( oBrw )

   DEFINE BUTTON OF oBar PROMPT "Del" IMAGE "../bitmaps/minus.png" ;
      ACTION If( MsgYesNo( "Delete this record ?" ),;
                 ( ( oBrw:cAlias )->( DbGoTo( oBrw:nRowPos ) ),;
                   ( oBrw:cAlias )->( DbDelete() ), ( oBrw:cAlias )->( DbPack() ),;
                     oBrw:Refresh() ),)

   DEFINE BUTTON OF oBar PROMPT "First" IMAGE "../bitmaps/first.png" ;
      ACTION oBrw:GoTop()

   DEFINE BUTTON OF oBar PROMPT "Last" IMAGE "../bitmaps/last.png" ;
      ACTION oBrw:GoBottom()
   
   DEFINE BUTTON OF oBar PROMPT "Structure" IMAGE "../bitmaps/preferences.png" ;
      ACTION ShowStruct( oBrw:cAlias )

   DEFINE BUTTON OF oBar PROMPT "Exit" IMAGE "../bitmaps/exit2.png" ;
      ACTION oWnd:End()

   @ 35, 20 BROWSE oBrw OF oWnd SIZE 672, 393 ALIAS Alias()

   // oBrw:bHeadClick:= { | obj , nindex| if(nindex== 1, msginfo("clickada cabecera"+str(nindex)),)  }
   
   oBrw:GoTop()
   
   oBrw:bChanged = { || oSay:SetText( "Alias: " + oBrw:cAlias + ;
                        "   Record: " + AllTrim( Str( oBrw:nRowPos ) ) + " / " + ;
                        AllTrim( Str( ( oBrw:cAlias )->( RecCount() ) ) ) ) }

   DEFINE MSGBAR OF oWnd

   @ 0, 10 SAY oSay PROMPT "Alias: " + oBrw:cAlias + ;
               "   Record: 1 / " + AllTrim( Str( ( oBrw:cAlias )->( RecCount() ) ) ) ;
      OF oWnd SIZE 300, 20 RAISED

   ACTIVATE WINDOW oWnd ;
      VALID ( ( oBrw:cAlias )->( DbCloseArea() ), .T. )

return nil

//----------------------------------------------------------------------------//

function ShowStruct( cAlias )

   local oDlg, oBrw, aInfo := ( cAlias )->( DbStruct() )
   
   DEFINE DIALOG oDlg TITLE "Dbf " + cAlias + " fields"
   
   oDlg:SetSize( 430, 395 )

   @ 33, 10 BROWSE oBrw ;
      FIELDS "", "", "", "" ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      OF oDlg SIZE 410, 327
   
   oBrw:SetArray( aInfo )
   oBrw:bLine = { | nRow | { aInfo[ nRow ][ 1 ], aInfo[ nRow ][ 2 ],;
                             Str( aInfo[ nRow ][ 3 ] ), Str( aInfo[ nRow ][ 4 ] ) } }

   DEFINE MSGBAR OF oDlg

   @ 0, 10 SAY "Total fields: " + AllTrim( Str( ( cAlias )->( FCount() ) ) ) ;
      OF oDlg SIZE 300, 20 RAISED
   
   ACTIVATE DIALOG oDlg CENTERED

return nil

//----------------------------------------------------------------------------//

function RecEdit( oBrw )

   MsgInfo( oBrw:cAlias )

return nil

//----------------------------------------------------------------------------//
 


Image
regards, saludos

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

Re: Un DBU con FiveMac

Postby Antonio Linares » Wed May 23, 2012 6:32 pm

Code: Select all  Expand view  RUN
#include "FiveMac.ch"

request DbfCdx

static oWnd

//----------------------------------------------------------------------------//

function Main()

   local oBar
 
   BuildMenu()
 
   DEFINE WINDOW oWnd TITLE "FiveDBU for FiveMac"

   oWnd:SetSize( ScreenWidth(), 0 )
   oWnd:SetPos( ScreenHeight() - oWnd:nHeight, 0 )

   DEFINE TOOLBAR oBar OF oWnd

   DEFINE BUTTON OF oBar PROMPT "New" IMAGE ImgPath() + "new.png" ;
      ACTION New()
   
   DEFINE BUTTON OF oBar PROMPT "Open" IMAGE ImgPath() + "open.png" ;
      ACTION Open()
     
   DEFINE BUTTON OF oBar PROMPT "Exit" IMAGE ImgPath() + "exit2.png" ;
      ACTION oWnd:End()

   ACTIVATE WINDOW oWnd ;
      VALID MsgYesNo( "Want to end ?" )
 
return nil

//----------------------------------------------------------------------------//
 
function BuildMenu()
 
   local oMenu
 
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."  ACTION New()
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit..." ACTION oWnd:End()
      ENDMENU
     
      MENUITEM "Help"
      MENU
         MENUITEM "Wiki..."
         MENUITEM "About..." ACTION MsgAbout( "(C) FiveTech Software 2012", "FiveMac" )
      ENDMENU
   ENDMENU
 
return oMenu

//----------------------------------------------------------------------------//

function New()

   local oDlg, oBrw, cFieldName := "", cType, nLength := 10, nDec := 0
   local cFileName := "", cRDD
   local aFields := {  }
   local oGet,oGetDeci ,oGetName,oGetLen,oCbx
   local oBtnCreate,oBtnEdit
   local aStruct
   
   DEFINE DIALOG oDlg TITLE "DBF Builder" ;
      FROM 207, 274 TO 590, 790

   @ 351, 20 SAY "FieldName:" OF oDlg SIZE 78, 17  

   @ 326, 20 GET oGet VAR cFieldName OF oDlg SIZE 125, 22  

   @ 351, 153 SAY "Type:" OF oDlg SIZE 51, 17  

   @ 326, 153 COMBOBOX oCbx VAR cType OF oDlg ;
      SIZE 124, 25 ITEMS { "Character", "Numeric", "Logical", "Date", "Memo" } ;
      ON CHANGE ( Iif(cType== "Numeric",oGetDeci:enabled() ,oGetDeci:disabled() ) )

   @ 351, 285 SAY "Length:" OF oDlg SIZE 50, 17
   
   @ 326, 285 GET oGetLen VAR nLength OF oDlg SIZE 43, 22
   oGetLen:setnumeric()  
   
   @ 351, 336 SAY "Dec:" OF oDlg SIZE 31, 17  

   @ 326, 336 GET oGetDeci VAR nDec OF oDlg SIZE 43, 22  
   
   oGetDeci:disabled()
   
   @ 73, 20 LISTBOX oBrw FIELDS "", "", "", "" ;
      HEADERS "FieldName", "Type", "Length", "Decimals" ;
      OF oDlg SIZE 379, 245 ;
      ON CHANGE ( cFieldName:= aFields[oBrw:nrowPos,1],oGet:refresh(),;
                  cType:= aFields[oBrw:nrowPos,2], oCbx:refresh(),;
                  nLength:=  aFields[oBrw:nrowPos,3],oGetLen:refresh() ,;
                  nDec   :=  aFields[oBrw:nrowPos,4],oGetDeci:refresh()  )
   
   oBrw:SetArray( aFields )
   oBrw:bLine = { | nRow | { aFields[ nRow ][ 1 ], aFields[ nRow ][ 2 ], alltrim(str(aFields[ nRow ][ 3 ])),;
                                        alltrim(str(aFields[ nRow ][ 4 ] ))} }
   oBrw:SetSelectorStyle( 1 )   
   oBrw:SetAlternateColor( .t. )     
       
   @ 324, 407 BUTTON "Add" OF oDlg ;
        ACTION ( btnAddField(@aFields,{ cFieldName,cType,nLength,nDec },oBrw:nRowPos),;
                        cFieldName :="" ,oBrw:refresh(), oGet:refresh()  )
   
   @ 274, 407 BUTTON oBtnedit PROMPT "Edit" OF oDlg ;
      ACTION ( aFields[oBrw:nRowPos]:= { cFieldName,cType,nLength,nDec } , ;
               cFieldName :="" ,oBrw:refresh(), oGet:refresh()  )
               
   oBtnEdit:disable()
     
   @ 242, 407 BUTTON "Up" OF oDlg ACTION SetFieldUp(@aFields,obrw:nRowPos )
   @ 210, 407 BUTTON "Down" OF oDlg ACTION SetFieldDown(@aFields,obrw:nRowPos )  
   @ 178, 407 BUTTON "Del" OF oDlg ACTION ( aDel( aFields, obrw:nRowPos ),ASize(aFields,Len(aFields)-1),oBrw:Refresh() )  


   @ 48, 20 SAY "DBF filename:" OF oDlg SIZE 92, 17  

   @ 46, 110 GET oGetName VAR cFileName OF oDlg SIZE 275, 22 ;
    VALID ( IF( !Empty(cFileName) .and. len(afields)>0 , oBtnCreate:Enable(),oBtnCreate:disable() ) , .t.   )

   @ 20, 73 SAY "RDD:" OF oDlg SIZE 108, 17  

   @ 16, 110 COMBOBOX cRDD OF oDlg ;
      SIZE 94, 25 ITEMS { "DBFNTX", "DBFCDX" }
     
     
   @ 101, 407 BUTTON "Code Gen." OF oDlg ACTION (msginfo(DbfGen( aFields )))
   

   @ 71, 407 BUTTON "Import" OF oDlg ACTION ( aStruct:= importDbf(), if ( !Empty(aStruct), ( afields:= aStruct,oBrw:SetArray( aFields ) ) ,),oBrw:refresh() )

   @ 41, 407 BUTTON oBtnCreate PROMPT "Create" OF oDlg ;  
             ACTION ( msginfo("crea dbf") , DBCREATE( cFileName, aFields ,cRdd )    )
   
   oBtnCreate:disable()
     
   ACTIVATE DIALOG oDlg
   
return nil

//----------------------------------------------------------------------------//

function SetFieldUp( aFields, nIndex )

   local BakaField

   if nIndex > 1
      BakaField = aFields[ nIndex - 1 ]
      aFields[ nIndex - 1 ] = aFields[ nIndex ]
      aFields[ nIndex ] = BakaField
   endif  

return nil

//----------------------------------------------------------------------------//

function SetFieldDown( aFields, nIndex )

   local BakaField

   if nIndex < Len( aFields )
      BakaField = aFields[ nIndex + 1 ]
      aFields[ nIndex + 1 ] = aFields[ nIndex ]
      aFields[ nIndex ] = BakaField
   endif  

return nil

//----------------------------------------------------------------------------//

function importDbf()

   local cFile := ChooseFile( "Select dbf file:", "Dbf" )
   local calias, aStruct

   if Upper( SubStr( cFile, Len( cFile ) - 3, 4 ) ) == ".DBF"
      USE ( cFile ) NEW  
      cAlias = Alias()
      aStruct = ( cAlias )->( DbStruct() )
      close( cAlias )
      MsgInfo( Len( aStruct ) )
   else
      MsgInfo( Upper( SubStr( cFile, Len( cFile ) - 3, 4 ) ) )  
      MsgInfo( "Invalid file type" )
   endif

return aStruct

//----------------------------------------------------------------------------//

function btnAddField( aFields, aField, nAt )

   DEFAULT nAt := Len( aFields )
 
   if Valtype( aField[ 3 ] ) == "C"
      aField[ 3 ] = Val( aField[ 3 ] )
   endif
 
   if Valtype( aField[ 4 ] ) == "C"
      aField[ 4 ] = Val( aField[ 4 ] )
   endif
 
   if Len( aFields ) == 0
      nAt = Len( aFields )
   endif  
 
   if nAt == Len( aFields)
      AAdd( aFields, aField )
   else    
      ASize( aFields, Len( aFields ) + 1 )
      AIns( aFields, nAt + 1 )
      aFields[ nAt + 1 ] = aField  
   endif
     
return nil

//----------------------------------------------------------------------------//

static function DbfGen( aFields )

   local cPrg  := "local aFields := "
   local aInfo := aFields
   local n, cTempName

   for n = 1 to Len( aInfo )
      cPrg +=  If( n == 1, "{ ", space(18) ) + '{ "' + ;
              aInfo[ n ][ 1 ] + '", "' + ;
              aInfo[ n ][ 2 ] + '", ' + ;
              AllTrim( Str( aInfo[ n ][ 3 ] ) ) + ", " + ;
              AllTrim( Str( aInfo[ n ][ 4 ] ) ) + "}" + ;
              If( n < Len( aInfo ), ",;", " } " ) + CRLF
   next
   
return cPrg

//----------------------------------------------------------------------------//

function Open()

   local cDbfName := ChooseFile( "Please select a DBF file", "dbf" )
   local oWnd, oBar, oBrw, oSay
   
   if ! File( cDbfName )
      return nil
   endif
     
   if File( cFileNoExt( cDbfName ) + ".cdx" )  
      USE ( cDbfName ) VIA "DBFCDX" NEW
   else  
      USE ( cDbfName ) NEW
   endif

   DEFINE WINDOW oWnd TITLE cDbfName ;
      FROM 213, 109 TO 650, 820

   DEFINE TOOLBAR oBar OF oWnd

   DEFINE BUTTON OF oBar PROMPT "Add" IMAGE ImgPath() + "add.png" ;
      ACTION ( oBrw:GoBottom(), ( oBrw:cAlias )->( DbAppend() ) )

   DEFINE BUTTON OF oBar PROMPT "Edit" IMAGE ImgPath() + "edit.png" ;
      ACTION RecEdit( oBrw )

   DEFINE BUTTON OF oBar PROMPT "Del" IMAGE ImgPath() + "minus.png" ;
      ACTION If( MsgYesNo( "Delete this record ?" ),;
                 ( ( oBrw:cAlias )->( DbGoTo( oBrw:nRowPos ) ),;
                   ( oBrw:cAlias )->( DbDelete() ), ( oBrw:cAlias )->( DbPack() ),;
                     oBrw:Refresh() ),)

   DEFINE BUTTON OF oBar PROMPT "First" IMAGE ImgPath() + "first.png" ;
      ACTION oBrw:GoTop()

   DEFINE BUTTON OF oBar PROMPT "Last" IMAGE ImgPath() + "last.png" ;
      ACTION oBrw:GoBottom()
   
   DEFINE BUTTON OF oBar PROMPT "Structure" IMAGE ImgPath() + "preferences.png" ;
      ACTION ShowStruct( oBrw:cAlias )

   DEFINE BUTTON OF oBar PROMPT "Exit" IMAGE ImgPath() + "exit2.png" ;
      ACTION oWnd:End()

   @ 35, 20 BROWSE oBrw OF oWnd SIZE 672, 393 ALIAS Alias()

   // oBrw:bHeadClick:= { | obj , nindex| if(nindex== 1, msginfo("clickada cabecera"+str(nindex)),)  }
   
   oBrw:SetColor( CLR_BLACK, CLR_GRAY )
   
   oBrw:GoTop()
   
   oBrw:bChanged = { || oSay:SetText( "Alias: " + oBrw:cAlias + ;
                        "   Record: " + AllTrim( Str( oBrw:nRowPos ) ) + " / " + ;
                        AllTrim( Str( ( oBrw:cAlias )->( RecCount() ) ) ) ) }

   DEFINE MSGBAR OF oWnd

   @ 0, 10 SAY oSay PROMPT "Alias: " + oBrw:cAlias + ;
               "   Record: 1 / " + AllTrim( Str( ( oBrw:cAlias )->( RecCount() ) ) ) ;
      OF oWnd SIZE 300, 20 RAISED

   ACTIVATE WINDOW oWnd ;
      VALID ( ( oBrw:cAlias )->( DbCloseArea() ), .T. )

return nil

//----------------------------------------------------------------------------//

function ShowStruct( cAlias )

   local oDlg, oBrw, aInfo := ( cAlias )->( DbStruct() )
   
   DEFINE DIALOG oDlg TITLE "Dbf " + cAlias + " fields"
   
   oDlg:SetSize( 430, 395 )

   @ 33, 10 BROWSE oBrw ;
      FIELDS "", "", "", "" ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      OF oDlg SIZE 410, 327
   
   oBrw:SetArray( aInfo )
   oBrw:bLine = { | nRow | { aInfo[ nRow ][ 1 ], aInfo[ nRow ][ 2 ],;
                             Str( aInfo[ nRow ][ 3 ] ), Str( aInfo[ nRow ][ 4 ] ) } }
   oBrw:SetColor( CLR_BLACK, CLR_GRAY )
   
   DEFINE MSGBAR OF oDlg

   @ 0, 10 SAY "Total fields: " + AllTrim( Str( ( cAlias )->( FCount() ) ) ) ;
      OF oDlg SIZE 300, 20 RAISED
   
   ACTIVATE DIALOG oDlg CENTERED

return nil

//----------------------------------------------------------------------------//

function RecEdit( oBrw )

   local oWnd, oBar, oSayRec, nRecNo
   local aRecord, cAlias := oBrw:cAlias
   
   ( cAlias )->( DbGoto( oBrw:nRowPos ) )
   
   nRecNo = ( cAlias )->( RecNo() )
   aRecord = ( cAlias )->( GetRecord() )
   
   DEFINE WINDOW oWnd TITLE "Edit: " + oBrw:cAlias SIZE 600, 500
   
   DEFINE TOOLBAR oBar OF oWnd

   DEFINE BUTTON OF oBar PROMPT "Prev" IMAGE ImgPath() + "first.png" ;
      ACTION ( If( nRecNo > 1, ( cAlias )->( DbGoTo( --nRecNo ) ),),;
               aRecord := ( cAlias )->( GetRecord() ), oBrw:Refresh(),;
               oSayRec:SetText( ( cAlias )->( GetRecNo() ) ) )

   DEFINE BUTTON OF oBar PROMPT "Next" IMAGE ImgPath() + "last.png" ;
      ACTION ( If( nRecNo < ( cAlias )->( RecCount() ), ( cAlias )->( DbGoTo( ++nRecNo ) ),),;
               aRecord := ( cAlias )->( GetRecord() ), oBrw:Refresh(),;
               oSayRec:SetText( ( cAlias )->( GetRecNo() ) ) )
     
   DEFINE BUTTON OF oBar PROMPT "Exit" IMAGE ImgPath() + "exit2.png" ;
      ACTION oWnd:End()
         
   @ 33, 10 BROWSE oBrw ;
      FIELDS "", "" ;
      HEADERS "Field", "Value" ;
      OF oWnd SIZE 579, 436
   
   oBrw:SetColEditable( 1, .F. )
   oBrw:SetColWidth( 2, 454 )
   oBrw:SetArray( aRecord )
   oBrw:bLine = { | nRow | { aRecord[ nRow ][ 1 ], aRecord[ nRow ][ 2 ] } }
   oBrw:SetColor( CLR_BLACK, CLR_GRAY )
   oBrw:GoTop()
   
   DEFINE MSGBAR OF oWnd

   @ 0, 10 SAY oSayRec PROMPT ( cAlias )->( GetRecNo() ) ;
      OF oWnd SIZE 300, 20 RAISED

   ACTIVATE WINDOW oWnd CENTERED

return nil

//----------------------------------------------------------------------------//

function GetRecNo()

return "Record: " + AllTrim( Str( RecNo() ) ) + " / " + ;
                    AllTrim( Str( RecCount() ) )

//----------------------------------------------------------------------------//

function GetRecord()

   local aRecord := {}, n

   for n = 1 to ( Alias() )->( FCount() )
      AAdd( aRecord, { ( Alias() )->( FieldName( n ) ),;
                       cValToChar( ( Alias() )->( FieldGet( n ) ) ) } )
   next                  

return aRecord

//----------------------------------------------------------------------------//


Image
regards, saludos

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

Re: Un DBU con FiveMac

Postby Antonio Linares » Fri May 25, 2012 8:43 pm

Tags support:

Image
regards, saludos

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

Re: Un DBU con FiveMac

Postby ramirezosvaldo2 » Fri Jan 04, 2013 2:56 am

Estimados

Despues de compilar el ultimo ejemplo, tengo lo siguiente

compiling...
Harbour 3.2.0dev (Rev. 18749)
Copyright (c) 1999-2013, http://harbour-project.org/
Compiling 'dbu.prg'...
dbu.prg(294) Warning W0001 Ambiguous reference 'CLR_BLACK'
dbu.prg(294) Warning W0001 Ambiguous reference 'CLR_GRAY'
dbu.prg(331) Warning W0001 Ambiguous reference 'CLR_BLACK'
dbu.prg(331) Warning W0001 Ambiguous reference 'CLR_GRAY'
dbu.prg(354) Error E0030 Syntax error "syntax error at 'WINDOW'"
dbu.prg(380) Warning W0001 Ambiguous reference 'CLR_BLACK'
dbu.prg(380) Warning W0001 Ambiguous reference 'CLR_GRAY'
dbu.prg(388) Error E0030 Syntax error "syntax error at 'WINDOW'"
2 errors

No code generated.
macmini:samples server$

Al parecer CLR_BLACK, No esta declarado, y el comando WINDOW, no acepta todos los parametros.

Baje la utlima actualizacion de fivemac, que creo que pudiera ser el problema,
Que puedo hacer ?
Gracias por la ayuda
Osvaldo Ramirez
ramirezosvaldo2
 
Posts: 58
Joined: Mon Jan 19, 2009 4:40 pm

Re: Un DBU con FiveMac

Postby Antonio Linares » Fri Jan 04, 2013 10:53 am

Osvaldo,

Que versión de OSX usas ?
regards, saludos

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

Re: Un DBU con FiveMac

Postby ramirezosvaldo2 » Fri Jan 04, 2013 4:39 pm

Estimado

Version 10.8.2

Saludos
ramirezosvaldo2
 
Posts: 58
Joined: Mon Jan 19, 2009 4:40 pm

Re: Un DBU con FiveMac

Postby mastintin » Sat Jan 05, 2013 11:26 am

veamos primero si este fivedbu te funciona sin problemas ....http://ge.tt/7N2FQlU/v/0?c
User avatar
mastintin
 
Posts: 1516
Joined: Thu May 27, 2010 2:06 pm

Re: Un DBU con FiveMac

Postby ramirezosvaldo2 » Sat Jan 05, 2013 5:09 pm

Si, este funciona perfecto!

Es el mismo codigo que esta en estos mensajes de Antonio ?

Saludos
Osvaldo Ramirez
ramirezosvaldo2
 
Posts: 58
Joined: Mon Jan 19, 2009 4:40 pm

Next

Return to FiveMac / FivePhone (iPhone, iPad)

Who is online

Users browsing this forum: No registered users and 3 guests