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();
            }
        }
    }

Kubernetes

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