Thursday, 19 December 2013

How to create Registration Form in ASP.NET with AJAX

// Put AjaxControlToolkit.dll in bin folder


 //// **************************************************////
//Inline Model

 //// **************************************************////





<%@ Page Language="C#" AutoEventWireup="true" CodeFile="regform.aspx.cs" Inherits="regform" %>
<%@ Register Src="~/Usercontrol/home2.ascx" TagName="head2" TagPrefix="ctl" %>
<%@ Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"%>
<!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></title>
    <link href="STYLE/Style.css" type="text/css" rel="stylesheet" />
       <link href="testimg/ddlevelsmenu-base.css"  type="text/css"  rel="stylesheet" />
<link href="testimg/ddlevelsmenu-topbar.css"  type="text/css" rel="stylesheet" />
<link href="testimg/ddlevelsmenu-sidebar.css"  type="text/css" rel="stylesheet" />
<script src="testimg/ddlevelsmenu.js" type="text/javascript"></script>
<script src="js/formValidator.js" type ="text/javascript"></script>
  <link href="STYLE/styleh.css" type="text/css" rel="stylesheet" />

    <style type="text/css">
        .style1
        {
            height: 54px;
        }
    </style>

</head>
<body >
    <form id="form1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnableScriptGlobalization ="true" EnableScriptLocalization="true"></asp:ToolkitScriptManager>
     <table id="td1" align="center"  class="tbl" style="background-image:url(image/ms1.gif);background-repeat:repeat;  width:900px;">
       <tr>
       <td colspan="2"><ctl:head2 ID="ctlhead" runat="server" /></td>
     
       </tr>
       <tr>
       <td colspan="2"></td>

       </tr>
       <tr>
        <td style="width:550px";>
            &nbsp;</td>
     <%--   -------------------body part------------------%>
        <td>
       
        <table  style="background-image:url(p_image/ms1.gif); background-repeat:no-repeat;  background-repeat:repeat-x; width:500px;" >
   <tr><td align="center" colspan="2"></td></tr>
   <tr><td colspan="2" align="left"><hr /><b>Name </b><hr /> </td></tr>
   <tr><td align="left" class="style1">
  
   <asp:TextBox ID="TextBoxfirstname" CssClass="unwatermarked" Width="150" Height="20" runat="server" /> <br/>
<%--<asp:RequiredFieldValidator ID="RequiredFieldValidatorfirstname" runat="server" Display='None' SetFocusOnError="true" ErrorMessage="Enter your First Name" ControlToValidate="TextBoxfirstname"></asp:RequiredFieldValidator>--%>
                <asp:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" runat="server"

                    TargetControlID="TextBoxfirstname"

                    WatermarkText=" First Name"

                    WatermarkCssClass="watermarked" />

           </td>
          
          
           <td align="left">

    <asp:TextBox ID="Textboxlastname" CssClass="unwatermarked" Width="130" Height="20" runat="server" />
<%--<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display='None' SetFocusOnError="true" ErrorMessage="Enter your First Name" ControlToValidate="Textboxlastname"></asp:RequiredFieldValidator>--%>
                <asp:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender2" runat="server"

                    TargetControlID="Textboxlastname"

                    WatermarkText="Last Name"

                    WatermarkCssClass="watermarked" />
   </td></tr>
   <tr><td colspan="2" align="left"><br /><b><hr />Enter E-Mail Id</b><hr /></td></tr>
   <tr><td colspan="2" align="left"><asp:TextBox ID="Textboxemailid" CssClass="unwatermarked" Width="250" Height="20" runat="server" />
<%--<asp:RequiredFieldValidator ID="requiredfieldvalidatoremailid" runat="server" ErrorMessage="Enter E-mail Id" Display='None' ControlToValidate="Textboxemailid"></asp:RequiredFieldValidator>
    <asp:RegularExpressionValidator ID="regularexpressionvalidatoremailid" runat="server"  ValidationExpression ="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="Enter valid Id" Display='None' ControlToValidate="Textboxemailid"></asp:RegularExpressionValidator>--%>
                <asp:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender3" runat="server"

                    TargetControlID="Textboxemailid"

                    WatermarkText="Enter Only Username"

                    WatermarkCssClass="watermarked" /><font size="3"><b>@xyz.com</b></font><br />
      
       <br /></td></tr>
      
      
                    <tr><td style="width:200px;" ><asp:ImageButton ID="btnCheck" runat="server"
                            ImageUrl="~/IMAGE/button-check-availability.png" onclick="btnCheck_Click" /></td><td><asp:Label ID="lblemail" Font-Bold="true" ForeColor="Green" runat="server"></asp:Label><asp:Label ID="lblmsg2" Font-Bold="true" ForeColor="Red" runat="server"></asp:Label></td></tr>
                   
                   
                   
                     <tr><td colspan="2" align="left"><hr /><b>Create your password  </b><hr /></td></tr>
                      <tr><td colspan="2" align="left">
                      <asp:TextBox ID="Textboxpassword"  Width="150" CssClass="pass" Height="20" runat="server" TextMode="Password"/>
                  <%--   <asp:RequiredFieldValidator ID="Requiredfieldvalidatorpassword" runat="server" ErrorMessage="Enter Password" Display='None' ControlToValidate="Textboxpassword"></asp:RequiredFieldValidator>--%>
                      <asp:PasswordStrength ID="pwdStrength" TargetControlID="Textboxpassword"
                      Enabled="True"  DisplayPosition="RightSide"
                      PrefixText="Strength:" TextStrengthDescriptions="Poor;Weak;Average;Good;Excellent"  runat="server"/>
                     
                        <asp:Label ID="Label1" runat="server"></asp:Label><br />
                       <font color="blue" size="2" align="left"> <b>Enter more then 8 character.</b></font>
                        <br /><br />
                      </td></tr>
                      <tr><td colspan="2" align="left"><hr /><b>Confirm your password  </b><hr /></td></tr>
                     <tr><td colspan="2" align="left">  <asp:TextBox ID="textconformpassword"  Width="150" Height="20" runat="server" TextMode="Password"/>
                    
                    <%-- <asp:RequiredFieldValidator ID="Requiredvalidator7" runat="server" ErrorMessage="Enter password" Display='None' ControlToValidate="textconformpassword"></asp:RequiredFieldValidator>
    <asp:CompareValidator ID="comparevalidator1" runat="server" ErrorMessage="Enter same password" Display='None'  ControlToValidate="textconformpassword" ControlToCompare="Textboxpassword"></asp:CompareValidator>--%>
                      <br /><br /></td></tr>
   <br /><br />
    <tr><td colspan="2" align="left"><hr /><b>Gender  </b><hr /></td></tr>
    <tr><td  align="left"><asp:DropDownList ID="ddlgender" runat="server" Width="150" >
                                <asp:ListItem value="Sex">Sex</asp:ListItem>
                                <asp:ListItem value="Male">Male</asp:ListItem>
                                <asp:ListItem value="Female">Female</asp:ListItem>
                             
                               
                               
                                </asp:DropDownList>
                                   <br /><br /></td></tr>
                               
    <tr><td colspan="2" align="left"><hr /><b>Birthday </b><hr /></td></tr>
    <tr><td align="left" colspan="2">
         <table><tr>
         <td>
          M<asp:DropDownList ID="ddlMonth" runat='server' Width="80" Height="20">
         <asp:ListItem Text="MM" Value="0"></asp:ListItem>
          <asp:ListItem Text="01" Value="1"></asp:ListItem>
          <asp:ListItem Text="02" Value="2"></asp:ListItem>
          <asp:ListItem Text="03" Value="3"></asp:ListItem>
          <asp:ListItem Text="04" Value="4"></asp:ListItem>
          <asp:ListItem Text="05" Value="5"></asp:ListItem>
          <asp:ListItem Text="06" Value="6"></asp:ListItem>
          <asp:ListItem Text="07" Value="7"></asp:ListItem>
          <asp:ListItem Text="08" Value="8"></asp:ListItem>
          <asp:ListItem Text="09" Value="9"></asp:ListItem>
          <asp:ListItem Text="10" Value="10"></asp:ListItem>
          <asp:ListItem Text="11" Value="11"></asp:ListItem>
          <asp:ListItem Text="12" Value="12"></asp:ListItem>
              </asp:DropDownList>
          </td>
        
        
        
        
       
        
        
        
        
         <td> &nbsp;&nbsp;&nbsp;&nbsp;
           D<asp:DropDownList ID="ddlDate" runat='server' Width="80" Height="20">
          <asp:ListItem Text="DD" Value="0"></asp:ListItem>
          <asp:ListItem Text="01" Value="1"></asp:ListItem>
          <asp:ListItem Text="02" Value="2"></asp:ListItem>
          <asp:ListItem Text="03" Value="3"></asp:ListItem>
          <asp:ListItem Text="04" Value="4"></asp:ListItem>
          <asp:ListItem Text="05" Value="5"></asp:ListItem>
          <asp:ListItem Text="06" Value="6"></asp:ListItem>
          <asp:ListItem Text="07" Value="7"></asp:ListItem>
          <asp:ListItem Text="08" Value="8"></asp:ListItem>
          <asp:ListItem Text="09" Value="9"></asp:ListItem>
          <asp:ListItem Text="10" Value="10"></asp:ListItem>
          <asp:ListItem Text="11" Value="11"></asp:ListItem>
          <asp:ListItem Text="12" Value="12"></asp:ListItem>
          <asp:ListItem Text="13" Value="13"></asp:ListItem>
          <asp:ListItem Text="14" Value="14"></asp:ListItem>
          <asp:ListItem Text="15" Value="15"></asp:ListItem>
          <asp:ListItem Text="16" Value="16"></asp:ListItem>
          <asp:ListItem Text="17" Value="17"></asp:ListItem>
          <asp:ListItem Text="18" Value="18"></asp:ListItem>
          <asp:ListItem Text="19" Value="19"></asp:ListItem>
          <asp:ListItem Text="20" Value="20"></asp:ListItem>
          <asp:ListItem Text="21" Value="21"></asp:ListItem>
          <asp:ListItem Text="22" Value="22"></asp:ListItem>
          <asp:ListItem Text="23" Value="23"></asp:ListItem>
          <asp:ListItem Text="24" Value="24"></asp:ListItem>
          <asp:ListItem Text="25" Value="25"></asp:ListItem>
          <asp:ListItem Text="26" Value="26"></asp:ListItem>
          <asp:ListItem Text="27" Value="27"></asp:ListItem>
          <asp:ListItem Text="28" Value="28"></asp:ListItem>
          <asp:ListItem Text="29" Value="29"></asp:ListItem>
          <asp:ListItem Text="30" Value="30"></asp:ListItem>
          <asp:ListItem Text="31" Value="31"></asp:ListItem>
         </asp:DropDownList>
        
     </td>
         <td> &nbsp;&nbsp;&nbsp;&nbsp; Y<asp:DropDownList ID="ddlyear" runat='server' Width="80" Height="20">
          <asp:ListItem Text="YYYY" Value="0"></asp:ListItem>
          <asp:ListItem Text="1970" Value="1970"></asp:ListItem>
          <asp:ListItem Text="1971" Value="1971"></asp:ListItem>
          <asp:ListItem Text="1972" Value="1972"></asp:ListItem>
          <asp:ListItem Text="1973" Value="1973"></asp:ListItem>
          <asp:ListItem Text="1974" Value="1974"></asp:ListItem>
          <asp:ListItem Text="1975" Value="1975"></asp:ListItem>
          <asp:ListItem Text="1976" Value="1976"></asp:ListItem>
          <asp:ListItem Text="1977" Value="1977"></asp:ListItem>
          <asp:ListItem Text="1978" Value="1978"></asp:ListItem>
          <asp:ListItem Text="1979" Value="1979"></asp:ListItem>
          <asp:ListItem Text="1980" Value="1980"></asp:ListItem>
          <asp:ListItem Text="1981" Value="1981"></asp:ListItem>
          <asp:ListItem Text="1982" Value="1982"></asp:ListItem>
          <asp:ListItem Text="1983" Value="1983"></asp:ListItem>
          <asp:ListItem Text="1984" Value="1984"></asp:ListItem>
          <asp:ListItem Text="1985" Value="1985"></asp:ListItem>
          <asp:ListItem Text="1986" Value="1986"></asp:ListItem>
          <asp:ListItem Text="1987" Value="1987"></asp:ListItem>
          <asp:ListItem Text="1988" Value="1988"></asp:ListItem>
          <asp:ListItem Text="1989" Value="1989"></asp:ListItem>
          <asp:ListItem Text="1990" Value="1990"></asp:ListItem>
          <asp:ListItem Text="1991" Value="1991"></asp:ListItem>
          <asp:ListItem Text="1992" Value="1992"></asp:ListItem>
          <asp:ListItem Text="1993" Value="1993"></asp:ListItem>
          <asp:ListItem Text="1994" Value="1994"></asp:ListItem>
          <asp:ListItem Text="1995" Value="1995"></asp:ListItem>
          <asp:ListItem Text="1996" Value="1996"></asp:ListItem>
          <asp:ListItem Text="1997" Value="1997"></asp:ListItem>
          <asp:ListItem Text="1998" Value="1998"></asp:ListItem>
          <asp:ListItem Text="1999" Value="1999"></asp:ListItem>
          <asp:ListItem Text="2000" Value="2000"></asp:ListItem>
         
          </asp:DropDownList></td>
         </tr></table>
        
                  </td></tr>
         <%--
         <tr><td colspan="2"  align="left"><hr /><b>Mobile phone </b><hr /></td></tr>
        
         <tr><td align="left"><asp:TextBox ID="txtmobile" CssClass="unwatermarked" Width="150" Height="20" runat="server" />

                <asp:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender6" runat="server"

                    TargetControlID="txtmobile"

                    WatermarkText="Enter valid mobile"

                    WatermarkCssClass="watermarked" />
<br /><br />
         </td></tr>--%>
        
           <tr><td colspan="2" align="left"><hr /><b>Other email address </b><hr /></td></tr>
        
         <tr><td  align="left"><asp:TextBox ID="txtemail" CssClass="unwatermarked" Width="200" Height="20" runat="server" />
                <%--  <asp:RegularExpressionValidator ID="regularexpressionvalidator1" runat="server"  ValidationExpression ="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="Enter valid Id" Display='None' ControlToValidate="txtemail"></asp:RegularExpressionValidator>--%>
                <asp:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender7" runat="server"

                    TargetControlID="txtemail"

                    WatermarkText="Enter other email"

                    WatermarkCssClass="watermarked" />
               
<br /><br />
         </td></tr>
           <tr><td colspan="2" align="left"><hr /><b>Select Question </b><hr /></td></tr>
        
         <tr><td  align="left"><asp:DropDownList ID="ddlquestion" runat="server" CssClass="Textdrop" Width="200" Height="25">
    <asp:ListItem Value="0">Please Select</asp:ListItem>
    <asp:ListItem Value="1">What's Your Pet Name</asp:ListItem>
    <asp:ListItem Value="2">What's Your School Name</asp:ListItem>
    <asp:ListItem Value="3">What's Your Teacher Name</asp:ListItem>
    <asp:ListItem Value="4">What's Your Favourite Hero</asp:ListItem>
    <asp:ListItem Value="5">What's Your Friend Name</asp:ListItem>
    </asp:DropDownList>             
<br /><br />
         </td></tr>
           <tr><td colspan="2" align="left"><hr /><b>Answer</b><hr /></td></tr>
        
         <tr><td  align="left"><asp:TextBox ID="TextboxAnswer" runat="server" Width="200" Height="20"></asp:TextBox>
               <%--    <asp:RequiredFieldValidator ID="RequiredfieldvalidatorAnswer" runat="server" ErrorMessage="Enter your Answer." Display='None' ControlToValidate="TextboxAnswer"></asp:RequiredFieldValidator>--%>
                <asp:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender4" runat="server"

                    TargetControlID="TextboxAnswer"

                    WatermarkText="Enter Answer"

                    WatermarkCssClass="watermarked" />
               
<br /><br />
         </td></tr>
          <tr><td colspan="2" align="left"><hr /><b>Choose Image For Profile</b><hr /></td></tr>
        
         <tr><td  align="left"><asp:fileupload ID="fu" runat="server" ></asp:fileupload>
               
<br /><br />
         </td></tr>
              <tr><td colspan="2" align="left"><hr /><b>Prove you're not robot </b><hr /></td></tr>
         <tr><td>
        
        
         <tr><td align="left"> <asp:Label ID="lblvalid" runat="server" Width="150px"
                 Height="45px" ForeColor="Red" Font-Bold="True" Font-Size="30pt"
                 BackColor="Gray"></asp:Label> <br /><br /><asp:TextBox ID="txtvalidcode" CssClass="unwatermarked" Width="150" Height="20" runat="server" />

                <asp:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender8" runat="server"

                    TargetControlID="txtvalidcode"

                    WatermarkText="Enter valid code"

                    WatermarkCssClass="watermarked" /></td>
                 <td align="left">
       </td></tr>
        
        
               
<br /><br />  </td></tr>
 <tr><td colspan="2" align="left"><hr /><b>Location </b><hr /></td></tr>
        
    
    
      <tr><td  align="left"><asp:TextBox ID="txtlocation" CssClass="unwatermarked" Width="200" Height="20" runat="server" />
 <%-- <asp:RequiredFieldValidator ID="Requiredfieldvalidator2" runat="server" ErrorMessage="Enter Country name." Display='None' ControlToValidate="txtlocation"></asp:RequiredFieldValidator>--%>
                <asp:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender9" runat="server"

                    TargetControlID="txtlocation"

                    WatermarkText="Enter Country"

                    WatermarkCssClass="watermarked" />
               
<br /><br />
         </td></tr>
         <tr><td colspan="2" align="left"><hr /><asp:CheckBox ID="chkTC" runat="server" /> &nbsp; I agree to the <font color="red"> Term of Srevices</font> and <font color="red"> Privacy Policy</font><hr /></td></tr>
         <tr><td><asp:Label ID="lblmsg" ForeColor="Red" Font-Bold="true" runat="server"></asp:Label></td><td align="right"><asp:ImageButton ID="imgbutton" runat="server"
                 Height="110" Width="150" ImageUrl="~/IMAGE/submit.jpg"
                 onclick="imgbutton_Click" />
                
               <%--  <asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowSummary="false" ShowMessageBox="true" />--%>
                 </td></tr>
                      
   </table>
       
       
        </td>
        </tr>
                 
    <tr><td colspan="2"><ctl:foot ID="foot1" runat="server" /></td></tr>
        </table>
      
    </form>
</body>
</html>




 //// **************************************************////

//Code Behind ( First tier) That is Front End ..............


 //// **************************************************////





using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class regform : System.Web.UI.Page
{
    bllRegistration reg;
    bllRegistration reg1;
    protected void Page_Load(object sender, EventArgs e)
    {
        capcha();
    }
public void capcha()
{
    string str = System.Guid.NewGuid().ToString();
        lblvalid.Text = str.ToString();
        str = str.Replace("_", String.Empty);
        lblvalid.Text = str.Substring(24, 6);

}
protected void btnCheck_Click(object sender, ImageClickEventArgs e)
{
    reg = new bllRegistration();

    reg.emailid = Textboxemailid.Text;
   string s = reg.checkemail(reg);
   if (s == "Available!")
   {
       lblmsg2.Visible = false;
       lblemail.Visible = true;
          lblemail.Text = "Welcome you are accepted";
        
      
   }
   else
   {
       lblemail.Visible = false;
       lblmsg2.Visible = true;
       lblmsg2.Text = "Email Id allready Exist.";
   }
}
protected void imgbutton_Click(object sender, ImageClickEventArgs e)
{
 if (chkTC.Checked)
        {
             reg = new bllRegistration();
            reg1 = new bllRegistration();
            reg1.emailid = Textboxemailid.Text;
            String ch = reg1.checkemail(reg1);
            if (ch == "Available!")
            {
                if (fu.HasFile)
                {
                    string path = Server.MapPath("./upload/");// mapping server path
                    string upath = fu.FileName;
                    fu.SaveAs(path + upath);//save the specified file
                    reg.fileupload = fu.FileName;
                }

                else
                {

                    if (ddlgender.Text=="Male")
                    {
                        reg.fileupload="male.jpg";
                    }
                    else
                    {
                        reg.fileupload="female.jpg";
                    }
                }

              
           
               
               
                reg.firstname = TextBoxfirstname.Text;
                reg.lastname = Textboxlastname.Text;
                reg.Date = Convert.ToInt32(ddlDate.Text);
                reg.Month = Convert.ToInt32(ddlMonth.Text);
                reg.year = Convert.ToInt32(ddlyear.Text);
                reg.DOB = Convert.ToDateTime(ddlMonth.Text + "/" + ddlDate.Text + "/" + ddlyear.Text);
                reg.emailid = Textboxemailid.Text;
                reg.password = Textboxpassword.Text;
                reg.Sex=ddlgender.Text;
                reg.location =txtlocation.Text;
                reg.SecId=txtemail.Text;
                reg.conformpassword = textconformpassword.Text;
                reg.question = Convert.ToInt32(ddlquestion.SelectedValue);
                reg.Answer = TextboxAnswer.Text;
                if (chkTC.Checked == true)
                    reg.TC = "true";
                else
                    reg.TC = "false";
                reg.Registration(reg);

                Response.Redirect("success.aspx?n=" + TextBoxfirstname.Text + " &p= " + txtemail.Text  );

            }
            else
            {
                lblmsg.Text = "Email id Already used !";
            }
        }
        else
        {
            lblmsg.Text = "Please accept T & C !";
        }
    }

}



 //// **************************************************////

//Second Tier(Bussines Logic layer(BLL)..............


 //// **************************************************////


 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 bllRegistration
/// </summary>

public class bllRegistration
{

    dalRegistraion dr;
    public bllRegistration()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    #region Private
    private string _fileupload;
    private string _firstname;
    private string _lastname;
    private int _date;
    private int _month;
    private int _year;
    private DateTime _dob;
    private string _emailid;
    private string _sex;
    private string _secid;
    private string _password;
    private string _conformpassword;
    private int _question;
    private string _answer;
    private string _tc;
    private string _state;
    private string _city;
    private string _location;
#endregion


    #region public
    public string City
    {
        get { return _city; }
        set { _city = value; }
    }
    public string Sex
    {
        get { return _sex; }
        set { _sex = value; }
    }
     public string location
    {
        get { return _location; }
        set { _location = value; }
    }

    public string SecId
    {
        get { return _secid; }
        set { _secid = value; }
    }
    public string State
    {
        get { return _state; }
        set { _state = value; }
    }
    public string fileupload
    {
        get { return _fileupload; }
        set { _fileupload = value; }
    }
    public String firstname
    {
        get { return _firstname; }
        set { _firstname = value; }

    }

    public String lastname
    {
        get { return _lastname; }
        set { _lastname = value; }

    }
    public int Date
    {
        get { return _date ; }
        set { _date = value; }

    }
    public int Month
    {
        get { return _month ; }
        set { _month= value ; }

    }
    public int year
    {
        get { return _year ; }
        set { _year = value ; }

    }

    public DateTime DOB
    {
        get { return _dob; }
        set { _dob = value; }

    }

    public String emailid
    {
        get { return _emailid ; }
        set { _emailid = value ; }

    }
    public String password
    {
        get { return _password ; }
        set { _password = value ; }

    }
    public String conformpassword
    {
        get { return _conformpassword ; }
        set { _conformpassword = value ; }

    }
    public int question
    {
        get { return _question ; }
        set { _question = value ; }

    }
    public String Answer
    {
        get { return _answer; }
        set { _answer = value; }

    }
    public String TC
    {
        get { return _tc; }
        set { _tc = value; }

    }

    #endregion

    public void Registration(bllRegistration br)
    {
        dr = new dalRegistraion();
        //to logic
        dr.newRegistration(br);
    }

    public String checkemail(bllRegistration br)
    {
        dr = new dalRegistraion();
        String msg = dr.newcheckemail(br);
        return msg;
      
    }
    public String forgetpassword(bllRegistration br)
    {
        dr = new dalRegistraion();
        String msg = dr.newforgetpassword(br);
        return msg;

    }
    public String login(bllRegistration br)
    {
        dr = new dalRegistraion();
        String msg = dr.newlogin(br);
        return msg;

    }
    public DataSet  searchfriend(bllRegistration br)
    {
       
       dalRegistraion  dr = new dalRegistraion();
       DataSet ds = new DataSet();
       ds = dr.searchfriend(br);
        return ds;

    }


}

 

 //// **************************************************////

//Third Tier(Data Access layer(DAL)..............


 //// **************************************************////


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>
/// Summary description for dalRegistraion
/// </summary>
public class dalRegistraion
{
    SqlConnection con;
    public dalRegistraion()
   
