private void dgRegisteredUser_DoubleClick(object sender, EventArgs e) { if (dgRegisteredUser.CurrentRow.Index != -1) { _entities = new MicroAccountsEntities1(); EncryptionDecription enc = new EncryptionDecription(); var uID = Convert.ToInt32(dgRegisteredUser.CurrentRow.Cells["SrNo"].Value); var userJoinData = (from a in _entities.tbl_UserProfile join b in _entities.tbl_UserLogiln on a.userId equals b.userId where a.userId == uID select new { a, b }).FirstOrDefault(); txtEmail.Text = userJoinData.a.email; txtF_name.Text = userJoinData.a.firstName; txtL_name.Text = userJoinData.a.lastName; txtMobileNo.Text = userJoinData.a.mobile.ToString(); //txtNewPass.Text = enc.Decrypt(userJoinData.b.password, "sblw-3hn8-sqoy19").ToString(); //txtNewPass.Text = enc.Decrypt(userJoinData.b.password).ToString(); txtNewPass.Text = userJoinData.b.password.Trim().ToString(); txtUserName.Text = userJoinData.b.loginId.ToString(); hiddenUID.Text = userJoinData.a.userId.ToString(); btnRegister.Text = "Update"; } }
private void btnRegister_Click(object sender, EventArgs e) { try { bool check = ValidateEmail(); EncryptionDecription enc; if (txtEmail.Text == string.Empty && txtF_name.Text == string.Empty && txtL_name.Text == string.Empty && txtUserName.Text == string.Empty && txtMobileNo.Text == string.Empty && txtNewPass.Text == string.Empty && txtConfirmPass.Text == string.Empty) { panel3.Visible = true; lblError.Text = "Enter all details."; txtEmail.Focus(); } else if (!check) { panel3.Visible = true; lblError.Text = txtEmail.Text + " is Invalid Email Address"; txtEmail.Focus(); } else if (txtEmail.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txtEmail, "Enter Email Address"); txtEmail.Focus(); panel3.Visible = true; lblError.Text = "Enter Email Address."; } else if (txtF_name.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txtF_name, "Enter First Name"); txtF_name.Focus(); panel3.Visible = true; lblError.Text = "Enter First Name."; } else if (txtL_name.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txtL_name, "Enter Last Name"); txtL_name.Focus(); panel3.Visible = true; lblError.Text = "Enter Last Name."; } else if (txtUserName.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txtUserName, "Enter User Name"); txtMobileNo.Focus(); panel3.Visible = true; lblError.Text = "Enter User Name."; } else if (txtMobileNo.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txtMobileNo, "Enter Mobile Number"); txtMobileNo.Focus(); panel3.Visible = true; lblError.Text = "Enter Mobile Number."; } else if (txtNewPass.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txtNewPass, "Enter Password"); txtNewPass.Focus(); panel3.Visible = true; lblError.Text = "Enter Password."; } else if (txtConfirmPass.Text == string.Empty) { errorProvider1.Clear(); errorProvider1.SetError(txtConfirmPass, "Re-enter Password"); txtConfirmPass.Focus(); panel3.Visible = true; lblError.Text = "Re-enter Password."; } else if (txtConfirmPass.Text != txtNewPass.Text) { errorProvider1.Clear(); errorProvider1.SetError(txtConfirmPass, "Re-enter Password"); txtConfirmPass.Clear(); txtConfirmPass.Focus(); panel3.Visible = true; lblError.Text = "Password and Confirm Password does not match."; } else { if (btnRegister.Text == "Register") { _entities = new MicroAccountsEntities1(); tbl_UserProfile userProfile = new tbl_UserProfile(); userProfile.email = txtEmail.Text.Trim().ToString(); userProfile.firstName = txtF_name.Text.Trim().ToString(); userProfile.lastName = txtL_name.Text.Trim().ToString(); userProfile.mobile = Convert.ToInt64(txtMobileNo.Text.Trim().ToString()); userProfile.createdDate = DateTime.Now; userProfile.updateDate = DateTime.Now; _entities.tbl_UserProfile.Add(userProfile); _entities.SaveChanges(); _entities = new MicroAccountsEntities1(); tbl_UserLogiln userlogin = new tbl_UserLogiln(); userlogin.loginId = txtUserName.Text.Trim().ToString(); //encryption of password by calling method of the class called EncryptionDecryption enc = new EncryptionDecription(); // var encPass = enc.Encrypt(txtNewPass.Text.Trim().ToString(), "sblw-3hn8-sqoy19"); // var encPass = enc.Encrypt(txtNewPass.Text.Trim().ToString()); userlogin.password = txtNewPass.Text.Trim().ToString(); userlogin.userId = _entities.tbl_UserProfile.Where(x => x.firstName == txtF_name.Text && x.email == txtEmail.Text).FirstOrDefault().userId; userlogin.createdDate = DateTime.Now; userlogin.updateDate = DateTime.Now; _entities.tbl_UserLogiln.Add(userlogin); _entities.SaveChanges(); DataGridSource(); MessageBox.Show("Register SuccessFull!"); } else { _entities = new MicroAccountsEntities1(); enc = new EncryptionDecription(); var uId = Convert.ToInt32(hiddenUID.Text); var dataToUpdate = _entities.tbl_UserProfile.Where(x => x.userId == uId).FirstOrDefault(); dataToUpdate.firstName = txtF_name.Text.Trim().ToString(); dataToUpdate.lastName = txtL_name.Text.Trim().ToString(); dataToUpdate.email = txtEmail.Text.Trim().ToString(); dataToUpdate.mobile = Convert.ToDecimal(txtMobileNo.Text.Trim()); dataToUpdate.updateDate = DateTime.Now; foreach (var item in dataToUpdate.tbl_UserLogiln) { item.loginId = txtUserName.Text.Trim().ToString(); // item.password = enc.Encrypt(txtNewPass.Text.ToString(), "sblw-3hn8-sqoy19"); item.password = enc.Encrypt(txtNewPass.Text.ToString()); item.updateDate = DateTime.Now; _entities.SaveChanges(); } _entities.SaveChanges(); DataGridSource(); MessageBox.Show("Updated SuccessFull!"); } ClearTextBox(); } } catch (Exception ex) { MessageBox.Show("Something went wrong. Contact your system administrator"); } }