0% found this document useful (0 votes)
159 views

Admin Side Coding (Dhaval)

This document contains code for an admin side master page and a city form page in ASP.NET. The master page code defines the header, menu, footer and includes JavaScript functions for validation. The city form page code defines form fields to add a new city record, including dropdowns to select country, state and status with validation requirements.

Uploaded by

Adv Sunil Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
159 views

Admin Side Coding (Dhaval)

This document contains code for an admin side master page and a city form page in ASP.NET. The master page code defines the header, menu, footer and includes JavaScript functions for validation. The city form page code defines form fields to add a new city record, including dropdowns to select country, state and status with validation requirements.

Uploaded by

Adv Sunil Joshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 101

Admin Side Coding

AdminMasterMenu.aspx

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="AdminMasterMenu.master.cs"


Inherits="Admin_AdminMasterMenu" %>

<%@ Register Src="Controls/ucAdminFooter.ascx" TagName="ucAdminFooter" TagPrefix="uc2" %>

<%@ Register Src="Controls/ucAdminHeaderMenu.ascx" TagName="ucAdminHeaderMenu"


TagPrefix="uc1" %>

<!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>Easy Leave</title>

<link href="../App_Themes/Theme/black_world.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" language="javascript">

function toggleAllCheckboexs(toggle)

n = document.forms[0].length;

var frm = document.forms[0];

for(i=0;i<frm.length;i++)

if(frm.elements[i].type=="checkbox")

if (frm.elements[i].name.indexOf('Cbx')==0)

frm.elements[i].checked=toggle;

}
function onlyNumbers(evt)

var e = event || evt;

var charCode = e.which || e.keyCode;

if ((charCode > 47 && charCode < 58))

return true;

else

return false ;

function OnlyChars(evt)

var e = event || evt;

var charCode = e.which || e.keyCode;

if ((charCode > 64 && charCode < 91)||(charCode > 96 && charCode < 123) || charCode==32)

return true;

else

return false ;

function onlyNumbersdot(evt)

var e = event || evt;

var charCode = e.which || e.keyCode;

if (charCode > 47 && charCode < 58 || charCode==46)


return true;

else

return false ;

function onlyNumbershifen(evt)

var e = event || evt;

var charCode = e.which || e.keyCode;

if ((charCode > 47 && charCode < 58 || charCode==45))

return true;

else

return false ;

function onlyNumbersUnderScore(evt)

var e = event || evt;

var charCode = e.which || e.keyCode;

if ((charCode > 47 && charCode < 58 || charCode==95))

return true;

else

return false ;

</script>
</head>

<body>

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>

<div>

<table width="815px" border="0" align="center" cellpadding="0" cellspacing="0">

<tr>

<td height="130" valign="top" >

<table border="0" cellpadding="0" cellspacing="0">

<tr >

<td class="border" style="width: 811px; text-align: center">

<table border="0" cellpadding="0" cellspacing="0" style="width: 264px">

<tr>

<td align="center" class="logo" style="width: 284px">

Easy Leave</td>

</tr>

</table>

</td>

</tr>

<tr>

<td>

<asp:Menu ID="Menu1" runat="server" BackColor="#B5C7DE" DynamicHorizontalOffset="2"

Font-Bold="True" Font-Names="Verdana" Font-Size="X-Small" ForeColor="#284E98"

Orientation="Horizontal" StaticEnableDefaultPopOutImage="False"
StaticSubMenuIndent="10px"
Width="100%" Height="25px">

<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />

<DynamicHoverStyle BackColor="#284E98" ForeColor="White" />

<DynamicMenuStyle BackColor="#B5C7DE" />

<StaticSelectedStyle BackColor="#507CD1" />

<DynamicSelectedStyle BackColor="#507CD1" />

<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />

<Items>

<asp:MenuItem Text="||" Value="||"></asp:MenuItem>

<asp:MenuItem Text="Administration" Value="Administration">

<asp:MenuItem NavigateUrl="~/Admin/frmChangePassword.aspx" Text="Change


Password" Value="Change Password">

</asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmManageDept.aspx" Text="Manage


Department" Value="Manage Document Category">

</asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmManageCountry.aspx" Text="Manage


Country" Value="Manage Country">

</asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmManageState.aspx" Text="Manage State"


Value="Manage State">

</asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmManageCity.aspx" Text="Manage City"


Value="Manage City">

</asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmManageStatus.aspx" Text="Manage Status"


Value="Manage Status">

</asp:MenuItem>
</asp:MenuItem>

<asp:MenuItem Text="|" Value="|"></asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmFindBalanceLeaves.aspx" Text="Manage Leave"

Value="Manage Leave"></asp:MenuItem>

<asp:MenuItem Text="|" Value="|"></asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmManageEmployee.aspx" Text="Manage


Employee"

Value="Manage Employee"></asp:MenuItem>

<asp:MenuItem Text="|" Value="|"></asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmLeaveChecking.aspx" Text="Manage Leave


Sanction"

Value="Manage Leave Sanction"></asp:MenuItem>

<asp:MenuItem Text="|" Value="|"></asp:MenuItem>

<asp:MenuItem Text="Reports" Value="Reports">

<asp:MenuItem NavigateUrl="~/Admin/frmMonthlyLeaveTransactions.aspx"
Text="Monthly Leave"

Value="Monthly Leave"></asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmYearlyLeaveTransactions.aspx" Text="Yearly


Leave"

Value="Yearly Leave"></asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmPresentedEmpList.aspx"
Text="PresentEmployeesList"

Value="PresentEmployeesList"></asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmNextDayEmpList.aspx"
Text="NextdayEmployeesList"

Value="NextdayEmployeesList"></asp:MenuItem>

</asp:MenuItem>

<asp:MenuItem Text="|" Value="|"></asp:MenuItem>


<asp:MenuItem NavigateUrl="~/Admin/frmSingOutSuccessFul.aspx" Text="Logout"
Value="Logout">

</asp:MenuItem>

<asp:MenuItem Text="||" Value="||"></asp:MenuItem>

</Items>

<StaticHoverStyle BackColor="#284E98" ForeColor="White" />

</asp:Menu>

</td>

</tr>

</table>

</td>

</tr>

<tr>

<td bgcolor="#7A7A7A" class="content" style="padding-top:10px; padding-bottom:10px; width:


815px;">

<div style="height:420px">

<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">

</asp:contentplaceholder>

</div>

</td>

</tr>

<tr>

<td bgcolor="#96C942" class="content" align="center" style="text-align: center;" >

<uc2:ucAdminFooter ID="UcAdminFooter1" runat="server" />

</td>

</tr>
</table>

</div>

</form>

</body>

</html>

Frmcity.aspx

<%@ Page Language="C#" MasterPageFile="~/Admin/AdminMasterMenu.master"


AutoEventWireup="true" CodeFile="frmAddCity.aspx.cs" Inherits="Administration_frmAddCity" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

<table border ="0" cellpadding ="0" cellspacing ="0" width="100%" height="375"


class="publicloginTable">

<tr >

<td style="width:100%" valign="top" align="left">

<table width="100%" class="admintablestyle">

<tr>

<td colspan="4" class="LoginTitle">

Add City

</td>

</tr>

<tr>

<td align="center" class="lblerror" colspan="4">

<asp:Label ID="lblError" runat="server" Visible="false" Text=""></asp:Label>

</td>
</tr>

<tr>

<td colspan="4" class="lblerror">

*- Mandatory fields</td>

</tr>

<tr>

<td style="width:18%" >

City Name<span class="lblerror">*</span>

</td>

<td style="width:2%">:</td>

<td style="width:18%">

<asp:TextBox ID="txtCityName" runat="server" Width="160px"></asp:TextBox>

</td>

<td>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"


ControlToValidate="txtCityName"

ErrorMessage="Please Enter CityName" >*</asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td >

City Description

</td>
<td>:</td>

<td>

<asp:TextBox ID="txtCityDescription" runat="server" TextMode="MultiLine"


Width="160px"></asp:TextBox>

</td>

<td>

</td>

</tr>

<tr>

<td>

Country Name<span class="lblerror">*</span></td>

<td>

:</td>

<td>

<asp:DropDownList ID="ddlCountryName" runat="server" AutoPostBack="True"


OnSelectedIndexChanged="ddlCountryName_SelectedIndexChanged" Width="90px">

</asp:DropDownList>

</td>

<td><asp:Label id="lblErrorCountryName" runat="server" Text="Select Country Name"


CssClass="lblerror" Visible="False"></asp:Label>

</td>

</tr>

<tr>

<td>

State Name<span class="lblerror">*</span></td>

<td>

:</td>
<td>

<asp:DropDownList ID="ddlStateName" runat="server" Width="90px">

</asp:DropDownList>

</td>

<td><asp:Label id="lblErrorStateName" runat="server" Text="Select State Name"


CssClass="lblerror" Visible="False"></asp:Label>

</td>

</tr>

<tr>

<td >

Status<span class="lblerror">*</span>

</td>

<td>:</td>

<td>

<asp:DropDownList ID="ddlStatus" runat="server" Width="90px">

<asp:ListItem>Select</asp:ListItem>

<asp:ListItem>Active</asp:ListItem>

<asp:ListItem>InActive</asp:ListItem>

</asp:DropDownList>

</td>

<td><asp:Label id="lblErrorStatus" runat="server" Text="Select Status Name" CssClass="lblerror"


Visible="False"></asp:Label>

</td>

</tr>

<tr>
<td colspan="2" style="height: 26px">

</td>

<td colspan="2" style="height: 26px">

<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" Width="65px"


/>&nbsp;

<asp:Button ID="btnBack" runat="server" Text="Back" OnClick="btnBack_Click"


CausesValidation="False" Width="65px" />

</td>

</tr>

</table></td></tr></table>

</asp:Content>

Adminheadermenu.aspx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ucAdminHeaderMenu.ascx.cs"


Inherits="Admin_Controls_ucHeaderMenu" %>

<table border="0" cellpadding="0" cellspacing="0" width="100%" align="center" >

<tr><td>

<asp:Menu ID="Menu1" runat="server" BackColor="#B5C7DE" DynamicHorizontalOffset="2" Font-


Names="Verdana" Font-Size="X-Small" ForeColor="#284E98" Orientation="Horizontal"
StaticSubMenuIndent="10px" Width="100%" Font-Bold="True"
StaticEnableDefaultPopOutImage="False">

<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />

<DynamicHoverStyle BackColor="#284E98" ForeColor="White" />

<DynamicMenuStyle BackColor="#B5C7DE" />

<StaticSelectedStyle BackColor="#507CD1" />


<DynamicSelectedStyle BackColor="#507CD1" />

<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />

<Items>

<asp:MenuItem Text="||" Value="||"></asp:MenuItem>

<asp:MenuItem Text="Administration" Value="Administration">

<asp:MenuItem Text="Change Password" Value="Change Password"


NavigateUrl="../frmChangePassword.aspx"></asp:MenuItem>

<asp:MenuItem Text="Manage Department" Value="Manage Document Category"


NavigateUrl="~/Admin/frmManageDept.aspx"></asp:MenuItem>

<asp:MenuItem Text="Manage Country" Value="Manage Country"


NavigateUrl="../frmManageCountry.aspx"></asp:MenuItem>

<asp:MenuItem Text="Manage State" Value="Manage State"


NavigateUrl="../frmManageState.aspx"></asp:MenuItem>

<asp:MenuItem Text="Manage City" Value="Manage City"


NavigateUrl="~/Admin/frmManageCity.aspx"></asp:MenuItem>

<asp:MenuItem Text="Manage Status" Value="Manage Status"


NavigateUrl="../frmManageStatus.aspx"></asp:MenuItem>

</asp:MenuItem>

<asp:MenuItem Text="|" Value="|"></asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmFindBalanceLeaves.aspx" Text="Manage Leave"


Value="Manage Leave">

</asp:MenuItem>

<asp:MenuItem Text="|" Value="|"></asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmManageEmployee.aspx" Text="Manage Employee"

Value="Manage Employee"></asp:MenuItem>

<asp:MenuItem Text="|" Value="|"></asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmLeaveChecking.aspx" Text="Manage Leave Sanction"

Value="Manage Leave Sanction"></asp:MenuItem>


<asp:MenuItem Text="|" Value="|"></asp:MenuItem>

<asp:MenuItem Text="Reports" Value="Reports">

<asp:MenuItem NavigateUrl="~/Admin/frmMonthlyLeaveTransactions.aspx" Text="Monthly


Leave"

Value="Monthly Leave"></asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmYearlyLeaveTransactions.aspx" Text="Yearly Leave"

Value="Yearly Leave"></asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmPresentedEmpList.aspx"
Text="PresentEmployeesList"

Value="PresentEmployeesList"></asp:MenuItem>

<asp:MenuItem NavigateUrl="~/Admin/frmNextDayEmpList.aspx"
Text="NextdayEmployeesList"

Value="NextdayEmployeesList"></asp:MenuItem>

</asp:MenuItem>

<asp:MenuItem Text="|" Value="|"></asp:MenuItem>

<asp:MenuItem Text="Logout" Value="Logout"


NavigateUrl="~/Admin/frmSingOutSuccessFul.aspx"></asp:MenuItem>

<asp:MenuItem Text="||" Value="||"></asp:MenuItem>

</Items>

<StaticHoverStyle BackColor="#284E98" ForeColor="White" />

</asp:Menu>

</td></tr>

</table>

Loginclass.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

/// <summary>
/// Summary description for clsApplication_Logic
/// </summary>
public class clsApplication_Logic
{
string _UserName, _StartingDate, _EndingDate, _ApplaiyingDate, _LeavePurpose;
int _LeaveTypeId, _NoOfDays, _AppStatusId, _ApplicationNo;
public string Sort_On;
public clsApplication_Logic()
{
//
// TODO: Add constructor logic here
//
}
public string UserName
{
get { return _UserName; }
set { _UserName = value; }
}
public string StartingDate
{
get { return _StartingDate; }
set { _StartingDate = value; }
}
public string EndingDate
{
get { return _EndingDate; }
set { _EndingDate = value; }
}
public string ApplaiyingDate
{
get { return _ApplaiyingDate; }
set { _ApplaiyingDate = value; }
}
public string LeavePurpose
{
get { return _LeavePurpose; }
set { _LeavePurpose = value; }
}

public int NoOfDays


{
get { return _NoOfDays; }
set { _NoOfDays = value; }
}

public int LeaveTypeId


{
get { return _LeaveTypeId; }
set { _LeaveTypeId = value; }
}
public int AppStatusId
{
get { return _AppStatusId; }
set { _AppStatusId = value; }
}

public int ApplicationNo


{
get { return _ApplicationNo; }
set { _ApplicationNo = value; }
}
public void AddLeaveApplication()
{
SqlParameter[] p = new SqlParameter[8];
p[0] = new SqlParameter("@LeaveTypeId", SqlDbType.Int);
p[0].Value = _LeaveTypeId;
p[1] = new SqlParameter("@UserName", SqlDbType.VarChar);
p[1].Value = _UserName;
p[2] = new SqlParameter("@StartingDate", SqlDbType.DateTime);
p[2].Value = Convert.ToDateTime(_StartingDate);
p[3] = new SqlParameter("@EndingDate", SqlDbType.DateTime);
p[3].Value = Convert.ToDateTime(_EndingDate);
p[4] = new SqlParameter("@ApplyingDate", SqlDbType.DateTime);
p[4].Value =Convert.ToDateTime( _ApplaiyingDate);
p[5] = new SqlParameter("@NoOfDays", SqlDbType.Int);
p[5].Value = _NoOfDays;
p[6] = new SqlParameter("@LeavePurpose", SqlDbType.VarChar);
p[6].Value = _LeavePurpose;
p[7] = new SqlParameter("@StatusId", SqlDbType.Int);
p[7].Value = 3;

SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),CommandType.StoredPro
cedure,"spAddLeaveApplication",p);
}

public void UpdateApplicationData()


{
SqlParameter[] p = new SqlParameter[2];
p[0] = new SqlParameter("@StausId", SqlDbType.Int);
p[0].Value = _AppStatusId;
p[1] = new SqlParameter("@ApplicationNo", SqlDbType.Int);
p[1].Value = _ApplicationNo;
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spUpdateApplicationData", p);
}

