Tuesday, 21 January 2014

Reading Numbers from Excel using X++


You can use below code snippet to read number values from excel in AX 2012

 muEmpBufferTable.Mobile =strFmt("%1",cells.item(row,11).value().bStr());

Wednesday, 8 January 2014

Insert Image into table using X++ in ax 2012



static void Job3(Args _args)
{
Image img;
Filename name;
str type;
#File
;
img = new Image();
type = '.'+strlwr(enum2value(img.saveType()));
name = WinAPI::getOpenFileName(element.hWnd(), [WinAPI::fileType(type),#AllFilesName+type], '', '');
if (name)
{
ttsbegin;
img.loadImage(name);
ImageTable.Image = img.getData();
ImageTable.write();
ttscommit;
}
   

}

Monday, 17 June 2013

Reading Data From Text File In C#, XPO Format

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            Microsoft.Office.Interop.Excel.Workbook mWorkBook;
            Microsoft.Office.Interop.Excel.Sheets mWorkSheets;
            Microsoft.Office.Interop.Excel.Worksheet mWSheet1;
            Microsoft.Office.Interop.Excel.Application oXL;
            int counter = 1; string line;
            string tempStr;
            StringBuilder sb = new StringBuilder();
            oXL =  new Microsoft.Office.Interop.Excel.Application();
            mWorkBook = oXL.Workbooks.Open(@"C:\Users\axuser\Desktop\Test.xlsx", 0, false, 5, "", "",   false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);

            oXL.Visible = true;
            mWorkSheets = mWorkBook.Worksheets;
            mWSheet1 = (Microsoft.Office.Interop.Excel.Worksheet)mWorkSheets.get_Item ("Sheet1");
            // Read the file and display it line by line.            
            using (System.IO.StreamReader file = new   System.IO.StreamReader(@"C:\Users\axuser\Desktop\Test.txt"))
            {
                while ((line = file.ReadLine()) != null)
                {
                    if (line.Contains("CONFIGURATIONKEY #"))
                    {
                        // This append the text and a newline into the StringBuilder buffer      
                        //sb.AppendLine(line.ToString());
                        tempStr = line.Substring(20, line.Length - 20);
                        mWSheet1.Cells[counter, 1] = tempStr;
                        counter++;
                    }
                }
            }
            //txtResult.Text = sb.ToString();
        }
    }
}

Monday, 8 April 2013

EDT Array as Range

this.query().dataSourceNo(1).addRange(fieldid2ext(fieldNum(myTableName, Dimension), 1));

Friday, 29 March 2013

Todays date in ax 2009 report


To Get the todays date in the Ax 2009 report write the following code in display method of the report

display public str ABC_TodaysDate()
{
    return date2Str(today(), 123, DateDay::Digits2, DateSeparator::Slash, DateMonth::Digits2, DateSeparator::Slash, DateYear::Digits4);
}

Desiging Excel Sheet using X++

http://daxjoyie.blogspot.in/2012/05/code-for-getting-current-company-in-ax.html

Code for Select All button


write this code in From Data Source Methods

public void selectAllClosed()
{
    QueryRun                queryRun;
    RBOGiftCardTable      _rboGiftCardTable;
    ;

    ttsbegin;
    queryRun = new QueryRun(this.query());

    while (queryRun.next())
    {
        _rboGiftCardTable = queryRun.get(tablenum(RBOGiftCardTable));
        if(_rboGiftCardTable.PartialClose_ABC ==NoYes::Yes)
        {
        _rboGiftCardTable.Close_ABC = NoYes::Yes;
        _rboGiftCardTable.selectForUpdate(true);
        _rboGiftCardTable.update();
        }

    }

    ttscommit;
    RBOGiftCardTable_ds.executeQuery();
   }