<F>BOL<F>
BOL.cs
............
using System;
using System.Collections.Generic;
using System.Text;
/// <summary>
/// Summary description for BOL
/// </summary>
namespace Tabakhat
{
namespace BOL
{
public struct Users
{
public long UserID;
public string UserName;
public string Password;
public byte AdminUser;
public byte Status;
}
public struct Customers
{
public long CustomerID;
public string Mobilenumber;
public string Password;
public string City;
public DateTime BirthDate;
}
public struct Categories
{
public int CatID;
public string CatName;
public string Description;
public string Path;
public byte Status;
}
public struct Items
{
public int ItemID;
public int CatID;
public string ItemName;
public string Description;
public String ImagePath;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace T
{
namespace BOL
{
public struct Users
{
public long UserID;
public string UserName;
public string Password;
public byte AdminUser;
public byte Status;
}
public struct Customers
{
public long CustomerID;
public string Mobilenumber;
public string Password;
public string City;
public DateTime BirthDate;
}
}
}
<F>BLL<F>
UsersBLL.cs
.........................
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using T.BOL;
using T.DAL;
namespace T
{
namespace BLL
{
public class UsersBLL
{
public UsersBLL()
{
//
// TODO: Add constructor logic here
//
}
public int AddUser(string name, string pass, byte admUser, byte status)
{
Users user = new Users();
user.UserName = name;
user.Password = pass;
user.AdminUser = admUser;
user.Status = status;
UsersDAL userDAl = new UsersDAL();
return userDAl.AddUser(user);
}
public void EditUser(string name, string pass, byte admUser, byte status, int id)
{
Users user = new Users();
user.UserID = id;
user.UserName = name;
user.Password = pass;
user.AdminUser = admUser;
user.Status = status;
UsersDAL userDAl = new UsersDAL();
userDAl.EditUser(user);
}
public void UpdateStatus(int ID, byte status)
{
Users user = new Users();
user.UserID = ID;
user.Status = status;
UsersDAL userDAl = new UsersDAL();
userDAl.UpdateStatus(user);
}
public Users CheckUser(String UserName, String Password)
{
UsersDAL userDAl = new UsersDAL();
return userDAl.CheckUser(UserName,Password);
}
public Users CheckUserAvailable(String UserName)
{
UsersDAL userDAl = new UsersDAL();
return userDAl.CheckUserAvailable(UserName);
}
public Users GetByUserID(long UserID)
{
UsersDAL userDAl = new UsersDAL();
return userDAl.GetByUserID(UserID);
}
public DataTable GetAllUsers()
{
UsersDAL userDAl = new UsersDAL();
return userDAl.GetAllUsers();
}
}
}
}
<F>DAL</F>
UsersDAL.cs
....................
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using T.BOL;
namespace T
{
namespace DAL
{
public class UsersDAL : DALBase
{
public UsersDAL()
{
//
// TODO: Add constructor logic here
//
}
public int AddUser(Users user)
{
SqlCommand cmnd = BuildCommandSP("User_AddUser");
cmnd.Parameters.AddWithValue("@UserName", user.UserName);
cmnd.Parameters.AddWithValue("@Password", user.Password );
cmnd.Parameters.AddWithValue("@AdminUser", user.AdminUser );
cmnd.Parameters.AddWithValue("@Status", user.Status);
return ExecCmndSP(ref cmnd);
}
public void EditUser(Users user)
{
SqlCommand cmnd = BuildCommandSP("User_EditUser");
cmnd.Parameters.AddWithValue("@UserName", user.UserName);
cmnd.Parameters.AddWithValue("@Password", user.Password);
cmnd.Parameters.AddWithValue("@AdminUser", user.AdminUser);
cmnd.Parameters.AddWithValue("@Status", user.Status);
cmnd.Parameters.AddWithValue("@UserID", user.UserID);
ExecCmndSP(ref cmnd);
}
public void UpdateStatus(Users user)
{
SqlCommand cmnd = BuildCommandSP("User_UpdateStatus");
cmnd.Parameters.AddWithValue("@Status", user.Status);
cmnd.Parameters.AddWithValue("@UserID", user.UserID);
ExecCmndSP(ref cmnd);
}
public Users CheckUser(String UserName, String Password)
{
SqlCommand cmnd = BuildCommandSP("User_CheckUser");
Users user = new Users();
cmnd.Parameters.AddWithValue("@Username", UserName);
cmnd.Parameters.AddWithValue("@PassWord", Password);
if (cmnd.Connection.State != ConnectionState.Open)
cmnd.Connection.Open();
SqlDataReader dr;
dr = cmnd.ExecuteReader();
if (dr.Read())
{
user.UserID = Convert.ToByte(dr["UserID"].ToString());
user.UserName = dr["Username"].ToString();
user.Password = dr["PassWord"].ToString();
user.AdminUser = Convert.ToByte(dr["AdminUser"]);
user.Status = Convert.ToByte (dr["Status"]);
}
cmnd.Connection.Close();
return user;
}
public Users CheckUserAvailable(String UserName)
{
SqlCommand cmnd = BuildCommandSP("User_CheckUserAvailable");
Users user = new Users();
cmnd.Parameters.AddWithValue("@Username", UserName);
if (cmnd.Connection.State != ConnectionState.Open)
cmnd.Connection.Open();
SqlDataReader dr;
dr = cmnd.ExecuteReader();
if (dr.Read())
{
user.UserID = Convert.ToByte(dr["UserID"].ToString());
user.UserName = dr["Username"].ToString();
user.Password = dr["PassWord"].ToString();
user.AdminUser = Convert.ToByte(dr["AdminUser"]);
user.Status = Convert.ToByte(dr["Status"]);
}
cmnd.Connection.Close();
return user;
}
public Users GetByUserID(long UserID)
{
SqlCommand cmnd = BuildCommandSP("User_GetByUserID");
Users user = new Users();
cmnd.Parameters.AddWithValue("@UserID", UserID);
if (cmnd.Connection.State != ConnectionState.Open)
cmnd.Connection.Open();
SqlDataReader dr;
dr = cmnd.ExecuteReader();
if (dr.Read())
{
user.UserID = Convert.ToInt64( dr["UserID"].ToString());
user.UserName = dr["Username"].ToString();
user.Password = dr["PassWord"].ToString();
user.AdminUser = Convert.ToByte (dr["AdminUser"]);
user.Status = Convert.ToByte(dr["Status"].ToString());
}
cmnd.Connection.Close();
return user;
}
public DataTable GetAllUsers()
{
DataTable result = new DataTable("Users");
SqlDataAdapter da = BuildBasicQuerySP("User_GetAllUsers");
da.Fill(result);
return result;
}
}
}
}
.................................................
Users.aspx.cs
...................
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using T.BLL;
using T.BOL;
public partial class CreateUser : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserName"] == null)
{
Response.Redirect("LogOf.aspx");
return;
}
if (Session["AdminUser"].ToString() == "0")
{
hlCreateUser.Visible = false;
}
else
{
hlCreateUser.Visible = true;
}
lblErrorMsg.Visible = false;
if (!IsPostBack)
{
refreshUserGrid();
}
}
protected void btnCreateUser_Click(object sender, EventArgs e)
{
int i = txtPass.Text.CompareTo(txtPassConfirm.Text);
if (txtPass.Text!=txtPassConfirm.Text) {
lblErrorMsg.Text = "User not created.\nBoth password should match!";
lblErrorMsg.Visible = true;
return;
}
UsersBLL userBLL = new UsersBLL();
Users user = new Users();
user = userBLL.CheckUserAvailable(txtUserName.Text);
if (user.UserName == null)
{
lblErrorMsg.Visible = false;
userBLL.AddUser(txtUserName.Text, txtPass.Text, Convert.ToByte(rdoAdminUser.Items[0].Selected), Convert.ToByte(rdoStatus.Items[0].Selected));
lblErrorMsg.Text = "User created successfuly!";
lblErrorMsg.Visible =true ;
refreshUserGrid();
}
else {
lblErrorMsg.Text = "User name already exist!";
lblErrorMsg.Visible = true;
}
}
protected void gvUserDtls_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//Accessing Edited values from the GridView
int id = Convert.ToInt16(((TextBox)gvUserDtls.Rows[e.RowIndex].Cells[0].Controls[0]).Text);
string name = ((TextBox)gvUserDtls.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
string pass = ((TextBox)gvUserDtls.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
bool admUser = ((CheckBox)gvUserDtls.Rows[e.RowIndex].Cells[3].Controls[0]).Checked;
bool status = ((CheckBox)gvUserDtls.Rows[e.RowIndex].Cells[4].Controls[0]).Checked;
UsersBLL userBLL = new UsersBLL();
userBLL.EditUser(name, pass, Convert.ToByte(admUser), Convert.ToByte(status), id);
gvUserDtls.EditIndex = -1;
refreshUserGrid();
}
}