public DataSet GetApplicationStatus()


{
SqlParameter[] p = new SqlParameter[1];
p[0] = new SqlParameter("@UserName", SqlDbType.VarChar);
p[0].Value = _UserName;
return SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spGetApplicationStatus",p);
}

public DataSet GetApplicationLeaveDetails()


{
SqlParameter[] p = new SqlParameter[1];
p[0] = new SqlParameter("@ApplicationNo", SqlDbType.Int);
p[0].Value = _ApplicationNo;
return SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spGetApplicationLeave", p);
}
//jan 04
public DataSet GetApplicationData()
{
string strSql = string.Empty;
strSql = "select * from tbl_ApplicationData a,tbl_Status s,tbl_LeaveType l where
a.ApplicationStatusId=s.StatusId and a.LeaveTypeId=l.LeaveTypeId ";
if (!string.IsNullOrEmpty(_UserName))
strSql += " and a.UserName like '%" + _UserName + "%'";
if (_LeaveTypeId!=0)
strSql += " and a.LeaveTypeId=" + _LeaveTypeId;
if (!string.IsNullOrEmpty(Sort_On))
{
strSql = strSql + " ORDER BY " + Sort_On;
}
else
{
strSql = strSql + " Order By a.UserName";
}
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;
}
}

clsBLAdminLogin_Logic.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
/// <summary>
/// Summary description for ClsBLAdminLogin
/// </summary>
public class clsAdminLogin_Logic
{
public clsAdminLogin_Logic()
{
//
// TODO: Add constructor logic here
//
}

string _AdminLoginId, _Password,_OldPassword;

public string Password


{
get { return _Password; }
set { _Password = value; }
}

public string AdminLoginId


{
get { return _AdminLoginId; }
set { _AdminLoginId = value; }
}

public string OldPassword


{
get { return _OldPassword; }
set { _OldPassword = value; }
}

public DataSet GetAdminLoginDetails()


{
SqlParameter[] p = new SqlParameter[2];
p[0] = new SqlParameter("@AdminLoginId", SqlDbType.VarChar);
p[0].Value = _AdminLoginId;
p[1] = new SqlParameter("@Password", SqlDbType.VarChar);
p[1].Value = _Password;
DataSet tempds =
SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spAdminLogin", p);
return tempds;
}

public bool CheckAdminOldPassword()


{
SqlParameter[] p = new SqlParameter[2];
p[0] = new SqlParameter("@AdminLoginId", SqlDbType.VarChar);
p[0].Value = _AdminLoginId;
p[1] = new SqlParameter("@Password", SqlDbType.VarChar);
p[1].Value = _OldPassword;
DataSet tempds =
SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spCheckAdminOldPassword", p);
DataRowCollection drc = tempds.Tables[0].Rows;
if (drc.Count > 0)
{
return true;
}
else
{
return false;
}
}

public int AdminChangeOldPassword()


{
SqlParameter[] p = new SqlParameter[2];
p[0] = new SqlParameter("@AdminLoginId", SqlDbType.VarChar);
p[0].Value = _AdminLoginId;
p[1] = new SqlParameter("@Password", SqlDbType.VarChar);
p[1].Value = _Password;
int i = SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spAdminChangePassword", p);
return i;
}

clsCity_Logic.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

///<summary >
///This is BOL City_Logic Class
/// Created By: Team A PropertyNet
/// Created On: 16-Oct-2007
/// Last Modified By: Team A PropertyNet
/// Last Modified On: 16-Oct-2007
/// </summary>
public class clsCity_Logic
{
private int _CityId;
private string _CityName;
private string _CityDescr;
public string Sort_On;
private int _StatusId;
private string _StatusName;
private string _CountryName;
private int _CountryId;
private int _StateId;
private string _StateName;
//private clsDbConnector objDbConnector;
public clsCity_Logic()
{
//objDbConnector = new clsDbConnector();
}
public int pro_CityId
{
get
{
return _CityId;
}
set
{
_CityId = value;
}
}
public string pro_CityName
{
get
{
return _CityName;
}
set
{
if (value.ToString() == "")
{
_CityName = "";
}
else
{
_CityName = value;
}
}
}
public string pro_CityDescription
{
get
{
return _CityDescr;
}
set
{
if (value.ToString() == "")
{
_CityDescr = "";
}
else
{
_CityDescr = value;
}
}
}

public string pro_StatusName


{
get
{
return _StatusName;
}
set
{
_StatusName = value;

}
}
public int pro_StatusId
{
get
{
return _StatusId;
}
set
{
_StatusId = value;
}
}
public string pro_CountryName
{
get
{
return _CountryName;
}
set
{
_CountryName = value;
}

public int pro_CountryId


{
get
{
return _CountryId;
}
set
{
_CountryId = value;
}

public int pro_StateId


{
get
{
return _StateId;
}
set
{
_StateId = value;
}

public string pro_StateName


{
get
{
return _StateName;
}
set
{
_StateName = value;
}

public DataSet GetCity()


{
string strSql = string.Empty;
strSql = "select
d.CityId,d.CityName,d.CityDescription,st.StateName,c.CountryName,s.StatusName from
tbl_CityDetails d,tbl_Country c,tbl_State st,tbl_Status s where d.StatusId=s.StatusId and
d.StateId=st.StateId and d.CountryId=c.CountryId";
if (_CityName != "")
strSql += " and CityName like '%" + _CityName + "%'";
if (_CountryName != "select" && _CountryName!=null)
{
strSql += " and CountryName='" + _CountryName+"'";
}
if (_StateName != "select" && _StateName!=null)
{
strSql += " and StateName='" + _StateName+"'";
}
if (Sort_On != "")
{
strSql = strSql + " ORDER BY " + Sort_On;
}
else
{
strSql = strSql + " Order By CityName";
}
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;
}
public void AddCity()
{
string strSql = string.Empty;
strSql += "Insert into
tbl_CityDetails(CityName,CityDescription,StateId,CountryId,StatusId)";
strSql += " values('" + _CityName + "',";
strSql += " '" + _CityDescr + "',";
strSql += _StateId + ",";
strSql += _CountryId + ",";
strSql += _StatusId + ")";
//objDbConnector.runSQL(strSql);
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
}

public void DeleteCity(string CityId)


{
string strSql = string.Empty;
strSql += "delete from tbl_CityDetails";
strSql += " where CityId in('" + CityId.Replace(",","','") + "')";
//objDbConnector.runSQL(strSql);
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
}
public void GetCityDetails()
{
string strSql = string.Empty;
strSql += "select
d.CityId,d.CityName,d.CityDescription,st.StateName,c.CountryName,s.StatusName from
tbl_CityDetails d,tbl_Country c,tbl_State st,tbl_Status s where d.StatusId=s.StatusId and
d.StateId=st.StateId and d.CountryId=c.CountryId";
strSql += " and CityId=" + _CityId;
DataSet dsTemp;
//dsTemp = objDbConnector.GetDataSet(strSql);
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
DataRowCollection drc = dsTemp.Tables[0].Rows;
if (drc.Count > 0)
{
_CityName = drc[0]["CityName"].ToString();
_CityDescr = drc[0]["CityDescription"].ToString();
_StateName = drc[0]["StateName"].ToString();
_CountryName = drc[0]["CountryName"].ToString();
_StatusName = drc[0]["StatusName"].ToString();
}
else
{
_CityName = "";
_CityDescr = "";
_CountryName = "";
_StateName = "";
_StatusName = "";
}
}
public void UpdateCity()
{
string strSql = string.Empty;
strSql += "Update tbl_CityDetails set";
strSql += " CityName='" + _CityName + "',";
strSql += " CityDescription='" + _CityDescr + "',";
strSql+=" StateId="+_StateId+",";
strSql += " CountryId=" + _CountryId + ",";
strSql += " StatusId=" + _StatusId;
strSql += " where CityId=" + _CityId;
//objDbConnector.runSQL(strSql);
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
}
public DataSet GetStatus()
{

string strSql = string.Empty;


strSql += "select StatusName,StatusId from tbl_Status";
DataSet dsTemp;
//ds = objDbConnector.GetDataSet(strSql);
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;

public DataSet GetState()


{

string strSql = string.Empty;


strSql += "select StateName,StateId from tbl_State";
if(_CountryId!=0)
strSql += " where CountryId=" + _CountryId;
DataSet dsTemp;
//ds = objDbConnector.GetDataSet(strSql);
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;

}
public DataSet GetCountry()
{
string strSql = string.Empty;
strSql += "select CountryName,CountryId from tbl_Country";
DataSet dsTemp;
//ds = objDbConnector.GetDataSet(strSql);
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;

clsCommon_Logic.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

///<summary>
//This is BOL Common_Logic Class
/// Created By: Team A PropertyNet
/// Created On: 19-Oct-2007
/// Last Modified By: Team A PropertyNet
/// Last Modified On: 19-Oct-2007
/// </summary
public class clsCommon_Logic
{

private string _CountryName;


private int _CountryId;
private int _StateId;
private string _StateName;
private int _CityId;
private string _CityName;

public clsCommon_Logic()
{

}
public string pro_CountryName
{
get
{
return _CountryName;
}
set
{
_CountryName = value;
}

}
public int pro_CountryId
{
get
{
return _CountryId;
}
set
{
_CountryId = value;
}

}
public int pro_StateId
{
get
{
return _StateId;
}
set
{
_StateId = value;
}

}
public string pro_StateName
{
get
{
return _StateName;
}
set
{
_StateName = value;
}

}
public int pro_CityId
{
get
{
return _CityId;
}
set
{
_CityId = value;
}
}
public string pro_CityName
{
get
{
return _CityName;
}
set
{
if (value.ToString() == "")
{
_CityName = "";
}
else
{
_CityName = value;
}
}
}

public DataSet GetStatusName()


{
string strSql = string.Empty;
strSql += "select StatusName,StatusId from tbl_Status";
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;
}
public DataSet GetCountryName()
{
string strSql=string.Empty;
strSql+="select CountryName,CountryId from tbl_Country ";
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;
}
public DataSet GetStateName()
{

string strSql = string.Empty;


strSql += "select StateName,StateId from tbl_State";
if(_CountryId!=0)
strSql += " where CountryId=" + _CountryId;
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;
}
public DataSet GetCityName()
{
string strSql = string.Empty;
strSql += "select CityName,CityId from tbl_CityDetails";
if (_StateId != 0)
strSql += " where StateId="+_StateId;
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;
}
public DataSet GetDeptName()
{
string strSql = string.Empty;
strSql += "select DeptName,DeptId from tbl_Dept";
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;
}
public DataSet GetDesignation()
{
string strSql = string.Empty;
strSql += "select * from tbl_Designation";
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;
}

/* public Boolean CheckMemberId(string memberid)


{
string strSql = string.Empty;
strSql += "select count(*) from tbl_Member_Details where MemberId='" + memberid +
"'";
DataSet ds = objDbConnector.GetDataSet(strSql);
//string q = ds.Tables[0].Rows[0][0].ToString();
//SqlDataReader sqlDr = objDbConnector.getSqlDataReader(strSql);
//string s = sqlDr[0].ToString();
if (int.Parse(ds.Tables[0].Rows[0][0].ToString()) == 1)
{
return true;
}
else
{
return false;
}
}*/
}

clsCountry_Logic.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
///<summary >
///This is BOL Country_Logic Class
/// Created By: Team A PropertyNet
/// Created On: 16-Oct-2007
/// Last Modified By: Team A PropertyNet
/// Last Modified On: 16-Oct-2007
/// </summary>
public class clsCountry_Logic
{
private int _CountryId;
private string _CountryName;
private string _CountryDescr;
private string _StatusName;
public string Sort_On;
private int _StatusId;
//int statusId;
//private clsDbConnector objDbConnector;
public clsCountry_Logic()
{
//objDbConnector = new clsDbConnector();
}
public int pro_CountryId
{
get
{
return _CountryId;
}
set
{
_CountryId = value;
}

public string pro_CountryName


{
get
{
return _CountryName;
}
set
{
if (value.ToString() == "")
{
_CountryName = "";
}
else
{
_CountryName = value;
}
}
}

public string pro_CountryDescription


{
get
{
return _CountryDescr;
}
set
{
if (value.ToString() == "")
{
_CountryDescr = "";
}
else
{
_CountryDescr = value;
}
}
}

public string pro_StatusName


{
get
{
return _StatusName;
}
set
{
_StatusName = value;

}
}
public int pro_StatusId
{
get
{
return _StatusId;
}
set
{
_StatusId = value;
}

public DataSet GetCountry()


{
string strSql = string.Empty;
strSql = "select c.CountryId,c.CountryName,c.CountryDescription,s.StatusName from
tbl_Country c,tbl_Status s where c.StatusId=s.StatusId";
if (_CountryName != "")
strSql += " and CountryName like '%" + _CountryName + "%'";
if (Sort_On != "")
{
strSql = strSql + " ORDER BY " + Sort_On;
}
else
{
strSql = strSql + " Order By CountryName";
}
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;
}

public void AddCountry()


{
string strSql = string.Empty;
strSql += "Insert into tbl_Country(CountryName,CountryDescription,StatusId)";
strSql += " values('" + _CountryName + "',";
strSql += " '" + _CountryDescr + "',"+_StatusId+")";
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
}

public void DeleteCountry(string CountryId)


{
string strSql = string.Empty;
strSql += "delete from tbl_Country";
strSql += " where CountryId in('" + CountryId.Replace(",", "','") + "')";
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
}

public void GetCountryDetails()


{
string strSql = string.Empty;
strSql += "select c.CountryId,c.CountryName,c.CountryDescription,s.StatusName
from tbl_Country c,tbl_Status s where c.StatusId=s.StatusId";
strSql += " and c.CountryId=" + _CountryId;
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
DataRowCollection drc = dsTemp.Tables[0].Rows;
if (drc.Count > 0)
{
_CountryName = drc[0]["CountryName"].ToString();
_CountryDescr = drc[0]["CountryDescription"].ToString();
_StatusName = drc[0]["StatusName"].ToString();
}
else
{
_CountryName = "";
_CountryDescr = "";
}
}

public void UpdateCountry()


{
string strSql = string.Empty;
strSql += "Update tbl_Country set";
strSql += " CountryName='" + _CountryName + "',";
strSql += " CountryDescription='" + _CountryDescr + "',";
strSql += " StatusId=" + _StatusId;
strSql += " where CountryId=" + _CountryId;
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
}

public DataSet GetStatusName()


{

string strSql = string.Empty;


strSql += "select StatusName,StatusId from tbl_Status";
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;

Deptlodic.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.ApplicationBlocks.Data;

/// <summary>
/// Summary description for clsDept_Logic
/// </summary>
public class clsDept_Logic
{
private int _DeptId;
private string _DeptName;
private string _DeptDescr;
private string _StatusName;
public string Sort_On;
private int _StatusId;
//int statusId;
//private clsDbConnector objDbConnector;
public clsDept_Logic()
{
//objDbConnector = new clsDbConnector();
}
public int pro_DeptId
{
get
{
return _DeptId;
}
set
{
_DeptId = value;
}

public string pro_DeptName


{
get
{
return _DeptName;
}
set
{
if (value.ToString() == "")
{
_DeptName = "";
}
else
{
_DeptName = value;
}
}
}

public string pro_DeptDescription


{
get
{
return _DeptDescr;
}
set
{
if (value.ToString() == "")
{
_DeptDescr = "";
}
else
{
_DeptDescr = value;
}
}
}

public string pro_StatusName


{
get
{
return _StatusName;
}
set
{
_StatusName = value;

}
}
public int pro_StatusId
{
get
{
return _StatusId;
}
set
{
_StatusId = value;
}

public DataSet GetDept()


{
string strSql = string.Empty;
//strSql = "select c.DeptId,c.DeptName,c.DeptDescription,s.StatusName from
tbl_Dept c,tbl_Status s where c.StatusId=s.StatusId";
strSql += "select * from tbl_Dept where 1=1";
if (_DeptName != "")
strSql += " and DeptName like '%" + _DeptName + "%'";
if (Sort_On != "")
{
strSql = strSql + " ORDER BY " + Sort_On;
}
else
{
strSql = strSql + " Order By DeptName";
}
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;
}

public void AddDept()


{
string strSql = string.Empty;
strSql += "Insert into tbl_Dept(DeptName,DeptDescription)";
strSql += " values('" + _DeptName + "',";
strSql += " '" + _DeptDescr + "')";
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
}

public void DeleteDept(string DeptId)


{
string strSql = string.Empty;
strSql += "delete from tbl_Dept";
strSql += " where DeptId in('" + DeptId.Replace(",", "','") + "')";
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
}

public void GetDeptDetails()


{
string strSql = string.Empty;
// strSql += "select c.DeptId,c.DeptName,c.DeptDescription,s.StatusName from
tbl_Dept c,tbl_Status s where c.StatusId=s.StatusId";
strSql += "select * from tbl_Dept where 1=1";
strSql += " and DeptId=" + _DeptId;
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
DataRowCollection drc = dsTemp.Tables[0].Rows;
if (drc.Count > 0)
{
_DeptName = drc[0]["DeptName"].ToString();
_DeptDescr = drc[0]["DeptDescription"].ToString();
//_StatusName = drc[0]["StatusName"].ToString();
}
else
{
_DeptName = "";
_DeptDescr = "";
}
}

public void UpdateDept()


{
string strSql = string.Empty;
strSql += "Update tbl_Dept set";
strSql += " DeptName='" + _DeptName + "',";
strSql += " DeptDescription='" + _DeptDescr + "'";
// strSql += " StatusId=" + _StatusId;
strSql += " where DeptId=" + _DeptId;
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
}

public DataSet GetStatusName()


{

string strSql = string.Empty;


strSql += "select StatusName,StatusId from tbl_Status";
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;

clsEmployee_Logic.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

/// <summary>
/// Summary description for clsEmployee_Logic
/// </summary>
public class clsEmployee_Logic
{
string _Password, _OldPassword, _EmployeeLoginId, _ContactNo, _Address, _EmailId,
_EmpName,_Designation,_Role,_UserName;
int _EmpId, _CityId, _StateId, _CountryId,_DeptId,_projId;
clsDbConnector objdDbConnector = new clsDbConnector();
public string Sort_On;

public string Role


{
get { return _Role; }
set { _Role = value; }
}
public int ProjId
{
get { return _projId;}
set { _projId = value; }
}

public string Password


{
get { return _Password; }
set { _Password = value; }
}

public int EmpId


{
get { return _EmpId; }
set { _EmpId = value; }
}
public string OldPassword
{
get { return _OldPassword; }
set { _OldPassword = value; }
}
public string EmployeeLoginId
{
get { return _EmployeeLoginId; }
set { _EmployeeLoginId = value; }
}
public string ContactNo
{
get { return _ContactNo; }
set { _ContactNo = value; }
}
public string Address
{
get { return _Address; }
set { _Address = value; }
}
public string EmailId
{
get { return _EmailId; }
set { _EmailId = value; }
}

public string EmpName


{
get { return _EmpName; }
set { _EmpName = value; }
}
public string Designation
{
get { return _Designation; }
set { _Designation = value; }
}
public string UserName
{
get { return _UserName; }
set { _UserName = value; }
}
public int CityId
{
get { return _CityId; }
set { _CityId = value; }
}

public int StateId


{
get { return _StateId; }
set { _StateId = value; }
}
public int CountryId
{
get { return _CountryId; }
set { _CountryId = value; }
}

public int DeptId


{
get { return _DeptId; }
set { _DeptId = value; }
}

public clsEmployee_Logic()
{
//
// TODO: Add constructor logic here
//
}

public DataSet GetEmployeeLoginDetails()


{
SqlParameter[] p = new SqlParameter[2];
p[0] = new SqlParameter("@UserLoginId", SqlDbType.VarChar);
p[0].Value = this._EmployeeLoginId;

p[1] = new SqlParameter("@Password", SqlDbType.VarChar);


p[1].Value = this.Password;

DataSet dsEmployeeLoginDetails=
SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spEmployeeLoginDetails", p);
return dsEmployeeLoginDetails;
}
public int EmployeeChangePassword()
{
//SqlParameter[] p = new SqlParameter[2];

//p[0] = new SqlParameter("@UserId", SqlDbType.VarChar);


//p[0].Value = this._EmployeeLoginId;
//p[1] = new SqlParameter("@Password", SqlDbType.VarChar);
//p[1].Value = this._Password;
int i=0 ;//= SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spEmployeeChangePassword", p);
return i;
}

public bool EmployeeCheckPassword()


{
//SqlParameter[] p = new SqlParameter[2];

//p[0] = new SqlParameter("@UserId", SqlDbType.VarChar);


//p[0].Value = this._EmployeeLoginId;
//p[1] = new SqlParameter("@Password", SqlDbType.VarChar);
//p[1].Value = _OldPassword;
//DataSet ds =
SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spEmployeeCheckPassword", p);
//DataRowCollection drc = ds.Tables[0].Rows;
//if (drc.Count > 0)
//{
// return true;
//}
//else
return false;
}

public int AddEmployeeDetails()


{

SqlParameter[] p = new SqlParameter[13];

p[0] = new SqlParameter("@DeptId", this._DeptId);


p[0].DbType = DbType.Int32;
p[1] = new SqlParameter("@ContactNo", this._ContactNo);
p[1].DbType = DbType.String;
p[2] = new SqlParameter("@Address", this._Address);
p[2].DbType = DbType.String;
p[3] = new SqlParameter("@CityId", this._CityId);
p[3].DbType = DbType.Int32;
p[4] = new SqlParameter("@StateId", this._StateId);
p[4].DbType = DbType.Int32;
p[5] = new SqlParameter("@CountryId", this._CountryId);
p[5].DbType = DbType.Int32;
p[6] = new SqlParameter("@EmailId", this._EmailId);
p[6].DbType = DbType.String;
p[7] = new SqlParameter("@EmpName", this._EmpName);
p[7].DbType = DbType.String;
p[8] = new SqlParameter("@output", SqlDbType.Int);
p[8].Direction = ParameterDirection.Output;
p[9] = new SqlParameter("@UserName", this._UserName);
p[9].DbType = DbType.String;
p[10] = new SqlParameter("@Password", this._Password);
p[10].DbType = DbType.String;
p[11] = new SqlParameter("@DesigName", SqlDbType.VarChar);
p[11].Value = _Designation;
p[12] = new SqlParameter("@Role", SqlDbType.VarChar);
p[12].Value = _Role;
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spAddEmployee", p);
return (int)p[8].Value;

public void AddEmployeeOnProject(string EmployeeIds, int ProjectId)


{
//int i = 0;
//string str = EmployeeIds;
//char[] delimiterChars = { ',' };
//string[] words = str.Split(delimiterChars);
//int length = words.Length;
//string[] sa = new string[length];
//foreach (string s in words)
//{
// sa[i] = "insert into tbl_EmpOnProj values(" + Convert.ToInt32(s) + "," +
ProjectId + ")";
// i++;
//}
//objdDbConnector.BatchTransaction(sa);

public DataSet GetEmployeeOnProject()


{
SqlParameter[] p = new SqlParameter[1];
p[0] = new SqlParameter("@ProjectId", SqlDbType.Int);
p[0].Value = _projId;
return SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spGetEmployeeOnProject", p);
}

public bool DeleteEmpDetails(string UserName)


{
string strSql1, strSql2;
strSql1 = string.Empty;
strSql1 += "delete from tbl_EmpDetails where UserName in('" +
UserName.Replace(",", "','") + "');";
strSql2 = "delete from tbl_Users where UserName in('" + UserName.Replace(",",
"','") + "')";
string[] strSql ={ strSql1, strSql2 };
Boolean b = objdDbConnector.BatchTransaction(strSql);
return b;

/* string strSql = string.Empty;


strSql += "delete from tbl_Supplier";
strSql += " where SupplierId in('" + SupplierId.Replace(",", "','") + "')";
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);*/
}

public void UpdateEmployeeDetails()


{

SqlParameter[] p = new SqlParameter[10];

p[0] = new SqlParameter("@DeptId", this._DeptId);


p[0].DbType = DbType.Int32;
p[1] = new SqlParameter("@ContactNo", this._ContactNo);
p[1].DbType = DbType.String;
p[2] = new SqlParameter("@Address", this._Address);
p[2].DbType = DbType.String;
p[3] = new SqlParameter("@CityId", this._CityId);
p[3].DbType = DbType.Int32;
p[4] = new SqlParameter("@StateId", this._StateId);
p[4].DbType = DbType.Int32;
p[5] = new SqlParameter("@CountryId", this._CountryId);
p[5].DbType = DbType.Int32;
p[6] = new SqlParameter("@EmailId", this._EmailId);
p[6].DbType = DbType.String;
p[7] = new SqlParameter("@UserName", this._UserName);
p[7].DbType = DbType.String;
p[8] = new SqlParameter("@Desig", this._Designation);
p[8].DbType = DbType.String;
p[9] = new SqlParameter("@EmpName", this._EmpName);
p[9].DbType = DbType.String;
// p[8] = new SqlParameter("@StatusId", this._StatusId);
// p[8].DbType = DbType.Int32;

//p[9] = new SqlParameter("@output", SqlDbType.Int);


//p[9].Direction = ParameterDirection.Output;

SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spUpdataEmployee", p);

public DataSet GetEmployee()


{

string strSql = string.Empty;


strSql = "select * from tbl_EmpDetails e,tbl_Users u where
u.UserName=e.UserName ";
if (!string.IsNullOrEmpty(_UserName))
strSql += " and u.UserName like '%" + _UserName + "%'";
if (!string.IsNullOrEmpty(Sort_On))
{
strSql = strSql + " ORDER BY " + Sort_On;
}
else
{
strSql = strSql + " Order By u.UserName";
}
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;
}

public void GetEmployeeDetails()


{
///*
//string strSql = string.Empty;
//strSql += "select * from tbl_ClientDetails u,tbl_ClientLoginAccount ul,
tbl_Status stat where u.StatusId=stat.StatusId and ul.ClientId=u.ClientId ";
//strSql += " and u.ClientId=" + _UserId;

SqlParameter[]p=new SqlParameter [1];


p[0] = new SqlParameter("@UserName", SqlDbType.VarChar);
p[0].Value=_UserName ;
DataSet dsTemp;;

dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure,"spGetEmpDetails",p);
DataRowCollection drc = dsTemp.Tables[0].Rows;
if (drc.Count > 0)
{
_UserName = drc[0]["UserName"].ToString();
_EmpName = drc[0]["EmpName"].ToString();
_Designation = drc[0]["EmpDesigName"].ToString();
_ContactNo = drc[0]["ContactNo"].ToString();
_Address = drc[0]["Address"].ToString();
_EmailId = drc[0]["EmailId"].ToString();
_CityId = Convert.ToInt32(drc[0]["CityId"].ToString());
_StateId = Convert.ToInt32(drc[0]["StateId"].ToString());
_CountryId = Convert.ToInt32(drc[0]["CountryId"].ToString());
_DeptId=Convert.ToInt32(drc[0]["DeptId"].ToString());
}
else
{
_EmpName = "";
_ContactNo = "";
_Address = "";
_EmailId = "";
}

/* public bool CheckUserName()


{
SqlParameter[] p = new SqlParameter[1];
p[0] = new SqlParameter("@UserName", SqlDbType.VarChar);
p[0].Value = _UserName;

DataSet ds =
SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spCheckUserName", p);
DataTable dtable = ds.Tables[0];
if (dtable.Rows.Count > 0)
return true;
else

return false;
* *
}*/

public DataSet GetPresentDayEmpList()


{

return SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, "spGetPresentDayEmpList");
}

public DataSet GetNextDayEmpList()


{

return SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, "spGetNextDayEmpList");
}

clsEmployeeLogin_Logic.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

/// <summary>
/// Summary description for clsEmployeeLogin_Logic
/// </summary>
public class clsEmployeeLogin_Logic
{
public clsEmployeeLogin_Logic()
{
//
// TODO: Add constructor logic here
//
}

string _UserName, _Password, _OldPassword;

public string Password


{
get { return _Password; }
set { _Password = value; }
}

public string UserName


{
get { return _UserName; }
set { _UserName = value; }
}

public string OldPassword


{
get { return _OldPassword; }
set { _OldPassword = value; }
}

public DataSet GetEmpLoginDetails()


{
SqlParameter[] p = new SqlParameter[2];
p[0] = new SqlParameter("@UserName", SqlDbType.VarChar);
p[0].Value = _UserName;
p[1] = new SqlParameter("@Password", SqlDbType.VarChar);
p[1].Value = _Password;
DataSet tempds =
SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spEmpLogin", p);
return tempds;
}

public int EmpChangeOldPassword()


{
SqlParameter[] p = new SqlParameter[2];
p[0] = new SqlParameter("@UserName", SqlDbType.VarChar);
p[0].Value = _UserName;
p[1] = new SqlParameter("@Password", SqlDbType.VarChar);
p[1].Value = _Password;
int i = SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spEmpChangePassword", p);
return i;
}

public bool CheckEmpOldPassword()


{
SqlParameter[] p = new SqlParameter[2];
p[0] = new SqlParameter("@UserName", SqlDbType.VarChar);
p[0].Value = _UserName;
p[1] = new SqlParameter("@Password", SqlDbType.VarChar);
p[1].Value = _OldPassword;
DataSet tempds =
SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spCheckEmpOldPassword", p);
DataRowCollection drc = tempds.Tables[0].Rows;
if (drc.Count > 0)
{
return true;
}
else
{
return false;
}
}

clsLeave_Logic.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

/// <summary>
/// Summary description for clsLeave_Logic
/// </summary>
public class clsLeave_Logic
{
private string
_LeaveTypeName,_UserName,_StartingMonth,_EndingMonth,_StartingDate,_EndingDate;
int _LeaveTypeId, _NoOfLeavesPerYear, _UsedLeaves, _BalanceLeaves, _ApplicationNo,
_AppStatusId;
int _CasualBalanceLeaves, _EarnBalanceLeaves, _HalfPaidBalanceLeaves,
_MedicalBalanceLeaves;
public string Sort_On;
public clsLeave_Logic()
{
//
// TODO: Add constructor logic here
//
}

public string StartingMonth


{
get { return _StartingMonth; }
set { _StartingMonth = value; }
}
public string EndingMonth
{
get { return _EndingMonth; }
set { _EndingMonth = value; }
}
public string StartingDate
{
get { return _StartingDate; }
set { _StartingDate = value; }
}
public string EndingDate
{
get { return _EndingDate; }
set { _EndingDate = value; }
}

public int ApplicationNo


{
get { return _ApplicationNo; }
set { _ApplicationNo = value; }
}
public int AppStatusId
{
get { return _AppStatusId; }
set { _AppStatusId = value; }
}
public int CasualBalanceLeaves
{
get { return _CasualBalanceLeaves; }
set { _CasualBalanceLeaves = value; }
}
public int EarnBalanceLeaves
{
get { return _EarnBalanceLeaves; }
set { _EarnBalanceLeaves = value; }
}
public int HalfPaidBalanceLeaves
{
get { return _HalfPaidBalanceLeaves; }
set { _HalfPaidBalanceLeaves = value; }
}
public int MedicalBalanceLeaves
{
get { return _MedicalBalanceLeaves; }
set { _MedicalBalanceLeaves = value; }
}

public string UserName


{
get { return _UserName; }
set { _UserName = value; }
}
public string LeaveTypeName
{
get { return _LeaveTypeName; }
set { _LeaveTypeName = value; }
}
public int LeaveTypeId
{
get { return _LeaveTypeId; }
set { _LeaveTypeId = value; }
}

public int NoOfLeavesPerYear


{
get { return _NoOfLeavesPerYear; }
set { _NoOfLeavesPerYear = value; }
}
public int UsedLeaves
{
get { return _UsedLeaves; }
set { _UsedLeaves = value; }
}
public int BalanceLeaves
{
get { return _BalanceLeaves; }
set { _BalanceLeaves = value; }
}

public int GetBalanceDays()


{
SqlParameter[] p = new SqlParameter[3];
p[0] = new SqlParameter("@LeaveTypeId", SqlDbType.Int);
p[0].Value = _LeaveTypeId;
p[1] = new SqlParameter("@UserName", SqlDbType.VarChar);
p[1].Value = _UserName;
p[2] = new SqlParameter("@Balanceleaves", SqlDbType.Int);
p[2].Direction = ParameterDirection.Output;

SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spGetBalanceDays", p);
//return i;
return (int)p[2].Value;
}
public DataSet GetLeaveType()
{
return SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spGetLeaveType");
}

//Jan 04 11.09am
public void GetTotalBalanceDays()
{
SqlParameter[] p = new SqlParameter[5];
p[0] = new SqlParameter("@UserName", SqlDbType.VarChar);
p[0].Value = _UserName;
p[1] = new SqlParameter("@CasualBalanceLeaves", SqlDbType.Int);
p[1].Direction = ParameterDirection.Output;
p[2] = new SqlParameter("@EarnBalanceLeaves", SqlDbType.Int);
p[2].Direction = ParameterDirection.Output;
p[3] = new SqlParameter("@HalfPaidBalanceLeaves", SqlDbType.Int);
p[3].Direction = ParameterDirection.Output;
p[4] = new SqlParameter("@MedicalBalanceLeaves", SqlDbType.Int);
p[4].Direction = ParameterDirection.Output;

SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spGetTotalBalanceDays", p);
_CasualBalanceLeaves = (int)p[1].Value;
_EarnBalanceLeaves = (int)p[2].Value;
_HalfPaidBalanceLeaves = (int)p[3].Value;
_MedicalBalanceLeaves = (int)p[4].Value;

public void AddLeaveDetails()


{
SqlParameter[] p = new SqlParameter[5];
p[0] = new SqlParameter("@UserName", SqlDbType.VarChar);
p[0].Value = _UserName;
p[1] = new SqlParameter("@ApplicationNo", SqlDbType.Int);
p[1].Value = _ApplicationNo;
p[2] = new SqlParameter("@AppStatusId", SqlDbType.Int);
p[2].Value = _AppStatusId;
p[3] = new SqlParameter("@BalanceLeaves", SqlDbType.Int);
p[3].Value = _BalanceLeaves;
p[4] = new SqlParameter("@LeaveTypeId", SqlDbType.Int);
p[4].Value = _LeaveTypeId;
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spAddLeaveDetails", p);
}

public bool CheckAppNoInLeaveDetails()


{
SqlParameter[] p = new SqlParameter[1];
p[0] = new SqlParameter("@ApplicationNo", SqlDbType.Int);
p[0].Value = _ApplicationNo;
DataSet ds= SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.StoredProcedure, "spCheckAppNoInLeaveDetails", p);
if (ds.Tables[0].Rows.Count > 0)
return false;
else
return true;
}

public DataSet GetMonthlyLeavetransactions()


{
string strSql = string.Empty;
strSql = "select * from tbl_ApplicationData a,tbl_Status s,tbl_LeaveType l where
a.ApplicationStatusId=s.StatusId and a.LeaveTypeId=l.LeaveTypeId ";
if (!string.IsNullOrEmpty(_UserName))
strSql += " and a.UserName like '%" + _UserName + "%'";
if (!string.IsNullOrEmpty(_StartingMonth))
{
strSql += " and a.StartingDate >'" + _StartingMonth + "' ";
}
if (!string.IsNullOrEmpty(_EndingMonth))
{
strSql += " and a.StartingDate <'" + _EndingMonth + "' ";
}
if (!string.IsNullOrEmpty(_StartingDate))
{
strSql += " and a.StartingDate >'" + _StartingDate + "' ";
}
if (!string.IsNullOrEmpty(_EndingDate))
{
strSql += " and a.StartingDate <'" + _EndingDate + "' ";
}
if (Sort_On != "")
{
strSql = strSql + " ORDER BY " + Sort_On;
}
else
{
strSql = strSql + " Order By a.UserName";
}
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;
}

Statelogic.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

///<summary>
///This is BOL State_Logic Class
/// Created By: Team A PropertyNet
/// Created On: 15-Oct-2007
/// Last Modified By: Team A PropertyNet
/// Last Modified On: 15-Oct-2007
/// </summary>
public class clsState_Logic
{
private int _StateId;
private string _StateName;
private string _StateDescr;
public string Sort_On;
private int _StatusId;
private string _StatusName;
private string _CountryName;
private int _CountryId;
//private clsDbConnector objDbConnector;
public clsState_Logic()
{
//objDbConnector = new clsDbConnector();
}
public int pro_StateId
{
get
{
return _StateId;
}
set
{
_StateId = value;
}
}
public string pro_StateName
{
get
{
return _StateName;
}
set
{
if (value.ToString() == "")
{
_StateName = "";
}
else
{
_StateName = value;
}
}
}
public string pro_StateDescription
{
get
{
return _StateDescr;
}
set
{
if (value.ToString() == "")
{
_StateDescr = "";
}
else
{
_StateDescr = value;
}
}
}

public string pro_StatusName


{
get
{
return _StatusName;
}
set
{
_StatusName = value;
}
}
public int pro_StatusId
{
get
{
return _StatusId;
}
set
{
_StatusId = value;
}

}
public string pro_CountryName
{
get
{
return _CountryName;
}
set
{
_CountryName= value;
}

public int pro_CountryId


{
get
{
return _CountryId;
}
set
{
_CountryId = value;
}

public DataSet GetState()


{
string strSql = string.Empty;
strSql = "select
st.StateId,st.StateName,st.StateDescription,c.CountryName,s.StatusName from tbl_Status s,
tbl_State st,tbl_Country c where st.CountryId=c.CountryId and s.StatusId=st.StatusId";
if (_StateName != "")
{

strSql += " and StateName like '%" + _StateName + "%'";

}
if (_CountryName != "select" && _CountryName!=null)
strSql = strSql + " and CountryName='" + _CountryName + "'";
//else
//{
// strSql = strSql + " and CountryName='" + _CountryName + "'";
//}

if (Sort_On != "")
{
strSql = strSql + " ORDER BY " + Sort_On;
}
else
{
strSql = strSql + " Order By StateName";
}

DataSet dsTemp;
//dsTemp = objDbConnector.GetDataSet(strSql);
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;
}
public void AddState()
{
string strSql = string.Empty;

strSql += "Insert into tbl_State(StateName,StateDescription,CountryId,StatusId)";


strSql += " values('" + _StateName + "',";
strSql += " '" + _StateDescr + "',"+_CountryId+"," + _StatusId + ")";
//objDbConnector.runSQL(strSql);
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
}

public void DeleteState(string StateId)


{
string strSql = string.Empty;
strSql += "delete from tbl_State";
strSql += " where StateId in('" + StateId.Replace(",","','") + "')";
//objDbConnector.runSQL(strSql);
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
}
public void GetStateDetails()
{
string strSql = string.Empty;
strSql += "select
st.StateId,st.StateName,st.StateDescription,c.CountryName,s.StatusName from tbl_Status s,
tbl_State st,tbl_Country c where st.CountryId=c.CountryId and s.StatusId=st.StatusId";
strSql += " and StateId=" + _StateId;
DataSet dsTemp;
// dsTemp = objDbConnector.GetDataSet(strSql);
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
DataRowCollection drc = dsTemp.Tables[0].Rows;
if (drc.Count > 0)
{
_StateName = drc[0]["StateName"].ToString();
_StateDescr = drc[0]["StateDescription"].ToString();
_CountryName = drc[0]["CountryName"].ToString();
_StatusName = drc[0]["StatusName"].ToString();
}
else
{
_StateName = "";
_StateDescr = "";
_CountryName = "";
_StatusName = "";
}
}
public void UpdateState()
{
string strSql = string.Empty;
strSql += "Update tbl_State set";
strSql += " StateName='" + _StateName + "',";
strSql += " StateDescription='" + _StateDescr + "',";
strSql += " CountryId=" + _CountryId+",";
strSql += " StatusId=" + _StatusId;
strSql += " where StateId=" + _StateId;
//objDbConnector.runSQL(strSql);
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
}

public DataSet GetStatusName()


{

string strSql = string.Empty;


strSql += "select StatusName,StatusId from tbl_Status";
DataSet dsTemp;
//ds = objDbConnector.GetDataSet(strSql);
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;

public DataSet GetCountryName()


{
string strSql = string.Empty;
strSql += "select CountryName,CountryId from tbl_Country";
DataSet dsTemp;
//ds = objDbConnector.GetDataSet(strSql);
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;

Statuslogic.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

/// <summary>
/// This is BOL Status_Logic Class
/// Created By: Team A PropertyNet
/// Created On: 13-Oct-2007
/// Last Modified By: Team A PropertyNet
/// Last Modified On: 13-Oct-2007
/// </summary>
public class clsStatus_Logic
{
private int _StatusId;
private string _StatusName;
private string _StatusDescr;
public string Sort_On;
//private clsDbConnector objDbConnector;
public clsStatus_Logic()
{
//objDbConnector = new clsDbConnector();
}
public int pro_StatusId
{
get
{
return _StatusId;
}
set
{
_StatusId = value;
}
}
public string pro_StatusName
{
get
{
return _StatusName;
}
set
{
if (value.ToString() == "")
{
_StatusName = "";
}
else
{
_StatusName = value;
}
}
}
public string pro_StatusDescription
{
get
{
return _StatusDescr;
}
set
{
if (value.ToString() == "")
{
_StatusDescr = "";
}
else
{
_StatusDescr = value;
}
}
}

public DataSet GetStatus()


{
string strSql = string.Empty;
strSql = "select * from tbl_Status";
if (!string.IsNullOrEmpty(_StatusName))
strSql += " where StatusName like '%" + _StatusName + "%'";
if (!string.IsNullOrEmpty(Sort_On))
{
strSql = strSql + " ORDER BY " + Sort_On;
}
else
{
strSql = strSql + " Order By StatusName";
}
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
return dsTemp;
}
public void AddStatus()
{
string strSql = string.Empty;
strSql += "Insert into tbl_Status(StatusName,StatusDescription)";
strSql += " values('" + _StatusName + "',";
strSql += " '" + _StatusDescr + "')";
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
}

public void DeleteStatus(string StatusId)


{
string strSql = string.Empty;
strSql += "delete from tbl_Status";
strSql += " where StatusId in('" + StatusId.Replace(",","','") + "')";
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
}
public void GetStatusDetails()
{
string strSql = string.Empty;
strSql += "select * from tbl_Status";
strSql += " where StatusId=" + _StatusId;
DataSet dsTemp;
dsTemp = SqlHelper.ExecuteDataset(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
DataRowCollection drc = dsTemp.Tables[0].Rows;
if (drc.Count > 0)
{
_StatusName = drc[0]["StatusName"].ToString();
_StatusDescr = drc[0]["StatusDescription"].ToString();
}
else
{
_StatusName = "";
_StatusDescr = "";
}
}
public void UpdateStatus()
{
string strSql = string.Empty;
strSql += "Update tbl_Status set";
strSql += " StatusName='" + _StatusName + "',";
strSql += " StatusDescription='" + _StatusDescr + "'";
strSql += " where StatusId=" + _StatusId;
SqlHelper.ExecuteNonQuery(ClsConnectionString.getConnectionString(),
CommandType.Text, strSql);
}
}

Connection.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for ClsConnectionstring
/// </summary>
public class ClsConnectionString
{
public ClsConnectionString()
{

}
public static string getConnectionString()
{
return ConfigurationManager.AppSettings["connstr"];
}
}

Sqldbclass.cs

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Web.Configuration;
/// <summary>
/// This is DAL Class
/// Created By: Team A PropertyNet
/// Created On: 09-Oct-2007
/// Last Modified By: Team A PropertyNet
/// Last Modified On: 09-Oct-2007
/// </summary>
public class clsDbConnector
{
private SqlConnection dbConnection;
private SqlDataAdapter dbAdapter;
private SqlCommand cmd;

public clsDbConnector()
{
this.dbConnection = new
SqlConnection(ConfigurationManager.AppSettings["connstr"]);
//Or
//this.dbConnection = new
SqlConnection(ConfigurationManager.ConnectionStrings["conString"]);
if (dbConnection.State == ConnectionState.Closed)
{
try
{
if (dbConnection.State == ConnectionState.Broken)
{
dbConnection.Close();
dbConnection.Open();
}
}
catch (Exception err)
{
throw err;
}
}
if (dbConnection.State == ConnectionState.Broken)
{
dbConnection.Close();
dbConnection.Open();
}
cmd = new SqlCommand();
}

public DataSet GetDataSet(string strSQL)


{
if (dbConnection.State == ConnectionState.Closed)
{
dbConnection.Open();
}
if (dbConnection.State == ConnectionState.Broken)
{
dbConnection.Close();
dbConnection.Open();
}
dbAdapter = new SqlDataAdapter(strSQL, dbConnection);
DataSet dsTemp;
dsTemp = new DataSet();
dbAdapter.Fill(dsTemp);
dbConnection.Close();
return dsTemp;
}

public SqlDataReader getSqlDataReader(string strSQL)


{
if (dbConnection.State == ConnectionState.Closed)
{
dbConnection.Open();
}
if (dbConnection.State == ConnectionState.Broken)
{
dbConnection.Close();
dbConnection.Open();
}
cmd.Connection = dbConnection;
cmd.CommandText = strSQL;
return cmd.ExecuteReader();
}

public void runSQL(string strSQL)


{
if (dbConnection.State == ConnectionState.Closed)
{
dbConnection.Open();
}
else if (dbConnection.State == ConnectionState.Broken)
{
dbConnection.Close();
dbConnection.Open();
}
cmd = new SqlCommand(strSQL, dbConnection);
cmd.ExecuteNonQuery();
dbConnection.Close();
}

public Boolean BatchTransaction(string[] strSql)


{

dbConnection.Open();
SqlTransaction t;
SqlCommand dbCommand = new SqlCommand();
t = dbConnection.BeginTransaction();
dbCommand.Connection = dbConnection;
dbCommand.Transaction = t;
try
{
for (int i = 0; i < strSql.Length; i++)
{
if (strSql[i].ToString() == null)
break;
dbCommand.CommandText = strSql[i].ToString();
dbCommand.ExecuteNonQuery();
}
//Commit Transactions
t.Commit();
t = null;
dbCommand.Dispose();
dbConnection.Close();
return true;
}
catch (Exception ex)
{
//Rollback Transactions
t.Rollback();
t = null;
string str = ex.Message;
dbCommand.Dispose();
dbConnection.Close();
return false;
}
}
}

Sqlhandler.cs

//===============================================================================
// Microsoft Data Access Application Block for .NET
// http://msdn.microsoft.com/library/en-us/dnbda/html/daab-rm.asp
//
// SQLHelper.cs
//
// This file contains the implementations of the SqlHelper and SqlHelperParameterCache
// classes.
//
// For more information see the Data Access Application Block Implementation Overview.
//
//===============================================================================
// Copyright (C) 2000-2001 Microsoft Corporation
// All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR
// FITNESS FOR A PARTICULAR PURPOSE.
//==============================================================================

using System;
using System.Data;
using System.Xml;
using System.Data.SqlClient;
using System.Collections;

namespace Microsoft.ApplicationBlocks.Data
{
/// <summary>
/// The SqlHelper class is intended to encapsulate high performance, scalable best
practices for
/// common uses of SqlClient.
/// </summary>

public sealed class SqlHelper


{
#region private utility methods & constructors

//Since this class provides only static methods, make the default
constructor private to prevent
//instances from being created with "new SqlHelper()".
private SqlHelper() {}

/// <summary>
/// This method is used to attach array of SqlParameters to a SqlCommand.
///
/// This method will assign a value of DbNull to any parameter with a
direction of
/// InputOutput and a value of null.
///
/// This behavior will prevent default values from being used, but
/// this will be the less common case than an intended pure output
parameter (derived as InputOutput)
/// where the user provided no input value.
/// </summary>
/// <param name="command">The command to which the parameters will be
added</param>
/// <param name="commandParameters">an array of SqlParameters tho be added
to command</param>
private static void AttachParameters(SqlCommand command, SqlParameter[]
commandParameters)
{
foreach (SqlParameter p in commandParameters)
{
//check for derived output value with no value assigned
if ((p.Direction == ParameterDirection.InputOutput) &&
(p.Value == null))
{
p.Value = DBNull.Value;
}

command.Parameters.Add(p);
}
}

/// <summary>
/// This method assigns an array of values to an array of SqlParameters.
/// </summary>
/// <param name="commandParameters">array of SqlParameters to be assigned
values</param>
/// <param name="parameterValues">array of objects holding the values to be
assigned</param>
private static void AssignParameterValues(SqlParameter[] commandParameters,
object[] parameterValues)
{
if ((commandParameters == null) || (parameterValues == null))
{
//do nothing if we get no data
return;
}

// we must have the same number of values as we pave parameters to


put them in
if (commandParameters.Length != parameterValues.Length)
{
throw new ArgumentException("Parameter count does not match
Parameter Value count.");
}

//iterate through the SqlParameters, assigning the values from the


corresponding position in the
//value array
for (int i = 0, j = commandParameters.Length; i < j; i++)
{
commandParameters[i].Value = parameterValues[i];
}
}

/// <summary>
/// This method opens (if necessary) and assigns a connection, transaction,
command type and parameters
/// to the provided command.
/// </summary>
/// <param name="command">the SqlCommand to be prepared</param>
/// <param name="connection">a valid SqlConnection, on which to execute
this command</param>
/// <param name="transaction">a valid SqlTransaction, or 'null'</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <param name="commandParameters">an array of SqlParameters to be
associated with the command or 'null' if no parameters are required</param>
private static void PrepareCommand(SqlCommand command, SqlConnection
connection, SqlTransaction transaction, CommandType commandType, string commandText,
SqlParameter[] commandParameters)
{
//if the provided connection is not open, we will open it
if (connection.State != ConnectionState.Open)
{
connection.Open();
}

//associate the connection with the command


command.Connection = connection;

//set the command text (stored procedure name or SQL statement)


command.CommandText = commandText;

//if we were provided a transaction, assign it.


if (transaction != null)
{
command.Transaction = transaction;
}

//set the command type


command.CommandType = commandType;

//attach the command parameters if they are provided


if (commandParameters != null)
{
AttachParameters(command, commandParameters);
}

return;
}

#endregion private utility methods & constructors

#region ExecuteNonQuery

/// <summary>
/// Execute a SqlCommand (that returns no resultset and takes no
parameters) against the database specified in
/// the connection string.
/// </summary>
/// <remarks>
/// e.g.:
/// int result = ExecuteNonQuery(connString, CommandType.StoredProcedure,
"PublishOrders");
/// </remarks>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <returns>an int representing the number of rows affected by the
command</returns>
public static int ExecuteNonQuery(string connectionString, CommandType
commandType, string commandText)
{
//pass through the call providing null for the set of SqlParameters
return ExecuteNonQuery(connectionString, commandType, commandText,
(SqlParameter[])null);
}

/// <summary>
/// Execute a SqlCommand (that returns no resultset) against the database
specified in the connection string
/// using the provided parameters.
/// </summary>
/// <remarks>
/// e.g.:
/// int result = ExecuteNonQuery(connString, CommandType.StoredProcedure,
"PublishOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <param name="commandParameters">an array of SqlParamters used to
execute the command</param>
/// <returns>an int representing the number of rows affected by the
command</returns>
public static int ExecuteNonQuery(string connectionString, CommandType
commandType, string commandText, params SqlParameter[] commandParameters)
{
//create & open a SqlConnection, and dispose of it after we are
done.
using (SqlConnection cn = new SqlConnection(connectionString))
{
cn.Open();

//call the overload that takes a connection in place of the


connection string
return ExecuteNonQuery(cn, commandType, commandText,
commandParameters);
}
}

/// <summary>
/// Execute a stored procedure via a SqlCommand (that returns no resultset)
against the database specified in
/// the connection string using the provided parameter values. This method
will query the database to discover the parameters for the
/// stored procedure (the first time each stored procedure is called), and
assign the values based on parameter order.
/// </summary>
/// <remarks>
/// This method provides no access to output parameters or the stored
procedure's return value parameter.
///
/// e.g.:
/// int result = ExecuteNonQuery(connString, "PublishOrders", 24, 36);
/// </remarks>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="spName">the name of the stored prcedure</param>
/// <param name="parameterValues">an array of objects to be assigned as the
input values of the stored procedure</param>
/// <returns>an int representing the number of rows affected by the
command</returns>
public static int ExecuteNonQuery(string connectionString, string spName,
params object[] parameterValues)
{
//if we receive parameter values, we need to figure out where they
go
if ((parameterValues != null) && (parameterValues.Length > 0))
{
//pull the parameters for this stored procedure from the
parameter cache (or discover them & populate the cache)
SqlParameter[] commandParameters =
SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);

//assign the provided values to these parameters based on


parameter order
AssignParameterValues(commandParameters, parameterValues);

//call the overload that takes an array of SqlParameters


return ExecuteNonQuery(connectionString,
CommandType.StoredProcedure, spName, commandParameters);
}
//otherwise we can just call the SP without params
else
{
return ExecuteNonQuery(connectionString,
CommandType.StoredProcedure, spName);
}
}

/// <summary>
/// Execute a SqlCommand (that returns no resultset and takes no
parameters) against the provided SqlConnection.
/// </summary>
/// <remarks>
/// e.g.:
/// int result = ExecuteNonQuery(conn, CommandType.StoredProcedure,
"PublishOrders");
/// </remarks>
/// <param name="connection">a valid SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <returns>an int representing the number of rows affected by the
command</returns>
public static int ExecuteNonQuery(SqlConnection connection, CommandType
commandType, string commandText)
{
//pass through the call providing null for the set of SqlParameters
return ExecuteNonQuery(connection, commandType, commandText,
(SqlParameter[])null);
}

/// <summary>
/// Execute a SqlCommand (that returns no resultset) against the specified
SqlConnection
/// using the provided parameters.
/// </summary>
/// <remarks>
/// e.g.:
/// int result = ExecuteNonQuery(conn, CommandType.StoredProcedure,
"PublishOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="connection">a valid SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <param name="commandParameters">an array of SqlParamters used to
execute the command</param>
/// <returns>an int representing the number of rows affected by the
command</returns>
public static int ExecuteNonQuery(SqlConnection connection, CommandType
commandType, string commandText, params SqlParameter[] commandParameters)
{
//create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, connection, (SqlTransaction)null, commandType,
commandText, commandParameters);

//finally, execute the command.


int retval = cmd.ExecuteNonQuery();

// detach the SqlParameters from the command object, so they can be


used again.
cmd.Parameters.Clear();
return retval;
}

/// <summary>
/// Execute a stored procedure via a SqlCommand (that returns no resultset)
against the specified SqlConnection
/// using the provided parameter values. This method will query the
database to discover the parameters for the
/// stored procedure (the first time each stored procedure is called), and
assign the values based on parameter order.
/// </summary>
/// <remarks>
/// This method provides no access to output parameters or the stored
procedure's return value parameter.
///
/// e.g.:
/// int result = ExecuteNonQuery(conn, "PublishOrders", 24, 36);
/// </remarks>
/// <param name="connection">a valid SqlConnection</param>
/// <param name="spName">the name of the stored procedure</param>
/// <param name="parameterValues">an array of objects to be assigned as the
input values of the stored procedure</param>
/// <returns>an int representing the number of rows affected by the
command</returns>
public static int ExecuteNonQuery(SqlConnection connection, string spName,
params object[] parameterValues)
{
//if we receive parameter values, we need to figure out where they
go
if ((parameterValues != null) && (parameterValues.Length > 0))
{
//pull the parameters for this stored procedure from the
parameter cache (or discover them & populate the cache)
SqlParameter[] commandParameters =
SqlHelperParameterCache.GetSpParameterSet(connection.ConnectionString, spName);

//assign the provided values to these parameters based on


parameter order
AssignParameterValues(commandParameters, parameterValues);
//call the overload that takes an array of SqlParameters
return ExecuteNonQuery(connection,
CommandType.StoredProcedure, spName, commandParameters);
}
//otherwise we can just call the SP without params
else
{
return ExecuteNonQuery(connection,
CommandType.StoredProcedure, spName);
}
}

/// <summary>
/// Execute a SqlCommand (that returns no resultset and takes no
parameters) against the provided SqlTransaction.
/// </summary>
/// <remarks>
/// e.g.:
/// int result = ExecuteNonQuery(trans, CommandType.StoredProcedure,
"PublishOrders");
/// </remarks>
/// <param name="transaction">a valid SqlTransaction</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <returns>an int representing the number of rows affected by the
command</returns>
public static int ExecuteNonQuery(SqlTransaction transaction, CommandType
commandType, string commandText)
{
//pass through the call providing null for the set of SqlParameters
return ExecuteNonQuery(transaction, commandType, commandText,
(SqlParameter[])null);
}

/// <summary>
/// Execute a SqlCommand (that returns no resultset) against the specified
SqlTransaction
/// using the provided parameters.
/// </summary>
/// <remarks>
/// e.g.:
/// int result = ExecuteNonQuery(trans, CommandType.StoredProcedure,
"GetOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="transaction">a valid SqlTransaction</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <param name="commandParameters">an array of SqlParamters used to
execute the command</param>
/// <returns>an int representing the number of rows affected by the
command</returns>
public static int ExecuteNonQuery(SqlTransaction transaction, CommandType
commandType, string commandText, params SqlParameter[] commandParameters)
{
//create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, transaction.Connection, transaction,
commandType, commandText, commandParameters);

//finally, execute the command.


int retval = cmd.ExecuteNonQuery();

// detach the SqlParameters from the command object, so they can be


used again.
cmd.Parameters.Clear();
return retval;
}

/// <summary>
/// Execute a stored procedure via a SqlCommand (that returns no resultset)
against the specified
/// SqlTransaction using the provided parameter values. This method will
query the database to discover the parameters for the
/// stored procedure (the first time each stored procedure is called), and
assign the values based on parameter order.
/// </summary>
/// <remarks>
/// This method provides no access to output parameters or the stored
procedure's return value parameter.
///
/// e.g.:
/// int result = ExecuteNonQuery(conn, trans, "PublishOrders", 24, 36);
/// </remarks>
/// <param name="transaction">a valid SqlTransaction</param>
/// <param name="spName">the name of the stored procedure</param>
/// <param name="parameterValues">an array of objects to be assigned as the
input values of the stored procedure</param>
/// <returns>an int representing the number of rows affected by the
command</returns>
public static int ExecuteNonQuery(SqlTransaction transaction, string
spName, params object[] parameterValues)
{
//if we receive parameter values, we need to figure out where they
go
if ((parameterValues != null) && (parameterValues.Length > 0))
{
//pull the parameters for this stored procedure from the
parameter cache (or discover them & populate the cache)
SqlParameter[] commandParameters =
SqlHelperParameterCache.GetSpParameterSet(transaction.Connection.ConnectionString,
spName);

//assign the provided values to these parameters based on


parameter order
AssignParameterValues(commandParameters, parameterValues);

//call the overload that takes an array of SqlParameters


return ExecuteNonQuery(transaction,
CommandType.StoredProcedure, spName, commandParameters);
}
//otherwise we can just call the SP without params
else
{
return ExecuteNonQuery(transaction,
CommandType.StoredProcedure, spName);
}
}

#endregion ExecuteNonQuery

#region ExecuteDataSet

/// <summary>
/// Execute a SqlCommand (that returns a resultset and takes no parameters)
against the database specified in
/// the connection string.
/// </summary>
/// <remarks>
/// e.g.:
/// DataSet ds = ExecuteDataset(connString, CommandType.StoredProcedure,
"GetOrders");
/// </remarks>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <returns>a dataset containing the resultset generated by the
command</returns>
public static DataSet ExecuteDataset(string connectionString, CommandType
commandType, string commandText)
{
//pass through the call providing null for the set of SqlParameters
return ExecuteDataset(connectionString, commandType, commandText,
(SqlParameter[])null);
}

/// <summary>
/// Execute a SqlCommand (that returns a resultset) against the database
specified in the connection string
/// using the provided parameters.
/// </summary>
/// <remarks>
/// e.g.:
/// DataSet ds = ExecuteDataset(connString, CommandType.StoredProcedure,
"GetOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <param name="commandParameters">an array of SqlParamters used to
execute the command</param>
/// <returns>a dataset containing the resultset generated by the
command</returns>
//***//
public static DataSet ExecuteDataset(string connectionString, CommandType
commandType, string commandText, params SqlParameter[] commandParameters)
{
//create & open a SqlConnection, and dispose of it after we are
done.
using (SqlConnection cn = new SqlConnection(connectionString))
{
cn.Open();

//call the overload that takes a connection in place of the


connection string
return ExecuteDataset(cn, commandType, commandText,
commandParameters);
}
}

/// <summary>
/// Execute a stored procedure via a SqlCommand (that returns a resultset)
against the database specified in
/// the connection string using the provided parameter values. This method
will query the database to discover the parameters for the
/// stored procedure (the first time each stored procedure is called), and
assign the values based on parameter order.
/// </summary>
/// <remarks>
/// This method provides no access to output parameters or the stored
procedure's return value parameter.
///
/// e.g.:
/// DataSet ds = ExecuteDataset(connString, "GetOrders", 24, 36);
/// </remarks>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="spName">the name of the stored procedure</param>
/// <param name="parameterValues">an array of objects to be assigned as the
input values of the stored procedure</param>
/// <returns>a dataset containing the resultset generated by the
command</returns>
public static DataSet ExecuteDataset(string connectionString, string
spName, params object[] parameterValues)
{
//if we receive parameter values, we need to figure out where they
go
if ((parameterValues != null) && (parameterValues.Length > 0))
{
//pull the parameters for this stored procedure from the
parameter cache (or discover them & populate the cache)
SqlParameter[] commandParameters =
SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);

//assign the provided values to these parameters based on


parameter order
AssignParameterValues(commandParameters, parameterValues);

//call the overload that takes an array of SqlParameters


return ExecuteDataset(connectionString,
CommandType.StoredProcedure, spName, commandParameters);
}
//otherwise we can just call the SP without params
else
{
return ExecuteDataset(connectionString,
CommandType.StoredProcedure, spName);
}
}

/// <summary>
/// Execute a SqlCommand (that returns a resultset and takes no parameters)
against the provided SqlConnection.
/// </summary>
/// <remarks>
/// e.g.:
/// DataSet ds = ExecuteDataset(conn, CommandType.StoredProcedure,
"GetOrders");
/// </remarks>
/// <param name="connection">a valid SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <returns>a dataset containing the resultset generated by the
command</returns>
public static DataSet ExecuteDataset(SqlConnection connection, CommandType
commandType, string commandText)
{
//pass through the call providing null for the set of SqlParameters
return ExecuteDataset(connection, commandType, commandText,
(SqlParameter[])null);
}

/// <summary>
/// Execute a SqlCommand (that returns a resultset) against the specified
SqlConnection
/// using the provided parameters.
/// </summary>
/// <remarks>
/// e.g.:
/// DataSet ds = ExecuteDataset(conn, CommandType.StoredProcedure,
"GetOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="connection">a valid SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <param name="commandParameters">an array of SqlParamters used to
execute the command</param>
/// <returns>a dataset containing the resultset generated by the
command</returns>
public static DataSet ExecuteDataset(SqlConnection connection, CommandType
commandType, string commandText, params SqlParameter[] commandParameters)
{
//create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, connection, (SqlTransaction)null, commandType,
commandText, commandParameters);
//create the DataAdapter & DataSet
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();

//fill the DataSet using default values for DataTable names, etc.
da.Fill(ds);

// detach the SqlParameters from the command object, so they can be


used again.
cmd.Parameters.Clear();

//return the dataset


return ds;
}

/// <summary>
/// Execute a stored procedure via a SqlCommand (that returns a resultset)
against the specified SqlConnection
/// using the provided parameter values. This method will query the
database to discover the parameters for the
/// stored procedure (the first time each stored procedure is called), and
assign the values based on parameter order.
/// </summary>
/// <remarks>
/// This method provides no access to output parameters or the stored
procedure's return value parameter.
///
/// e.g.:
/// DataSet ds = ExecuteDataset(conn, "GetOrders", 24, 36);
/// </remarks>
/// <param name="connection">a valid SqlConnection</param>
/// <param name="spName">the name of the stored procedure</param>
/// <param name="parameterValues">an array of objects to be assigned as the
input values of the stored procedure</param>
/// <returns>a dataset containing the resultset generated by the
command</returns>
public static DataSet ExecuteDataset(SqlConnection connection, string
spName, params object[] parameterValues)
{
//if we receive parameter values, we need to figure out where they
go
if ((parameterValues != null) && (parameterValues.Length > 0))
{
//pull the parameters for this stored procedure from the
parameter cache (or discover them & populate the cache)
SqlParameter[] commandParameters =
SqlHelperParameterCache.GetSpParameterSet(connection.ConnectionString, spName);

//assign the provided values to these parameters based on


parameter order
AssignParameterValues(commandParameters, parameterValues);

//call the overload that takes an array of SqlParameters


return ExecuteDataset(connection, CommandType.StoredProcedure,
spName, commandParameters);
}
//otherwise we can just call the SP without params
else
{
return ExecuteDataset(connection, CommandType.StoredProcedure,
spName);
}
}

/// <summary>
/// Execute a SqlCommand (that returns a resultset and takes no parameters)
against the provided SqlTransaction.
/// </summary>
/// <remarks>
/// e.g.:
/// DataSet ds = ExecuteDataset(trans, CommandType.StoredProcedure,
"GetOrders");
/// </remarks>
/// <param name="transaction">a valid SqlTransaction</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <returns>a dataset containing the resultset generated by the
command</returns>
public static DataSet ExecuteDataset(SqlTransaction transaction,
CommandType commandType, string commandText)
{
//pass through the call providing null for the set of SqlParameters
return ExecuteDataset(transaction, commandType, commandText,
(SqlParameter[])null);
}

/// <summary>
/// Execute a SqlCommand (that returns a resultset) against the specified
SqlTransaction
/// using the provided parameters.
/// </summary>
/// <remarks>
/// e.g.:
/// DataSet ds = ExecuteDataset(trans, CommandType.StoredProcedure,
"GetOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="transaction">a valid SqlTransaction</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <param name="commandParameters">an array of SqlParamters used to
execute the command</param>
/// <returns>a dataset containing the resultset generated by the
command</returns>
public static DataSet ExecuteDataset(SqlTransaction transaction,
CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
//create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, transaction.Connection, transaction,
commandType, commandText, commandParameters);
//create the DataAdapter & DataSet
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();

//fill the DataSet using default values for DataTable names, etc.
da.Fill(ds);

// detach the SqlParameters from the command object, so they can be


used again.
cmd.Parameters.Clear();

//return the dataset


return ds;
}

/// <summary>
/// Execute a stored procedure via a SqlCommand (that returns a resultset)
against the specified
/// SqlTransaction using the provided parameter values. This method will
query the database to discover the parameters for the
/// stored procedure (the first time each stored procedure is called), and
assign the values based on parameter order.
/// </summary>
/// <remarks>
/// This method provides no access to output parameters or the stored
procedure's return value parameter.
///
/// e.g.:
/// DataSet ds = ExecuteDataset(trans, "GetOrders", 24, 36);
/// </remarks>
/// <param name="transaction">a valid SqlTransaction</param>
/// <param name="spName">the name of the stored procedure</param>
/// <param name="parameterValues">an array of objects to be assigned as the
input values of the stored procedure</param>
/// <returns>a dataset containing the resultset generated by the
command</returns>
public static DataSet ExecuteDataset(SqlTransaction transaction, string
spName, params object[] parameterValues)
{
//if we receive parameter values, we need to figure out where they
go
if ((parameterValues != null) && (parameterValues.Length > 0))
{
//pull the parameters for this stored procedure from the
parameter cache (or discover them & populate the cache)
SqlParameter[] commandParameters =
SqlHelperParameterCache.GetSpParameterSet(transaction.Connection.ConnectionString,
spName);

//assign the provided values to these parameters based on


parameter order
AssignParameterValues(commandParameters, parameterValues);

//call the overload that takes an array of SqlParameters


return ExecuteDataset(transaction,
CommandType.StoredProcedure, spName, commandParameters);
}
//otherwise we can just call the SP without params
else
{
return ExecuteDataset(transaction,
CommandType.StoredProcedure, spName);
}
}

#endregion ExecuteDataSet

#region ExecuteReader

/// <summary>
/// this enum is used to indicate whether the connection was provided by
the caller, or created by SqlHelper, so that
/// we can set the appropriate CommandBehavior when calling ExecuteReader()
/// </summary>
private enum SqlConnectionOwnership
{
/// <summary>Connection is owned and managed by SqlHelper</summary>
Internal,
/// <summary>Connection is owned and managed by the caller</summary>
External
}

/// <summary>
/// Create and prepare a SqlCommand, and call ExecuteReader with the
appropriate CommandBehavior.
/// </summary>
/// <remarks>
/// If we created and opened the connection, we want the connection to be
closed when the DataReader is closed.
///
/// If the caller provided the connection, we want to leave it to them to
manage.
/// </remarks>
/// <param name="connection">a valid SqlConnection, on which to execute
this command</param>
/// <param name="transaction">a valid SqlTransaction, or 'null'</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <param name="commandParameters">an array of SqlParameters to be
associated with the command or 'null' if no parameters are required</param>
/// <param name="connectionOwnership">indicates whether the connection
parameter was provided by the caller, or created by SqlHelper</param>
/// <returns>SqlDataReader containing the results of the command</returns>
private static SqlDataReader ExecuteReader(SqlConnection connection,
SqlTransaction transaction, CommandType commandType, string commandText, SqlParameter[]
commandParameters, SqlConnectionOwnership connectionOwnership)
{
//create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, connection, transaction, commandType,
commandText, commandParameters);

//create a reader
SqlDataReader dr;
// call ExecuteReader with the appropriate CommandBehavior
if (connectionOwnership == SqlConnectionOwnership.External)
{
dr = cmd.ExecuteReader();
}
else
{
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
}

// detach the SqlParameters from the command object, so they can be


used again.
cmd.Parameters.Clear();

return dr;
}

/// <summary>
/// Execute a SqlCommand (that returns a resultset and takes no parameters)
against the database specified in
/// the connection string.
/// </summary>
/// <remarks>
/// e.g.:
/// SqlDataReader dr = ExecuteReader(connString,
CommandType.StoredProcedure, "GetOrders");
/// </remarks>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <returns>a SqlDataReader containing the resultset generated by the
command</returns>
public static SqlDataReader ExecuteReader(string connectionString,
CommandType commandType, string commandText)
{
//pass through the call providing null for the set of SqlParameters
return ExecuteReader(connectionString, commandType, commandText,
(SqlParameter[])null);
}

/// <summary>
/// Execute a SqlCommand (that returns a resultset) against the database
specified in the connection string
/// using the provided parameters.
/// </summary>
/// <remarks>
/// e.g.:
/// SqlDataReader dr = ExecuteReader(connString,
CommandType.StoredProcedure, "GetOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <param name="commandParameters">an array of SqlParamters used to
execute the command</param>
/// <returns>a SqlDataReader containing the resultset generated by the
command</returns>
public static SqlDataReader ExecuteReader(string connectionString,
CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
//create & open a SqlConnection
SqlConnection cn = new SqlConnection(connectionString);
cn.Open();

try
{
//call the private overload that takes an internally owned
connection in place of the connection string
return ExecuteReader(cn, null, commandType, commandText,
commandParameters,SqlConnectionOwnership.Internal);
}
catch
{
//if we fail to return the SqlDatReader, we need to close the
connection ourselves
cn.Close();
throw;
}
}

/// <summary>
/// Execute a stored procedure via a SqlCommand (that returns a resultset)
against the database specified in
/// the connection string using the provided parameter values. This method
will query the database to discover the parameters for the
/// stored procedure (the first time each stored procedure is called), and
assign the values based on parameter order.
/// </summary>
/// <remarks>
/// This method provides no access to output parameters or the stored
procedure's return value parameter.
///
/// e.g.:
/// SqlDataReader dr = ExecuteReader(connString, "GetOrders", 24, 36);
/// </remarks>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="spName">the name of the stored procedure</param>
/// <param name="parameterValues">an array of objects to be assigned as the
input values of the stored procedure</param>
/// <returns>a SqlDataReader containing the resultset generated by the
command</returns>
public static SqlDataReader ExecuteReader(string connectionString, string
spName, params object[] parameterValues)
{
//if we receive parameter values, we need to figure out where they
go
if ((parameterValues != null) && (parameterValues.Length > 0))
{
//pull the parameters for this stored procedure from the
parameter cache (or discover them & populate the cache)
SqlParameter[] commandParameters =
SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);

//assign the provided values to these parameters based on


parameter order
AssignParameterValues(commandParameters, parameterValues);

//call the overload that takes an array of SqlParameters


return ExecuteReader(connectionString,
CommandType.StoredProcedure, spName, commandParameters);
}
//otherwise we can just call the SP without params
else
{
return ExecuteReader(connectionString,
CommandType.StoredProcedure, spName);
}
}

/// <summary>
/// Execute a SqlCommand (that returns a resultset and takes no parameters)
against the provided SqlConnection.
/// </summary>
/// <remarks>
/// e.g.:
/// SqlDataReader dr = ExecuteReader(conn, CommandType.StoredProcedure,
"GetOrders");
/// </remarks>
/// <param name="connection">a valid SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <returns>a SqlDataReader containing the resultset generated by the
command</returns>
public static SqlDataReader ExecuteReader(SqlConnection connection,
CommandType commandType, string commandText)
{
//pass through the call providing null for the set of SqlParameters
return ExecuteReader(connection, commandType, commandText,
(SqlParameter[])null);
}

/// <summary>
/// Execute a SqlCommand (that returns a resultset) against the specified
SqlConnection
/// using the provided parameters.
/// </summary>
/// <remarks>
/// e.g.:
/// SqlDataReader dr = ExecuteReader(conn, CommandType.StoredProcedure,
"GetOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="connection">a valid SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <param name="commandParameters">an array of SqlParamters used to
execute the command</param>
/// <returns>a SqlDataReader containing the resultset generated by the
command</returns>
public static SqlDataReader ExecuteReader(SqlConnection connection,
CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
//pass through the call to the private overload using a null
transaction value and an externally owned connection
return ExecuteReader(connection, (SqlTransaction)null, commandType,
commandText, commandParameters, SqlConnectionOwnership.External);
}

/// <summary>
/// Execute a stored procedure via a SqlCommand (that returns a resultset)
against the specified SqlConnection
/// using the provided parameter values. This method will query the
database to discover the parameters for the
/// stored procedure (the first time each stored procedure is called), and
assign the values based on parameter order.
/// </summary>
/// <remarks>
/// This method provides no access to output parameters or the stored
procedure's return value parameter.
///
/// e.g.:
/// SqlDataReader dr = ExecuteReader(conn, "GetOrders", 24, 36);
/// </remarks>
/// <param name="connection">a valid SqlConnection</param>
/// <param name="spName">the name of the stored procedure</param>
/// <param name="parameterValues">an array of objects to be assigned as the
input values of the stored procedure</param>
/// <returns>a SqlDataReader containing the resultset generated by the
command</returns>
public static SqlDataReader ExecuteReader(SqlConnection connection, string
spName, params object[] parameterValues)
{
//if we receive parameter values, we need to figure out where they
go
if ((parameterValues != null) && (parameterValues.Length > 0))
{
SqlParameter[] commandParameters =
SqlHelperParameterCache.GetSpParameterSet(connection.ConnectionString, spName);

AssignParameterValues(commandParameters, parameterValues);

return ExecuteReader(connection, CommandType.StoredProcedure,


spName, commandParameters);
}
//otherwise we can just call the SP without params
else
{
return ExecuteReader(connection, CommandType.StoredProcedure,
spName);
}
}
/// <summary>
/// Execute a SqlCommand (that returns a resultset and takes no parameters)
against the provided SqlTransaction.
/// </summary>
/// <remarks>
/// e.g.:
/// SqlDataReader dr = ExecuteReader(trans, CommandType.StoredProcedure,
"GetOrders");
/// </remarks>
/// <param name="transaction">a valid SqlTransaction</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <returns>a SqlDataReader containing the resultset generated by the
command</returns>
public static SqlDataReader ExecuteReader(SqlTransaction transaction,
CommandType commandType, string commandText)
{
//pass through the call providing null for the set of SqlParameters
return ExecuteReader(transaction, commandType, commandText,
(SqlParameter[])null);
}

/// <summary>
/// Execute a SqlCommand (that returns a resultset) against the specified
SqlTransaction
/// using the provided parameters.
/// </summary>
/// <remarks>
/// e.g.:
/// SqlDataReader dr = ExecuteReader(trans, CommandType.StoredProcedure,
"GetOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="transaction">a valid SqlTransaction</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <param name="commandParameters">an array of SqlParamters used to
execute the command</param>
/// <returns>a SqlDataReader containing the resultset generated by the
command</returns>
public static SqlDataReader ExecuteReader(SqlTransaction transaction,
CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
//pass through to private overload, indicating that the connection
is owned by the caller
return ExecuteReader(transaction.Connection, transaction,
commandType, commandText, commandParameters, SqlConnectionOwnership.External);
}

/// <summary>
/// Execute a stored procedure via a SqlCommand (that returns a resultset)
against the specified
/// SqlTransaction using the provided parameter values. This method will
query the database to discover the parameters for the
/// stored procedure (the first time each stored procedure is called), and
assign the values based on parameter order.
/// </summary>
/// <remarks>
/// This method provides no access to output parameters or the stored
procedure's return value parameter.
///
/// e.g.:
/// SqlDataReader dr = ExecuteReader(trans, "GetOrders", 24, 36);
/// </remarks>
/// <param name="transaction">a valid SqlTransaction</param>
/// <param name="spName">the name of the stored procedure</param>
/// <param name="parameterValues">an array of objects to be assigned as the
input values of the stored procedure</param>
/// <returns>a SqlDataReader containing the resultset generated by the
command</returns>
public static SqlDataReader ExecuteReader(SqlTransaction transaction,
string spName, params object[] parameterValues)
{
//if we receive parameter values, we need to figure out where they
go
if ((parameterValues != null) && (parameterValues.Length > 0))
{
SqlParameter[] commandParameters =
SqlHelperParameterCache.GetSpParameterSet(transaction.Connection.ConnectionString,
spName);

AssignParameterValues(commandParameters, parameterValues);

return ExecuteReader(transaction, CommandType.StoredProcedure,


spName, commandParameters);
}
//otherwise we can just call the SP without params
else
{
return ExecuteReader(transaction, CommandType.StoredProcedure,
spName);
}
}

#endregion ExecuteReader

#region ExecuteScalar

/// <summary>
/// Execute a SqlCommand (that returns a 1x1 resultset and takes no
parameters) against the database specified in
/// the connection string.
/// </summary>
/// <remarks>
/// e.g.:
/// int orderCount = (int)ExecuteScalar(connString,
CommandType.StoredProcedure, "GetOrderCount");
/// </remarks>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <returns>an object containing the value in the 1x1 resultset generated
by the command</returns>
public static object ExecuteScalar(string connectionString, CommandType
commandType, string commandText)
{
//pass through the call providing null for the set of SqlParameters
return ExecuteScalar(connectionString, commandType, commandText,
(SqlParameter[])null);
}

/// <summary>
/// Execute a SqlCommand (that returns a 1x1 resultset) against the
database specified in the connection string
/// using the provided parameters.
/// </summary>
/// <remarks>
/// e.g.:
/// int orderCount = (int)ExecuteScalar(connString,
CommandType.StoredProcedure, "GetOrderCount", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <param name="commandParameters">an array of SqlParamters used to
execute the command</param>
/// <returns>an object containing the value in the 1x1 resultset generated
by the command</returns>
public static object ExecuteScalar(string connectionString, CommandType
commandType, string commandText, params SqlParameter[] commandParameters)
{
//create & open a SqlConnection, and dispose of it after we are
done.
using (SqlConnection cn = new SqlConnection(connectionString))
{
cn.Open();

//call the overload that takes a connection in place of the


connection string
return ExecuteScalar(cn, commandType, commandText,
commandParameters);
}
}

/// <summary>
/// Execute a stored procedure via a SqlCommand (that returns a 1x1
resultset) against the database specified in
/// the connection string using the provided parameter values. This method
will query the database to discover the parameters for the
/// stored procedure (the first time each stored procedure is called), and
assign the values based on parameter order.
/// </summary>
/// <remarks>
/// This method provides no access to output parameters or the stored
procedure's return value parameter.
///
/// e.g.:
/// int orderCount = (int)ExecuteScalar(connString, "GetOrderCount", 24,
36);
/// </remarks>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="spName">the name of the stored procedure</param>
/// <param name="parameterValues">an array of objects to be assigned as the
input values of the stored procedure</param>
/// <returns>an object containing the value in the 1x1 resultset generated
by the command</returns>
public static object ExecuteScalar(string connectionString, string spName,
params object[] parameterValues)
{
//if we receive parameter values, we need to figure out where they
go
if ((parameterValues != null) && (parameterValues.Length > 0))
{
//pull the parameters for this stored procedure from the
parameter cache (or discover them & populate the cache)
SqlParameter[] commandParameters =
SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);

//assign the provided values to these parameters based on


parameter order
AssignParameterValues(commandParameters, parameterValues);

//call the overload that takes an array of SqlParameters


return ExecuteScalar(connectionString,
CommandType.StoredProcedure, spName, commandParameters);
}
//otherwise we can just call the SP without params
else
{
return ExecuteScalar(connectionString,
CommandType.StoredProcedure, spName);
}
}

/// <summary>
/// Execute a SqlCommand (that returns a 1x1 resultset and takes no
parameters) against the provided SqlConnection.
/// </summary>
/// <remarks>
/// e.g.:
/// int orderCount = (int)ExecuteScalar(conn, CommandType.StoredProcedure,
"GetOrderCount");
/// </remarks>
/// <param name="connection">a valid SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <returns>an object containing the value in the 1x1 resultset generated
by the command</returns>
public static object ExecuteScalar(SqlConnection connection, CommandType
commandType, string commandText)
{
//pass through the call providing null for the set of SqlParameters
return ExecuteScalar(connection, commandType, commandText,
(SqlParameter[])null);
}

/// <summary>
/// Execute a SqlCommand (that returns a 1x1 resultset) against the
specified SqlConnection
/// using the provided parameters.
/// </summary>
/// <remarks>
/// e.g.:
/// int orderCount = (int)ExecuteScalar(conn, CommandType.StoredProcedure,
"GetOrderCount", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="connection">a valid SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <param name="commandParameters">an array of SqlParamters used to
execute the command</param>
/// <returns>an object containing the value in the 1x1 resultset generated
by the command</returns>
public static object ExecuteScalar(SqlConnection connection, CommandType
commandType, string commandText, params SqlParameter[] commandParameters)
{
//create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, connection, (SqlTransaction)null, commandType,
commandText, commandParameters);

//execute the command & return the results


object retval = cmd.ExecuteScalar();

// detach the SqlParameters from the command object, so they can be


used again.
cmd.Parameters.Clear();
return retval;

/// <summary>
/// Execute a stored procedure via a SqlCommand (that returns a 1x1
resultset) against the specified SqlConnection
/// using the provided parameter values. This method will query the
database to discover the parameters for the
/// stored procedure (the first time each stored procedure is called), and
assign the values based on parameter order.
/// </summary>
/// <remarks>
/// This method provides no access to output parameters or the stored
procedure's return value parameter.
///
/// e.g.:
/// int orderCount = (int)ExecuteScalar(conn, "GetOrderCount", 24, 36);
/// </remarks>
/// <param name="connection">a valid SqlConnection</param>
/// <param name="spName">the name of the stored procedure</param>
/// <param name="parameterValues">an array of objects to be assigned as the
input values of the stored procedure</param>
/// <returns>an object containing the value in the 1x1 resultset generated
by the command</returns>
public static object ExecuteScalar(SqlConnection connection, string spName,
params object[] parameterValues)
{
//if we receive parameter values, we need to figure out where they
go
if ((parameterValues != null) && (parameterValues.Length > 0))
{
//pull the parameters for this stored procedure from the
parameter cache (or discover them & populate the cache)
SqlParameter[] commandParameters =
SqlHelperParameterCache.GetSpParameterSet(connection.ConnectionString, spName);

//assign the provided values to these parameters based on


parameter order
AssignParameterValues(commandParameters, parameterValues);

//call the overload that takes an array of SqlParameters


return ExecuteScalar(connection, CommandType.StoredProcedure,
spName, commandParameters);
}
//otherwise we can just call the SP without params
else
{
return ExecuteScalar(connection, CommandType.StoredProcedure,
spName);
}
}

/// <summary>
/// Execute a SqlCommand (that returns a 1x1 resultset and takes no
parameters) against the provided SqlTransaction.
/// </summary>
/// <remarks>
/// e.g.:
/// int orderCount = (int)ExecuteScalar(trans,
CommandType.StoredProcedure, "GetOrderCount");
/// </remarks>
/// <param name="transaction">a valid SqlTransaction</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <returns>an object containing the value in the 1x1 resultset generated
by the command</returns>
public static object ExecuteScalar(SqlTransaction transaction, CommandType
commandType, string commandText)
{
//pass through the call providing null for the set of SqlParameters
return ExecuteScalar(transaction, commandType, commandText,
(SqlParameter[])null);
}

/// <summary>
/// Execute a SqlCommand (that returns a 1x1 resultset) against the
specified SqlTransaction
/// using the provided parameters.
/// </summary>
/// <remarks>
/// e.g.:
/// int orderCount = (int)ExecuteScalar(trans,
CommandType.StoredProcedure, "GetOrderCount", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="transaction">a valid SqlTransaction</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <param name="commandParameters">an array of SqlParamters used to
execute the command</param>
/// <returns>an object containing the value in the 1x1 resultset generated
by the command</returns>
public static object ExecuteScalar(SqlTransaction transaction, CommandType
commandType, string commandText, params SqlParameter[] commandParameters)
{
//create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, transaction.Connection, transaction,
commandType, commandText, commandParameters);

//execute the command & return the results


object retval = cmd.ExecuteScalar();

// detach the SqlParameters from the command object, so they can be


used again.
cmd.Parameters.Clear();
return retval;
}

/// <summary>
/// Execute a stored procedure via a SqlCommand (that returns a 1x1
resultset) against the specified
/// SqlTransaction using the provided parameter values. This method will
query the database to discover the parameters for the
/// stored procedure (the first time each stored procedure is called), and
assign the values based on parameter order.
/// </summary>
/// <remarks>
/// This method provides no access to output parameters or the stored
procedure's return value parameter.
///
/// e.g.:
/// int orderCount = (int)ExecuteScalar(trans, "GetOrderCount", 24, 36);
/// </remarks>
/// <param name="transaction">a valid SqlTransaction</param>
/// <param name="spName">the name of the stored procedure</param>
/// <param name="parameterValues">an array of objects to be assigned as the
input values of the stored procedure</param>
/// <returns>an object containing the value in the 1x1 resultset generated
by the command</returns>
public static object ExecuteScalar(SqlTransaction transaction, string
spName, params object[] parameterValues)
{
//if we receive parameter values, we need to figure out where they
go
if ((parameterValues != null) && (parameterValues.Length > 0))
{
//pull the parameters for this stored procedure from the
parameter cache (or discover them & populate the cache)
SqlParameter[] commandParameters =
SqlHelperParameterCache.GetSpParameterSet(transaction.Connection.ConnectionString,
spName);

//assign the provided values to these parameters based on


parameter order
AssignParameterValues(commandParameters, parameterValues);

//call the overload that takes an array of SqlParameters


return ExecuteScalar(transaction, CommandType.StoredProcedure,
spName, commandParameters);
}
//otherwise we can just call the SP without params
else
{
return ExecuteScalar(transaction, CommandType.StoredProcedure,
spName);
}
}

#endregion ExecuteScalar

#region ExecuteXmlReader

/// <summary>
/// Execute a SqlCommand (that returns a resultset and takes no parameters)
against the provided SqlConnection.
/// </summary>
/// <remarks>
/// e.g.:
/// XmlReader r = ExecuteXmlReader(conn, CommandType.StoredProcedure,
"GetOrders");
/// </remarks>
/// <param name="connection">a valid SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL command
using "FOR XML AUTO"</param>
/// <returns>an XmlReader containing the resultset generated by the
command</returns>
public static XmlReader ExecuteXmlReader(SqlConnection connection,
CommandType commandType, string commandText)
{
//pass through the call providing null for the set of SqlParameters
return ExecuteXmlReader(connection, commandType, commandText,
(SqlParameter[])null);
}
/// <summary>
/// Execute a SqlCommand (that returns a resultset) against the specified
SqlConnection
/// using the provided parameters.
/// </summary>
/// <remarks>
/// e.g.:
/// XmlReader r = ExecuteXmlReader(conn, CommandType.StoredProcedure,
"GetOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="connection">a valid SqlConnection</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL command
using "FOR XML AUTO"</param>
/// <param name="commandParameters">an array of SqlParamters used to
execute the command</param>
/// <returns>an XmlReader containing the resultset generated by the
command</returns>
public static XmlReader ExecuteXmlReader(SqlConnection connection,
CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
//create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, connection, (SqlTransaction)null, commandType,
commandText, commandParameters);

