Customising the Company Login window series – Visual Studio Tools revisited – Visual C#


David Meego - Click for blog homepageJust before I left Microsoft, I was writing a series of blog articles about Customising the Company Login window so that you could see the full company name in the drop down list for long company names.

I had shown how to achieve the customisation with Dexterity and with Visual Basic for Applications, but was having problems getting it to work from Visual Studio Tools.

The problem was that Visual Studio Tools does not have the properties and methods to get and set the sizes of the fields. So the solution was to access the Continuum library to execute pass through Dexterity sanScript instead. My original article is below:

In the article, I explained how I was unable to get the references working to allow me to call the Continuum library. In the end, I ran out of time before I left Microsoft and so I issued a challenge to the community to take my idea and make it work.

Well, Tim Wappat from the Dynamic Coding Blocks blog, took up my challenge and was able to complete the customisation. He explains how he got it working in the following article:

Based on Tim’s article and had another go at making this work and below the steps I used for Visual C#:

  1. Ensure Visual Studio Tools for Microsoft Dynamics GP is installed. If necessary use Mariano’s article to get it installed on later versions of Visual Studio.
  2. Launch Visual Studio and create a new Microsoft Dynamics GP Addin Visual C# project. I called mine SwitchCompanyWidthVC, because I plan to write both a C# and VB.Net version.
  3. In the Solution Explorer, right click on References and select Add Reference.
  4. In the Reference Manager window expand COM and search for “Continuum“.
  5. Select the version of the Dynamics Continuum Integration Library for your version of Microsoft Dynamics GP and click OK.
  6. In the Solution Explorer, right click on References and select Add Reference.
  7. in the Reference Manager windows expand Assemblies and search for “Forms.
  8. Select the System.Windows.Forms assembly and click OK.
  9. In the Solution Explorer, expand References and click on Application.Dynamics. The properties will be displayed. Double click on Copy Local to change it to False.
  10. Repeat previous step for the Microsoft.Dexterity.Bridge reference.
  11. Using Tim’s idea to store the Dexterity sanScript code as a project resource, cut the script below to the clipboard. This is the same script as used in the Dexterity version of the customisation.
  12. In the Solution Explorer, right click on Resources and select Add >> New Item.
  13. In the Add New Item window, under General select Resources File.
  14. Change the Name of the resource from String1 to CompanySwitchScript.
  15. Paste in the Dexterity sanScript code from the clipboard into the Value cell.
  16. Replace the project code with the Visual C# code below.
  17. The changes are:
    1. Adding Namespace for System.Windows.Forms.
    2. Registering the event when the Switch Company form opens.
    3. Handling the event by executing the previously stored Dexterity sanScript code.
  18. From the menus, select Build >> Build Solution.
  19. Copy the file “C:\Users\<Username>\Documents\Visual Studio 2013\Projects\SwitchCompanyWidthVC\SwitchCompanyWidthVC\bin\x86\Debug\SwitchCompanyWidthVC.dll” to your application’s Addins folder.

 

Visual C# code

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

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

public void Initialize()
{
// Register Event to trigger when Switch Company form opens
Microsoft.Dexterity.Applications.Dynamics.Forms.SwitchCompany.OpenAfterOriginal += new EventHandler(SwitchCompanyFormPre);
}

void SwitchCompanyFormPre(object sender, EventArgs e)
{
Dynamics.Application CompilerApp = new Dynamics.Application();
string CompilerMessage = "";
int CompilerError = 0;
// Execute SanScript in Dynamics GP
CompilerError = CompilerApp.ExecuteSanscript(Resources.Resource1.CompanySwitchScript, out CompilerMessage);
if (CompilerError != 0)
{
MessageBox.Show(CompilerMessage);
}
}

}
}

 

 Dexterity sanScript code

local integer l_adjust, h_pos, v_pos, h_size, v_size;

default form to 'Switch Company';
default window to 'Switch Company';

l_adjust = 230;

Field_GetPosition('(L) Company Names', h_pos, v_pos);
Field_GetSize('(L) Company Names', h_size, v_size);

move field '(L) Company Names' to h_pos - l_adjust, -1;
resize field '(L) Company Names' to h_size + l_adjust, -1;

move field '(L) RememberMe' to h_pos - l_adjust, -1;
resize field '(L) RememberMe' to h_size + l_adjust, -1;

move field '(L) SQL Server' to h_pos - l_adjust, -1;
resize field '(L) SQL Server' to h_size + l_adjust, -1;

move field 'User ID' to h_pos - l_adjust, -1;
resize field 'User ID' to h_size + l_adjust, -1;

move field '(L) Number of Users In' to h_pos - l_adjust, -1;
{resize field '(L) Number of Users In' to h_size + l_adjust, -1;
}
move field 'Max Number User In System'[1] to h_pos - l_adjust, -1;
{resize field 'Max Number User In System'[1] to h_size + l_adjust, -1;
}

 

The end result is now the Switch company window has been modified via Visual Studio Tools.

SwitchCompanyWidth

Note: This code is a great example of using pass through Dexterity code from Visual C#, however this technique is not supported by Microsoft.

Thanks to Tim Wappat for pointing me in the right direction.

David

This article was originally posted on http://www.winthropdc.com/blog.

Advertisements

9 thoughts on “Customising the Company Login window series – Visual Studio Tools revisited – Visual C#

Please post feedback or comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s