Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CR 8.5 RDC VFP7 'Server has not yet been opened' error
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Crystal Reports
Divers
Thread ID:
00665637
Message ID:
00668287
Vues:
84
Thank you for your help. I created a .dll file to handle the crystal reports printing and exporting. Please excuse my inelegant coding and wide format. I used an API call in the .dll to alert users of errors (I'm a News2News.com member and I like their API calls) since the VFP MessageBox won't work in a .dll file. The .dll is registering fine and working fine on our Windows 2000 workstations but won't even register on the &*(*(! Windows 98 machines...






***************************************************************************************************************
***************************************************************************************************************
****** CLASS CrystalRun ***************************************************************************************
***************************************************************************************************************
***************************************************************************************************************

DEFINE CLASS CrystalRun as session olepublic

***************************************************************************************************************
**** ExportToFile *********************************************************************************************
***************************************************************************************************************

PROCEDURE ExportToFile(tcCrystalReportName as String, ;
tcDBFName as String, ;
tnDestinationType as Integer, ;
tcDownName as String)

#INCLUDE VFPCrystal.h

PUBLIC goCr as CRYSTALRUNTIME.Application
PUBLIC goCrRpt as CRYSTALRUNTIME.Report
PUBLIC goCrData as CRYSTALRUNTIME.Database
PUBLIC goCrTables as CRYSTALRUNTIME.DatabaseTables
PUBLIC goCrExportOptions as CRYSTALRUNTIME.ExportOptions
PUBLIC goCrPrintingStatus as CRYSTALRUNTIME.PrintingStatus

IF VARTYPE(tcCrystalReportName) = "C"
tcCrystalReportName = ALLTRIM(tcCrystalReportName)
ENDIF VARTYPE(tcCrystalReportName) = "C"

IF VARTYPE(tcDBFName) = "C"
tcDBFName = ALLTRIM(tcDBFName)
ENDIF VARTYPE(tcDBFName) = "C"

IF VARTYPE(tcDownName) = "C"
tcDownName = ALLTRIM(tcDownName)
ENDIF VARTYPE(tcDownName) = "C"

IF VARTYPE(tcCrystalReportName) # "C" OR EMPTY(ALLTRIM(tcCrystalReportName))
=NewMsgBox ("No Crystal Report was Defined.", "No Report.",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF VARTYPE(tcCrystalReportName) # "C" OR EMPTY(ALLTRIM(tcCrystalReportName))

IF NOT ".RPT" $ UPPER(tcCrystalReportName)
tcCrystalReportName = tcCrystalReportName + ".RPT"
ENDIF NOT ".RPT" $ UPPER(tcCrystalReportName)

IF NOT FILE(tcCrystalReportName)
=NewMsgBox ("Unable to Find Report " + tcCrystalReportName, "Not Found",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF NOT FILE(cCrystalReportName)

IF VARTYPE(tcDBFName) # "C" OR EMPTY(ALLTRIM(tcDBFName))
=NewMsgBox ("No DBF File was Selected.","No DBF File.",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF VARTYPE(tcDBFName) # "C" OR EMPTY(ALLTRIM(tcDBFName))

IF NOT ".DBF" $ UPPER(tcDBFName)
tcDBFName = tcDBFName + ".DBF"
ENDIF

IF NOT FILE(tcDBFName)
=NewMsgBox ("Unable to Find DBF " + tcDBFName,"Not Found.",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF NOT FILE(tcDBFName)

IF VARTYPE(tnDestinationType) # "N" OR NOT PADL(ALLTRIM(STR(tnDestinationType,2,0)),2,"0") $ ;
"01|02|03|04|05|06|07|08|09|10|11|12|13|14|18|19|20|21|22|24|27|28|29|30|31|32|33|34|35|36"
=NewMsgBox ("No Valid Export File Type was Selected.","No Export Type.",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF

IF VARTYPE(tcDownName) # "C" OR EMPTY(ALLTRIM(tcDownName))
=NewMsgBox ("No Output File was Selected.","No Output File.",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF VARTYPE(tcDownName) # "C" OR EMPTY(ALLTRIM(tcDownName))

tcDownName = ALLTRIM(ADDBS(JUSTPATH(tcDownName))) + ;
ALLTRIM(JUSTSTEM(tcDownName)) + ;
"." + ;
ALLTRIM(CheckDownExt(tnDestinationType))

* Create the CR Application Object
goCr = CREATEOBJECT("CrystalRuntime.Application")
IF VARTYPE(goCr) # "O"
=NewMsgBox ("Error Creating CrystalRuntime.Application","Creation Error",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF VARTYPE(goCr) # "O"

goCrRpt = goCr.OpenReport(tcCrystalReportName)
IF VARTYPE(goCrRpt) # "O"
=NewMsgBox ("Error Opening " + tcCrystalReportName,"Error Opening Report.",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF VARTYPE(goCrRpt) # "O"

goCrRpt.UseIndexForSpeed= .F.
goCrRpt.DiscardSavedData()
goCrRpt.MorePrintEngineErrorMessages= .T.
goCrRpt.DisplayProgressDialog= .F.
goCrRpt.EnableParameterPrompting= .F.
*** goCrRpt.PaperOrientation
*** goCrRpt.PaperSize

goCrData = goCrRpt.Database

IF VARTYPE(goCrData) # "O"
=NewMsgBox ("Error Creating goCrData","Error Creating goCrData",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF VARTYPE(goCrData) # "O"

goCrTables = goCrData.Tables

IF VARTYPE(goCrTables) # "O"
=NewMsgBox ("Error Creating goCrTables","Error Creating goCrTables",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF VARTYPE(goCrTables) # "O"

goCrTables.Item(1).Location = tcDBFName && e.g. "I:\AUTOREP\ACTIVITY.DBF"

llConnected=goCrTables.Item(1).TestConnectivity()

IF NOT llConnected
=NewMsgBox ("Unable to Connect to Table " + tcDBFName,"Unable to Connect",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF NOT llConnected

goCrRpt.ReadRecords()

goCrExportOptions = goCrRpt.ExportOptions
goCrExportOptions.DestinationType= crEDTDiskFile
goCrExportOptions.FormatType= tnDestinationType && crEFTPortableDocFormat
goCrExportOptions.PDFExportAllPages= .T.
goCrExportOptions.DiskFileName= tcDownName && "c:\temp\tammi.pdf"

goCrRpt.Export(.F.)

=TakeOutTheGarbage()

ENDPROC && ExportToFile

***************************************************************************************************************
**** PrintReport **********************************************************************************************
***************************************************************************************************************

PROCEDURE PrintReport(tcCrystalReportName as String, ;
tcDBFName as String)

#INCLUDE VFPCrystal.h

PUBLIC goCr as CRYSTALRUNTIME.Application
PUBLIC goCrRpt as CRYSTALRUNTIME.Report
PUBLIC goCrData as CRYSTALRUNTIME.Database
PUBLIC goCrTables as CRYSTALRUNTIME.DatabaseTables
PUBLIC goCrExportOptions as CRYSTALRUNTIME.ExportOptions
PUBLIC goCrPrintingStatus as CRYSTALRUNTIME.PrintingStatus

IF VARTYPE(tcCrystalReportName) = "C"
tcCrystalReportName = ALLTRIM(tcCrystalReportName)
ENDIF VARTYPE(tcCrystalReportName) = "C"

IF VARTYPE(tcDBFName) = "C"
tcDBFName = ALLTRIM(tcDBFName)
ENDIF VARTYPE(tcDBFName) = "C"

IF VARTYPE(tcCrystalReportName) # "C" OR EMPTY(ALLTRIM(tcCrystalReportName))
=NewMsgBox ("No Crystal Report was Defined.", "No Report.",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF VARTYPE(tcCrystalReportName) # "C" OR EMPTY(ALLTRIM(tcCrystalReportName))

IF NOT ".RPT" $ UPPER(tcCrystalReportName)
tcCrystalReportName = tcCrystalReportName + ".RPT"
ENDIF NOT ".RPT" $ UPPER(tcCrystalReportName)

IF NOT FILE(tcCrystalReportName)
=NewMsgBox ("Unable to Find Report " + tcCrystalReportName, "Not Found",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF NOT FILE(cCrystalReportName)

IF VARTYPE(tcDBFName) # "C" OR EMPTY(ALLTRIM(tcDBFName))
=NewMsgBox ("No DBF File was Selected.","No DBF File.",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF VARTYPE(tcDBFName) # "C" OR EMPTY(ALLTRIM(tcDBFName))

IF NOT ".DBF" $ UPPER(tcDBFName)
tcDBFName = tcDBFName + ".DBF"
ENDIF

IF NOT FILE(tcDBFName)
=NewMsgBox ("Unable to Find DBF " + tcDBFName,"Not Found.",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF NOT FILE(tcDBFName)

* Create the CR Application Object
goCr = CREATEOBJECT("CrystalRuntime.Application")
IF VARTYPE(goCr) # "O"
=NewMsgBox ("Error Creating CrystalRuntime.Application","Creation Error",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF VARTYPE(goCr) # "O"

goCrRpt = goCr.OpenReport(tcCrystalReportName)
IF VARTYPE(goCrRpt) # "O"
=NewMsgBox ("Error Opening " + tcCrystalReportName,"Error Opening Report.",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF VARTYPE(goCrRpt) # "O"

goCrRpt.UseIndexForSpeed= .F.
goCrRpt.DiscardSavedData()
goCrRpt.MorePrintEngineErrorMessages= .T.
goCrRpt.DisplayProgressDialog= .F.
goCrRpt.EnableParameterPrompting= .F.
*** goCrRpt.PaperOrientation
*** goCrRpt.PaperSize

goCrData = goCrRpt.Database

IF VARTYPE(goCrData) # "O"
=NewMsgBox ("Error Creating goCrData","Error Creating goCrData",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF VARTYPE(goCrData) # "O"

goCrTables = goCrData.Tables

IF VARTYPE(goCrTables) # "O"
=NewMsgBox ("Error Creating goCrTables","Error Creating goCrTables",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF VARTYPE(goCrTables) # "O"

goCrTables.Item(1).Location = tcDBFName && e.g. "I:\AUTOREP\ACTIVITY.DBF"

llConnected=goCrTables.Item(1).TestConnectivity()

IF NOT llConnected
=NewMsgBox ("Unable to Connect to Table " + tcDBFName,"Unable to Connect",MB_OK + MB_ICONEXCLAMATION + MB_SYSTEMMODAL)
RETURN
ENDIF NOT llConnected

goCrRpt.ReadRecords()

goCrRpt.PrinterSetup(0)
goCrRpt.PrintOut(.T.)

goCrPrintingStatus = goCrRpt.PrintingStatus

=TakeOutTheGarbage()

ENDPROC && PrintReport
ENDDEFINE




PROCEDURE CheckDownExt
LPARAMETERS nDestinationType

#INCLUDE VFPCrystal.h

LOCAL cExtension

DO case
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "01|33"
cExtension = "RPT"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "02"
cExtension = "DIF"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "03"
cExtension = "REC"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "04|35"
cExtension = "RTF"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "05"
cExtension = "CSV"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "06"
cExtension = "TSV"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "07"
cExtension = "CHR"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "08|10|34"
cExtension = "TXT"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "09"
cExtension = "TTX"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "11"
cExtension = "WKS"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "12"
cExtension = "WK1"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "13"
cExtension = "WK3"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "14"
cExtension = "DOC"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "18|19|20|21|22|27|28|29|30"
cExtension = "XLS"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "24|32"
cExtension = "HTML"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "31"
cExtension = "PDF"
CASE PADL(ALLTRIM(STR(nDestinationType,2,0)),2,"0") $ "36"
cExtension = "XML"
ENDCASE

RETURN cExtension

ENDPROC


PROCEDURE NewMsgBox
LPARAMETERS tcText, tcCaption, tnType

*** Many Thanks to News2News.com !!! ***
*** Source: http://www.news2news.com/vfp/
*** -------------------------------------

LOCAL lnResponse
lnResponse = 0

IF VARTYPE(tnType) # "N"
tnType = 0
ENDIF VARTYPE(tnType) # "N"

DECLARE INTEGER MessageBox IN user32 As MsgBox;
INTEGER hwnd,;
STRING lpText,;
STRING lpCaption,;
INTEGER wType

DECLARE INTEGER GetActiveWindow IN user32

hwnd = GetActiveWindow()
lnResponse = MsgBox (0, tcText, tcCaption, tnType)

RETURN lnResponse

ENDPROC


PROCEDURE TakeOutTheGarbage
* Manual garbage collection

goCr = NULL
goCrRpt = NULL
goCrData = NULL
goCrTables = NULL
goCrExportOptions = NULL
goCrPrintingStatus = NULL

ENDPROC
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform