PDA

View Full Version : need tips on code for print webcomponent


ABC123

randbo
04-04-2007, 01:38 AM
The below is a webcomponent for printing some reports I used the demo code from "WebContactList":, The only extra feature I wanted to add was the choice of HTML or PDF output. what code needs to be entered to add this extra choice?

Your help is appreciated. If you need me to provide more info, just let me know. Thanks.


ContactType: All or Individual
OutputType: HTML or PDF [this choice doesn't work yet, need code]
ContactList: <list of contacts>
ReportList: <list of reports>
PRINT
-------------------below form properties after validate code------------


collections = alltrim(CurrentForm.Controls.ContactList)
report = alltrim(CurrentForm.Controls.ReportList)
if CurrentForm.Controls.ContactType = "1" then
dim filter as c
dim order as c
Filter = ".T."
Order = "Collection_status+str(Current_balance,19,5)"
Dim filename as c
filename = session.session_folder + "tempreport.pdf"
filename = report.saveas(report,"pdf",filter,order,filename,.f.)
if file.exists(filename)
currentform.RedirectTarget = session.session_url + "tempreport.pdf?" + time("hms3")
end if
else
IF eval_valid("collections") = .f. Then
goto skipreport
end if
dim filter as c
dim order as c
Filter = "Collections_id = \""+collections+"\""
Order = ""
Dim filename as c
filename = session.session_folder + "tempreport.pdf"
filename = report.saveas(report,"pdf",filter,order,filename,.f.)
if file.exists(filename)
currentform.RedirectTarget = session.session_url + "tempreport.pdf?" + time("hms3")
end if
skipreport:

end if

Steve Wood
04-04-2007, 02:06 AM
This non-elegant example code should get you there. If you toggle the value for repext from "PDF" to "HTML" it controls the output format.


dim filter as c
dim order as c

dim rep as c
repext = "html"
rep = quote(repext)

Filter = ".T."
Order = ""
Dim filename as c
filename = session.session_folder + "tempreport."+repext
filename = report.saveas("entry_log@[PathAlias.ADB_Path]\web_actions.ddd",rep,filter,order,filename,.f.)
if file.exists(filename)
currentform.RedirectTarget = session.session_url + "tempreport."+repext + "?" + time("hms3")
end if

randbo
04-04-2007, 12:39 PM
Steve, thanks, sorry, I may missunderstand how this should be pasted into the code. I know that [repext = "html"] but shouldn't there be a "pdf" reference also? feel like I'm butchering your code. Sorry

Don't I need something like the following:

With outputtype being the toggle between pdf and html?.


rep = alltrim(CurrentForm.Controls.OutputType)

dim rep as c
repext = "html"
rep = quote(repext)

I pasted your code where I thought it should go, but, it's either missing a "if - end if" statement or something. I'm sorry. The modified code is below:
-----------------------------------------------------
collections = alltrim(CurrentForm.Controls.ContactList)
report = alltrim(CurrentForm.Controls.ReportList)


if CurrentForm.Controls.ContactType = "1" then
dim filter as c
dim order as c
dim rep as c
repext = "html"
rep = quote(repext)
Filter = ".T."
Order = "Collection_status+str(Current_balance,19,5)"
Dim filename as c
filename = session.session_folder + "tempreport."+repext
filename = report.saveas(report,rep,filter,order,filename,.f.)
if file.exists(filename)
currentform.RedirectTarget = session.session_url + "tempreport."+repext + "?" + time("hms3")
end if
else
IF eval_valid("collections") = .f. Then
goto skipreport
end if
dim filter as c
dim order as c
dim rep as c
repext = "html"
rep = quote(repext)
Filter = "Collections_id = \""+collections+"\""
Order = ""
Dim filename as c
filename = session.session_folder + "tempreport."+repext
filename = report.saveas(report,rep,filter,order,filename,.f.)
if file.exists(filename)
currentform.RedirectTarget = session.session_url + "tempreport."+repext + "?" + time("hms3")
end if
skipreport:

end if

Steve Wood
04-04-2007, 01:21 PM
Yes, you'd pull the setting for the report type outside the rest of your code. An example assuming you are using a control on your dialog to determine html or pdf:


if CurrentForm.Controls.ReportType = "HTML"
repext = "html"
else
repext = "pdf
end if

if CurrentForm.Controls.ContactType = "1" then
dim filter as c
dim order as c
dim rep as c
rep = quote(repext)
Filter = ".T."
Order = "Collection_status+str(Current_balance,19,5)"
Dim filename as c
filename = session.session_folder + "tempreport."+repext
filename = report.saveas(report,rep,filter,order,filename,.f.)
if file.exists(filename)
currentform.RedirectTarget = session.session_url + "tempreport."+repext + "?" + time("hms3")
end if
...rest of your code

Or your "IF" statement could just be:


repext = CurrentForm.Controls.ReportType

The reason for the quote(repext) is to put quotes around the value, which is what the report.saveas() is looking for.

randbo
04-04-2007, 03:21 PM
Thanks Steve, I'm going to see if I can make this work. I noticed your online webex's, will try to make the upcoming events. Sounds like they are very informative.

AaronBBrown
04-04-2007, 03:27 PM
Rand,

Just for reference, you might be interested in the following article that I wrote on how to put formatted code into message board posts.

Code Blocks (http://msgboard.alphasoftware.com/alphaforum/showthread.php?t=57348)

Aaron

randbo
04-05-2007, 01:10 AM
Steve, I think I did what you said, it works only for the PDF, not the HTML

Any idea what I've missed? Thanks for your help with this.



collections = alltrim(CurrentForm.Controls.ContactList)
report = alltrim(CurrentForm.Controls.ReportList)
repext = CurrentForm.Controls.OutputType

if CurrentForm.Controls.OutputType = "HTML"
repext = "html"
else
repext = "pdf"
end if

if CurrentForm.Controls.ContactType = "1" then
dim filter as c
dim order as c
dim rep as c
rep = quote(repext)
Filter = ".T."
Order = "Collection_status+str(Current_balance,19,5)"
Dim filename as c
filename = session.session_folder + "tempreport."+repext
filename = report.saveas(report,rep,filter,order,filename,.f.)
if file.exists(filename)
currentform.RedirectTarget = session.session_url + "tempreport."+repext + "?" + time("hms3")
end if
else
IF eval_valid("collections") = .f. Then
goto skipreport
end if
dim filter as c
dim order as c
dim rep as c
rep = quote(repext)
Filter = "Collections_id = \""+collections+"\""
Order = ""
Dim filename as c
filename = session.session_folder + "tempreport."+repext
filename = report.saveas(report,rep,filter,order,filename,.f.)
if file.exists(filename)
currentform.RedirectTarget = session.session_url + "tempreport."+repext + "?" + time("hms3")
end if
skipreport:

end if

randbo
04-05-2007, 01:13 AM
the error I recieve when I select HTML is the following:


404 Not Found
The requested URL /session_folders/a51659df89554ca89f160810ebfb34b5/tempreport.html was not found on this server.

Steve Wood
04-05-2007, 01:47 AM
Maybe your CurrentForm.Controls.OutputType never equals "HTML". Find out and fix it if so. I tried your IF statement using a DropDownBox for OutputType control, and that worked (properly set repext).

Look in your session folder to see if a file is generated, but perhaps with a wrong name, resulting in it not being found. Maybe its being saved as .htm, although it uses .html in my tests.

There would be no need for the repext = CurrentForm.Controls.OutputType
statement if the IF statement is working.