csharp 打印BAQ(和其他)报告

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 打印BAQ(和其他)报告相关的知识,希望对你有一定的参考价值。

// Get the workstation method information the way Epicor does.

string workID = Epicor.Mfg.Lib.Report.EpiReportFunctions.GetWorkStationID(otSession);

jobTravDS.JobTravParam[0].WorkstationID = workID;
// Alternative to the string building garbage below.

Epicor.Mfg.Lib.Report.EpiPageAndPrinterSettings.CreatePrinterSettingsAsString(printDialog1.PrinterSettings);
Epicor.Mfg.Lib.Report.EpiPageAndPrinterSettings.CreatePageSettingsAsString(printDialog1.PrinterSettings.DefaultPageSettings);
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";
    }
// 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;
}
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);
	}

以上是关于csharp 打印BAQ(和其他)报告的主要内容,如果未能解决你的问题,请参考以下文章

csharp Epicor 10.1从代码调用BAQ

csharp 在ASP.NET中流式传输和下载RDLC报告

csharp 创建,初始化和打印数组的示例。

csharp 创建,初始化和打印数组的示例。

Reportviewer,一些报告打印,而另一些则不会

csharp 示例 - CSHARP - 报告 - GenerateReport-GenerateBubbleChartFromJsoninExcel.cs