Search Chirayu Software Solutions Blog

Thursday, October 11, 2012

Crystal Report Session -1

Step-1 : Download Crystal Report from below link

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


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

Just click ok button to proceed

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


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


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:


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

        //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"
    Title="ShapedWindow" Height="267" Width="620"
    Background="Transparent" WindowStyle="None" OpacityMask="White"
    AllowsTransparency="True" WindowStartupLocation="CenterScreen">
        <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">
        <Button Height="25" HorizontalAlignment="Right" Margin="0,0,97,54" Name="btnLogin" VerticalAlignment="Bottom" Width="131" FontSize="12" >
        <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" />

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.