Register.aspx

 

This web page allows the user to register himself, so that he can buy online the items he needs.

 

Here I have prohibited the creation of duplicate users as well as it prompts for a valid email id if in case its not registered properly.

 

The validation code and the submit event code is given below

 

 

Validation Code

 

private bool validation()   // THIS METHOD CHECKS THE USER ENTRIES.

         {

             String strErr ="";

             bool blnStatus=true;

            

             if(Name.Text.CompareTo("")==0)

             {

                 strErr = "Please enter the name.\\n";

                 blnStatus = false;

             }

             if(email.Text.CompareTo("") == 0)

             {

                 strErr +="Please enter ur mail id.\\n";

                 blnStatus = false;

             }

             if(pass.Text.CompareTo("")== 0 && confirmpassword.Text.CompareTo("")==0)

             {

                 strErr +="Check ur password.\\n";

                 blnStatus = false;

             }

             if(pass.Text != confirmpassword.Text)

             {

                 strErr +="Both passwords should be same.\\n";

                 blnStatus = false;

             }

            

             if(strErr.CompareTo("") == 1)

             {

                 strErr = "The following errors occured.\\n" + strErr;

                 RegisterStartupScript("Closepopup","<script>ShowMessage('" +strErr +"');</script>");

             }

            

             return blnStatus;

 

 

         }

 

         private bool duplicateuser()  // THIS METHOD CHECKS FOR DUPLICATE USERS.

                                       // THE LOGIC IS SELECT ROWS HAVING SOME ATTRIBUTES.IF ROWS ARE PRESENT THEN THE USERNAME OR EMAIL ID IS ALREADY PRESENT.ELSE gO AHEAD AND REGISTER.

         {

             bool blnStatus = true;

             SqlConnection combcon = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);

             SqlCommand dupread = new SqlCommand("Select fullname,emailaddress from employees where fullname = '" + Name.Text +"' and emailaddress ='" + email.Text +"'",combcon);

             try

             {                                // USE DATAREADER CLASS TO SELECT FORWARD READ ONLY DATA. AND FOR SELECTING A SINGLE RESULT.

                 combcon.Open();

                 SqlDataReader myreader = dupread.ExecuteReader(CommandBehavior.CloseConnection);

                 if(myreader.HasRows)

                 {

                      RegisterStartupScript("popup","<script>ShowMessage(\"the username or email id has already been taken.Please select some other\");</script>");

                      blnStatus = false;  // THIS IS A CLIENT SIDE SCRIPT VALIDATION TECHNIQUE.

                 }

             }

             catch(Exception ex)

             {

                 Console.WriteLine(ex.Message.ToString());

             }

             return blnStatus;

         }

 

private void submit_Click(object sender, System.EventArgs e)

         {

             if(validation() && duplicateuser())// Check if the user has put valid data and check if some othet user with the same username and email id is present.

             {

                 // if yes then instantiate an object of class Shopping funct and call method of getshoppingcartid for assignng  TEMPORARY ID.

                

                 prjstart.Components.Shoppingfunct tempcartid = new prjstart.Components.Shoppingfunct();

                 string shoppingcartid = tempcartid.getshoppingcart();

 

                 prjstart.Employeedb  submitid = new Employeedb();//Create an instance of employee db class.

                 string tempsubmitid = submitid.addemployeedetails(Name.Text,email.Text,prjstart.Components.encryptpass.protectpassword(pass.Text));

                 if (tempsubmitid != "") // Code for writing employee details.

                 {

 

                      // Set the user's authentication name to the customerId

                      FormsAuthentication.SetAuthCookie(shoppingcartid, false);

                      //Creates an authentication ticket and attaches it to the cookie's collection of the outgoing response. It does not perform a redirect.

         

                     

                      // Migrate any existing shopping cart items into the permanent shopping cart

         tempcartid.MigrateCart(shoppingcartid, Convert.ToInt32(tempsubmitid));

 

                      // Store the user's fullname in a cookie for personalization purposes

                      Response.Cookies["vijaymukhisprojectname"].Value = Server.HtmlEncode(Name.Text);

                      Response.Cookies["vijaymukhisprojectpass"].Value = Server.HtmlEncode(pass.Text);

                      Response.Cookies["vijaymukhisprojectemail"].Value = Server.HtmlEncode(email.Text);

 

                      // Redirect browser back to shopping cart page

                      Response.Redirect("registersuccessful.aspx");

                 }

                

             }

 

         }

 

 

back to the main page