Ejemplo TdosPrn

Ejemplo TdosPrn

Postby TOTOVIOTTI » Wed Aug 17, 2016 11:36 am

Amigos
necesitaría probar un pequeño ejemplo de TdosPrn pero no hay forma.
Sólo con la clase nativa, sin modificaciones y si tiene vista previa con la clase nativa
también.
He probado varios de los que están en el foro y no los puedo hacer funcionar.
Descargué y enlacé la txtprev.prg y nada...
No encuentro nada en la carpeta SAMPLES del FWH.
Gracias
Roberto
Univ@c I.S.I.
Desarrolladores de Software
http://www.elcolegioencasa.edu.ar
User avatar
TOTOVIOTTI
 
Posts: 387
Joined: Fri Feb 05, 2010 11:30 am
Location: San Francisco - Córdoba - Argentina

Re: Ejemplo TdosPrn

Postby karinha » Wed Aug 17, 2016 12:57 pm

Mui facil:

Code: Select all  Expand view

/*
USB com TDOSPRN.PRG

Enla cabecera de mi rutina de impresión hice esto:

cPorta := PrnGetPort()
cPrinter := PrinterPortToName( cPorta )
if empty(cPrinter)
   cPrinter := PrinterPortToName( "USB002" )
   if empty(cPrinter)
      cPrinter := PrinterPortToName( "USB001" )
   endif
endif
 

Despues empiezo la impresión, preo creando un archivo:


oPrin := TDosPrn():New("minuta.txt")
oPrin:StartPage()
...
...
 

Y en el fin de la rutina hago esto:


...
...
oPrin:EndPage()
oPrin:End()


PrintFileRaw( cPrinter, TrueName("MINUTA.TXT"), "Impressão de Vendas" )
*/


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

//----- Definicao de comando SAY para TdosPrn ---------------------------------
//

#xcommand @ <nRow>, <nCol> SAY <cText> OF <oPrinter> => <oPrinter>:Say(<nRow>, <nCol>, <cText> )

//-------------------------------------------------------------------------//
// Imprime os Cupons Nao Fiscal da Pizzaria/Restaurante
//-------------------------------------------------------------------------//

