Created
August 31, 2016 15:37
-
-
Save hasokeric/a2db2962ad50861875f1199fc07c5ae6 to your computer and use it in GitHub Desktop.
Printing BAQ (and other) Reports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void btnPrntDetail_Click(object sender, System.EventArgs args) | |
{ | |
if (edvEnd.Row > -1) | |
{ | |
// Set status | |
oTrans.PushStatusText("Production Detail Report Submitting..",true); | |
// Create report object | |
Session otSession = (Session)oTrans.Session; | |
JobProdDtl jobproddtl = new JobProdDtl(otSession.ConnectionPool); | |
JobProdDtlDataSet dsjobproddtl = jobproddtl.GetNewParameters(); | |
// Set filters | |
dsjobproddtl.JobProdDtlParam[0].JobList = edvJobHead.dataView[edvJobHead.Row]["JobNum"].ToString(); | |
dsjobproddtl.JobProdDtlParam[0].AsmList = ""; | |
dsjobproddtl.JobProdDtlParam[0].MaterialTrans = true; | |
dsjobproddtl.JobProdDtlParam[0].LaborTrans = true; | |
dsjobproddtl.JobProdDtlParam[0].PrintProfit = true; | |
dsjobproddtl.JobProdDtlParam[0].AllowJobProfitability = true; | |
// Prep generic values | |
PrepPrintJob(dsjobproddtl, otSession, true); | |
// Print and clean | |
jobproddtl.SubmitToAgent(dsjobproddtl, "SystemTaskAgent", 0, 0, "Epicor.Mfg.UIRpt.JobProdDtl"); | |
jobproddtl = null; | |
// Default status | |
oTrans.PushStatusText("Ready",false); | |
} | |
} | |
// Paste in customization as is no changes | |
private void PrepPrintJob(DataSet ds, Session otSession, bool prntDefaults) | |
{ | |
// Provide print dialog support | |
PrintDialog printDialog = new PrintDialog(); | |
if(!prntDefaults) | |
{ | |
if (printDialog.ShowDialog() != DialogResult.OK) | |
{ | |
throw new Exception("Printing canceled"); | |
} | |
} | |
// Params that need setting | |
ds.Tables[0].Rows[0]["AutoAction"] = "Print"; | |
ds.Tables[0].Rows[0]["AgentID"] = "SystemTaskAgent"; | |
ds.Tables[0].Rows[0]["DateFormat"] = "m/d/yyyy"; | |
ds.Tables[0].Rows[0]["NumericFormat"] = ",."; | |
// Print Params | |
ds.Tables[0].Rows[0]["PrinterName"] = printDialog.PrinterSettings.PrinterName; | |
ds.Tables[0].Rows[0]["RptPageSettings"] = Epicor.Mfg.Lib.Report.EpiPageAndPrinterSettings.CreatePageSettingsAsString(printDialog.PrinterSettings.DefaultPageSettings); | |
ds.Tables[0].Rows[0]["RptPrinterSettings"] = Epicor.Mfg.Lib.Report.EpiPageAndPrinterSettings.CreatePrinterSettingsAsString(printDialog.PrinterSettings); | |
ds.Tables[0].Rows[0]["WorkstationID"] = Epicor.Mfg.Lib.Report.EpiReportFunctions.GetWorkStationID(otSession); | |
ds.Tables[0].Rows[0]["ReportCultureCode"] = Epicor.Mfg.Lib.Report.EpiReportFunctions.GetRptCultureCode(otSession); | |
ds.Tables[0].Rows[0]["ReportCurrencyCode"] = Epicor.Mfg.Lib.Report.EpiReportFunctions.GetRptCurrencyCode(ds.Tables[0].Rows[0]["ReportCultureCode"].ToString(), otSession); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Printing Epicor Forms. | |
// Run a trace to get the params for the specific form you want to print. | |
// Include: | |
// Epicor.Mfg.Rpt.JobTrav | |
// Epicor.Mfg.Rpt.IJobTrav | |
// Epicor.Mfg.UIRPT.JobTrav | |
// Get Print Settings | |
PrintDialog printDialog = new PrintDialog(); | |
if (printDialog.ShowDialog() == DialogResult.OK) | |
{ | |
string printerName = printDialog.PrinterSettings.PrinterName; | |
// Get Page Settings | |
StringBuilder pgSet = new StringBuilder(); | |
pgSet.Append("Color="); | |
pgSet.Append(printDialog.PrinterSettings.DefaultPageSettings.Color.ToString()); | |
pgSet.Append(",Landscape="); | |
pgSet.Append(printDialog.PrinterSettings.DefaultPageSettings.Landscape.ToString()); | |
pgSet.Append(",Margins=[Left=100 Right=100 Top=100 Bottom=100]"); | |
/*pgSet.Append(printDialog.PrinterSettings.DefaultPageSettings.Margins);*/ | |
pgSet.Append(",PaperSize=[Kind=\""); | |
pgSet.Append(printDialog.PrinterSettings.DefaultPageSettings.PaperSize.Kind); | |
pgSet.Append("\" Height="); | |
pgSet.Append(printDialog.PrinterSettings.DefaultPageSettings.PaperSize.Height); | |
pgSet.Append(" Width="); | |
pgSet.Append(printDialog.PrinterSettings.DefaultPageSettings.PaperSize.Width); | |
pgSet.Append("],PaperSource=[SourceName=\""); | |
pgSet.Append(printDialog.PrinterSettings.PaperSources[0].SourceName); | |
pgSet.Append("\" Kind=\""); | |
pgSet.Append(printDialog.PrinterSettings.PaperSources[0].Kind); | |
pgSet.Append("\"],PrinterResolution=[]"); | |
// Get Printer Settings | |
StringBuilder prSet = new StringBuilder(); | |
prSet.Append("PrinterName=\""); | |
prSet.Append(printDialog.PrinterSettings.PrinterName); | |
prSet.Append("\""); | |
prSet.Append(",Copies="); | |
prSet.Append(printDialog.PrinterSettings.Copies.ToString()); | |
prSet.Append(",Collate="); | |
prSet.Append(printDialog.PrinterSettings.Collate.ToString()); | |
prSet.Append(",FromPage="); | |
prSet.Append(printDialog.PrinterSettings.FromPage.ToString()); | |
prSet.Append(",ToPage="); | |
prSet.Append(printDialog.PrinterSettings.ToPage.ToString()); | |
PrintJobs("JobNum",printerName, prSet.ToString(), pgSet.ToString()); | |
} | |
private static void PrintJobs(string p, string printer, string printerSettings, string pageSettings) | |
{ | |
Session session = (Session)oTrans.Session; | |
JobTrav jobTrav = new JobTrav(session.ConnectionPool); | |
JobTravDataSet jobTravDS = jobTrav.GetNewParameters(); | |
// Params | |
jobTravDS.JobTravParam[0].PrntAllMassPrnt = false; | |
jobTravDS.JobTravParam[0].Jobs = p; | |
jobTravDS.JobTravParam[0].Assembly = "0"; | |
jobTravDS.JobTravParam[0].SubAssem = false; | |
jobTravDS.JobTravParam[0].NewPgPerAsm = false; | |
jobTravDS.JobTravParam[0].OprDates = false; | |
jobTravDS.JobTravParam[0].OprStd = false; | |
jobTravDS.JobTravParam[0].BarCodes = false; | |
jobTravDS.JobTravParam[0].ShpSchd = false; | |
jobTravDS.JobTravParam[0].PrintSchedResources = true; | |
jobTravDS.JobTravParam[0].PrintSchedResrcDesc = true; | |
jobTravDS.JobTravParam[0].AutoAction = "Print"; | |
jobTravDS.JobTravParam[0].PrinterName = printer; | |
jobTravDS.JobTravParam[0].AgentSchedNum = 0;// <--- 0 is immediate get the sched ID from Task Agent if different | |
jobTravDS.JobTravParam[0].AgentID = "SystemTaskAgent"; | |
jobTravDS.JobTravParam[0].AgentTaskNum = 0; | |
jobTravDS.JobTravParam[0].RecurringTask = false; | |
jobTravDS.JobTravParam[0].RptPageSettings = pageSettings; | |
jobTravDS.JobTravParam[0].RptPrinterSettings = printerSettings; | |
jobTravDS.JobTravParam[0].ReportStyleNum = 1002; | |
jobTravDS.JobTravParam[0].WorkstationID = Environment.MachineName + " 1"; | |
jobTravDS.JobTravParam[0].ArchiveCode = 0; | |
jobTravDS.JobTravParam[0].DateFormat = "m/d/yyyy"; | |
jobTravDS.JobTravParam[0].NumericFormat = ",."; | |
jobTravDS.JobTravParam[0].ProcessTaskNum = 0; | |
jobTravDS.JobTravParam[0].DecimalsGeneral = 2; | |
jobTravDS.JobTravParam[0].DecimalsCost = 5; | |
jobTravDS.JobTravParam[0].DecimalsPrice = 5; | |
jobTravDS.JobTravParam[0].GlbDecimalsGeneral = 2; | |
jobTravDS.JobTravParam[0].GlbDecimalsCost = 5; | |
jobTravDS.JobTravParam[0].GlbDecimalsPrice = 5; | |
jobTravDS.JobTravParam[0].ReportCurrencyCode = "USD"; | |
jobTravDS.JobTravParam[0].ReportCultureCode = "en-US"; | |
jobTrav.SubmitToAgent(jobTravDS, "SystemTaskAgent", 0, 0, "Epicor.Mfg.UIRpt.JobTravJobEntry"); | |
//jobTrav.RunDirect(jobTravDS); | |
jobTrav = null; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void PrintLabel(List<string> jobs) { | |
// Filter options need to look like: "'aoeu','sth','345th'" | |
for (int i = 0; i < jobs.Count; i++) | |
jobs[i] = string.Format("'{0}'", jobs[i]); | |
var filter = string.Join(", ", jobs.ToArray()); | |
// Get the report dataset | |
BAQReportImpl baqRep = WCFServiceSupport.CreateImpl<BAQReportImpl>(((Session)oTrans.Session), ImplBase<BAQReportSvcContract>.UriPath); | |
var baqRepDS = baqRep.GetNewBAQReportParam(reportID); | |
// Setup the parameters | |
DynamicReportAdapter dra = new DynamicReportAdapter(oTrans); | |
dra.BOConnect(); | |
var reportID = "JobQueue-Labels"; | |
dra.GetByID(reportID); | |
dra.DynamicReportData.BAQRptFilter[0].FilterValue = filter; | |
baqRep.GetDefaults(baqRepDS); | |
baqRepDS.BAQReportParam[0].Filter1 = dra.DynamicReportData.GetXml(); | |
PrepPrintJob(baqRepDS, reportID, (Session)oTrans.Session, true, false); | |
// Print! | |
baqRep.SubmitToAgent(baqRepDS, "SystemTaskAgent", 0, 0, "Epicor.Mfg.UIRpt.BAQReport;JobQueue-Labels"); | |
} | |
/// <param name="UseDefaults">Use defaults vs prompt user</param> | |
/// <param name="Print">Print vs Preview</param> | |
private void PrepPrintJob(BAQReportDataSet ds, string reportID, Session session, bool UseDefaults, bool Print) { | |
// Provide print dialog support | |
PrintDialog printDialog = new PrintDialog(); | |
if (!UseDefaults) | |
if (printDialog.ShowDialog()!=DialogResult.OK) | |
throw new Exception("Printing canceled"); | |
// Params that need setting | |
ds.BAQReportParam[0].AutoAction = "SSRSPREVIEW"; | |
ds.BAQReportParam[0].AgentID = "SystemTaskAgent"; | |
ds.BAQReportParam[0].DateFormat = "m/d/yyyy"; | |
ds.BAQReportParam[0].NumericFormat = ",."; | |
ds.BAQReportParam[0].ReportID = reportID; | |
ds.BAQReportParam[0].BAQRptID = reportID; | |
ds.BAQReportParam[0].BAQID = reportID; | |
ds.BAQReportParam[0].ReportStyleNum = 1; | |
// Print Params | |
if (Print) { | |
// Don't need this to preview. | |
ds.BAQReportParam[0].PrinterName = printDialog.PrinterSettings.PrinterName; | |
ds.BAQReportParam[0].RptPageSettings = Ice.Lib.Report.EpiPageAndPrinterSettings.CreatePageSettingsAsString(printDialog.PrinterSettings.DefaultPageSettings); | |
ds.BAQReportParam[0].RptPrinterSettings = Ice.Lib.Report.EpiPageAndPrinterSettings.CreatePrinterSettingsAsString(printDialog.PrinterSettings); | |
} | |
ds.BAQReportParam[0].WorkstationID = Ice.Lib.Report.EpiReportFunctions.GetWorkStationID(session); | |
ds.BAQReportParam[0].ReportCultureCode = Ice.Lib.Report.EpiReportFunctions.GetRptCultureCode(session); | |
ds.BAQReportParam[0].ReportCurrencyCode = Ice.Lib.Report.EpiReportFunctions.GetRptCurrencyCode(ds.Tables[0].Rows[0]["ReportCultureCode"].ToString(), session); | |
ds.BAQReportParam[0].SSRSRenderFormat = "PDF"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Alternative to the string building garbage below. | |
Epicor.Mfg.Lib.Report.EpiPageAndPrinterSettings.CreatePrinterSettingsAsString(printDialog1.PrinterSettings); | |
Epicor.Mfg.Lib.Report.EpiPageAndPrinterSettings.CreatePageSettingsAsString(printDialog1.PrinterSettings.DefaultPageSettings); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get the workstation method information the way Epicor does. | |
string workID = Epicor.Mfg.Lib.Report.EpiReportFunctions.GetWorkStationID(otSession); | |
jobTravDS.JobTravParam[0].WorkstationID = workID; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is best one to use if we want to print a BAQ report automatically using a BPM?