using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
// here we are providing bussiness logic for the current application
public class BussinessLogicLayer
{
SqlConnection cn;
SqlCommand cmd;
SqlDataReader dr;
public BussinessLogicLayer()
{
string cs;
cs = ConfigurationManager.ConnectionStrings["SSDCS"].ConnectionString;
cn = new SqlConnection(cs);
cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandType = CommandType.Text;
}
public SqlDataReader GetAllUsers()
{
cmd.CommandText = "select * from SSDUsers";
if (cn.State == ConnectionState.Closed)
cn.Open();
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
//closing connection reader
return dr;
}
public bool IsUserExists(string uname)
{
cmd.CommandText = string.Format("select count (*) from SSDUsers where Username={0}", uname);
//For checking the table is present or not
if (cn.State == ConnectionState.Closed)
cn.Open();
//for opening the connection
int count = int.Parse(cmd.ExecuteScalar().ToString());
//execute scalar method return objects that's why we are using parsing
cn.Close();
if (count > 0)
return true;
else
return false;
}
public bool validateuser(string uname, string pwd)
{
cmd.CommandText = string.Format("select count(*) from SSDUsers where Username{0},Password={1}", uname, pwd);
if (cn.State == ConnectionState.Closed)
cn.Open();
int count = int.Parse(cmd.ExecuteScalar().ToString());
cn.Close();
if (count > 0)
return true;
else
return false;
}
public bool AddUser(string uname, string pwd)
{
cmd.CommandText = string.Format("insert into SSDUsers values Username={0},Password={1}", uname, pwd);
//String.Formt Replaces each format item in a specified string with the text equivalent of a corresponding object's value.
if (cn.State == ConnectionState.Closed)
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
return true;
}
public bool ChangePassword(string uname, string opwd, string npwd)
{
if (validateuser(uname, opwd) == true)
cmd.CommandText = string.Format("Update SSDUsers set Password={0} where Username={1}", npwd, uname);
if (cn.State == ConnectionState.Closed)
{
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
return true;
}
else
{
return false;
}
}
public bool RemoveUser(string uname)
{
if (IsUserExists(uname) == true)
{
cmd.CommandText = string.Format("delete from SSDUsers where UserName={0}", uname);
if (cn.State == ConnectionState.Closed)
{
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
return true;
}
else
{
return false;
}
}
}
}
vprOYZdTzbGloriane July 3, 2011 at 9:07 AM
Now thatÂ?s stulbe! Great to hear from you.
doubt in asp.netsudhir June 14, 2012 at 9:26 PM
using System; using System.Data; using System.Data.SqlClient; using System.Configuration; // here we are providing bussiness logic for the current application public class BussinessLogicLayer { SqlConnection cn; SqlCommand cmd; SqlDataReader dr; public BussinessLogicLayer() { string cs; cs = ConfigurationManager.ConnectionStrings["SSDCS"].ConnectionString; cn = new SqlConnection(cs); cmd = new SqlCommand(); cmd.Connection = cn; cmd.CommandType = CommandType.Text; } public SqlDataReader GetAllUsers() { cmd.CommandText = "select * from SSDUsers"; if (cn.State == ConnectionState.Closed) cn.Open(); dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); //closing connection reader return dr; } public bool IsUserExists(string uname) { cmd.CommandText = string.Format("select count (*) from SSDUsers where Username={0}", uname); //For checking the table is present or not if (cn.State == ConnectionState.Closed) cn.Open(); //for opening the connection int count = int.Parse(cmd.ExecuteScalar().ToString()); //execute scalar method return objects that's why we are using parsing cn.Close(); if (count > 0) return true; else return false; } public bool validateuser(string uname, string pwd) { cmd.CommandText = string.Format("select count(*) from SSDUsers where Username{0},Password={1}", uname, pwd); if (cn.State == ConnectionState.Closed) cn.Open(); int count = int.Parse(cmd.ExecuteScalar().ToString()); cn.Close(); if (count > 0) return true; else return false; } public bool AddUser(string uname, string pwd) { cmd.CommandText = string.Format("insert into SSDUsers values Username={0},Password={1}", uname, pwd); //String.Formt Replaces each format item in a specified string with the text equivalent of a corresponding object's value. if (cn.State == ConnectionState.Closed) cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } public bool ChangePassword(string uname, string opwd, string npwd) { if (validateuser(uname, opwd) == true) cmd.CommandText = string.Format("Update SSDUsers set Password={0} where Username={1}", npwd, uname); if (cn.State == ConnectionState.Closed) { cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } else { return false; } } public bool RemoveUser(string uname) { if (IsUserExists(uname) == true) { cmd.CommandText = string.Format("delete from SSDUsers where UserName={0}", uname); if (cn.State == ConnectionState.Closed) { cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } else { return false; } } } }
iphone trainingmanish jaiswal September 25, 2012 at 8:45 PM
are u provide any training for iphone technology?? if yes then tell me all about this like new batch, timing, fee structure??
Post your Comment