Showing posts with label Crystal Reports. Show all posts
Showing posts with label Crystal Reports. Show all posts

Friday, 17 February 2012

Crystal Reports : Using a specific Group Sort Order

Changing Sort Order of Groups in Crystal Reports


Problem: Membership Invoices are grouped on Finishes , but we wish the invoices output in CalculateNo order.
By default, Crystal sorts on the grouped field.Then What to do?





 IF you have to make your record group by a field(Which by default happen when you create group)
To Sort In In Different Field order you must think your REPORT like this

Group Header #1

Group Header #2

Details Section

Group Footer #2

Group Footer #1






For this you have to first create a group then create another group which will look like this...

in your FIELD EXPLORER





 and below one in GROUP EXPERT



Means  Group  #2 (eg. finish here) Is Under Group  #1 (eg. cal_id here) So First data will SORT IN ORDER BY Group  #1 then SORT IN GROUP BY Group  #2


Hope It Will Help You

Tuesday, 31 January 2012

Crystal Reports And Formula

Quick Start Crystal Reports And Formula



There are several different kinds of formulas in Crystal Reports: report, conditional formatting, selection, search formulas, and running total condition. The majority of formulas in a report are report formulas and conditional formatting formulas.



To Start Up With Basics Of  Formulas In Crystal Report
1)If You Are Very Unknown To Crystal Report Or Not Understanding What I am Talking About You Can View My Previous Blog Which Will Help You To Quick Start With Quick Start With Crystal Report

And If You Understand Keep Continue With This......



1)First Of All,Open Your Crystal Report File In Visual Studio,Now You Have A Field Explorer Like Below




2)Now Right click On Formula field ,And Click New,You Will get A Window Like Below One.





3)Now Type The Name You Want To Give Your Formula,(Which You'll Further Just Drag On Your report And It Will Show The Value Coming From The Output Of The Formula Execution).
Below Is The Screen You'll Get After Clicking Use Editor.Now Understand The Below Image And Apply Your Self Defined Formulas In Report




Below Are Sample Which You Can Use To Understand Formula Rules For Crystal Report.
Some Thing You Note Written Under {} are field of particular table or view.

Formula Field Is Easy To Use

1)
"FY " +  Totext(ToNumber({wsp_DSSRptPerfCrit;1.startyear})+ 1)

will give an date(eg.) FY 2,009.00

2)

"FY " +  Totext(ToNumber({wsp_DSSRptPerfCrit;1.startyear})+ 1,0)
 will give u the same date(abv eg.) FY 2,009



These above called basic syntax


But this one called crystal syntax


Sum Up A Column Could Be Done As

local numberVar a;

a:=a+ ToNumber({vw_PackingInvoicePart2Merge.totalpcs});

ToText(a);

To 'SUM' up you can also right click on report and go for this
insert>summary
choose your column name from summary window...and select calculate summary as SUM it will sum up that particular coloumn


Discount Could Be Done As
local numberVar a;


 local numberVar b;

a:=sum({VIEWINVOICEFRESH.multy});
b:=ToNumber({VIEWINVOICEFRESH.Discount})*a/100;

ToText(b);

Number To Word Could Be Done As

local numberVar a;

 local numberVar b;
 local numberVar c;
 local numberVar d;
 local numberVar e;
a:=sum({VIEWINVOICEFRESH.multy});
b:=ToNumber({VIEWINVOICEFRESH.Discount})*a/100;
c:=ToNumber({VIEWINVOICEFRESH.Fright});
d:=ToNumber({VIEWINVOICEFRESH.ET});
e:=a+c+d-b;
ToText(e);

ucase(ToWords(e,0)+" and "+{VIEWINVOICEFRESH.Small_Unit}  +" " + towords((Round(e,2)-int(e))*100,0)+" Only");

And What if there is a condition that write 25.00 as twenty five but 23.89 as twenty three Cents eighty nine only(Dynamically in Crystal report)??

In Such Case Use This:

if Round({@Total Amount},2) - Int({@Total Amount}) = 0 then
"Ringgit Malaysia: " + ToWords ({@Total Amount},0) + " only"
else
"Ringgit Malaysia: " + {@
NumToWords1}  + " and " + "Cents " + ToWords ((Round({@Total Amount},2) - Int({@Total Amount})) * 100, 0) + " only"



Now The Things You Must Ask Me Are....
what is?
ucase()-To Write Words In UPPER CASE
towords()-use to understand an integer as word
ToText(e)-Convert Any Thing as String
ToText(e,0)-Remove decimal from end like 25.00 to 25
sum()-Sum Up Selected Column
(Round(e,2) -Use To Round Off Figure of Integer.


To Fit Size Of Detail Section 


print at bootom of page for group footer
fit section for detail section

Thursday, 19 January 2012

Crystal Report Details Values Conflicts

Crystal Report Showing Wrong Values On Pressing Print Button?
or
Crystal Report Details Section Value Changes On Run Time When You Click Print Button?

A Major Hurdel Of Crytal Report Is Solved Now!
Did You Ever Notice The Values In Details Section Changes Automatically When You Press Any Button From The Crystal Report Toolbar On Top.
In Simple Words Its Just Because Crystal Report Saying That Please Learn The Life Cycle Of ASP.Net Page Again!
By Means Of This I Want To Say That Crystal Report Showing Confliction In Values Because Of Loading All Values On Page Load Every Time!


Basically you are addicted to love using thing like this..

Writing your reprt binding function in page load by making sure that page is not post back



 protected void Page_Load(object sender, EventArgs e)  
    {                 
           if (!Page.IsPostBack)
            { 
               bindingfunction();    
            }
    }







Why Don't You Try Put You Binding function In Page_Init Step of Page life cycle

protected void Page_Init(object sender, EventArgs e)  
    {                 
           if (!Page.IsPostBack)
            {
               bindingfunction();    
            }
    }






And You'll See Nothing Is Sorted Out Because You Are Still Calling your page.ispostback here
just remove it and see the problem is no more existed in your crystal page.


protected void Page_Init(object sender, EventArgs e)  
    {                 
          
              bindingfunction();    
           
    }

Ask Me If You Didn't Understand any thing  from above or you have further more question

Sunday, 8 January 2012

Diffrent kind of rows in crystal report asp.net

Generating Rows With Logic Of 'Group By'


There were some condition where you require to filter your data accordingly with a single value,for eg. you want to show a product one side(lets say right side) and its all rows of its processing  in other.



For Such Cases You Have To Use Grouping Concept Of Crystal Reports.
Below Is An Sample Of It..

1)Create table table_Product,as i 've created below

 

2)Create  Another Table With Name table_Details,as i 've created below


3)Lets says you've entered or the values under those table are like Below..

table_Product
 

table_Details












4)Now Add A Crystal Report And A Asp.net Page with name CrystalReport.rpt and CReport.aspx
respectively as Below


5)Now Proceed Step 1  to  7 From My Previous Example Creating Basic Example Of Crystal Report And Make Your Tables Attached To Your Crystal Report As Below.

6)Now Here Is The Thing Comes!
Right Click to The Group Name Field And Click On Insert Group As Above,
After that a pop up window will appear,Now Select the Column Name By Which you Need To do 'Group By' as below.



7)By Default The A Group #1 Name Object Is Now Created With Group header section and Group footer section,as below.




8)Now Add Details By Draging To Section3, Group header section & Group footer section and you'll get the result




I've done changes as below two images you can change as per your requirements.
I)


II)


9)Finally When You Generate The Out Put Will Be Like This...




Download Sample From Here


Friday, 11 November 2011

Crystal Report Basic Sample

 
7 Easy Steps to get start with Crystal Report.


To Start With You Shold Have A Table In your Database.





Before I start I would like to recommend new kind of reporting which is which is currently a hot topic in IT industry, that is Power bi,and you can head start with it by viewing this popular video on power bi which can make you power bi professional in very simple stepsas below.




1)Open visual studio...then create website

2)Now open  toolbox,go on Reporting TAB,Add Crystal Report Viewer To Any Of Your Blank ASPX page,
(if only Pointer And MicrosoftViewer Is Present or If Crystal Report Is Not Existed In the Reporting TAB.Go through the VISUAL STUDIO SET UP AGAIN AND CHOOSE  ADD NEW ITEM instead of UPDATE OPTION THIS TIME and you'll see in the installation list crystal report is in the last!)



2)Now After You Drag The Crystal Report Viewer Control you'll get a control in your page with name 'CrystalReportViewer1')

Now right click to your solution add new item and select CrystalReport.this will add crystal report to  your solution (as you add webform or any file) wth name 'CrystalReport.rpt'

Now You Have
a Crystal Report (CrystalReport.rpt)
And
a Crystal Report Control (CrystalReportViewer1)In a Form Who Can Handle It.




3)Now When You Open Crystal Report  The Screen Will Look Some Thing Like This



 
4)Now You’ll Find Field Explorer side bar in right with solution Explorer As Shown open it and right click Database Field




5) After That A New Window Will open ‘DATABASE EXPERT’

Now Here  Is The Thing You Have To Go Smoothly.
Click ‘create new connection’ + sign
then + sign of OL EDB ADO



then a window will appear which wil ask you to set your database path...

make proper connection…
After that your database will get generate on right hand side pane.





Click > and transfer your database to 'selected table' box(on right hand side)
Click table name press ok

and you have done 90% of work!






6)
Now just Explore database field of field explorer(Field Explorer  Only Appears in CrytalReport) and drag coloumn name to the Crystal report .
wherever you want
(Coloum automaticly behave as they are bind in gridview or datalist)




Check the toolbox you have four tools to design.










7)
Write this code in form .cs file where the control exist

i)add these namespaces must


using System.IO;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Enterprise;
using CrystalDecisions.ReportSource;



ii)and continue to this as you understand

Now the basic thing you have to do is Binding Your Database Value to Crystal Report!
if You Understand the basic binding you can easily notice that i 've just binded values to crytal report!


public void NormalBinding()
{

SqlCommand sqlcmd = new SqlCommand("
select * from sample", con);SqlDataAdapter  da = new SqlDataAdapter(sqlcmd); 
DataTable dt = new DataTable();
dt.Clear();
da.Fill(dt);


if (dt.Rows.Count > 0)
{
ReportDocument RptDoc = new ReportDocument();

RptDoc.Load(Server.MapPath("CrystalReport.rpt"));
RptDoc.SetDataSource(dt);

CrystalReportViewer1.ReportSource = RptDoc;
CrystalReportViewer1.DataBind();

}

                            



Above one is all about a function  NormalBinding() who's used to bind data in crystal report!      
you can take a look to basic binding on my basic asp.net post.



Now Your Whole Project Will Look Some thing Like This.

.ASPX PAGE
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="crys.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
    Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
    </div>
    </form>
   
</body>
</html>

.CS FILE
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Enterprise;
using CrystalDecisions.ReportSource;
public partial class _Default : System.Web.UI.Page
{
    SqlConnection sconn = new SqlConnection(ConfigurationManager.AppSettings["regattacon"]);
    string sid;
    SqlDataAdapter da;
    string query;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
         
            bindproformainvoicepi_no();

        }
    }

    public void bindproformainvoicepi_no()
    {

        query = "select * from sample";
        SqlCommand sqlcmd = new SqlCommand(query, sconn);

        da = new SqlDataAdapter(sqlcmd); DataTable dt = new DataTable();
        dt.Clear();
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            ReportDocument RptDoc = new ReportDocument();

            RptDoc.Load(Server.MapPath("CrystalReport.rpt"));
            RptDoc.SetDataSource(dt);

            CrystalReportViewer1.ReportSource = RptDoc;
            CrystalReportViewer1.DataBind();
          


        }
    }
}






RUN it and have fun with CRYSTAL REPORT,with its nice printing,exporting to excel,pdl,doc ,style












Print Only Grid View in ASP.net

ASP.net How to Print Only GridView < div id ="gridviewDiv" >   < asp:GridView ID ="gridViewToPri...