Currency Converter in Dynamics Ax



Description:-

For example if my accounting currency is USD and I have configured GBP for currency conversion, then if I select GBP and double click on the Currency converter form, then the values in all the forms in AX should be shown in GBP or any other currency.
Here is the sample code to convert the Amount in one currency to another currency.

In Dynamics Ax 2009

static void CurrencyConverter(Args _args)
{
  CurrencyExchHelper currencyExchangeHelper;
  AmountMst amountMST;
  AmountCur amountCur;
  ;
  amountCur = 5000.00;
  currencyExchangeHelper = CurrencyExchHelper::newExchDate("KSI","USD",systemDateGet());
  amountMST = currencyExchangeHelper.calculateAmountCurToMst(amountCur ,true);
  info(strFmt('%1',amountMST));
}

In Dynamics Ax 2012

Static void SR_CEH_Example11(Args _args)
{
  CurrencyExchangeHelper currencyExchangeHelper;
  CurrencyCode transCurrency = 'EUR';
  AmountCur amountCur = 500.00;
  AmountMst amountMST;

  currencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::current(), systemDateGet());
  amountMST = currencyExchangeHelper.calculateTransactionToAccounting(transCurrency, amountCur ,true);
  info(strFmt('%1',amountMST));
}
How to create SSRS Report in ax 2012

How to create SSRS Report in ax 2012

Description:-
 
A Report data provider class is commonly known as RDP. RDP is the data source type which is available when we add a new dataset to the report in Visual Studio. RDP is a class which resides inside AX and executes the business logic, processes the data, and returns a dataset which is rendered in the report.

A Report data provider class should be ideally used in the following cases:

We cannot directly use a query to access the data from the database
The data has to prepare on the basis of business logic

To define a Report data provider class, we use the following syntax:

[SRSReportParameterAttribute(classStr(SalesInvoiceRegisterContract))]
class SalesInvoiceRegisterDp extends SRSReportDataProviderBase
{
    CustAccount                  _CustAccount;
    BaseDate                     _FromDate,_ToDate;
    SalesInvoiceRegisterContract _Contract;
    SalesInvoiceRegistertmp     SalesInvoiceRegistertmp;
}

Now create table return method in data provider class like below.

[SRSReportDataSetAttribute("SalesInvoiceRegistertmp")]
public SalesInvoiceRegistertmp getSalesInvoiceRegistertmp()
{
    select * from SalesInvoiceRegistertmp;//temp table
    return SalesInvoiceRegistertmp;
}

Now create ProcessReport method in Data Provider class.

public void processReport()
{
    _Contract                   = this.parmDataContract();

    _FromDate                   = _Contract.ParmFromDate();
    _ToDate                     = _Contract.ParmToDate();
    _CustAccount                = _Contract.ParmCustAccount();
}

Report contract class

Report contracts in AX 2012 are used for defining parameters to the SSRS report. We can define any number of parameters using X++ statements of any data type, which can be passed on to the RDP class. And then, we can use the same contracts to query data from the database engine which will decrease an overhead on execution of a query in SQL.

To define a Report contract class we use the following syntax:

[DataContractAttribute]
class SalesInvoiceRegisterContract implements SysOperationValidatable
{
    BaseDate                    FromDate,ToDate;
    CustAccount                 CustAccount;
}

Now create customer account parameter method in contract class.

[DataMemberAttribute("Customer"),SysOperationLabelAttribute("Customer"),SysOperationDisplayOrderAttribute('1')]
public CustAccount ParmCustAccount(CustAccount _CustAccount = CustAccount)
{
    CustAccount = _CustAccount;
    return CustAccount;
}

Now create from date and to date method In contract class.

[DataMemberAttribute('FromDate'), SysOperationLabelAttribute('From Date'), SysOperationDisplayOrderAttribute("2")]
Public BaseDate ParmFromDate(BaseDate _FromDate = FromDate)
{
    FromDate = _FromDate;
    return FromDate;
}

[DataMemberAttribute('ToDate'), SysOperationLabelAttribute('To Date'), SysOperationDisplayOrderAttribute("3")]
Public BaseDate ParmToDate(BaseDate _ToDate = ToDate)
{
    ToDate = _ToDate;
    return ToDate;
}

Now create validate method in contract class for validate report parameter in contract class like below.

