Thursday, February 4, 2010

REGISTRATION PAGE

protected void btnsubmit_Click(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
BLL_Users objReg = new BLL_Users();

objReg.CollegeName = txtCollegename.Text.Trim();
objReg.UserName = txtUsername.Text.Trim();
objReg.Password = txtPassword.Text.Trim();
objReg.RollNumber = txtrollnumber.Text.Trim();
objReg.FirstName = txtFirstname.Text.Trim();
objReg.MiddleName = txtMiddlename.Text.Trim();
objReg.LastName = txtLastname.Text.Trim();
objReg.Sex = RadioBtnSex.SelectedItem.Text.Trim();
//objReg.BirthDate = Convert.ToDateTime(txtBirthdate.Text.Trim());
objReg.BirthDate = DateTime.Parse(txtBirthdate.Text.Trim(),

System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat);
objReg.Faculty = drpdFaculty.SelectedValue;
objReg.Qualification = txtQualification.Text.Trim();
objReg.MobileNumber = txtMobileNumber.Text.Trim();
objReg.EmailId = txtEmailid.Text.Trim();
objReg.Address = txtAddress.Text.Trim();

int CheckUserExist = objReg.User_Registration();

if (CheckUserExist == 0)
{
txtCollegename.Text = "";
txtUsername.Text = "";
txtPassword.Text = "";
txtFirstname.Text = "";
txtMiddlename.Text = "";
txtLastname.Text = "";
RadioBtnSex.SelectedItem.Selected = false;
txtBirthdate.Text = "";
drpdFaculty.SelectedValue = "--Select--";
txtQualification.Text = "";
txtMobileNumber.Text = "";
txtEmailid.Text = "";
txtAddress.Text = "";
Session["msg"] = "Thanks for registration to the course.";
Response.Redirect("Login.aspx", false);
}
else if (CheckUserExist == 1)
{
lbl_success.Font.Bold = true;
lbl_success.ForeColor = Color.Red;
lbl_success.Text = "This UserName is already present. Please enter another UserName.";
txtUsername.Text = "";
txtUsername.Focus();
}
else if (CheckUserExist == 2)
{
lbl_success.Font.Bold = true;
lbl_success.ForeColor = Color.Red;
lbl_success.Text = "This EmailID is already present. Please enter another EmailID.";
txtEmailid.Text = "";
txtEmailid.Focus();
}
else if (CheckUserExist == 3)
{
lbl_success.Font.Bold = true;
lbl_success.ForeColor = Color.Red;
lbl_success.Text = "This rollnumber is already present. Please enter correct rollnumber.";
txtrollnumber.Text = "";
txtrollnumber.Focus();
}
}

}

BLL_REgistration.cs

public int User_Registration()
{
int CheckUserExist;
try
{
CheckUserExist = DAL_Users.User_Registration(this);
return CheckUserExist;
}
catch (Exception ex)
{
ex = ex;
return 5;
}
}


DAL_registration.cs

public static int User_Registration(BLL_Users objRegister)
{

string strCon = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection conn = new SqlConnection(strCon);
conn.Open();
SqlCommand cmd = new SqlCommand("Select UserName,EmailID,RollNumber from [360LMS_Users] where UserName = '" +

objRegister.UserName + "' or EmailID='" + objRegister.EmailId + "'or RollNumber='" + objRegister.RollNumber + "'", conn);
SqlDataReader dr = cmd.ExecuteReader();
try
{
if (!dr.HasRows)
{
dr.Close();
SqlHelper.ExecuteScalar(conn, CommandType.StoredProcedure, "360LMS_User_Registration", new

SqlParameter("@college_name", objRegister.CollegeName), new SqlParameter("@user_name", objRegister.UserName), new

SqlParameter("@password", objRegister.Password),new SqlParameter("@rollnumber",objRegister.RollNumber), new

SqlParameter("@first_name", objRegister.FirstName), new SqlParameter("@middle_name", objRegister.MiddleName), new

SqlParameter("@last_name", objRegister.LastName), new SqlParameter("@sex", objRegister.Sex), new SqlParameter("@birth_date",

objRegister.BirthDate), new SqlParameter("@faculty", objRegister.Faculty), new SqlParameter("@qualification",

objRegister.Qualification), new SqlParameter("@mobile_number", objRegister.MobileNumber), new SqlParameter("@email_id",

objRegister.EmailId), new SqlParameter("@address ", objRegister.Address));
return 0;
}
else
{
while (dr.Read())
{
if(dr.GetString(0)== objRegister.UserName)
{
return 1;
}
else if(dr.GetString(1) == objRegister.EmailId)
{
return 2;
}
else if (dr.GetString(2) == objRegister.RollNumber)
{
return 3;
}

}
}
}
catch(Exception ex)
{
ex = ex;
return 4;
}
return 5;
}

No comments:

Post a Comment