Tuesday, December 9, 2014

Crystal Report Example

First create a Data Set

Click on Add Button
It prompts for a message saying as




Click on Yes Button



Click on Table Adapter.



Click on New Connection



Click on Continue


Give your Server Name
User Name
Password

And Click on Test Connection.


And click on Ok 


 And Click on Next Button


You can write your own query or u can use the stored procedure






Click on Finish





Select crystal report.rpt file and the below screen is visible


And Click on Ok button

And then press ctrl +alt +T


Double Click on ADO.NET(XML)



Give the dataset path of the folder in FileNamePath

Click on Finish

And Build the solution


And Click on Ok Button

Delete Print Date and Page N  from the crystal Report

Go to field explorer and drag your fields to Detail View

We can Format the Header Text by

We can change the font and color by  Format Object Option

To increase the text size automatically 
Select the text object in details tab and then

Right click on it (Format Object)



Now, the Report is Ready add it to the Default page as below

Write the Following Code in .cs page as below

private ReportDocument _reportDocument;
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType =CommandType.StoredProcedure;
        cmd.CommandText = "GetDepartmentInformation";
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        
        DataSet ds = new DataSet();
        da.Fill(ds);
        _reportDocument = new ReportDocument();
        _reportDocument.Load(Server.MapPath("CrystalReport.rpt"));
        _reportDocument.SetDataSource(ds.Tables[1]);
        CrystalReportViewer1.ReportSource = _reportDocument;
        CrystalReportViewer1.DataBind();
    }

Run, it display a blank page without output
To solve this issue, 
Go to this Path : C:\inetpub\wwwroot\aspnet_client\system_web\4_0_30319 .
2) Copy folder name crystalreportviewers13 , and iclude it in your web project.
3) At the Head form where you load and have the crystal report viewer call this java script file.
<head runat="server">  <title>View Report</title> 

<script lang="javaScript" type="text/javascript" src="crystalreportviewers13/js/crviewer/crv.js">

</script>
</head>



In case if you want to Add your own Header Name, like Company Name and Address then, write the following code in .cs page as below


  _reportDocument = new ReportDocument();
        _reportDocument.Load(Server.MapPath("CrystalReport.rpt"));
        _reportDocument.SetDataSource(ds.Tables[1]);
        CrystalReportViewer1.ReportSource = _reportDocument;
        CrystalReportViewer1.DataBind();
        string CompanyName = "abc";
        string Address = "Hyd";
        _reportDocument.DataDefinition.FormulaFields["Company"].Text = "'" + CompanyName + "'";
  _reportDocument.DataDefinition.FormulaFields["Address1"].Text = "'" + Address + "'";



Go to Crystal Report  
Press Ctrl+Alt+T
Field Explorer 




Similary Add Address in Field Explorer
Then Drag them to Report Header as below



In case if you want the output to be displayed in different format like excel, pdf, word, etc

private void ShowReport()
    {
        Response.Buffer = false;
        Response.ClearContent();
        Response.ClearHeaders();

        //for pdf format
        _reportDocument.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "abc")

        //for excel forma
        //_reportDocument.ExportToHttpResponse(ExportFormatType.Excel, Response, false, "abc");

        //for rich text
        //_reportDocument.ExportToHttpResponse(ExportFormatType.RichText, Response, false, "abc");

        //for word
        //_reportDocument.ExportToHttpResponse(ExportFormatType.WordForWindows, Response, false, "abc");

    }


And call that method in main method

string CompanyName = "abc";
        string Address = "Hyd";
        _reportDocument.DataDefinition.FormulaFields["Company"].Text = "'" + CompanyName + "'";
        _reportDocument.DataDefinition.FormulaFields["Address1"].Text = "'" + Address + "'";

           ShowReport();

To Insert Border 





To Insert Line (Similar to Table Columns)



Sunday, July 6, 2014

ENUM

What is enum
It is the value type with set of related named constants
Often referred to as an enumerator list
Enum type can be integer, float.but if you use beside int it has to be cast

Enum is used to create numeric constants in .net framework
By default, the first enumerator has the value 0 , and the value of each successive enumerator is increased by 1
 Enum dow    {sat,sun,mon,tue,wed,thu,fri };

namespaceConsoleApplication2
{
    class program
    {
        public enum DayofWeek
        {
            sunday=1,monday=2,tuesday=3,wednesday=4,thursday,friday,saturday
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Day of week {0} {1}", (int)DayofWeek.sunday, DayofWeek.sunday);
            Console.WriteLine("Day of week {0} {1}", (int)DayofWeek.monday, DayofWeek.monday);
            Console.WriteLine("Day of week {0} {1}", (int)DayofWeek.tuesday, DayofWeek.tuesday);
            Console.WriteLine("Day of week {0} {1}", (int)DayofWeek.wednesday, DayofWeek.wednesday);
            Console.ReadKey();
        }
    }
}

Output:





some important points about enum
enum are enumerated data types in c sharp

enum are strongly typed constants they are  strongly type i,e  an enum of one type may not be implicit assigned to an enum of another type.

Enum values are fixed , enum can be displayed as string and processed as an integer.

Enum are value type and are created on stack and not on heap
               
    class program
    {
        publicenum Volume
        {
            low, medium, high
        }
        classEnumSwitch
        {
            staticvoid Main()
            {
                Volume myvolume = Volume.medium;
                switch (myvolume)
                {
                    case Volume.low:
                        Console.WriteLine("the volume is low");
                        break;
                    case Volume.medium:
                        Console.WriteLine("the volume is medium");
                        break;
                    case Volume.high:
                        Console.WriteLine("the volume is high");
                        break;
                }
                Console.ReadKey();
            }
        }
    }

Saturday, July 5, 2014

Class vs Structure

Structures:
These are also user defined types similar to a class under which you can define all the members what we can define under class.

class
structure
it is reference type
it is value type
it wasn’t faster in access than a structure
these are faster in access
to create a object we required to use a new operator which is mandatory
we can create the object of it without using new operator also
get its memory allocated on managed heap which provides automatic memory management with the help of garbage collector
Gets it memory allocated on stack which does not provides dynamic memory allocation. garbage collector can’t come into picture
it supports inheritance
it does not support inheritance
a programmer can define a default constructor or will be defined by the compiler if  no constructor exists in the class
a default constructor can only be defined by the compiler a programmer can never do it.
can contains variables declared and initialized
can contain variable declaration but can’t be initialized should be initialized either using object of the structure or constructor of the structure.




Structure Example

namespaceConsoleApplication2
{
    structmystruct
    {
        intx;
        publicmystruct(int x)
        {
            this.x = x;
        }
        publicvoid Test()
        {
            Console.WriteLine("Method" + x);
        }
        publicstatic voidMain()
        {
            mystructm1;
            m1.x = 100;
            m1.Test();
            mystructm2 = new mystruct(200);
            m2.Test();
            Console.ReadKey();
        }
    }
}


Output:
Method 100
Method 200

Delegates

Delegates

This were pointer to Methods whenever we call a method to execute a method it creates a stack and destroys .Each time the method is called a stack is created and destroyed.
If u wants to call a method for multiple times without multiple stacks getting created and destroyed make use of a “Delegate”.

Is a type which holds the method(s) reference in an object?
It is also referred as type safe function.       Type safe means same parameter type and same return type

Advantages
Used to call a method asynchronously.
Effective use of delegates approves the performance of application.

Declaration
Syntax:
Public delegate type of delegate, delegatename ()
Eg:
Public delegate int mydelegate(int delvar1,int delvar2)

Delegates:
Public void Add(int x, int y)
{
Console.WriteLine(x+y);
}
Public delegate void AddDel(int x, int y)

Public string SayHello(string name)
{
return “Hello” +name;
}
Public delegate string sayDel(string str)
Creating objects of Delegates
AddDel ad=new AddDel(Add);
sayDel sd=new sayDel(SayHello);

Delegates are of two types
Single cast delegates
Multi cast delegates

Single cast delegate:

If a delegate is used for calling only a single method than it is known as single cast delegate.



output


Multi cast Delegate

If a delegate is used for calling more than one method than it is called as Multi Cast Delegate.
If you want to add a method to the invocation list  of a delegate object, you simple make use of the overloaded+=operator and if you want to remove a method from invocation list make use of overloaded –

Note:
If you want to create a multi cast delegate with return type you will get the return type of the last method in the invocation list.





Server.Transfer and Respone.Redirect

server.transfer
Response.Redirect

does not send any message to the browser but rather redirects the user directly from the server itself
it sends message to the browser saying  it to  move to some different page.
so in server .transfer there is no round trip
has round trip and hence put loads on server
using server.transfer you can not redirect to different server
example if your server is www.yahoo.com and cannot using server.transfer to move to www.microsoft.com
 but yes , you can move to www.yahoo.com/travels i.e within the websites
using response.redirect  you can redirect to different server




Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...