Search Chirayu Software Solutions Blog

Thursday, October 11, 2012

Crystal Report Session -1

Step-1 : Download Crystal Report from below link

http://downloads.businessobjects.com/akdlm/cr4vs2010/CRforVS_13_0.exe

Step -2 Create new website

Step - 3 Create Database and One employee table with some filed and data

Step -4 Create Dataset for a employee table

Step -5 Add Crystal Report


Crstalreportusingvs2010/Figure_8.JPG

Now it will ask for the reportcreation type of how you want to create the report.

Crstalreportusingvs2010/Figure_9.JPG
Just click ok button to proceed

Step- 6 Click Project Data >ADO.NET Datasets
Now clik >> button  on dataset

Crstalreportusingvs2010/Figure_10.JPG

Now click on the Finish button and it will show the next screen

Crstalreportusingvs2010/rsz_figure_11.jpg


Once report file is added, you can see Field Explorer on the left side near server explorer.
Expand Database Fields, under that you will be able to find Datatable that we have created earlier. Just expand it and drag one by one filed from Field Explorer to the rpt file under detail section.

Now the report design part is over. Now we have to fetch the data from d dataset and then bind that  to the report viewer.

Step -7
First Drag a CrystalReportViewer control on aspx page from tool box as per below screen:

Crstalreportusingvs2010/Figure_12.JPG

Step -8 Now Add following code in .cs file


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class ReportViewer : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
          
        ReportDocument rptDoc = new ReportDocument();

// First Three line of using Dataset
        DataSet1TableAdapters.infoTableAdapter da= new DataSet1TableAdapters.infoTableAdapter();
        DataSet1.infoDataTable dt1 = new DataSet1.infoDataTable();
        DataSet1.infoRow dr1;
     // Fetch Data
        dt1 = da.GetData();
      

        // Your .rpt file path will be below
        rptDoc.Load(Server.MapPath("CrystalReport.rpt"));

        rptDoc.Database.Tables[0].SetDataSource((DataTable)(dt1));
        //set dataset to the report viewer.
             CrystalReportViewer1.ReportSource = rptDoc;
    }

Now just save everything and run report.


Monday, October 8, 2012

Shaped WPF Form

Step - 1 Download this  image

Step -2 

Open Visual Studio 2010 and create new project.
Under Visual C# project templates, select Windows>>WPF Application.
Use the following XAML:
               <Window x:Class="ShapedWPFForm.ShapedWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ShapedWindow" Height="267" Width="620"
    Background="Transparent" WindowStyle="None" OpacityMask="White"
    AllowsTransparency="True" WindowStartupLocation="CenterScreen">
    <Grid>
        <Image Name="imgBackground" Stretch="Fill" Source="Shape.png" />
        <Label Height="26" Margin="280,55,244,0" Name="lblUserName" VerticalAlignment="Top" FontWeight="Bold" Foreground="Azure"></Label>
            
        <Label Height="26" Margin="280,83,244,0" Name="lblPassword" VerticalAlignment="Top" FontWeight="Bold" Foreground="Azure">
           
        </Label>
        <Button Height="25" HorizontalAlignment="Right" Margin="0,0,97,54" Name="btnLogin" VerticalAlignment="Bottom" Width="131" FontSize="12" >
            
        </Button>
        <TextBox Height="24" HorizontalAlignment="Right" Margin="0,55,89,0" Name="txtUserName" VerticalAlignment="Top" Width="149" />
        <TextBox Height="24" HorizontalAlignment="Right" Margin="0,85,89,0" Name="txtPassword" VerticalAlignment="Top" Width="149" />
    </Grid>
</Window>


And that's it, it's done. :)
Let me explain the XAML:
  1. allowstransparency="True" - This property makes the Form transparent.
  2. background="Transparent" - This property specifies that the background color should be transparent.
  3. windowstyle="None" - This property removes the title bar and makes the form borderless. Basically removes all the system controls from the form.
  4. opacitymask="White" - This property makes the specified background color invisible from the form.