//create the DataAdapter & DataSet


XmlReader retval = cmd.ExecuteXmlReader();

// detach the SqlParameters from the command object, so they can be


used again.
cmd.Parameters.Clear();
return retval;

/// <summary>
/// Execute a stored procedure via a SqlCommand (that returns a resultset)
against the specified SqlConnection
/// using the provided parameter values. This method will query the
database to discover the parameters for the
/// stored procedure (the first time each stored procedure is called), and
assign the values based on parameter order.
/// </summary>
/// <remarks>
/// This method provides no access to output parameters or the stored
procedure's return value parameter.
///
/// e.g.:
/// XmlReader r = ExecuteXmlReader(conn, "GetOrders", 24, 36);
/// </remarks>
/// <param name="connection">a valid SqlConnection</param>
/// <param name="spName">the name of the stored procedure using "FOR XML
AUTO"</param>
/// <param name="parameterValues">an array of objects to be assigned as the
input values of the stored procedure</param>
/// <returns>an XmlReader containing the resultset generated by the
command</returns>
public static XmlReader ExecuteXmlReader(SqlConnection connection, string
spName, params object[] parameterValues)
{
//if we receive parameter values, we need to figure out where they
go
if ((parameterValues != null) && (parameterValues.Length > 0))
{
//pull the parameters for this stored procedure from the
parameter cache (or discover them & populate the cache)
SqlParameter[] commandParameters =
SqlHelperParameterCache.GetSpParameterSet(connection.ConnectionString, spName);

//assign the provided values to these parameters based on


parameter order
AssignParameterValues(commandParameters, parameterValues);

//call the overload that takes an array of SqlParameters


return ExecuteXmlReader(connection,
CommandType.StoredProcedure, spName, commandParameters);
}
//otherwise we can just call the SP without params
else
{
return ExecuteXmlReader(connection,
CommandType.StoredProcedure, spName);
}
}

/// <summary>
/// Execute a SqlCommand (that returns a resultset and takes no parameters)
against the provided SqlTransaction.
/// </summary>
/// <remarks>
/// e.g.:
/// XmlReader r = ExecuteXmlReader(trans, CommandType.StoredProcedure,
"GetOrders");
/// </remarks>
/// <param name="transaction">a valid SqlTransaction</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL command
using "FOR XML AUTO"</param>
/// <returns>an XmlReader containing the resultset generated by the
command</returns>
public static XmlReader ExecuteXmlReader(SqlTransaction transaction,
CommandType commandType, string commandText)
{
//pass through the call providing null for the set of SqlParameters
return ExecuteXmlReader(transaction, commandType, commandText,
(SqlParameter[])null);
}

/// <summary>
/// Execute a SqlCommand (that returns a resultset) against the specified
SqlTransaction
/// using the provided parameters.
/// </summary>
/// <remarks>
/// e.g.:
/// XmlReader r = ExecuteXmlReader(trans, CommandType.StoredProcedure,
"GetOrders", new SqlParameter("@prodid", 24));
/// </remarks>
/// <param name="transaction">a valid SqlTransaction</param>
/// <param name="commandType">the CommandType (stored procedure, text,
etc.)</param>
/// <param name="commandText">the stored procedure name or T-SQL command
using "FOR XML AUTO"</param>
/// <param name="commandParameters">an array of SqlParamters used to
execute the command</param>
/// <returns>an XmlReader containing the resultset generated by the
command</returns>
public static XmlReader ExecuteXmlReader(SqlTransaction transaction,
CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
//create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
PrepareCommand(cmd, transaction.Connection, transaction,
commandType, commandText, commandParameters);

//create the DataAdapter & DataSet


XmlReader retval = cmd.ExecuteXmlReader();

// detach the SqlParameters from the command object, so they can be


used again.
cmd.Parameters.Clear();
return retval;
}

/// <summary>
/// Execute a stored procedure via a SqlCommand (that returns a resultset)
against the specified
/// SqlTransaction using the provided parameter values. This method will
query the database to discover the parameters for the
/// stored procedure (the first time each stored procedure is called), and
assign the values based on parameter order.
/// </summary>
/// <remarks>
/// This method provides no access to output parameters or the stored
procedure's return value parameter.
///
/// e.g.:
/// XmlReader r = ExecuteXmlReader(trans, "GetOrders", 24, 36);
/// </remarks>
/// <param name="transaction">a valid SqlTransaction</param>
/// <param name="spName">the name of the stored procedure</param>
/// <param name="parameterValues">an array of objects to be assigned as the
input values of the stored procedure</param>
/// <returns>a dataset containing the resultset generated by the
command</returns>
public static XmlReader ExecuteXmlReader(SqlTransaction transaction, string
spName, params object[] parameterValues)
{
//if we receive parameter values, we need to figure out where they
go
if ((parameterValues != null) && (parameterValues.Length > 0))
{
//pull the parameters for this stored procedure from the
parameter cache (or discover them & populate the cache)
SqlParameter[] commandParameters =
SqlHelperParameterCache.GetSpParameterSet(transaction.Connection.ConnectionString,
spName);

//assign the provided values to these parameters based on


parameter order
AssignParameterValues(commandParameters, parameterValues);

//call the overload that takes an array of SqlParameters


return ExecuteXmlReader(transaction,
CommandType.StoredProcedure, spName, commandParameters);
}
//otherwise we can just call the SP without params
else
{
return ExecuteXmlReader(transaction,
CommandType.StoredProcedure, spName);
}
}

#endregion ExecuteXmlReader
}