    {
        con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["dreamprojectConnectionString"].ConnectionString);
        //con = new SqlConnection("Data Source=STUDENT-4730FA6;Initial Catalog=dreamproject;Integrated Security=True");
    }


    public void newRegistration(bllRegistration br)
    {
        String strsql = "insert into tbluser(image,firstname,lastname,dd,mm,year,dob,emailid,password,questionno,answer,tc,status,sex,state) values(@image,@firstname, @lastname, @dd, @mm, @year, @dob, @emailid, @password, @questionno, @answer, @tc,0,@sex,@location)";
    con.Open();
   
    SqlCommand cmd = new SqlCommand(strsql,con);
    SqlParameter param = new SqlParameter();
   
  

    param = new SqlParameter();
    param.ParameterName = "@image";
    param.Value =br.fileupload;
    cmd.Parameters.Add(param);

   /* param = new SqlParameter();
    param.ParameterName = "@secid";
    param.Value = br.SecId;
    cmd.Parameters.Add(param); */

    param = new SqlParameter();
    param.ParameterName = "@sex";
    param.Value = br.Sex;
    cmd.Parameters.Add(param);

    param = new SqlParameter();
    param.ParameterName = "@location";
    param.Value = br.location;
    cmd.Parameters.Add(param);

    param = new SqlParameter();
    param.ParameterName ="@firstname";
    param.Value = br.firstname;
    cmd.Parameters.Add(param);

    param = new SqlParameter();
    param.ParameterName = "@lastname";
    param.Value = br.lastname;
    cmd.Parameters.Add(param);

    param = new SqlParameter();
    param.ParameterName = "@dd";
    param.Value = br.Date ;
    cmd.Parameters.Add(param);

    param = new SqlParameter();
    param.ParameterName = "@mm";
    param.Value = br.Month ;
    cmd.Parameters.Add(param);

    param = new SqlParameter();
    param.ParameterName = "@year";
    param.Value = br.year ;
    cmd.Parameters.Add(param);

    param = new SqlParameter();
    param.ParameterName = "@dob";
    param.Value = br.DOB;
    cmd.Parameters.Add(param);

    param = new SqlParameter();
    param.ParameterName = "@emailid";
    param.Value = br.emailid ;
    cmd.Parameters.Add(param);

    param = new SqlParameter();
    param.ParameterName = "@password";
    param.Value = br.password ;
    cmd.Parameters.Add(param);

    param = new SqlParameter();
    param.ParameterName = "@questionno";
    param.Value = br.question;
    cmd.Parameters.Add(param);

    param = new SqlParameter();
    param.ParameterName = "@answer";
    param.Value = br.Answer ;
    cmd.Parameters.Add(param);

    param = new SqlParameter();
    param.ParameterName = "@tc";
    param.Value = br.TC ;
    cmd.Parameters.Add(param);

    cmd.ExecuteNonQuery();
}


   
   public String newcheckemail(bllRegistration br)
    {
        string msg = "";
      try {

          string selsql = "select emailid from tbluser where emailid='" + br.emailid+ "' ";
          SqlDataAdapter adp = new SqlDataAdapter(selsql, con);
          DataSet ds = new DataSet();
          adp.Fill(ds);
            if (ds.Tables[0].Rows.Count>0)
            {
                msg = "Already exist!";
            }
            else
                msg = "Available!";
        
         }
        catch (Exception e)
        {
        
        }


        return msg;

    }

    public String newforgetpassword(bllRegistration br)
    {
        string msg = "";
        try
        {

            string selsql = "select userid,emailid,password from tbluser where emailid='"+br.emailid+"' and questionno="+br.question+" and answer='"+br.Answer+"'";
            SqlDataAdapter adp = new SqlDataAdapter(selsql, con);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                msg = "right";
            }
            else
                msg = "wrong";

        }
        catch (Exception s)
        {

        }
        return msg;
    }
    public String newlogin(bllRegistration br)
    {
        string msg = "";
        try
        {

            string selsql = "select emailid,password from tbluser where emailid='" + br.emailid + "' and password='" + br.password + "'";
            SqlDataAdapter adp = new SqlDataAdapter(selsql, con);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            if (ds.Tables[0].Rows.Count > 0)
            {
                msg = "Successful login";
            }
            else
                msg = "Wrong password!";

        }
        catch (Exception s)
        {

        }
        return msg;
    }

    public DataSet searchfriend(bllRegistration br)
    {
        DataSet ds = new DataSet();
        try
        {

            string selsql = "select ('./upload/'+image)imgurl,edit,(firstname  + lastname)name,userid,emailid,state,city from tbluser where firstname like '"+br.firstname +"%'";
            SqlDataAdapter adp = new SqlDataAdapter(selsql, con);
       
            adp.Fill(ds);
           
        }
        catch (Exception s)
        {

        }
        if (ds.Tables[0].Rows.Count > 0)
        {
            return ds;
        }
        else
        {
            return (new DataSet());
        }

      
    }
           

}






No comments:

Post a Comment