STATIC FUNCTION IMPRIMIR_CUPOM( nKey, aGetVenda, oLbx, oDlgVendas, DbClientes,;
                                                       DbEstoque,  DbPedidos )

    FIELD QTD_VENDEU, DESCRICAO, VLUNITARIO, TOTITEM, TOTPEDIDO
    FIELD MENSAG1, MENSAG2, MENSAG3, MENSAG4, MENSAG5

    LOCAL nLinha, nPag, oPrn, Conta, Pula, DbMensag

    MEMVAR XNUMPEDIDO,   nNumeroTel,   cCodClien,   cNomeClien,   cEndClien,  ;
           cNomeProduto, nQuantidade,  nValorProd,  nValorCompra, oSayCxLivre,;
           XCGCCLI,      nQtdeEstoque, nCodigoProd
    MEMVAR nDinheiro,    nCheque,     nChequePre,  nTickets,     nCartaoCred,;
           nCartaoDebi,  nContraVale, nTaxaEntreg, nValorTroco,  nSomaSubTot,;
           XTROCOCLI,    Valor_Pago,  nValor_Pago, oSayEmpresa

    //-> Nome Fantasia da Empresa - Est  em EMPRESA.DBF
    PUBLIC XDA, XCAIXA, XCODVEND, XNOMEEMP, XFANTASIA, XIMPQTDECOP, ;
           XPULARLINHA

    nLinha      := 0
    nPag        := 1

    IF XIMPQTDECOP <= 0
       XIMPQTDECOP := 1
    ENDIF

    //-> Mensagens do Rodape
    IF NETUSE( "MENSAGEM", .T. )
       DATABASE DbMensag
       DbMensag:Load()        //-> Temporario = a FP_PROV.DBF
       DbMensag:SetBuffer( .T. )
    ENDIF

    SELECT ( DbPedidos:cAlias )
    DbPedidos:SetOrder( 1 )
    GO TOP

    // Para Rede de Computadores
    // oPrn:New("\\seuterminal\suaimpressora\LPT1")
    oPrn:= TDosPrn():New( "CUPOM.TXT" ) // para ir para um arquivo .txt
    // oPrn:= TDosPrn():New()        // para ir para impressora em definitivo
    // oPrn := TDosPrn():New("lpt1") // para ir para impressora em definitivo
    // Este Comando, Liga a Impressora. NÆo Tirar Nunca
    oPrn:StartPage() // da Start(inicializa) na p gina.
    oPrn:lZeraBuffer := .T.             // Inibe o Pulo da P gina

    //-> Inicia a Impressao - Cabe‡alho do Cupom
    //-> Modo Draft
    @ nLinha, 00 SAY +CHR(18)+CHR(27)+"2"+CHR(27)+"H"          OF oPrn

    @ nLinha, 00 SAY SUBST( XNOMEEMP, 1, 23 )                  OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY CHR(15)+REPLICATE("-",38)                 OF oPrn
    nLinha := nLinha + 1

    //-> Modo Condensado
    @ nLinha, 00 SAY CHR(15)+"HORA: " + TIME() + " - " + ;
                            + DTOC(XDA)                        OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY OemToAnsi("PEDIDO N§: " ) + ;
                     ALLTRIM(STRZERO( XNUMPEDIDO ) )           OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY "FONE..: " + nNumeroTel                   OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY SUBSTR( cNomeClien, 1, 40 )               OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY SUBSTR( cEndClien, 1, 40 )                OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY REPLICATE("-",38)                         OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY "Cod   Qtde   Descricao  Unit     Valor"  OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY REPLICATE("-",38)                         OF oPrn
    nLinha := nLinha + 1

    //-> Imprime o Pedido
    WHILE !EOF()

       SYSREFRESH()

       IF EOF()
          EXIT
       ENDIF

       @ nLinha, 00 SAY ( DbPedidos:cAlias )->CODIGO          OF oPrn
       nLinha := nLinha + 1

       @ nLinha, 00 SAY ( ALLTRIM( STR( QTD_VENDEU ) ) ) +[ - ]+ ;
                        ( SUBSTR( DESCRICAO, 01, 17 ) )  OF oPrn

       nLinha := nLinha + 1

       @ nLinha, 00 SAY ( SUBSTR( DESCRICAO, 18, 35 ) )            +  ;
                          TRANSFORM( VLUNITARIO, "@E  99,999.99" ) +  ;
                          TRANSFORM( TOTITEM,    "@E 999,999.99" ) OF oPrn

       nLinha := nLinha + 1

       DBSKIP()

    ENDDO

    //-> Total do Pedido
    IF EOF() .OR. TOTPEDIDO <= 0
       SKIP(-1)
    ENDIF

    @ nLinha, 00 SAY CHR(15)+REPLICATE("-",38)                  OF oPrn
    nLinha := nLinha + 1

    IF nDinheiro    > 0
       @ nLinha, 00 SAY "EM DINHEIRO:   " + ;
                    TRANSFORM( nDinheiro, "@E 999,999.99" )    OF oPrn
       nLinha := nLinha + 1
    ENDIF

    IF nCheque      > 0
       @ nLinha, 00 SAY "EM CHEQUE:     " + ;
                    TRANSFORM( nCheque, "@E 999,999.99" )      OF oPrn
       nLinha := nLinha + 1
    ENDIF

    IF nChequePre   > 0
       @ nLinha, 00 SAY "EM CHEQUE PRE: " + ;
                    TRANSFORM( nChequePre, "@E 999,999.99" )   OF oPrn
       nLinha := nLinha + 1
    ENDIF

    IF nTickets     > 0
       @ nLinha, 00 SAY "EM TICKETS:    " + ;
                    TRANSFORM( nTickets, "@E 999,999.99" )     OF oPrn
       nLinha := nLinha + 1
    ENDIF

    IF nCartaoCred  > 0
       @ nLinha, 00 SAY "EM C. CREDITO: " + ;
                    TRANSFORM( nCartaoCred, "@E 999,999.99" )  OF oPrn
       nLinha := nLinha + 1
    ENDIF

    IF nCartaoDebi  > 0
       @ nLinha, 00 SAY "EM C. DEBITO:  " + ;
                    TRANSFORM( nCartaoDebi, "@E 999,999.99" )  OF oPrn
       nLinha := nLinha + 1
    ENDIF

    IF nContraVale  > 0
       @ nLinha, 00 SAY "EM C. VALE:    " + ;
                    TRANSFORM( nContraVale, "@E 999,999.99" )  OF oPrn
       nLinha := nLinha + 1
    ENDIF

    @ nLinha, 00 SAY CHR(15)+REPLICATE("-",38)                  OF oPrn
    nLinha := nLinha + 1

    //-> Fechou o Cupom
    @ nLinha, 00 SAY +CHR(18)+CHR(27)+"2"+CHR(27)+"H"  + ;
                     "TOTAL: "                         + ;
                     TRANSFORM( TOTPEDIDO, "@E 9,999,999.99" )  OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY CHR(15)+REPLICATE("-",38)                  OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY CHR(15)+"TROCO:    " + ;
                 TRANSFORM( XTROCOCLI, "@E 999,999.99" )        OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY "CAIXA: " + STRZERO( XCAIXA, 3 ) + [ - ] + ;
                     "OPERADOR: " + XCODVEND                    OF oPrn
    nLinha := nLinha + 1

    @ nLinha, 00 SAY CHR(15)+REPLICATE("-",38)                  OF oPrn
    nLinha := nLinha + 1

    SELECT ( DbMensag:cAlias )
    GO TOP

    WHILE !EOF()

       SYSREFRESH()

       IF EOF()
          EXIT
       ENDIF

       IF (MENSAG1 ) != SPACE(40)
          @ nLinha, 00 SAY MENSAG1  OF oPrn
          nLinha := nLinha + 1
       ENDIF

       IF (MENSAG2 ) != SPACE(40)
          @ nLinha, 00 SAY MENSAG2  OF oPrn
          nLinha := nLinha + 1
       ENDIF

       IF (MENSAG3 ) != SPACE(40)
          @ nLinha, 00 SAY MENSAG3  OF oPrn
          nLinha := nLinha + 1
       ENDIF

       IF (MENSAG4 ) != SPACE(40)
          @ nLinha, 00 SAY MENSAG4  OF oPrn
          nLinha := nLinha + 1
       ENDIF

       IF (MENSAG5 ) != SPACE(40)
          @ nLinha, 00 SAY MENSAG5  OF oPrn
          nLinha := nLinha + 1
       ENDIF

       @ nLinha, 00 SAY CHR(15)+REPLICATE("-",38)              OF oPrn
       nLinha := nLinha + 1

       DBSKIP()

    ENDDO

    //-> Pulos do Cupom
    FOR PULA = 1 TO XPULARLINHA
       @ nLinha, 00 SAY "."                                    OF oPrn
       nLinha := nLinha + 1
    NEXT PULA

    //-> Modo Draft
    @ nLinha, 00 SAY +CHR(18)+CHR(27)+"2"+CHR(27)+"H"           OF oPrn

    oPrn:EndPage()
    oPrn:End()

    //--- imprime no spool do windows, liberando o micro para trabalhar.
    ImpSpool( "CUPOM.TXT",, .T. ) // esta em DBMANT.PRG impressora USB/matricial
    //--- opcionamente pode-se apagar o arquivo passando .t. no 3o. parametro.

    DbMensag:Close()

    SELECT ( DbPedidos:cAlias )
    DbPedidos:SetOrder( 1 )
    DbPedidos:Gotop()

