Monday, May 26, 2014

Configuring the SSRS Reports to Asp.Net for Locally

Step 1:- Creating the one sample .rdlc file report from SSRS templete
Step 2:- Add Reference to the project “Microsoft.ReportViewer.WebForms”

<%@ Register
Assembly="Microsoft.ReportViewer.WebForms,
Version=10.0.0.0,
Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"
       Namespace="Microsoft.Reporting.WebForms"
TagPrefix="rsweb" %>

Step 3:-Add this report tag

<rsweb:ReportViewer
ID="ReportViewerForCSDRS"
runat="server"
ShowPrintButton="true"
       Font-Names="Verdana"
       Visible="true"
       Font-Size="8pt"
       InteractiveDeviceInfos="(Collection)"
       WaitMessageFont-Names="Verdana"
       WaitMessageFont-Size="14pt"
       Width="100%"
       Height="600px"
       ShowBackButton="False"
       ShowDocumentMapButton="False"
       ShowFindControls="False"
       ShowParameterPrompts="False"
       ShowExportControls="True">
</rsweb:ReportViewer>


Step 4:- Full the dataset from the data base

ClsRptPL objPL = new ClsRptPL();
objPL.FromDate = Convert.ToDateTime(Request.QueryString["FromDate"]);
objPL.ToDate = Convert.ToDateTime(Request.QueryString["ToDate"]);


DataSet ds = new DataSet();

ds=  (fill the data set)

Step 5:- Bind data set to the report datasource

ReportDataSource reportDSHeader = new ReportDataSource("DataSetName", ds.Tables[0]);
ReportViewerForCSDRS.LocalReport.DataSources.Clear();
ReportViewerForCSDRS.LocalReport.EnableExternalImages = true;
ReportViewerForCSDRS.LocalReport.DataSources.Add(reportDSHeader);

Note: “DataSetName” Here displaying the name of the dataset is same as the Report Dataset name while creating the RDLC report

Step 5:- With Parameters report

Here we configure the report parameters

Make Shure that the parameter name is as same as the report parameter name



ReportParameter[] repparams = new ReportParameter[2];

repparams[0] = new ReportParameter();
repparams[0].Name = "FromDate";
repparams[0].Values.Add(objPL.FromDate.ToString());

repparams[1] = new ReportParameter();
repparams[1].Name = "ToDate";
repparams[1].Values.Add(objPL.ToDate.ToString());

ReportViewerForCSDRS.LocalReport.SetParameters(repparams);

ReportViewerForCSDRS.LocalReport.ReportPath = Server.MapPath("ReportRDLC\\PaymentReceipt.rdl"); 

ReportViewerForCSDRS.LocalReport.Refresh();
ReportViewerForCSDRS.ShowExportControls = true;
ReportViewerForCSDRS.ShowReportBody = true;
ReportViewerForCSDRS.ShowToolBar = true;

NOTE: Make sure to add this code in the web config file 

 <system.webServer>
  <handlers>
    <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

</handlers>
</system.webServer>

---------------------

<system.web>
 <compilation debug="true" targetFramework="4.5">

  <buildProviders>
        <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
   </buildProviders>


  <httpHandlers>
   <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        validate="false" />

   </httpHandlers>

 </compilation> 

</system.web>


Also Export for PDF and Excel

        Warning[] warnings;
        string[] streamids;
        string mimeType, encoding, extension;
        string ReportName = string.Empty;

protected void imgpdf_Click(object sender, ImageClickEventArgs e)
        {
            //extension = ".pdf";
            ReportName = "SampleReceipt";
            byte[] bytes = ReportViewerForCSDRS.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
            Response.ContentType = "application/excel";
            Response.AddHeader("Content-disposition", "filename=" + ReportName + "." + extension);

            Response.OutputStream.Write(bytes, 0, bytes.Length);
            Response.OutputStream.Flush();
            Response.OutputStream.Close();
            Response.Flush();
            Response.Close();
        }

protected void imgexcel_Click(object sender, ImageClickEventArgs e)
        {

            byte[] bytes = ReportViewerForCSDRS.LocalReport.Render("EXCEL", null, out mimeType, out encoding, out extension, out streamids, out warnings);
            Response.ContentType = "application/excel";
            Response.AddHeader("Content-disposition", "filename=" + ReportName + "." + extension);

            Response.OutputStream.Write(bytes, 0, bytes.Length);
            Response.OutputStream.Flush();
            Response.OutputStream.Close();
            Response.Flush();
            Response.Close();
        }




For Complete Proper look and fee for the SSRS Report design in aspx


<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .overlay
        {
            position: fixed;
            z-index: 98;
            top: 0px;
            left: 0px;
            right: 0px;
            bottom: 0px;
            background-color: #EBEBEB;
            filter: alpha(opacity=80);
            opacity: 0.8;
        }
        #ctl00_ContentPlaceHolder1_rptCommon_ctl05
        {
            background-color: White !important;
            background-image: none !important;
            text-align: left !important;
        }
        #P91bea07e815a4c2187960cfbaecf3a3e_1_oReportCell
        {
            width: 10% !important;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <h2 class="module-title" align="center">
        <asp:Label runat="server" ID="lblScreenHeader" Text="" Width="1090px" Font-Size="Medium"
            Style="text-decoration: underline" /></h2>
    <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release" EnablePageMethods="true"
        EnablePartialRendering="true" LoadScriptsBeforeUI="true">
    </asp:ScriptManager>
    <table align="right">
        <tr align="right">
            <td>
                <asp:ImageButton ID="imgexcel" runat="server" ImageUrl="~/images/excel.jpg" Width="30px"
                    Height="30px" OnClick="imgexcel_Click" ToolTip="Export to Excel" />
                <asp:ImageButton ID="imgpdf" runat="server" ImageUrl="~/images/pdf.png" Width="30px"
                    Height="30px" OnClick="imgpdf_Click" ToolTip="Export to Pdf" />
            </td>
        </tr>
        <tr align="right">
            <td>
                &nbsp;
            </td>
        </tr>
        <tr align="center">
            <td>
                <div style="width: 1103px; overflow:auto;">
                    <rsweb:ReportViewer ID="rptCommon" runat="server" ShowPrintButton="true" Font-Names="Verdana"
                        Visible="true" Font-Size="8pt" InteractiveDeviceInfos="(Collection)" WaitMessageFont-Names="Verdana"
                        WaitMessageFont-Size="14pt" Width="100%" Height="100%" ShowBackButton="False"
                        ShowDocumentMapButton="False" ShowFindControls="False" ShowParameterPrompts="False"
                        ShowExportControls="True" SizeToReportContent="true" ShowPageNavigationControls="True"
                        ShowToolBar="False">
                    </rsweb:ReportViewer>
                </div>
            </td>
        </tr>
    </table>
</asp:Content>


Execute the project and check

For any clarifications or queries please don’t hesitate to call or Email

Phone :- + 91-9492179390


Email :- lannam@technobrainltd.com (or) lokeshtec@gmail.com 
Read More »

Monday, May 19, 2014

Simply creating the properties based on the SQL table structure

Step 1:- Copy this code and past in your sql editer

declare @TableName sysname = '@TableName'
declare @result varchar(max) = 'public class ' + @TableName + '
{'

select @result = @result + '
    public ' + ColumnType + ' ' + ColumnName + ' { get; set; }
'
from
(
    select
        replace(col.name, ' ', '_') ColumnName,
        column_id,
        case typ.name
            when 'bigint' then 'long'
            when 'binary' then 'byte[]'
            when 'bit' then 'bool'
            when 'char' then 'string'
            when 'date' then 'DateTime'
            when 'datetime' then 'DateTime'
            when 'datetime2' then 'DateTime'
            when 'datetimeoffset' then 'DateTimeOffset'
            when 'decimal' then 'decimal'
            when 'float' then 'float'
            when 'image' then 'byte[]'
            when 'int' then 'int'
            when 'money' then 'decimal'
            when 'nchar' then 'char'
            when 'ntext' then 'string'
            when 'numeric' then 'decimal'
            when 'nvarchar' then 'string'
            when 'real' then 'double'
            when 'smalldatetime' then 'DateTime'
            when 'smallint' then 'short'
            when 'smallmoney' then 'decimal'
            when 'text' then 'string'
            when 'time' then 'TimeSpan'
            when 'timestamp' then 'DateTime'
            when 'tinyint' then 'byte'
            when 'uniqueidentifier' then 'Guid'
            when 'varbinary' then 'byte[]'
            when 'varchar' then 'string'
            else 'UNKNOWN_' + typ.name
        end ColumnType
    from sys.columns col
        join sys.types typ on
            col.system_type_id = typ.system_type_id AND col.user_type_id = typ.user_type_id
    where object_id = object_id(@TableName)
) t
order by column_id

set @result = @result  + '
}'


print @result


Step 2:- Copy your table name and past at "@TableName"

Step 3:- OutPut



public class NewPawn
{
    public int Sno { get; set; }

    public int SnoPawn { get; set; }

    public DateTime Pawndate { get; set; }

    public string Name { get; set; }

    public string FatherHusbandName { get; set; }

    public string FullAddress { get; set; }

    public int AmountOfPrincipalOfLoan { get; set; }

    public string AmountOfPrincipalOfLoanInWords { get; set; }

    public string Particulars { get; set; }

    public int PayInterestForEvery3Months { get; set; }

    public int MyAnnualIncome1 { get; set; }

    public int MyAnnualIncome2 { get; set; }

    public DateTime DateOfExpiry { get; set; }

    public string Kg1 { get; set; }

    public string Kg2 { get; set; }

    public string G1 { get; set; }

    public string G2 { get; set; }

    public string MG1 { get; set; }

    public string MG2 { get; set; }

    public string PV1 { get; set; }

    public string PV2 { get; set; }

    public byte[] SignatureOwner { get; set; }

    public byte[] SignatureClient { get; set; }

    public bool Status { get; set; }

    public string CreatedBy { get; set; }

    public DateTime CreatedDate { get; set; }

    public string LastModifiedBy { get; set; }

    public DateTime LastModifiedDate { get; set; }

}



For any clarifications or queries please don’t hesitate to call or Email

Phone :- + 91-9492179390


Email :- lannam@technobrainltd.com (or) lokeshtec@gmail.com 

Read More »

Wednesday, March 19, 2014

How to use Full CPU Usage using Asp.net C#

Step1: - Create one sample web page 

Step2:- Go to default.aspx page

Step3:- In the default.aspx.cs page add this namespace " using System.Threading; "

Step4:- Before page load method add this line " static AutoResetEvent _AREvt; "

Step5:- In the page load method add this code part

_AREvt = new AutoResetEvent(false);

ThreadStart ts = new ThreadStart(Test);
Thread th = new Thread(ts);
th.IsBackground = true;
th.Priority = ThreadPriority.Lowest;
th.Start();

ts = new ThreadStart(Test1);
th = new Thread(ts);
th.IsBackground = true;
th.Priority = ThreadPriority.Lowest;
th.Start();

ts = new ThreadStart(Test1);
th = new Thread(ts);
th.IsBackground = true;
th.Priority = ThreadPriority.Lowest;
th.Start();

ts = new ThreadStart(Test1);
th = new Thread(ts);
th.IsBackground = true;
th.Priority = ThreadPriority.Lowest;
th.Start();


All this code is working based on the threading concept

Step6:- Add these two methods

static void Test()
        {

            while (true)
            {

                //do what you need todo
                _AREvt.WaitOne(10, true);
                for (Int64 i = 0; i < 10000000000; i++)
                {
                    for (Int64 j = 0; j < 10000000000; j++)
                    {
                        for (Int64 k = 0; k < 10000000000; k++)
                        {

                        }
                    }
                }
            }
        }




static void Test1()
        {
            while (true)
            {

                //do what you need todo
                _AREvt.WaitOne(10, true);
                for (Int64 i = 0; i < 10000000000; i++)
                {
                    for (Int64 j = 0; j < 10000000000; j++)
                    {
                        for (Int64 k = 0; k < 10000000000; k++)
                        {

                        }
                    }
                }

            }
        }

Step7:- Run the project and check the CPU usage

Full page is look like below


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;

namespace SampleTestingCodes
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        static AutoResetEvent _AREvt;
        protected void Page_Load(object sender, EventArgs e)
        {
            _AREvt = new AutoResetEvent(false);

            ThreadStart ts = new ThreadStart(Test);
            Thread th = new Thread(ts);
            th.IsBackground = true;
            th.Priority = ThreadPriority.Lowest;
            th.Start();

            ts = new ThreadStart(Test1);
            th = new Thread(ts);
            th.IsBackground = true;
            th.Priority = ThreadPriority.Lowest;
            th.Start();

            ts = new ThreadStart(Test1);
            th = new Thread(ts);
            th.IsBackground = true;
            th.Priority = ThreadPriority.Lowest;
            th.Start();

            ts = new ThreadStart(Test1);
            th = new Thread(ts);
            th.IsBackground = true;
            th.Priority = ThreadPriority.Lowest;
            th.Start();
        }


        static void Test()
        {

            while (true)
            {

                //do what you need todo
                _AREvt.WaitOne(10, true);
                for (Int64 i = 0; i < 10000000000; i++)
                {
                    for (Int64 j = 0; j < 10000000000; j++)
                    {
                        for (Int64 k = 0; k < 10000000000; k++)
                        {

                        }
                    }
                }
            }
        }

        static void Test1()
        {
            while (true)
            {

                //do what you need todo
                _AREvt.WaitOne(10, true);
                for (Int64 i = 0; i < 10000000000; i++)
                {
                    for (Int64 j = 0; j < 10000000000; j++)
                    {
                        for (Int64 k = 0; k < 10000000000; k++)
                        {

                        }
                    }
                }

            }
        }
    }
}


Demo





For any clarifications or queries please don’t hesitate to call or Email

Phone :- + 91-9492179390


Email :- lannam@technobrainltd.com (or) lokeshtec@gmail.com 

Read More »