日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[AX]AX2012 SSRS报表使用Report Data Method

發布時間:2023/12/19 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [AX]AX2012 SSRS报表使用Report Data Method 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在AX2012的SSRS報表中可以使用c#或者Visual basic .net編寫report data method來獲取和操作數據,由report data method返回的數據可以用在報表的表達式中,也可以用作dataset的數據源。

使用Report data method首先需要創建AX model工程,在工程中添加一個報表,雙擊打開報表,在報表的Data methods節點下右鍵“Add data method”,設置其名稱,右鍵點擊這個添加的data method在菜單中選擇“View code”,Visual studio會自動創建一個C#的工程,工程名稱為“報表名稱.BusinessLogic”,并定義一個和報表名稱相同的類,同時自動添加一個DataMethod特性標注的靜態方法,類似:

public partial class TestDataMethodReport {[DataMethod(), PermissionSet(SecurityAction.Assert, Name = "FullTrust")]public static string DataMethod1(){throw new NotImplementedException("The method or operation is not implemented.");} }

默認是使用C#工程,要使用Visual basic需要手工設置報表的屬性“Data method library”為一個預先添加到AOT中的visual basic的工程,然后就可以在這個VB工程中添加相應的report data method類和方法。

如果要使用report data method作為dataset的數據源,report data method必須返回值類型必須是IEnumerable<DataRow>或者DataTable。返回的數據量可能比較的多,建議使用yield return 返回一個IEnumerable<DataRow>的數據,這要比返回DataTable效率高。report data method可以有參數,這些參數和報表dataset的參數想對應。由于類的名稱和報表名稱要求相同,所以一個reprot data method只能用在一個報表中,不能被多個報表共享。下面是一個report data method返回數據集的例子:

[DataMethod(), PermissionSet(SecurityAction.Assert, Name = "FullTrust")] public static IEnumerable<DataRow> CreateInventoryItemByRow() {// Define a data table.DataTable table = new DataTable();table.Columns.Add(new DataColumn("ItemID", Type.GetType("System.Int32")));table.Columns.Add(new DataColumn("Name", Type.GetType("System.String")));table.Columns.Add(new DataColumn("Description", Type.GetType("System.String")));table.Columns.Add(new DataColumn("Cost", Type.GetType("System.Decimal")));table.Columns.Add(new DataColumn("SellingPrice", Type.GetType("System.Decimal")));DataRow row = null;row = table.NewRow();row.ItemArray = new object[] { 1734, "Clamp", "Workbench Clamp", 12.48, 17.99 };yield return row;row = table.NewRow();row.ItemArray = new object[] { 1983, "Saw", "Wooden Handle Saw", 7.89, 11.99 };yield return row;row = table.NewRow();row.ItemArray = new object[] { 6728, "Screwdriver", "Standard Screwdriver", 2.75, 3.99 };yield return row;row = table.NewRow();row.ItemArray = new object[] { 4920, "Nails", "Roofing Nails 5lbs", 12.45, 15.99 };yield return row;row = table.NewRow();row.ItemArray = new object[] { 4829, "Tape Measure", "25 ft Tape Measure", 12.87, 16.99 };yield return row;row = table.NewRow();row.ItemArray = new object[] { 2893, "Nails", "Finish Nails", 3.90, 5.99 };yield return row; }

?要在報表中使用report data method作為數據源,首先需要編譯包含report data method的bussiness logic工程并添加到AOT中。在報表中新建一個dataset,dataset的數據源選擇Dynamics AX,Data source type選擇bussiness logic,點擊Query屬性的...按鈕就可以選擇相應的report data method。包含report的ax model工程也需要編譯后添加到AOT,否則也是看不到這個report data method的。

?Data report method還可以用在報表的一些表達式中,比如AX自帶的Ax model工程CaseReports中用到了這樣一個data method:

public partial class Case_MyCases [DataMethod(), PermissionSet(SecurityAction.Assert, Name = "FullTrust")] public static string GetDefaultColorDark(int index) {return ColorHelper.GetDefaultColorDark(index); }

報表chart圖形有使用這個方法作為數據系列的顏色:

=GetDefaultColorDark(0)

Report data method使用.net編寫可以讀取AX以為的數據源,也可以使用custom service來從X++方法獲取數據,X++被編譯為.net CIL后由custom service宿主供托管代碼調用。先在AX中定義一個X++的類:

public class HelloWorld { } [SysEntryPointAttribute(true)] public str printHelloWorld() { return "Hello World"; }

在AOT的service節點下新建一個service,設置Name為MyService,ExternalName為HelloWorldService,選擇Class為HelloWorld。在MyService下添加一個service operations,選擇方法printHelloWorld。

在AOT的Service group下添加一個名為MyServiceGroup的組,把MyService拖到這個組中,部署MyServiceGroup。

?回到Visual studio中的bussinesslogic工程,在工程的reference下添加一個service reference,服務URL類似:http://[machinename]:8101/DynamicsAx/Services/MyServiceGroup。在列出的服務中選擇MyServiceGroup添加到工程,刪除工程中的app.config文件,編譯時app.config重新生成。在bussiness logic工程添加一個新的report data method來測試,注意在cs文件中using相應的service reference:

public static string HelloWorldDataMethod() {// Create an instance of the client proxy class that connects to the service exposed in Microsoft Dynamics AX.var client = AxServiceManagement.CreateServiceClient<HelloWorldServiceClient>("MyServiceGroup");// Call the "printHelloWorld" operation on the service - passing the company that you are testing in.CallContext context = new CallContext();context.Company = "ceu";string returnedValue = client.printHelloWorld(context);// Return the result.return returnedValue; }

在report上新建一個precision的design,添加一個textbox到design,設置其value屬性為表達式:

=HelloWorldDataMethod()

預覽報表textbox顯示#error,VS的輸出中有警告信息:

Warning 7 The Value expression for the textrun ‘Textbox1.Paragraphs[0].TextRuns[0]’ contains an error: Unable to find matching endpoint configuration for the passed contract 'HelloWorldService' and port name 'MyServiceGroup' TestDataMethodReport.PrecisionDesign1 [Preview] 0 0

?新建了一個控制臺的工程來測試這個AIF service,卻是能正常得到結果的。不知道問題出在哪里,來回刪除service reference重建運行報表也是一樣的。意外重啟了服務器,再運行報表正常了,...問題又出在那個哪個緩存沒更新?!問題還不算完,在VS里預覽報表沒有問題了,但是在AX通過menu item運行報表或者在SQL report service的頁面上運行報表又是一樣的錯誤結果,真是無語啊。查看windows日志有這樣的錯誤:

Object Server 01: An error has occurred in the services framework. Method: AifMessageInspector::AfterReceiveRequest. Error: System.ServiceModel.FaultException: Failed to logon to Microsoft Dynamics AX.
at Microsoft.Dynamics.Ax.Services.AxServiceOperationContext.InitializeSession()
at Microsoft.Dynamics.Ax.Services.AxServiceOperationContext.InitializeContext()
at Microsoft.Dynamics.Ax.Services.AxServiceOperationContext.Attach(OperationContext owner)
at System.ServiceModel.ExtensionCollection`1.InsertItem(Int32 index, IExtension`1 item)
at System.Collections.Generic.SynchronizedCollection`1.Add(T item)
at Microsoft.Dynamics.Ax.Services.AifMessageInspector.AfterReceiveRequest(Message& request, IClientChannel channel, InstanceContext instanceContext)

貌似是什么權限類的錯誤,google發現不少人都遇到這個錯誤(http://community.dynamics.com/product/ax/f/33/p/64670/158445.aspx#158445),有人說要把report service的賬號添加到windows access authorized group和pre-windows 2000 compatiable group,還有人說要在ax client configuration中刷新下配置,不知道什么時候還出現了這樣的錯誤:

Unable to write the generated WCF configuration to local storage. The generated WCF configuration will be used from memory. The contents of the new configuration are written to the following temp file: C:\Users\AOS\AppData\Local\Temp\Microsoft.Dynamics.AX.Framework.Services.Client.Configuration.ClientConfigurationInternal.log.

AOS是我的AOS service的賬戶,也是SQL report service的賬戶,好像是要被配置文件寫到注冊表被拒絕而使用內存中的配置信息,不知道是不是這個原因。還有人說升級了AX kernel,錯誤消失了,就這樣放著吧,以后再說,休息一下,休息一下。

這個Report data method可以用在報表的表達式中,更多內容參見http://msdn.microsoft.com/en-us/library/cc587341.aspx

?

轉載于:https://www.cnblogs.com/duanshuiliu/archive/2012/08/23/2651904.html

總結

以上是生活随笔為你收集整理的[AX]AX2012 SSRS报表使用Report Data Method的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。