FiveDBU for 32/64 bits

Post Reply
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

FiveDBU for 32/64 bits

Post by Antonio Linares »

Developing it :-)

Image

FiveDBU.prg

Code: Select all

#include "FiveWin.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

static oWnd

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

function Main()

   local oBar

   DEFINE WINDOW oWnd TITLE "FiveDBU" MDI MENU BuildMenu()

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "New" FILENAME "../bitmaps/32x32/new.bmp" 

   DEFINE BUTTON OF oBar PROMPT "Open" FILENAME "../bitmaps/32x32/open.bmp" ACTION Open()

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ACTION oWnd:End()

   DEFINE MSGBAR PROMPT "FiveDBU 32/64 bits" OF oWnd 2010 KEYBOARD DATE

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

return nil

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

function BuildMenu()

   local oMenu
   
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit" ACTION oWnd:End()
      ENDMENU
      
      // oMenu:AddEdit()
      oMenu:AddMdi()
      oMenu:AddHelp( "FiveDBU", "(c) FiveTech Software 2012" )
   ENDMENU
   
return oMenu      

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

function Open()

   local oWnd, cFileName := cGetFile( "*.dbf", "Please select a DBF" )
   local oBar, oBrw, oMsgBar
   
   if ! File( cFileName )
      return nil
   endif
   
   if File( cFileNoExt( cFileName ) + ".ntx" )
      USE ( cFileName ) VIA "DBFNTX" NEW
   else   
      USE ( cFileName ) VIA "DBFCDX" NEW
   endif        
   
   DEFINE WINDOW oWnd TITLE cFileName MDICHILD

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Add" FILENAME "../bitmaps/32x32/plus.bmp" ;
      ACTION ( ( oBrw:cAlias )->( DbAppend() ), oBrw:Refresh(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Edit" FILENAME "../bitmaps/32x32/edit.bmp" ACTION ( oBrw:cAlias )->( Edit() )

   DEFINE BUTTON OF oBar PROMPT "Del" FILENAME "../bitmaps/32x32/minus.bmp" ACTION oWnd:End()

   DEFINE BUTTON OF oBar PROMPT "Struct" FILENAME "../bitmaps/32x32/setup.bmp" ;
      ACTION ( oBrw:cAlias )->( Struct() ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd LINES ;
      ON CHANGE oMsgBar:SetText( "Alias: " + Alias() + ;
                                 " RecNo: " + AllTrim( Str( RecNo() ) ) + "/" + ;
                                 AllTrim( Str( RecCount() ) ) )

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   oBrw:bLDblClick = { || ( oBrw:cAlias )->( Edit() ) }                      
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar PROMPT "Alias: " + Alias() + " RecNo: " + ;
      AllTrim( Str( RecNo() ) ) + "/" + ;
      AllTrim( Str( RecCount() ) ) OF oWnd 2010 
   
   ACTIVATE WINDOW oWnd
   
return nil   

//----------------------------------------------------------------------------//
   
function Edit()

   local oWnd, aRecord := ( Alias() )->( LoadRecord() ), oBar, oBrw, oMsgBar
   local cAlias := Alias(), oBtnSave
   
   DEFINE WINDOW oWnd TITLE "Edit " + Alias() MDICHILD

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON oBtnSave OF oBar PROMPT "Save" FILENAME "../bitmaps/32x32/floppy.bmp"

   oBtnSave:Disable()

   DEFINE BUTTON OF oBar PROMPT "Prev" FILENAME "../bitmaps/32x32/prev.bmp" ACTION ( cAlias )->( DbSkip( -1 ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Next" FILENAME "../bitmaps/32x32/next.bmp" ACTION ( cAlias )->( DbSkip( 1 ) ) 

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd ARRAY aRecord AUTOCOLS LINES ;
      HEADERS "FieldName", "Value" COLSIZES 150, 400 FASTEDIT

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar PROMPT " RecNo: " + AllTrim( Str( RecNo() ) ) + "/" + ;
      AllTrim( Str( RecCount() ) ) OF oWnd 2010
   
   ACTIVATE WINDOW oWnd
   
return nil      

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

function LoadRecord()

   local aRecord := {}, n
   
   for n = 1 to FCount()
      AAdd( aRecord, { FieldName( n ), cValToChar( FieldGet( n ) ) } )
   next
   
return aRecord      
   
//----------------------------------------------------------------------------// 

function Struct()

   local oDlg, oBrw, aFields := DbStruct()
   
   DEFINE DIALOG oDlg TITLE Alias() + " fields" SIZE 400, 400

   @ 0, 0 XBROWSE oBrw ARRAY aFields AUTOCOLS LINES ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      COLSIZES 150, 50, 80, 80

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   
   oBrw:CreateFromCode()
      
   oDlg:oClient = oBrw
   
   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( BuildStructBar( oDlg, oBrw ), oDlg:Resize(), oBrw:SetFocus() )
   
return nil   

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

function BuildStructBar( oDlg, oBrw )

   local oBar

   DEFINE BUTTONBAR oBar OF oDlg 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Code" FILENAME "../bitmaps/32x32/source.bmp" ;
      ACTION ( TxtStruct(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oDlg:End() GROUP

return nil

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

function TxtStruct()

   local cCode := "local aFields := { ", n
   
   for n = 1 to FCount()
      if n > 1
         cCode += Space( 27 )
      endif   
      cCode += '{ "' + FieldName( n ) + '", "' + ;
               FieldType( n ) + '", ' + ;
               AllTrim( Str( FieldLen( n ) ) ) + ", " + ;
               AllTrim( Str( FieldDec( n ) ) ) + " },;" + CRLF
   next
   
   cCode = SubStr( cCode, 1, Len( cCode ) - 4 ) + " }"
   
   MemoEdit( cCode, "Code" )

return nil

//----------------------------------------------------------------------------//   
regards, saludos

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

Re: FiveDBU for 32/64 bits

Post by Antonio Linares »

Code: Select all

#include "FiveWin.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

static oWnd

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

function Main()

   local oBar

   DEFINE WINDOW oWnd TITLE "FiveDBU" MDI MENU BuildMenu()

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "New" FILENAME "../bitmaps/32x32/new.bmp" 

   DEFINE BUTTON OF oBar PROMPT "Open" FILENAME "../bitmaps/32x32/open.bmp" ACTION Open()

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ACTION oWnd:End()

   DEFINE MSGBAR PROMPT "FiveDBU 32/64 bits" OF oWnd 2010 KEYBOARD DATE

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

return nil

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

function BuildMenu()

   local oMenu
   
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit" ACTION oWnd:End()
      ENDMENU
      
      // oMenu:AddEdit()
      oMenu:AddMdi()
      oMenu:AddHelp( "FiveDBU", "(c) FiveTech Software 2012" )
   ENDMENU
   
return oMenu      

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

function Open()

   local oWnd, cFileName := cGetFile( "*.dbf", "Please select a DBF" )
   local oBar, oBrw, oMsgBar
   
   if ! File( cFileName )
      return nil
   endif
   
   if File( cFileNoExt( cFileName ) + ".ntx" )
      USE ( cFileName ) VIA "DBFNTX" NEW
   else   
      USE ( cFileName ) VIA "DBFCDX" NEW
   endif        
   
   DEFINE WINDOW oWnd TITLE cFileName MDICHILD

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Add" FILENAME "../bitmaps/32x32/plus.bmp" ;
      ACTION ( ( oBrw:cAlias )->( DbAppend() ), oBrw:Refresh(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Edit" FILENAME "../bitmaps/32x32/edit.bmp" ACTION ( oBrw:cAlias )->( Edit() )

   DEFINE BUTTON OF oBar PROMPT "Del" FILENAME "../bitmaps/32x32/minus.bmp" ACTION oWnd:End()

   DEFINE BUTTON OF oBar PROMPT "Struct" FILENAME "../bitmaps/32x32/setup.bmp" ;
      ACTION ( oBrw:cAlias )->( Struct() ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd LINES ;
      ON CHANGE oMsgBar:SetText( "Alias: " + Alias() + ;
                                 " RecNo: " + AllTrim( Str( RecNo() ) ) + "/" + ;
                                 AllTrim( Str( RecCount() ) ) )

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   oBrw:bLDblClick = { || ( oBrw:cAlias )->( Edit() ) }                      
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar PROMPT "Alias: " + Alias() + " RecNo: " + ;
      AllTrim( Str( RecNo() ) ) + "/" + ;
      AllTrim( Str( RecCount() ) ) OF oWnd 2010 
   
   ACTIVATE WINDOW oWnd
   
return nil   

//----------------------------------------------------------------------------//
   
function Edit()

   local oWnd, aRecord := ( Alias() )->( LoadRecord() ), oBar, oBrw, oMsgBar
   local cAlias := Alias(), oBtnSave
   
   DEFINE WINDOW oWnd TITLE "Edit " + Alias() MDICHILD

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON oBtnSave OF oBar PROMPT "Save" FILENAME "../bitmaps/32x32/floppy.bmp"

   oBtnSave:Disable()

   DEFINE BUTTON OF oBar PROMPT "Prev" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( -1 ) ),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Next" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( 1 ) ),;
               If( ( cAlias )->( Eof() ), ( cAlias )->( DbSkip( -1 ) ),),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd ARRAY aRecord AUTOCOLS LINES ;
      HEADERS "FieldName", "Value" COLSIZES 150, 400 FASTEDIT ;
      ON CHANGE ( oMsgBar:cMsgDef := " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + ;
                                 "/" + AllTrim( Str( ( cAlias )->( RecCount() ) ) ),;
                  oMsgBar:Refresh() )                 

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar ;
      PROMPT " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + "/" + ;
      AllTrim( Str( ( cAlias )->( RecCount() ) ) ) OF oWnd 2010
   
   ACTIVATE WINDOW oWnd
   
return nil      

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

function LoadRecord()

   local aRecord := {}, n
   
   for n = 1 to FCount()
      AAdd( aRecord, { FieldName( n ), cValToChar( FieldGet( n ) ) } )
   next
   
return aRecord      
   
//----------------------------------------------------------------------------// 

function Struct()

   local oDlg, oBrw, aFields := DbStruct()
   
   DEFINE DIALOG oDlg TITLE Alias() + " fields" SIZE 400, 400

   @ 0, 0 XBROWSE oBrw ARRAY aFields AUTOCOLS LINES ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      COLSIZES 150, 50, 80, 80

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   
   oBrw:CreateFromCode()
      
   oDlg:oClient = oBrw
   
   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( BuildStructBar( oDlg, oBrw ), oDlg:Resize(), oBrw:SetFocus() )
   
return nil   

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

function BuildStructBar( oDlg, oBrw )

   local oBar

   DEFINE BUTTONBAR oBar OF oDlg 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Code" FILENAME "../bitmaps/32x32/source.bmp" ;
      ACTION ( TxtStruct(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oDlg:End() GROUP

return nil

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

function TxtStruct()

   local cCode := "local aFields := { ", n
   
   for n = 1 to FCount()
      if n > 1
         cCode += Space( 27 )
      endif   
      cCode += '{ "' + FieldName( n ) + '", "' + ;
               FieldType( n ) + '", ' + ;
               AllTrim( Str( FieldLen( n ) ) ) + ", " + ;
               AllTrim( Str( FieldDec( n ) ) ) + " },;" + CRLF
   next
   
   cCode = SubStr( cCode, 1, Len( cCode ) - 4 ) + " }"
   
   MemoEdit( cCode, "Code" )

return nil

//----------------------------------------------------------------------------//   
regards, saludos

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

Re: FiveDBU for 32/64 bits

Post by Antonio Linares »

Code: Select all

#include "FiveWin.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

static oWnd

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

function Main()

   local oBar

   DEFINE WINDOW oWnd TITLE "FiveDBU" MDI MENU BuildMenu()

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "New" FILENAME "../bitmaps/32x32/new.bmp" 

   DEFINE BUTTON OF oBar PROMPT "Open" FILENAME "../bitmaps/32x32/open.bmp" ACTION Open()

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ACTION oWnd:End()

   DEFINE MSGBAR PROMPT "FiveDBU 32/64 bits" OF oWnd 2010 KEYBOARD DATE

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

return nil

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

function BuildMenu()

   local oMenu
   
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit" ACTION oWnd:End()
      ENDMENU
      
      // oMenu:AddEdit()
      oMenu:AddMdi()
      oMenu:AddHelp( "FiveDBU", "(c) FiveTech Software 2012" )
   ENDMENU
   
return oMenu      

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

function Open()

   local oWnd, cFileName := cGetFile( "*.dbf", "Please select a DBF" )
   local oBar, oBrw, oMsgBar
   
   if ! File( cFileName )
      return nil
   endif
   
   if File( cFileNoExt( cFileName ) + ".ntx" )
      USE ( cFileName ) VIA "DBFNTX" NEW
   else   
      USE ( cFileName ) VIA "DBFCDX" NEW
   endif        
   
   DEFINE WINDOW oWnd TITLE cFileName MDICHILD

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Add" FILENAME "../bitmaps/32x32/plus.bmp" ;
      ACTION ( ( oBrw:cAlias )->( DbAppend() ), oBrw:Refresh(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Edit" FILENAME "../bitmaps/32x32/edit.bmp" ACTION ( oBrw:cAlias )->( Edit() )

   DEFINE BUTTON OF oBar PROMPT "Del" FILENAME "../bitmaps/32x32/minus.bmp" ACTION oWnd:End()

   DEFINE BUTTON OF oBar PROMPT "Struct" FILENAME "../bitmaps/32x32/setup.bmp" ;
      ACTION ( oBrw:cAlias )->( Struct() ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd LINES ;
      ON CHANGE oMsgBar:SetText( "Alias: " + Alias() + ;
                                 " RecNo: " + AllTrim( Str( RecNo() ) ) + "/" + ;
                                 AllTrim( Str( RecCount() ) ) )

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   oBrw:bLDblClick = { || ( oBrw:cAlias )->( Edit() ) }                      
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar PROMPT "Alias: " + Alias() + " RecNo: " + ;
      AllTrim( Str( RecNo() ) ) + "/" + ;
      AllTrim( Str( RecCount() ) ) OF oWnd 2010 
   
   ACTIVATE WINDOW oWnd
   
return nil   

//----------------------------------------------------------------------------//
   
function Edit()

   local oWnd, aRecord := ( Alias() )->( LoadRecord() ), oBar, oBrw, oMsgBar
   local cAlias := Alias(), oBtnSave
   
   DEFINE WINDOW oWnd TITLE "Edit " + Alias() MDICHILD

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON oBtnSave OF oBar PROMPT "Save" FILENAME "../bitmaps/32x32/floppy.bmp"

   oBtnSave:Disable()

   DEFINE BUTTON OF oBar PROMPT "Prev" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( -1 ) ),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Next" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( 1 ) ),;
               If( ( cAlias )->( Eof() ), ( cAlias )->( DbSkip( -1 ) ),),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd ARRAY aRecord AUTOCOLS LINES ;
      HEADERS "FieldName", "Value" COLSIZES 150, 400 FASTEDIT ;
      ON CHANGE ( oMsgBar:cMsgDef := " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + ;
                                 "/" + AllTrim( Str( ( cAlias )->( RecCount() ) ) ),;
                  oMsgBar:Refresh() )                 

   oBrw:nEditTypes = EDIT_GET
   oBrw:aCols[ 1 ]:nEditType = 0 // Don't allow to edit first column
   oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar ;
      PROMPT " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + "/" + ;
      AllTrim( Str( ( cAlias )->( RecCount() ) ) ) OF oWnd 2010
   
   ACTIVATE WINDOW oWnd
   
return nil      

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

function LoadRecord()

   local aRecord := {}, n
   
   for n = 1 to FCount()
      AAdd( aRecord, { FieldName( n ), cValToChar( FieldGet( n ) ) } )
   next
   
return aRecord      
   
//----------------------------------------------------------------------------// 

function Struct()

   local oDlg, oBrw, aFields := DbStruct()
   
   DEFINE DIALOG oDlg TITLE Alias() + " fields" SIZE 400, 400

   @ 0, 0 XBROWSE oBrw ARRAY aFields AUTOCOLS LINES ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      COLSIZES 150, 50, 80, 80

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   
   oBrw:CreateFromCode()
      
   oDlg:oClient = oBrw
   
   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( BuildStructBar( oDlg, oBrw ), oDlg:Resize(), oBrw:SetFocus() )
   
return nil   

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

function BuildStructBar( oDlg, oBrw )

   local oBar

   DEFINE BUTTONBAR oBar OF oDlg 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Code" FILENAME "../bitmaps/32x32/source.bmp" ;
      ACTION ( TxtStruct(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oDlg:End() GROUP

return nil

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

function TxtStruct()

   local cCode := "local aFields := { ", n
   
   for n = 1 to FCount()
      if n > 1
         cCode += Space( 27 )
      endif   
      cCode += '{ "' + FieldName( n ) + '", "' + ;
               FieldType( n ) + '", ' + ;
               AllTrim( Str( FieldLen( n ) ) ) + ", " + ;
               AllTrim( Str( FieldDec( n ) ) ) + " },;" + CRLF
   next
   
   cCode = SubStr( cCode, 1, Len( cCode ) - 4 ) + " }"
   
   MemoEdit( cCode, "Code" )

return nil

//----------------------------------------------------------------------------//   
regards, saludos

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

Re: FiveDBU for 32/64 bits

Post by Antonio Linares »

Implemented records auto editing:

Code: Select all

#include "FiveWin.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

static oWnd

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

function Main()

   local oBar

   DEFINE WINDOW oWnd TITLE "FiveDBU" MDI MENU BuildMenu()

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "New" FILENAME "../bitmaps/32x32/new.bmp" 

   DEFINE BUTTON OF oBar PROMPT "Open" FILENAME "../bitmaps/32x32/open.bmp" ACTION Open()

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ACTION oWnd:End()

   DEFINE MSGBAR PROMPT "FiveDBU 32/64 bits" OF oWnd 2010 KEYBOARD DATE

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

return nil

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

function BuildMenu()

   local oMenu
   
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit" ACTION oWnd:End()
      ENDMENU
      
      // oMenu:AddEdit()
      oMenu:AddMdi()
      oMenu:AddHelp( "FiveDBU", "(c) FiveTech Software 2012" )
   ENDMENU
   
return oMenu      

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

function Open()

   local oWnd, cFileName := cGetFile( "*.dbf", "Please select a DBF" )
   local oBar, oBrw, oMsgBar
   
   if ! File( cFileName )
      return nil
   endif
   
   if File( cFileNoExt( cFileName ) + ".ntx" )
      USE ( cFileName ) VIA "DBFNTX" NEW
   else   
      USE ( cFileName ) VIA "DBFCDX" NEW
   endif        
   
   DEFINE WINDOW oWnd TITLE cFileName MDICHILD

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Add" FILENAME "../bitmaps/32x32/plus.bmp" ;
      ACTION ( ( oBrw:cAlias )->( DbAppend() ), oBrw:Refresh(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Edit" FILENAME "../bitmaps/32x32/edit.bmp" ACTION ( oBrw:cAlias )->( Edit() )

   DEFINE BUTTON OF oBar PROMPT "Del" FILENAME "../bitmaps/32x32/minus.bmp" ACTION oWnd:End()

   DEFINE BUTTON OF oBar PROMPT "Struct" FILENAME "../bitmaps/32x32/setup.bmp" ;
      ACTION ( oBrw:cAlias )->( Struct() ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd LINES ;
      ON CHANGE oMsgBar:SetText( "Alias: " + Alias() + ;
                                 " RecNo: " + AllTrim( Str( RecNo() ) ) + "/" + ;
                                 AllTrim( Str( RecCount() ) ) )

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   oBrw:bLDblClick = { || ( oBrw:cAlias )->( Edit() ) }                      
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar PROMPT "Alias: " + Alias() + " RecNo: " + ;
      AllTrim( Str( RecNo() ) ) + "/" + ;
      AllTrim( Str( RecCount() ) ) OF oWnd 2010 
   
   ACTIVATE WINDOW oWnd
   
return nil   

//----------------------------------------------------------------------------//
   
function Edit()

   local oWnd, aRecord := ( Alias() )->( LoadRecord() ), oBar, oBrw, oMsgBar
   local cAlias := Alias(), oBtnSave, nRecNo := ( Alias() )->( RecNo() )
   
   DEFINE WINDOW oWnd TITLE "Edit " + Alias() MDICHILD

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON oBtnSave OF oBar PROMPT "Save" FILENAME "../bitmaps/32x32/floppy.bmp" ;
      ACTION ( ( cAlias )->( SaveRecord( aRecord, nRecNo ) ), oBtnSave:Disable() )

   oBtnSave:Disable()

   DEFINE BUTTON OF oBar PROMPT "Prev" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( -1 ) ),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Next" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( 1 ) ),;
               If( ( cAlias )->( Eof() ), ( cAlias )->( DbSkip( -1 ) ),),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd ARRAY aRecord AUTOCOLS LINES ;
      HEADERS "FieldName", "Value" COLSIZES 150, 400 FASTEDIT ;
      ON CHANGE ( oMsgBar:cMsgDef := " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + ;
                                 "/" + AllTrim( Str( ( cAlias )->( RecCount() ) ) ),;
                  oMsgBar:Refresh() )                 

   oBrw:nEditTypes = EDIT_GET
   oBrw:aCols[ 1 ]:nEditType = 0 // Don't allow to edit first column
   oBrw:aCols[ 2 ]:bOnChange = { || oBtnSave:Enable() }
   oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar ;
      PROMPT " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + "/" + ;
      AllTrim( Str( ( cAlias )->( RecCount() ) ) ) OF oWnd 2010
   
   ACTIVATE WINDOW oWnd
   
return nil      

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

function LoadRecord()

   local aRecord := {}, n
   
   for n = 1 to FCount()
      AAdd( aRecord, { FieldName( n ), cValToChar( FieldGet( n ) ) } )
   next
   
return aRecord      
   
//----------------------------------------------------------------------------// 

function SaveRecord( aRecord, nRecNo )

   local n, cType

   ( Alias() )->( DbGoTo( nRecNo ) )
   
   for n = 1 to Len( aRecord )
       cType = ( Alias() )->( FieldType( n ) )
       
       do case
          case cType $ "C,M"
               ( Alias() )->( FieldPut( n, aRecord[ n ][ 2 ] ) )
              
          case cType == "N"
               ( Alias() )->( FieldPut( n, Val( aRecord[ n ][ 2 ] ) ) )

          case cType == "D"
               ( Alias() )->( FieldPut( n, CToD( aRecord[ n ][ 2 ] ) ) )

          case cType == "L"
               ( Alias() )->( FieldPut( n, Upper( AllTrim( aRecord[ n ][ 2 ] ) ) == ".T." ) )
       endcase        
   next

   MsgInfo( "Record updated" )
   
return nil      

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

function Struct()

   local oDlg, oBrw, aFields := DbStruct()
   
   DEFINE DIALOG oDlg TITLE Alias() + " fields" SIZE 400, 400

   @ 0, 0 XBROWSE oBrw ARRAY aFields AUTOCOLS LINES ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      COLSIZES 150, 50, 80, 80

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   
   oBrw:CreateFromCode()
      
   oDlg:oClient = oBrw
   
   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( BuildStructBar( oDlg, oBrw ), oDlg:Resize(), oBrw:SetFocus() )
   
return nil   

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

function BuildStructBar( oDlg, oBrw )

   local oBar

   DEFINE BUTTONBAR oBar OF oDlg 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Code" FILENAME "../bitmaps/32x32/source.bmp" ;
      ACTION ( TxtStruct(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oDlg:End() GROUP

return nil

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

function TxtStruct()

   local cCode := "local aFields := { ", n
   
   for n = 1 to FCount()
      if n > 1
         cCode += Space( 27 )
      endif   
      cCode += '{ "' + FieldName( n ) + '", "' + ;
               FieldType( n ) + '", ' + ;
               AllTrim( Str( FieldLen( n ) ) ) + ", " + ;
               AllTrim( Str( FieldDec( n ) ) ) + " },;" + CRLF
   next
   
   cCode = SubStr( cCode, 1, Len( cCode ) - 4 ) + " }"
   
   MemoEdit( cCode, "Code" )

return nil

//----------------------------------------------------------------------------//   
regards, saludos

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

Re: FiveDBU for 32/64 bits

Post by Antonio Linares »

Index tags automatic selection:

Image

Code: Select all

#include "FiveWin.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

static oWndMain

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

function Main()

   local oBar

   DEFINE WINDOW oWndMain TITLE "FiveDBU" MDI MENU BuildMenu()

   DEFINE BUTTONBAR oBar OF oWndMain 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "New" FILENAME "../bitmaps/32x32/new.bmp" 

   DEFINE BUTTON OF oBar PROMPT "Open" FILENAME "../bitmaps/32x32/open.bmp" ACTION Open()

   DEFINE BUTTON OF oBar PROMPT "Prev" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION oWndMain:PrevWindow() GROUP WHEN Len( oWndMain:oWndClient:aWnd ) > 1

   DEFINE BUTTON OF oBar PROMPT "Next" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION oWndMain:NextWindow() WHEN Len( oWndMain:oWndClient:aWnd ) > 1

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oWndMain:End() GROUP

   DEFINE MSGBAR PROMPT "FiveDBU 32/64 bits" OF oWndMain 2010 KEYBOARD DATE

   ACTIVATE WINDOW oWndMain MAXIMIZED ;
      VALID MsgYesNo( "Want to end ?" )

return nil

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

function BuildMenu()

   local oMenu
   
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit" ACTION oWndMain:End()
      ENDMENU
      
      // oMenu:AddEdit()
      oMenu:AddMdi()
      oMenu:AddHelp( "FiveDBU", "(c) FiveTech Software 2012" )
   ENDMENU
   
return oMenu      

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

function Open()

   local oWnd, cFileName := cGetFile( "*.dbf", "Please select a DBF" )
   local oBar, oBrw, oMsgBar, oPopup, cAlias
   
   if ! File( cFileName )
      return nil
   endif
   
   if File( cFileNoExt( cFileName ) + ".ntx" )
      USE ( cFileName ) VIA "DBFNTX" NEW
   else   
      USE ( cFileName ) VIA "DBFCDX" NEW
      cAlias = Alias()
   endif        
   
   MENU oPopup POPUP
      for n = 1 to 15
         if ! Empty( OrdName( n ) )
            if ! Empty( OrdName( 1 ) )
               DbSetOrder( OrdName( 1 ) )
            endif   
            MENUITEM OrdName( n ) ;
               ACTION ( ( cAlias )->( DbSetOrder( oMenuItem:cPrompt ) ),;
                        oBrw:Refresh(), oBrw:SetFocus() )
         endif
      next    
   ENDMENU   
   
   DEFINE WINDOW oWnd TITLE cFileName MDICHILD

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Add" FILENAME "../bitmaps/32x32/plus.bmp" ;
      ACTION ( ( oBrw:cAlias )->( DbAppend() ), oBrw:Refresh(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Edit" FILENAME "../bitmaps/32x32/edit.bmp" ACTION ( oBrw:cAlias )->( Edit() )

   DEFINE BUTTON OF oBar PROMPT "Del" FILENAME "../bitmaps/32x32/minus.bmp" ;
      ACTION If( MsgYesNo( "Want to delete this record ?" ),;
                ( ( oBrw:cAlias )->( DbDelete() ), oBrw:Refresh() ),)

   DEFINE BUTTON OF oBar PROMPT "Index" FILENAME "../bitmaps/32x32/index.bmp" ;
      GROUP MENU oPopup

   DEFINE BUTTON OF oBar PROMPT "Top" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION ( oBrw:GoTop(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Bottom" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION ( oBrw:GoBottom(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Struct" FILENAME "../bitmaps/32x32/setup.bmp" ;
      ACTION ( oBrw:cAlias )->( Struct() ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd LINES ;
      ON CHANGE oMsgBar:SetText( "Alias: " + Alias() + ;
                                 " RecNo: " + AllTrim( Str( RecNo() ) ) + "/" + ;
                                 AllTrim( Str( RecCount() ) ) )

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   oBrw:bLDblClick = { || ( oBrw:cAlias )->( Edit() ) }                      
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar PROMPT "Alias: " + Alias() + " RecNo: " + ;
      AllTrim( Str( RecNo() ) ) + "/" + ;
      AllTrim( Str( RecCount() ) ) OF oWnd 2010 
   
   ACTIVATE WINDOW oWnd
   
return nil   

//----------------------------------------------------------------------------//
   
function Edit()

   local oWnd, aRecord := ( Alias() )->( LoadRecord() ), oBar, oBrw, oMsgBar
   local cAlias := Alias(), oBtnSave, nRecNo := ( Alias() )->( RecNo() )
   
   DEFINE WINDOW oWnd TITLE "Edit " + Alias() MDICHILD

   oWndMain:oBar:AEvalWhen()

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON oBtnSave OF oBar PROMPT "Save" FILENAME "../bitmaps/32x32/floppy.bmp" ;
      ACTION ( ( cAlias )->( SaveRecord( aRecord, nRecNo ) ), oBtnSave:Disable() )

   oBtnSave:Disable()

   DEFINE BUTTON OF oBar PROMPT "Prev" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( -1 ) ),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Next" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( 1 ) ),;
               If( ( cAlias )->( Eof() ), ( cAlias )->( DbSkip( -1 ) ),),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd ARRAY aRecord AUTOCOLS LINES ;
      HEADERS "FieldName", "Value" COLSIZES 150, 400 FASTEDIT ;
      ON CHANGE ( oMsgBar:cMsgDef := " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + ;
                                 "/" + AllTrim( Str( ( cAlias )->( RecCount() ) ) ),;
                  oMsgBar:Refresh() )                 

   oBrw:nEditTypes = EDIT_GET
   oBrw:aCols[ 1 ]:nEditType = 0 // Don't allow to edit first column
   oBrw:aCols[ 2 ]:bOnChange = { || oBtnSave:Enable() }
   oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar ;
      PROMPT " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + "/" + ;
      AllTrim( Str( ( cAlias )->( RecCount() ) ) ) OF oWnd 2010
   
   ACTIVATE WINDOW oWnd
   
return nil      

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

function LoadRecord()

   local aRecord := {}, n
   
   for n = 1 to FCount()
      AAdd( aRecord, { FieldName( n ), cValToChar( FieldGet( n ) ) } )
   next
   
return aRecord      
   
//----------------------------------------------------------------------------// 

function SaveRecord( aRecord, nRecNo )

   local n, cType

   ( Alias() )->( DbGoTo( nRecNo ) )
   
   for n = 1 to Len( aRecord )
       cType = ( Alias() )->( FieldType( n ) )
       
       do case
          case cType $ "C,M"
               ( Alias() )->( FieldPut( n, aRecord[ n ][ 2 ] ) )
              
          case cType == "N"
               ( Alias() )->( FieldPut( n, Val( aRecord[ n ][ 2 ] ) ) )

          case cType == "D"
               ( Alias() )->( FieldPut( n, CToD( aRecord[ n ][ 2 ] ) ) )

          case cType == "L"
               ( Alias() )->( FieldPut( n, Upper( AllTrim( aRecord[ n ][ 2 ] ) ) == ".T." ) )
       endcase        
   next

   MsgInfo( "Record updated" )
   
return nil      

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

function Struct()

   local oDlg, oBrw, aFields := DbStruct()
   
   DEFINE DIALOG oDlg TITLE Alias() + " fields" SIZE 400, 400

   @ 0, 0 XBROWSE oBrw ARRAY aFields AUTOCOLS LINES ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      COLSIZES 150, 50, 80, 80

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   
   oBrw:CreateFromCode()
      
   oDlg:oClient = oBrw
   
   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( BuildStructBar( oDlg, oBrw ), oDlg:Resize(), oBrw:SetFocus() )
   
return nil   

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

function BuildStructBar( oDlg, oBrw )

   local oBar

   DEFINE BUTTONBAR oBar OF oDlg 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Code" FILENAME "../bitmaps/32x32/source.bmp" ;
      ACTION ( TxtStruct(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oDlg:End() GROUP

return nil

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

function TxtStruct()

   local cCode := "local aFields := { ", n
   
   for n = 1 to FCount()
      if n > 1
         cCode += Space( 27 )
      endif   
      cCode += '{ "' + FieldName( n ) + '", "' + ;
               FieldType( n ) + '", ' + ;
               AllTrim( Str( FieldLen( n ) ) ) + ", " + ;
               AllTrim( Str( FieldDec( n ) ) ) + " },;" + CRLF
   next
   
   cCode = SubStr( cCode, 1, Len( cCode ) - 4 ) + " }"
   
   MemoEdit( cCode, "Code" )

return nil

//----------------------------------------------------------------------------//   
regards, saludos

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

Re: FiveDBU for 32/64 bits

Post by Antonio Linares »

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: FiveDBU for 32/64 bits

Post by Otto »

Hello Antonio,
this is good looking. For me as a DBF based developer a dBase Editor is very important.
In the samples
xbrdbu.prg there is the complete functionality for "new".

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: FiveDBU for 32/64 bits

Post by Antonio Linares »

Image

Image

Code: Select all

#include "FiveWin.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

static oWndMain

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

function Main()

   local oBar, oBmpTiled

   SetDlgGradient( { { 1, RGB( 199, 216, 237 ), RGB( 237, 242, 248 ) } } )

   DEFINE BITMAP oBmpTiled FILENAME "..\bitmaps\backgrnd\iosbg.bmp"

   DEFINE WINDOW oWndMain TITLE "FiveDBU" MDI MENU BuildMenu()

   DEFINE BUTTONBAR oBar OF oWndMain 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "New" FILENAME "../bitmaps/32x32/new.bmp" ;
      ACTION New()

   DEFINE BUTTON OF oBar PROMPT "Open" FILENAME "../bitmaps/32x32/open.bmp" ACTION Open()

   DEFINE BUTTON OF oBar PROMPT "Prev" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION oWndMain:PrevWindow() GROUP WHEN Len( oWndMain:oWndClient:aWnd ) > 1

   DEFINE BUTTON OF oBar PROMPT "Next" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION oWndMain:NextWindow() WHEN Len( oWndMain:oWndClient:aWnd ) > 1

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oWndMain:End() GROUP

   DEFINE MSGBAR PROMPT "FiveDBU 32/64 bits" OF oWndMain 2010 KEYBOARD DATE

   ACTIVATE WINDOW oWndMain MAXIMIZED ;
      VALID MsgYesNo( "Want to end ?" ) ;
      ON PAINT DrawTiled( hDC, oWndMain, oBmpTiled )
   
   oBmpTiled:End()      

return nil

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

function BuildMenu()

   local oMenu
   
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit" ACTION oWndMain:End()
      ENDMENU
      
      // oMenu:AddEdit()
      oMenu:AddMdi()
      oMenu:AddHelp( "FiveDBU", "(c) FiveTech Software 2012" )
   ENDMENU
   
return oMenu      

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

function Open()

   local oWnd, cFileName := cGetFile( "*.dbf", "Please select a DBF" )
   local oBar, oBrw, oMsgBar, oPopup, cAlias
   
   if ! File( cFileName )
      return nil
   endif
   
   if File( cFileNoExt( cFileName ) + ".ntx" )
      USE ( cFileName ) VIA "DBFNTX" NEW
   else   
      USE ( cFileName ) VIA "DBFCDX" NEW
      cAlias = Alias()
   endif        
   
   MENU oPopup POPUP
      for n = 1 to 15
         if ! Empty( OrdName( n ) )
            if ! Empty( OrdName( 1 ) )
               DbSetOrder( OrdName( 1 ) )
            endif   
            MENUITEM OrdName( n ) ;
               ACTION ( ( cAlias )->( DbSetOrder( oMenuItem:cPrompt ) ),;
                        oBrw:Refresh(), oBrw:SetFocus() )
         endif
      next    
   ENDMENU   
   
   DEFINE WINDOW oWnd TITLE cFileName MDICHILD

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Add" FILENAME "../bitmaps/32x32/plus.bmp" ;
      ACTION ( ( oBrw:cAlias )->( DbAppend() ), oBrw:Refresh(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Edit" FILENAME "../bitmaps/32x32/edit.bmp" ACTION ( oBrw:cAlias )->( Edit() )

   DEFINE BUTTON OF oBar PROMPT "Del" FILENAME "../bitmaps/32x32/minus.bmp" ;
      ACTION If( MsgYesNo( "Want to delete this record ?" ),;
                ( ( oBrw:cAlias )->( DbDelete() ), oBrw:Refresh() ),)

   DEFINE BUTTON OF oBar PROMPT "Index" FILENAME "../bitmaps/32x32/index.bmp" ;
      GROUP MENU oPopup

   DEFINE BUTTON OF oBar PROMPT "Top" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION ( oBrw:GoTop(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Bottom" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION ( oBrw:GoBottom(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Struct" FILENAME "../bitmaps/32x32/setup.bmp" ;
      ACTION ( oBrw:cAlias )->( Struct() ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Report" FILENAME "../bitmaps/32x32/print.bmp" ;
      ACTION oBrw:Report()

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd LINES ;
      ON CHANGE oMsgBar:SetText( "Alias: " + Alias() + ;
                                 " RecNo: " + AllTrim( Str( RecNo() ) ) + "/" + ;
                                 AllTrim( Str( RecCount() ) ) )

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   oBrw:bLDblClick = { || ( oBrw:cAlias )->( Edit() ) }                      
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar PROMPT "Alias: " + Alias() + " RecNo: " + ;
      AllTrim( Str( RecNo() ) ) + "/" + ;
      AllTrim( Str( RecCount() ) ) OF oWnd 2010 
   
   ACTIVATE WINDOW oWnd
   
return nil   

//----------------------------------------------------------------------------//
   
function Edit()

   local oWnd, aRecord := ( Alias() )->( LoadRecord() ), oBar, oBrw, oMsgBar
   local cAlias := Alias(), oBtnSave, nRecNo := ( Alias() )->( RecNo() )
   
   DEFINE WINDOW oWnd TITLE "Edit " + Alias() MDICHILD

   oWndMain:oBar:AEvalWhen()

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON oBtnSave OF oBar PROMPT "Save" FILENAME "../bitmaps/32x32/floppy.bmp" ;
      ACTION ( ( cAlias )->( SaveRecord( aRecord, nRecNo ) ), oBtnSave:Disable() )

   oBtnSave:Disable()

   DEFINE BUTTON OF oBar PROMPT "Prev" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( -1 ) ),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Next" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( 1 ) ),;
               If( ( cAlias )->( Eof() ), ( cAlias )->( DbSkip( -1 ) ),),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd ARRAY aRecord AUTOCOLS LINES ;
      HEADERS "FieldName", "Value" COLSIZES 150, 400 FASTEDIT ;
      ON CHANGE ( oMsgBar:cMsgDef := " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + ;
                                 "/" + AllTrim( Str( ( cAlias )->( RecCount() ) ) ),;
                  oMsgBar:Refresh() )                 

   oBrw:nEditTypes = EDIT_GET
   oBrw:aCols[ 1 ]:nEditType = 0 // Don't allow to edit first column
   oBrw:aCols[ 2 ]:bOnChange = { || oBtnSave:Enable() }
   oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar ;
      PROMPT " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + "/" + ;
      AllTrim( Str( ( cAlias )->( RecCount() ) ) ) OF oWnd 2010
   
   ACTIVATE WINDOW oWnd
   
return nil      

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

function LoadRecord()

   local aRecord := {}, n
   
   for n = 1 to FCount()
      AAdd( aRecord, { FieldName( n ), cValToChar( FieldGet( n ) ) } )
   next
   
return aRecord      
   
//----------------------------------------------------------------------------// 

function SaveRecord( aRecord, nRecNo )

   local n, cType

   ( Alias() )->( DbGoTo( nRecNo ) )
   
   for n = 1 to Len( aRecord )
       cType = ( Alias() )->( FieldType( n ) )
       
       do case
          case cType $ "C,M"
               ( Alias() )->( FieldPut( n, aRecord[ n ][ 2 ] ) )
              
          case cType == "N"
               ( Alias() )->( FieldPut( n, Val( aRecord[ n ][ 2 ] ) ) )

          case cType == "D"
               ( Alias() )->( FieldPut( n, CToD( aRecord[ n ][ 2 ] ) ) )

          case cType == "L"
               ( Alias() )->( FieldPut( n, Upper( AllTrim( aRecord[ n ][ 2 ] ) ) == ".T." ) )
       endcase        
   next

   MsgInfo( "Record updated" )
   
return nil      

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

function Struct()

   local oDlg, oBrw, aFields := DbStruct()
   
   DEFINE DIALOG oDlg TITLE Alias() + " fields" SIZE 400, 400

   @ 0, 0 XBROWSE oBrw ARRAY aFields AUTOCOLS LINES ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      COLSIZES 150, 50, 80, 80

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   
   oBrw:CreateFromCode()
      
   oDlg:oClient = oBrw
   
   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( BuildStructBar( oDlg, oBrw ), oDlg:Resize(), oBrw:SetFocus() )
   
return nil   

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

function BuildStructBar( oDlg, oBrw )

   local oBar

   DEFINE BUTTONBAR oBar OF oDlg 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Code" FILENAME "../bitmaps/32x32/source.bmp" ;
      ACTION ( TxtStruct(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oDlg:End() GROUP

return nil

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

function TxtStruct()

   local cCode := "local aFields := { ", n
   
   for n = 1 to FCount()
      if n > 1
         cCode += Space( 27 )
      endif   
      cCode += '{ "' + FieldName( n ) + '", "' + ;
               FieldType( n ) + '", ' + ;
               AllTrim( Str( FieldLen( n ) ) ) + ", " + ;
               AllTrim( Str( FieldDec( n ) ) ) + " },;" + CRLF
   next
   
   cCode = SubStr( cCode, 1, Len( cCode ) - 4 ) + " }"
   
   MemoEdit( cCode, "Code" )

return nil

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

function New()

   local oDlg 
   local cFieldName := Space( 10 ), cType, nLen := 10, nDec := 0
   local aFields := { Array( 4 ) }, cDbfName := Space( 8 )
   
   DEFINE DIALOG oDlg TITLE "DBF builder" SIZE 415, 400

   @ 0.5,  2 SAY "Field Name" OF oDlg SIZE 40, 8
   @ 0.5, 10 SAY "Type" OF oDlg SIZE 40, 8
   @ 0.5, 17 SAY "Len" OF oDlg SIZE 40, 8
   @ 0.5, 22 SAY "Dec" OF oDlg SIZE 20, 8 
   
   @ 1.4, 1 GET cFieldName OF oDlg SIZE 41, 11
   
   @ 1.3, 6.5 COMBOBOX cType ITEMS { "Character", "Number", "Date", "Logical" } ;
      OF oDlg

   @ 1.4, 11.9 GET nLen PICTURE "999" OF oDlg SIZE 25, 11

   @ 1.4, 15.4 GET nDec PICTURE "999" OF oDlg SIZE 25, 11

   @ 0.9, 26 BUTTON "&Add" OF oDlg SIZE 45, 13

   @ 2.2, 2 SAY "Fields" OF oDlg SIZE 40, 8
   
   @ 3.2, 1 XBROWSE oBrw ARRAY aFields AUTOCOLS ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      COLSIZES 90, 55, 40, 40 ;
      SIZE 140, 130 OF oDlg
   
   oBrw:CreateFromCode()

   @ 2.4, 26 BUTTON "&Edit" OF oDlg SIZE 45, 13

   @ 3.4, 26 BUTTON "&Delete" OF oDlg SIZE 45, 13

   @ 4.4, 26 BUTTON "Move &Up" OF oDlg SIZE 45, 13

   @ 5.4, 26 BUTTON "Move D&own" OF oDlg SIZE 45, 13

   @ 12.1, 2 SAY "DBF Name:" OF oDlg SIZE 40, 8

   @ 14, 6 GET cDbfName OF oDlg SIZE 100, 11

   @ 10, 26 BUTTON "&Create" OF oDlg SIZE 45, 13

   ACTIVATE DIALOG oDlg CENTERED

return nil

//----------------------------------------------------------------------------//   
regards, saludos

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

Re: FiveDBU for 32/64 bits

Post by Antonio Linares »

Code: Select all

#include "FiveWin.ch"
#include "xbrowse.ch"

REQUEST DBFCDX

static oWndMain

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

function Main()

   local oBar, oBmpTiled

   SetDlgGradient( { { 1, RGB( 199, 216, 237 ), RGB( 237, 242, 248 ) } } )

   DEFINE BITMAP oBmpTiled FILENAME "..\bitmaps\backgrnd\iosbg.bmp"

   DEFINE WINDOW oWndMain TITLE "FiveDBU" MDI MENU BuildMenu()

   DEFINE BUTTONBAR oBar OF oWndMain 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "New" FILENAME "../bitmaps/32x32/new.bmp" ;
      ACTION New()

   DEFINE BUTTON OF oBar PROMPT "Open" FILENAME "../bitmaps/32x32/open.bmp" ACTION Open()

   DEFINE BUTTON OF oBar PROMPT "Prev" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION oWndMain:PrevWindow() GROUP WHEN Len( oWndMain:oWndClient:aWnd ) > 1

   DEFINE BUTTON OF oBar PROMPT "Next" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION oWndMain:NextWindow() WHEN Len( oWndMain:oWndClient:aWnd ) > 1

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oWndMain:End() GROUP

   DEFINE MSGBAR PROMPT "FiveDBU 32/64 bits" OF oWndMain 2010 KEYBOARD DATE

   ACTIVATE WINDOW oWndMain MAXIMIZED ;
      VALID MsgYesNo( "Want to end ?" ) ;
      ON PAINT DrawTiled( hDC, oWndMain, oBmpTiled )
   
   oBmpTiled:End()      

return nil

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

function BuildMenu()

   local oMenu
   
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit" ACTION oWndMain:End()
      ENDMENU
      
      // oMenu:AddEdit()
      oMenu:AddMdi()
      oMenu:AddHelp( "FiveDBU", "(c) FiveTech Software 2012" )
   ENDMENU
   
return oMenu      

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

function Open( cFileName )

   local oWnd, oBar, oBrw, oMsgBar, oPopup, cAlias, n
   
   DEFAULT cFileName := cGetFile( "*.dbf", "Please select a DBF" )
   
   if ! "." $ cFileName
      cFileName += ".dbf"
   endif   
   
   if ! File( cFileName )
      if ! Empty( cFileName )
         MsgStop( "File not found: " + cFileName )
      endif   
      return nil
   endif
   
   if File( cFileNoExt( cFileName ) + ".ntx" )
      USE ( cFileName ) VIA "DBFNTX" NEW
   else   
      USE ( cFileName ) VIA "DBFCDX" NEW
      cAlias = Alias()
   endif        
   
   MENU oPopup POPUP
      for n = 1 to 15
         if ! Empty( OrdName( n ) )
            if ! Empty( OrdName( 1 ) )
               DbSetOrder( OrdName( 1 ) )
            endif   
            MENUITEM OrdName( n ) ;
               ACTION ( ( cAlias )->( DbSetOrder( oMenuItem:cPrompt ) ),;
                        oBrw:Refresh(), oBrw:SetFocus() )
         endif
      next    
   ENDMENU   
   
   DEFINE WINDOW oWnd TITLE "Browse " + cFileName MDICHILD

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Add" FILENAME "../bitmaps/32x32/plus.bmp" ;
      ACTION ( ( oBrw:cAlias )->( DbAppend() ), oBrw:Refresh(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Edit" FILENAME "../bitmaps/32x32/edit.bmp" ;
      ACTION ( oBrw:cAlias )->( Edit() )

   DEFINE BUTTON OF oBar PROMPT "Del" FILENAME "../bitmaps/32x32/minus.bmp" ;
      ACTION If( MsgYesNo( "Want to delete this record ?" ),;
                ( ( oBrw:cAlias )->( DbDelete() ), oBrw:Refresh() ),)

   DEFINE BUTTON OF oBar PROMPT "Index" FILENAME "../bitmaps/32x32/index.bmp" ;
      GROUP MENU oPopup

   DEFINE BUTTON OF oBar PROMPT "Top" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION ( oBrw:GoTop(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Bottom" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION ( oBrw:GoBottom(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Struct" FILENAME "../bitmaps/32x32/setup.bmp" ;
      ACTION ( oBrw:cAlias )->( Struct() ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Report" FILENAME "../bitmaps/32x32/print.bmp" ;
      ACTION oBrw:Report()

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd LINES ;
      ON CHANGE oMsgBar:SetText( "Alias: " + Alias() + ;
                                 " RecNo: " + AllTrim( Str( RecNo() ) ) + "/" + ;
                                 AllTrim( Str( RecCount() ) ) )

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   oBrw:bLDblClick = { || ( oBrw:cAlias )->( Edit() ) }                      
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar PROMPT "Alias: " + Alias() + " RecNo: " + ;
      AllTrim( Str( RecNo() ) ) + "/" + ;
      AllTrim( Str( RecCount() ) ) OF oWnd 2010 
   
   ACTIVATE WINDOW oWnd
   
return nil   

//----------------------------------------------------------------------------//
   
function Edit()

   local oWnd, aRecord := ( Alias() )->( LoadRecord() ), oBar, oBrw, oMsgBar
   local cAlias := Alias(), oBtnSave, nRecNo := ( Alias() )->( RecNo() )
   
   DEFINE WINDOW oWnd TITLE "Edit " + Alias() MDICHILD

   oWndMain:oBar:AEvalWhen()

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON oBtnSave OF oBar PROMPT "Save" FILENAME "../bitmaps/32x32/floppy.bmp" ;
      ACTION ( ( cAlias )->( SaveRecord( aRecord, nRecNo ) ), oBtnSave:Disable() )

   oBtnSave:Disable()

   DEFINE BUTTON OF oBar PROMPT "Prev" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( -1 ) ),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Next" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( 1 ) ),;
               If( ( cAlias )->( Eof() ), ( cAlias )->( DbSkip( -1 ) ),),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd ARRAY aRecord AUTOCOLS LINES ;
      HEADERS "FieldName", "Value" COLSIZES 150, 400 FASTEDIT ;
      ON CHANGE ( oMsgBar:cMsgDef := " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + ;
                                 "/" + AllTrim( Str( ( cAlias )->( RecCount() ) ) ),;
                  oMsgBar:Refresh() )                 

   oBrw:nEditTypes = EDIT_GET
   oBrw:aCols[ 1 ]:nEditType = 0 // Don't allow to edit first column
   oBrw:aCols[ 2 ]:bOnChange = { || oBtnSave:Enable() }
   oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar ;
      PROMPT " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + "/" + ;
      AllTrim( Str( ( cAlias )->( RecCount() ) ) ) OF oWnd 2010
   
   ACTIVATE WINDOW oWnd
   
return nil      

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

function LoadRecord()

   local aRecord := {}, n
   
   for n = 1 to FCount()
      AAdd( aRecord, { FieldName( n ), cValToChar( FieldGet( n ) ) } )
   next
   
return aRecord      
   
//----------------------------------------------------------------------------// 

function SaveRecord( aRecord, nRecNo )

   local n, cType

   ( Alias() )->( DbGoTo( nRecNo ) )
   
   for n = 1 to Len( aRecord )
       cType = ( Alias() )->( FieldType( n ) )
       
       do case
          case cType $ "C,M"
               ( Alias() )->( FieldPut( n, aRecord[ n ][ 2 ] ) )
              
          case cType == "N"
               ( Alias() )->( FieldPut( n, Val( aRecord[ n ][ 2 ] ) ) )

          case cType == "D"
               ( Alias() )->( FieldPut( n, CToD( aRecord[ n ][ 2 ] ) ) )

          case cType == "L"
               ( Alias() )->( FieldPut( n, Upper( AllTrim( aRecord[ n ][ 2 ] ) ) == ".T." ) )
       endcase        
   next

   MsgInfo( "Record updated" )
   
return nil      

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

function Struct()

   local oDlg, oBrw, aFields := DbStruct()
   
   DEFINE DIALOG oDlg TITLE Alias() + " fields" SIZE 400, 400

   @ 0, 0 XBROWSE oBrw ARRAY aFields AUTOCOLS LINES ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      COLSIZES 150, 50, 80, 80

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   
   oBrw:CreateFromCode()
      
   oDlg:oClient = oBrw
   
   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( BuildStructBar( oDlg, oBrw ), oDlg:Resize(), oBrw:SetFocus() )
   
return nil   

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

function BuildStructBar( oDlg, oBrw )

   local oBar

   DEFINE BUTTONBAR oBar OF oDlg 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Code" FILENAME "../bitmaps/32x32/source.bmp" ;
      ACTION ( TxtStruct(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oDlg:End() GROUP

return nil

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

function TxtStruct()

   local cCode := "local aFields := { ", n
   
   for n = 1 to FCount()
      if n > 1
         cCode += Space( 27 )
      endif   
      cCode += '{ "' + FieldName( n ) + '", "' + ;
               FieldType( n ) + '", ' + ;
               AllTrim( Str( FieldLen( n ) ) ) + ", " + ;
               AllTrim( Str( FieldDec( n ) ) ) + " },;" + CRLF
   next
   
   cCode = SubStr( cCode, 1, Len( cCode ) - 4 ) + " }"
   
   MemoEdit( cCode, "Code" )

return nil

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

function New()

   local oDlg, oGet, oBrw 
   local cFieldName := Space( 10 ), cType, nLen := 10, nDec := 0
   local aFields := { Array( 4 ) }, cDbfName := Space( 8 )
   
   DEFINE DIALOG oDlg TITLE "DBF builder" SIZE 415, 400

   @ 0.5,  2 SAY "Field Name" OF oDlg SIZE 40, 8
   @ 0.5, 10 SAY "Type" OF oDlg SIZE 40, 8
   @ 0.5, 17 SAY "Len" OF oDlg SIZE 40, 8
   @ 0.5, 22 SAY "Dec" OF oDlg SIZE 20, 8 
   
   @ 1.4, 1 GET oGet VAR cFieldName PICTURE "!!!!!!!!!!" OF oDlg SIZE 41, 11
   
   @ 1.3, 6.5 COMBOBOX cType ITEMS { "Character", "Number", "Date", "Logical" } ;
      OF oDlg

   @ 1.4, 11.9 GET nLen PICTURE "999" OF oDlg SIZE 25, 11

   @ 1.4, 15.4 GET nDec PICTURE "999" OF oDlg SIZE 25, 11

   @ 0.9, 26 BUTTON "&Add" OF oDlg SIZE 45, 13 ;
      ACTION AddField( @aFields, @cFieldName, @cType, @nLen, @nDec, oGet, oBrw )

   @ 2.2, 2 SAY "Fields" OF oDlg SIZE 40, 8
   
   @ 3.2, 1 XBROWSE oBrw ARRAY aFields AUTOCOLS ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      COLSIZES 90, 55, 40, 40 ;
      SIZE 140, 130 OF oDlg

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }    
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   oBrw:CreateFromCode()

   @ 2.4, 26 BUTTON "&Edit" OF oDlg SIZE 45, 13

   @ 3.4, 26 BUTTON "&Delete" OF oDlg SIZE 45, 13

   @ 4.4, 26 BUTTON "Move &Up" OF oDlg SIZE 45, 13

   @ 5.4, 26 BUTTON "Move D&own" OF oDlg SIZE 45, 13

   @ 12.1, 2 SAY "DBF Name:" OF oDlg SIZE 30, 8

   @ 14, 6 GET cDbfName PICTURE "!!!!!!!!!!!!" OF oDlg SIZE 100, 11

   @ 10, 26 BUTTON "&Create" OF oDlg SIZE 45, 13 ;
      ACTION ( If( ! Empty( cDbfName ) .and. Len( aFields ) > 0,;
          DbCreate( cDbfName, aFields ),), oDlg:End(),;
          Open( hb_CurDrive() + ":\" + CurDir() + "\" + cDbfName ) )

   ACTIVATE DIALOG oDlg CENTERED

return nil

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

function AddField( aFields, cFieldName, cType, nLen, nDec, oGet, oBrw )

   if Empty( cFieldName )
      oGet:SetPos( 0 )
      return nil
   endif   

   if Len( aFields ) == 1 .and. Empty( aFields[ 1 ][ 1 ] )
      aFields = { { cFieldName, Upper( Left( cType, 1 ) ), nLen, nDec } }
   else   
      AAdd( aFields, { cFieldName, Upper( Left( cType, 1 ) ), nLen, nDec } )
   endif
      
   oBrw:SetArray( aFields )
   oGet:VarPut( cFieldName := Space( 10 ) )
   oGet:SetPos( 0 )
   oGet:SetFocus()
   oBrw:GoBottom()
               
return nil

//----------------------------------------------------------------------------//                  
regards, saludos

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

Re: FiveDBU for 32/64 bits

Post by Antonio Linares »

Swaping fields order in DBF builder:

Code: Select all

   @ 4.4, 26 BUTTON "Move &Up" OF oDlg SIZE 45, 13 ;
      ACTION If( oBrw:nArrayAt > 1,;
                 ( aTemp := aFields[ oBrw:nArrayAt ],;
                   aFields[ oBrw:nArrayAt ] := aFields[ oBrw:nArrayAt - 1 ],;
                   aFields[ oBrw:nArrayAt - 1 ] := aTemp,;
                   oBrw:GoUp() ),) 

   @ 5.4, 26 BUTTON "Move D&own" OF oDlg SIZE 45, 13 ;
      ACTION If( oBrw:nArrayAt < Len( aFields ),;
                 ( aTemp := aFields[ oBrw:nArrayAt ],;
                   aFields[ oBrw:nArrayAt ] := aFields[ oBrw:nArrayAt + 1 ],;
                   aFields[ oBrw:nArrayAt + 1 ] := aTemp,;
                   oBrw:GoDown() ),) 
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
TimStone
Posts: 2536
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA
Contact:

Re: FiveDBU for 32/64 bits

Post by TimStone »

Antonio,

I was going to play with your code, so I took the last one you posted ( full version ) and added it to an application.

It simply didn't run ... Windows got an error.

Once you have something ready I'll be happy to play with it and give you the feedback.

I built a File Editor into my application several months ago. It is a class and is designed to do tasks specific to the files in my application. I think your dbu would be best implemented as a class !

Tim
Tim Stone
http://www.MasterLinkSoftware.com
timstone@masterlinksoftware.com
Using: FWH 19.06 with Harbour 3.2.0 / Microsoft Visual Studio Community 2019
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: FiveDBU for 32/64 bits

Post by Antonio Linares »

Tim,

Here it is working fine using Harbour and xHarbour (free).

Yes, we could easily have it as an object (of a Class) to include it in any app :-)
regards, saludos

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

Re: FiveDBU for 32/64 bits

Post by Antonio Linares »

Image

Code: Select all

#include "FiveWin.ch"
#include "xbrowse.ch"

#ifdef __XHARBOUR__
   #define hb_CurDrive() CurDrive()
#endif   

REQUEST DBFCDX

static oWndMain

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

function Main()

   local oBar, oBmpTiled

   SetDlgGradient( { { 1, RGB( 199, 216, 237 ), RGB( 237, 242, 248 ) } } )

   DEFINE BITMAP oBmpTiled FILENAME "..\bitmaps\backgrnd\iosbg.bmp"

   DEFINE WINDOW oWndMain TITLE "FiveDBU" MDI MENU BuildMenu()

   DEFINE BUTTONBAR oBar OF oWndMain 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "New" FILENAME "../bitmaps/32x32/new.bmp" ;
      ACTION New()

   DEFINE BUTTON OF oBar PROMPT "Open" FILENAME "../bitmaps/32x32/open.bmp" ACTION Open()

   DEFINE BUTTON OF oBar PROMPT "Prev" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION oWndMain:PrevWindow() GROUP WHEN Len( oWndMain:oWndClient:aWnd ) > 1

   DEFINE BUTTON OF oBar PROMPT "Next" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION oWndMain:NextWindow() WHEN Len( oWndMain:oWndClient:aWnd ) > 1

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oWndMain:End() GROUP

   DEFINE MSGBAR PROMPT "FiveDBU 32/64 bits" OF oWndMain 2010 KEYBOARD DATE

   ACTIVATE WINDOW oWndMain MAXIMIZED ;
      VALID MsgYesNo( "Want to end ?" ) ;
      ON PAINT DrawTiled( hDC, oWndMain, oBmpTiled )
   
   oBmpTiled:End()      

return nil

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

function BuildMenu()

   local oMenu
   
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit" ACTION oWndMain:End()
      ENDMENU
      
      // oMenu:AddEdit()
      oMenu:AddMdi()
      oMenu:AddHelp( "FiveDBU", "(c) FiveTech Software 2012" )
   ENDMENU
   
return oMenu      

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

function Open( cFileName )

   local oWnd, oBar, oBrw, oMsgBar, oPopup, cAlias, n
   
   DEFAULT cFileName := cGetFile( "*.dbf", "Please select a DBF" )
   
   if ! "." $ cFileName
      cFileName += ".dbf"
   endif   
   
   if ! File( cFileName )
      if ! Empty( cFileName )
         MsgStop( "File not found: " + cFileName )
      endif   
      return nil
   endif
   
   if File( cFileNoExt( cFileName ) + ".ntx" )
      USE ( cFileName ) VIA "DBFNTX" NEW
   else   
      USE ( cFileName ) VIA "DBFCDX" NEW
      cAlias = Alias()
   endif        
   
   MENU oPopup POPUP
      for n = 1 to 15
         if ! Empty( OrdName( n ) )
            if ! Empty( OrdName( 1 ) )
               DbSetOrder( OrdName( 1 ) )
            endif   
            MENUITEM OrdName( n ) ;
               ACTION ( ( cAlias )->( DbSetOrder( oMenuItem:cPrompt ) ),;
                        oBrw:Refresh(), oBrw:SetFocus() )
         endif
      next    
   ENDMENU   
   
   DEFINE WINDOW oWnd TITLE "Browse " + cFileName MDICHILD

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Add" FILENAME "../bitmaps/32x32/plus.bmp" ;
      ACTION ( ( oBrw:cAlias )->( DbAppend() ), oBrw:Refresh(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Edit" FILENAME "../bitmaps/32x32/edit.bmp" ;
      ACTION ( oBrw:cAlias )->( Edit() )

   DEFINE BUTTON OF oBar PROMPT "Del" FILENAME "../bitmaps/32x32/minus.bmp" ;
      ACTION If( MsgYesNo( "Want to delete this record ?" ),;
                ( ( oBrw:cAlias )->( DbDelete() ), oBrw:Refresh() ),)

   DEFINE BUTTON OF oBar PROMPT "Index" FILENAME "../bitmaps/32x32/index.bmp" ;
      GROUP MENU oPopup ACTION Indexes()

   DEFINE BUTTON OF oBar PROMPT "Top" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION ( oBrw:GoTop(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Bottom" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION ( oBrw:GoBottom(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Struct" FILENAME "../bitmaps/32x32/setup.bmp" ;
      ACTION ( oBrw:cAlias )->( Struct() ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Report" FILENAME "../bitmaps/32x32/print.bmp" ;
      ACTION oBrw:Report()

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd LINES ;
      ON CHANGE oMsgBar:SetText( "Alias: " + Alias() + ;
                                 " RecNo: " + AllTrim( Str( RecNo() ) ) + "/" + ;
                                 AllTrim( Str( RecCount() ) ) )

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   oBrw:bLDblClick = { || ( oBrw:cAlias )->( Edit() ) }                      
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar PROMPT "Alias: " + Alias() + " RecNo: " + ;
      AllTrim( Str( RecNo() ) ) + "/" + ;
      AllTrim( Str( RecCount() ) ) OF oWnd 2010 
   
   ACTIVATE WINDOW oWnd
   
return nil   

//----------------------------------------------------------------------------//
   
function Edit()

   local oWnd, aRecord := ( Alias() )->( LoadRecord() ), oBar, oBrw, oMsgBar
   local cAlias := Alias(), oBtnSave, nRecNo := ( Alias() )->( RecNo() )
   
   DEFINE WINDOW oWnd TITLE "Edit " + Alias() MDICHILD

   oWndMain:oBar:AEvalWhen()

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON oBtnSave OF oBar PROMPT "Save" FILENAME "../bitmaps/32x32/floppy.bmp" ;
      ACTION ( ( cAlias )->( SaveRecord( aRecord, nRecNo ) ), oBtnSave:Disable() )

   oBtnSave:Disable()

   DEFINE BUTTON OF oBar PROMPT "Prev" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( -1 ) ),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Next" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( 1 ) ),;
               If( ( cAlias )->( Eof() ), ( cAlias )->( DbSkip( -1 ) ),),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd ARRAY aRecord AUTOCOLS LINES ;
      HEADERS "FieldName", "Value" COLSIZES 150, 400 FASTEDIT ;
      ON CHANGE ( oMsgBar:cMsgDef := " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + ;
                                 "/" + AllTrim( Str( ( cAlias )->( RecCount() ) ) ),;
                  oMsgBar:Refresh() )                 

   oBrw:nEditTypes = EDIT_GET
   oBrw:aCols[ 1 ]:nEditType = 0 // Don't allow to edit first column
   oBrw:aCols[ 2 ]:bOnChange = { || oBtnSave:Enable() }
   oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar ;
      PROMPT " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + "/" + ;
      AllTrim( Str( ( cAlias )->( RecCount() ) ) ) OF oWnd 2010
   
   ACTIVATE WINDOW oWnd
   
return nil      

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

function IndexBuilder()

   local oDlg, cKey := Space( 80 )
   
   DEFINE DIALOG oDlg TITLE "Index builder" SIZE 600, 500 

   oDlg:lDesign = .T.

   @ 0.5,  2 SAY "Index on" OF oDlg SIZE 40, 8

   @ 1.4, 1 GET cKey OF oDlg SIZE 140, 11 ACTION ExpBuilder()
   
   @ 0.5, 15 SAY "Tag" OF oDlg SIZE 40, 8
   
   ACTIVATE DIALOG oDlg CENTERED

return nil

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

function Indexes()

   local oWnd, oBar, oBrw, oMsgBar
   local cAlias := Alias(), aIndexes := {}, n 
   
   for n = 1 to 15
      if ! Empty( OrdName( n ) )
         AAdd( aIndexes, { n,;
                           OrdName( n ),;
                           OrdKey( n ),;
                           OrdFor( n ),;
                           OrdBagName( n ),;
                           OrdBagExt( n ) } )
      endif   
   next    
   
   DEFINE WINDOW oWnd TITLE "Indexes of " + Alias() MDICHILD

   oWndMain:oBar:AEvalWhen()

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70

   DEFINE BUTTON OF oBar PROMPT "Add" FILENAME "../bitmaps/32x32/plus.bmp" ;
      ACTION ( MsgInfo( "Add Tag" ), oBrw:Refresh(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Edit" FILENAME "../bitmaps/32x32/edit.bmp" ;
      ACTION ( MsgInfo( "Edit" ) )

   DEFINE BUTTON OF oBar PROMPT "Del" FILENAME "../bitmaps/32x32/minus.bmp" ;
      ACTION If( MsgYesNo( "Want to delete this tag ?" ),;
                ( ( cAlias )->( OrdBagClear( oBrw:nArrayAt ) ), oBrw:Refresh() ),)
   
   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd ARRAY aIndexes AUTOCOLS LINES ;
      HEADERS "Order", "TagName", "Expression", "For", "BagName", "BagExt" ;
      COLSIZES 50, 150, 400, 300, 150, 150

   oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar 2010
   
   ACTIVATE WINDOW oWnd 

return nil

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

function ExpBuilder()

   local oDlg
   
   DEFINE DIALOG oDlg TITLE "Expression builder"
   
   ACTIVATE DIALOG oDlg CENTERED

return nil

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

function LoadRecord()

   local aRecord := {}, n
   
   for n = 1 to FCount()
      AAdd( aRecord, { FieldName( n ), cValToChar( FieldGet( n ) ) } )
   next
   
return aRecord      
   
//----------------------------------------------------------------------------// 

function SaveRecord( aRecord, nRecNo )

   local n, cType

   ( Alias() )->( DbGoTo( nRecNo ) )
   
   for n = 1 to Len( aRecord )
       cType = ( Alias() )->( FieldType( n ) )
       
       do case
          case cType $ "C,M"
               ( Alias() )->( FieldPut( n, aRecord[ n ][ 2 ] ) )
              
          case cType == "N"
               ( Alias() )->( FieldPut( n, Val( aRecord[ n ][ 2 ] ) ) )

          case cType == "D"
               ( Alias() )->( FieldPut( n, CToD( aRecord[ n ][ 2 ] ) ) )

          case cType == "L"
               ( Alias() )->( FieldPut( n, Upper( AllTrim( aRecord[ n ][ 2 ] ) ) == ".T." ) )
       endcase        
   next

   MsgInfo( "Record updated" )
   
return nil      

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

function Struct()

   local oDlg, oBrw, aFields := DbStruct()
   
   DEFINE DIALOG oDlg TITLE Alias() + " fields" SIZE 400, 400

   @ 0, 0 XBROWSE oBrw ARRAY aFields AUTOCOLS LINES ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      COLSIZES 150, 50, 80, 80

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   
   oBrw:CreateFromCode()
      
   oDlg:oClient = oBrw
   
   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( BuildStructBar( oDlg, oBrw ), oDlg:Resize(), oBrw:SetFocus() )
   
return nil   

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

function BuildStructBar( oDlg, oBrw )

   local oBar

   DEFINE BUTTONBAR oBar OF oDlg 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Code" FILENAME "../bitmaps/32x32/source.bmp" ;
      ACTION ( TxtStruct(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oDlg:End() GROUP

return nil

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

function TxtStruct()

   local cCode := "local aFields := { ", n
   
   for n = 1 to FCount()
      if n > 1
         cCode += Space( 27 )
      endif   
      cCode += '{ "' + FieldName( n ) + '", "' + ;
               FieldType( n ) + '", ' + ;
               AllTrim( Str( FieldLen( n ) ) ) + ", " + ;
               AllTrim( Str( FieldDec( n ) ) ) + " },;" + CRLF
   next
   
   cCode = SubStr( cCode, 1, Len( cCode ) - 4 ) + " }"
   
   MemoEdit( cCode, "Code" )

return nil

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

function New()

   local oDlg, oGet, oBrw 
   local cFieldName := Space( 10 ), cType, nLen := 10, nDec := 0
   local aFields := { Array( 4 ) }, cDbfName := Space( 8 ), aTemp
   
   DEFINE DIALOG oDlg TITLE "DBF builder" SIZE 415, 400

   @ 0.5,  2 SAY "Field Name" OF oDlg SIZE 40, 8
   @ 0.5, 10 SAY "Type" OF oDlg SIZE 40, 8
   @ 0.5, 17 SAY "Len" OF oDlg SIZE 40, 8
   @ 0.5, 22 SAY "Dec" OF oDlg SIZE 20, 8 
   
   @ 1.4, 1 GET oGet VAR cFieldName PICTURE "!!!!!!!!!!" OF oDlg SIZE 41, 11
   
   @ 1.3, 6.5 COMBOBOX cType ITEMS { "Character", "Number", "Date", "Logical" } ;
      OF oDlg

   @ 1.4, 11.9 GET nLen PICTURE "999" OF oDlg SIZE 25, 11

   @ 1.4, 15.4 GET nDec PICTURE "999" OF oDlg SIZE 25, 11

   @ 0.9, 26 BUTTON "&Add" OF oDlg SIZE 45, 13 ;
      ACTION AddField( @aFields, @cFieldName, @cType, @nLen, @nDec, oGet, oBrw )

   @ 2.2, 2 SAY "Fields" OF oDlg SIZE 40, 8
   
   @ 3.2, 1 XBROWSE oBrw ARRAY aFields AUTOCOLS ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      COLSIZES 90, 55, 40, 40 ;
      SIZE 140, 130 OF oDlg

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }    
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   oBrw:CreateFromCode()

   @ 2.4, 26 BUTTON "&Edit" OF oDlg SIZE 45, 13

   @ 3.4, 26 BUTTON "&Delete" OF oDlg SIZE 45, 13

   @ 4.4, 26 BUTTON "Move &Up" OF oDlg SIZE 45, 13 ;
      ACTION If( oBrw:nArrayAt > 1,;
                 ( aTemp := aFields[ oBrw:nArrayAt ],;
                   aFields[ oBrw:nArrayAt ] := aFields[ oBrw:nArrayAt - 1 ],;
                   aFields[ oBrw:nArrayAt - 1 ] := aTemp,;
                   oBrw:GoUp() ),) 

   @ 5.4, 26 BUTTON "Move D&own" OF oDlg SIZE 45, 13 ;
      ACTION If( oBrw:nArrayAt < Len( aFields ),;
                 ( aTemp := aFields[ oBrw:nArrayAt ],;
                   aFields[ oBrw:nArrayAt ] := aFields[ oBrw:nArrayAt + 1 ],;
                   aFields[ oBrw:nArrayAt + 1 ] := aTemp,;
                   oBrw:GoDown() ),) 

   @ 12.1, 2 SAY "DBF Name:" OF oDlg SIZE 30, 8

   @ 14, 6 GET cDbfName PICTURE "!!!!!!!!!!!!" OF oDlg SIZE 100, 11

   @ 10, 26 BUTTON "&Create" OF oDlg SIZE 45, 13 ;
      ACTION ( If( ! Empty( cDbfName ) .and. Len( aFields ) > 0,;
          DbCreate( cDbfName, aFields ),), oDlg:End(),;
          Open( hb_CurDrive() + ":\" + CurDir() + "\" + cDbfName ) )

   ACTIVATE DIALOG oDlg CENTERED

return nil

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

function AddField( aFields, cFieldName, cType, nLen, nDec, oGet, oBrw )

   if Empty( cFieldName )
      oGet:SetPos( 0 )
      return nil
   endif   

   if Len( aFields ) == 1 .and. Empty( aFields[ 1 ][ 1 ] )
      aFields = { { cFieldName, Upper( Left( cType, 1 ) ), nLen, nDec } }
   else   
      AAdd( aFields, { cFieldName, Upper( Left( cType, 1 ) ), nLen, nDec } )
   endif
      
   oBrw:SetArray( aFields )
   oGet:VarPut( cFieldName := Space( 10 ) )
   oGet:SetPos( 0 )
   oGet:SetFocus()
   oBrw:GoBottom()
               
return nil

//----------------------------------------------------------------------------//                  
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: FiveDBU for 32/64 bits

Post by driessen »

Antonio,

I tested your fivedbu and I really must congratulate you. Great job.

A few remarks, if I may :

1. The number of indexes in a CDX-files : it looks to me that there is a limit of 15 indexes. Is that correct ? Can the number of indexes be extended ?
2. How can I order my file with "Natural order" ?
3. An error occurs when I open a file, then close the file and then I try to open the file again.
4. Deleting a record doesn't seem to work.

Thanks for a great utility.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: FiveDBU for 32/64 bits

Post by Antonio Linares »

Implemented Search on current tag:

Image

fivedbu.prg

Code: Select all

#include "FiveWin.ch"
#include "xbrowse.ch"

#ifdef __XHARBOUR__
   #define hb_CurDrive() CurDrive()
#endif   

REQUEST DBFCDX

static oWndMain, aSearches := {}

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

function Main()

   local oBar, oBmpTiled

   SetDlgGradient( { { 1, RGB( 199, 216, 237 ), RGB( 237, 242, 248 ) } } )

   DEFINE BITMAP oBmpTiled FILENAME "..\bitmaps\backgrnd\iosbg.bmp"

   DEFINE WINDOW oWndMain TITLE "FiveDBU" MDI MENU BuildMenu()

   DEFINE BUTTONBAR oBar OF oWndMain 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "New" FILENAME "../bitmaps/32x32/new.bmp" ;
      ACTION New()

   DEFINE BUTTON OF oBar PROMPT "Open" FILENAME "../bitmaps/32x32/open.bmp" ACTION Open()

   DEFINE BUTTON OF oBar PROMPT "Prev" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION oWndMain:PrevWindow() GROUP WHEN Len( oWndMain:oWndClient:aWnd ) > 1

   DEFINE BUTTON OF oBar PROMPT "Next" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION oWndMain:NextWindow() WHEN Len( oWndMain:oWndClient:aWnd ) > 1

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oWndMain:End() GROUP

   DEFINE MSGBAR PROMPT "FiveDBU 32/64 bits" OF oWndMain 2010 KEYBOARD DATE

   ACTIVATE WINDOW oWndMain MAXIMIZED ;
      VALID MsgYesNo( "Want to end ?" ) ;
      ON PAINT DrawTiled( hDC, oWndMain, oBmpTiled )
   
   oBmpTiled:End()      

return nil

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

function BuildMenu()

   local oMenu
   
   MENU oMenu
      MENUITEM "Files"
      MENU
         MENUITEM "New..."
         MENUITEM "Open..." ACTION Open()
         SEPARATOR
         MENUITEM "Exit" ACTION oWndMain:End()
      ENDMENU
      
      // oMenu:AddEdit()
      oMenu:AddMdi()
      oMenu:AddHelp( "FiveDBU", "(c) FiveTech Software 2012" )
   ENDMENU
   
return oMenu      

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

function Open( cFileName )

   local oWnd, oBar, oBrw, oMsgBar, oPopup, cAlias, n
   
   DEFAULT cFileName := cGetFile( "*.dbf", "Please select a DBF" )
   
   if ! "." $ cFileName
      cFileName += ".dbf"
   endif   
   
   if ! File( cFileName )
      if ! Empty( cFileName )
         MsgStop( "File not found: " + cFileName )
      endif   
      return nil
   endif
   
   if File( cFileNoExt( cFileName ) + ".ntx" )
      USE ( cFileName ) VIA "DBFNTX" NEW
   else   
      USE ( cFileName ) VIA "DBFCDX" NEW
      cAlias = Alias()
   endif        
   
   MENU oPopup POPUP
      MENUITEM "Natural order" ;
         ACTION ( ( cAlias )->( DbSetOrder( 0 ) ), oBrw:Refresh(), oBrw:SetFocus() )
      SEPARATOR   
      for n = 1 to 15
         if ! Empty( OrdName( n ) )
            if ! Empty( OrdName( 1 ) )
               DbSetOrder( OrdName( 1 ) )
            endif   
            MENUITEM OrdName( n ) ;
               ACTION ( ( cAlias )->( DbSetOrder( oMenuItem:cPrompt ) ),;
                        oBrw:Refresh(), oBrw:SetFocus() )
         endif
      next    
   ENDMENU   
   
   DEFINE WINDOW oWnd TITLE "Browse " + cFileName MDICHILD

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Add" FILENAME "../bitmaps/32x32/plus.bmp" ;
      ACTION ( ( oBrw:cAlias )->( DbAppend() ), oBrw:Refresh(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Edit" FILENAME "../bitmaps/32x32/edit.bmp" ;
      ACTION ( oBrw:cAlias )->( Edit() )

   DEFINE BUTTON OF oBar PROMPT "Del" FILENAME "../bitmaps/32x32/minus.bmp" ;
      ACTION If( MsgYesNo( "Want to delete this record ?" ),;
                ( ( oBrw:cAlias )->( DbDelete() ), oBrw:Refresh() ),)

   DEFINE BUTTON OF oBar PROMPT "Search" FILENAME "../bitmaps/32x32/search.bmp" ;
      GROUP ACTION ( cAlias )->( Search( oBrw ) )

   DEFINE BUTTON OF oBar PROMPT "Index" FILENAME "../bitmaps/32x32/index.bmp" ;
      MENU oPopup ACTION ( cAlias )->( Indexes() )

   DEFINE BUTTON OF oBar PROMPT "Top" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION ( oBrw:GoTop(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Bottom" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION ( oBrw:GoBottom(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Struct" FILENAME "../bitmaps/32x32/setup.bmp" ;
      ACTION ( oBrw:cAlias )->( Struct() ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Report" FILENAME "../bitmaps/32x32/print.bmp" ;
      ACTION oBrw:Report()

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd LINES ;
      ON CHANGE oMsgBar:SetText( "Alias: " + Alias() + ;
                                 " RecNo: " + AllTrim( Str( RecNo() ) ) + "/" + ;
                                 AllTrim( Str( RecCount() ) ) )

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   oBrw:bLDblClick = { || ( oBrw:cAlias )->( Edit() ) }                      
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar PROMPT "Alias: " + Alias() + " RecNo: " + ;
      AllTrim( Str( RecNo() ) ) + "/" + ;
      AllTrim( Str( RecCount() ) ) OF oWnd 2010 
   
   ACTIVATE WINDOW oWnd
   
return nil   

//----------------------------------------------------------------------------//
   
function Edit()

   local oWnd, aRecord := ( Alias() )->( LoadRecord() ), oBar, oBrw, oMsgBar
   local cAlias := Alias(), oBtnSave, nRecNo := ( Alias() )->( RecNo() )
   
   DEFINE WINDOW oWnd TITLE "Edit " + Alias() MDICHILD

   oWndMain:oBar:AEvalWhen()

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70
   
   DEFINE BUTTON oBtnSave OF oBar PROMPT "Save" FILENAME "../bitmaps/32x32/floppy.bmp" ;
      ACTION ( ( cAlias )->( SaveRecord( aRecord, nRecNo ) ), oBtnSave:Disable() )

   oBtnSave:Disable()

   DEFINE BUTTON OF oBar PROMPT "Prev" FILENAME "../bitmaps/32x32/prev.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( -1 ) ),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Next" FILENAME "../bitmaps/32x32/next.bmp" ;
      ACTION ( ( cAlias )->( DbSkip( 1 ) ),;
               If( ( cAlias )->( Eof() ), ( cAlias )->( DbSkip( -1 ) ),),;
               oBrw:SetArray( aRecord := ( cAlias )->( LoadRecord() ) ),;
               oBrw:SetFocus(), Eval( oBrw:bChange ) ) GROUP

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd ARRAY aRecord AUTOCOLS LINES ;
      HEADERS "FieldName", "Value" COLSIZES 150, 400 FASTEDIT ;
      ON CHANGE ( oMsgBar:cMsgDef := " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + ;
                                 "/" + AllTrim( Str( ( cAlias )->( RecCount() ) ) ),;
                  oMsgBar:Refresh() )                 

   oBrw:nEditTypes = EDIT_GET
   oBrw:aCols[ 1 ]:nEditType = 0 // Don't allow to edit first column
   oBrw:aCols[ 2 ]:bOnChange = { || oBtnSave:Enable() }
   oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar ;
      PROMPT " RecNo: " + AllTrim( Str( ( cAlias )->( RecNo() ) ) ) + "/" + ;
      AllTrim( Str( ( cAlias )->( RecCount() ) ) ) OF oWnd 2010
   
   ACTIVATE WINDOW oWnd
   
return nil      

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

function IndexBuilder()

   local oDlg, cKey := Space( 80 )
   
   DEFINE DIALOG oDlg TITLE "Index builder" SIZE 600, 500 

   oDlg:lDesign = .T.

   @ 0.5,  2 SAY "Index on" OF oDlg SIZE 40, 8

   @ 1.4, 1 GET cKey OF oDlg SIZE 140, 11 ACTION ExpBuilder()
   
   @ 0.5, 15 SAY "Tag" OF oDlg SIZE 40, 8
   
   ACTIVATE DIALOG oDlg CENTERED

return nil

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

function Indexes()

   local oWnd, oBar, oBrw, oMsgBar
   local cAlias := Alias(), aIndexes := {}, n 
   
   for n = 1 to 15
      if ! Empty( OrdName( n ) )
         AAdd( aIndexes, { n,;
                           OrdName( n ),;
                           OrdKey( n ),;
                           OrdFor( n ),;
                           OrdBagName( n ),;
                           OrdBagExt( n ) } )
      endif   
   next    
   
   DEFINE WINDOW oWnd TITLE "Indexes of " + Alias() MDICHILD

   oWndMain:oBar:AEvalWhen()

   DEFINE BUTTONBAR oBar OF oWnd 2010 SIZE 70, 70

   DEFINE BUTTON OF oBar PROMPT "Add" FILENAME "../bitmaps/32x32/plus.bmp" ;
      ACTION ( MsgInfo( "Add Tag" ), oBrw:Refresh(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Edit" FILENAME "../bitmaps/32x32/edit.bmp" ;
      ACTION ( MsgInfo( "Edit" ) )

   DEFINE BUTTON OF oBar PROMPT "Del" FILENAME "../bitmaps/32x32/minus.bmp" ;
      ACTION If( MsgYesNo( "Want to delete this tag ?" ),;
                ( ( cAlias )->( OrdBagClear( oBrw:nArrayAt ) ), oBrw:Refresh() ),)
   
   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oWnd:End() GROUP

   @ 0, 0 XBROWSE oBrw OF oWnd ARRAY aIndexes AUTOCOLS LINES ;
      HEADERS "Order", "TagName", "Expression", "For", "BagName", "BagExt" ;
      COLSIZES 50, 150, 400, 400, 150, 150

   oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   oBrw:CreateFromCode()
   oBrw:SetFocus()
   
   oWnd:oClient = oBrw

   DEFINE MSGBAR oMsgBar 2010
   
   ACTIVATE WINDOW oWnd 

return nil

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

function ExpBuilder()

   local oDlg
   
   DEFINE DIALOG oDlg TITLE "Expression builder"
   
   ACTIVATE DIALOG oDlg CENTERED

return nil

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

function LoadRecord()

   local aRecord := {}, n
   
   for n = 1 to FCount()
      AAdd( aRecord, { FieldName( n ), cValToChar( FieldGet( n ) ) } )
   next
   
return aRecord      
   
//----------------------------------------------------------------------------// 

function Search( oBrw )

   local oDlg, oCbx, cSearch := Space( 50 )
   local nRecNo := RecNo(), lInc := .T.
   
   DEFINE DIALOG oDlg TITLE "Search: " + Alias() SIZE 400, 200
   
   @ 0.5, 1.5 SAY "Ordered by: " + OrdName() OF oDlg
   
   @ 1.2, 1.5 SAY "Key: " + OrdKey() OF oDlg
   
   @ 2.4, 1.2 COMBOBOX oCbx VAR cSearch ITEMS aSearches OF oDlg SIZE 180, 150 ;
     STYLE CBS_DROPDOWN
   
   oCbx:oGet:bChange = { || DbSeek( AllTrim( oCbx:GetText() ), lInc ), oBrw:Refresh() } 
   
   @ 3.7, 1.5 CHECKBOX lInc PROMPT "&Incremental" OF oDlg SIZE 80, 10
   
   @ 4, 7 BUTTON "&Ok" OF oDlg SIZE 45, 13 ;
      ACTION ( If( ! DbSeek( AllTrim( cSearch ), lInc ), DbGoTo( nRecNo ),),;
               AAdd( aSearches, AllTrim( cSearch ) ), oDlg:End() )

   @ 4, 18 BUTTON "&Cancel" OF oDlg SIZE 45, 13 ACTION oDlg:End()
   
   ACTIVATE DIALOG oDlg CENTERED
   
return nil   

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

function SaveRecord( aRecord, nRecNo )

   local n, cType

   ( Alias() )->( DbGoTo( nRecNo ) )
   
   for n = 1 to Len( aRecord )
       cType = ( Alias() )->( FieldType( n ) )
       
       do case
          case cType $ "C,M"
               ( Alias() )->( FieldPut( n, aRecord[ n ][ 2 ] ) )
              
          case cType == "N"
               ( Alias() )->( FieldPut( n, Val( aRecord[ n ][ 2 ] ) ) )

          case cType == "D"
               ( Alias() )->( FieldPut( n, CToD( aRecord[ n ][ 2 ] ) ) )

          case cType == "L"
               ( Alias() )->( FieldPut( n, Upper( AllTrim( aRecord[ n ][ 2 ] ) ) == ".T." ) )
       endcase        
   next

   MsgInfo( "Record updated" )
   
return nil      

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

function Struct()

   local oDlg, oBrw, aFields := DbStruct()
   
   DEFINE DIALOG oDlg TITLE Alias() + " fields" SIZE 400, 400

   @ 0, 0 XBROWSE oBrw ARRAY aFields AUTOCOLS LINES ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      COLSIZES 150, 50, 80, 80

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }                      
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   
   oBrw:CreateFromCode()
      
   oDlg:oClient = oBrw
   
   ACTIVATE DIALOG oDlg CENTERED ;
      ON INIT ( BuildStructBar( oDlg, oBrw ), oDlg:Resize(), oBrw:SetFocus() )
   
return nil   

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

function BuildStructBar( oDlg, oBrw )

   local oBar

   DEFINE BUTTONBAR oBar OF oDlg 2010 SIZE 70, 70
   
   DEFINE BUTTON OF oBar PROMPT "Code" FILENAME "../bitmaps/32x32/source.bmp" ;
      ACTION ( TxtStruct(), oBrw:SetFocus() )

   DEFINE BUTTON OF oBar PROMPT "Exit" FILENAME "../bitmaps/32x32/exit.bmp" ;
      ACTION oDlg:End() GROUP

return nil

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

function TxtStruct()

   local cCode := "local aFields := { ", n
   
   for n = 1 to FCount()
      if n > 1
         cCode += Space( 27 )
      endif   
      cCode += '{ "' + FieldName( n ) + '", "' + ;
               FieldType( n ) + '", ' + ;
               AllTrim( Str( FieldLen( n ) ) ) + ", " + ;
               AllTrim( Str( FieldDec( n ) ) ) + " },;" + CRLF
   next
   
   cCode = SubStr( cCode, 1, Len( cCode ) - 4 ) + " }"
   
   MemoEdit( cCode, "Code" )

return nil

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

function New()

   local oDlg, oGet, oBrw 
   local cFieldName := Space( 10 ), cType, nLen := 10, nDec := 0
   local aFields := { Array( 4 ) }, cDbfName := Space( 8 ), aTemp
   
   DEFINE DIALOG oDlg TITLE "DBF builder" SIZE 415, 400

   @ 0.5,  2 SAY "Field Name" OF oDlg SIZE 40, 8
   @ 0.5, 10 SAY "Type" OF oDlg SIZE 40, 8
   @ 0.5, 17 SAY "Len" OF oDlg SIZE 40, 8
   @ 0.5, 22 SAY "Dec" OF oDlg SIZE 20, 8 
   
   @ 1.4, 1 GET oGet VAR cFieldName PICTURE "!!!!!!!!!!" OF oDlg SIZE 41, 11
   
   @ 1.3, 6.5 COMBOBOX cType ITEMS { "Character", "Number", "Date", "Logical" } ;
      OF oDlg

   @ 1.4, 11.9 GET nLen PICTURE "999" OF oDlg SIZE 25, 11

   @ 1.4, 15.4 GET nDec PICTURE "999" OF oDlg SIZE 25, 11

   @ 0.9, 26 BUTTON "&Add" OF oDlg SIZE 45, 13 ;
      ACTION AddField( @aFields, @cFieldName, @cType, @nLen, @nDec, oGet, oBrw )

   @ 2.2, 2 SAY "Fields" OF oDlg SIZE 40, 8
   
   @ 3.2, 1 XBROWSE oBrw ARRAY aFields AUTOCOLS ;
      HEADERS "Name", "Type", "Len", "Dec" ;
      COLSIZES 90, 55, 40, 40 ;
      SIZE 140, 130 OF oDlg

   oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROW   
   oBrw:bClrStd = { || If( oBrw:KeyNo() % 2 == 0, ;
                         { CLR_BLACK, RGB( 198, 255, 198 ) }, ;
                         { CLR_BLACK, RGB( 232, 255, 232 ) } ) }
   oBrw:bClrSel = { || { CLR_WHITE, RGB( 0x33, 0x66, 0xCC ) } }    
   oBrw:SetColor( CLR_BLACK, RGB( 232, 255, 232 ) )
   oBrw:CreateFromCode()

   @ 2.4, 26 BUTTON "&Edit" OF oDlg SIZE 45, 13

   @ 3.4, 26 BUTTON "&Delete" OF oDlg SIZE 45, 13

   @ 4.4, 26 BUTTON "Move &Up" OF oDlg SIZE 45, 13 ;
      ACTION If( oBrw:nArrayAt > 1,;
                 ( aTemp := aFields[ oBrw:nArrayAt ],;
                   aFields[ oBrw:nArrayAt ] := aFields[ oBrw:nArrayAt - 1 ],;
                   aFields[ oBrw:nArrayAt - 1 ] := aTemp,;
                   oBrw:GoUp() ),) 

   @ 5.4, 26 BUTTON "Move D&own" OF oDlg SIZE 45, 13 ;
      ACTION If( oBrw:nArrayAt < Len( aFields ),;
                 ( aTemp := aFields[ oBrw:nArrayAt ],;
                   aFields[ oBrw:nArrayAt ] := aFields[ oBrw:nArrayAt + 1 ],;
                   aFields[ oBrw:nArrayAt + 1 ] := aTemp,;
                   oBrw:GoDown() ),) 

   @ 12.1, 2 SAY "DBF Name:" OF oDlg SIZE 30, 8

   @ 14, 6 GET cDbfName PICTURE "!!!!!!!!!!!!" OF oDlg SIZE 100, 11

   @ 10, 26 BUTTON "&Create" OF oDlg SIZE 45, 13 ;
      ACTION ( If( ! Empty( cDbfName ) .and. Len( aFields ) > 0,;
          DbCreate( cDbfName, aFields ),), oDlg:End(),;
          Open( hb_CurDrive() + ":\" + CurDir() + "\" + cDbfName ) )

   ACTIVATE DIALOG oDlg CENTERED

return nil

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

function AddField( aFields, cFieldName, cType, nLen, nDec, oGet, oBrw )

   if Empty( cFieldName )
      oGet:SetPos( 0 )
      return nil
   endif   

   if Len( aFields ) == 1 .and. Empty( aFields[ 1 ][ 1 ] )
      aFields = { { cFieldName, Upper( Left( cType, 1 ) ), nLen, nDec } }
   else   
      AAdd( aFields, { cFieldName, Upper( Left( cType, 1 ) ), nLen, nDec } )
   endif
      
   oBrw:SetArray( aFields )
   oGet:VarPut( cFieldName := Space( 10 ) )
   oGet:SetPos( 0 )
   oGet:SetFocus()
   oBrw:GoBottom()
               
return nil

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

#pragma BEGINDUMP

#include <hbapi.h>
#include <hbapirdd.h>

HB_FUNC( ORDCONDGET )
{
   AREAP pArea = ( AREAP ) hb_rddGetCurrentWorkAreaPointer();
   
   if( pArea )
   {
      LPDBORDERCONDINFO lpdbOrdCondInfo = pArea->lpdbOrdCondInfo;
      
      if( lpdbOrdCondInfo && lpdbOrdCondInfo->abWhile )
         hb_retc( lpdbOrdCondInfo->abWhile );
      else
         hb_retc( "" );   
   }
   else
      hb_retc( "" );     
}

#pragma ENDDUMP

//----------------------------------------------------------------------------//  
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply