1

嗨朋友们,我从 sap b1 开始我在 Visual Studio 2010 中使用 c# 创建了我自己的附加 sap 我的表单将直接向我的水晶报告发送一个值,而不显示以前的任何人都可以帮助我的版本 sap 是 9.2 我试过这段代码但是它不起作用

        //add crystalreport to my add-on

        SAPbobsCOM.ReportTypesService rptTypeService = (SAPbobsCOM.ReportTypesService)
         Menu.company.GetCompanyService().GetBusinessService(SAPbobsCOM.ServiceTypes.ReportTypesService);
        SAPbobsCOM.ReportType newType = (SAPbobsCOM.ReportType)
        rptTypeService.GetDataInterface(SAPbobsCOM.ReportTypesServiceDataInterfaces.rtsReportType);
        newType.TypeName = "CodeBarre_etat";
        newType.AddonName = "PRINT_CODEBARRE";
        newType.AddonFormType = "PRINT_CODEBARRE";
        newType.MenuID = "PRINT_CODEBARRE";
        SAPbobsCOM.ReportTypeParams newTypeParam = rptTypeService.AddReportType(newType);


        //add layout to my report 

        SAPbobsCOM.ReportLayoutsService rptService = (SAPbobsCOM.ReportLayoutsService)
         Menu.company.GetCompanyService().GetBusinessService(SAPbobsCOM.ServiceTypes.ReportLayoutsService);
        SAPbobsCOM.ReportLayout newReport = (SAPbobsCOM.ReportLayout)
        rptService.GetDataInterface(SAPbobsCOM.ReportLayoutsServiceDataInterfaces.rlsdiReportLayout);
        newReport.Author = Menu.company.UserName;
        newReport.Category = SAPbobsCOM.ReportLayoutCategoryEnum.rlcCrystal;
        newReport.Name = "PRINT_CODEBARREL";
        newReport.TypeCode = newTypeParam.TypeCode;
        SAPbobsCOM.ReportLayoutParams newReportParam = rptService.AddReportLayout(newReport);

        // Set the report layout into the report type.

        newType = rptTypeService.GetReportType(newTypeParam);
        newType.DefaultReportLayout = newReportParam.LayoutCode;
        rptTypeService.UpdateReportType(newType);




        SAPbobsCOM.BlobParams oBlobParams = (SAPbobsCOM.BlobParams)
       Menu. company.GetCompanyService().GetDataInterface(SAPbobsCOM.CompanyServiceDataInterfaces.csdiBlobParams);
        oBlobParams.Table = "OITM";
        oBlobParams.Field = "Template";
        SAPbobsCOM.BlobTableKeySegment oKeySegment = oBlobParams.BlobTableKeySegments.Add();
        oKeySegment.Name = "ItemCode";
        oKeySegment.Value = newReportParam.LayoutCode;


        FileStream oFile = new FileStream("CodeBarre_etat.rpt", System.IO.FileMode.Open);
        int fileSize = (int)oFile.Length;
        byte[] buf = new byte[fileSize];
        oFile.Read(buf, 0, fileSize);
        oFile.Dispose();
        //SAPbobsCOM.Blob oBlob = (SAPbobsCOM.Blob)
        //Menu.company.GetCompanyService().GetDataInterface(SAPbobsCOM.CompanyServiceDataInterfaces.csdiBlob);

        SAPbobsCOM.Blob oBlob = (SAPbobsCOM.Blob)(Menu.company.GetCompanyService().GetDataInterface(SAPbobsCOM.CompanyServiceDataInterfaces.csdiBlob));
        oBlob.Content = Convert.ToBase64String(buf, 0, fileSize);
        Menu.company.GetCompanyService().SetBlob(oBlobParams, oBlob);
4

1 回答 1

0

不确定您的代码可能存在什么问题,但下面是您尝试做的工作的实现(尽管在 VB 中,而不是在 C# 中,但翻译它应该相当简单)。

这是一个示例调用:

setCrystalReport(REPORT_TITLE_SUMMARY, My.Settings.ReportsPath.TrimEnd("\") & "\" & "comm_report_summary.rpt", _
                    oForm, "myFormTypeID", "My Add-On Name", "MENU_ID_VALUE")

功能:

    'Returns new CR TypeCode
Private Function setCrystalReport(ByVal rptName As String, ByVal rptPath As String, ByRef oForm As SAPbouiCOM.Form, ByVal formType As String, _
                                  ByVal addOnName As String, ByVal menuID As String) As String
    Try
        '1. Ad a new report type => ReportTypesService (8.81+ only)
        Dim rptTypeService As SAPbobsCOM.ReportTypesService
        Dim newType As SAPbobsCOM.ReportType

        rptTypeService = SBO_Company.GetCompanyService().GetBusinessService(SAPbobsCOM.ServiceTypes.ReportTypesService)
        newType = rptTypeService.GetDataInterface(SAPbobsCOM.ReportTypesServiceDataInterfaces.rtsReportType)

        newType.TypeName = rptName
        newType.AddonName = addOnName
        newType.AddonFormType = formType
        newType.MenuID = menuID
        Dim newTypeParam As SAPbobsCOM.ReportTypeParams
        newTypeParam = rptTypeService.AddReportType(newType)

        '2. Add a new report layout => ReportLayoutService
        Dim rptService As SAPbobsCOM.ReportLayoutsService
        Dim newReport As SAPbobsCOM.ReportLayout

        rptService = SBO_Company.GetCompanyService().GetBusinessService(SAPbobsCOM.ServiceTypes.ReportLayoutsService)
        newReport = rptService.GetDataInterface(SAPbobsCOM.ReportLayoutsServiceDataInterfaces.rlsdiReportLayout)
        newReport.Author = SBO_Company.UserName
        newReport.Category = SAPbobsCOM.ReportLayoutCategoryEnum.rlcCrystal
        newReport.Name = rptName
        newReport.TypeCode = newTypeParam.TypeCode

        Dim newReportParam As SAPbobsCOM.ReportLayoutParams
        newReportParam = rptService.AddReportLayout(newReport)

        '3. Set the report layout into the report type
        newType = rptTypeService.GetReportType(newTypeParam)
        newType.DefaultReportLayout = newReportParam.LayoutCode
        rptTypeService.UpdateReportType(newType)

        '4. Link the Report layout code to the Crystal Report file
        Dim oBlobParams As SAPbobsCOM.BlobParams
        Dim oKeySegment As SAPbobsCOM.BlobTableKeySegment

        oBlobParams = SBO_Company.GetCompanyService().GetDataInterface(SAPbobsCOM.CompanyServiceDataInterfaces.csdiBlobParams)
        oBlobParams.Table = "RDOC"
        oBlobParams.Field = "Template"

        oKeySegment = oBlobParams.BlobTableKeySegments.Add()
        oKeySegment.Name = "DocCode"
        oKeySegment.Value = newReportParam.LayoutCode

        Dim oFile As New FileStream(rptPath, System.IO.FileMode.Open)
        Dim fileSize As Integer
        fileSize = oFile.Length
        Dim buf(fileSize) As Byte
        oFile.Read(buf, 0, fileSize)
        oFile.Dispose()

        Dim oBlob As SAPbobsCOM.Blob
        oBlob = SBO_Company.GetCompanyService().GetDataInterface(SAPbobsCOM.CompanyServiceDataInterfaces.csdiBlob)

        oBlob.Content = Convert.ToBase64String(buf, 0, fileSize)
        SBO_Company.GetCompanyService().SetBlob(oBlobParams, oBlob)

        '5. Link the new report type to your form
        Return newType.TypeCode
    Catch ex As Exception
        Dim exString As String = ""
        exString = "Exception caught in setCrystalReport Method. Details: " & ex.Message
        If Not ex.InnerException Is Nothing Then
            exString += "  Inner Exception: " + ex.InnerException.Message
        End If
        SBO_Application.StatusBar.SetText(exString, SAPbouiCOM.BoMessageTime.bmt_Medium, _
                           SAPbouiCOM.BoStatusBarMessageType.smt_Error)
        Return "-1"
    End Try
End Function
于 2016-06-16T15:24:18.597 回答