Sample Data Methods

Get Information about an Enum

public static System.Data.DataTable GetAXEnum(string enumname)
{
    if (enumname == null)
    {
        throw new System.ArgumentNullException("enumname");
    }
    
    var dt = new System.Data.DataTable();
    dt.Columns.Add("Symbol", typeof(string));
    dt.Columns.Add("IntValue",typeof(int));
    dt.Columns.Add("Label",typeof(string));

    var ax = Microsoft.Dynamics.Framework.Reports.SessionManager.GetSession();
    int enum_id = (int)ax.CallStaticClassMethod("Global", "enumName2Id", enumname);
    var enum_obj = ax.CreateAxaptaObject("DictEnum", Convert.ToString(enum_id));
    int val_count = (int)enum_obj.Call("values");

    dt.BeginLoadData();

    for (int i = 0; i < val_count; i++)
    {
        string symbol = (string)enum_obj.Call("value2Symbol", i);

        if (symbol.Length > 0)
        {
            int int_value = (int)enum_obj.Call("symbol2Value", symbol);
            string label = (string)enum_obj.Call("value2Label", i);
            dt.Rows.Add(symbol, int_value, label);
        }
    }
    dt.EndLoadData();
    
    return dt;
}


Get Filler Data

public static System.Data.DataTable GetFillerData(int num_rows, int num_cols)
{
    var dt = new System.Data.DataTable();
    for (int i = 0; i < num_cols; i++)
    {
        dt.Columns.Add(string.Format("Col{0:00}", i), typeof(string));
    }

    var rand = new System.Random();
    dt.BeginLoadData();

    var obj_array = new object[num_cols];
    for (int r = 0; r < num_rows; r++)
    {
        for (int c = 0; c < num_cols; c++)
        {
            obj_array[c] = string.Format("{0:0.0}", rand.NextDouble() * 10.0);
        }
        dt.Rows.Add(obj_array);
    }
    dt.EndLoadData();

    return dt;
}


Dynamically creating a bitmap to place in a report

public static byte[] DataMethod1() 
{ 
    using (var bmp = new System.Drawing.Bitmap(600, 200)) 
    { 
        var brush_white = System.Drawing.Brushes.White; 

        using (var g = System.Drawing.Graphics.FromImage(bmp)) 
        { 
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; 
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; 

            var f = new System.Drawing.Font("Courier", 36.0f); 
            g.DrawRectangle(System.Drawing.Pens.Red, 10, 10, 400, 100); 

        } 

        var memstream = new System.IO.MemoryStream(); 
        bmp.Save(memstream, System.Drawing.Imaging.ImageFormat.Png); 
        var bytearray = memstream.ToArray(); 
        return bytearray;
    } 


Executing a query in a DataMethod

[DataMethod(), AxSessionPermission(SecurityAction.Assert)]
public static System.Data.DataTable GetCustomerData()
{
    var table = AxQuery.ExecuteQuery("select * from CustGroupSRS");
    return table;
}

Last edited May 26, 2011 at 3:05 PM by saveenr, version 7

Comments

No comments yet.