protected void btnRegister_Click(object sender, EventArgs e) { DataAccessLayer DAL = new DataAccessLayer(); string Username = txtUserName.Text; string Firstname = txtFirstName.Text; string Lastname = txtLastName.Text; string EmailID = txtEmail.Text; string Passport = txtPassport.Text; string Gender = ddlGender.SelectedValue; string Mobile = txtMobile.Text; string Password = Security.GetHash256(txtPassword.Text, txtUserName.Text); string ConfirmPassword = Security.GetHash256(txtConfirmPassword.Text, txtUserName.Text); string Profile = ddlUserProfile.SelectedValue; string Status = ddlStatus.SelectedValue; if (DAL.UsernameExists(Username)) { lblErrorMessage.Visible = true; lblErrorMessage.Text = "Username Already Exists!"; lblErrorMessage.ForeColor = System.Drawing.Color.Red; } else if (DAL.EmailIDExists(EmailID)) { lblErrorMessage.Visible = true; lblErrorMessage.Text = "Email-ID Already Exists!"; lblErrorMessage.ForeColor = System.Drawing.Color.Red; } else if (DAL.PassportExists(Passport)) { lblErrorMessage.Visible = true; lblErrorMessage.Text = "User Already Exists With Passport!"; lblErrorMessage.ForeColor = System.Drawing.Color.Red; } else { lblErrorMessage.Visible = true; lblErrorMessage.Text = "Username available!"; lblErrorMessage.ForeColor = System.Drawing.Color.Green; DataAccessLayer.InsertUser(Username, Firstname, Lastname, EmailID, Passport, Gender, Mobile, Password, Profile, Status); Response.Redirect("Login.aspx"); } }
protected void grdViewUsers_RowCommand1(object sender, GridViewCommandEventArgs e) { int ddl = ddlSearch.SelectedValue.Length; int txt = txtSearch.Text.Length; if (e.CommandName == "InsertRow") { try { DataAccessLayer DAL = new DataAccessLayer(); string Username = ((TextBox)grdViewUsers.FooterRow.FindControl("txtInsertUserName")).Text; string Firstname = ((TextBox)grdViewUsers.FooterRow.FindControl("txtInsertFirstName")).Text; string Lastname = ((TextBox)grdViewUsers.FooterRow.FindControl("txtInsertLastName")).Text; string EmailID = ((TextBox)grdViewUsers.FooterRow.FindControl("txtInsertEmailID")).Text; string Passport = ((TextBox)grdViewUsers.FooterRow.FindControl("txtInsertPassport")).Text; string Gender = ((DropDownList)grdViewUsers.FooterRow.FindControl("ddlInsertGender")).SelectedValue; string Mobile = ((TextBox)grdViewUsers.FooterRow.FindControl("txtInsertMobile")).Text; string pwd = ((TextBox)grdViewUsers.FooterRow.FindControl("txtInsertPassword")).Text; string Password = Security.GetHash256(pwd, Username); string UserProfile = ((DropDownList)grdViewUsers.FooterRow.FindControl("ddlInsertUserProfile")).SelectedValue; string Status = ((DropDownList)grdViewUsers.FooterRow.FindControl("ddlInsertStatus")).SelectedValue; if (DAL.UsernameExists(Username)) { lblUserErrorMessage.Visible = true; lblUserErrorMessage.Text = "Username Already Exists!"; lblUserErrorMessage.ForeColor = System.Drawing.Color.Red; } else if (DAL.EmailIDExists(EmailID)) { lblUserErrorMessage.Visible = true; lblUserErrorMessage.Text = "Email-ID Already Exists!"; lblUserErrorMessage.ForeColor = System.Drawing.Color.Red; } else if (DAL.PassportExists(Passport)) { lblUserErrorMessage.Visible = true; lblUserErrorMessage.Text = "User Already Registered With Passport!"; lblUserErrorMessage.ForeColor = System.Drawing.Color.Red; } else { lblUserErrorMessage.Visible = true; lblUserErrorMessage.Text = "User Profile for <b>" + Username + "</b> has been created"; lblUserErrorMessage.ForeColor = System.Drawing.Color.Green; DataAccessLayer.InsertUser(Username, Firstname, Lastname, EmailID, Passport, Gender, Mobile, Password, UserProfile, Status); GridBind(); } } catch (Exception ex) { lblUserErrorMessage.Visible = true; lblUserErrorMessage.Text = "Exception Occur: " + ex.Message; lblUserErrorMessage.ForeColor = System.Drawing.Color.Red; } } else if (e.CommandName == "EditRow") { try { lblUserException.Visible = false; lblUserErrorMessage.Visible = false; if (ddl != 0 && txt != 0) { int rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex; grdViewUsers.EditIndex = rowIndex; GridSearch(); } else { int rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex; grdViewUsers.EditIndex = rowIndex; GridBind(); } } catch (Exception ex) { lblUserErrorMessage.Visible = true; lblUserErrorMessage.Text = "Exception Occur: " + ex.Message; lblUserErrorMessage.ForeColor = System.Drawing.Color.Red; } } else if (e.CommandName == "DeleteRow") { try { lblUserException.Visible = false; lblUserException.Visible = false; if (ddl != 0 && txt != 0) { DataAccessLayer.DeleteUser(Convert.ToInt32(e.CommandArgument)); GridSearch(); } else { DataAccessLayer.DeleteUser(Convert.ToInt32(e.CommandArgument)); GridBind(); } } catch (Exception ex) { lblUserException.Visible = true; lblUserException.Text = "Exception Occur: " + ex.Message; lblUserException.ForeColor = System.Drawing.Color.Red; } } else if (e.CommandName == "CancelUpdate") { try { lblUserException.Visible = false; lblUserErrorMessage.Visible = false; if (ddl != 0 && txt != 0) { grdViewUsers.EditIndex = -1; GridSearch(); lblSearchError.Visible = false; } else { grdViewUsers.EditIndex = -1; GridBind(); lblSearchError.Visible = false; } } catch (Exception ex) { lblUserException.Visible = true; lblUserException.Text = "Exception Occur: " + ex.Message; lblUserException.ForeColor = System.Drawing.Color.Red; } } else if (e.CommandName == "UpdateRow") { try { lblUserErrorMessage.Visible = false; int rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex; int UserID = Convert.ToInt32(e.CommandArgument); string Username = ((TextBox)grdViewUsers.Rows[rowIndex].FindControl("txtEditUserName")).Text; string Firstname = ((TextBox)grdViewUsers.Rows[rowIndex].FindControl("txtEditFirstName")).Text; string Lastname = ((TextBox)grdViewUsers.Rows[rowIndex].FindControl("txteditLastName")).Text; string EmailID = ((TextBox)grdViewUsers.Rows[rowIndex].FindControl("txtEditEmailID")).Text; string Passport = ((TextBox)grdViewUsers.Rows[rowIndex].FindControl("txtEditPassport")).Text; string Gender = ((DropDownList)grdViewUsers.Rows[rowIndex].FindControl("ddlEditGender")).SelectedValue; string Mobile = ((TextBox)grdViewUsers.Rows[rowIndex].FindControl("txtEditMobile")).Text; string pwd = ((TextBox)grdViewUsers.Rows[rowIndex].FindControl("txtEditPassword")).Text; string Password = Security.GetHash256(pwd, Username); string UserProfile = ((DropDownList)grdViewUsers.Rows[rowIndex].FindControl("ddlEditUserProfile")).SelectedValue; string Status = ((DropDownList)grdViewUsers.Rows[rowIndex].FindControl("ddlEditStatus")).SelectedValue; DataAccessLayer.UpdateUser(UserID, Username, Firstname, Lastname, EmailID, Passport, Gender, Mobile, Password, UserProfile, Status); lblUserErrorMessage.Visible = true; lblUserErrorMessage.Text = "User Profile for <b>" + Username + "</b> has been udpated"; lblUserErrorMessage.ForeColor = System.Drawing.Color.Green; if (ddl != 0 && txt != 0) { grdViewUsers.EditIndex = -1; GridSearch(); lblSearchError.Visible = false; } else { grdViewUsers.EditIndex = -1; GridBind(); lblSearchError.Visible = false; } } catch (Exception ex) { lblUserErrorMessage.Visible = true; lblUserErrorMessage.Text = "Exception Occur: " + ex.Message; lblUserErrorMessage.ForeColor = System.Drawing.Color.Red; } } }