Click here to Skip to main content
15,867,453 members
Articles / Programming Languages / C# 3.5

Integrate Microsoft Dynamics Axapta with Temperature Conversion C# Application - Part II

Rate me:
Please Sign up or sign in to vote.
4.86/5 (6 votes)
14 Dec 2010CPOL5 min read 71.6K   1.1K   13   8
This article will demonstrate that after sending the data from Axapta to Temperature conversion application, how we can post back the converted temperature to Axapta.

Introduction

To understand this article, one has to go through Part I. This will be useful for those ISVs or clients who would like to send the data back to Axapta after processing from third party application. As earlier stated in Part I, when temperature will be converted, then the temperature data can be sent back to Axapta by using C# application. My main intention to develop and publish these articles is to help the ISVs and clients for having POC about the integration of their existing applications with Axapta.

In order to understand the advantage of this article, please read the following scenario:

We have the data in Axapta which needs to operate by some processes. Client or ISV is already having the third party application which has all desired functionalities to process the data. This kind of integration I had published in Part I of this article. Now there is a greater extent of requirement to again update the Axapta with process data from third party application. This functionality is beautifully demonstrated with the help of Temperature conversion application.

To demonstrate this POC, I modified the same application which I developed in my Part I.

To understand this POC, one should be proficient regarding Object oriented concepts for C# and Axapta. One should have extensive working experience in Axapta and C#.

Here, I will not only give the source code but also the description about the code that I added to Part I .

Let’s begin this interesting journey…

Background

To develop the Axapta connector, one should have extensive knowledge of X++ and C#. This means that one should have working knowledge of object oriented programming.

To understand this article, one should go through Part I. In addition to that, one should have Axapta with SQL Server 2005 and Visual Studio 2008 with SP1 installed on their system.

Modification 1: Creation of AxHelper Class

This class contains the code to connect to Axapta from Temperature Conversion application.

C#
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.Dynamics.BusinessConnectorNet; 
namespace CvrtC2Frnt 
{ Microsoft.Dynamics.BusinessConnectorNet 
class AxHelper:BC 
{ 
	BC bc = new BC(); 
	Axapta ax; 
	string tableName = "SalesTable"; 
	AxaptaRecord axRecord; 
	public void SetAxRec(Boolean Farenhite, double Temp, string SalesId) 
	{ 
		ax = bc.GetAxConnection(); 
		if (ax != null) 
		{ 
			using (axRecord = ax.CreateAxaptaRecord(tableName)) 
			{ 
				ax.TTSBegin(); 
				axRecord.ExecuteStmt("select forupdate * 
				from %1 where %1.SalesId ==" + "'" + SalesId + "'" ); 
				axRecord.set_Field(50001, Temp); 
				if (Farenhite == true) 
					axRecord.set_Field(50002, 1); 
				else 
					axRecord.set_Field(50002, 0); 
				axRecord.Update(); 
				ax.TTSCommit(); 
			} 
		} 
	} 
} 
}

The above code clearly specifies that we are using Microsoft.Dynamics.BusinessConnectorNet DLL to send the data to Axapta.

Modification 2: Creation of BC Class

C#
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.Dynamics.BusinessConnectorNet; 
namespace CvrtC2Frnt 
{ 
class BC 
{ 
	Axapta ax; 
	AxaptaRecord axRecord; 
	public Axapta GetAxConnection() 
	{ 
		ax = new Axapta(); 
		ax.Logon(null, null, null, null); 
		return ax; 
	} 
} 
}

The above helps to connect to Axapta.

Modification 3: Modify ConverTemp Class

C#
namespace CvrtC2Frnt 
{ 
public class ConvertTemp 
{ 
	public static double sourceTemp=0, destTemp=0; 
	public static bool Faren = false; 
	public static string SalesId = string.Empty; 
	public static double ConvertCelsiusToFahrenheit(double c) 
	{ 
		destTemp = 0; 
		destTemp = ((9.0 / 5.0) * c) + 32; 
		return ((9.0 / 5.0) * c) + 32; 
	} 
	public static double ConvertFahrenheitToCelsius(double f) 
	{ 
		destTemp = 0; 
		destTemp = (5.0 / 9.0) * (f - 32); 
		return (5.0 / 9.0) * (f - 32); 
	} 
	public void ShowResult( double Temperature,bool Farenhite, string salesId) 
	{ 
		ShowTemperature sT = new ShowTemperature(Temperature, Farenhite, salesId); 
		sT.Show(); 
	} 
} 
}

In the above code, SalesID is added so that we can modify the SalesTable in Axapta for the converted temperature.

Modification 4: Modify Convert Button

C#
private void btnConvert_Click(object sender, EventArgs e) 
{ 
	AxHelper axhlp = new AxHelper(); 
	if (ConvertTemp.Faren == true) 
	{ 
		txtDestTmp.Text = Convert.ToString(ConvertTemp.
			ConvertFahrenheitToCelsius(double.Parse(txtSourceTmp.Text))); 
		axhlp.SetAxRec(false, ConvertTemp.ConvertFahrenheitToCelsius
			(double.Parse(txtSourceTmp.Text)),ConvertTemp.SalesId); 
	} 
	if (ConvertTemp.Faren == false) 
	{ 
		txtDestTmp.Text = Convert.ToString(ConvertTemp.
			ConvertCelsiusToFahrenheit(double.Parse(txtSourceTmp.Text))); 
		axhlp.SetAxRec(true, ConvertTemp.ConvertCelsiusToFahrenheit
			(double.Parse(txtSourceTmp.Text)), ConvertTemp.SalesId); 
	} 
}

In the above code, ConvertCelsiusToFahrenheit is now taking three parameters to update the SalesTable after converting temperature.

Modification 5: Modify ShowTemperature Constructor

C#
public ShowTemperature(double Temperature, Boolean Fahrenheit, string SalesId) 
{ 
	InitializeComponent(); 
	txtSourceTmp.Text = Temperature.ToString(); 
	ConvertTemp.Faren = Fahrenheit; 
	ConvertTemp.sourceTemp = Temperature; 
	ConvertTemp.SalesId = SalesId; 
}

In the above code, SalesID is now also initializing with value from Axapta so that we can update the SalesTable with the converted temperature by C# application.

Modification 6: Modify the ConvertTemperature Class in Axapta

C#
void ConvertTemperature(real Temperature, Boolean Fahrenheit, str SalesId) 
{ 
	ct = new CvrtC2Frnt.ConvertTemp(); 
	ct.ShowResult(Temperature, Fahrenheit, SalesId); 
}

In the above, SalesID is added as a third parameter.

Modification 7: Modify the Clicked Function for ConvertTemperature Button on SalesTable in Axapta

C#
void clicked() 
{ 
	Temperature tem = new Temperature(); 
	; 
	tem.ConvertTemperature( element.salesTable().Temperature, 
		element.salesTable().Farenhite, element.salesTable().SalesId); 
	super(); 
}

Now finally let’s have a demo…

Demo 1

Pic3.jpg

On the above SalesTable Axapta form, key in the Temperature as 45 and uncheck Fahrenheit. This means that Temperature is 45 degree Celsius. Click on Convert Temperature button on the above form.

Click on Convert button on Convert Temperature C# form.

Pic5.jpg

On the above Sales Order form in Axapta, Temperature is converted to Fahrenheit.

This is it!

In this article, not only temperature is converted but also posted to Axapta SalesOrder.

I have another surprise in this article. Upto now, I had integrated ConvertTemperature application with SalesOrder Card form but now in Demo 2, one can see how easily we can integrate it to SalesListPage of Axapta.

Let us start …

Demo 2

On the above SalesOrderList page, one can see the Temperature Add-on tab on Action page. Two command buttons one can see, i.e.:

a) Refresh – To refresh the SalesOrderList page.

Convert Temperature- This will populate the same Convert Temperature form from C# as it was coming from SalesCard form.

Pic7.jpg

On the above form, click on Covert button to convert the 45 degree Celsius to Fahrenheit.

Pic8.jpg

We can see that 45 degree Celsius is converted to 113 Fahrenheit. The converted temperature is also updated in SalesList Page. To see that, click on refresh button on SalesList Page.

Pic9.jpg

You got the converted temperature in Axapta SalesList page too via C#.

I am providing complete C# code and Axapta code so that any ISV, client and developers can understand that how we can use the UI and logic of any third party application in C# with Axapta records to process it and again posting back to Axapta. Big and small organization always looks for this kind of two way integration to save time and effort for implementing new functionalities in ERP. Instead of implementing new functionality in ERP, we can integrate the third party application to ERP for achieving the desired functionality.

Please note that this Temperature conversion application can also easily be integrated with Microsoft Dynamics Navision by writing only 8 lines of code. This means that developers should have working knowledge of C# and Axapta. They should also follow the best practices prescribed by Product owner. In our case, it is Microsoft. As I had worked on lot of integrations project for Axapta and Navision for Various ISV's, developers should know the ERP very well technically. If the ERP is Axapta, then one should know the Object oriented concepts and at least 2 years of Axapta experience with at least 1 year of C# experience. C# is important as without the C# experience, developers who only know Navision or Axapta will be 95% idle. Now a days integrating Axapta and Navision is becoming very easy, matter of 8 hours only with any other application. We should give full credit to Microsoft as they had exposed the business logic and code of Axapta and Navision through web service. So folks, happy coding, but be very careful as you going to play with the financial data which is very crucial to any client... 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Kanasz Robert1-Dec-11 2:52
professionalKanasz Robert1-Dec-11 2:52 
GeneralMy vote of 5 Pin
prasad0222-Dec-10 4:09
prasad0222-Dec-10 4:09 
GeneralRe: My vote of 5 Pin
abhishek pareek200923-Dec-10 3:08
abhishek pareek200923-Dec-10 3:08 
GeneralMy vote of 5 Pin
John_1713-Dec-10 22:08
John_1713-Dec-10 22:08 
GeneralRe: My vote of 5 Pin
abhishek pareek200923-Dec-10 3:08
abhishek pareek200923-Dec-10 3:08 
GeneralMy vote of 5 Pin
cemalcanefe9-Dec-10 1:41
cemalcanefe9-Dec-10 1:41 
GeneralRe: My vote of 5 Pin
abhishek pareek200923-Dec-10 3:08
abhishek pareek200923-Dec-10 3:08 
GeneralPlease format Pin
tec-goblin6-Dec-10 12:16
tec-goblin6-Dec-10 12:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.