RETURN NIL

// Maravilhoso Ednaldo Cabra Bom!!!
//----------------------------------------------------------------------------//
// Funcao    : ImpSpool( cFileTxt, cPorta, lErase )
// Autor     : Ednaldo Rolim (edrol@pop.com.br)
// Descricao : Envia um arquivo TXT criado pela TDosPrn para uma
//             porta de Impressora.
//----------------------------------------------------------------------------//
FUNCTION ImpSpool( cFileTxt, cPorta, lErase )

    LOCAL CPRINTER

    //para capturar antes da impressão
    //cPorta := PrnGetPorta()
    //WinExec( cPorta )
    //depois da impressão
    //WinExex( "Net Use Lpt1: \Delete" )
    //Ficou mais facil e simples do que criar as portas na Classe TDosPrn
    //cPorta := If( cPorta == nil, Alltrim( PrnGetPort() ), cPorta ) ; lErase := If( lErase == nil, .T., lErase );

    //cPorta := PrnGetPort()
    Default cPorta := Alltrim( PrnGetPort() ), lErase:= .t.

    cPrinter := PrinterPortToName( cPorta )

    IF EMPTY( cPrinter )

       cPrinter := PrinterPortToName( "USB002" )

       IF EMPTY(cPrinter)

          cPrinter := PrinterPortToName( "USB001" )

       ENDIF

    ENDIF
   
    IF .NOT. FILE( cFileTxt )

       MsgInfo( OemToAnsi( "NÇO ACHEI O ARQUIVO MODO TEXTO PARA IMPRIMIR NA MATRICIAL" ), ;
                OemToAnsi( "NÇO ACHEI O ARQUIVO MODO TEXTO PARA IMPRIMIR NA MATRICIAL" ) )

       RETURN( .F. )

    ENDIF

    IF .NOT. EMPTY( cPrinter )  // TEM USB

       PrintFileRaw( cPrinter, TrueName( "CUPOM.TXT" ), "Impressão de Vendas" )

    ELSEIF LEN( cPorta ) <= 5 .and. Left( Upper(cPorta), 4 ) = "LPT1"

       //--- Spool Local - Matricial em LPT1
       cPorta:= "PRN"

       WAITRUN("COMMAND.COM /C COPY /B " + cFileTxt + " " + cPorta, 0 )

    ELSE

       //--- Spool Remoto - Matricial em LPT1
       WAITRUN("COMMAND.COM /C COPY /B " + cFileTxt + " " + cPorta, 0 )

    ENDIF

    IF lErase // Vem .T. da tela de vendas
       FERASE( cFileTxt )
    ENDIF

RETURN( .T. )
 


Saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Ejemplo TdosPrn

Postby TOTOVIOTTI » Wed Aug 17, 2016 1:01 pm

Gracias Joao! Voy a probar!
Univ@c I.S.I.
Desarrolladores de Software
http://www.elcolegioencasa.edu.ar
User avatar
TOTOVIOTTI
 
Posts: 387
Joined: Fri Feb 05, 2010 11:30 am
Location: San Francisco - Córdoba - Argentina

Re: Ejemplo TdosPrn

Postby karinha » Wed Aug 17, 2016 1:30 pm

TDOSPRN.PRG que yo uso sin problemas:

Code: Select all  Expand view

/*
ÚÄ Programa ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³   Aplication: Class TDosPrint                                            ³
³         File: TDOSPRN.PRG                                                ³
³       Author: Ignacio Ortiz de Z£¤iga Echeverr¡a                         ³
³          CIS: Ignacio Ortiz (Ignacio_Ortiz)                              ³
³     Internet: http://www.ozs.com                                         ³
³         Date: 09/13/96                                                   ³
³         Time: 20:20:07                                                   ³
³    Copyright: 1997 by Ortiz de Zu¤iga, S.L.                              ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

NOTES:

This peace of software is freeware and is not part of FiveWin.

The following code will let you print directly to the printer from inside
any Fivewin program, like OLD DOS days. Those users that need DOS printing
speed can use this class instead of the TPrinter class.

The use of the class is very easy and is very similar to the TPrinter class
of Fivewin, but we have not create any command to avoid the use of any
static vars.

This is a little sample of how to use the new class:

  LOCAL oPrn

  oPrn := TDosPrn():New("lpt1")

  oPrn:StartPage()                                    // optional
  oPrn:Say(10,20, "This goes in line 10, column 20")
  oPrn:EndPage()                                      // optional

  oPrn:End()

A little description of all the members of this class:

DATA:

 cPort:        Printing port, by default "LPT1"
 cCompress:    String for compressed mode, by default "15"
 cNormal:      String for normal mode, by default "18"
 cFormFeed:    String for EJECT, by default "12"
 hDC:          Printing file Handle (Internal use)
 nRow:         Current printing row
 nCol:         Current pringing column
 nLeftMargin:  Left margin, by default 0
 nTopMargin:   Top margin, by default 0

METHODS:

 New(cPort)    Constructor, no comment
 End()         Destructor, no comment
 StartPage()   Begining of a page, this method is optional
 EndPage()     End of page, this method is optional if there is only on page,
               or you try to print in a row that is before the current one,
               like it did happen with the SAY command
 Command(c)    Let you send any command to the printer without changing the
               current row and col. The string to pass as a parameter should
               content the ascii values of the command separated with commas,
               for example, the command to reset Epson printers should
               be: "27,69"
 SetCoors(r,c) Let you change the current row and col is the equivalent of
               SetPrc() of Ca-Clipper
 NewLine()     Increments the current row
 Write(cText)  Prints the string cText in the current row and column
 Say(nRow   ,; Prints the string cText in nRow, nCol
     nCol   ,;
     cText   )
 SayCmp()      The same as the method Say but prints in compressed mode and
               the row is updated accordly.

NOTE:

At the end of this class is a little function call WorkSheet that will make
the job of DOS printing a lot easier.

Enjoy it!

*/


/*
// Baixei de www.fivewin.com.br em 01/11/2002
// Modifiquei em 03/11/2002 - kapiabafwh@bol.com.br  By JoÆo.
// InclusÆo: Parte Modificada Por Ednaldo Rolim - edrol@pop.com.br
// Acrescentada a Parte Modificada Pelo Gilmer: www.fivewin.com.br
*/


#Include "FiveWin.Ch"
#Include "Fileio.Ch"

#Translate nTrim(<n>)  => AllTrim(Str(<n>,10,0))

#define PF_BUFLEN   2048

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

CLASS TDosPrn

     DATA LastError
     DATA cPort, cCompress, cNormal, cFormFeed, cBuffer
     DATA hDC, nRow, nCol, nLeftMargin, nTopMargin
     DATA lAnsiToOem, lCompress
     DATA lZeraBuffer // By Gilmer www.fivewin.com.br
     DATA ImpUSB // AS LOGICAL  By Diego@sysfar.com.br // Imprimir na USB

     DATA oWnd, oPagina                      // Ednaldo
     DATA nPage        AS NUMERIC            // Ednaldo

     //METHOD New(cPort) CONSTRUCTOR
     METHOD New(cPort, cVerUSB) CONSTRUCTOR   // By Diego da Sysfar

     METHOD End()

     // Antigo(Old)
     // METHOD StartPage()  VIRTUAL // NÆo Conta as P ginas
     // METHOD EndPage()

     // Novo (New)   // Conta as P ginas By Ednaldo Rolim
     METHOD StartPage()    INLINE ::ShowProc()           // Ednaldo

     METHOD EndPage()

     // METHOD Command(xPar1, xPar2, xPar3, xPar4, xPar5) //velho
     METHOD Command(cStr1, cStr2, cStr3, cStr4, cStr5)   // novo

     METHOD SetCoors(nRow, nCol)

     METHOD NewLine()       INLINE (::cBuffer += CRLF ,;
                                    ::nRow++          ,;
                                    ::nCol    := 0     )

     METHOD Write(cText, lAToO) ;
            INLINE (IIF(lAtoO == NIL, lAtoO := .T.,),;
                    ::cBuffer += iif(lAtoO, AnsitoOem(cText), cText) ,;
                    ::nCol    += len(cText)                           )

     METHOD Say(nRow, nCol, cText, lAToO)

     METHOD SayCmp(nRow, nCol, cText)

     METHOD CharSay(nRow,nCol,cText) INLINE (IIf(::lCompress,;
                ::SayCmp(nRow,nCol,cText),;
                ::Say(nRow,nCol,cText)))

     METHOD ZeraBuffer() // By. Gilmer

     METHOD PrintFile(cFile)

     METHOD ShowProc()          // Ednaldo

ENDCLASS

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

METHOD New( cPort, lFile, lCompress, cVerUSB ) CLASS TDosPrn

     DEFAULT cPort   := "LPT1", ;
             cVerUSB := .F.,    ;
             lFile   := .T.   , ;
             lCompress := .F.

     cPort := Upper(cPort)

     /* // Copiei de DOSPRINT.PRG
     [EPSON]
     Normal=18
     Bold=27,18,27,69
     Medium=27,70,27,58
     Compress=15
     Large=27,69,27,18,27,14
     Tiny=27,70,27,83,0,27,49,18,15
     NoTiny=27,70,27,84,27,50
     FormFeed=12
     Length=27,67,0

     [OKIDATA]
     Normal=27,70,27,84,27,50,27,15,18
     Bold=27,18,27,69
     Medium=27,70,27,58
     Compress=27,70,27,84,27,15
     Large=27,69,27,18,27,14
     Tiny=27,70,27,83,0,27,49,18,15
     NoTiny=27,70,27,84,27,50
     Image=27,76
     Header=
     Footer=
     Jump=216
     FormFeed=12
     Length=27,67,0
     */


     ::ImpUSB      := .F.
     ::cCompress   := "15"
     ::cNormal     := "18"
     ::cFormFeed   := "  "  // 12  //Pulo de P gina
     ::cBuffer     := ""
     ::nLeftMargin := 0
     ::nTopMargin  := 0
     ::nRow        := 0
     ::nCol        := 0
     ::lAnsiToOem  := .T.
     ::cPort       := cPort + iif(!"." $ cPort, ".PRN", "")

     If cVerUSB .and. upper( PrnGetPort( ) )="USB"
        //::cPort := DirTempdoWindows()+"\usb.imp"
         ::cPort       := cPort + iif(!"." $ cPort, ".IMP", "")
     Endif

     ::hDC         := fCreate(::cPort)
     ::LastError   := 0
     // By. Gilmer  // .F. Pula P gina, .T. NÆo Pula a P gina (Cupom Fiscal)
     ::lZeraBuffer := .F.

     IF ::hDC < 0
          ::LastError := fError()
     ENDIF

     ::nPage := 1                  // Ednaldo
     ::ShowProc()                  // Ednaldo

