10.09.2008, 23:05 | #1 |
Участник
|
axStart: Date methods in your Visual Studio Dynamics AX Report.
Источник: http://axstart.spaces.live.com/Blog/...C0A0!380.entry
============== I have followed some AX 2009 Trainings and all those training had one repeating issue. We don’t know how this works. So frustrated with this repeating answer, I decide it to find it out myself. It took about 12 hours to get this completely deeply knowledge about this issue. So when you read and played with it for 2 hours, your benefit is still 10 hours. Data method act like a temporary table creator. The creator defines the table (DataTable) and fills it with data. The return type of this Data method acts like a dataset for your report. Small click true demo: · Create new Visual studio project · Select with the right mouse the add data method option on DataMethods Node · Double click on this new created node. And a static C #method appears. using System; using System.Collections.Generic; using System.Security.Permissions; using Microsoft.Dynamics.Framework.Reports; publicpartialclassReport1 { [DataMethod(), AxSessionPermission(SecurityAction.Assert)] publicstaticstring DataMethod1() { thrownewException("The method or operation is not imp."); } } These static methods will become our new Dataset of the type Business Logic. Change the return type of this static method to DataTable. This method will finally appear in the list of the query property of the DataSet. In case off a compile error add the line using System.Data; to your code. There are a couple of good examples on MSDN, but if you don’t know the key words to find it, it becomes mission impossible. The MSDN links: Defining Report Data Methods (VS Reporting Tools for AX). There is not a good example about dealing with display methods, so I will give you this example. It simple creates a invent Table with the fields Item Group, Item Name, Item Id and the display method costpcsPrice(). [DataMethod(), AxSessionPermission(SecurityAction.Assert)] publicstaticDataTable RetrieveItemData() { // Retrieve records from the InventTable table. AxaptaRecordWrapper record = SessionManager.GetSession().CreateAxaptaRecord("InventTable"); record.ExecuteStmt("select * from %1"); // Create a data table. Add columns for item group and item information. DataTable table = newDataTable(); table.Columns.Add(newDataColumn("Item group", Type.GetType("System.String"))); table.Columns.Add(newDataColumn("Item information", Type.GetType("System.String"))); table.Columns.Add(newDataColumn("ItemID", Type.GetType("System.String"))); table.Columns.Add(newDataColumn("costPcsPrice", Type.GetType("System.String"))); // Iterate through the results. Add the item group to the data table. Call the display method while (record.Found) { string groupId = record.GetField("ItemGroupID").ToString(); string itemName = record.GetField("ItemName").ToString(); string itemId = record.GetField("ItemID").ToString(); table.Rows.Add(groupId, itemName, itemId,record.Call("costPcsPrice").ToString());// use display method record.Next(); } return table; } On the MSDN link one topic is not covered. How can I use my parameters in my DataMethods? Thanks to a tutorial from Elena Pricoiu from Microsoft, I was able to find out how it’s working. [DataMethod(), AxSessionPermission(SecurityAction.Assert)] publicstaticDataTable myParameters(System.String _AxSTart, System.Int16 _columns, System.Int16 _rows) { DataTable dataTable = newDataTable(); for (int counter = 0; counter < _columns; counter++) { dataTable.Columns.Add(_AxSTart + counter.ToString()); } //create data; for (int counter = 0; counter < _rows; counter++) { object[] rowVals = newobject[_columns]; rowVals[0] = _AxSTart; rowVals[1] = _columns.ToString(); //etc. dataTable.Rows.Add(rowVals); } return dataTable; } When you connect a dataset to this data method, the parameters are created on the flight. When completing your project, it possible to store the report into the AOT. Be aware that this example creates a dataset with dynamic column names. It is also interesting to investigate the existing reports in the AOT, especially the Shared Library Report. Deploy this library to your c# environment and add that project to your own project. Next add a reference from your project to the SharedLibrary Project. Finally add the line using Microsoft.Dynamics.Framework.Reports.SharedLibrary; to your code. From this point the default AX table templates for your report design are available in your report. Источник: http://axstart.spaces.live.com/Blog/...C0A0!380.entry
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
Теги |
ax2009, reporting services |
|
|