So the programmatic printing topic has been done and redone numerous times; I thought I’d definitely find sample code that works for my specific situation. Well… “Uncle”!
Sitrep:
I’ve created a BAQ Report that has 1 option field which takes an alphanumeric ID. The query itself would return all records in my UD100 table, but the report uses an option field to grab just the UD100 record I am looking for (Key1 field). This works fine when printing from my customized application.
Challenge:
I’m trying to bypass all dialog boxes and send the crystal report straight to the default printer for this dedicated workstation. Therefore, on ButtonClick(), print!
Acceptable solution:
I’ll be happy just creating the XML. There’s another @josecgomez post that uses FileSystemWatcher to send the XML to print, so I may try that.
Current location:
I’ve cobbled together (and reduced) posts by @josecgomez and @hkeric.wci (they deal w/SSRS output, but okay), and there are other examples out there in the netherweb.
I’ve reduced it all to the following. But, when run, it goes active in report monitor and runs until I stop the task agent. It does create a properly formatted XML file, but it includes all records from the UD table.
private void PrintTicket()
{
string BAQ = “MDI-RPT-ScaleTkt”;
string report = “MDI_RPT-ScaleTk”;
string format = “MDI_RPT-ScaleTk”;
string agentID = “SystemTaskAgent”;
string reportname = “Scale Ticket”;
Session otSession = (Session)oTrans.Session;
string workStation = Ice.Lib.Report.EpiReportFunctions.GetWorkStationID(otSession);
string userID = otSession.UserID;
string ticketNum = edv.CurrentDataRow[“Key1”].ToString();
try
{
var baqR = WCFServiceSupport.CreateImpl<Ice.Proxy.Rpt.BAQReportImpl>(otSession, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.BAQReportSvcContract>.UriPath);
var dynamicReport = WCFServiceSupport.CreateImpl<Ice.Proxy.BO.DynamicReportImpl>(otSession, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.DynamicReportSvcContract>.UriPath);
//var rptMonitor = WCFServiceSupport.CreateImpl<Ice.Proxy.BO.ReportMonitorImpl>((Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.ReportMonitorSvcContract>.UriPath);// GET DEFAULT REPORT PARAMETERS var rptDs = dynamicReport.GetByID(report); var baqRptDS = baqR.GetNewBAQReportParam(report); baqRptDS.BAQReportParam[0].AutoAction="PREVIEW"; baqRptDS.BAQReportParam[0].WorkstationID=workStation; baqRptDS.BAQReportParam[0].UserID=userID; baqRptDS.BAQReportParam[0].SSRSRenderFormat = format; baqRptDS.BAQReportParam[0].AttachmentType = format; baqRptDS.BAQReportParam[0].BAQRptID=(report); baqRptDS.BAQReportParam[0].ReportID=(report); baqRptDS.BAQReportParam[0].Summary = false; baqRptDS.BAQReportParam[0].ReportStyleNum = 1; baqRptDS.BAQReportParam[0].BAQID=(BAQ); baqRptDS.BAQReportParam[0].ReportTitle = reportname; baqRptDS.BAQReportParam[0].Option01 = ticketNum; // Just ONE ticket rptDs.AcceptChanges(); StringWriter writer = new StringWriter(); rptDs.WriteXml(writer); baqRptDS.BAQReportParam[0].Filter1 = writer.ToString(); baqR.SubmitToAgent(baqRptDS, agentID, 0, 0,"Epicor.Mfg.UIRpt.BAQReport"); } catch (Exception ex) { MessageBox.Show("An error occured trying to print report." + ex.Message); }
Does anyone care to offer a suggestion on this very old and tired topic?