RETURN Self


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

METHOD End() CLASS TDosPrn

     IF !empty(::nRow+::nCol)
          ::EndPage()
     ENDIF

     ::LastError := 0

     IF !fClose(::hDC)
          ::LastError := fError()
     ENDIF

     CursorArrow()

     if ::oWnd != Nil                    // Ednaldo
        ::oWnd:End()                     // Ednaldo
     endif                               // Ednaldo

RETURN NIL

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

METHOD EndPage() CLASS TDosPrn

     LOCAL nFor, nLen, nSec
     LOCAL lError

     If !::lZeraBuffer  // By Gilmer
        ::Command(::cFormFeed)
     End

     ::LastError := 0

     IF fWrite(::hDC, ::cBuffer) < len(::cBuffer)
          ::LastError := fError()
     ENDIF

     ::cBuffer := ""
     ::nRow    := 0
     ::nCol    := 0

RETURN NIL

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

//METHOD Command(xPar1, xPar2, xPar3, xPar4, xPar5) CLASS TDosPrn // Velho
METHOD Command(cStr1, cStr2, cStr3, cStr4, cStr5) CLASS TDosPrn  // Novo

     LOCAL cCommand, cToken, cString
     LOCAL nToken

     //cString  := cValToChar(xPar1) // Velho

     cString  := cStr1   // Novo

/* // Velho
     IF xPar2 != NIL
          cString += ","+cValToChar(xPar2)
     ENDIF
*/


     IF cStr2 != NIL
          cString += ","+cStr2
     ENDIF

/*   // Velho
     IF xPar3 != NIL
          cString += ","+cValToChar(xPar3)
     ENDIF
*/


     IF cStr3 != NIL
          cString += ","+cStr3
     ENDIF

/*   // Velho
     IF xPar4 != NIL
          cString += ","+cValToChar(xPar4)
     ENDIF
*/


     IF cStr4 != NIL
          cString += ","+cStr4
     ENDIF

/*   // Velho
     IF xPar5 != NIL
          cString += ","+cValToChar(xPar5)
     ENDIF
*/


     IF cStr5 != NIL
          cString += ","+cStr5
     ENDIF

     cCommand := ""
     nToken   := 1

     DO WHILE !Empty(cToken := StrToken(cString, nToken++, ","))
          cCommand += Chr(Val(cToken))
     ENDDO

     ::cBuffer += cCommand

RETURN NIL

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

METHOD SetCoors(nRow, nCol) CLASS TDosPrn

     nRow += ::nTopMargin
     nCol += ::nLeftMargin

     IF ::nRow > nRow
          ::EndPage()
          ::nPage++                          // Ednaldo
          ::StartPage()
     ENDIF

     /*   // do Site
     IF ::nRow > nRow
          ::EndPage()
          ::StartPage()
     ENDIF
     */


     // Tava Aqui

     /*   // do Site
     IF nRow == ::nRow  .AND. nCol < ::nCol
          ::EndPage()
          ::StartPage()
     ENDIF
     */


     DO WHILE ::nRow < nRow
          ::NewLine()
     ENDDO

     IF nCol > ::nCol
          ::Write(Space(nCol-::nCol))
     ENDIF

     // Para Imprimir Primeiro na coluna desejada exemplo 1§ na Coluna 50
     // Depois na coluna 05... By NetSpeed Inverte-se a Ordem da Cabe‡a de
     // ImpressÆo, Come‡ando do Fim Para o Inicio...
     If nRow == ::nRow .and. nCol < ::nCol
         ::Write(Chr(13))  // NetSpeed
     Endif

     // Aqui Inicia da Coluna 1 em diante, nÆo faz como a anterior.
     // Ou Seja do Inicio Para o Fim da Cabe‡a de ImpressÆo, o Que ‚ Normal.
     IF nRow == ::nRow  .AND. nCol < ::nCol
          ::EndPage()
          ::nPage++                          // Ednaldo
          ::StartPage()
     ENDIF

     // By. Gilmer
     If Len(::cBuffer)>=7928
        ::ZeraBuffer()
     Endif

RETURN NIL

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

METHOD Say(nRow, nCol, cText, lAToO) CLASS TDosPrn

     DEFAULT lAToO := ::lAnsiToOem

     IF VALTYPE( cText ) = "D"
        cText := DTOC( cText )
     ENDIF

     IF VALTYPE( cText ) = "N"
        cText := STR( cText )
     ENDIF

     ::SetCoors(nRow, nCol)

     ::Write(cText, lAToO)

