Getting Started with VST: WinForms and Controls – Part 1

July 31, 2009

If you have been around Microsoft Dexterity long enough, by now you are already aware that Dex is not an object oriented development environment, and rather supports a concept called object-based development. In the traditional sense, Dexterity does not allow you to define classes and derive objects from those classes. However, someone figured out that a Dexterity form can act as a container or class, with the Scripts and Functions tabs allowing you to define the contructors, destructors and methods for the class. In addition, adding fields to a window and setting the proper values for those fields allows developers to set the state of an object. Given the nature of the form and how the scripts on that form are called, and the values for fields on windows are set, forms can simulate classes with public and private methods in traditional object oriented programming terms.

Thank goodness, you don’t need to do all this in Visual Studio! VST allows you to define a WinForm, or in simple terms, a Windows Form. Forms in VST cannot be grouped as you would normally do in Dexterity, so in that sense, they behave like typical Dexterity window, but they still provide all the functionality, including the look and feel due to the inherited properties created with the Dexterity Bridge assembly.

Customer Hobbies WinForm

Our example today, will show how to add the equivalent of a Dexterity form trigger, known in VST as a menu handler event. Typically, form triggers add an entry to the Additional menu on a Dexterity form. Today, we will add a Customer Hobbies form and will then add a menu handler event to the Customer Maintenance form to call our form.

1) Open Visual Studio. Go to File > New > Project to create a new Visual Studio project.

2) Find the Dynamics GP in the Project Types pane, then choose Microsoft Dynamics GP Add-In from the installed templates pane.

3) Enter a name for the project. We will be naming our project GPWinForm.

4) Click OK to continue

5) Make sure your GPAddIn.cs code looks like this:

GPAddIn.cs


using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Dexterity.Bridge;
using Microsoft.Dexterity.Applications;
using Microsoft.Dexterity.Applications.DynamicsDictionary;

namespace GPWinForm
{
public class GPAddIn : IDexterityAddIn
{
// IDexterityAddIn interface

public void Initialize()
{

}
}
}

6) We will first define our WinForm. In Solution Explorer, right-click on the project name and navigate to Add > New Item as shown in the figure below.

7) In the Add New Item window we will highlight Microsoft Dynamics GP Form and name our form rmCustomerHobbies.cs. Click on Add to continue.

8) Here comes VST into play! When the form is defined, you will notice a set of providers at the bottom of the design window, as shown below.

These providers allow WinForms and certain controls to inherit properties unique to Dexterity windows and controls. In the example, our WinForm is given a Control area and a Status area by default. To change the window title, locate the Text property in the Properties window and edit to Customer Hobbies.

9) Now, let’s add some controls — you will need to resize your window accordingly. We will add a few prompts (known as labels in Visual Studio) and a few strings (known as text boxes in Visual Studio). First our text boxes:

a) Click on the TextBox control in the Toolbox. We will add the CustomerNumber field. Set the properties for the field as follow:


b) Now, let’s add the CustomerName field. We can follow the same steps used in (a). At the end your window should look like this:


In traditional Dexterity style, these two fields will inherit the values displayed in the Customer Maintenance window when a record is selected and the Customer Hobbies window is selected.

10) Now we can add the labels that will identify our fields when the window is opened. We will add the Customer ID and Customer Name labels, but most importantly, show how you can link fields to their prompts as well, just like in Dexterity.

a) Click on the Label control in the Toolbox. Now place the label in from of the CustomerNumber field. Size the label accordingly and align accordingly. Set the label properties as follow:

NOTE: Unlike Dexterity, label controls are referenciable via code, hence the Name property of the control.

b) Repeat step (a) for the Customer Name label and set the propeties as well.


11) Now let’s proceed to link the fields to their prompts. One of the properties unique to VST label controls is the LinkField on dexLabelProvider. This property will display a drop-down list that will allow you to select the corresponding window field for the label, as shown below:


Once a label is linked to a textbox, you will see the traditional underline that accompanies all Dexterity prompts.

12) Following the same guidelines, we will add 4 more text boxes, rmCustomerSports, rmCustomerSportsTeam, rmCustomerLeisureActivity, and rmCustomerRestaurant, and the corresponding labels to indicate the customer’s hobbies. Note that the Enabled property for these new controls must be set to True to allow the controls to receive data. We will also use an empty label from the Toolbox to create the separator between the window’s static section and the data entry section, a la Dexterity. Your final window should look like this — don’t worry if you did not get the same results, I have uploaded the solution for your benefit.


Part 2 of the “WinForms and Controls” series will discuss adding the typical buttons to the screen, like the Ok button, the window help button and the window notes buttons. In addition to the code needed to produce the menu handler event.

Downloads

GPWinForm Solution – click here.

Until next post!

MG.-
Mariano Gomez, MVP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com/

Updates to this article
08/07/2009 – Fixed broken link to solution download.

Advertisements

New Article on MSDynamicsWorld: "Implementation Advocates"

July 29, 2009

” By definition… I could not take either the customer’s side or the partner’s side in my assessment”

My new article on MSDynamicsWorld is up! In this article, I discuss a specific case that happened a few months aback in which I had a chance not to play the devil’s advocate, but rather the devils’ advocate — If you are familiar with the English language grammar, you probably know the distinction between devil’s and devils’. Please read the article as it contains important information about my professional experiences as a consultant working with Microsoft Dynamics GP customers and partners and gives an insight into what’s happening in the implementation world.

Until next post!

MG.-
Mariano Gomez, MVP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com


Microsoft Dynamics GP in Russian – Microsoft Dynamics Г.П. на русском языке

July 28, 2009

For the past few months I took it up on myself to produce a translated Russian version of Dynamics GP. What began as fun little project in response to seeing a lot of GP information in Russian on Partnersource, is now showing some remarkable results. I have managed to translate 45% of the string resources and adjust the screens accordingly aided by numerous accounting software books I ordered from Moscow — and my wife who is from Moscow herself 🙂 — to get the proper terms and meaning in place.

Here is a sample of some of the screens (more to come),

Dynamics GP Login Window

Account Maintenance Window

Customer Maintenance Window

Unlike Chinese or Korean, the Cyrilic alphabet is not a double-byte alphabet and can easily be managed by Dexterity. However, this project was met with its own set of challenges when I started the translation process, for example, how to get Microsoft Windows to display Cyrilic characters to begin with. I sorted this out by installing Dynamics GP on a server with a default Russian locale configured. The reason this is important, as I discovered, is because ANSI characters have different values depending on the Windows locale. This way, as strings were translated in my Notepad text file, Dexterity would be able to read and display them in their native format (as long as they were not double byte characters).

For more information on the translation process I used, please take a look at Dave Musgrave‘s Translating Dexterity Applications Series of articles.

I will provide more information about the progress of this fun project and, hey!, may even consider partnering opportunities. After all, as you all know Dynamics AX is the only Microsoft product being distributed in Eastern Europe.

Until next post!

MG.-
Mariano Gomez, MVP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com/


Dynamics MVP recognised for contribution to Support Debugging Tool!

July 27, 2009

The Microsoft MVP Award Program Blog has a post up on my efforts and contributions to build 11 of Support Debugging Tool. The article highlights my input to the email engine now available in SDT. To read the full article, click here.

Until next post!

MG.-
Mariano Gomez, MVP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com/


Getting started with VST: "Hello World!" – The Video

July 24, 2009

1st Online Conference for Great Plains Arabia

July 22, 2009

Fellow Microsoft Dynamics GP MVP Monzer Osama is organizing the 1st Online Conference for Great Plains Arabia community – http://www.GP4Arab.com/forum. Monzer is the founder and moderator of this leading GP community in the Middle East of more than 2,000 partners and users. Monzer elaborates, “I will talk about how to connect Microsoft Excel to Microsoft SQL Server externally, and using Pivot tables and Pivot Charts as a reporting and analysis tools , then I will explain how that data will [refresh] automatically.

Sessions will be conducted in a workshop format, making the agenda very hands-on. If you are interested in joining the event, here is the session information:


Event link: http://gp4arab.eventbrite.com/
Date: Wednesday, July 29, 2009
Time: 6:00 PM – 7:00 PM (Saudi Arabia Time zone GMT+0300)

Monzer will attempt to present this session in English at a later date.

Until next post!

MG.-
Mariano Gomez, MVP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com/


Getting started with VST: "Hello World!" project

July 21, 2009

Adventures of a Microsoft Dexterity Developer

Okay, so we did not get this far to bring up a “Hello World” message, but I figured that’s a pretty standard thing to do in the software development world to introduce a tool or language to software developers, so I am not going to pass upon the chance!

Creating our first Visual Studio Tools project… with a twist!

For this project, we want to be able to register two events that will allow us to display the messages “Getting ready to say Hello World!” and “Hello World” messages after login is successful and before and after the Toolbar form is loaded. Usually, this method of trigger registration is used by Dexterity developers to run code after log in, so I figured I would replicate something we are most familiar with.

Topics being covered

  • Creating a VST project
  • Events registration
  • Running your code before and after login
  • Building and Deploying VST project

Let’s get started!

1) Open Visual Studio. Go to File > New > Project to create a new Visual Studio project.

2) Find the Dynamics GP in the Project Types pane, then choose Microsoft Dynamics GP Add-In from the installed templates pane.

3) Enter a name for the project. We will be naming our project GPHelloWorld.

4) Click OK to continue.


NOTE: As indicated, I will be using C# as my development language, however, the steps to initiate the project for VB.NET should be the same.

5) Upon clicking OK, Visual Studio will proceed to initialize our project for us. The first thing you will see is the Initialize() method in the GPAddIn class. The GPAddIn is an implementation of the IDexterityAddIn interface. Sufficient to say, the Initialize() method is equivalent to the global Startup script in a Dexterity integrating application, serving as entry point to the add-in project.

GPAddIn.cs


using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Dexterity.Bridge;
using Microsoft.Dexterity.Applications;

namespace GPHelloWorld
{
public class GPAddIn : IDexterityAddIn
{
// IDexterityAddIn interface
public void Initialize()
{

}
}
}

NOTE the Solution Explorer window will show the references to the primary assembly responsible for exposing Dynamics GP resources: the Microsoft.Dexterity.Bridge assembly. As well, you can find all picture resources that will make our VST controls look awefully similar to the standard controls available to integrating Dexterity applications.

6) Now, we will proceed to register the event on the Toolbar form. We will display a message “Getting ready to say Hello World!” before the toolbar form is loaded and one that says “Hello World!” after the toolbar is loaded. You can then decide what event works best for your individual needs.

GPAddIn.cs


using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Microsoft.Dexterity.Bridge;
using Microsoft.Dexterity.Applications;
using Microsoft.Dexterity.Applications.DynamicsDictionary;


namespace GPHelloWorld
{
public class GPAddIn : IDexterityAddIn
{
// IDexterityAddIn interface
public void Initialize()
{
ToolbarForm toolbar;
toolbar = Dynamics.Forms.Toolbar;

// add registration before the form open event
toolbar.OpenBeforeOriginal += new System.ComponentModel.CancelEventHandler(toolbar_OpenBeforeOriginal);

// add registration after the form open event
toolbar.OpenAfterOriginal += new EventHandler(toolbar_OpenAfterOriginal);
}

void toolbar_OpenBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)
{
MessageBox.Show("Getting ready to say Hello World!");
}

void toolbar_OpenAfterOriginal(object sender, EventArgs e)
{
MessageBox.Show("Hello World!");

}
}
}

A couple things to highlight in the code:

a) Like references in Dexterity, VST allows you to create variables that point to specific dictionary resources. The definitions for the various dictionary resources are found in an additional namespace available in the application assembly, Microsoft.Dexterity.Applications.DynamicsDictionary.


using Microsoft.Dexterity.Applications.DynamicsDictionary;

Once the namespace is added, you can then proceed to declare a variable that will represent the Toolbar form.


public void Initialize()
{
ToolbarForm toolbar;
toolbar = Dynamics.Forms.Toolbar;
.
.
}

b) An event registration is the Visual Studio equivalent of a Dexterity trigger. As such, they must be included in the Initialize() method, added automatically when the project was created. The Initialize() method is the equivalent of the Startup() script in a Dexterity integrating application. To register the events that will be executed before and after the Toolbar form is loaded, the following code was added,


// add registration before the form open event
toolbar.OpenBeforeOriginal += new System.ComponentModel.CancelEventHandler(toolbar_OpenBeforeOriginal);

// add registration after the form open event
toolbar.OpenAfterOriginal += new EventHandler(toolbar_OpenAfterOriginal);

If you noticed when you typed the += character sequence, you were prompted to press the TAB key twice! Intellisense automatically completed the code and added the overload methods for each event handler. Now, that’s a time saver! Imagine if we had this type of capability when adding the trigger registration scripts in Dexterity!

c) The rest was just cosmetics.. I added the MessageBox.Show() function to display our two messages in each overload method. The MessageBox is part of the System.Windows.Forms namespace which must be added to the using section of the application.


void toolbar_OpenBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)

{
MessageBox.Show("Getting ready to say Hello World!");
}

void toolbar_OpenAfterOriginal(object sender, EventArgs e)
{
MessageBox.Show("Hello World!");
}

Simple enough!

7) Building the solution is done via the Build menu, but before, we can set our final assembly name by right-clicking on the GPHelloWorld project in the Solution Explorer window and selecting the Properties option.

8) Build the solution. You should be able to find your new assembly in the Bin\Debug folder of the solution directory, typically under C:\Users\yourUser\Documents\Visual Studio 2008\Projects\GPHelloWorld\GPHelloWorld\bin\Debug.

Copy the resulting project assembly to the AddIns folder under your Microsoft Dynamics GP installation directory.

Testing the solution

Open Microsoft Dynamics GP to see the results. Before the Toolbar form is loaded, we will receive the first message:

Once the Toolbar form is loaded, our next message will be displayed, as follows:


I guess this is not bad for a first try, is it?

While integrating solutions tend to be a lot more complex than our Hello World application, the principles will be the same. For our next installment, I will be contructing a WinForm and showing common ways to store and retrieve data in a VST solution.

Downloads

HelloWorld Solution C# – Click here
HelloWorld Solution VB.NET – Click here

Until next post!

MG.-
Mariano Gomez, MVP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com/