Hey all, I have been trying for hours how to figure this out. I am trying to print a BAQ SSRS report from a button click. I can get it to show up as a preview, but it will not print to the printer. I am using a network printer that is on the Epicor SQL server, and I keep getting a “Printer Does Not Exist” Error. Can any of you tell me what I am doing wrong? Here is my code:
private void epiButtonC1_Click(object sender, System.EventArgs args)
{
string agentID = "";
try
{
Session otSession = (Session)oTrans.Session;
//Set the workstationID
string workStation = Ice.Lib.Report.EpiReportFunctions.GetWorkStationID(otSession);
//Get or Set the AgentID
using (var aSA = new SysAgentAdapter(oTrans))
{
oTrans.PushStatusText("Get System Agent Info", true);
aSA.BOConnect();
aSA.GetDefaultTaskAgentID(out agentID);
if (!string.IsNullOrEmpty(agentID)) { agentID = "SystemTaskAgent"; }
}
//MessageBox.Show(agentID + ", " + workStation);
{
var baqR = WCFServiceSupport.CreateImpl<Ice.Proxy.Rpt.BAQReportImpl>((Session)oTrans.Session, Epicor.ServiceModel.Channels.ImplBase<Ice.Contracts.BAQReportSvcContract>.UriPath);
var dynamicReport = WCFServiceSupport.CreateImpl<Ice.Proxy.BO.DynamicReportImpl>((Session)oTrans.Session, 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("P-NOTES2");
var baqRptDS = baqR.GetNewBAQReportParam("P-NOTES2");
//baqRptDS.BAQReportParam[0].Option01 = guid.ToString();
baqRptDS.BAQReportParam[0].AutoAction="SSRSPrint";
baqRptDS.BAQReportParam[0].PrinterName=@"\\server1\BrotherEngineering";
baqRptDS.BAQReportParam[0].RptPageSettings = "Color=False,Landscape=True,Margins=[Left=0 Right=0 Top=0 Bottom=0],PaperSize=[Kind='Letter' PaperName='Letter' Height=1100 Width=850],PaperSource=[SourceName='Auto Select' Kind='AutomaticFeed'],PrinterResolution=[Kind='Custom' X=600 Y=600]";
baqRptDS.BAQReportParam[0].RptPrinterSettings = "PrinterName='\\\\server1\\BrotherEngineering',Copies=1,Collate=False,Duplex=Simplex,FromPage=1,ToPage=1";
baqRptDS.BAQReportParam[0].PrintReportParameters=false;
baqRptDS.BAQReportParam[0].WorkstationID=workStation;
baqRptDS.BAQReportParam[0].SSRSRenderFormat = "PDF";
baqRptDS.BAQReportParam[0].Character01="PrintPrev";
//baqRptDS.BAQReportParam[0].Character02=flag;
baqRptDS.BAQReportParam[0].BAQRptID=("P-NOTES2");
baqRptDS.BAQReportParam[0].ReportID=("P-NOTES2");
baqRptDS.BAQReportParam[0].Summary = false;
baqRptDS.BAQReportParam[0].ReportStyleNum = 1;
baqRptDS.BAQReportParam[0].BAQID=("P-NOTES2");
baqRptDS.BAQReportParam[0].ReportTitle = "Production Notes";
//baqRptDS.BAQReportParam[0].TaskNote = guid.ToString();
//rptDs.BAQRptOptionFld[0].FieldValue = guid.ToString();
rptDs.AcceptChanges();
StringWriter writer = new StringWriter();
rptDs.WriteXml(writer);
baqRptDS.BAQReportParam[0].Filter1 = writer.ToString();
//baqR.RunDirect(baqRptDS);
baqR.SubmitToAgent(baqRptDS, agentID, 0, 0, "Epicor.Mfg.UIRpt.BAQReport");
//MessageBox.Show("Report Submitted to System Agent for processing.");
}
}
catch (Exception ex)
{
MessageBox.Show("An error occured trying to print report." + ex.Message);
}
}