Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

Microsoft Dynamic CRM 4.0 : MapPoint Integration (part 1) - MapPoint 2009

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/18/2011 5:52:17 PM
MapPoint is an extendable product and technology that enables users to create complex mapping and data scenarios. It is significantly more sophisticated than the other mapping technologies in that it has geographic information system (GIS) integration with latitude and longitude options. We have included it within its own section because the application, MapPoint 2009, can be used without an Internet connection, which is a common scenario where users don’t have access to call the MapPoint web services.

We will review two different options:

  • Windows-based usage of MapPoint 2009 (without Internet connection)

  • MapPoint web service integration (Internet connection required)

MapPoint 2009

With this option, we can leverage the MapPoint 2009 software development kit (SDK) to display Microsoft Dynamics CRM data within the application.

Note

It is important to note that MapPoint is a compiled .NET application and not a web application.


In the example, we modify a MapPoint user interface control and create a text box that shows the Microsoft Dynamics CRM accounts based on the account name, add a Search button, and a data grid to show the resulting/matching accounts and finally include a Locate button that locates the selected address on the MapPoint map.

The Search button includes the business logic to fetch the Microsoft Dynamics CRM accounts using a fetch query based on the user input to retrieve all the accounts in Microsoft Dynamics CRM that match the account name entered in the text box. Figure 1 shows the final custom application.

Figure 1. MapPoint 2009 with custom CRM integration for accounts.

To deploy the Windows-based usage of MapPoint 2009, complete the following steps:

1.
On a computer that has MapPoint 2009 installed, create a new Windows application and reference the MapPoint assemblies.

2.
Create two class files: one for Business Logic and one for Data Access.

For the Business Logic page, use this code:

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Data;
using System.Configuration;
using System.Text;
using System.Xml;

namespace MapPointApp
{
class BusinessLogic
{
#region Global Declaration
DataAccessLayer mscrmAccess = null;
#endregion

public BusinessLogic()
{
mscrmAccess = new DataAccessLayer();
}

public DataTable GetAccountDetails(string accName)
{
StringBuilder fetchXML = new StringBuilder();
fetchXML.Append(@"<fetch mapping=""logical""><entity name=""account"">");
fetchXML.Append(@"<attribute name=""name"" />");
fetchXML.Append(@"<attribute name=""address1_line1"" />");
fetchXML.Append(@"<attribute name=""address1_city"" />");
fetchXML.Append(@"<attribute name=""address1_stateorprovince"" />");
fetchXML.Append(@"<attribute name=""address1_postalcode"" />");
fetchXML.Append(@"<filter><condition attribute=""name"" operator=""like"" value=""");
fetchXML.Append(accName);
fetchXML.Append(@"%""/></filter></entity></fetch>");

string resultSet = mscrmAccess.ExecuteCRMQuery(fetchXML.ToString());
XmlDocument xmlDocument = new XmlDocument();

xmlDocument.LoadXml(resultSet);
string xPath = @"/resultset/result";
XmlNodeList xmlNodeList = xmlDocument.SelectNodes(xPath);

DataTable caseDataTable = new DataTable();

DataColumn dColumn;

dColumn = new DataColumn();
dColumn.DataType = Type.GetType("System.String");
dColumn.ColumnName = "AccountName";
caseDataTable.Columns.Add(dColumn);

dColumn = new DataColumn();
dColumn.DataType = Type.GetType("System.String");
dColumn.ColumnName = "Street";
caseDataTable.Columns.Add(dColumn);

dColumn = new DataColumn();
dColumn.DataType = Type.GetType("System.String");
dColumn.ColumnName = "City";
caseDataTable.Columns.Add(dColumn);

dColumn = new DataColumn();
dColumn.DataType = Type.GetType("System.String");
dColumn.ColumnName = "State";
caseDataTable.Columns.Add(dColumn);

dColumn = new DataColumn();
dColumn.DataType = Type.GetType("System.String");
dColumn.ColumnName = "PostalCode";
caseDataTable.Columns.Add(dColumn);

foreach (XmlNode node in xmlNodeList)
{
DataRow dRow = caseDataTable.NewRow();
if (node.SelectSingleNode("name") != null)
{
dRow["AccountName"] =node.SelectSingleNode("name").InnerText;
}
if (node.SelectSingleNode("address1_line1") != null)
{
dRow["Street"] =node.SelectSingleNode("address1_line1").InnerText;
}
if (node.SelectSingleNode("address1_city") != null)
{
dRow["City"] =node.SelectSingleNode("address1_city").InnerText;
}
if (node.SelectSingleNode("address1_stateorprovince") != null)
{
dRow["State"] = node.SelectSingleNode("address1_stateorprovince").InnerText;
}
if (node.SelectSingleNode("address1_postalcode") != null)
{
dRow["PostalCode"] = node.SelectSingleNode("address1_postalcode").InnerText;
}
caseDataTable.Rows.Add(dRow);
}

return caseDataTable;
}

}
}


For the Data Access layer, use this code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Services.Protocols;
using MapPointApp.CRMSDK;

namespace MapPointApp
{
class DataAccessLayer
{
#region global Declaration
protected string crmServer = null;
protected CrmService crmService = null;
protected string crmWebServicesUrl = null;
#endregion

public DataAccessLayer()
{
crmServer = "http://192.168.0.1:5555/mscrmservices";
string userName = "administrator";
string userPwd = "password";
string userDomain = "crmdev";
string crmOrgName = "Webfortis";

if (crmServer.Length == 0 || (!crmServer.StartsWith("http://") && !crmServer.StartsWith("https://")))
{
throw new ApplicationException("CRM server url is wrong, please contact your system administrator.");
}

if (!crmServer.EndsWith("/"))
{
crmServer += "/2007/";
}
else
{
crmServer += "2007/";
}

crmWebServicesUrl = string.Concat(crmServer, "CrmService.asmx");


crmService = new CrmService();
crmService.Url = crmWebServicesUrl;
crmService.Credentials = new System.Net.NetworkCredential(userName, userPwd, userDomain);

crmService.PreAuthenticate = true;
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.OrganizationName = crmOrgName;
token.AuthenticationType = 0;
crmService.CrmAuthenticationTokenValue = token;
}

public string ExecuteCRMQuery(string fetchXML)
{
try
{
//Fetch XML Execution
return crmService.Fetch(fetchXML);
}
catch (SoapException Ex)
{
throw new ApplicationException("Unable to retrieve CRM records. Please contact your system administrator", Ex);
}
catch (Exception Ex)
{
throw new ApplicationException("Unable to retrieve CRM records. Please contact your system administrator", Ex);
}
}
}
}


Be sure to change the section in the Data Access layer with your server, username, user password, domain, and organization, as shown in Figure 2.



Figure 2. Server-specific credentials.

3.
Create a new form within the solution with the following code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MapPointApp
{
public partial class Form1 : Form
{

#region Global Declaration
BusinessLogic bLogic = null;
MapPoint.Map objMap = null;
MapPoint.Location objLoc = null;
MapPoint.FindResults objResults = null;
MapPoint.Pushpin objPushpin = null;
MapPoint.Symbol objSymbol = null;
object key = 1;
#endregion

public Form1()
{
InitializeComponent();

bLogic = new BusinessLogic();

objMap = MPC.NewMap(MapPoint.GeoMapRegion.geoMapNorthAmerica);

}

public void GetAccountDetails()
{
DataTable accountTable = bLogic.GetAccountDetails(txtAccName.Text);
dataGridView1.DataSource = accountTable;
}

private void btnLocate_Click(object sender, EventArgs e)
{
DataGridViewRow selectedRow = dataGridView1.SelectedRows[0];

string accName = selectedRow.Cells[0].Value.ToString();
string street = selectedRow.Cells[1].Value.ToString();
string city = selectedRow.Cells[2].Value.ToString();
string state = selectedRow.Cells[3].Value.ToString();
string postalCode = selectedRow.Cells[4].Value.ToString();

objResults = objMap.FindAddressResults(street, city, "", state, postalCode, MapPoint.GeoCountry.geoCountryUnitedStates);

objLoc = (MapPoint.Location)objResults.get_Item(ref key);

objMap.AddPushpin(objLoc, accName).Highlight = true;

objPushpin = objMap.FindPushpin(accName);
objPushpin.BalloonState = MapPoint.GeoBalloonState.geoDisplayBalloon;
//objSymbol = objMap.Symbols.Add("C:/WINDOWS/Prairie Wind.bmp");
//objPushpin.Symbol = objSymbol;
//objPushpin.BalloonState = MapPoint.GeoBalloonState.geoDisplayBalloon;
objLoc.GoTo();
}

private void btnSearch_Click(object sender, EventArgs e)
{
GetAccountDetails();
}
}
}


4.
The resulting solution will look similar to Figure 3 and will allow you to enter CRM account information and search for matches.

Figure 3. Custom MapPoint form.

To use the form, enter all or part of a CRM account and click Search. The grid will display the resulting matches from CRM (as shown in Figure 4), and when you select a row and click Locate, the location will display (see Figure 5).

Figure 4. Searching for accounts in CRM through MapPoint.

Figure 5. Mapped CRM account.
Other -----------------
- Microsoft Dynamic CRM 4.0 : Microsoft Live Search Maps
- Configuring Email Settings in Windows Small Business Server 2011 (part 2) - Setting Mailbox Quotas & Moving Exchange Server Data
- Configuring Email Settings in Windows Small Business Server 2011 (part 1) - Configure a Smart Host for Internet Email & Using the POP3 Connector
- System Center Configuration Manager 2007 : Configuration Manager Queries - Relationships, Operations, and Joins
- System Center Configuration Manager 2007 : Configuration Manager Queries - Advanced Queries
- Active Directory Domain Services 2008 : Modify a Group Object Managed By Properties & Modify a Group Object Protection from Deletion
- Active Directory Domain Services 2008 : Modify a Group Object’s Type & Modify a Group Object’s Members
- Windows Server 2003 : Managing WWW Sites (part 4) - HTTP Headers Tab & Custom Errors Tab
- Windows Server 2003 : Managing WWW Sites (part 3) - Directory Security Tab
- Windows Server 2003 : Managing WWW Sites (part 2) - Home Directory Tab & Documents Tab
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server