Sei sulla pagina 1di 38

Registration page:

Registration page Source Code:

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


AutoEventWireup="true" CodeFile="frmRegistration.aspx.cs"
Inherits="frmRegistration" Title="frmRegistration" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit"


tagprefix="cc1" %>

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


<style type="text/css">
.style4
{
font-size: larger;
font-weight: bold;
color: #FF3300;
}
.style5
{
width: 100%;
}
.style6
{
width: 398px;
}
.style7
{
font-size: large;
color: #FFFF00;
font-weight: bold;
}
.style8
{
color: #FF0000;
font-size: small;
}
.style10
{
width: 110px;
color: blue;
}
.style11
{
width: 150px;
color: blue;
}
.style12
{
width: 83px;
color: blue;
}
.style13
{
}
.style14
{
width: 25px;
}
.style15
{
width: 40px;
color: blue;
}
.style16
{
width: 35px;
color: blue;
}
.style17
{
width: 70px;
color: blue;
}
.style18
{
width: 170px;
}
.style19
{
width: 170px;
color: #0000FF;
}
.style20
{
width: 170px;
color: #3333FF;
}
.style21
{
width: 170px;
color: #3333CC;
}
.style22
{
height: 28px;
}
.style23
{
color: blue;
}
.style24
{
color: #006600;
}
.style25
{
font-size: large;
color: #006666;
font-weight: bold;
}
.style26
{
color: #FF0000;
font-weight: bold;
font-size: small;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<h2 align="center" style="height: 32px">
<span class="style4">New Users Register Here</span><br />
</h2>
<table class="style5">
<tr>
<td class="style6">
<img alt="" src="ProjectImages/doctor%20and%20drugs.jpg"
style="width: 413px; height: 404px" /><br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</td>
<td>
<asp:Panel ID="Panel1" runat="server"
GroupingText="Registration Form"
BackColor="White" ForeColor="Red">

<table class="style5">
<tr>
<td class="style7" colspan="2">
<span class="style24">Enter Personal
Details:</span><span class="style8">(*)Mandatory Fields</span></td>
</tr>
<tr>
<td align="right" class="style23" colspan="2">
<table class="style5">
<tr>
<td class="style10">
First Name:</td>
<td align="left" class="style11">
<asp:TextBox ID="txtFname"
runat="server" Height="23px" ValidationGroup="add"
Width="135px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtFname"
ErrorMessage="*" ValidationGroup="add"></asp:RequiredFieldValidator>
</td>
<td class="style12">
Last Name:</td>
<td align="left" class="style23">
<asp:TextBox ID="txtLname"
runat="server" Height="23px" ValidationGroup="add"
Width="135px"></asp:TextBox>
</td>
</tr>
</table>
</td>
</tr>
<tr class="style23">
<td align="right" class="style22">
Gender:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</td>

<td align="left" class="style22">


<asp:RadioButton ID="rdMale" runat="server"
style="color: #000000"
Text="Male" />
&nbsp;&nbsp;
<asp:RadioButton ID="rdFemale" runat="server"
style="color: #000000"
Text="Female" />
</td>

</tr>
<tr>
<td align="right" class="style19">&nbsp; Address:</td>
<td class="style23">
<asp:TextBox ID="txtAddress" runat="server"
Height="44px" TextMode="MultiLine"
ValidationGroup="add" Width="170px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtAddress" ErrorMessage="*"
ValidationGroup="add"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" class="style19">
PhoneNo:</td>
<td class="style23">
<asp:TextBox ID="txtPhoneno" runat="server"
Height="25px"
Width="150px"
ValidationGroup="add"></asp:TextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtPhoneno"
ErrorMessage="*" ValidationExpression="\d{10}"

ValidationGroup="add"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td align="right" class="style19">
Date Of Reg:</td>
<td style="color: #FF0000">
<span class="style23">
<asp:TextBox ID="txtDate" runat="server"
Height="26px" ValidationGroup="add"
Width="150px"></asp:TextBox>
</span>
<cc1:CalendarExtender ID="CalendarExtender1"
runat="server"
TargetControlID="txtDate">
</cc1:CalendarExtender>
<span>e.g (dd/mm/yyyy)</span></td>
</tr>
<tr>
<td align="right" class="style19">
EmailId:</td>
<td>
<span class="style23">
<asp:TextBox ID="txtEmail" runat="server"
Height="24px" ValidationGroup="add"
Width="150px"></asp:TextBox>
<asp:RegularExpressionValidator
ID="RegularExpressionValidator2" runat="server"
ControlToValidate="txtEmail" ErrorMessage="*"
ValidationExpression="\w+([-+.']\w+)*@\w+
([-.]\w+)*\.\w+([-.]\w+)*"

ValidationGroup="add"></asp:RegularExpressionValidator>
</span>
<br class="style23" />
<span>e.g (ab.ab@mail.com)</span></td>
</tr>
<tr>
<td align="right" class="style19">
Qualification:</td>
<td class="style23">
<asp:DropDownList ID="ddlQualification"
runat="server" Height="20px"
ValidationGroup="add" Width="100px">
<asp:ListItem>---Select---</asp:ListItem>
<asp:ListItem>Bi.P.C</asp:ListItem>
<asp:ListItem>M.Pharmse</asp:ListItem>
<asp:ListItem>B.Pharmce</asp:ListItem>
<asp:ListItem>D.Pharmace</asp:ListItem>
<asp:ListItem>Bio Technology</asp:ListItem>
<asp:ListItem>M.Sc Chemestry</asp:ListItem>
<asp:ListItem>M.Sc Zoovolagy</asp:ListItem>
<asp:ListItem>B.Sc</asp:ListItem>
<asp:ListItem>Madicin</asp:ListItem>
<asp:ListItem>M.Sc Bio.Tech</asp:ListItem>
<asp:ListItem>Agriculture B.Sc</asp:ListItem>
<asp:ListItem>Organic Chemistry</asp:ListItem>
<asp:ListItem>MCA</asp:ListItem>
<asp:ListItem>MBA</asp:ListItem>
<asp:ListItem>Other</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator3" runat="server"
ControlToValidate="ddlQualification"
ErrorMessage="*" ValidationGroup="add"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" class="style18">
<span class="style23">Experience:</span></td>
<td>
<table>
<tr>
<td align="right" class="style14">
Yrs</span></td>
<td class="style15">
<asp:DropDownList ID="ddlyrs"
runat="server" ValidationGroup="add">
<asp:ListItem>---Select---
</asp:ListItem>
<asp:ListItem>0</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
</asp:DropDownList>
</td>
<td align="right" class="style16">
Mths</td>
<td class="style17">
<asp:DropDownList ID="ddlMnths"
runat="server" ValidationGroup="add">
<asp:ListItem>---Select---
</asp:ListItem>
<asp:ListItem>0</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right" class="style19">
Designation:</td>
<td class="style23">
<asp:TextBox ID="txtDesignation" runat="server"
Height="23px"
ValidationGroup="add"
Width="150px"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right" class="style19">
Photo:</td>
<td class="style23">
<asp:FileUpload ID="FileUpload1" runat="server"
Width="227px" />
</td>
</tr>
<tr>
<td align="right" class="style18">
&nbsp;</td>
<td>
<asp:ScriptManager ID="ScriptManager1"
runat="server">
</asp:ScriptManager>
</td>
</tr>

<tr>
<td align="left" class="style13" colspan="2">
<span class="style25">Enter Login
Details:</span><span class="style26">(*)Mandatory
Fields</span></td>
</tr>
<tr>

<td align="right" class="style19">


Choose Type:</td>
<td>
<asp:DropDownList ID="ddlType" runat="server"
Height="16px"
ValidationGroup="add" Width="100px">
<asp:ListItem>---Select---</asp:ListItem>
<asp:ListItem>Distributor</asp:ListItem>
<asp:ListItem>Retailor</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator4" runat="server"
ControlToValidate="ddlType" ErrorMessage="*"
ValidationGroup="add"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" class="style20">
User Name:</td>
<td>
<asp:TextBox ID="txtUserName" runat="server"
Height="22px"
ValidationGroup="add"
Width="150px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator5" runat="server"
ControlToValidate="txtUserName"
ErrorMessage="*" ValidationGroup="add"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" class="style18">
</td>
<td>
<asp:Button ID="btnCheck" runat="server"
ForeColor="Red"
onclick="btnCheck_Click" Text="Check
Availability" Width="116px" />
<asp:Label ID="Label1" runat="server" Text="Label"
Visible="False"></asp:Label>
</td>
</tr>
<tr>
<td align="right" class="style21">Password: </td>
<td>
<asp:TextBox ID="txtPassword" runat="server"
Height="22px" TextMode="Password"
ValidationGroup="add" Width="150px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator6" runat="server"
ControlToValidate="txtPassword" ErrorMessage="*"
ValidationGroup="add"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" class="style20">Confirm Password:</td>
<td>
<asp:TextBox ID="txtCpassword" runat="server"
Height="23px" Width="150px"
ValidationGroup="add"
TextMode="Password"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1"
runat="server"
ControlToCompare="txtPassword"
ControlToValidate="txtCpassword"
ErrorMessage="Pwd Mismatch"
ValidationGroup="add"></asp:CompareValidator>
</td>
</tr>
<tr>
<td align="right" class="style21">Choose Security
Qtn:</td>
<td>
<asp:DropDownList ID="ddlQuestion" runat="server"
Height="16px"
ValidationGroup="add" Width="150px">
<asp:ListItem>---Select---</asp:ListItem>
<asp:ListItem>What is ur first Phone no?
</asp:ListItem>
<asp:ListItem>First Crush?</asp:ListItem>
<asp:ListItem>Favourite Actor?</asp:ListItem>
<asp:ListItem>Favourite Sports?</asp:ListItem>
<asp:ListItem>Favourite Cricketer?</asp:ListItem>
<asp:ListItem>Favourite Novel?</asp:ListItem>
<asp:ListItem>School Teacher?</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator7" runat="server"
ControlToValidate="ddlQuestion" ErrorMessage="*"
ValidationGroup="add"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" class="style20">Answer:</td>
<td>
<asp:TextBox ID="txtAnswer" runat="server"
Height="23px" ValidationGroup="add"
Width="150px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator8" runat="server"
ControlToValidate="txtAnswer" ErrorMessage="*"
ValidationGroup="add"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblResult" runat="server"
ForeColor="Red" Visible="False"></asp:Label>
</td>
<td>
<asp:Button ID="btnRegister" runat="server" Font-
Bold="True" ForeColor="Red"
onclick="btnRegister_Click" Text="Register"
ValidationGroup="add"
Width="82px" />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="btnCancel" runat="server" Font-
Bold="True" ForeColor="Red"
onclick="btnCancel_Click" Text="Cancel" />
</td>
</tr>

</table>
</asp:Panel>
</td>
</tr>
</table>
<p>
</p>
</asp:Content>
Registration page Code Behind:
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;

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


{
clsRegistration objReg = new clsRegistration();
byte[] imageSize;
string id, msg;
int RoleId;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
protected void btnRegister_Click(object sender, EventArgs e)
{
//string id;
//int RoleId;
try
{
id = objReg.GeneratiDorRId();
}
catch (Exception er)
{
lblResult.Visible = true;
lblResult.Text = er.Message;
}
try
{
RoleId = objReg.GetRoleId(ddlType.SelectedItem.ToString());
}
catch (Exception er)
{
lblResult.Visible = true;
lblResult.Text = er.Message;
}
//txtId.Text = id;
objReg.DorRid = id;
objReg.Firstname = txtFname.Text;
objReg.LastName = txtLname.Text;
objReg.Address = txtAddress.Text;
objReg.Phoneno = txtPhoneno.Text;
objReg.Email = txtEmail.Text;
objReg.Qualification = ddlQualification.SelectedItem.ToString();
objReg.DORegistration = Convert.ToDateTime(txtDate.Text);
objReg.Experience = ddlyrs.SelectedItem.ToString() + "Yrs" +
ddlMnths.SelectedItem.ToString() + "Mths";
objReg.Designation = txtDesignation.Text;
objReg.Status = "Not Registered";
objReg.RoleId = RoleId;
if (rdMale.Checked)
objReg.Gender = rdMale.Text;
else
objReg.Gender = rdFemale.Text;
if (txtUserName.Text.Contains("@"))
objReg.UserName = txtUserName.Text.Trim();
else
objReg.UserName = (txtUserName.Text + "@webpharms.com").Trim();
objReg.Password = txtPassword.Text;
objReg.CPassword = txtCpassword.Text;
objReg.HintQtn = ddlQuestion.SelectedItem.ToString();
objReg.Answer = txtAnswer.Text;
if (FileUpload1.PostedFile != null &&
FileUpload1.PostedFile.FileName != "")
{
imageSize = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile image1 = FileUpload1.PostedFile;
image1.InputStream.Read(imageSize, 0,
(int)FileUpload1.PostedFile.ContentLength);
}
try
{
int i = objReg.InsertData(imageSize);
if (i > 0)
{
lblResult.Visible = true;
lblResult.Text = "Remember Your Registration Id For Furhter
Reference i.e:" + id.ToString();
}
}
catch (Exception er)
{
lblResult.Visible = true;
lblResult.Text = er.Message;
}
}
protected void btnCancel_Click(object sender, EventArgs e)
{
txtAddress.Text = "";
txtAnswer.Text = "";
txtCpassword.Text = "";
txtPassword.Text = "";
txtPhoneno.Text = "";
txtUserName.Text = "";
txtFname.Text = "";
txtLname.Text = "";
txtPhoneno.Text = "";
txtEmail.Text = "";
txtDesignation.Text = "";
txtDate.Text = "";
ddlMnths.SelectedIndex = 0;
ddlQualification.SelectedIndex = 0;
ddlQuestion.SelectedIndex = 0;
ddlType.SelectedIndex = 0;
ddlyrs.SelectedIndex = 0;
Label1.Visible = false;
lblResult.Visible = false;

}
protected void btnCheck_Click(object sender, EventArgs e)
{
try
{
if (txtUserName.Text.Contains("@"))
objReg.UserName = txtUserName.Text.Trim();
else
objReg.UserName = (txtUserName.Text +
"@webpharms.com").Trim();
objReg.CheckUserAvailability(out msg);
Label1.Visible = true;
Label1.Text = msg;
}
catch (Exception er)
{
Label1.Visible = true;
Label1.Text = er.Message;
}
}
}

Registration page Business Logic(class):

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 E–Pharmaceuticals.DAL;
using System.Data.SqlClient;

/// <summary>
/// Summary description for clsRegistration
/// </summary>
public class clsRegistration
{
public clsRegistration()
{
//
// TODO: Add constructor logic here
//
}
string _DorRid, _FirstName, _LastName, _Address, _PhoneNo,_Email,
_Qualification,_Gender;
string
_Experience,_Designation,_status,_UserName,_Password,_Cpassword,_HintQtn,_Answ
er;
DateTime _DORegistration;
byte[] _Image;
int _RoleId;
public string DorRid
{
get { return _DorRid; }
set { _DorRid = value; }
}
public string Firstname
{
get { return _FirstName; }
set { _FirstName = value; }
}
public string LastName
{
get { return _LastName; }
set { _LastName = value; }
}
public string Address
{
get { return _Address; }
set { _Address = value; }
}
public string Phoneno
{
get { return _PhoneNo; }
set { _PhoneNo = value; }
}
public string Email
{
get { return _Email; }
set { _Email = value; }
}
public string Qualification
{
get { return _Qualification; }
set { _Qualification = value; }
}
public string Gender
{
get { return _Gender; }
set { _Gender = value; }
}
public string Experience
{
get { return _Experience; }
set { _Experience = value; }
}
public string Designation
{
get { return _Designation; }
set { _Designation = value; }
}
public string Status
{
get { return _status; }
set { _status = value; }
}
public string UserName
{
get { return _UserName; }
set { _UserName = value; }
}
public string Password
{
get { return _Password; }
set { _Password = value; }
}
public string CPassword
{
get { return _Cpassword; }
set { _Cpassword = value; }
}
public string HintQtn
{
get { return _HintQtn; }
set { _HintQtn = value; }
}
public string Answer
{
get { return _Answer; }
set { _Answer = value; }
}
public DateTime DORegistration
{
get { return _DORegistration; }
set { _DORegistration = value; }
}
public byte[] Image
{
get { return _Image; }
set { _Image = value; }
}
public int RoleId
{
get { return _RoleId; }
set { _RoleId = value; }
}

//Auto Generation Record Ids


public string GeneratiDorRId()
{
try
{
//DataSet ds = dac.GetEmpId();
DataSet ds = SqlHelper.ExecuteDataset(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_GetDorRId");
DataTable dt = new DataTable();
//dt = ds.Tables["tblRegistration"];
dt = ds.Tables[0];
int id = dt.Rows.Count;
string nid = null;
string nid1;
int nid2;

if (id < 0)
{
nid = "R0001";
}
else
{
nid1 = Convert.ToString(dt.Rows[id-1][0]);

if (id >= 0 && id < 9)


{
//nid1 = Convert.ToString(dt.Rows[0][id]);
nid2 = Convert.ToInt32(nid1.Substring(1, 4).ToString());
nid2 = nid2 + 1;
nid = "R000" + nid2;
}
else if (id >= 9 && id < 99)
{
//nid1 = Convert.ToString(dt.Rows[0][id]);
nid2 = Convert.ToInt32(nid1.Substring(1, 4).ToString());
nid2 = nid2 + 1;
nid = "R00" + nid2;
}
else if (id >= 99 && id < 999)
{
//nid1 = Convert.ToString(dt.Rows[0][id]);
nid2 = Convert.ToInt32(nid1.Substring(1, 4).ToString());
nid2 = nid2 + 1;
nid = "R0" + nid2;
}
else
{
//nid1 = Convert.ToString(dt.Rows[0][id]);
nid2 = Convert.ToInt32(nid1.Substring(1, 4).ToString());
nid2 = nid2 + 1;
nid = "R" + nid2;

}
return nid;
}
catch (ArgumentException er)
{
throw new ArgumentException(er.Message);
}
}
//Getting RoleId
public int GetRoleId(string RoleType)
{
try
{
SqlParameter[] p = new SqlParameter[1];
p[0] = new SqlParameter("@RoleType", RoleType);
int id =
Convert.ToInt32(SqlHelper.ExecuteScalar(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_GetRoleId", p));
return id;
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Insert Data into Registration and Login Table


public int InsertData(byte [] image)
{
try
{
SqlParameter[] p = new SqlParameter[19];
p[0] = new SqlParameter("@DorRId", _DorRid);
p[1] = new SqlParameter("@FirstName", _FirstName);
p[2] = new SqlParameter("@LastName", _LastName);
p[3] = new SqlParameter("@Gender", _Gender);
p[4] = new SqlParameter("@Address", _Address);
p[5] = new SqlParameter("@PhoneNo", _PhoneNo);
p[6] = new SqlParameter("@DoRegistration", _DORegistration);
p[7] = new SqlParameter("@Email", _Email);
p[8] = new SqlParameter("@Qualification", _Qualification);
p[9] = new SqlParameter("@Experience", _Experience);
p[10] = new SqlParameter("@Designation", _Designation);
p[11] = new SqlParameter("@photo", image);
p[12] = new SqlParameter("@status", _status);
p[13] = new SqlParameter("@Username", _UserName);
p[14] = new SqlParameter("@RoleId", _RoleId);
p[15] = new SqlParameter("@password", _Password);
p[16] = new SqlParameter("@Cpassword", _Cpassword);
p[17] = new SqlParameter("@HintQtn", _HintQtn);
p[18] = new SqlParameter("@Answer", _Answer);
return SqlHelper.ExecuteNonQuery(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_InsertRegistration", p);

}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Check Username Availability


public void CheckUserAvailability(out string msg)
{
try
{
SqlParameter[] p = new SqlParameter[2];
p[0] = new SqlParameter("@UserName", _UserName);
p[1] = new SqlParameter("@Message",SqlDbType.VarChar,50);
p[1].Direction = ParameterDirection.Output;
//msg = p[1].Value;
SqlHelper.ExecuteNonQuery(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_CheckAvailabilityUserName", p);
msg = Convert.ToString(p[1].Value);
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Checking login authentication


public int CheckloginAuthentication(out string id, out string Rtype)
{
try
{
SqlParameter[] p = new SqlParameter[6];
p[0] = new SqlParameter("@UserName", _UserName);
p[1] = new SqlParameter("@Password", _Password);
p[2] = new SqlParameter("@RoleId", SqlDbType.Int);
p[2].Direction = ParameterDirection.Output;
p[3] = new SqlParameter("@RoleType", SqlDbType.VarChar, 25);
p[3].Direction = ParameterDirection.Output;
p[4] = new SqlParameter("@DorRId", SqlDbType.VarChar, 10);
p[4].Direction = ParameterDirection.Output;
p[5] = new SqlParameter("@Msg", SqlDbType.VarChar, 50);
p[5].Direction = ParameterDirection.Output;
SqlHelper.ExecuteNonQuery(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_LoginCheck", p);
id = Convert.ToString(p[4].Value);
Rtype = Convert.ToString(p[3].Value);
string msg = Convert.ToString(p[5].Value);
int rid = Convert.ToInt32(p[2].Value);
if (msg != "")
throw new ArgumentException(msg);
return rid;
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Getting the Password for user if Remember


public void GetPassword(out string pwd)
{
try
{
SqlParameter[] p = new SqlParameter[5];
p[0] = new SqlParameter("@Username", _UserName);
p[1] = new SqlParameter("@Question", _HintQtn);
p[2] = new SqlParameter("@answer", _Answer);
p[3] = new SqlParameter("@Password", SqlDbType.VarChar, 25);
p[3].Direction = ParameterDirection.Output;
p[4] = new SqlParameter("@msg", SqlDbType.VarChar, 50);
p[4].Direction = ParameterDirection.Output;
//p[5] = new SqlParameter("", SqlDbType.VarChar, 50);
//p[5].Direction = ParameterDirection.Output;
SqlHelper.ExecuteNonQuery(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_ForgotPassword", p);
pwd = Convert.ToString(p[3].Value);
string msg = Convert.ToString(p[4].Value);
if (msg != "")
throw new ArgumentException(msg);
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Updating the Password for a perticular user


public void ChangePassword(string oldpwd)
{
try
{
SqlParameter[] p = new SqlParameter[5];
p[0] = new SqlParameter("@Username", _UserName);
p[1] = new SqlParameter("@OldPwd", oldpwd);
p[2] = new SqlParameter("@NewPwd", _Password);
p[3] = new SqlParameter("@Cpwd", _Cpassword);
p[4] = new SqlParameter("@Msg", SqlDbType.VarChar, 50);
p[4].Direction = ParameterDirection.Output;
SqlHelper.ExecuteNonQuery(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_ChangePwd", p);
string msg = Convert.ToString(p[4].Value);
if (msg != "")
throw new ArgumentException(msg);
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Get Registration Details for admin to approve or Reject the profiles


public DataSet GetUnRegesteredProfiles()
{
try
{
SqlParameter[] p = new SqlParameter[2];
p[0] = new SqlParameter("@Status", _status);
p[1] = new SqlParameter("@DorRId", _DorRid);
return SqlHelper.ExecuteDataset(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_GetUnregisteredProfile_Update", p);
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Get Phote for a perticular User


public DataSet GetUserPhoto(string id)
{
try
{
SqlParameter[] p = new SqlParameter[1];
p[0] = new SqlParameter("@DorRId", id);
return SqlHelper.ExecuteDataset(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_GetUserPhoto", p);
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Get Registered id for the perticular Username


public string GetregisterId()
{
try
{
SqlParameter[] p = new SqlParameter[1];
p[0] = new SqlParameter("@UserName", _UserName);
return
Convert.ToString(SqlHelper.ExecuteScalar(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_GetRegisteredId", p));

}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Updating the User Profile Details


public void UpdateProfile()
{
try
{
SqlParameter[] p = new SqlParameter[13];
p[0] = new SqlParameter("@DorRId", _DorRid);
p[1] = new SqlParameter("@FirstName", _FirstName);
p[2] = new SqlParameter("@LastName", _LastName);
p[3] = new SqlParameter("@Gender", _Gender);
p[4] = new SqlParameter("@Address", _Address);
p[5] = new SqlParameter("@PhoneNo", _PhoneNo);
p[6] = new SqlParameter("@DoRegistration", _DORegistration);
p[7] = new SqlParameter("@Email", _Email);
p[8] = new SqlParameter("@Qualification", _Qualification);
p[9] = new SqlParameter("@Experience", _Experience);
p[10] = new SqlParameter("@Designation", _Designation);
p[11] = new SqlParameter("@Photo", _Image);
p[12] = new SqlParameter("@Status", _status);
SqlHelper.ExecuteNonQuery(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_UpdateProfile", p);
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}
}

Registration Table Creation:


USE [dbE–Pharmaceuticals]
GO

/****** Object: Table [dbo].[tblRegistration] Script Date: 11/20/2010


12:28:27 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[tblRegistration](


[DorRId] [varchar](10) NOT NULL,
[FirstName] [varchar](25) NOT NULL,
[LastName] [varchar](25) NOT NULL,
[Gender] [varchar](10) NULL,
[Address] [varchar](200) NOT NULL,
[PhoneNo] [varchar](15) NOT NULL,
[DORegistration] [datetime] NULL,
[Email] [varchar](25) NOT NULL,
[Qualification] [varchar](25) NOT NULL,
[Experience] [varchar](25) NULL,
[Designation] [varchar](25) NULL,
[Photo] [image] NULL,
[status] [varchar](15) NOT NULL,
CONSTRAINT [PK__tblRegistration__7E6CC920] PRIMARY KEY CLUSTERED
(
[DorRId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

SET ANSI_PADDING OFF


GO
USE [dbE–Pharmaceuticals]
GO

/****** Object: Table [dbo].[tblLoginDetails] Script Date: 11/20/2010


12:29:17 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[tblLoginDetails](


[Username] [varchar](35) NOT NULL,
[DorRId] [varchar](10) NULL,
[RoleId] [int] NULL,
[Password] [varchar](25) NOT NULL,
[Cpassword] [varchar](25) NOT NULL,
[HintQtn] [varchar](50) NOT NULL,
[Answer] [varchar](25) NOT NULL,
PRIMARY KEY CLUSTERED
(
[Username] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF


GO

ALTER TABLE [dbo].[tblLoginDetails] WITH CHECK ADD CONSTRAINT


[FK__tblLoginD__DorRI__060DEAE8] FOREIGN KEY([DorRId])
REFERENCES [dbo].[tblRegistration] ([DorRId])
GO

ALTER TABLE [dbo].[tblLoginDetails] CHECK CONSTRAINT


[FK__tblLoginD__DorRI__060DEAE8]
GO

ALTER TABLE [dbo].[tblLoginDetails] WITH CHECK ADD FOREIGN KEY([RoleId])


REFERENCES [dbo].[tblRoleMaster] ([RoleId])
GO

Registration Procedure For Insert Data:


USE [dbE–Pharmaceuticals]
GO
/****** Object: StoredProcedure [dbo].[Sp_InsertRegistration] Script Date:
11/20/2010 12:30:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create procedure [dbo].[Sp_InsertRegistration](
@DorRId varchar(10),
@FirstName varchar(25),
@LastName varchar(25),
@Gender varchar(10),
@Address varchar(200),
@PhoneNo varchar(15),
@DoRegistration datetime,
@Email varchar(25),
@Qualification varchar(25),
@Experience varchar(25),
@Designation varchar(25),
@photo Image=null,
@status varchar(15),
@Username varchar(35),
@RoleId int,
@password varchar(25),
@Cpassword varchar(25),
@HintQtn varchar(50),
@Answer varchar(25))

as

begin

begin transaction
insert into tblRegistration
values(@DorRId,@FirstName,@LastName,@Gender,@Address,@PhoneNo,@DoRegistration,
@Email,
@Qualification,@Experience,@Designation,@photo,@status)

insert into tblLoginDetails


values(@Username,@DorRId,@RoleId,@password,@Cpassword,@HintQtn,@Answer)

commit transaction
end
Login Form:

Login Form Source Code:


<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="frmLogin.aspx.cs" Inherits="frmLogin"
Title="frmLogin" %>

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


<style type="text/css">
.style4
{
width: 100%;
height: 175px;
}
.style5
{
width: 288px;
}
.style6
{
color: #FF0000;
font-weight: bold;
font-size: x-large;
font-style: italic;
}
.style7
{
width: 210px;
}
.style8
{
width: 210px;
font-weight: normal;
color: black;
}
.style9
{
color: #FF33CC;
font-weight: normal;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<p align="center" style="height: 25px">
<span class="style6">Register Users Login Here.....</span><br />
</p>
<table class="style4">
<tr>
<td class="style5">
<img alt="" src="ProjectImages/pharma.jpg"
style="width: 320px; height: 218px" /></td>
<td>
<asp:Panel ID="pnlLogin" runat="server" Font-Bold="True"
ForeColor="Red"
GroupingText="Login" Height="199px">
<table class="style4">
<tr>
<td class="style9" colspan="2">(*)Mandatory Fields</td>
</tr>
<tr>
<td align="right" class="style8">
User Name:</td>
<td>
<asp:TextBox ID="txtUname" runat="server"
Height="24px" Width="150px"
ValidationGroup="a"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtUname"
ErrorMessage="*" ValidationGroup="a"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" class="style8">
Password:</td>
<td>
<asp:TextBox ID="txtPassword" runat="server"
Height="24px" Width="150px"
ValidationGroup="a"
TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtPassword"
ErrorMessage="*" ValidationGroup="a"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right" class="style7">
&nbsp;</td>
<td>
<asp:LinkButton ID="lnkForgot" runat="server"
Font-Bold="False" ForeColor="Red"
onclick="lnkForgot_Click">ForGot
Password</asp:LinkButton>
</td>
</tr>
<tr>
<td align="right" class="style7">
&nbsp;</td>
<td>
<asp:CheckBox ID="chkRemember" runat="server"
Font-Bold="False"
Font-Size="Medium" ForeColor="Black"
style="font-size: small; font-weight: 700"
Text="Remember Me Next Time"
ValidationGroup="a" />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnLogin" runat="server" Font-
Bold="True" ForeColor="Red"
Text="Login" ValidationGroup="a"
onclick="btnLogin_Click" />
<asp:Label ID="lblResult" runat="server"
Visible="False"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
</td>
</tr>
</table>
<p style="height: 102px">
</p>
</asp:Content>
Login Form Code Behind:
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;

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


{
clsRegistration objreg = new clsRegistration();
int RoleId;
string RoleType, Id,msg,username;
protected void Page_Load(object sender, EventArgs e)
{
// ExpirePageCache();
}

protected void btnLogin_Click(object sender, EventArgs e)


{
if (txtUname.Text.Contains("@"))
username = txtUname.Text.Trim();
else
username = (txtUname.Text + "@webpharms.com").Trim();
objreg.UserName = username;
objreg.Password = txtPassword.Text;
//objreg.Password =
FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text,
"sha1");
try
{
RoleId = objreg.CheckloginAuthentication(out Id, out RoleType);
if (RoleType == "Administrator")
{
FormsAuthentication.RedirectFromLoginPage(username,
chkRemember.Checked);
//Session["Username"] = txtUname.Text;
HttpCookie c1 = new HttpCookie("userinfo");
c1.Values.Add("username", txtUname.Text);
c1.Values.Add("DorRId", Id);
Response.Cookies.Add(c1);
Response.Redirect("~/ADMIN/frmAdminHome.aspx?Rtype=" +
RoleType);
}
else if (RoleType == "Distributor")
{
FormsAuthentication.RedirectFromLoginPage(username,
chkRemember.Checked);
HttpCookie c1 = new HttpCookie("userinfo");
c1.Values.Add("username", txtUname.Text);
c1.Values.Add("DorRId", Id);
Response.Cookies.Add(c1);
Response.Redirect("~/DISTRIBUTOR/frmDistributorHome.aspx?
Rtype=" + RoleType);
}
else
{
FormsAuthentication.RedirectFromLoginPage(username,
chkRemember.Checked);
HttpCookie c1 = new HttpCookie("userinfo");
c1.Values.Add("username", txtUname.Text);
c1.Values.Add("DorRId", Id);
Response.Cookies.Add(c1);
Response.Redirect("~/RETAILOR/frmRetailorHome.aspx?Rtype="
+ RoleType);
}
}
//}
catch (Exception er)
{
lblResult.Visible = true;
lblResult.Text = er.Message;
}
}
protected void lnkForgot_Click(object sender, EventArgs e)
{
Response.Redirect("frmForgotPassword.aspx");
}
}

Login Form Business Logic(Class):


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 E–Pharmaceuticals.DAL;
using System.Data.SqlClient;

/// <summary>
/// Summary description for clsRegistration
/// </summary>
public class clsRegistration
{
public clsRegistration()
{
//
// TODO: Add constructor logic here
//
}
string _DorRid, _FirstName, _LastName, _Address, _PhoneNo,_Email,
_Qualification,_Gender;
string
_Experience,_Designation,_status,_UserName,_Password,_Cpassword,_HintQtn,_Answ
er;
DateTime _DORegistration;
byte[] _Image;
int _RoleId;
public string DorRid
{
get { return _DorRid; }
set { _DorRid = value; }
}
public string Firstname
{
get { return _FirstName; }
set { _FirstName = value; }
}
public string LastName
{
get { return _LastName; }
set { _LastName = value; }
}
public string Address
{
get { return _Address; }
set { _Address = value; }
}
public string Phoneno
{
get { return _PhoneNo; }
set { _PhoneNo = value; }
}
public string Email
{
get { return _Email; }
set { _Email = value; }
}
public string Qualification
{
get { return _Qualification; }
set { _Qualification = value; }
}
public string Gender
{
get { return _Gender; }
set { _Gender = value; }
}
public string Experience
{
get { return _Experience; }
set { _Experience = value; }
}
public string Designation
{
get { return _Designation; }
set { _Designation = value; }
}
public string Status
{
get { return _status; }
set { _status = value; }
}
public string UserName
{
get { return _UserName; }
set { _UserName = value; }
}
public string Password
{
get { return _Password; }
set { _Password = value; }
}
public string CPassword
{
get { return _Cpassword; }
set { _Cpassword = value; }
}
public string HintQtn
{
get { return _HintQtn; }
set { _HintQtn = value; }
}
public string Answer
{
get { return _Answer; }
set { _Answer = value; }
}
public DateTime DORegistration
{
get { return _DORegistration; }
set { _DORegistration = value; }
}
public byte[] Image
{
get { return _Image; }
set { _Image = value; }
}
public int RoleId
{
get { return _RoleId; }
set { _RoleId = value; }
}

//Auto Generation Record Ids


public string GeneratiDorRId()
{
try
{
//DataSet ds = dac.GetEmpId();
DataSet ds = SqlHelper.ExecuteDataset(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_GetDorRId");
DataTable dt = new DataTable();
//dt = ds.Tables["tblRegistration"];
dt = ds.Tables[0];
int id = dt.Rows.Count;
string nid = null;
string nid1;
int nid2;

if (id < 0)
{
nid = "R0001";
}
else
{
nid1 = Convert.ToString(dt.Rows[id-1][0]);

if (id >= 0 && id < 9)


{
//nid1 = Convert.ToString(dt.Rows[0][id]);
nid2 = Convert.ToInt32(nid1.Substring(1, 4).ToString());
nid2 = nid2 + 1;
nid = "R000" + nid2;
}
else if (id >= 9 && id < 99)
{
//nid1 = Convert.ToString(dt.Rows[0][id]);
nid2 = Convert.ToInt32(nid1.Substring(1, 4).ToString());
nid2 = nid2 + 1;
nid = "R00" + nid2;
}
else if (id >= 99 && id < 999)
{
//nid1 = Convert.ToString(dt.Rows[0][id]);
nid2 = Convert.ToInt32(nid1.Substring(1, 4).ToString());
nid2 = nid2 + 1;
nid = "R0" + nid2;
}
else
{
//nid1 = Convert.ToString(dt.Rows[0][id]);
nid2 = Convert.ToInt32(nid1.Substring(1, 4).ToString());
nid2 = nid2 + 1;
nid = "R" + nid2;

}
return nid;
}
catch (ArgumentException er)
{
throw new ArgumentException(er.Message);
}
}
//Getting RoleId
public int GetRoleId(string RoleType)
{
try
{
SqlParameter[] p = new SqlParameter[1];
p[0] = new SqlParameter("@RoleType", RoleType);
int id =
Convert.ToInt32(SqlHelper.ExecuteScalar(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_GetRoleId", p));
return id;
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Insert Data into Registration and Login Table


public int InsertData(byte [] image)
{
try
{
SqlParameter[] p = new SqlParameter[19];
p[0] = new SqlParameter("@DorRId", _DorRid);
p[1] = new SqlParameter("@FirstName", _FirstName);
p[2] = new SqlParameter("@LastName", _LastName);
p[3] = new SqlParameter("@Gender", _Gender);
p[4] = new SqlParameter("@Address", _Address);
p[5] = new SqlParameter("@PhoneNo", _PhoneNo);
p[6] = new SqlParameter("@DoRegistration", _DORegistration);
p[7] = new SqlParameter("@Email", _Email);
p[8] = new SqlParameter("@Qualification", _Qualification);
p[9] = new SqlParameter("@Experience", _Experience);
p[10] = new SqlParameter("@Designation", _Designation);
p[11] = new SqlParameter("@photo", image);
p[12] = new SqlParameter("@status", _status);
p[13] = new SqlParameter("@Username", _UserName);
p[14] = new SqlParameter("@RoleId", _RoleId);
p[15] = new SqlParameter("@password", _Password);
p[16] = new SqlParameter("@Cpassword", _Cpassword);
p[17] = new SqlParameter("@HintQtn", _HintQtn);
p[18] = new SqlParameter("@Answer", _Answer);
return SqlHelper.ExecuteNonQuery(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_InsertRegistration", p);

}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Check Username Availability


public void CheckUserAvailability(out string msg)
{
try
{
SqlParameter[] p = new SqlParameter[2];
p[0] = new SqlParameter("@UserName", _UserName);
p[1] = new SqlParameter("@Message",SqlDbType.VarChar,50);
p[1].Direction = ParameterDirection.Output;
//msg = p[1].Value;
SqlHelper.ExecuteNonQuery(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_CheckAvailabilityUserName", p);
msg = Convert.ToString(p[1].Value);
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Checking login authentication


public int CheckloginAuthentication(out string id, out string Rtype)
{
try
{
SqlParameter[] p = new SqlParameter[6];
p[0] = new SqlParameter("@UserName", _UserName);
p[1] = new SqlParameter("@Password", _Password);
p[2] = new SqlParameter("@RoleId", SqlDbType.Int);
p[2].Direction = ParameterDirection.Output;
p[3] = new SqlParameter("@RoleType", SqlDbType.VarChar, 25);
p[3].Direction = ParameterDirection.Output;
p[4] = new SqlParameter("@DorRId", SqlDbType.VarChar, 10);
p[4].Direction = ParameterDirection.Output;
p[5] = new SqlParameter("@Msg", SqlDbType.VarChar, 50);
p[5].Direction = ParameterDirection.Output;
SqlHelper.ExecuteNonQuery(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_LoginCheck", p);
id = Convert.ToString(p[4].Value);
Rtype = Convert.ToString(p[3].Value);
string msg = Convert.ToString(p[5].Value);
int rid = Convert.ToInt32(p[2].Value);
if (msg != "")
throw new ArgumentException(msg);
return rid;
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Getting the Password for user if Remember


public void GetPassword(out string pwd)
{
try
{
SqlParameter[] p = new SqlParameter[5];
p[0] = new SqlParameter("@Username", _UserName);
p[1] = new SqlParameter("@Question", _HintQtn);
p[2] = new SqlParameter("@answer", _Answer);
p[3] = new SqlParameter("@Password", SqlDbType.VarChar, 25);
p[3].Direction = ParameterDirection.Output;
p[4] = new SqlParameter("@msg", SqlDbType.VarChar, 50);
p[4].Direction = ParameterDirection.Output;
//p[5] = new SqlParameter("", SqlDbType.VarChar, 50);
//p[5].Direction = ParameterDirection.Output;
SqlHelper.ExecuteNonQuery(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_ForgotPassword", p);
pwd = Convert.ToString(p[3].Value);
string msg = Convert.ToString(p[4].Value);
if (msg != "")
throw new ArgumentException(msg);
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Updating the Password for a perticular user


public void ChangePassword(string oldpwd)
{
try
{
SqlParameter[] p = new SqlParameter[5];
p[0] = new SqlParameter("@Username", _UserName);
p[1] = new SqlParameter("@OldPwd", oldpwd);
p[2] = new SqlParameter("@NewPwd", _Password);
p[3] = new SqlParameter("@Cpwd", _Cpassword);
p[4] = new SqlParameter("@Msg", SqlDbType.VarChar, 50);
p[4].Direction = ParameterDirection.Output;
SqlHelper.ExecuteNonQuery(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_ChangePwd", p);
string msg = Convert.ToString(p[4].Value);
if (msg != "")
throw new ArgumentException(msg);
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Get Registration Details for admin to approve or Reject the profiles


public DataSet GetUnRegesteredProfiles()
{
try
{
SqlParameter[] p = new SqlParameter[2];
p[0] = new SqlParameter("@Status", _status);
p[1] = new SqlParameter("@DorRId", _DorRid);
return SqlHelper.ExecuteDataset(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_GetUnregisteredProfile_Update", p);
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Get Phote for a perticular User


public DataSet GetUserPhoto(string id)
{
try
{
SqlParameter[] p = new SqlParameter[1];
p[0] = new SqlParameter("@DorRId", id);
return SqlHelper.ExecuteDataset(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_GetUserPhoto", p);
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Get Registered id for the perticular Username


public string GetregisterId()
{
try
{
SqlParameter[] p = new SqlParameter[1];
p[0] = new SqlParameter("@UserName", _UserName);
return
Convert.ToString(SqlHelper.ExecuteScalar(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_GetRegisteredId", p));

}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}

//Updating the User Profile Details


public void UpdateProfile()
{
try
{
SqlParameter[] p = new SqlParameter[13];
p[0] = new SqlParameter("@DorRId", _DorRid);
p[1] = new SqlParameter("@FirstName", _FirstName);
p[2] = new SqlParameter("@LastName", _LastName);
p[3] = new SqlParameter("@Gender", _Gender);
p[4] = new SqlParameter("@Address", _Address);
p[5] = new SqlParameter("@PhoneNo", _PhoneNo);
p[6] = new SqlParameter("@DoRegistration", _DORegistration);
p[7] = new SqlParameter("@Email", _Email);
p[8] = new SqlParameter("@Qualification", _Qualification);
p[9] = new SqlParameter("@Experience", _Experience);
p[10] = new SqlParameter("@Designation", _Designation);
p[11] = new SqlParameter("@Photo", _Image);
p[12] = new SqlParameter("@Status", _status);
SqlHelper.ExecuteNonQuery(clsConnection.connection(),
CommandType.StoredProcedure, "Sp_UpdateProfile", p);
}
catch (Exception er)
{
throw new ArgumentException(er.Message);
}
}
}

Login Table Creation:


USE [dbE–Pharmaceuticals]
GO

/****** Object: Table [dbo].[tblLoginDetails] Script Date: 11/20/2010


12:29:17 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[tblLoginDetails](


[Username] [varchar](35) NOT NULL,
[DorRId] [varchar](10) NULL,
[RoleId] [int] NULL,
[Password] [varchar](25) NOT NULL,
[Cpassword] [varchar](25) NOT NULL,
[HintQtn] [varchar](50) NOT NULL,
[Answer] [varchar](25) NOT NULL,
PRIMARY KEY CLUSTERED
(
[Username] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF


GO

ALTER TABLE [dbo].[tblLoginDetails] WITH CHECK ADD CONSTRAINT


[FK__tblLoginD__DorRI__060DEAE8] FOREIGN KEY([DorRId])
REFERENCES [dbo].[tblRegistration] ([DorRId])
GO

ALTER TABLE [dbo].[tblLoginDetails] CHECK CONSTRAINT


[FK__tblLoginD__DorRI__060DEAE8]
GO
ALTER TABLE [dbo].[tblLoginDetails] WITH CHECK ADD FOREIGN KEY([RoleId])
REFERENCES [dbo].[tblRoleMaster] ([RoleId])
GO

Login Procedure to Check Login:


USE [dbE–Pharmaceuticals]
GO
/****** Object: StoredProcedure [dbo].[Sp_LoginCheck] Script Date:
11/20/2010 12:36:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create procedure [dbo].[Sp_LoginCheck](
@UserName varchar(25),
@Password varchar(25),
@RoleId int out,
@RoleType varchar(25) out,
@DorRId varchar(10) out,
@Msg varchar(50) out)

as

begin
declare @Status varchar(25)

set @DorRId=(select DorRId from tblLoginDetails where UserName=@UserName and


Password=@Password)

if @DorRId is null
begin
set @RoleType=0
set @RoleId=0
set @Msg='User Name or Pwd Incorrect'
end

else

begin
set @Status=(select status from tblRegistration where DorRId=@DorRId)
if @Status = 'Registered'
begin
set @RoleId=(select RoleId from tblLoginDetails where UserName=@UserName and
Password=@Password)
set @RoleType=(select RoleType from tblRolemaster where RoleId=@RoleId)
end
else
begin
set @RoleId=(select RoleId from tblLoginDetails where UserName=@UserName and
Password=@Password)
set @RoleType=(select RoleType from tblRolemaster where RoleId=@RoleId)
set @Msg='Still ur Profile is in Pending'
end
end

end

Potrebbero piacerti anche