AXForum  
Вернуться   AXForum > Microsoft Dynamics CRM > Dynamics CRM: Blogs
DAX
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 19.04.2008, 12:28   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
Introduction:


This post describes the simplest possible way to get started with creating a .net project in Microsoft Visual Studio, and use C/Front in c# code to connecct to a Microsoft Dynamics NAV database. The example here is based on the sample from the product CD, which will install to this folder: C:Program FilesMicrosoft Dynamics NAVSDKCFRONTDotNetSampleApplication. More details can be seen from that sample, and I will also make further blog posts to describe further use of C/Front. For this post, all we want to do is to make a connection.


The example here was made in Visual Studio 2008. You can do the same in Visual Studio 2005. The NAV database in this example is running on SQL Server. To make it connect to a Native NAV database you nee to adjust NetType and DriverType.


Time to complete: Approximately 20 minutes.



Example:


C/Front is part of SDK (Software Developers Kit), which also includes the Communication Components. If you haven't installed it already, then install SDK from the NAV product CD. Then follow the steps below:


1) Open Microsoft visual Studio 2005/2008


2) Create a new project (File -> New -> Project). As project type, select "Visual c#", then select "Windows Forms Application". Type in a name and click OK.


3) Include C/Front to your project by rightclicking on "References" on the right hand side, under "Solution Explorer", and select "Add Reference". Go to the Browse-tab, and select Microsoft.Navision.CFront.CFrontDotNet.dll. As default this is installed in this folder: C:Program FilesMicrosoft Dynamics NAVSDKCFRONT.


4) Now, add a button to your Form (View -> Toolbox, then double-click a button to add it). Also add a TextBox so we have a place to display data from C/Front. Double-click on the button to get to the code.


5) At the top of the code-window where Visual Studio has already added a number of "using"-commands, also add a line for C/Front: using Microsoft.Navision.CFront;


6) All the preparations done, we are now ready to program with C/Front. Go back down the the function "privatevoid button1_Click", and copy in the code below. Just adjust values NavisionPath, ServerName and CompanyName to match your system:



// Declare specific C/Front variables


NavisionNetType NetType;


NavisionDriverType DriverType;


NavisionValue Data;


// Set Net Type and Driver Type (SQL or native)


DriverType =
NavisionDriverType.Sql;


NetType =
NavisionNetType.SqlDefault;


CFrontDotNet.DriverType = DriverType;


int CT; // Currentt Table. Keep name short, since we need to type it in a lot


int CR; // CurrentRecord. Keep name short, as above


CFrontDotNet.NavisionPath = "C:ClientsW15SP1RTM";


CFrontDotNet.Instance.ConnectServerAndOpenDatabase("Lohndorf1", NetType, "W1500SP1", 2000, true, true, "", "");


CFrontDotNet.Instance.OpenCompany("CRONUS International Ltd.");


CT =
CFrontDotNet.Instance.OpenTable(18);


CR =
CFrontDotNet.Instance.AllocRecord(CT);


CFrontDotNet.Instance.FindFirstRecord(CT, CR);


Data =
CFrontDotNet.Instance.GetFieldData(CT, CR, 2);


NavisionText NAVText;


NAVText = Data;


textBox1.Text = NAVText.ToString();


// Important: Close down Navision when finished.


CFrontDotNet.Instance.FreeRecord(CR);


CFrontDotNet.Instance.CloseTable(CT);


CFrontDotNet.Instance.CloseCompany();


CFrontDotNet.Instance.CloseDatabase();


CFrontDotNet.Instance.DisconnectServer();


CFrontDotNet.Instance.Dispose();





7) Save the project. As default it will save to this folder: C:Users[UserName]DocumentsVisual Studio 2008ProjectsCFrontSampleVS2008[ProjectName]


8) Finally, copy the files CFront.dll and CFrontSQL.dll from the C/Front folder (default C:Program FilesMicrosoft Dynamics NAVSDKCFRONT) into the project sub-folder binDebug



Now try to run it. Build the project first (Buld -> Build [ProjectName]), and check that it builds without errors. Then run it (Debug -> Start Debugging - F5). If succesful, it will display the customer name of the first customer on the form.


Comments:


Always set the NavisionPath and point it to a NAV client folder of the same version as C/Front. This is where C/Front will locate essential files like dlls, flf and stx files. If you don't set this path, you are likely to get error 2 in module 1 ("The system cannot find the file specified.").


C/Front requires granule 1,800 C/FRONT. It connects just like a normal client, so it will also consume a normal user session while connected.






Lars Lohndorf-Larsen


Microsoft Dynamics UK



Microsoft Customer Service and Support (CSS) EMEA


These postings are provided "AS IS" with no warranties and confer no rights. You assume all risk for your use.



Читать дальше
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 


Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 22:01.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.