Custom Papersize Report Foxpro (II)

Bagian 2 hehe, langsung aja yaa, jadi ceritanya ada client yang mempunya standar ukuran kertas na klo 1 client ga apa apa bisa didatangin bagaimana klo banyak client, dengan standar berbeda repot dah engkau😀, alternatif kita bikin custom secara programing reportnya dengan foxpro, langsung aja nih

pertama bikin report(pastinya), selanjtunya bikin program (.prg) dengan nama newpaper.prg, selanjutnya bikin procedure dengan nama customPaper dan Idpaper


Procedure customPaper(lcNamaPaper)
Local hPrinter
Local cPrinterName, cPaperName
Local pPaperName, sPaperSize
Local nResult, nBufLen, nPaperWidth, nPaperHeight

Declare Long GetLastError In Kernel32
Declare Long ClosePrinter In WinSpool.Drv Long hPrinter
Declare Long OpenPrinter In WinSpool.Drv ;
String cPrinterName, Long @O_hPrinter, Long pDefault

Declare Long GetForm In WinSpool.drv As GetPrinterForm ;
Long hPrinter, String pFormName, ;
Long nLevelInfo, String @O_pFormInfo, ;
Long nBufSize, Long @O_nBufNeeded

Declare Long AddForm In WinSpool.drv As AddPrinterForm ;
Long hPrinter, Long nLevelInfo, String @pFormInfo

Declare Long LocalAlloc In Kernel32 Long uFlags, Long dwBytes
Declare Long LocalFree In Kernel32 Long Hmem

cPrinterName = Set( 'Printer', 2 ) && Get default Windows printer
hPrinter = 0

If (OpenPrinter( cPrinterName, @hPrinter, 0 ) != 0)
cPaperName = lcNamaPaper
nBufLen = 32 && FORM_INFO_1_Size
cInfo = Replicate( Chr(0), 32 )
nResult = GetPrinterForm( hPrinter, cPaperName, 1, ;
@cInfo, nBufLen, @nBufLen )

If (nResult == 0) && Get printer form failed
nResult = GetLastError()

If (nResult == 1902) && ERROR_INVALID_FORM_NAME
** Custom Printer Form not exist, add the new one
nPaperWidth =22000 / 2 && Paper size is in 1/1000 millimeters
nPaperHeight =317000 / 2

sPaperSize = BinToC( nPaperWidth, '4rs' ) + BinToC( nPaperHeight, '4rs' )
pPaperName = LocalAlloc( 64, 32 )

If (pPaperName != 0)
Sys( 2600, pPaperName, Len( cPaperName ), cPaperName )
cInfo = BinToC( 0, '4rs' ) + BinToC( pPaperName, '4rs' ) + ;
sPaperSize + BinToC( 0, '4rs' ) + BinToC( 0, '4rs' ) + sPaperSize

If (AddPrinterForm( hPrinter, 1, cInfo ) != 0)
? 'Custom paper form (' + cPaperName + ') has been added! '
Else
? 'Error:', GetLastError()
Endif

LocalFree( pPaperName )
Endif

Else
If (nResult == 122) && Insufficient buffer
? 'Error: Custom Paper Form already exist!'
Else
? 'Error: ', nResult
Endif
Endif
Else
? 'Error: ', nResult
Endif
ClosePrinter( hPrinter )
Endif
Endproc

 

Procedure Idpaper(lcNamaPaper)
#Define DC_PAPERS 2
#Define DC_PAPERS_Size 2
#Define DC_PAPERNAMES 16
#Define DC_PAPERNAMES_Size 64
Declare Long DeviceCapabilities In WinSpool.drv ;
String cPrinterName, String cPort, Short nCapFlags, ;
String @O_cBuffer, Long pDevMode

Local Array la_Printer[1]
Local ln_Row, ln_Result, ln_I, ln_Index
Local lc_PrinterName, lc_Buffer
Local lc_FindPaperName, lc_PaperName, lc_PaperSizeID
lc_PrinterName = Set( 'Printer', 2 ) && Get default windows printer
= Aprinters( la_Printer )
ln_Row = Ascan( la_Printer, lc_PrinterName, 1, 0, 0, 9 )
ln_Result = DeviceCapabilities( la_Printer[ ln_Row, 1 ], ;
la_Printer[ ln_Row, 2 ], DC_PAPERNAMES, 0, 0 )
If (ln_Result > 0)
ln_Index = -1
lc_FindPaperName = Upper(lcNamaPaper)
lc_Buffer = Replicate( Chr(0), ln_Result * DC_PAPERNAMES_Size )
ln_Result = DeviceCapabilities( la_Printer[ ln_Row, 1 ], ;
la_Printer[ ln_Row, 2 ], DC_PAPERNAMES, @lc_Buffer, 0 )
For ln_I = 0 To ln_Result-1
lc_PaperName = Upper( Substr( lc_Buffer, (ln_I * DC_PAPERNAMES_Size )+1, ;
DC_PAPERNAMES_Size ))
If (lc_FindPaperName $ lc_PaperName)
ln_Index = ln_I
Exit
Endif
Next
If (ln_Index != -1)
** Paper Name found, Get The PaperSize ID
ln_Result = DeviceCapabilities( la_Printer[ ln_Row, 1 ], ;
la_Printer[ ln_Row, 2 ], DC_PAPERS, 0, 0 )
If (ln_Result > 0)
lc_Buffer = Replicate( Chr(0), ln_Result * DC_PAPERS_Size )
ln_Result = DeviceCapabilities( la_Printer[ ln_Row, 1 ], ;
la_Printer[ ln_Row, 2 ], DC_PAPERS, @lc_Buffer, 0 )
lc_PaperSizeID = Substr( lc_Buffer, (ln_Index * DC_PAPERS_Size )+1, DC_PAPERS_Size )

* ? 'PaperSize ID for "' + lc_FindPaperName + '" is', CToBin( lc_PaperSizeID, '2rs' )
Endif
Endif
ENDIF
RETURN CToBin( lc_PaperSizeID, '2rs' )
Endproc

procedure custompaper digunakan untuk setting ukuran kertas makanya ada widht dan height paper, dan idpaper adalah id unix yang dihasilkan dari create custompaper tadi, naa ID paper ini yang nanti akan di replace kedalam report(.frx) info lengkapnya bisa baca disini https://rubahmania.wordpress.com/2016/05/20/custom-pagesize-report-foxpro/

cara memakainya gampang aja

report awal, adalah legal, idpapernya 5

1

selanjutnya coba bikin script di program


Clea
lcNamaPaper='MyCustom - Half A4'
customPaper(lcNamaPaper)
lnPagesize=Idpaper(lcNamaPaper)
?lnPagesize
update tbreport SET nPagesize = lnPagesize WHERE idUser='001'

naa nanti report akan terbentung dengan nama MyCustom – Half A4 dengan widht 22000 dan height 317000 ,

btw hitungan lebar panjang kertas adalah dari milimeter ke inci yang mana 1 milimiter = 0,0393701 inci , baca baca lah ntr paham kq, ok jalankan script diatas, hasilanya

1

dan liat di print setup,

Untitled

kertas dengan nama MyCustom terbentuk , jadi deh😀

hasilnya,User A (001)

1

sedangkan User B

1

[edit]

penggunaan di form begini,

Capture

di set dulu procedure newpaper.prg di program main🙂

2

baru deh runningkan formnya hasilnya sama diatas

Ref :

http://hermantan.blogspot.co.id/

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: