Tuesday, February 15, 2011

WCF Service

1)create service
2)debug
3)copy the url address
4)go to visual studio 2008 commad prompt wrire the command
as

c:/>svcutil /language:cs /out:proxy.cs /config:app.config http://localhost/wcfbatch8-9/MathService.svc
-->hit Enter it creates the following files
c:/>app.config
c:/>proxy.cs
 --------------------------------------------------------------
to open it in a notpad
c:/>notepad app.config
c:/>notepad proxy.cs

To create in a required directory
example to go to D:/ Drive
c:\>d:
it is changed to
D:\>
---------------------------------------
To Open folders in D:\ Drive
D:\>dir
-----------------------------------
To Open folder in D:\ drive
D:\>cd foldername
it changed to
D:\foldername>
------------------------
To go back to a folder
D:\foldername>cd..
it chaanged to
D:\>
----------------
 

Set Expire Date to application

http://www.stardeveloper.com/articles/expires-and-max-age-headers-in-aspnet/

http://www.stardeveloper.com/articles/real-world-example-of-load-time-improvement-after-using-static-resource-caching/

date Formats:

 select convert(varchar(11),getdate(),111)

varchar(max)----datatype
getdate ()---------Method to get the system date
formating-----
100 for:--------------- Mar 28 2011 
104for----------------28.03.2011
108 for ------------18:22:31 (System time)

Note: we can give the third parameter as100 to 121 give any number...
1-25 give diferent formats of date...

E



Saturday, February 12, 2011

Crystal Reports

1) design Crytal repport
2) Write A select Comand Stored Procedure For Required Fields  From The Related tables..
3)Go to View--> Select Solution Explorer-->Right Click on Project -->add new item
4) select Dataset From Templates--> Change the name of dataset

5)go to visual studio menu-->View-->Select Server Explorer

6)Refresh The data Connections--> add new Connection to add your database
7) after adding refresh the data base
8)Open (double click)the datatset   that you have added in the solution explorer
9)select the stored procedure you have return for selected fields
10)drag the stored procedure and drop it in dataset

--------------------------------------------------------------------------------------------
step-1
---------
Create Stored procedure with the required fields which you want to display in the crystal reports........

example
-------

create proc sp_Demo(@id varchar(50))
as
select s1.*,s2,* from TableA S1,TableB s2 where s1.id=s2.id and s1.id=(some values.....)

execute the query........

step-2
---------
->Using VS-2008
->right click on project name->Add New Item->Dataset->specify a Name->Click Ok
a form opens with .xsd extension (example:Dataset1.xsd)
------------------------------
Note .You Must Change The The Name...
Don't Give The Name as Dataset.xsd
---------------------------------------
->now open Server Explorer from View Tab in VS-2008
->connect the data connection,select the database stored procedure which u have created(i.e., sp_Demo) from server explorer,now drag the stored procedure which u have created i.e (sp_Demo) and drop it in the .xsd window(i.e Dataset1.xsd)
->build the solution of .xsd window

step-3
------
->->Right click on project name->click on Add new Item->Crystal Reports->specify meaning ful name(i.e CrystalReportDemo.rpt)->click OK->another dialogue box appears->select as a Blank Report i.e second option->click OK
->Crsytal Report window is opened....now design the Crystal view based on ur requirement.......

step-4
------
-->come back to crystal report which u have designd
->right click on database fields in field Explorer
->select Database Expert,a dialogue box appears
->In the right panel of the dialogue box click on ProjectData->ADO.NET Datasets->select the appropriate dataset file which u hve created in step-2(i.e Dataset1)
->select the storedprocedure which u hve created(i.e sp_Demo) and click on '>' button
->click on OK

Now required fields are stored in Database fields in Field Explorer,just click the + symbol beside Database Fields.....
->Now place the dataitems required on the crystal report by drap and drop method


step-5
------
->right click on project name->Add new Item->Class->
->specify a class file with some meaninf ful name(i.e Reports.cs)class file
->inherit system.web.ui.page class to import some features into the Reports class(i.e., public class Reports : System.Web.UI.Page )("public class Reports" is genarated by default just add ": System.Web.UI.Page" to the class name Reports)
->place the following code within some method based on the stored procedure u have created,and pass the required parameters to the method(number of parameters passed to the method should match the parameters passed th the stored procedure).....
--------------------------------------
Note:
////Crystal Report Path="~\\Reports\\CrystalReportDemo.rpt"    ////
////Stored Procedure Name=="sp_Demo"
////Your Reports Will Be generate  In PDF Format("context.Response.ContentType = "application/pdf""

-----------------------------------------
Write The following code in Reports.cs Class file

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


public class Reports : System.Web.UI.Page
{

// //Conection Objects Are created in a seperate classs named Connection.cs../ OR you can write connection objects in the page itself/////
    connection obj1 = new connection();
    ReportDocument rpt = new ReportDocument();
    DataSet1 ds1 = new DataSet1();

public void Demoreport(string s)
    {
     
        obj1.con.Open();
        obj1.cmd = new SqlCommand("sp_Demo", obj1.con);
        obj1.cmd.CommandType = CommandType.StoredProcedure;
        obj1.cmd.Parameters.AddWithValue("@id", s);
        obj1.da = new SqlDataAdapter(obj1.cmd);
        obj1.da.Fill(ds1, "sp_Demo");


 
        rpt.Load(Server.MapPath("~\\Reports\\CrystalReportDemo.rpt"));
        rpt.SetDataSource(ds1.Tables["sp_Demo"]);

        System.Web.HttpContext context = System.Web.HttpContext.Current;
        MemoryStream oStream;  // using System.IO
        oStream = (MemoryStream)
        rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
        context.Response.Clear();
       context.Response.Buffer = true;
        context.Response.ContentType = "application/pdf";
        context.Response.BinaryWrite(oStream.ToArray());
        context.Response.End();

     }


step-6
-------
->Place the following code in the print button......of the .aspx.cs file

protected void ButtonPrint_Click(object sender, EventArgs e)
{
Reports rpt=new Reports;
rpt.Demoreport(txt_id.text);
}

--------------------
here:
Reports is the Class name Where the Demoreport( string s) Method is Written..
txt_id.text = Parameter Passed...



NOTE:The Above process will be displayed in PDF Format....to change the format change the code in Report class file..........




Friday, February 11, 2011

Exceptions Handling

Exceptions in Alert Box:::
---------------------------------------
 try
{
do some thing
}
    catch (Exception ex)
    {

        Response.Write("<script>alert(\"an error occur\")</script>");
    }


References
http://stackoverflow.com/questions/3930941/how-to-show-exception-variable-value-in-alert-box-in-asp-net-using-c

Tuesday, February 1, 2011

Grid View Control

-->Write a Function in Administrator.cs class file as follows

 public DataSet viewEmployees()
    {
        obj.ds = SqlHelper.ExecuteDataset(obj.con, CommandType.StoredProcedure, "[sp_allemployees]");
        return obj.ds;
    }
 -----------------------------------------------------------------
-->write a Fill() Method in addemployee.aspx as follows

public void fill()    {
        DataSet ds = obj.viewEmployees();
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
-----------------------------------------------------------------

PAGE INDEXING

1) Set Property of Gridview ----Allow Paging=true;

2) and write code in
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
fill();
}
------------------------------------------
ROW EDITING

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        fill();
    }
----------------------------------------
ROW CANCELING


 protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        fill();
    }


----------------------------------------
 ROW DELETING

 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        obj.deleteemployee(GridView1.DataKeys[e.RowIndex].Values[0].ToString());
        fill();
    }


OR
 --------------------------------------
Row Updating

protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

        TextBox empno = (TextBox)GridView2.Rows[e.RowIndex].FindControl("txtempno") as TextBox;
        TextBox ename = GridView2.Rows[e.RowIndex].FindControl("txtename") as TextBox;
        TextBox esal = (TextBox)GridView2.Rows[e.RowIndex].FindControl("txtesal") as
TextBox;
        sc2.UpdateGrid(Convert.ToInt32(empno.Text), ename.Text,
Convert.ToDecimal(esal.Text));
       

 GridView2.EditIndex = -1;
        fillgrid();
    }


-------------------------------------------
 REferences
http://devilswork.wordpress.com/2009/03/27/gridview-row-edit-delete-and-update/