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 DataAccessLayer;
using BusinessLogic;
///
/// Summary description for BaseDB
///
namespace DataAccessLayer
{
public class BaseDB
{
///
/// This is a comman function which is used by various class files for getting dataset.
///
/// sqlcommand type object
///
internal static DataSet GetDataset(SqlCommand oCommand)//Accepts sqlcommand and procedure name as parameters and makes connection with database to bring required data and returns dataset
{
using (DataSet oDataSet = new DataSet())
{
using (SqlConnection oConn = new SqlConnection(CommonClass.getConnectionPath()))
{
oCommand.Connection = oConn;
oCommand.CommandType = CommandType.StoredProcedure;
oCommand.CommandTimeout = 3600;
using (SqlDataAdapter oAdapter = new SqlDataAdapter())
{
oAdapter.SelectCommand = oCommand;
try
{
oAdapter.Fill(oDataSet);
}
catch (Exception e)
{
throw e;
}
}
}
return oDataSet;
}
}
///
/// This is a commen function used by various class files to get scalar values from databae.
///
/// sqlcommand type object
///
internal static object ExecuteScalar(SqlCommand oCommand)
{
object objectToRead = null;
using (SqlConnection oConn = new SqlConnection(CommonClass.getConnectionPath()))
{
if (oConn.State == ConnectionState.Closed)
{
oConn.Open();
}
oCommand.Connection = oConn;
oCommand.CommandType = CommandType.StoredProcedure;
oCommand.CommandTimeout = 3600;
try { objectToRead = oCommand.ExecuteScalar(); }
catch (Exception e) { throw e; }
}
return objectToRead;
}
///
/// Commen function shared by all the class file to execute update , delete queries and return nothing.
///
/// sqlcommand type object
internal static int ExecuteNonQuery(SqlCommand oCommand)
{
using (SqlConnection oConn = new SqlConnection(CommonClass.getConnectionPath()))
{
if (oConn.State == ConnectionState.Closed)
{
oConn.Open();
}
oCommand.Connection = oConn;
oCommand.CommandType = CommandType.StoredProcedure;
oCommand.CommandTimeout = 3600;
try { return oCommand.ExecuteNonQuery(); }
catch (Exception e) { return 0; }
}
}
///
/// Commen function shared by all the class file to execute update , delete queries
/// and return no. of rows affected, because in file we perform other operations on the base
/// of rows affected.
///
/// sqlcommand type object
///
internal static int ExecuteNonQuery_ReturnVal(SqlCommand oCommand)
{
int RowsAffected = 0;
using (SqlConnection oConn = new SqlConnection(CommonClass.getConnectionPath()))
{
if (oConn.State == ConnectionState.Closed)
{
oConn.Open();
}
oCommand.Connection = oConn;
oCommand.CommandType = CommandType.StoredProcedure;
oCommand.CommandTimeout = 3600;
try
{
RowsAffected = oCommand.ExecuteNonQuery();
return RowsAffected;
}
catch (Exception e)
{
return RowsAffected;
}
}
return RowsAffected;
}
}
}
COMMON CLASS
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;
///
/// Summary description for CommonClass
///
///
namespace BusinessLogic
{
public class CommonClass
{
public CommonClass()
{
//
// TODO: Add constructor logic here
//
}
public static string getConnectionPath()
{
return ConfigurationManager.ConnectionStrings["connStr"].ConnectionString.ToString();
}
public static string Trim( TextBox tb)
{
return tb.Text.Trim();
}
public static void AddParameter(SqlCommand cmd, string parmName, string value)
{
parmName = "@" + parmName.Trim();
cmd.Parameters.AddWithValue(parmName, value);
}
///
/// This function used for bind GridView with dataset.
///
///
///
///
public static int Bind(DataSet dst, GridView gv)
{
try
{
if (dst.Tables[0].Rows.Count > 0)
{
gv.DataSource = dst;
gv.DataBind();
return 1;
}
else
{
return 2;
}
}
catch
{
return 0;/// Error
}
}
public static string StyleforSelectedRow()
{
return "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#add8e6'";
}
///
/// Function is used for insert - between strings etc phone number
///
///
///
///
public static string PhoneString(string str, int len)
{
string retString = string.Empty;;
if (str.Length == len)
{
retString ="("+ str.Substring(0, 3) +") "+ str.Substring(3, 3) +"-"+ str.Substring(6, 4);
return retString;
}
return str;
}
///
/// This function break the email from @ when lenthh is > 25
///
public static string EMailBreak(string str, int len)
{
string retString = string.Empty; ;
if ((str.Length > len) && ( str.Contains("@")))
{
retString = str.Replace("@", "
@");
return retString;
}
return str;
}
}
}
APPLICATION PATH TO FIND WHERE APPLICATION
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;
///
/// Summary description for CommonClass
///
///
namespace BusinessLogic
{
public class CommonClass
{
public CommonClass()
{
//
// TODO: Add constructor logic here
//
}
public static string getConnectionPath()
{
return ConfigurationManager.ConnectionStrings["connStr"].ConnectionString.ToString();
}
public static string Trim( TextBox tb)
{
return tb.Text.Trim();
}
public static void AddParameter(SqlCommand cmd, string parmName, string value)
{
parmName = "@" + parmName.Trim();
cmd.Parameters.AddWithValue(parmName, value);
}
///
/// This function used for bind GridView with dataset.
///
///
///
///
public static int Bind(DataSet dst, GridView gv)
{
try
{
if (dst.Tables[0].Rows.Count > 0)
{
gv.DataSource = dst;
gv.DataBind();
return 1;
}
else
{
return 2;
}
}
catch
{
return 0;/// Error
}
}
public static string StyleforSelectedRow()
{
return "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#add8e6'";
}
///
/// Function is used for insert - between strings etc phone number
///
///
///
///
public static string PhoneString(string str, int len)
{
string retString = string.Empty;;
if (str.Length == len)
{
retString ="("+ str.Substring(0, 3) +") "+ str.Substring(3, 3) +"-"+ str.Substring(6, 4);
return retString;
}
return str;
}
///
/// This function break the email from @ when lenthh is > 25
///
public static string EMailBreak(string str, int len)
{
string retString = string.Empty; ;
if ((str.Length > len) && ( str.Contains("@")))
{
retString = str.Replace("@", "
@");
return retString;
}
return str;
}
}
}
Thanks
Helpondesk Team