public boolean validate()
{
    boolean isValid = true;

    if (!FromDate)
    {
        isValid = checkFailed(strFmt("@SYS84753", "@SYS180311"));
    }
    if (!ToDate)
    {
        isValid = checkFailed(strFmt("@SYS84753", "@SYS180217"));
    }
    if(FromDate && ToDate)
    {
        if (FromDate > ToDate)
        {
            isValid = checkFailed(strFmt("@SYS300457", date2StrUsr(FromDate, DateFlags::FormatAll), date2StrUsr(ToDate, DateFlags::FormatAll)));
        }
    }
    return isValid;
}

Now in Visual Studio add the following

Add Report
Add Data Set
       Set the Properties for that Data Set.
       Set the Parameters you want to set blank value for ItemId Parameters

      Allow blank = true
      Null-able = true

Add Precision Design
Deployed SSRS Report and Run it.
How to Estimating Execution Time and Take ScreenShot in Dynamics Ax

How to Estimating Execution Time and Take ScreenShot in Dynamics Ax

Description:- 

In this article we will she how to take screen shot using X++. Here i have Create System Bit Image to Take Bitmap Image and Save in where you want to save using FileSaveDialog Box. Using getSystemMetrics to get Height and Width of Screen to take Image and Capture and Save it to Using FileSaveDialog box in Dynamics Ax.

Code:-

