home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 16 / CD_ASCQ_16_0994.iso / news / 4611 / fw16d.ins / SAMPLES / FWBROW.PRG < prev    next >
Text File  |  1994-05-30  |  11KB  |  346 lines

  1. //----------------------------------------------------------------------------//
  2. //  FiveWin 1.0 - Ejemplos
  3. //  (c) A.Linares, F.Pulpón 1993
  4. //
  5. //  Construir con BUILD FwBrow
  6. //  To build: BUILD FwBrow
  7. //----------------------------------------------------------------------------//
  8.  
  9. // Una típica aplicación de gestión
  10. // Typical bussiness application
  11.  
  12. #include "FiveWin.ch"
  13.  
  14. static oWnd
  15.  
  16. //----------------------------------------------------------------------------//
  17.  
  18. function Main()
  19.  
  20.    local oBrush, oBar, oBmp
  21.    local cOldBmp := GetProfString( "Desktop", "WallPaper" )
  22.  
  23.    SetDeskWallPaper( "..\bitmaps\fivewin.bmp" )
  24.  
  25.    DEFINE BRUSH oBrush STYLE TILED       // FiveWin new predefined Brushes
  26.  
  27.    DEFINE WINDOW oWnd FROM 4, 4 TO 25, 75 ;
  28.       TITLE FWVERSION + " - Browsing power" ;
  29.       MENU BuildMenu() ;
  30.       BRUSH oBrush
  31.  
  32.    DEFINE BUTTONBAR oBar OF oWnd
  33.  
  34.    DEFINE BUTTON FILENAME "..\bitmaps\OpenPrj.bmp" OF oBar ;
  35.       ACTION OpenDbf() MESSAGE "Browse any DBF..."
  36.  
  37.    DEFINE BUTTON FILENAME "..\bitmaps\Exit.bmp" OF oBar ;
  38.       ACTION If( MsgYesNo( "Do you want to End ?", "Please, Select" ), oWnd:End(), ) ;
  39.       MESSAGE "End this session"
  40.  
  41.    DEFINE BUTTON FILENAME "..\bitmaps\Edit.bmp" OF oBar GROUP ;
  42.       MESSAGE "Using a Browse with dynamic Bitmap selection" ACTION Clients()
  43.  
  44.    DEFINE BUTTON FILENAME "..\bitmaps\Ques2.bmp" OF oBar ;
  45.       MESSAGE "How to get FiveWin 1.2" ACTION WinHelp( "Order.hlp" )
  46.  
  47.    SET MESSAGE OF oWnd TO FWVERSION + FWCOPYRIGHT
  48.  
  49.    @ 4, 16 BITMAP oBmp FILENAME "..\bitmaps\Tutanka1.bmp" ADJUST SIZE 280, 200 OF oWnd ;
  50.                        ON CLICK ( oBmp:lStretch := ! oBmp:lStretch, oBmp:Refresh( .t. ) )
  51.  
  52.    ACTIVATE WINDOW oWnd
  53.  
  54.    SetDeskWallPaper( cOldBmp )              // We restore old WallPaper...
  55.  
  56. return nil
  57.  
  58. //----------------------------------------------------------------------------//
  59.  
  60. function BuildMenu()
  61.  
  62.    local oMenu
  63.    
  64.    MENU oMenu
  65.       
  66.       MENUITEM OemToAnsi( "&Information" )
  67.       MENU
  68.          MENUITEM "&About..." ;
  69.             ACTION MsgInfo( "(C) A.Linares, F.Pulp≤n 1993", "FiveWin 1.2" ) ;
  70.             MESSAGE OemToAnsi( "Some information about this demo" )
  71.          SEPARATOR
  72.          MENUITEM "&Exit demo..." ACTION ;
  73.             If( MsgYesNo( "Do you want to end ?", "Please, Select" ), oWnd:End,) ;
  74.             MESSAGE "End the execution of this demo"
  75.       ENDMENU
  76.       
  77.       MENUITEM "&Clients Control" ACTION Clients()
  78.       
  79.       MENUITEM "&Utilities"
  80.       MENU
  81.          MENUITEM "&Calculator..." ACTION WinExec( "Calc" ) ;
  82.             MESSAGE "Calling Windows Calculator"
  83.  
  84.          MENUITEM "C&alendar..."  ACTION WinExec( "Calendar" ) ;
  85.             MESSAGE "Calling Windows Calendar"
  86.  
  87.          SEPARATOR
  88.  
  89.          MENUITEM "&Writing..."    ACTION WinExec( "Write" ) ;
  90.             MESSAGE "Calling Windows Write"
  91.       ENDMENU
  92.  
  93.    ENDMENU
  94.  
  95. return oMenu
  96.  
  97. //----------------------------------------------------------------------------//
  98.  
  99. function Clients()
  100.  
  101.    local oDlg
  102.    local oLbx
  103.    local aHBitMaps:= { ReadBitmap( 0, "..\bitmaps\Level1.bmp" ), ; // BitMaps de 14 x 32
  104.                        ReadBitmap( 0, "..\bitmaps\Level2.bmp" ), ;
  105.                        ReadBitmap( 0, "..\bitmaps\Level3.bmp" ), ;
  106.                        ReadBitmap( 0, "..\bitmaps\Level4.bmp" ),;
  107.                        ReadBitmap( 0, "..\bitmaps\Level5.bmp" ) }
  108.  
  109.    if ! File( "clientes.dbf" )
  110.       DbCreate( "Clientes.dbf", { { "Nombre",    "C", 40, 0 },;
  111.                                   { "Direccion", "C", 50, 0 },;
  112.                                   { "Telefono",  "C", 12, 0 },;
  113.                                   { "Edad",      "N",  2, 0 },;
  114.                                   { "Productos", "C", 10, 0 },;
  115.                                   { "Nivel",     "N",  2, 0 } } )
  116.    endif
  117.    
  118.    USE Clientes
  119.    if RecCount() == 0
  120.       APPEND BLANK
  121.    endif
  122.    INDEX ON Clientes->Nombre TO CliName
  123.    SET INDEX TO CliName
  124.    GO TOP
  125.  
  126.    DEFINE DIALOG oDlg FROM 3, 3 TO 26, 79 TITLE "Clients Management"
  127.  
  128.    @ 0,  1 SAY " &Clients List"  OF oDlg
  129.  
  130.    @ 1, 1 LISTBOX oLbx FIELDS aHBitmaps[ Max( 1, Clientes->Nivel ) ],;
  131.                               Clientes->Nombre, Clientes->Direccion,;
  132.                               Clientes->Telefono, ;
  133.                               Str( Clientes->Edad, 3 ) ;
  134.           HEADERS    "L", "Name", "Address", "Phone", "Age" ;
  135.           FIELDSIZES 16, 240, 310, 114, 24 ;
  136.           SIZE 284, 137 OF oDlg
  137.  
  138.    @ 13,  1 BUTTON "&New"    OF oDlg ACTION EditClient( oLbx, .t. ) ;
  139.                                               SIZE 40, 12
  140.    @ 13,  8 BUTTON "&Modify" OF oDlg ACTION EditClient( oLbx, .f. ) ;
  141.                                               SIZE 40, 12
  142.    @ 13, 15 BUTTON "&Delete" OF oDlg ACTION DelClient( oLbx )  SIZE 40, 12
  143.    @ 13, 22 BUTTON "&Search" OF oDlg ACTION SeekClient( oLbx ) SIZE 40, 12
  144.    @ 13, 29 BUTTON "&Print"  OF oDlg ACTION Listar( oLbx )     SIZE 40, 12
  145.    @ 13, 36 BUTTON "&Exit"   OF oDlg ACTION oDlg:End()         SIZE 40, 12
  146.  
  147.    ACTIVATE DIALOG oDlg
  148.  
  149.    USE
  150.  
  151.    AEval( aHBitmaps, { | hBmp | DeleteObject( hBmp ) } )
  152.    
  153. return nil
  154.  
  155. //----------------------------------------------------------------------------//
  156.  
  157. static function EditClient( oLbx, lAppend )
  158.  
  159.    local oDlg
  160.    local lFivePro
  161.    local lDialog
  162.    local lObjects
  163.    local nNivel
  164.    local cName
  165.    local cAddress
  166.    local cPhone
  167.    local nAge
  168.    local lSave := .f.
  169.    local nOldRec := RecNo()
  170.  
  171.    DEFAULT lAppend := .f.
  172.  
  173.    if lAppend
  174.       GOTO BOTTOM
  175.       SKIP
  176.    endif
  177.  
  178.    lFivePro = "F" $ Clientes->Productos
  179.    lDialog  = "D" $ Clientes->Productos
  180.    lObjects = "O" $ Clientes->Productos
  181.    nNivel   = max( 1, Clientes->Nivel )
  182.    cName    = Clientes->Nombre
  183.    cAddress = Clientes->Direccion
  184.    cPhone   = Clientes->Telefono
  185.    nAge     = Clientes->Edad
  186.  
  187.    DEFINE DIALOG oDlg FROM 8, 2 TO 25, 65 ;
  188.       TITLE If( lAppend, "Nuevo Cliente", "Modifique Cliente" )
  189.  
  190.    @ 1,  1 SAY "&Nombre:" OF oDlg
  191.    @ 1,  6 GET cName OF oDlg
  192.    @ 2,  1 SAY OemToAnsi( "&Dirección:" ) OF oDlg
  193.    @ 2,  6 GET cAddress OF oDlg
  194.  
  195.    @ 3,  1 TO 7, 8 LABEL "&Productos" OF oDlg
  196.    @ 4,  1 CHECKBOX lFivePro PROMPT "&FivePro" OF oDlg
  197.    @ 5,  1 CHECKBOX lDialog  PROMPT "&Dialog"  OF oDlg
  198.    @ 6,  1 CHECKBOX lObjects PROMPT "&Objects" OF oDlg
  199.  
  200.    @ 3,  9 TO 7, 17 LABEL "&Nivel" OF oDlg
  201.    @ 4,  9 RADIO nNivel PROMPT "&Inicial", "A&vanzado", "&Experto" OF oDlg
  202.  
  203.    @ 4, 16 SAY OemToAnsi( "&Teléfono:" ) OF oDlg
  204.    @ 4, 21 GET cPhone OF oDlg SIZE 60, 11 PICTURE "@R 99-999-9999999"
  205.  
  206.    @ 6, 16 SAY OemToAnsi( "&Edad:" ) OF oDlg
  207.    @ 6, 21 GET nAge OF oDlg SIZE 20, 11
  208.  
  209.    @ 9,  9 BUTTON "&Aceptar"  OF oDlg SIZE 50, 12 ACTION ( lSave := .t. , oDlg:End() )
  210.    @ 9, 19 BUTTON "&Cancelar" OF oDlg SIZE 50, 12 ACTION oDlg:End()
  211.  
  212.    ACTIVATE DIALOG oDlg CENTERED
  213.  
  214.    if lSave .and. !empty( cName )
  215.  
  216.       if lAppend
  217.          APPEND BLANK
  218.       endif
  219.  
  220.       Clientes->Nombre     := cName
  221.       Clientes->Direccion  := cAddress
  222.       Clientes->Productos  := if( lFivePro, "F", "" ) + ;
  223.                               if( lDialog,  "D", "" ) + ;
  224.                               if( lObjects, "O", "" )
  225.  
  226.       Clientes->Nivel      := nNivel
  227.       Clientes->Telefono   := cPhone
  228.       Clientes->Edad       := nAge
  229.  
  230.       oLbx:Refresh()          // We want the ListBox to be repainted
  231.  
  232.    else
  233.  
  234.       if empty( cName ) .and. lSave
  235.          nMsgBox( "Debe entrar un Nombre para que el registro se valide" )
  236.       endif
  237.  
  238.       GOTO nOldRec
  239.  
  240.    endif
  241.  
  242. return nil
  243.  
  244. //---------------------------------------------------------------------------//
  245.  
  246. static function DelClient( oLbx )
  247.  
  248.    if MsgYesNo( OemToAnsi( "Atención:" ) + CRLF + ;
  249.                 OemToAnsi( "¿ Está seguro de " + ;
  250.                 "querer borrar este registro ?" ) + CRLF + CRLF + ;
  251.                 OemToAnsi( Clientes->Nombre ) )
  252.       DELETE
  253.       PACK
  254.  
  255.       oLbx:Refresh()  // Repintamos el ListBox
  256.  
  257.    endif
  258.  
  259. return nil
  260.  
  261. //----------------------------------------------------------------------------//
  262.  
  263. static function SeekClient( oLbx )
  264.  
  265.    local cNombre := Space( 30 )
  266.    local nRecNo  := RecNo()
  267.  
  268.    SET SOFTSEEK ON
  269.  
  270.    if MsgGet( "Buscar por", "Nombre del Cliente", @cNombre,;
  271.               "..\bitmaps\lupa.bmp" )
  272.  
  273.       if ! DbSeek( cNombre )
  274.          nMsgBox( "No encuentro ese Cliente", OemToAnsi( "Atención" ) )
  275.          GO nRecNo
  276.       else
  277.          oLbx:UpStable()           // Corrects same page stabilizing Bug
  278.          oLbx:Refresh()            // Repintamos el ListBox
  279.       endif
  280.    endif
  281.  
  282. return nil
  283.  
  284. //----------------------------------------------------------------------------//
  285.  
  286. function Listar( oLbx )
  287.  
  288.    local oPrn, fntArial
  289.    local nRow := 1, nRec := Recno()
  290.  
  291.    GO TOP
  292.  
  293.    DEFINE FONT fntArial NAME "Arial" SIZE 40, 60
  294.  
  295.    PRINT oPrn NAME "Clientes"                // Nombre del listado a generar
  296.  
  297.       PAGE
  298.          while ! EoF()
  299.             oPrn:Say( nRow, 1, Clientes->Nombre, fntArial )
  300.  
  301.             nRow += fntArial:nHeight
  302.  
  303.             if nRow > 50 * fntArial:nHeight  // Nº de líneas x Alto caracter
  304.                nRow = 1                      // Tendremos que calcular el
  305.                ENDPAGE                       // número de líneas que podemos
  306.                PAGE                          // utilizar con un font determinado
  307.             endif
  308.  
  309.             SKIP
  310.          end
  311.       ENDPAGE
  312.  
  313.    ENDPRINT
  314.  
  315.    GOTO nRec
  316.  
  317.    RELEASE FONT fntArial
  318.  
  319. return nil
  320.  
  321. //----------------------------------------------------------------------------//
  322.  
  323. function OpenDbf()
  324.  
  325.    local cFile := cGetFile( "Clipper DataBase (*.dbf) | *.dbf", "Select a DBF" )
  326.  
  327.    if ! Empty( cFile )
  328.       USE ( cFile )
  329.  
  330.       // Quick and easy browses!
  331.       // Fully integrated into a Dialog Box !!!
  332.  
  333.       Browse( "FiveWin Automatic Browse Power",;
  334.               "Easy Browses without pain...",;
  335.               { || MsgInfo( "This will be executed from first button...", "Info1" ) },;
  336.               { || MsgInfo( "You can atach any action to the buttons...", "Info2" ) },;
  337.               { || MsgInfo( "We also provide full source code of this...", "Info3" ) },;
  338.               { || MsgInfo( "So you can adapt it to your necesities", "Info4" ) } )
  339.       USE
  340.    endif
  341.  
  342. return nil
  343.  
  344. //---------------------------------------------------------------------------//
  345.  
  346.