Category Archives: General .NET

Visual Studio 2012 Report Project: Using dataset web service data source step by step

Recently I was working on a project which involves creating SSRS reports using a web service which returns dataset as data source, after searching a lot and tries different bites of techniques, here is the final working solution step by step:

Problem definition:

You can’t get the actual values of the returned dataset fields or you are new to XML data sources and you need the step by step guide.

Solution:

Install Microsoft SQL Server Data Tools – Business Intelligence for Visual Studio 2012 from the following link: http://www.microsoft.com/en-us/download/details.aspx?id=36843 .

Once installed you can now see the following project types as below:

image

Install Fiddler from the following link http://fiddler2.com/get-fiddler (Fiddler helps you to inspect the web service output in real time in case your have no access to the local server which has the service hosted).

Install XMLQuire from the following link http://qutoric.com/xmlquire/ (XMLQuire helps you to get the exact ElemenPath which will be explained soon).

Now, get back to VS and create a new “Report Server Project” and then create a new “Shared Data Source” as shown below:

image

Replace the “Connection String” with the actual path of your service and supply credentials if required.

Now create a new “Shared Dataset”, select the data source created above and then add the following query:

<Query xmlns=”http://tempuri.org/”>
<SoapAction>http://tempuri.org/GetReportIFTSB07</SoapAction>
<Method Namespace=”http://tempuri.org/” Name=”GetReportIFTSB07″>
    <Parameters>
      <Parameter Name=”FiscalYear”>
        <DefaultValue>2013</DefaultValue>
      </Parameter>
      <Parameter Name=”Agency”>
        <DefaultValue>141</DefaultValue>
      </Parameter>
      <Parameter Name=”AccountPeriod1″>
        <DefaultValue>03</DefaultValue>
      </Parameter>
      <Parameter Name=”AccountPeriod2″>
        <DefaultValue>04</DefaultValue>
      </Parameter>
    </Parameters>
  </Method>
<ElementPath IgnoreNameSpace=”True”>*</ElementPath>
</Query>

Modify the query with the method name and required method parameters.

Run the query and get back to Fiddler (Fiddler will keep monitoring all the events while running), click on the web service call to get the XML results as shown below:

image 

Switch to TextView and copy the whole response.

Open XMLQuire and copy the whole XML from previous step into the editor.

Click on the part of the XML response which contains the data as shown below:

image 

Notice in XMLQuire in the XSD pane, it shows an element path like: /soap:Envelope/soap:Body/GetReportIFTSB07Response/GetReportIFTSB07Result/diffgr:diffgram/NewDataSet/Table[1]

Copy and edit the XSD to something like  GetReportIFTSB07Response/GetReportIFTSB07Result/diffgr:diffgram/NewDataSet/Table{MINUS_LINE_AMT}

So the final query will be:

<Query xmlns=”http://tempuri.org/”>
<SoapAction>http://tempuri.org/GetReportIFTSB07</SoapAction>
<Method Namespace=”http://tempuri.org/” Name=”GetReportIFTSB07″>
    <Parameters>
      <Parameter Name=”FiscalYear”>
        <DefaultValue>2013</DefaultValue>
      </Parameter>
      <Parameter Name=”Agency”>
        <DefaultValue>141</DefaultValue>
      </Parameter>
      <Parameter Name=”AccountPeriod1″>
        <DefaultValue>03</DefaultValue>
      </Parameter>
      <Parameter Name=”AccountPeriod2″>
        <DefaultValue>04</DefaultValue>
      </Parameter>
    </Parameters>
  </Method>
<ElementPath IgnoreNameSpace=”True”>GetReportIFTSB07Response/GetReportIFTSB07Result/diffgr:diffgram/NewDataSet/Table{MINUS_LINE_AMT}</ElementPath>
</Query>

Now you can see the actual data from the dataset instead of the first results.

Notes:

  1. http://tempuri.org/ is the default xmlns replace it with the one from your web service response.
  2. You can edit the required fields to be retrieved by modifying the “MINUS_LINE_AMT” within the “ElementPath” to include more fields separated by “,” example <ElementPath IgnoreNameSpace=”True”>GetReportIFTSB07Response/GetReportIFTSB07Result/diffgr:diffgram/NewDataSet/Table{PLUS_LINE_AMT,MINUS_LINE_AMT}</ElementPath>.
  3. Parameters must be passed as shown in the query to retrieve the right data.

I hope that helped.

Ahmed

SharePoint 2010 Field Formulas (In Arabic)

Just came cross an issue lately with SharePoint 2010 field (Column) formulas.

The issues is when I was applying formulas on Arabic culture sites, SharePoint kept giving me errors parsing the formula.

For example:

I have 2 fields [Start Date] and [End Date]

To calculate the days between the two dates and display “-” if the [End Date] is empty, you can use something like:

=IF(ISBLANK([End Date]),”-“,DATEDIF([End Date],[Start Date],”d”))

This will calculate the days between the two dates only if the [End Date] is blank and works perfectly in English based sites.

If you want to do the same in Arabic Language sites (Even if the column names in English), simple you need to replace the comma “,” with semi column “;”, the result will be something this:

=IF(ISBLANK(النهاية);”-“;DATEDIF(البداية;النهاية;”d”))

As stated in this MSDN article, this must be done for specific languages/cultures and if the website culture changed back again to English, the formula will be changed automatically to use the comma model (Didn’t test this).

I hope that helped

Ahmed

2010 in review

The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here’s a high level summary of its overall blog health:

Healthy blog!

The Blog-Health-o-Meter™ reads This blog is doing awesome!.

Crunchy numbers

Featured image

A Boeing 747-400 passenger jet can hold 416 passengers. This blog was viewed about 5,100 times in 2010. That’s about 12 full 747s.

In 2010, there were 5 new posts, growing the total archive of this blog to 27 posts. There were 12 pictures uploaded, taking up a total of 4mb. That’s about a picture per month.

The busiest day of the year was September 1st with 38 views. The most popular post that day was Home.

Where did they come from?

The top referring sites in 2010 were oryxdev.com, social.msdn.microsoft.com, oryxdev.net, google.co.in, and google.com.

Some visitors came searching, mostly for jquery ajax sample, presentation layer sharepoint bi, sharepoint oracle database, php ajax vehicle tracking, and loading effect in silverlight.

Attractions in 2010

These are the posts and pages that got the most views in 2010.

1

Home January 2009
5 comments

2

jQuery AJAX Load Sample February 2009

3

Connecting Oracle Database to Microsoft Office SharePoint Server 2007 – Concepts July 2009
1 comment

4

ASP.NET AJAX 4.0 Deep Dive Live Meeting Presentation and Samples April 2009

5

Using Microsoft Virtual Earth for Vehicle Tracking and Geo Fencing Sample March 2009
5 comments

Using Microsoft Virtual Earth for Vehicle Tracking and Geo Fencing Sample

Introduction

Today, I had to build a sample  demo using Microsoft Virtual Earth to simulate vehicle tracking and geo fencing.

The term geo fencing was a little bit new to me, you can have a look here for more details.

Using the code

My sample here consists of two parts, one is the live tracking of moving objects based on geospatial data [Longitude, Latitude], and the second part is about geo fencing a moving object to a limited geographic area.

During my research on how to calculate geospatial data  for a specific point on the map, I came across the following sample which helped me a lot to get the test data for my sample.

Now, let’s have a look at our sample and how it works:

First, we need to build our default.aspx page:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
      <title>Vehicle Tracking System</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <script language="javascript" type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>
   1:  
   2:       <script language="javascript" type="text/javascript" src="scripts/Tracking.js">

</script>
</head>
<body onload="GetMap();">
<table width="100%" border="0" cellpadding="0" cellspacing="10">
<tr>
<td id="tabsContainer">
<a onclick='StartTracking();'>Vechile Tracking Demo</a>
<a onclick='StartGeoFencing();'>Geo Fencing Demo</a>
<br />
<div id="traceArea"></div>
</td>
</tr>
<tr>
<td>
<div id="myMap"></div>
</td>
</tr>
</table>
</body>
</html>

Then, we need to build the Tracking.js which contains all the JavaScript code for our demo:

// The Map Object
var map = null;
        
      function GetMap()
      {
         map = new VEMap('myMap');
         var centerat = new VELatLong(29.511604, 47.6061625);
         map.LoadMap(centerat,12,VEMapStyle.Road ,false);
         map.SetZoomLevel(9);
      }
      
      function StartTracking()
      {
            // Vechile one
            // Create sperate layer for that vechile
            var layer = new VEShapeLayer();
            map.AddShapeLayer(layer);
            // Add the intial position
            AddPushpin(29.791604, 47.7061625,'Vehicle 999001',"Time: " + new Date().toTimeString(),layer,'auto1.gif');
            // Add the addtional positions
            window.setTimeout(function() { AddPushpin(29.807604, 47.7141625,'Vehicle 999001','Time: ' + new Date().toTimeString(),layer,'auto1.gif');},1000);
            window.setTimeout(function() { AddPushpin(29.803604, 47.7201625,'Vehicle 999001','Time: ' + new Date().toTimeString(),layer,'auto1.gif');},2000);
            window.setTimeout(function() { AddPushpin(29.801604, 47.7281625,'Vehicle 999001','Time: ' + new Date().toTimeString(),layer,'auto1.gif');},3000);
            window.setTimeout(function() { AddPushpin(29.830604, 47.7331625,'Vehicle 999001','Time: ' + new Date().toTimeString(),layer,'auto1.gif');},4000);
            window.setTimeout(function() { AddPushpin(29.870604, 47.7451625,'Vehicle 999001','Time: ' + new Date().toTimeString(),layer,'auto1.gif');},5000);
            window.setTimeout(function() { AddPushpin(29.890604, 47.7601625,'Vehicle 999001','Time: ' + new Date().toTimeString(),layer,'auto1.gif');},6000);
            
            // Vechile two
            var layer2 = new VEShapeLayer();
            map.AddShapeLayer(layer2);
            AddPushpin(29.711604, 47.8061625,'Vehicle 999002',"Time: " + new Date().toTimeString(),layer2,'orange_car_icon.gif');
            window.setTimeout(function() { AddPushpin(29.707604, 47.8141625,'Vehicle 999002','Time: ' + new Date().toTimeString(),layer2,'orange_car_icon.gif');},1000);
            window.setTimeout(function() { AddPushpin(29.703604, 47.8201625,'Vehicle 999002','Time: ' + new Date().toTimeString(),layer2,'orange_car_icon.gif');},2000);
            window.setTimeout(function() { AddPushpin(29.701604, 47.8281625,'Vehicle 999002','Time: ' + new Date().toTimeString(),layer2,'orange_car_icon.gif');},3000);
            window.setTimeout(function() { AddPushpin(29.695604, 47.8331625,'Vehicle 999002','Time: ' + new Date().toTimeString(),layer2,'orange_car_icon.gif');},4000);
            window.setTimeout(function() { AddPushpin(29.685604, 47.8451625,'Vehicle 999002','Time: ' + new Date().toTimeString(),layer2,'orange_car_icon.gif');},5000);
            window.setTimeout(function() { AddPushpin(29.680604, 47.8601625,'Vehicle 999002','Time: ' + new Date().toTimeString(),layer2,'orange_car_icon.gif');},6000);
            
            // Vechile three
            var layer3 = new VEShapeLayer();
            map.AddShapeLayer(layer3);
            AddPushpin(29.660604, 47.6601625,'Vehicle 999003',"Time: " + new Date().toTimeString(),layer3,'shippingVechile.png');
            window.setTimeout(function() { AddPushpin(29.670604, 47.6451625,'Vehicle 999003','Time: ' + new Date().toTimeString(),layer3,'shippingVechile.png');},1000);
            window.setTimeout(function() { AddPushpin(29.685604, 47.6331625,'Vehicle 999003','Time: ' + new Date().toTimeString(),layer3,'shippingVechile.png');},2000);
            window.setTimeout(function() { AddPushpin(29.701604, 47.6281625,'Vehicle 999003','Time: ' + new Date().toTimeString(),layer3,'shippingVechile.png');},3000);
            window.setTimeout(function() { AddPushpin(29.703604, 47.6201625,'Vehicle 999003','Time: ' + new Date().toTimeString(),layer3,'shippingVechile.png');},4000);
            window.setTimeout(function() { AddPushpin(29.707604, 47.6141625,'Vehicle 999003','Time: ' + new Date().toTimeString(),layer3,'shippingVechile.png');},5000);
            window.setTimeout(function() { AddPushpin(29.711604, 47.6061625,'Vehicle 999003','Time: ' + new Date().toTimeString(),layer3,'shippingVechile.png');},6000);
      
      }
      
      function StartGeoFencing()
      {
      // Load the map on the required location
        var centerat = new VELatLong(29.34524, 47.66744);
         map.LoadMap(centerat,12,VEMapStyle.Road ,false);
         map.SetZoomLevel(11);
         // Create the layer for the vechile
        var layer = new VEShapeLayer();
        map.AddShapeLayer(layer);
        // Add the points
        AddPushpin(29.429, 47.48891,'Vehicle 999231',"Time: " + new Date().toTimeString(),layer,'car-icon.gif');
        window.setTimeout(function() { AddPushpin(29.42541, 47.53011,'Vehicle 999231','Time: ' + new Date().toTimeString(),layer,'car-icon.gif');},1000);
        window.setTimeout(function() { AddPushpin(29.42182, 47.57543,'Vehicle 999231','Time: ' + new Date().toTimeString(),layer,'car-icon.gif');},2000);
        window.setTimeout(function() { AddPushpin(29.41943, 47.61526,'Vehicle 999231','Time: ' + new Date().toTimeString(),layer,'car-icon.gif');},3000);
        window.setTimeout(function() { AddPushpin(29.37516, 47.63036,'Vehicle 999231','Time: ' + new Date().toTimeString(),layer,'car-icon.gif');},4000);
        window.setTimeout(function() { AddPushpin(29.35841, 47.65233,'Vehicle 999231','Time: ' + new Date().toTimeString(),layer,'car-icon.gif');},5000);
        window.setTimeout(function() { AddPushpin(29.34524, 47.66744,'Vehicle 999231','Time: ' + new Date().toTimeString(),layer,'car-icon.gif');},6000);
        window.setTimeout("alert('The vehicle 999231 crossed to Al Jahra boundries');",6100);
      }
      
      function AddPushpin(pLat,pLong,title,desc,layer,imgName)
      {   
          // Clear the layer shapes  
          ClearLayer(layer);
          // Create the shape object
          var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(pLat, pLong));
          shape.SetCustomIcon("<img src='images/" + imgName +"'/>");
          shape.SetTitle(title);
          shape.SetDescription(desc);
          layer.AddShape(shape);
      }

      function ClearLayer(layer)
      {
      // Delete all shapes in a layer
        layer.DeleteAllShapes();
      }
          

As you see all the test data I got it from the Location Chooser sample.

Now. let’s see some screenshots from our demo:

The initial screen

image 

The vechile tracking demo:

image

As you see the the vechiles images keep on moving according to the coordinates I gave to it from the JavaScript, sure you can retrieve these data from a database or a web service.

The next screen shot shows a moving vechile that suppose to not cross a specific boundary.

 image

When the car cross that boundary which is [Al Jahra] boundary, an alert appears to the user to tell about that error. 

image

We can use the sample basics to provide a near real time tracking for any moving objects.

The objects itself must use some technique like GPS to tell the application about its current location.

I’m working now on some more advanced geo fencing techniques using Microsoft Virtual Earth and ArcGIS, I’ll post about it soon.

You can download the sample code here.

I hope that helped

Ahmed

jQuery AJAX Load Sample

Introduction

Many of us need use tabs to load multi view information to the user.

Using server side tabs which reload all the page to show a specific piece of information is not a desirable technique all the time.

jQuery has a very nice way to do so, which is the topic of that post.

Using the code

In this sample I’m using the jQuery AJAX load function to get specific information from the server, based on query string using client side scripts.

First, let’s build the default.aspx page like the following:

<%@ Page Language="C#"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>JQuery AJAX Load Sample</title>
    <script language="javascript" type="text/javascript" src="Scripts/jquery-1.2.6.min.js"></script>
        <script language="javascript" type="text/javascript" src="Scripts/Main.js">

</script>
</head>
<body>
<div>
<h1>JQuery AJAX Load Sample</h1>
<div id="tabsContainer">
<a class="tab" onclick="GetSectionDetails('summery','detailsArea');">Summery</a>
<a onclick="GetSectionDetails('certificates','detailsArea');" >Certificats</a>
<a onclick="GetSectionDetails('contacts','detailsArea');">Contact details</a>
</div>
<div id="detailsArea"></div>
</div>
</body>
</html>

Second, let’s build the generic handler GetDetails.ashx, which will be used to retrieve the section details:

using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace JQuery.Samples.AJAX.Handlers
{
    /// <summary>
    /// Summary description for $codebehindclassname$
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class GetDetails : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            // Just to let you see the loading effect
            System.Threading.Thread.Sleep(2000);

            // Getting the correct data according to the query string.
            // You can replace the static content with database retrieved data.
            switch (context.Request.QueryString["sectionId"].ToLower())
            {
                case("summery"):
                    context.Response.Write(@"Having +3 years of experience as a software developer specialized in design and implementation of web based applications using Microsoft technologies associated with strong analytic and design skills. 
                                             <br/>Worked with both Waterfall and Agile project management methodologies and managed teams with Scrum. 
                                             <br/>Holding a MCTS and MCPD in web development and had great knowledge dealing with web applications. 
                                             <br/>Also had a good experience in the development with MOSS 2007, MCMS 2002 and beginning MS Dynamic CRM 4.0");
                    break;
                case ("certificates"):
                    context.Response.Write(@"<h2>MCPD</h2>
                                            Enterprise Applications Developer, Visual Studio 2005 
                                            <br/>Web Developer, Visual Studio 2005
                                            <h2>MCTS</h2>
                                            Microsoft Office SharePoint Server 2007 ― Application Development 
                                            <br/>Distributed Applications Development, .NET Framework 2.0 
                                            <br/>Windows-Based Client Development, .NET Framework 2.0 
                                            <br/>Windows SharePoint Services 3.0 Application Development 
                                            <br/>Web-Based Client Development, .NET Framework 2.0
                                            <h2>MCP</h2>
                                            Application Development Foundation, .NET Framework 2.0
                                            <h2>Bachelor of  Science</h2>
                                            Mansoura University, Information Systems Department, 2005");
                    break;
                case("contacts"):
                    context.Response.Write(@"<h2>Email</h2>     
                                            shokr.ahmed@gmail.com
                                            <h2>MSN</h2>    
                                            shokr.ahmed@hotmail.com
                                            <h2>Skype</h2>
                                            ahmed.shokr
                                            <h2>Mobile (Kuwait)</h2>
                                            +96565963141
                                            <h2>Mobile (Egypt)</h2>
                                            +20104492755
                                            <h2>Address</h2>
                                            Amman St., Salymia, Kuwait");
                    break;
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

Now, all what we need to do, is to retrieve the correct section information form the client script:

// The handler url
var handlerUrl = 'Handlers/GetDetails.ashx';

// Load the first tab on the page load
$(document).ready(
                    function(){
                                GetSectionDetails('summery','detailsArea');
                              }
                  );

// Loads the specified section details
function GetSectionDetails(sectionId,detailsAreaId)
{
    var detailArea = '#' + detailsAreaId;
    var getUrl = handlerUrl + '?sectionId=' + sectionId;
    $(detailArea).html("Loading....");
    $(detailArea).load(FormatUrl(getUrl));
}

// Format the url to include a random number to avoid caching
// This is very important when dealing with dynamic data
function FormatUrl(url)
{
    var newUrl = url;
    newUrl += '&ver=' + Math.random().toString();
    return newUrl;
}

The sample in action:

The loading… effect:

image

The first section after loading:

image

Another section loaded by client side event:

image

You can play with the styles to make it more like tabs control, but I don’t like CSS so much so I’m leaving it to you 🙂

You can download the sample here.

I hope that helped

Ahmed

Just passed MCTS Microsoft Office SharePoint Server 2007: Application Development

I just passed my MCTS MOSS Application Development, the exam was not that difficult, I had passed with 980 score out of 1000 🙂

The exam was just 32 questions and it covers the following areas:

  • Enterprise Search
  • Working with templates and forms
  • BDC of course 🙂
  • Excel services
  • User profile (Try to practice the usage of the UserProfileManager)
  • Document libraries
  • Workflow (Not enough questions on WF, it needs more deep ones)
  • Audience management (Try to practice the usage of AudienceManager)
  • SSO (Not enough also 🙂 )

This is the main topics, I can’t say any more information of course 🙂

It’s very nice to test your knowledge and get recognized as expert in the same time, thanks to MS for that 🙂

For who wants to see my full transcript please go to Microsoft certification transcript online 

Use the following details to get the transcript:

  1. Transcript ID:       748530
  2. Access code:         publicview

I hope that helped

Ahmed