Static void ScreenShot(Args _args)
{
    System.Drawing.Bitmap           bitmap;
    System.Drawing.Graphics         graphics;
    System.Windows.Forms.Screen     primaryScreen;
    System.Drawing.Rectangle        bounds;
    int x, y, k, l;
    str SaveToFileName;
    System.Int32                    width;
    System.Int32                    height;
    filename                        filename;
    FromTime startTime = timeNow();
    int i;
    str dummyStr;
    str filepath;
    container confilter = [".jpg","*.jpg"];
    #WINAPI
    //#define.FileName('DynamicsAx_Screenshot.jpg')
    ;
    try
    {
    for (i = 1 ; i <= 1000000; i++)
    {
       dummyStr += int2str(i);
    }
    primaryScreen   = System.Windows.Forms.Screen::get_PrimaryScreen();
    bounds          = primaryScreen.get_Bounds();
    [x, y, k, l]    = WinApi::getWindowRect(infolog.hWnd());
    //width           = 1280;//_control.widthValue();
    //height          = 800;//_control.heightValue();
    width       = WinAPI::getSystemMetrics(#SM_CXSCREEN);
    height      = WinAPI::getSystemMetrics(#SM_CYSCREEN);

    // TwC: used API CLRObject
    // BP Deviation Documented
    bitmap          = new System.Drawing.Bitmap(width,height);
    graphics        = System.Drawing.Graphics::FromImage(bitmap);
    graphics.CopyFromScreen(x,y,0,0,bitmap.get_Size());
    }
    catch(exception::Error)
    {
       error("The file could not be saved");
    }
    //Save File
    filepath = WinAPI::getSaveFileName(
    0,
    confilter,
    "",
    "File Save Dialog",
    ".jpg",
    "Untitled");

    // 5 for the My Documents folder
    //SaveToFileName  = strfmt(@"%1\%2",WinApi::getFolderPath(5),#FileName);
    SaveToFileName  = strfmt(@"%1",filepath);
    if(winapi::fileExists(SaveToFileName,false))
    winapi::deleteFile(SaveToFileName);
    bitmap.Save(SaveToFileName, System.Drawing.Imaging.ImageFormat::get_Png());
    if(winapi::fileExists(SaveToFileName,false))
            winapi::shellExecute(SaveToFileName);
}

How to check download speed in asp.net


Description:-

In this article I will explain how to check and find the Internet Connection (Download) speed using C#. A file of known size will be downloaded from a remote server 5-10 times and the time required to download the file is noted. Finally the average of these readings will be used to calculate approximate Internet Connection or Download speed. For more accurate readings, you need to download larger files.

I am downloading a jQuery script file from Google CDN. The size of the file is 261 KB, which I have determined from windows explorer. The download speed of calculated by dividing the size of the file (in KB) with the difference in download start and end time (in seconds).

The above process is repeated 5 times and the result is stored in an array after each iteration. Follow given code to check your internet connection speed (download speed).

Default.aspx:-
<div>
  <asp:Label ID="lblDownloadSpeed" runat="server" />
  <asp:Button ID="Button1" Text="Check Speed" runat="server" OnClick="CheckSpeed" />
</div>

Step 2: Now Call a JavaScript in your webPage

<script type="text/javascript" src="Scripts/advajax.js"></script>

Step 3: Now generate Button Click event to Create Code for Check Download Speed.

Default.aspx.cs:-
protected void CheckSpeed(object sender, EventArgs e)
{
   double[] speeds = new double[5];
   for (int i = 0; i < 5; i++)
   {
      intjQueryFileSize = 261; //Size of File in KB.
      WebClient client = new WebClient();
      DateTime startTime = DateTime.Now;
      client.DownloadFile("http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js", Server.MapPath("~/jQuery.js"));
      DateTime endTime = DateTime.Now;
      speeds[i] = Math.Round((jQueryFileSize / (endTime - startTime).TotalSeconds));
   }
   lblDownloadSpeed.Text = string.Format("Download Speed: {0}KB/s", speeds.Average());
}

NameSpaces:-

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Linq;

Step 4: Now run you WebPage.
Step 5: Click on CheckSpeed button to Check Download Speed.

How to modify vendor or customer account in ax


Description:-

In this article we will look about how to change or modify customer/vendor account number in ax, as we know we can’t change/modify customer/vendor account number in dynamics ax because its unique record and maintain unique key, as customization is also not possible to change/modify directly from the table because if we have transaction for that customer/vendor in inventory then it’s not possible to change directly.

Microsoft provided such facility if you want to change/modify account number, then you can change it to record information and it’s modify all table entries directly you don’t have to spend more time into that. Here I have given information for changing the customer/vendor account number in dynamics ax.

Here I have given example for change/modify vendor account number.
Step-1: if you want to change vendor account number then go to All vendor page and select vendor account which vendor account number you want to change/modify. After right click on it and select “Record info”.

Step-2: after that below pop up will open for record information, with that form click on the Rename button.









Step-3: after click on rename button one pop up will open for entering the new vendor account number like below and you have to enter a new account number.

Step-4: after the confirmation popup will open and asked for renaming the vendor account number like “are you sure you want to rename APPL-000001 to APPL-000010”. You have to click on yes and will take some time if you have more transaction for this vendor.

Issues with deleting inbound port in dynamics ax

Description:-

First thing to note is to delete a Dynamics AX In-Bound port you must ensure that the port is Deactivate. In case you try to delete an Active port, you will get an error message similar to below. The port Inbound port name' must be underplayed before it can be deleted. Just click button Deactivate after selecting the port you want to delete.

Path: System administration > Setup > Services and Application Integration Framework > Inbound ports

Another issue which you might have encountered while trying to delete an inbound port is the error message – "Port cannot be deleted while dependent Gateway queue exist. Delete dependent Gateway queue and try again."

This happens when you have dependent records in Queue manager. The solution is to go to Queue manager and delete all the records which are using the port you want to delete.
Path: System administration > Periodic > Services and Application Integration Framework > Queue manager


Dynamic checkbox checked event in asp.net


Description:-

In this article we will see How to Handle Dynamic Checkbox Checked Event in dot net. Here I have Create Simple demo to Understand Easily. For Create Dynamic Check box you have to Create Checkbox Dynamically in Page_Load event. Here I have Created Check box and Handle that Created Checkbox Event for Check or Uncheck.

You can create much control Dynamically in dot net. Here I have used Checkbox Control to Understand.

Create Webpage and Add Label control for Display Messgae . when we checkd or uncheck from that Check box Control.

Default.aspx:-

<div>
  <asp:Label ID="lblMessage" runat="server" Text="Label"></asp:Label>
</div>

Default.aspx.cs:-

protected void Page_Load(object sender, EventArgs e)
        {
            chkDynamic = new CheckBox();
            chkDynamic.ID = "chkExample";
            chkDynamic.Text = "Check / Uncheck";
            chkDynamic.AutoPostBack = true;
            chkDynamic.CheckedChanged += new EventHandler
                               (chkDynamic_CheckedChanged);
            this.Form.Controls.Add(chkDynamic);
        }

Her is the Checkbox Checked Event perform action on that check Box.

protected void chkDynamic_CheckedChanged (object sender, EventArgs e)
        {
            if (chkDynamic.Checked)
                lblMessage.Text = "you checked the checkbox";
            else if (!chkDynamic.Checked)
                lblMessage.Text = "checkbox is not checked";
        }

Now we are done to perform Checkbox Event. Run your application there you will get Checkbox control for Check or Uncheck.