Register



  public class DBConnection
    {
        private string _connectionString = ConfigurationManager.ConnectionStrings["RegisterConnection"].ConnectionString;
        private SqlConnection _sqlConnection = null;
        private SqlCommand _sqlCommand = null;
        private SqlDataAdapter _sqlDataAdapter = null;
        private DataSet _dataSet = null;
        private DataTable _dataTable = null;
        public DBConnection()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public DataSet GetDataSet(string queryStatement, SqlParameter[] sqlParams)
        {
            _dataSet = new DataSet();
            try
            {
                _sqlConnection = new SqlConnection(_connectionString);
                _sqlCommand = new SqlCommand(queryStatement, _sqlConnection);
                _sqlCommand.CommandType = CommandType.StoredProcedure;
                _sqlCommand.Parameters.AddRange(sqlParams);
                _sqlDataAdapter = new SqlDataAdapter(_sqlCommand);
                _sqlDataAdapter.Fill(_dataSet);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            return _dataSet;
        }

        public DataTable GetDataTable(string queryStatement, SqlParameter[] sqlParams)
        {
            _dataTable = new DataTable();
            try
            {
                _sqlConnection = new SqlConnection(_connectionString);
                _sqlCommand = new SqlCommand(queryStatement, _sqlConnection);
                _sqlCommand.CommandType = CommandType.StoredProcedure;
                _sqlCommand.Parameters.AddRange(sqlParams);
                _sqlDataAdapter = new SqlDataAdapter(_sqlCommand);
                _sqlDataAdapter.Fill(_dataTable);
            }
            catch (Exception ex)
            {

            }
            return _dataTable;
        }

        public string GetJson(DataTable dt)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
            Dictionary<string, object> row = null;
            foreach (DataRow dr in dt.Rows)
            {
                row = new Dictionary<string, object>();
                foreach (DataColumn col in dt.Columns)
                {
                    row.Add(col.ColumnName.Trim(), dr[col]);
                }
                rows.Add(row);
            }
            return serializer.Serialize(rows);
        }

        public string GetJsonDataset(DataSet ds)
        {

            System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            ArrayList root = new ArrayList();
            List<Dictionary<string, object>> table;
            Dictionary<string, object> data;

            foreach (DataTable dt in ds.Tables)
            {
                table = new List<Dictionary<string, object>>();
                foreach (DataRow dr in dt.Rows)
                {
                    data = new Dictionary<string, object>();
                    foreach (DataColumn col in dt.Columns)
                    {
                        data.Add(col.ColumnName, dr[col]);
                    }
                    table.Add(data);
                }
                root.Add(table);
            }

            return serializer.Serialize(root);
        }
    }















public partial class Register : System.Web.UI.Page
    {
        private static SqlConnection _sqlConnection = null;
        private static SqlCommand _sqlCommand = null;
        private static DataSet _dataSet = null;
        private static DataTable _dataTable = null;
        private static SqlParameter[] _sqlParameter = null;
        private static DBConnection _helper = null;
        private JavaScriptSerializer _serializer = null;
        private Dictionary<string, string> _jsonData;
        private static string _queryStatement = string.Empty;
        private static string _jsonOutput = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
           
        }
        public Register()
        {
            _helper = new DBConnection();
        }

        //[WebMethod]
        //public static DataTable RegisterSubmit(string uname, string email, string pwd)
        //{
        //    Register obj = new Register();
        //    obj.query = "";

        //    obj.query = @"Regitsration";
        //    obj._sqlParameter = new SqlParameter[] {
        //           new SqlParameter("@Username",uname),
        //            new SqlParameter("@Email",email),
        //            new SqlParameter("@password",pwd),
        //        };

        //    return obj.conn.GetDataTable(obj.query, obj._sqlParameter);
        //}

        [WebMethod]
        public static string RegisterSubmit(string uname, string email, string pwd)
        {
            _jsonOutput = string.Empty;
            _queryStatement = "[DMS].[Regitsration]";
            _sqlParameter = new SqlParameter[] {
                    new SqlParameter("@Username",uname),
                    new SqlParameter("@Email",email),
                    new SqlParameter("@password",pwd),
                };
            try
            {
                _dataSet = _helper.GetDataSet(_queryStatement, _sqlParameter);
                if (_dataSet.Tables[0].Rows.Count > 0)
                {
                    _jsonOutput = _helper.GetJsonDataset(_dataSet);
                }
                else
                {
                    _jsonOutput = "";
                }
            }
            catch (Exception ex)
            {
                _jsonOutput = "";
            }
            return _jsonOutput;
        }

   

    }















