written report with customized content, records changes

You can share your experience with HMG. Share with some screenshots/project details so that others will also be benefited.

Moderator: Rathinagiri

Post Reply
User avatar
nguyenchiduc
Posts: 78
Joined: Sat Nov 13, 2010 7:27 am

written report with customized content, records changes

Post by nguyenchiduc »

Hi all

I have written a report for my job. Content changes according to records, and form requested by my boss. I'm happy because HMG3 have done.

You can also write a report specific to your job.

Note: need to align the coordinates of @ x, y of the PRINT command to display exactly as required. Write the command to automatically loop when new page

Code: Select all

/* commands*/
select database
select printer default preview

START PRINTDOC
    START PRINTPAGE

    DO WHILE. NOT. EOF()
       IF test == .T.
           START PRINTPAGE

           @x,y  print "...content..."
       ELSE
    
          @x,y  print "...content..."

           END PRINTPAGE
       ENDIF
    ENDDO

   /* commands*/

   @x,y  print "...content..."
   END PRINTPAGE

END PRINTDOC
Below is screenshot:

Example 1 :

Image

Example 2 :

Image

Image

Image
User avatar
nguyenchiduc
Posts: 78
Joined: Sat Nov 13, 2010 7:27 am

Re: written report with customized content, records changes

Post by nguyenchiduc »

You also can export from .dbf to .html file and write, draw something in.
Example : export from .dbf file to c:\temp\Export.html

Code: Select all

#include "hmg.ch"
#include "Fileio.ch"

FUNCTION MAIN
  REQUEST DBFCDX
  
  get_file()    
  
  DEFINE WINDOW Main_form AT 1,1 WIDTH 2 HEIGHT 2 MAIN 
  END WINDOW  
RETURN

PROCEDURE get_file()
  LOCAL dbf_file := '' , message := '' , fields_total := 0

	dbf_file := Getfile ( { {'.dbf Files','*.dbf'} } , 'Export from .dbf to .html' , 'c:\' , .f. , .t. )
	USE &dbf_file alias database SHARED NEW via "DBFCDX"
	fields_total := fcount() 
	
  IF (nHandle := FCREATE("c:\temp\Export.html", FC_NORMAL)) == -1
	   message := "File " + "c:\temp\Export.html " + "cannot be created:" + FERROR()
     MsgExclamation(message,"File cannot be created" )
     QUIT
           
  ELSE
      message := "<HTML><BODY><CENTER><B>" 
      message := message + "EXPORT FROM " + dbf_file + " TO c:\temp\Export.html"
      message := message + "</B></CENTER><BR>"
      FWRITE(nHandle, message)

      message := "1) You can post something here...<BR>"
      FWRITE(nHandle, message)
      message := "2) You can post something here...<BR>"
      FWRITE(nHandle, message)
      message := "3) You can post something here...<BR>"
      FWRITE(nHandle, message)
      message := ".................................<BR><BR>"
      FWRITE(nHandle, message)
      
      FWRITE(nHandle, '<CENTER><TABLE BORDER=1>')
      
      message := ""

      FOR i := 1 to fields_total
        message := message + "<TD>" + FIELDNAME(i) + "</TD>"  
      NEXT
      message := "<TR>" + message + "</TR>" 
      FWRITE(nHandle, message)
      
      message := ""
      DO WHILE .NOT. EOF()
          FOR i := 1 to fields_total
            DO CASE
            CASE valtype(database->(FIELDGET(i))) == "C"
                message := message + "<TD>" + database->(FIELDGET(i)) + " </TD>"
            CASE valtype(database->(FIELDGET(i))) == "N"
                message := message + "<TD>" + str(database->(FIELDGET(i))) + " </TD>"    
            CASE valtype(database->(FIELDGET(i))) == "D"
                message := message + "<TD>" + DTOC(database->(FIELDGET(i))) + " </TD>"                                                         
            ENDCASE
                                 
         NEXT

         message := "<TR>" + message + "</TR>"
         
         FWRITE(nHandle, message)
         
         message := ""
         database->( DBSKIP() )         
      
      ENDDO
      
      message := "</TABLE></CENTER><BR>" 
      FWRITE(nHandle,message)                           
      
      message := "4) You can post something here...<BR>"
      FWRITE(nHandle, message)
      message := "5) You can post something here...<BR>"
      FWRITE(nHandle, message)
      message := "6) You can post something here...<BR>"
      FWRITE(nHandle, message)
            
      message := "</BODY></HTML>"
      FWRITE(nHandle,message)
      
      FCLOSE(nHandle)
      
      message := "EXPORT FROM " + dbf_file + " TO c:\temp\Export.html"       
      MSGBOX(message, 'EXPORT OK !')
      QUIT            
  ENDIF
  
RETURN

User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: written report with customized content, records changes

Post by esgici »

nguyenchiduc wrote:You also can export from .dbf to .html file and write, draw something in.
Thanks to sharing :)

By the way, does low-level file IO is mandatory and/or necessary :?:

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
User avatar
nguyenchiduc
Posts: 78
Joined: Sat Nov 13, 2010 7:27 am

Re: written report with customized content, records changes

Post by nguyenchiduc »

esgici wrote:Thanks to sharing :)

By the way, does low-level file IO is mandatory and/or necessary :?:

Regards

--

Esgici
Thank you
I only illustrate the vast capabilities of HMG that we have not fully exploited.

For example:

If we know the structure of files such as Excel, Pdf, Xml... we can import/export directly to the file .Dbf .

HMG and Apache webserver can be applied to the Web - CGI, based on the file .dbf or queries from the database such as Oracle, MySQL, MS SQL,...
Post Reply