Tuesday 30 October 2012

Create RDLC Report Chart in ASP.net


Add XSD page in your project
In this XSD Page you create a Data Table.. (Example Given Below)


Then Add a RDLC page in your Project.
In This rdlc page you add a chart (Tools --> Double click Chart ).

Set the DataSet in your rdlc page same as given below the image..

 then click the chart and set the x and y axis column name...


Then add a Aspx page . Drag a report Viewer in that aspx page...
 <rsweb:ReportViewer ID="rptViewer" runat="server" Width="700px">
  </rsweb:ReportViewer>


Then give the given below the query in your (ASPX) button click (or) page load event

        rptViewer.LocalReport.EnableExternalImages = true;
        rptViewer.ProcessingMode = ProcessingMode.Local;
        rptViewer.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
        rptViewer.LocalReport.DataSources.Clear();

        DataView dvChart = Obj_Admission.chart();
        rptViewer.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.
ReportDataSource("", dtPayRpt.DefaultView));
        rptViewer.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("DataSet1", dvChart));
        rptViewer.LocalReport.Refresh();

Then run your project and see the result..
Thank You

Sunday 21 October 2012

Stored Procedure select Query In SQL server

There are lots of situation, Where we have to use Store Procedure in our project. But beginners don’t get proper code for  Select Query For Store Procedure. Using this code they can do it:

In Class File give the query same as given below

public static DataTable SelectItemDetailsSearch(string str1 string str2)
        {
                SqlParameter[] sqlParams = new SqlParameter[2];

                sqlParams[0] = new SqlParameter("@Category", SqlDbType.VarChar, 50);
                sqlParams[0].Value = str1 ;

                sqlParams[1] = new SqlParameter("@ItemType", SqlDbType.VarChar, 150);
                sqlParams[1].Value = str2;

                DAL.Sql ocp = new DAL.Sql();
                return ocp.GetDetails_DT_SP("ViewItem_Search", sqlParams);
        }


Then give the query in sql server


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER PROCEDURE [dbo].[ViewItem_Search]
(
@Category varchar(50),
@ItemType varchar(150)
)

AS

Begin
if(@Category != 'All'and @ItemType!='All' )

SELECT  a.Item_Id AS Code, d.CategoryName as Category,a.ItemName, a.ItemDefaultPrice AS Price,
                      CONVERT(varchar, a.LastUpdateDate,
                      103) + ' ' + CONVERT(varchar, a.LastUpdateDate, 108) AS LastUpdateDate
FROM     ItemDetails AS a INNER JOIN
                      ItemCategory AS d ON a.ItemCategory_Id = d.ItemCategory_Id
WHERE      (d.CategoryName = @Category and a.ItemType=@ItemType)
ORDER BY d.CategoryName,a.ItemCode
END

Then Select All The Sql Query Then Run or Press F5

Command(s) completed successfully.
Message Display In Your SQL server page...
Then Run your project ..


Wednesday 17 October 2012

Create Chart In ASP.net

Create Chart control in asp.net 
Aspx Page

<asp:Chart ID="Chart1" runat="server" BorderlineColor="Black" BorderlineDashStyle=
"Solid" BackColor="#B6D6EC" BackGradientStyle="TopBottom" BackSecondaryColor=
"White" Width="720px" Height="450px">
<Titles>
<asp:Title Name="Title1" Text="" Alignment="TopCenter" Font="Verdana, 12pt, 
style=Bold">
</asp:Title>
</Titles>
<Series>
<asp:Series Name="Series1" CustomProperties="DrawingStyle=Cylinder,
MaxPixelPointWidth=50" ShadowOffset="2" IsValueShownAsLabel="True" 
ChartType="Column">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1" BackGradientStyle="TopBottom" BackSecondaryColor=
"#B6D6EC"
BorderDashStyle="Solid" BorderWidth="2">
<AxisX Interval="1" TextOrientation="Rotated90">
<MajorGrid Enabled="False" />
</AxisX>
</asp:ChartArea>
</ChartAreas>
</asp:Chart> 

Coad Behind

Dataview dv = ExpenseDetails.GetExpApproverChart();
Chart1.Series["Series1"].Points.DataBindXY(dv, "ColumnName1", dv, "ColumnName2"); 

OR


Chart.aspx
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Chart.aspx.cs"
Inherits="Chart" %>

<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI.DataVisualization.Charting"
TagPrefix="asp" %>
<!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>ASP.NET Chart Control Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1><b>ASP.NET Chart Control Example</b></h1>
<asp:Chart ID="ChartAspnet" runat="server" Height="400px" Width="500px">
<Series>
<asp:Series Name="SeriesASPNET" ChartType="Column" ChartArea="ChartAreaASPnet">
</asp:Series>
<asp:Series Name="SeriesASPNET1" ChartType="Column" ChartArea="ChartAreaASPnet">
</asp:Series>
 
</Series>
 
<ChartAreas>
 
<asp:ChartArea Name="ChartAreaASPnet">
 
</asp:ChartArea>
 
</ChartAreas>
 
</asp:Chart>
 
</div>

 
</form>
</body>
</html>
 
 
Chart.aspx.cs
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.DataVisualization.Charting;

namespace ASPNETChart
{
    public partial class Chart : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable objDT = default(DataTable);
            objDT = CreateDataTable();

            ChartAspnet.DataSource = dt;

            ChartAspnet.Series[0].YValueMembers = "ChartVolume1";
            ChartAspnet.Series[1].YValueMembers = "ChartVolume2";

            ChartAspnet.Series[0].XValueMember = "Date";
            
            ChartAspnet.DataBind();
        }

        
        private DataTable CreateDataTable()
        {
            DataTable objDT = new DataTable();

            objDT.Columns.Add("Date");
            objDT.Columns.Add("ChartVolume1");
            objDT.Columns.Add("ChartVolume2");

            DataRow objDr;

            objDr = objDT.NewRow();
            objDr["Date"] = "Jan";
            objDr["ChartVolume1"] = 3500;
            objDr["ChartVolume2"] = 4102;
            objDT.Rows.Add(objDr);

            objDr = objDT.NewRow();
            objDr["Date"] = "Feb";
            objDr["ChartVolume1"] = 6046;
            objDr["ChartVolume2"] = 4222;
            objDT.Rows.Add(objDr);

            objDr = objDT.NewRow();
            objDr["Date"] = "Mar";
            objDr["ChartVolume1"] = 4909;
            objDr["ChartVolume2"] = 2935;
            objDT.Rows.Add(objDr);

            objDr = dt.NewRow();
            objDr["Date"] = "Apr";
            objDr["ChartVolume1"] = 4500;
            objDr["ChartVolume2"] = 5320;
            objDT.Rows.Add(objDr);

            objDr = dt.NewRow();
            objDr["Date"] = "May";
            objDr["ChartVolume1"] = 5500;
            objDr["ChartVolume2"] = 5001;
            objDT.Rows.Add(objDr);

            objDr = objDT.NewRow();
            objDr["Date"] = "Jun";
            objDr["ChartVolume1"] = 3566;
            objDr["ChartVolume2"] = 4456;
            objDT.Rows.Add(objDr);

            return objDT;
        }
    }
}

ASP.Net Menu Control


Write the below Query in Aspx Design Page

<style type="text/css">
        .menustyle
        {
            background-color: #6C6C6C;
            text-align: left;
            color: White;
            font-family: Arial;
            font-weight: bold;
            font-size: 8pt;
            z-index: 20;
        }
        .mouseover
        {
            background-color: #7D7D7D;
            text-align: left;
            color: White;
            font-family: Arial;
            font-weight: bold;
            font-size: 8pt;
            cursor: hand;
            z-index: 20;
        }
    </style>

<asp:Menu ID="mnuMaster" Height="20px" runat="server" StaticEnableDefaultPopOutImage="false"
Orientation="Horizontal" Width="85%" OnMenuItemClick="mnuMaster_MenuItemClick">
      <StaticMenuStyle CssClass="menustyle" />
      <DynamicMenuStyle CssClass="menustyle" />
      <StaticMenuItemStyle CssClass="menustyle" />
      <DynamicMenuItemStyle CssClass="menustyle" Height="20px" />
      <StaticSelectedStyle CssClass="mouseover" />
       <StaticHoverStyle CssClass="mouseover" />
       <DynamicHoverStyle CssClass="mouseover" />
 </asp:Menu>

Then Write the below Query in Aspx.cs Page
 //Show The Menu

ht_Authorisedby = new Hashtable();
ht_AccessTo = new Hashtable();


#region Database Fetching, Adding in HashTable and Storing in Session

DataTable m_dtUser = new DataTable();
m_dtUser = BLL.Admin.UserDetails.GetUserType_RefID();

foreach (DataRow dr in m_dtUser.Rows)
{
strAuthorisedBy = dr["AuthorisedMenu"].ToString();
strAccessTo = dr["AccessTo"].ToString();
}
int a = 1; string strKeyVal1 = string.Empty;
foreach (string strsplitAuthorBy in strAuthorisedBy.Split(','))
{
strKeyVal1 = "KeyAuthorise" + a;
ht_Authorisedby.Add(strKeyVal1, strsplitAuthorBy.ToString());
a = a + 1;
}
int b = 1; string strKeyVal2 = string.Empty;
foreach (string strsplitAccTo in strAccessTo.Split(':'))
{
strKeyVal2 = "KeyAccessTo" + b;
ht_AccessTo.Add(strKeyVal2, strsplitAccTo.ToString());
b = b + 1;
}

#endregion
 



mnuMaster.Items.Clear();
for (int a = 1; a <= ht_Authorisedby.Count; a++)//each (object obj in ht_Authorisedby.Values)
 {
   string strAuthorBy = ((String)ht_Authorisedby["KeyAuthorise" + a]);//(obj));
    MenuItem menuParent = new MenuItem(strAuthorBy);     mnuMaster.Items.Add(menuParent);
foreach (string strSubMenuName in ((String)ht_AccessTo["KeyAccessTo" + a]).Split(','))
     {
         int a1 = strSubMenuName.Split('#').Length;
          if (a1 == 1)
               {
                 MenuItem menuChild = new MenuItem(strSubMenuName); menuParent.ChildItems.Add(menuChild);
                 }
            else
                  {
                  string[] strSubChildMenuName = strSubMenuName.Split('#');
                   MenuItem menuChild = new MenuItem(strSubChildMenuName[0].ToString()); menuParent.ChildItems.Add(menuChild);
foreach (string strChildSubChildMenuName in strSubChildMenuName[1].ToString().Split(';'))
                 {
                 MenuItem menuSubChild = new MenuItem(strChildSubChildMenuName); menuChild.ChildItems.Add(menuSubChild);
                            }
                        }
                    }
                }

 //Assign PageLink 

protected void mnuMaster_MenuItemClick(object sender, MenuEventArgs e)
{
case "MainMenu":
switch (e.Item.Value)
{
case "Sub Menu1":
Response.Redirect("SubMenu1.aspx");
break;

case " Sub Menu2":
Response.Redirect("SubMenu2.aspx ");
break;

case " Sub Menu3":                          
Response.Redirect("SubMenu3.aspx ");
break;

case " Sub Menu4":
Response.Redirect("SubMenu4.aspx ");
break;

case " Sub Menu5":
Response.Redirect("SubMenu5.aspx ");
break;
}
}

Save The Data in database Given Below The Format


MainMenu# Sub Menu1; Sub Menu2; Sub Menu3; Sub Menu4; Sub Menu5:


using query


if (chkMainMenu.Checked)
 {
 if (strAccessTo == "") { strAccessTo = strAccessTo + " MainMenu #"; }
 else { strAccessTo = strAccessTo + "," + " MainMenu#"; }

 if (chkSubMenu1.Checked)
   {
if (tempExpRpt == "") { strAccessTo = strAccessTo + " Sub Menu1"; }
else { strAccessTo = strAccessTo + "; Sub Menu1"; }
tempExpRpt += " Sub Menu1";
}

if (chkSubMenu2.Checked)
{
if (tempExpRpt == "") { strAccessTo = strAccessTo + " Sub Menu2"; }
 else { strAccessTo = strAccessTo + "; Sub Menu2"; }
 tempExpRpt += " Sub Menu2";
  }

if (chkSubMenu3.Checked)
 {
if (tempExpRpt == "") { strAccessTo = strAccessTo + " Sub Menu3"; }
else { strAccessTo = strAccessTo + "; "; }
tempExpRpt += " Sub Menu3";
}

if (chkSubMenu4.Checked)
{
if (tempExpRpt == "") { strAccessTo = strAccessTo + " Sub Menu4"; }
else { strAccessTo = strAccessTo + "; Sub Menu4"; }
tempExpRpt += " Sub Menu4";
}

if (chkSubMenu5.Checked)
{
if (tempExpRpt == "") { strAccessTo = strAccessTo + " Sub Menu5"; }
else { strAccessTo = strAccessTo + "; Sub Menu5"; }
tempExpRpt += " Sub Menu5";
 }
}



Friday 12 October 2012

Create RDLC Report in ASP.net



Insert RDLC page in your Project.
Then Design Your RDLC (report) page. With the help of text box and Table

Create Parameter


Click the report Data in your RDLC page
Then Right Click On the parameter and click add

Assign Parameter Value to Textbox

Right Click RDLC page textbox Then Click Expression
Click Parameter Then Double Click Your Parameter Name

Pass Parameter value from code behind


Add  Microsoft.ReportViewer.Common Dll and Microsoft.ReportViewer.WebForms
Dll To Your Project.
Then add using Microsoft.Reporting.WebForms;
Namespace in your coading page.

ArrayList list = m_alStudPaymentDetail[dtIndex] as ArrayList;
hnCurrentPayment.Value = (string)list[0];

rptViewer.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("", dtPayRpt.DefaultView));
ReportParameter[] param = new ReportParameter[8];
param[0] = new ReportParameter("param0", “printBy”);
param[1] = new ReportParameter("param1", "Printed Date  :" + date[0].ToString());
param[2] = new ReportParameter("param2", "StudentName");
param[3] = new ReportParameter("param3", "CourseName");
param[4] = new ReportParameter("param4", "FeeDetail");
param[5] = new ReportParameter("param5", "Date");
param[6] = new ReportParameter("param6", "TotalFee");
param[7] = new ReportParameter("param7", "Father Name")        rptViewer.LocalReport.SetParameters(param);
rptViewer.LocalReport.Refresh();



Set RDLC page Table Value in ASP.net


Create a new XSD page in your Project
Right Click on This Page
Then click Add à DataTable




Add Your column in that the Data Table




Then Set DataTable Name to Table DataSourse

Pass DataTable Value To RDLC Report

DataTable dtProject = BLL.ReportQuery.clsAmountPayReceive.GetSalesItem();

rptViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
rptViewer.LocalReport.ReportEmbeddedResource       "WebUI.Forms.ShrooqalReport.DetailsOfSales.rdlc";
rptViewer.LocalReport.DataSources.Clear();

rptViewer.LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("Rdlc DataTableName", dtProject.DefaultView));
rptViewer.LocalReport.Refresh();


Then Run the Project and see The Report .

Thank You

Set serial number in rdlc report in asp.net






Now right click on the detail row of the Sr. No column and Click on on Expression..

In the Expression Window, Expand Common Function category and Click on Miscellaneous



Now Double click on RowNumber and Pass keyword Nothing as a parameter .

Press Ok button and Thats it..

Demo



Thursday 4 October 2012

File Download in ASP.NET

There are lots of situation, Where we have to use file Downloader in our project. But beginners don’t get proper code for  Downloading File. Using this code they can do it:

 File Download Query

 

             m_FilePath = "~/PdfProductFile/Raja.pdf";
            m_FileName = "Raja.pdf";
            string ext = Convert.ToString(Path.GetExtension(m_FileName.Trim('.')));
            System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
            response.ClearContent();
            response.Clear();
            response.ContentType = "Raja/" + ext.Replace('.', ' ') + "";
            response.AddHeader("Content-Disposition", "attachment; filename=\"" + m_FileName + "\"");
            response.TransmitFile(m_FilePath);
            response.Flush();
            response.End();