<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="RegisterLoginPractice.Register" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Register</title>
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet"></link>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"></link>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"></link>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style type="text/css">
body{
color: #fff;
background: #63738a;
font-family: 'Roboto', sans-serif;
}
    .form-control{
height: 40px;
box-shadow: none;
color: #969fa4;
}
.form-control:focus{
border-color: #5cb85c;
}
    .form-control, .btn{       
        border-radius: 3px;
    }
.signup-form{
width: 400px;
margin: 0 auto;
padding: 30px 0;
}
.signup-form h2{
color: #636363;
        margin: 0 0 15px;
position: relative;
text-align: center;
    }
.signup-form h2:before, .signup-form h2:after{
content: "";
height: 2px;
width: 30%;
background: #d4d4d4;
position: absolute;
top: 50%;
z-index: 2;
}
.signup-form h2:before{
left: 0;
}
.signup-form h2:after{
right: 0;
}
    .signup-form .hint-text{
color: #999;
margin-bottom: 30px;
text-align: center;
}
    .signup-form form{
color: #999;
border-radius: 3px;
    margin-bottom: 15px;
        background: #f2f3f7;
        box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
        padding: 30px;
    }
.signup-form .form-group{
margin-bottom: 20px;
}
.signup-form input[type="checkbox"]{
margin-top: 3px;
}
.signup-form .btn{       
        font-size: 16px;
        font-weight: bold;
min-width: 140px;
        outline: none !important;
    }
.signup-form .row div:first-child{
padding-right: 10px;
}
.signup-form .row div:last-child{
padding-left: 10px;
}   
    .signup-form a{
color: #fff;
text-decoration: underline;
}
    .signup-form a:hover{
text-decoration: none;
}
.signup-form form a{
color: #5cb85c;
text-decoration: none;
}
.signup-form form a:hover{
text-decoration: underline;

</style>
</head>
<body style="background-color:white">
    <form id="form1" runat="server">
        <div class="signup-form">
<h2>Register</h2>
<p class="hint-text">Create your account. It's free and only takes a minute.</p>
        <div class="form-group">
<div class="row">
<div class="col-xs-6"><input type="text" id="txtUserName" class="form-control" name="first_name" placeholder="First Name" required="required"></div>
<div class="col-xs-6"><input type="text" class="form-control" name="last_name" placeholder="Last Name" required="required"></div>
</div>       
        </div>
        <div class="form-group">
        <input id="txtemail" type="email" class="form-control" name="email" placeholder="Email" required="required">
        </div>
<div class="form-group">
            <input  type="password" class="form-control" name="password" placeholder="Password" required="required">
        </div>
<div class="form-group">
            <input id="txtpwd" type="password" class="form-control" name="confirm_password" placeholder="Confirm Password" required="required">
        </div>       
        <div class="form-group">
<label class="hint-text checkbox-inline"><input type="checkbox" required="required"> I accept the <a class="hint-text" href="#">Terms of Use</a> &amp; <a class="hint-text" href="#">Privacy Policy</a></label>
</div>
<div class="form-group">
            <button id="btnSubmit" type="submit" class="btn btn-success btn-lg btn-block">Register Now</button>
        </div>
<div class="text-center">Already have an account? <a href="#">Sign in</a></div>
</div>
    </form>
</body>
 <script type="text/javascript">
     $(document).ready(function () {
       
         $("#btnSubmit").click(function (e) {
             alert("Hi1");
             debugger;
             $.ajax({
                 type: "POST",
                 contentType: "application/json; charset=utf-8",
                 dataType: "json",
                 url: "Register.aspx/RegisterSubmit",
                 data: '{"uname":"' + $("#txtUserName").val() + '","email":"' + $("#txtUserName").val() + '","pwd":"' + $("#txtUserName").val() + '"}',
                 success: function (res) {
                     var rows = JSON.parse(res.d);
                 },
                 error: function (res) {

                     $("#divAjaxLoader").addClass("hide");
                 }
             });
         });       

       
     });
 </script>
</html>















<?xml version="1.0" encoding="utf-8"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.7.2"/>
    <httpRuntime targetFramework="4.7.2"/>
  </system.web>
  <connectionStrings>
    <!--<add name="RegisterConnection" connectionString="Server=DESKTOP-V19P0LI\\SQLEXPRESS; Database=StudentsDB; Integrated Security=True;" providerName="System.Data.SqlClient" />-->
    <!--<add name="RegisterConnection" connectionString="Server=localhost; Database= StudentsDB; Integrated Security=True;" providerName="System.Data.SqlClient" />-->
    <add name="RegisterConnection" connectionString="Data Source=localhost\SQLSERVER;Initial Catalog=StudentsDB;Integrated Security=True;" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>

</configuration>

Comments

Popular Posts