Monday, November 25, 2013

Options for creating a Hyperlink column in Crystal Reports

I this article i will talk about options for creating a Hyperlink column in Crystal reports.

Following are the list of available Options for creating Hyperlink in Crystal Reports


1.No Hyperlink
2.A Website on the Internet
3.Current Website Field Value
4.An E-mail Address
5.A File
6.Current E-mail Field Value

Lets explore each option in detail:-

1. No Hyperlink
   This is the default option. There is no hyperlink associated 
   with the selected report object.

2. Website on the Internet
   Using this option a report object can be linked to a static
   web address. Using the formula button URL based on a 
   field value can be created.

   This option can be used to connect to Business Objects, Web 
   Intelligence, and OLAP Intelligence documents.

3. Current Website Field Value
   This option can be used to create a hyperlink out of 
   the selected field . The field must be stored as a proper 
   hyperlink in the data source.

4. An E-mail Address
   This option can be used to create a “mailto” address from the 
   selected field. Using the formula button an address based on 
   a field value can be created.

5. A File
   Using this option a hyperlink to a file on a specific 
   computer or networked computer can be created. Using the 
   formula button a file path based on a field value can be 
   created.

6. Current E-mail Field Value
   Using this option an email hyperlink out of the field you 
   selected can be created. The field must be stored as a proper 
   email address in the report data source.

Hope this helps.

Happy Coding......

Tuesday, November 19, 2013

Creating Exploded PIE chart using Microsoft Chart Controls in ASP.Net application

In this article i will be creating Exploded PIE chart using Microsoft Chart Controls available with .NET Framework 4.0.

I will display a companies advisor's commission details as PIE chart on the web page.

Lets start with the designing:

Select ToolBox -> Data -> Chart option

You can drag and drop the chart control in your web page or double click the chart control option and it will be added to the web page.

For making Exploded PIE chart Exploded property needs to be set to true for the DataPoint which is supposed to be exploded.

pieChart.Series["chartSeries"].Points[index]["Exploded"] = "True";

Aspx Code:-
<!-- 
1. asp:Series
   Label="#PERCENT" (property value is required if you want to display the result in percentile format)
2. asp:ChartArea 
   Area3DStyle-Inclination="10" (property value is required if you want control the chart inclination. Max value allowed is 90)  
--> 
<asp:Chart ID="PieChart" runat="server" Height="500px" Width="800px">
<series>
   <asp:Series Name="ChartSeries" ChartType="Pie" ChartArea="MainArea" IsValueShownAsLabel="true" Label="#PERCENT" >
   </asp:Series>
</series>
<chartareas>
  <asp:ChartArea Name="MainArea" Area3DStyle-Inclination="10" Area3DStyle-IsClustered="false" Area3DStyle-Enable3D="true" >
  </asp:ChartArea>
</chartareas>
</asp:Chart>


Code behind (.cs file):-

void createPIEChart()
{
//creating a DataTable object
DataTable oDataTable = new DataTable();
           
//Adding columns to the datatable
oDataTable.Columns.Add("Advisor_Name"typeof(String));
oDataTable.Columns.Add("Color"typeof(String));
oDataTable.Columns.Add("Commission"typeof(Double));

//Adding new Row to the table
DataRow dr = oDataTable.NewRow();

//Adding advisor details as rows
dr["Advisor_Name"] = "Stephen Smith";
dr["Color"] = "Green";
dr["Commission"] = 6000.50;
oDataTable.Rows.Add(dr);

dr = oDataTable.NewRow();
dr["Advisor_Name"] = "Reggie Augstin";
dr["Color"] = "Red";
dr["Commission"] = 20000.90;
oDataTable.Rows.Add(dr);

dr = oDataTable.NewRow();
dr["Advisor_Name"] = "Rahul Mehta";
dr["Color"] = "Blue";
dr["Commission"] = 35000;
oDataTable.Rows.Add(dr);


int i=0;
foreach (DataRow dr in oDataTable.Rows)
{
  DataPoint oDataPoint = new DataPoint(0, double.Parse(dr["Commission"].ToString()));
  oDataPoint.Color = System.Drawing.Color.FromName(dr["Color"].ToString());
  //adding tooltip
  oDataPoint.ToolTip = dr["Advisor_Name"].ToString()+" Earned "+ dr["Commission"].ToString()+" as Commission";
  PieChart.Series["ChartSeries"].Points.Add(oDataPoint);


   //custom properties Exploded for series needs to be added 
  pieChart.Series["chartSeries"].Points[i]["Exploded"] = "True";
  i++; 
}           

PieChart.Series["ChartSeries"]["PointWidth"] = "0.1";
PieChart.Series["ChartSeries"]["DrawingStyle"] = "Cylinder";
PieChart.Series["ChartSeries"]["PieLabelStyle"] = "Outside";
PieChart.Series["ChartSeries"].Font = new System.Drawing.Font("Calibri", 7, System.Drawing.FontStyle.Regular);

PieChart.ChartAreas["MainArea"].InnerPlotPosition.Width = 40;
PieChart.ChartAreas["MainArea"].InnerPlotPosition.Height = 98;
PieChart.ChartAreas["MainArea"].InnerPlotPosition.X = 25;
PieChart.ChartAreas["MainArea"].InnerPlotPosition.Y = 1;
}

output:-


Hope this helps.

Happy Coding.....

Sunday, November 17, 2013

Creating PIE chart using Microsoft Chart Controls in ASP.NET

In this article i will be creating PIE chart using Microsoft Chart Controls available with .NET Framework 4.0.

I will display a companies advisor's commission details as PIE chart on the web page.

Lets start with the designing:

Select ToolBox -> Data -> Chart option

You can drag and drop the chart control in your web page or double click the chart control option and it will be added to the web page.

Aspx Code:-
<!-- 
1. asp:Series
   Label="#PERCENT" (property value is required if you want to display the result in percentile format)
2. asp:ChartArea 
   Area3DStyle-Inclination="10" (property value is required if you want control the chart inclination. Max value allowed is 90)  
--> 
<asp:Chart ID="PieChart" runat="server" Height="250px" Width="500px">
<series>
   <asp:Series Name="ChartSeries" ChartType="Pie" ChartArea="MainArea" IsValueShownAsLabel="true" Label="#PERCENT" >
   </asp:Series>
</series>
<chartareas>
  <asp:ChartArea Name="MainArea" Area3DStyle-Inclination="10" Area3DStyle-IsClustered="false" Area3DStyle-Enable3D="true" >
  </asp:ChartArea>
</chartareas>
</asp:Chart>

Code behind (.cs file):-

void createChart()
{
//creating a DataTable object
DataTable oDataTable = new DataTable();
           
//Adding columns to the datatable
oDataTable.Columns.Add("Advisor_Name", typeof(String));
oDataTable.Columns.Add("Color", typeof(String));
oDataTable.Columns.Add("Commission", typeof(Double));

//Adding new Row to the table
DataRow dr = oDataTable.NewRow();

//Adding advisor details as rows
dr["Advisor_Name"] = "Stephen Smith";
dr["Color"] = "Green";
dr["Commission"] = 6000.50;
oDataTable.Rows.Add(dr);

dr = oDataTable.NewRow();
dr["Advisor_Name"] = "Reggie Augstin";
dr["Color"] = "Red";
dr["Commission"] = 20000.90;
oDataTable.Rows.Add(dr);

dr = oDataTable.NewRow();
dr["Advisor_Name"] = "Rahul Mehta";
dr["Color"] = "Blue";
dr["Commission"] = 35000;
oDataTable.Rows.Add(dr);

foreach (DataRow dr in oDataTable.Rows)
{
  DataPoint oDataPoint = new DataPoint(0, double.Parse(dr["Commission"].ToString()));
  oDataPoint.Color = System.Drawing.Color.FromName(dr["Color"].ToString());
  //adding tooltip
  oDataPoint.ToolTip = dr["Advisor_Name"].ToString()+" Earned "+ dr["Commission"].ToString()+" as Commission";
   PieChart.Series["ChartSeries"].Points.Add(oDataPoint);
}           

PieChart.Series["ChartSeries"]["PointWidth"] = "0.1";
PieChart.Series["ChartSeries"]["DrawingStyle"] = "Cylinder";
PieChart.Series["ChartSeries"]["PieLabelStyle"] = "Outside";
PieChart.Series["ChartSeries"].Font = new System.Drawing.Font("Calibri", 7, System.Drawing.FontStyle.Regular);

PieChart.ChartAreas["MainArea"].InnerPlotPosition.Width = 40;
PieChart.ChartAreas["MainArea"].InnerPlotPosition.Height = 98;
PieChart.ChartAreas["MainArea"].InnerPlotPosition.X = 25;
PieChart.ChartAreas["MainArea"].InnerPlotPosition.Y = 1;
}

output:-


Hope this helps.

Happy Coding.....

Friday, November 15, 2013

Complex Structured XML Nodes and Attributes reading using LINQ

In this article i will be using examples to show the ways to read a complex structured XML nodes and attributes value using LINQ. 

As you are aware of the powerful features LINQ provides, and the best thing about LINQ is simple and easy way to use it. 


I have created a customerconfig.xml XML file, which contains following details


  • 1st Section -> Source Feed Info (Feed file placed in a shared location)

    • CSV File path placed in a shared location
    • CSV File Name
    • Data demiliter of the CSV File

  • 2nd Section -> Column names, datatype and index position (available in the csv file)
    • First_Name
    • Last_Name
    • DOB
    • EMP_No
customerconfig.xml 

<?xml version="1.0" encoding="utf-8"?>
<FeedInfo>
  <CustomerFeedInfo IsActive="1">
    <SourceInfo>
      <Separator>,</Separator>
      <FilePath>c:\shared\feed</FilePath>
      <FileName>employee.csv</FileName>
    </SourceInfo>
    <ColumnDetails>
      <Column Name="First_Name" Index="0" DataType="String"/>
      <Column Name="Last_Name" Index="1" DataType="String"/>
      <Column Name="DOB" Index="2" DataType="DateTime"/>
      <Column Name="Emp_No" Index="3" DataType="Int"/>
    </ColumnDetails>
  </CustomerFeedInfo>
</FeedInfo>

I am using C#.Net, .Net Framework 4.0 and VS 2010.

Lets start with the coding to read the node and attribute values from different sections of the configuation xml.



//first assigning the xml file path to a variable
string path = AppDomain.CurrentDomain.BaseDirectory.Replace(@"\bin\Debug", @"");          
path = path + "/CustomerConfig.xml";

XDocument class represents a XML document. XDocument.Load method Creates a new System.Xml.Linq.XDocument object from a file.

XDocument xDoc = XDocument.Load(path);

//LINQ query to read the xml file details
var feedDetails = from feed in xDoc.Descendants("CustomerFeedInfo")
                  where feed.Attribute("IsActive").Value == "1"
                  select new
                  {
                     SourceInfo = feed.Descendants("SourceInfo").Descendants(),
                     ColumnInfo = feed.Descendants("ColumnDetails").Descendants()
                  };

//using foreach to loop through all the items available in feedDetails
foreach (var feed in feedDetails)
{
   //Config file source details reading 

   //Index based sourceinfo retrieval
   string separator = feed.SourceInfo.ElementAt(0).Value;
   string filepath = feed.SourceInfo.ElementAt(1).Value;
   string fileName = feed.SourceInfo.ElementAt(2).Value;

   //foreach loop for sourceinfo retrieval 
   Console.WriteLine("Source Info Details");
                Console.WriteLine();
                foreach (XElement xe in feed.SourceInfo)
                {
                    Console.WriteLine(xe.Name+" = "+ xe.Value);
                }

   Console.WriteLine();

   //column details retrieval
   Console.WriteLine("Column Details");
   Console.WriteLine();

   //using index position
   string sColumn = feed.ColumnInfo.ElementAt(0).Attribute("Name").Value;
   string sColumn1 = feed.ColumnInfo.ElementAt(1).Attribute("Name").Value;
   string sColumn2 = feed.ColumnInfo.ElementAt(2).Attribute("Name").Value;

   //using foreach loop to retrieve the column details
   foreach (XElement xe in feed.ColumnInfo)
   {
       Console.WriteLine(xe.Attribute("Name").ToString()+"="+ xe.Attribute("Name").Value);
   }
}

output:-


I hope these examples gives clear idea about LINQ to XML features.

Happy Coding.....