//Updates the profile private void UpdateProfile() { int intResult; string strResult = ""; //Checks to see if it exists try { strResult = CProfiles.CheckProfileExists(Convert.ToInt32(txtProfileID.Text)); } catch (Exception ex) { MessageBox.Show("Failed to get single value in UpdateProfile: " + ex.ToString(), "Database error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (!(strResult == "1")) { tslStatus.Text = "Profile Does Not Exist"; return; } else { try { ArrayList parameters = new ArrayList(); parameters.Add(new SqlParameter("profileID", txtProfileID.Text)); parameters.Add(new SqlParameter("firstName", txtFName.Text)); parameters.Add(new SqlParameter("lastName", txtLName.Text)); if (!(txtMiddleInitial.Text == "" || txtMiddleInitial.Text == null)) { parameters.Add(new SqlParameter("middleInitial", txtMiddleInitial.Text)); } parameters.Add(new SqlParameter("dateOfBirth", Convert.ToDateTime(dtmDOB.Text))); parameters.Add(new SqlParameter("phoneNumber", mtbPhone.Text)); parameters.Add(new SqlParameter("mailingAddress", txtMailing.Text)); parameters.Add(new SqlParameter("City", txtCity.Text)); parameters.Add(new SqlParameter("ZIP", mtbZip.Text)); parameters.Add(new SqlParameter("userName", txtUsername.Text)); parameters.Add(new SqlParameter("password", txtPassword.Text)); parameters.Add(new SqlParameter("email", txtEmail.Text)); intResult = CProfiles.UpdateProfile(parameters); if (!(intResult == 1)) { errP.SetError(btnSave, "Unable to update profile"); tslStatus.Text = "Unable To Update"; } else { tslStatus.Text = "Updated Profile"; } } catch (Exception ex) { MessageBox.Show("Failed to update profile in btnSave_Click: " + ex.ToString(), "Database error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
//Search for profile using profile ID, populates form if found private void btnSearch_Click(object sender, EventArgs e) { //Used to check if Profile exists or Not string strResult = ""; //Check to see if it exists try { strResult = CProfiles.CheckProfileExists(Convert.ToInt32(txtProfileID.Text)); } catch (Exception ex) { MessageBox.Show("Failed to get single value in btnSearch_Click: " + ex.ToString(), "Database error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (!(strResult == "1")) { tslStatus.Text = "Profile Does Not Exist"; return; } else { //Load the profile try { SqlDataReader objDR; objDR = CProfiles.GetProfileByID(txtProfileID.Text); if (objDR.Read()) { txtFName.Text = objDR.GetString(1); txtLName.Text = objDR.GetString(2); dtmDOB.Text = objDR.GetDateTime(4).ToString(); mtbPhone.Text = objDR.GetString(5); txtMailing.Text = objDR.GetString(6); txtCity.Text = objDR.GetString(7); mtbZip.Text = objDR.GetInt32(8).ToString(); txtUsername.Text = objDR.GetString(9); txtPassword.Text = objDR.GetString(10); txtEmail.Text = objDR.GetString(11); } objDR.Close(); LoadAccounts(); tslStatus.Text = "Profile Found"; } catch (Exception ex) { MessageBox.Show("Failed to get data reader in btnSearch_Click: " + ex.ToString(), "Database error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }