AX SSRS report data helper

While we develop a ax ssrs report often using 'Business Logic' rather than 'AX Queries'. The 'Business Logic' is base on a AX class, there is a static method return a data type as 'System.Data.DataTable'.  While using the 'DataTable' type, we need to define the data columns frequently. It is a boring job. So I define a data helper to help to reduce the boring process. 

Note: Befor using the helper, it needs to assign the code permission.

  InteropPermission    InteropPermission;
  ;
  interopPermission = new InteropPermission(InteropKind::ClrInterop);
    interopPermission.assert();

    //Helper code

    CodeAccessPermission::revertAssert();

  

public class DataHelperNewSRS
{
    System.Data.DataTable               g_DataTable;
    System.Data.DataColumnCollection    g_DataColumnCon;
    System.Data.DataRowCollection       g_DataRowCon;
    System.Data.DataRow                 g_DataRow;

    List                                g_List;
    Container                           g_Con;
}

void run()
{
    ;

    this.init();
    this.fetchData();
}

protected void init()
{
    ;

    g_DataTable     = new System.Data.DataTable();
    g_DataColumnCon = g_DataTable.get_Columns();
    g_DataRowCon    = g_DataTable.get_Rows();
    g_List          = new List(Types::Container);
}

protected void fetchData()
{
    ;

    //Fetch the data here
}

protected void insertColumns(str _Name, Types _DataType, boolean _IsEnd = false)
{
    ;

    g_List.addEnd([_Name, _DataType]);

    if (_IsEnd)
        this.insertColumns_DEL();
}

private void insertColumns_DEL()
{
    ListEnumerator      m_LE;
    str                 m_Name, m_Type;
    Types               m_DataType;
    int                 i;
    ;

    m_LE = g_List.getEnumerator();

    while (m_LE.moveNext())
    {
        [m_Name, m_DataType] = m_LE.current();

        m_Type = this.getDataType(m_DataType);
        g_DataColumnCon.Add(m_Name, System.Type::GetType(m_Type));

        i++;
        g_Con = conins(g_Con, i, m_Name);
    }

}

private str getDataType(Types _DataType)
{
    ;

    switch (_DataType)
    {
        case Types::String   : return "System.String";
        case Types::Integer  : return "System.Int32";
        case Types::Int64    : return "System.Int64";
        case Types::Date     : return "System.DateTime";
        case Types::Real     : return "System.Decimal";
    }

    return "System.String";
}

protected void insertDataRows(container _con)
{
    int         i, m_RecNum = conlen(_con);
    str         m_Name;
    anytype     m_Data;
    ;

    g_DataRow = g_DataTable.NewRow();

    for (i = 1; i <= m_RecNum; i++)
    {
        m_Name = conpeek(g_Con, i);
        m_Data = conpeek(_con, i);

        g_DataRow.set_Item(m_Name, m_Data);
    }

    g_DataRowCon.Add(g_DataRow);

}

System.Data.DataTable getData()
{
    ;

    return g_DataTable;
}

  

posted @ 2014-11-17 17:11  Sprite.z  Views(258)  Comments(0Edit  收藏  举报