/// <summary>
/// SqlHelperParameterCache provides functions to leverage a static cache of
procedure parameters, and the
/// ability to discover parameters for stored procedures at run-time.
/// </summary>
public sealed class SqlHelperParameterCache
{
#region private methods, variables, and constructors

//Since this class provides only static methods, make the default
constructor private to prevent
//instances from being created with "new SqlHelperParameterCache()".
private SqlHelperParameterCache() {}

private static Hashtable paramCache = Hashtable.Synchronized(new


Hashtable());

/// <summary>
/// resolve at run time the appropriate set of SqlParameters for a stored
procedure
/// </summary>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="spName">the name of the stored procedure</param>
/// <param name="includeReturnValueParameter">whether or not to include
their return value parameter</param>
/// <returns></returns>
private static SqlParameter[] DiscoverSpParameterSet(string
connectionString, string spName, bool includeReturnValueParameter)
{
using (SqlConnection cn = new SqlConnection(connectionString))
using (SqlCommand cmd = new SqlCommand(spName,cn))
{
cn.Open();
cmd.CommandType = CommandType.StoredProcedure;

SqlCommandBuilder.DeriveParameters(cmd);

if (!includeReturnValueParameter)
{
cmd.Parameters.RemoveAt(0);
}

SqlParameter[] discoveredParameters = new


SqlParameter[cmd.Parameters.Count];;

cmd.Parameters.CopyTo(discoveredParameters, 0);

return discoveredParameters;
}
}

//deep copy of cached SqlParameter array


private static SqlParameter[] CloneParameters(SqlParameter[]
originalParameters)
{
SqlParameter[] clonedParameters = new
SqlParameter[originalParameters.Length];

for (int i = 0, j = originalParameters.Length; i < j; i++)


{
clonedParameters[i] =
(SqlParameter)((ICloneable)originalParameters[i]).Clone();
}

return clonedParameters;
}

#endregion private methods, variables, and constructors

#region caching functions

/// <summary>
/// add parameter array to the cache
/// </summary>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <param name="commandParameters">an array of SqlParamters to be
cached</param>
public static void CacheParameterSet(string connectionString, string
commandText, params SqlParameter[] commandParameters)
{
string hashKey = connectionString + ":" + commandText;

paramCache[hashKey] = commandParameters;
}
/// <summary>
/// retrieve a parameter array from the cache
/// </summary>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="commandText">the stored procedure name or T-SQL
command</param>
/// <returns>an array of SqlParamters</returns>
public static SqlParameter[] GetCachedParameterSet(string connectionString,
string commandText)
{
string hashKey = connectionString + ":" + commandText;

SqlParameter[] cachedParameters =
(SqlParameter[])paramCache[hashKey];

if (cachedParameters == null)
{
return null;
}
else
{
return CloneParameters(cachedParameters);
}
}

#endregion caching functions

#region Parameter Discovery Functions

/// <summary>
/// Retrieves the set of SqlParameters appropriate for the stored procedure
/// </summary>
/// <remarks>
/// This method will query the database for this information, and then
store it in a cache for future requests.
/// </remarks>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="spName">the name of the stored procedure</param>
/// <returns>an array of SqlParameters</returns>
public static SqlParameter[] GetSpParameterSet(string connectionString,
string spName)
{
return GetSpParameterSet(connectionString, spName, false);
}

/// <summary>
/// Retrieves the set of SqlParameters appropriate for the stored procedure
/// </summary>
/// <remarks>
/// This method will query the database for this information, and then
store it in a cache for future requests.
/// </remarks>
/// <param name="connectionString">a valid connection string for a
SqlConnection</param>
/// <param name="spName">the name of the stored procedure</param>
/// <param name="includeReturnValueParameter">a bool value indicating
whether the return value parameter should be included in the results</param>
/// <returns>an array of SqlParameters</returns>
public static SqlParameter[] GetSpParameterSet(string connectionString,
string spName, bool includeReturnValueParameter)
{
string hashKey = connectionString + ":" + spName +
(includeReturnValueParameter ? ":include ReturnValue Parameter":"");

SqlParameter[] cachedParameters;

cachedParameters = (SqlParameter[])paramCache[hashKey];

if (cachedParameters == null)
{
cachedParameters = (SqlParameter[])(paramCache[hashKey] =
DiscoverSpParameterSet(connectionString, spName, includeReturnValueParameter));
}

return CloneParameters(cachedParameters);
}

#endregion Parameter Discovery Functions

}
}

Employee Side Coding

ApplicationStatus.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Employee_frmApllicationStatus : System.Web.UI.Page


{
clsApplication_Logic objApplication = new clsApplication_Logic();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
objApplication.UserName = Session["UserName"].ToString();
DataSet ds=objApplication.GetApplicationStatus();
gvAppStatus.DataSource = ds.Tables[0];
gvAppStatus.DataBind();
}
}
}
Changepassword.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Employee_frmEmpChangePassword : System.Web.UI.Page


{
clsEmployeeLogin_Logic LoginObj = new clsEmployeeLogin_Logic();

protected void Page_Load(object sender, EventArgs e)


{

}
protected void btnSubmit_Click(object sender, EventArgs e)
{
Page.Validate();
if (Page.IsValid)
{
LoginObj .UserName = Session["UserName"].ToString();
LoginObj.OldPassword = txtOldPassword.Text.Trim();
if (LoginObj.CheckEmpOldPassword() == true)
{
if (txtNewPassword.Text.Trim() == txtOldPassword.Text.Trim())
{
lblError.Text = "New Password should not be same as Old Password";
lblError.Visible = true;
lblSuccess.Visible = false;
}
else
{
LoginObj .Password = txtNewPassword.Text.Trim();
LoginObj.EmpChangeOldPassword ();
lblSuccess.Visible = true;
lblSuccess.Text = "Your Password has been changed successfully!";
lblError.Visible = false;

}
}
else
{
lblError.Text = "Invalid Old Password";
lblError.Visible = true;
lblSuccess.Visible = false;
}
}
}
}
EmployeeHome.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Employee_frmEmployeeHome : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserName"] == null)
{
Response.Redirect("frmEmployeeLogin.aspx");
}
LblEmp.Text = "Welcome To " + Session ["UserName"].ToString();

}
}

EmployeeLogin.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Employee_frmEmployeeLogin : System.Web.UI.Page


{
clsEmployeeLogin_Logic LoginObj=new clsEmployeeLogin_Logic ();
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnSubmit_Click(object sender, EventArgs e)
{
try
{
LoginObj.UserName = txtLoginId.Text.Trim();
LoginObj.Password = txtPassword.Text.Trim();
DataSet dsEmpLoginDetail = LoginObj.GetEmpLoginDetails ();
DataRowCollection drc = dsEmpLoginDetail.Tables[0].Rows;
if (drc.Count > 0)
{
lblError.Visible = false;
DataRow dr = drc[0];
Session["UserName"] = dr["UserName"].ToString();
//Session["EmpLoginId"] = dr["EmpLoginId"];

}
else
{
lblError.Visible = true;
lblError.Text = "Invalid Login ID/Password";
}
}
catch (Exception ex)
{
lblError.Visible = true;
lblError.Text = ex.Message.ToString();
}
Response.Redirect("frmEmployeeHome.aspx");

protected void LnkNewUser_Click(object sender, EventArgs e)


{
//Response.Redirect("frmEmployeeRegistration.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("~/Default.aspx");
}
}

employeeLogout.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Employee_frmEmployeeLogOutSuccessful : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
Session.Abandon();
Response.Redirect("~/Default.aspx");
}

Leaveapplication.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Employee_frmLeaveApplication : System.Web.UI.Page


{
clsLeave_Logic objLeave = new clsLeave_Logic();
clsApplication_Logic objApplicaion = new clsApplication_Logic();
protected void Page_Load(object sender, EventArgs e)
{

if (Session["UserName"] == null)
{
Response.Redirect("frmEmployeeLogin.aspx");
}
else
txtUserName.Text = Session["UserName"].ToString();
if (!IsPostBack)
{
BindLeavetype();

}
GMDStartDate.Attributes.Add("readonly", "readOnly()");
}

void BindLeavetype()
{
DataSet dsLeavetype = objLeave.GetLeaveType();
ddlLeaveType.DataSource = dsLeavetype.Tables[0];
ddlLeaveType.DataTextField = "LeaveTypeName";
ddlLeaveType.DataValueField = "LeaveTypeId";
ddlLeaveType.DataBind();
ddlLeaveType.Items.Insert(0, "Select");
}

protected void ddlLeaveType_SelectedIndexChanged(object sender, EventArgs e)


{
if (ddlLeaveType.SelectedItem.Text != "Select")
{
objLeave.UserName = Session["UserName"].ToString();
objLeave.LeaveTypeId = Convert.ToInt32(ddlLeaveType.SelectedItem.Value);
int BalaceLeaves = objLeave.GetBalanceDays();
txtBalanceLeave.Text = BalaceLeaves.ToString();
}
else
txtBalanceLeave.Text = "";
}
protected void btnApplyLeave_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(txtNoOfdays.Text) <= Convert.ToInt32(txtBalanceLeave.Text))
{
objApplicaion.UserName = Session["UserName"].ToString();
objApplicaion.LeaveTypeId = Convert.ToInt32(ddlLeaveType.SelectedItem.Value);
objApplicaion.StartingDate = GMDStartDate.DateString;
objApplicaion.ApplaiyingDate = System.DateTime.Now.ToString();
objApplicaion.NoOfDays = Convert.ToInt32(txtNoOfdays.Text);
//string.Format("{0:yyyy-MM-dd}", System.DateTime.Now.AddDays(1))
DateTime s = GMDStartDate.Date;
objApplicaion.EndingDate =
(s.AddDays(Convert.ToInt32(txtNoOfdays.Text))).ToString();
objApplicaion.LeavePurpose = txtPurpose.Text;
objApplicaion.AddLeaveApplication();
Response.Redirect("frmLeaveApplicationSuccess.aspx");
}
else
{
lblError.Visible = true;
lblError.Text = "No of Days should not be more than Balalnce days";
}
}
protected void btnBack_Click(object sender, EventArgs e)
{
Response.Redirect("frmEmployeeHome.aspx");
}
}

updateEmployee.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Employee_frmEditEmployeeDetails : System.Web.UI.Page


{
clsEmployee_Logic EmpObj = new clsEmployee_Logic();
clsCommon_Logic objCommon = new clsCommon_Logic();
// clsUsers_Logic objUser = new clsUsers_Logic();
protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
BindDept();
BindCountry();
// BindStatus();
BindState();
BindCity();
BindDesignation();
BindData();
}
}
void BindCountry()
{
DataSet dsCountry = objCommon.GetCountryName();
ddlCountryName.DataSource = dsCountry.Tables[0];
ddlCountryName.DataTextField = "CountryName";
ddlCountryName.DataValueField = "CountryId";
ddlCountryName.DataBind();
ddlCountryName.Items.Insert(0, "Select");
}
void BindState()
{
DataSet dsState = objCommon.GetStateName();
ddlStateName.DataSource = dsState.Tables[0];
ddlStateName.DataTextField = "StateName";
ddlStateName.DataValueField = "StateId";
ddlStateName.DataBind();
ddlStateName.Items.Insert(0, "Select");

}
void BindCity()
{
DataSet dsCity = objCommon.GetCityName();
ddlCityName.DataSource = dsCity.Tables[0];
ddlCityName.DataTextField = "CityName";
ddlCityName.DataValueField = "CityId";
ddlCityName.DataBind();
ddlCityName.Items.Insert(0, "Select");
}
void BindDept()
{
DataSet dsDept = objCommon.GetDeptName();
ddlDept.DataSource = dsDept.Tables[0];
ddlDept.DataTextField = "DeptName";
ddlDept.DataValueField = "DeptId";
ddlDept.DataBind();
ddlDept.Items.Insert(0, "Select");
}
void BindDesignation()
{
DataSet dsDesgn = objCommon.GetDesignation();
ddlDesig.DataSource = dsDesgn.Tables[0];
ddlDesig.DataTextField = "DesigType";
// ddlDesig.DataValueField = "DesigId";
ddlDesig.DataBind();
ddlDesig.Items.Insert(0, "Select");
}

public void BindData()


{
EmpObj.UserName = Session["UserName"].ToString();
EmpObj.GetEmployeeDetails();
txtUserName.Text = Session["UserName"].ToString();
txtEmpName.Text = EmpObj.EmpName;
//txtPassword.Text = EmpObj.Password;
txtAddress.Text = EmpObj.Address;
txtEmailId.Text = EmpObj.EmailId;
txtContactNo.Text = EmpObj.ContactNo;
//Modifications
int DeptIndex =
ddlDept.Items.IndexOf(ddlDept.Items.FindByValue(EmpObj.DeptId.ToString()));
if (DeptIndex >= 0)
ddlDept.Items[DeptIndex].Selected = true;

int CountryIndex =
ddlCountryName.Items.IndexOf(ddlCountryName.Items.FindByValue(EmpObj.CountryId.ToString()
));
if (CountryIndex >= 0)
ddlCountryName.Items[CountryIndex].Selected = true;

int StateIndex =
ddlStateName.Items.IndexOf(ddlStateName.Items.FindByValue(EmpObj.StateId.ToString()));
if (StateIndex >= 0)
ddlStateName.Items[StateIndex].Selected = true;

int CityIndex =
ddlCityName.Items.IndexOf(ddlCityName.Items.FindByValue(EmpObj.CityId.ToString()));
if (CityIndex >= 0)
ddlCityName.Items[CityIndex].Selected = true;

int DesigIndex =
ddlDesig.Items.IndexOf(ddlDesig.Items.FindByText(EmpObj.Designation.ToString()));
if (DesigIndex >= 0)
ddlDesig.Items[DesigIndex].Selected = true;
}

protected void btnBack_Click(object sender, EventArgs e)


{
Response.Redirect("frmEmployeeHome.aspx");
}
protected void ddlCountryName_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlCountryName.SelectedItem.Text != "Select")
{
objCommon.pro_CountryId = Convert.ToInt32(ddlCountryName.SelectedItem.Value);
BindState();
}
}
protected void ddlStateName_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlStateName.SelectedItem.Text != "Select")
{
objCommon.pro_StateId = Convert.ToInt32(ddlStateName.SelectedItem.Value);
BindCity();
}
}
protected void ddlCityName_SelectedIndexChanged(object sender, EventArgs e)
{

protected void btnUpdate_Click(object sender, EventArgs e)


{
EmpObj.UserName = Session["UserName"].ToString();
//EmpObj.EmpId =Convert.ToInt32(Session["EmpId"].ToString());
EmpObj.EmpName = txtEmpName.Text.Trim();
EmpObj.Address = txtAddress.Text.Trim();
EmpObj.Designation = ddlDesig.SelectedItem.Text;
EmpObj.CountryId = Convert.ToInt32(ddlCountryName.SelectedItem.Value);
EmpObj.StateId = Convert.ToInt32(ddlStateName.SelectedItem.Value);
EmpObj.CityId = Convert.ToInt32(ddlCityName.SelectedItem.Value);
EmpObj.ContactNo = txtContactNo.Text.Trim();
EmpObj.DeptId = Convert.ToInt32(ddlDept.SelectedItem.Value);
EmpObj.EmailId = txtEmailId.Text.Trim();
// EmpObj.StatusId = Convert.ToInt32(ddlStatus.SelectedItem.Value);
EmpObj.UpdateEmployeeDetails();
}
}

Employeemaster

<%@ Master Language="C#" AutoEventWireup="true"


CodeFile="SimpleEmployeeMasterPage.master.cs" Inherits="Employee_SimpleEmployeeMasterPage"
%>

<!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 id="Head1" runat="server">

<title>Untitled Page</title>

<link href="../App_Themes/Theme/black_world.css" rel="stylesheet" type="text/css" />

</head>

<body>

<form id="form1" runat="server">

<asp:ScriptManager ID="ScriptManager1" runat="server">

</asp:ScriptManager>
<div>

<table width="779" border="0" align="center" cellpadding="0" cellspacing="0" class="bordermain">

<tr>

<td height="130" valign="top" style="background-image:url(../Images/bg.jpg); background-


repeat:repeat-x;"><table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>

<td><table border="0" cellspacing="0" cellpadding="0">

<tr>

<td class="border" style="text-align: center; width: 800px;"><table border="0" cellspacing="0"


cellpadding="0">

<tr>

<td align="center" class="logo" style="width: 284px">

Easy Leave &nbsp;</td>

</tr>

</table></td>

<td></td>

</tr>

</table></td>

</tr>

<tr>

<td>

</td>

</tr>
</table></td>

</tr>

<tr>

<td bgcolor="#7A7A7A" class="content" style="padding-top:10px; padding-bottom:10px;">

<div style="height:408px">

<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">

</asp:contentplaceholder>

</div>

</td>

</tr>

<tr>

<td height="30" bgcolor="#96C942" class="content" align="center" style="text-align: center" >

All Rights Reserved &copy; </td>

</tr>

</table>

</div>

</form>

</body>

</html>

You might also like