RETURN NIL

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

METHOD SayCmp(nRow, nCol, cText, lAToO) CLASS TDosPrn

     DEFAULT lAToO := ::lAnsiToOem

     ::Command(::cCompress)
     ::SetCoors(nRow, nCol)
     ::cBuffer += iif(lAToO, AnsitoOem(cText), cText)
     ::nCol    += Int(len(cText))
     * by Digao     ::nCol    += Int(len(cText)/1.7+.5)
     ::Command(::cNormal)

RETURN NIL

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

METHOD ZeraBuffer() CLASS TDosPrn

    /* // Em Ingles
    ::LastError := 0

    If ::lZeraBuffer
        IF fWrite(::hDC, ::cBuffer) < len(::cBuffer)
                ::LastError := fError()
        ENDIF
        ::cBuffer := ""
    Endif
    */


    // Em Clipper Puro Como ‚!
    Self:LastError := 0

    If Self:lZeraBuffer
        IF fWrite(Self:hDC, Self:cBuffer) < len(Self:cBuffer)
             Self:LastError := fError()
        ENDIF
        Self:cBuffer := ""
    Endif

RETURN NIL

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

FUNCTION WorkSheet(cPort)

     LOCAL oPrn
     LOCAL cLine
     LOCAL nFor

     cLine := ""

     FOR nFor := 0 TO 7
          cLine += Str(nFor,1)+Replicate(".",9)
     NEXT

     cLine := Substr(cLine,3)

     oPrn := TDosPrn():New(cPort)

     oPrn:StartPage()

     //alterei em 29/03/2004
     FOR nFor := 0 TO  56 //65
          oPrn:Say(nFor,0,StrZero(nFor,2)+cLine)
     NEXT

     oPrn:EndPage()

     oPrn:End()

RETURN NIL

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

METHOD PrintFile(cFile) CLASS TDosPrn

     LOCAL hFile
     LOCAL nRead
     LOCAL cBuffer

     hFile := FOpen(cFile, FO_READ)

     IF hFile < 0
          RETURN .F.
     ENDIF

     cBuffer := Space(PF_BUFLEN)

     DO
          nRead := fRead(hFile, @cBuffer, PF_BUFLEN)

          IF fWrite(::hDC, Left(cBuffer, nRead)) < nRead
               ::LastError := fError()
               fClose(hFile)
               RETURN .F.
          ENDIF
     UNTIL nRead == PF_BUFLEN

     fClose(hFile)

RETURN .T.

//----------------------------------------------------------------------------//
// Visualiza Processo de impressao                 // Ednaldo
//----------------------------------------------------------------------------//
METHOD ShowProc() CLASS TDosPrn                  

     IF ::oWnd = Nil
                   
*        DEFINE DIALOG ::oWnd TITLE "Imprimindo ..."  ;
*               FROM  230, 217 TO 360, 575 PIXEL ;
*               COLORS CLR_BLACK, nRGB(193,205,205)
*        
*        @ 10, 08 TO 40, 172 OF ::oWnd PIXEL
*
*        @ 1.4, 2 ICON NAME "PRINT.ICO" OF ::oWnd
*        
*        @ 25, 35  SAY "Imprimindo Página :"  ;
*                  PIXEL OF ::oWnd SIZE 70, 12  RIGHT
*
*        @ 25, 107 SAY ::oPagina VAR ::nPage  ;
*                  PIXEL OF ::oWnd UPDATE SIZE 15, 12 RIGHT
*
*        @ 47, 60 BUTTON "Aguarde..." SIZE 60, 12 ;
*                 PIXEL  OF ::oWnd  ACTION .t.
*
*        ::oWnd:bPainted := {|| iif(::nPage>0, ::oPagina:Refresh(), )}
*
*        ACTIVATE DIALOG ::oWnd CENTER NOWAIT
*
*        EndDialog()
        ResAllFree()

        CursorWait()
        SysRefresh()

     ELSE

        ::oWnd:BeginPaint()
        ::oWnd:Paint()
        ::oWnd:EndPaint()

     ENDIF

RETURN NIL

// Fim do Programa.
 


Saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Ejemplo TdosPrn

Postby TOTOVIOTTI » Wed Aug 17, 2016 7:38 pm

Gracias!!
Univ@c I.S.I.
Desarrolladores de Software
http://www.elcolegioencasa.edu.ar
User avatar
TOTOVIOTTI
 
Posts: 387
Joined: Fri Feb 05, 2010 11:30 am
Location: San Francisco - Córdoba - Argentina

Re: Ejemplo TdosPrn

Postby LuisPonce » Thu Aug 18, 2016 4:01 am

Hola Roberto

Aunque ya te pasaron unos buenos ejemplos, te alcanzo uno mas,,, que nunca esa demas

Esta es la cabecera de la clase:

ÚÄ Programa ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
³ Aplication: Class TDosPrint ³
³ File: TDOSPRN.PRG ³
³ Author: Ignacio Ortiz de Z£¤iga Echeverr¡a ³
³ CIS: Ignacio Ortiz (Ignacio_Ortiz) ³
³ Internet: http://ourworld.compuserve.com/homepages/Ignacio_Ortiz ³
³ Date: 09/13/96 ³
³ Time: 20:20:07 ³
³ Copyright: 1997 by Ortiz de Zu¤iga, S.L. ³
ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

NOTES:

This peace of software is freeware and is not part of FiveWin.

The following code will let you print directly to the printer from inside
any Fivewin program, like OLD DOS days. Those users that need DOS printing
speed can use this class instead of the TPrinter class.

The use of the class is very easy and is very similar to the TPrinter class
of Fivewin, but we have not create any command to avoid the use of any
static vars.

This is a little sample of how to use the new class:

LOCAL oPrn

oPrn := TDosPrn():New("lpt1")

oPrn:Say(10,20, "This goes in line 10, column 20")
oPrn:EndPage() // optional

oPrn:End()

A little description of all the members of this class:

DATA:

cPort: Printing port, by default "LPT1"
cCompress: String for compressed mode, by default "15"
cNormal: String for normal mode, by default "18"
cFormFeed: String for EJECT, by default "12"
hDC: Printing file Handle (Internal use)
nRow: Current printing row
nCol: Current pringing column
nLeftMargin: Left margin, by default 0
nTopMargin: Top margin, by default 0
lAnsiToOem: If .T. a Ansi to Oem translation is done automatically
whe printing, by default is .T.

METHODS:

New(cPort) Constructor, no comment
End() Destructor, no comment
EndPage() End of page, this method is optional if there is only on page
Command(c) Let you send any command to the printer without changing the
current row and col. The string to pass as a parameter should
content the ascii values of the command separated with commas,
for example, the command to reset Epson printers should
be: "27,69"
SetCoors(r,c) Let you change the current row and col is the equivalent of
SetPrc() of Ca-Clipper
NewLine() Increments the current row
Write(cText) Prints the string cText in the current row and column
Say(nRow ,; Prints the string cText in nRow, nCol
nCol ,; lAtoO indicates if the string should be transformed to Oem,
cText ,; by default is ::lAnsiToOem
lAtoO )
SayCmp() The same as the method Say but prints in compressed mode and
the row is updated accordly.

NOTE:

If you try to print on a row before the current one a EJECT will be
done automatically.

In the same way if you try to print on the same row as the current, but
in a previous column from the current one a EJECT will be done automatically

At the end of this class is a little function call WorkSheet that will make
the job of DOS printing a lot easier.

Enjoy it!


********************************************************************************
********************************************************************************

La Clase desarrollada originalmente por Ignacio Ortiz me ha resultado útil por
su sencillez y efectividad.

El único punto debil de esta clase se encuentra cuando el usuario manda a imprimir
y la impresora no está lista (sea cual sea la causa). Esto hace que FiveWin capture
el error, saltando sobre cualquier manejador de error que el programador defina,
y mostrando esa horrorosa ventana blanca que ya todos conocemos.
Si el usuario resuelve el problema de la impresora (sigo hablando de cuando aparece
la horrorosa ventana blanca), la impresión se realiza, pero a la final el programa
termina explotando igual.

Ahora les presento algunas modificaciones que le realizado a esta clase con la idea
que la impresión se realice directamente en los puertos físicos de la impresora,
emulando (en cierta forma) la función que realiza el ROM BIOS, y buscando evitar que
el manejador de errores se adelante en situaciones como la que les comenté en el
parrafo enterior.

La idea es que hagan todas las pruebas posibles para pulirla, y dejarle abierta a Uds.
la posibilidad de manejar los eventuales errores de acuerdo a la necesidad particular
de cada quien.

Este trabajo ES GRATIS!. Lo único que les pido es que no borren este comentario, ni la
documentación anexa, ni los comentarios intercalados en los lugares donde se han realizado
las modificaciones.

En mi caso real, utilizo esta misma clase, pero la que ha sido modificada por el
compañero Jose E. Serrano E. (JESE), quien le añadió algunas características más,
pero manteniendo la misma estructura de la clase original de Ignacio.
Cuando estas modificaciones funcionen sin inconvenientes, las transferiré a la clase
modificada por JESE.

Un Abrazo a todos,
y que les sea útil

Giancarlo J. Sabattino S.
08 Julio 2001
gsabattino@cantv.net


Este trabajo se lo dedico a los compañeros Hernán D. Cecarrelli, José E. Serrano E. (JESE),
Juan José Machado, y a Willy Quintana.


NOTAS IMPORTANTES:

Esta clase está orientada totalmente a impresoras matriciales, o impresoras que se comporten
como impresores matriciales, por lo que su uso en cualquier otro tipo de impresora puede
causar resultados indeseados.

Esta clase trabaja directamente sobre los puertos PRN, LPT1 y LPT2 que existan físicamente en el
equipo, por lo que no funcionará en ningún otro tipo de dispositivo. Para mantener compatibilidad,
se puede pasar un nombre de archivo para grabar la impresión en disco tal como lo hace la clase
original.

En teoría, no debe ser activada si alguna aplicación Windows se encuentra haciendo uso de la
misma impresora que se desea utilizar. Yo no he intentado utilizarla de esta forma, pero la
lógica me dice que los resultados serán totalmente impredecibles.


y este es el ejemplo:

Code: Select all  Expand view
     oPrnCmp:=TDosPrn():New(cFilPrn)    // oPrnCmp:=TDosPrn():New("luis.prn")
      oPrnCmp:Command( { 27, 64 } )

      oPrnCmp:Say( nRow, 00, PADC("CIERRE DE TURNO ",40), nCompress )
       nRow++
      oPrnCmp:Say( nRow, 00, Repl("-",40), nCompress )
       nRow ++
      oPrnCmp:Say( nRow, 00, "Rango: "+TRIM(cRango), nCompress )
       nRow++
      oPrnCmp:Say( nRow, 00, "Zona : "+TRIM(cNomIsla), nCompress )
       nRow++
      oPrnCmp:Say( nRow, 00, "Turno: "+TRIM(cNomTurno), nCompress )
       nRow++

      oPrnCmp:Say( nRow, 00, Repl("-",40), nCompress )
       nRow ++
      oPrnCmp:Say( nRow, 00, PADC("Vendedor: "+cVendedor+" "+cNomVen,40), nCompress )
       nRow++
      oPrnCmp:Say( nRow, 00, Repl("-",40), nCompress )
       nRow ++


      FOR G=1 TO LEN(aTitGrupo)

        oPrnCmp:Say( nRow, 00, aTitGrupo[G][2] , { nCompress } )
         nRow ++

      NEXT

      oPrnCmp:Say( nRow, 00, Repl("-",40), nCompress )
       nRow ++
      oPrnCmp:Say( nRow, 00, mmInicial+DTOC(DATE())+" - "+TIME(), { nCompress } )
      oPrnCmp:Say( nRow, 28, TRANS(nTotalRep,MA72C), { nCompress } )
       nRow ++
       nRow+=7
      oPrnCmp:Say( nRow, 00, chr(27) + chr(105) , nCompress )  // Corte Parcial

      oPrnCmp:EndPage()
      oPrnCmp:End()

      PrintFileRaw( cLptDoc, cFilPrn )    // PrintFileRaw( "\\CAJA01\TICKET", "luis.prn" )
 



lo uso a partir de una clase modificada por Giancarlo J. Sabattino S. (08-07-2001), lo que me agrada es que el command() recibe un array, tambien genera un archivo.prn que puedes direccionar a cualquier impresora, local o en red
Luis Ponce
User avatar
LuisPonce
 
Posts: 192
Joined: Tue Jul 01, 2008 6:34 pm
Location: PERU

Re: Ejemplo TdosPrn

Postby TOTOVIOTTI » Thu Aug 18, 2016 12:20 pm

Gracias!
Ahora si lo pude hacer funcionar!

Me queda una pequeña cosita por resolver... habrá forma de determinar
si la impresora a la que deseo mandar mi impresión es Láser o Chorro a Tinta o
Matriz de Puntos?

Estuve viendo que Cristóbal nombró la PRTINFO de VisualFox, pero no puedo
encontrar fuentes de eso para ver como se puede determinar desde FW el
tipo de tracción de la impresora seleccionada...

Muchas gracias!
Roberto
Univ@c I.S.I.
Desarrolladores de Software
http://www.elcolegioencasa.edu.ar
User avatar
TOTOVIOTTI
 
Posts: 387
Joined: Fri Feb 05, 2010 11:30 am
Location: San Francisco - Córdoba - Argentina

Re: Ejemplo TdosPrn

Postby karinha » Thu Aug 18, 2016 1:47 pm

Luis, puede muestrar:

Code: Select all  Expand view

   cLptDoc

   y

   cFilPrn
 


Gracias, saludos.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Ejemplo TdosPrn

Postby TOTOVIOTTI » Thu Aug 18, 2016 1:51 pm

Joao:
Esos datos son del programa de Luis o de la consulta que hago yo?
Roberto
Univ@c I.S.I.
Desarrolladores de Software
http://www.elcolegioencasa.edu.ar
User avatar
TOTOVIOTTI
 
Posts: 387
Joined: Fri Feb 05, 2010 11:30 am
Location: San Francisco - Córdoba - Argentina

Re: Ejemplo TdosPrn

Postby karinha » Thu Aug 18, 2016 2:25 pm

Del programa de Luis, creo que el tien que muestrar un código más completo, para que cuando sea un novato, comprenda mejor.

Saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Ejemplo TdosPrn

Postby LuisPonce » Thu Aug 18, 2016 2:52 pm

Joao, Roberto

cLptDoc:="luis.prn"
cFilPrn:="\\CAJA01\TICKET"

cLptDoc; es una variable LOCAL que contiene el nombre del file que generará la TDOSPRN, en este caso genera un file "luis.prn"

cFilPrn; es otra variable LOCAL que contiene la ruta y nombre de la impresora a la cual enviaré el reporte

Con esta instruccion:

Code: Select all  Expand view
PrintFileRaw( cLptDoc, cFilPrn )    // PrintFileRaw( "\\CAJA01\TICKET", "luis.prn" )


Envio el reporte "luis.prn" a la impresora "\\CAJA01\TICKET" (Impresora nombrada como "TICKET" en el equipo de nombre "CAJA01"); ambas variables del codigo, estan comentadas "//" en el ejemplo que publiqué

Ademas de corte parcial que va en el ejemplo, tambien hay un comando para abrir el cajon del dinero mediante el puerto RJ11 de la impresora, alguien sabe cual es ese comando?? y la paridad del cableado?.

Saludos
Last edited by LuisPonce on Thu Aug 18, 2016 3:01 pm, edited 1 time in total.
Luis Ponce
User avatar
LuisPonce
 
Posts: 192
Joined: Tue Jul 01, 2008 6:34 pm
Location: PERU

Re: Ejemplo TdosPrn

Postby karinha » Thu Aug 18, 2016 3:01 pm

Gracias Luis, perfecto.

Saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7214
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 82 guests