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