/* * CREATED: C. Stanhope Mar 3 2018 * MODIFIED: P. Chavez MAR 27 2018 * - Added to method body, used Holly's code * * Page_Load() * Run on page load and is used to display today's and tomorrow's access codes if a care site is selected from the drop-down list. * * PARAMETERS: * object sender - references the object that raised the Page_Load event * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty) * * RETURNS: * void * * ODEV METHOD CALLS: * UserManager.FindById() * MessageUserControl.ShowErrorMessage() * CareSiteController.GetCareSiteByCareSiteID() * DisplayAccessCodes() */ protected void Page_Load(object sender, EventArgs e) { if (CareSiteDDL.SelectedIndex == 0) { CodeCards.Visible = false; } if (User.IsInRole(AuthorizationLevelRoles.User)) { UserManager userManager = new UserManager(); ApplicationUser account = userManager.FindById(User.Identity.GetUserId()); CareSiteController careSiteController = new CareSiteController(); int accountCareSiteId = account.caresiteid == null ? 0 : (int)account.caresiteid; if (accountCareSiteId == 0) { MessageUserControl.ShowErrorMessage("Your account has no assigned care site. Please contact your administrator to be assigned a care site."); } else { try { CareSiteDDL.DataSourceID = null; CareSiteDDL.AppendDataBoundItems = false; List <CareSiteDTO> tempCareSiteList = new List <CareSiteDTO>(); tempCareSiteList.Add(careSiteController.GetCareSiteByCareSiteID(accountCareSiteId)); CareSiteDDL.DataSource = tempCareSiteList; CareSiteDDL.DataBind(); DisplayAccessCodes(accountCareSiteId); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Could not retrieve User's care site. Please try again. If error persists, please contact your administrator.", ex); } } } }
/* * CREATED: A. Valberg MAR 3 2018 * MODIFIED: H. Conant MAR 5 2018 * - Updated method signature * - Updated method body code * MODIFIED: H. Conant MAR 27 2018 * - Updated method body code * MODIFIED: H. L'Heureux APR 03 2018 * - Updated method body code * * AddUnitButton_Click() * This method allows the user to add a specified unit in the database. * * PARAMETERS: * object sender - object on the page that is being targeted * EventArgs e - event that has triggered the method * * RETURNS: * void * * ODEV METHOD CALLS: * MessageUserControl.ShowInfoMessage() * UnitController.AddUnit() * MessageUserControl.ShowSuccessMessage() * MessageUserControl.ShowErrorMessage() * ClearPage() */ protected void AddUnitButton_Click(object sender, EventArgs e) { string pattern = @"^[A-z 0-9 .-]{1,60}$"; Regex reg = new Regex(pattern); Match unitNameFormat = reg.Match(AddUnitNameTB.Text); if (string.IsNullOrWhiteSpace(AddUnitNameTB.Text) || AddUnitNameTB.Text.Length > 60 || !unitNameFormat.Success) { MessageUserControl.ShowInfoMessage("Please enter a unit name up to 60 characters. Unit names can only contain letters, numbers, and the following symbols: . -"); } else { int tempCareSiteID; int.TryParse(CareSiteDDL.SelectedValue, out tempCareSiteID); if (tempCareSiteID == 0) { MessageUserControl.ShowInfoMessage("Please select a care site."); } else { UnitDTO tempUnit = new UnitDTO(); tempUnit.caresiteid = tempCareSiteID; tempUnit.unitname = AddUnitNameTB.Text.Trim(); try { unitController.AddUnit(tempUnit); MessageUserControl.ShowSuccessMessage("Unit " + AddUnitNameTB.Text + " has been added to the " + CareSiteDDL.SelectedItem.Text + " care site."); ClearPage(); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Adding unit failed. Please try again. If error persists, please contact your administrator.", ex); } } } }
/* * CREATED: H. Conant MAR 4 2018 * MODIFIED: H. Conant MAR 20 2018 * - Added method body * * Page_Load() * This method runs any code it contains when the page loads. * * PARAMETERS: * object sender - object on the page that is being targeted * EventArgs e - event that has triggered the method * * RETURNS: * void * * ODEV METHOD CALLS: * UserManager.FindById() * MessageUserControl.ShowErrorMessage() * CareSiteController.GetCareSiteByCareSiteID() * UnitController.GetCareSiteUnits() * UnitController.GetAllUnits() */ protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (User.IsInRole(AuthorizationLevelRoles.User)) { UserManager userManager = new UserManager(); ApplicationUser account = new ApplicationUser(); try { account = userManager.FindById(User.Identity.GetUserId()); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Your account has no assigned care site. Please contact your administrator to be assigned a care site.", ex); } CareSiteController careSiteController = new CareSiteController(); int accountCareSiteId = account.caresiteid == null ? 0 : (int)account.caresiteid; if (accountCareSiteId == 0) { MessageUserControl.ShowErrorMessage("Your account has no assigned care site. Please contact your administrator to be assigned a care site."); } else { try { CareSiteDDL.DataSourceID = null; CareSiteDDL.AppendDataBoundItems = false; List <CareSiteDTO> tempCareSiteList = new List <CareSiteDTO>(); tempCareSiteList.Add(careSiteController.GetCareSiteByCareSiteID(accountCareSiteId)); CareSiteDDL.DataSource = tempCareSiteList; CareSiteDDL.DataBind(); List <UnitDTO> tempUnitList = unitController.GetCareSiteUnits(accountCareSiteId); UnitRepeater.DataSource = tempUnitList; UnitRepeater.DataBind(); unitsdiv.Attributes.Remove("style"); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Retrieving user care site and/or units from the database failed. Please try again. If error persists, please contact your administrator.", ex); } } } else { if (CareSiteDDL.SelectedValue == "0") { try { int tempCareSiteId; int.TryParse(CareSiteDDL.SelectedValue, out tempCareSiteId); List <UnitDTO> tempUnitList = unitController.GetAllUnits(); UnitRepeater.DataSource = tempUnitList; UnitRepeater.DataBind(); unitsdiv.Attributes.Add("style", "display:none"); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Retrieving units from the database failed. Please try again. If error persists, please contact your administrator.", ex); } } else { try { int tempCareSiteId; int.TryParse(CareSiteDDL.SelectedValue, out tempCareSiteId); List <UnitDTO> tempUnitList = unitController.GetCareSiteUnits(tempCareSiteId); UnitRepeater.DataSource = tempUnitList; UnitRepeater.DataBind(); unitsdiv.Attributes.Remove("style"); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Retrieving units from the database failed. Please try again. If error persists, please contact your administrator.", ex); } } } } }
/* * CREATED: H. Conant MAR 13 2018 * MODIFIED: A. Valberg MAR 28 2018 * -Updated fields after adding 2 tables (agegroup & gender) * MODIFIED: H. Conant MAR 31 2018 * -Updated gender and age to repeaters and ODSes * * RetrieveSurveys_Click() * This method runs any code it contains when the "Retrieve Surveys" button is clicked. * * PARAMETERS: * object sender - object on the page that is being targeted * EventArgs e - event that has triggered the method * * RETURNS: * void * * ODEV METHOD CALLS: * MessageUserControl.ShowInfoMessage() * MessageUserControl.ShowInfoList() * SurveyController.GetSurveys() * MessageUserControl.ShowErrorMessage() */ protected void RetrieveSurveys_Click(object sender, EventArgs e) { ResultCountLabel.Text = "0"; List <string> message = new List <string>(); SurveyRepeater.DataSource = null; SurveyRepeater.DataBind(); List <int> unitIds = new List <int>(); List <int> genders = new List <int>(); List <int> respodentIds = new List <int>(); List <int> ages = new List <int>(); DateTime dateOne = new DateTime(); DateTime dateTwo = new DateTime(); string pattern = @"^$|^(0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])[/][0-9]{4}$"; Regex reg = new Regex(pattern); Match properStartDateFormat = reg.Match(dateStart.Value); Match properEndDateFormat = reg.Match(dateEnd.Value); if (!properStartDateFormat.Success || !properEndDateFormat.Success) { message.Add("Please enter valid date(s) using the pattern mm/dd/yyyy or leave the date fields blank."); } else { if (dateStart.Value != "") { if (DateTime.TryParse(dateStart.Value, out dateOne) == false) { message.Add("Please enter a valid start date value or leave it blank."); } } if (dateEnd.Value != "") { if (DateTime.TryParse(dateEnd.Value, out dateTwo) == false) { message.Add("Please enter a valid end date value or leave it blank."); } } } if (dateStart.Value != "" && dateEnd.Value != "" && dateOne > dateTwo) { message.Add("Please ensure that the provided end date occurs after or on the same day as the provided start date."); } if (dateTwo > DateTime.Today || dateOne > DateTime.Today) { message.Add("Please select dates that are on or before today's date."); } foreach (RepeaterItem item in UnitRepeater.Items) { CheckBox tempCheckBox = (CheckBox)item.FindControl("CheckBox"); HiddenField tempHiddenField = (HiddenField)item.FindControl("HiddenUnitID"); if (tempCheckBox.Text.Length > 10) { tempCheckBox = (CheckBox)item.FindControl("CheckBox1"); } if (tempCheckBox.Checked == true) { int tempUntId; int.TryParse(tempHiddenField.Value, out tempUntId); unitIds.Add(tempUntId); } } if (unitIds.Count < 1) { message.Add("Please select at least one unit to filter by."); } foreach (RepeaterItem item in GenderRepeater.Items) { CheckBox tempCheckBox = (CheckBox)item.FindControl("CheckBox"); HiddenField tempHiddenField = (HiddenField)item.FindControl("HiddenGenderID"); if (tempCheckBox.Text.Length > 10) { tempCheckBox = (CheckBox)item.FindControl("CheckBox1"); } if (tempCheckBox.Checked == true) { int tempGenderId; int.TryParse(tempHiddenField.Value, out tempGenderId); genders.Add(tempGenderId); } } if (genders.Count < 1) { message.Add("Please select at least one gender to filter by."); } foreach (RepeaterItem item in RespondentTypeRepeater.Items) { CheckBox tempCheckBox = (CheckBox)item.FindControl("CheckBox"); HiddenField tempHiddenField = (HiddenField)item.FindControl("HiddenRespondentID"); if (tempCheckBox.Text.Length > 10) { tempCheckBox = (CheckBox)item.FindControl("CheckBox1"); } if (tempCheckBox.Checked == true) { int tempTypeId; int.TryParse(tempHiddenField.Value, out tempTypeId); respodentIds.Add(tempTypeId); } } if (respodentIds.Count < 1) { message.Add("Please select at least one respondent type to filter by."); } foreach (RepeaterItem item in AgeRepeater.Items) { CheckBox tempCheckBox = (CheckBox)item.FindControl("CheckBox"); HiddenField tempHiddenField = (HiddenField)item.FindControl("HiddenAgeGroupID"); if (tempCheckBox.Text.Length > 10) { tempCheckBox = (CheckBox)item.FindControl("CheckBox1"); } if (tempCheckBox.Checked == true) { int tempAgeId; int.TryParse(tempHiddenField.Value, out tempAgeId); ages.Add(tempAgeId); } } if (ages.Count < 1) { message.Add("Please select at least one age range to filter by."); } if (message.Count == 1) { MessageUserControl.ShowInfoMessage(message[0]); } else if (message.Count > 1) { MessageUserControl.ShowInfoList("Please address the following errors and try again: ", message); } else { try { List <ExtendedSurveyDTO> surveys = new List <ExtendedSurveyDTO>(); if (dateStart.Value == "" && dateEnd.Value == "") { surveys = surveyController.GetSurveys(unitIds, genders, ages, respodentIds); } else if (dateStart.Value == "" && dateEnd.Value != "") { dateOne = DateTime.MinValue; surveys = surveyController.GetSurveys(unitIds, genders, ages, dateOne, dateTwo, respodentIds); } else if (dateStart.Value != "" && dateEnd.Value == "") { dateTwo = DateTime.Today; dateEnd.Value = DateTime.Today.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture); surveys = surveyController.GetSurveys(unitIds, genders, ages, dateOne, dateTwo, respodentIds); } else { surveys = surveyController.GetSurveys(unitIds, genders, ages, dateOne, dateTwo, respodentIds); } if (surveys.Count < 1) { MessageUserControl.ShowInfoMessage("No surveys found matching the entered search criteria."); } else { ResultCountLabel.Text = (surveys.Count).ToString(); SurveyRepeater.DataSource = surveys; SurveyRepeater.DataBind(); } } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Retrieving surveys from the database failed. Please try again. If error persists, please contact your administrator.", ex); } } }
/* * CREATED: P. Chavez MAR 22 2018 * MODIFIED: C. Stanhope APR 5 2018 * - inputs now trim whitespace * MODIFIED: C. Stanhope APR 14 2018 * - user messages formatted the same as other pages * * AddAccountButton_Click() * This method creates a new account based on the input fields when the button is clicked. * * PARAMETERS: * object sender - references the object that raised the Page_Load event * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty) * * RETURNS: * void * * ODEV METHOD CALLS: * ErrorMessagesAndValidation.ErrorList() * MessageUserControl.ShowInfoMessage() * UserManager.GenerateNewPassword() * UserManager.AddAccountUser() * MessageUserControl.ShowSuccessMessage() * MessageUserControl.ShowErrorMessage() * MessageUserControl.ShowInfoList() */ protected void AddAccountButton_Click(object sender, EventArgs e) { //Retrieve the values from the controls string firstNameText = FirstNameTextBox.Text.Trim(); string lastNameText = LastNameTextBox.Text.Trim(); string emailText = EmailTextBox.Text.Trim(); string authLevelText = AuthorizationLevelRolesRadioList.SelectedValue; int careSiteID = int.Parse(CareSiteDDL.Visible == false ? "0" : CareSiteDDL.SelectedValue); List <string> errorList = new List <string>(); bool isValid = true; #region check if any inputs are blank if (string.IsNullOrWhiteSpace(firstNameText)) { errorList.Add("First Name"); isValid = false; } if (string.IsNullOrWhiteSpace(lastNameText)) { errorList.Add("Last Name"); isValid = false; } if (string.IsNullOrWhiteSpace(emailText)) { errorList.Add("Email"); isValid = false; } if (string.IsNullOrWhiteSpace(authLevelText)) { errorList.Add("Authorization Level"); isValid = false; } #endregion if (!isValid) { ErrorMessagesAndValidation errMessAndVal = new ErrorMessagesAndValidation(); string errorMessage = errMessAndVal.ErrorList(errorList); MessageUserControl.ShowInfoMessage(errorMessage); } else { bool matchRegex = true; List <string> regexErrorList = new List <string>(); Regex regexName = new Regex(@"^(?m)[A-Za-z][A-Za-z`. -]*$", RegexOptions.IgnoreCase); if (!regexName.Match(firstNameText).Success) { matchRegex = false; regexErrorList.Add("First Name can only contain letters, dashes, apostrophes, grave accents, spaces and periods."); } if (!regexName.Match(lastNameText).Success) { matchRegex = false; regexErrorList.Add("Last Name can only contain letters, dashes, apostrophes, grave accents, spaces and periods."); } if (!emailText.Contains("@")) { matchRegex = false; regexErrorList.Add("Email must include an '@' symbol."); } if (careSiteID == 0 && authLevelText == AuthorizationLevelRoles.User) { matchRegex = false; regexErrorList.Add("The Authorization Level User must have a Care Site associated with the account."); } if (matchRegex) { try { UserManager userManager = new UserManager(); string newPassword = userManager.GenerateNewPassword(); ApplicationUser newUserAccount = userManager.AddAccountUser(firstNameText, lastNameText, emailText, authLevelText, careSiteID, newPassword); string resultMessage = string.Format("The new account was created! UserName: {0} | Password: {1}", newUserAccount.UserName, newPassword); MessageUserControl.ShowSuccessMessage(resultMessage); //Reset the fields FirstNameTextBox.Text = ""; LastNameTextBox.Text = ""; EmailTextBox.Text = ""; AuthorizationLevelRolesRadioList.SelectedValue = AuthorizationLevelRoles.User; CareSiteDDL.SelectedValue = "0"; CareSiteDDL.Visible = true; CareSiteLabel.Visible = true; } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Adding account failed. Please try again. If error persists, please contact your administrator.", ex); } } else // A regex didn't match { MessageUserControl.ShowInfoList("The following errors caused adding a management account to fail: ", regexErrorList); } } }
/* * CREATED: C. Stanhope MAR 21 2018 * MODIFIED: C. Stanhope APR 5 2018 * - new word trims whitespace * MODIFIED: C. Stanhope APR 6 2018 * - added try-catch for database access * * UpdateAccessCodeButton_Click() * Triggered when the "UpdateAccessCodeButton" is clicked and is used to update the selected access code's word and status to whatever the user changed it to. * * PARAMETERS: * object sender - references the object that raised the Page_Load event * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty) * * RETURNS: * void * * ODEV METHOD CALLS: * ValidateAccessCodeWord() * AccessCodeController.UpdateAccessCode() * ClearPage() * ResetSearchFilters() * MessageUserControl.ShowInfoMessage() * MessageUserControl.ShowErrorMessage() */ protected void UpdateAccessCodeButton_Click(object sender, EventArgs e) { #region getting values from page string newWord = UpdateAccessCodeTextBox.Text.ToLower().Trim(); bool newStatus; if (UpdateAccessActiveStatusCodeRadioButtonList.SelectedItem.Value.Equals("y")) { newStatus = true; } else { newStatus = false; } #endregion if (newWord.Equals(selectedAccessCode.accesscodeword) && newStatus == selectedAccessCode.activeyn) // no changes made { MessageUserControl.ShowInfoMessage("No changes to update."); } else if (newWord.Equals(selectedAccessCode.accesscodeword)) // status changed but word did not { selectedAccessCode.activeyn = newStatus; try { accessCodeController.UpdateAccessCode(selectedAccessCode); if (newStatus == true) { MessageUserControl.ShowSuccessMessage("Access code '" + newWord + "' was marked as active."); } else { MessageUserControl.ShowSuccessMessage("Access code '" + newWord + "' was marked as inactive."); } ClearPage(); ResetSearchFilters(); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Updating access code failed. Please try again. If error persists, please contact your administrator.", ex); } } else // word was changed { if (ValidateAccessCodeWord(newWord)) { selectedAccessCode.accesscodeword = newWord; selectedAccessCode.activeyn = newStatus; try { accessCodeController.UpdateAccessCode(selectedAccessCode); MessageUserControl.ShowSuccessMessage("Access code '" + newWord + "' updated."); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Updating access code failed. Please try again. If error persists, please contact your administrator.", ex); } ClearPage(); ResetSearchFilters(); } else // not a valid word { MessageUserControl.ShowInfoMessage("The access code '" + newWord + "' is not valid. Please ensure the access code is between 6 and 8 letters (no numbers or symbols are permitted)."); } } }
/* * CREATED: C. Stanhope MAR 17 2018 * MODIFIED: C. Stanhope MAR 19 2018 * - modified to reflect globalization of accessCodeList * - added visibility change of update and word list sections * MODIFIED: C. Stanhope APR 5 2018 * - trims whitespace from inputs * MODIFIED: C. Stanhope APR 6 2018 * - added try-catch for database access * * SearchButton_Click() * Triggered when the "SearchButton" is clicked and is used to collect filtering data from the page and display access codes based on the search parameters. * * PARAMETERS: * object sender - references the object that raised the Page_Load event * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty) * * RETURNS: * void * * ODEV METHOD CALLS: * AccessCodeController.GetAccessCodesByStatus() * AccessCodeController.GetAccessCodesByKeyword() * AccessCodeController.GetAccessCodesByExactMatch() * AccessCodeController.GetAccessCodesByStartingLetter() * BindAccessCodeRepeater() * MessageUserControl.ShowErrorMessage() * MessageUserControl.ShowInfoMessage() */ protected void SearchButton_Click(object sender, EventArgs e) { // hide previous search and update results AccessCodeTableContainer.Visible = false; UpdateAccessCodeContainer.Visible = false; selectedAccessCode = null; string searchText = SearchKeywordTB.Text; if (searchText.Length > 0 && searchText.Trim().Length == 0) // if the only characters entered into the box are spaces { MessageUserControl.ShowInfoMessage("No words found matching the entered search criteria."); SearchKeywordTB.Text = ""; } else // if more than spaces are entered into the textbox. Or of the textbox is empty { searchText = searchText.Trim(); SearchKeywordTB.Text = searchText; // clearing whitespace from the textbox string searchType = SearchTypeRadioButtonList.SelectedValue; bool?activeStatus = null; // if null, show both active and inactive. if false, show inactive only. if true show active only #region Setting activeStatus variable bool showActive = ShowActiveCheckbox.Checked; bool showInactive = ShowInactiveCheckbox.Checked; if (showActive && !showInactive) { activeStatus = true; } else if (!showActive && showInactive) { activeStatus = false; } #endregion if (showActive || showInactive) // at least one active status checkbox is selected { try { #region select appropriate search type (keyword, match exactly, starts with) if (searchText.Length == 0) // no search text entered, just active status filtering { accessCodeList = accessCodeController.GetAccessCodesByStatus(activeStatus); } else // some search text exists in textbox { if (searchType.Equals(containsRadioButtonValue)) // keyword { accessCodeList = accessCodeController.GetAccessCodesByKeyword(searchText, activeStatus); } else if (searchType.Equals(matchExactlyRadioButtonValue)) // match exactly { accessCodeList = accessCodeController.GetAccessCodesByExactMatch(searchText, activeStatus); } else if (searchType.Equals(startsWithRadioButtonValue)) // starts with { accessCodeList = accessCodeController.GetAccessCodesByStartingLetter(searchText, activeStatus); } else // something broke { MessageUserControl.ShowErrorMessage("Search type does not exist. Please report to administrator."); accessCodeList.Clear(); } } #endregion if (accessCodeList.Count() > 0) { // display access code table AccessCodeTableContainer.Visible = true; // when new data is received, bind Repeater BindAccessCodeRepeater(); } else // no access codes found matching search { MessageUserControl.ShowInfoMessage("No words found matching the entered search criteria."); } } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Searching access code in the database failed. Please try again. If error persists, please contact your administrator.", ex); } } else // no active status checkbox is selected { MessageUserControl.ShowInfoMessage("Please select at least one active status to filter by."); } } }
/* * CREATED: H. Conant MAR 13 2018 * MODIFIED: H. Conant MAR 20 2018 * - Updated method signature * * RetrieveUnitList_Select() * This method runs any code it contains when the index changes for the care site drop down. * * PARAMETERS: * object sender - object on the page that is being targeted * EventArgs e - event that has triggered the method * * RETURNS: * void * * ODEV METHOD CALLS: * UnitController.GetCareSiteUnits() * MessageUserControl.ShowErrorMessage() * UnitController.GetAllUnits() */ protected void RetrieveUnitList_Select(object sender, EventArgs e) { CareSiteDDL.SelectedValue = CareSiteDDL.SelectedValue; ContactRequestsRepeater.DataSource = null; ContactRequestsRepeater.DataBind(); ResultCountLabel.Text = "-"; if (User.IsInRole(AuthorizationLevelRoles.User)) { try { int tempCareSiteId; int.TryParse(CareSiteDDL.SelectedValue, out tempCareSiteId); List <UnitDTO> tempUnitList = unitController.GetCareSiteUnits(tempCareSiteId); UnitRepeater.DataSource = tempUnitList; UnitRepeater.DataBind(); unitsdiv.Attributes.Remove("style"); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Retrieving units from the database failed. Please try again. If error persists, please contact your administrator.", ex); } } else { if (CareSiteDDL.SelectedValue == "0") { try { int tempCareSiteId; int.TryParse(CareSiteDDL.SelectedValue, out tempCareSiteId); List <UnitDTO> tempUnitList = unitController.GetAllUnits(); UnitRepeater.DataSource = tempUnitList; UnitRepeater.DataBind(); unitsdiv.Attributes.Add("style", "display:none"); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Retrieving units from the database failed. Please try again. If error persists, please contact your administrator.", ex); } } else { try { int tempCareSiteId; int.TryParse(CareSiteDDL.SelectedValue, out tempCareSiteId); List <UnitDTO> tempUnitList = unitController.GetCareSiteUnits(tempCareSiteId); UnitRepeater.DataSource = tempUnitList; UnitRepeater.DataBind(); unitsdiv.Attributes.Remove("style"); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Retrieving units from the database failed. Please try again. If error persists, please contact your administrator.", ex); } } } }
/* * CREATED: A. Valberg MAR 19 2018 * * ProcessReport() * This method validates all user input & filters, and then processes the report. * * PARAMETERS: * None * * RETURNS: * void * * ODEV METHOD CALLS: * ControlValidation() * MessageUserControl.ShowInfoMessage() * MessageUserControl.ShowInfoList() * GetData() */ protected void ProcessReport() { // list to hold error msgs List <string> errors = new List <string>(); // local variables for page controls int questionID; questionID = QuestionDDL.SelectedValue != "" ? int.Parse(QuestionDDL.SelectedValue) : 0; List <string> unitIDs = new List <string>(); List <string> respondentTypes = new List <string>(); List <string> genders = new List <string>(); List <string> ages = new List <string>(); DateTime startDate = new DateTime(), endDate = new DateTime(); // regex to check date fields string pattern = @"^$|^(0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])[/][0-9]{4}$"; Regex reg = new Regex(pattern); // finding and retrieving page controls if (CareSiteDDL.SelectedValue != "") { ControlValidation(UnitRepeater, unitIDs, "HiddenUnitID"); } ControlValidation(RespondentTypeRepeater, respondentTypes, "HiddenRespondentTypeID"); ControlValidation(GenderRepeater, genders, "HiddenGenderID"); ControlValidation(AgeGroupRepeater, ages, "HiddenAgeGroupID"); // care site & unit validation if (CareSiteDDL.SelectedValue != "" && unitIDs.Count == 0) { errors.Add("Please select at least one unit."); } // date validation // checking if the data matches the regex if (!reg.IsMatch(dateStart.Text) || !reg.IsMatch(dateEnd.Text)) { errors.Add("Please enter valid date(s) using the pattern mm/dd/yyyy or leave the date fields blank."); } else { // checking if the data can be parsed if (dateStart.Text != "" && !DateTime.TryParse(dateStart.Text, out startDate)) { errors.Add("Please enter a valid start date value or leave it blank."); } if (dateEnd.Text != "" && !DateTime.TryParse(dateEnd.Text, out endDate)) { errors.Add("Please enter a valid start date value or leave it blank."); } // checking if the dates are valid if (startDate > DateTime.Today || endDate > DateTime.Today) { errors.Add("Please select dates that are on or before today's date."); } if (dateStart.Text != "" && dateEnd.Text != "" && startDate > endDate) { errors.Add("Please ensure that the provided end date occurs after or on the same day as the provided start date."); } else { if (dateStart.Text != "" && dateEnd.Text == "") { dateEnd.Text = DateTime.Today.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture); endDate = DateTime.Today; } } } // respondent type validation if (respondentTypes.Count == 0) { errors.Add("Please select at least one respondent type to filter by."); } // gender validation if (genders.Count == 0) { errors.Add("Please select at least one gender to filter by."); } // age group validation if (ages.Count == 0) { errors.Add("Please select at least one age group to filter by."); } // question validation if (questionID == 0) { errors.Add("Please select a question from the drop-down list."); } // check if there were errors found; if not, process the report if (errors.Count == 1) { MessageUserControl.ShowInfoMessage(errors[0]); ReportViewer1.Visible = false; } else { if (errors.Count > 1) { MessageUserControl.ShowInfoList("Please address the following errors and try again:", errors); ReportViewer1.Visible = false; } else // all data is assumed valid, create dataset { // these statements are to clear filters lists if all are selected; makes the query neater if (dateEnd.Text == "") { dateEnd.Text = DateTime.Today.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture); } if (respondentTypes.Count == RespondentTypeRepeater.Items.Count) { respondentTypes.Clear(); } if (ages.Count == AgeGroupRepeater.Items.Count) { ages.Clear(); } if (genders.Count == GenderRepeater.Items.Count) { genders.Clear(); } // creating a dataset and trying to fill it with the GetData method DataSet dt = new DataSet(); try { dt = GetData(questionID, unitIDs, respondentTypes, genders, ages, startDate, endDate); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("An error occurred while processing the report. Please reload the page and try again. If the error persists, please contact your administrator.", ex); } // checking if 0 surveys are found - display "no data found" int count = 0; foreach (DataRow row in dt.Tables[0].Rows) { count += int.Parse(row.ItemArray[3].ToString()); } if (count == 0) { MessageUserControl.ShowInfoMessage("No data was found matching the entered search criteria."); ReportViewer1.Visible = false; } else // if you get here, the filters are valid! run the report. { ReportViewer1.Visible = true; ReportParameter param = new ReportParameter("QuestionID", QuestionDDL.SelectedItem.Text.Split(':')[0]); ReportDataSource rds = new ReportDataSource("ReportSource", dt.Tables[0]); ReportViewer1.LocalReport.DataSources.Clear(); ReportViewer1.LocalReport.ReportPath = "Reports/Report.rdlc"; ReportViewer1.LocalReport.SetParameters(param); ReportViewer1.LocalReport.DisplayName = "Reports_" + QuestionDDL.SelectedItem.Text.Split(':')[0] + "_" + DateTime.Now.ToString("MMMddyyyy_HHmm"); ReportViewer1.LocalReport.DataSources.Add(rds); ReportViewer1.LocalReport.Refresh(); } } } }
/* * CREATED: C. Stanhope MAR 23 2018 * MODIFIED: C. Stanhope MAR 24 2018 * - Added validation, finished method * MODIFIED: C. Stanhope APR 5 2018 * - trim whitespace on inputs * - validation now matches add care site * MODIFIED: C. Stanhope APR 6 2018 * - added try-catch for database access * MODIFIED: C. Stanhope APR 17 2018 * - fixed city regex to limit at 30 characters * - fixed care site regex to limit at 80 characters * * UpdateCareSiteButton_Click() * Used to update a care site in the database. Validates all input fields and updates only if valid. * * PARAMETERS: * object sender - references the object that raised the Page_Load event * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty) * * RETURNS: * void * * ODEV METHOD CALLS: * MessageUserControl.ShowInfoMessage() * CareSiteController.GetCareSiteByCareSiteID() * MessageUserControl.ShowErrorMessage() * ErrorMessagesAndValidation.ErrorList() */ protected void UpdateCareSiteButton_Click(object sender, EventArgs e) { if (selectedCareSite != null) { bool isValid = true; List <string> errorList = new List <string>(); #region regexes for validation Regex careSiteRegex = new Regex(@"^[A-z]{1}[A-z 0-9 .-]{4,79}$"); Regex addressRegex = new Regex(@"^[A-z 0-9 .#-]{1,40}$"); Regex cityRegex = new Regex(@"^[A-z]{1}[A-z .-]{0,29}$"); #endregion #region get values from page and validate string careSiteName = CareSiteNameTextBox.Text.Trim(); if (!careSiteRegex.IsMatch(careSiteName)) { errorList.Add("Care site must be a minimum of 5 characters and a maximum of 80 characters long. It must start with a letter and can contain letters, numbers, and the following symbols: . -"); isValid = false; } string address = AddressTextBox.Text.Trim(); if (!addressRegex.IsMatch(address)) { errorList.Add("Address must be a minimum of 1 character and a maximum of 40 characters long. It can contain letters, numbers, and the following symbols: # . -"); isValid = false; } string city = CityTextBox.Text.Trim(); if (!cityRegex.IsMatch(city)) { errorList.Add("City must be a minimum of 1 letter and a maximum of 30 characters long. It must start with a letter and can contain letters and the following symbols: . -"); isValid = false; } string province = ProvinceDDL.SelectedValue; #endregion if (isValid) { #region see if data changed bool dataChanged = false; if (selectedCareSite.caresitename != careSiteName) { dataChanged = true; } else if (selectedCareSite.address != address) { dataChanged = true; } else if (selectedCareSite.city != city) { dataChanged = true; } else if (selectedCareSite.province != province) { dataChanged = true; } #endregion if (dataChanged) { #region put valid data into selectedCareSite, add to database, show success message, change DDL selectedCareSite.caresitename = careSiteName; selectedCareSite.address = address; selectedCareSite.city = city; selectedCareSite.province = province; try { careSiteController.UpdateCareSite(selectedCareSite); MessageUserControl.ShowSuccessMessage("The " + selectedCareSite.caresitename + " care site was successfully updated."); CareSiteDDL.SelectedItem.Text = selectedCareSite.caresitename; } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Updating care site failed. Please try again. If error persists, please contact your administrator.", ex); } #endregion } else { MessageUserControl.ShowInfoMessage("No changes to save."); } } else { #region show user message with "errors" ErrorMessagesAndValidation errMessAndVal = new ErrorMessagesAndValidation(); string errorMessage = errMessAndVal.ErrorList(errorList); //MessageUserControl.ShowInfoMessage(errorMessage); MessageUserControl.ShowInfoList("The following errors caused adding a care site to fail: ", errorList); #endregion } } else // no care site selected { MessageUserControl.ShowErrorMessage("No care site selected. The \"Update Care Site\" button should not be available if no care site is selected. Please try again. If error persists, please contact your administrator."); } }
/* * CREATED: H. Conant MAR 17 2018 * * Page_Load() * This method runs any code it contains when the page loads. * Will obtain survey details, questions and answers to the questions. * * PARAMETERS: * object sender - object on the page that is being targeted * EventArgs e - event that has triggered the method * * RETURNS: * void * * ODEV METHOD CALLS: * SurveyController.GetSurveyDetails() * MessageUserControl.ShowErrorMessage() * UserManager.FindById() * UnitController.GetUnit() * SurveyAnswerController.GetSurveyAnswers() * SurveyQuestionController.GetSurveyQuestions() * MessageUserControl.ShowInfoMessage() */ protected void Page_Load(object sender, EventArgs e) { int surveyId = 0; int.TryParse(Request.QueryString["id"], out surveyId); if (surveyId == 0) { Response.Redirect("/Management/contact_requests.aspx"); } else { ExtendedSurveyDTO survey = new ExtendedSurveyDTO(); try { survey = surveyController.GetSurveyDetails(surveyId); } catch (Exception ex) { if (survey.surveyid != -1) { MessageUserControl.ShowErrorMessage("Could not retrieve survey. Please try again. If error persists, please contact your administrator.", ex); } } if (survey.surveyid == 0 || string.IsNullOrEmpty(survey.surveyid.ToString()) || survey.surveyid == -1) { Response.Redirect("/Management/contact_requests.aspx"); } else { if (User.IsInRole(AuthorizationLevelRoles.User)) { UserManager userManager = new MSS.System.BLL.Security.UserManager(); ApplicationUser account = new ApplicationUser(); try { account = userManager.FindById(User.Identity.GetUserId()); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Could not retrieve user accounts. Please try again. If error persists, please contact your administrator.", ex); } CareSiteController careSiteController = new CareSiteController(); int accountCareSiteId = account.caresiteid == null ? 0 : (int)account.caresiteid; if (accountCareSiteId == 0) { Response.Redirect("/Management/contact_requests.aspx"); } else { UnitDTO surveyUnit = new UnitDTO(); try { surveyUnit = unitController.GetUnit(survey.unitid); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Could not retrieve care site. Please try again. If error persists, please contact your administrator.", ex); survey = new ExtendedSurveyDTO(); } if (surveyUnit.caresiteid != accountCareSiteId) { Response.Redirect("/Management/contact_requests.aspx"); } } } SurveyIDLabel.Text = survey.surveyid.ToString(); DateLabel.Text = survey.date.ToString("MMM dd, yyyy"); UnitLabel.Text = survey.unitname; CareSiteLabel.Text = survey.caresitename; RespondentTypeLabel.Text = survey.respondenttypename; AgeLabel.Text = survey.agegroupname; GenderLabel.Text = survey.gendername; if (string.IsNullOrEmpty(survey.firstname)) { Name.Text = "Name not provided"; } else { Name.Text = survey.firstname; } BedNumber.Text = String.IsNullOrEmpty(survey.bednaumber) ? "Not Provided" : survey.bednaumber; PhoneNumber.Text = String.IsNullOrEmpty(survey.phonenumber) ? "Not Provided" : survey.phonenumber; if (survey.preferredcontact == null || survey.preferredcontact == "I don't want to be contacted") { BedNumberLabel.Visible = false; BedNumber.Visible = false; PhoneNumberLabel.Visible = false; PhoneNumber.Visible = false; ProcessedStatusLabel.Visible = false; ProcessedStatus.Visible = false; ProcessRequestButton.Enabled = false; ProcessRequestButton.Visible = false; PreferredContactLabel.Text = String.IsNullOrEmpty(survey.preferredcontact) ? "I don't want to be contacted" : survey.preferredcontact; } else { PreferredContactLabel.Text = survey.preferredcontact; if (BedNumber.Text == "Not Provided") { BedNumberLabel.Visible = false; BedNumber.Visible = false; } else { BedNumberLabel.Visible = true; BedNumber.Visible = true; } if (PhoneNumber.Text == "Not Provided") { PhoneNumberLabel.Visible = false; PhoneNumber.Visible = false; } else { PhoneNumberLabel.Visible = true; PhoneNumber.Visible = true; } if (survey.contactedyn == true) { ProcessedStatus.Text = "Processed"; ProcessedStatus.ForeColor = System.Drawing.Color.Green; ProcessRequestButton.Enabled = false; ProcessRequestButton.Visible = false; } else if (survey.contactedyn == false) { ProcessedStatus.Text = "Not Processed"; ProcessedStatus.ForeColor = System.Drawing.Color.Red; ProcessRequestButton.Enabled = true; ProcessRequestButton.Visible = true; } else { ProcessedStatus.Text = "Contact not requested"; ProcessedStatus.ForeColor = System.Drawing.Color.Black; ProcessRequestButton.Enabled = false; ProcessRequestButton.Visible = false; } } List <surveyanswer> surveyAnswers = new List <surveyanswer>(); List <surveyquestion> surveyQuestions = new List <surveyquestion>(); try { surveyAnswers = surveyAnswerController.GetSurveyAnswers(survey.surveyid); surveyQuestions = surveyQuestionController.GetSurveyQuestions(); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Could not retrieve survey answers or questions. Please try again. If error persists, please contact your administrator.", ex); } if (surveyQuestions.Count > 0) { foreach (surveyquestion question in surveyQuestions) { switch (question.surveyquestionid) { case 1: Question1aLabel.Text = question.question; break; case 2: Question1bLabel.Text = question.question; break; case 3: Question1cLabel.Text = question.question; break; case 4: Question1dLabel.Text = question.question; break; case 5: Question1eLabel.Text = question.question; break; case 6: Question2Label.Text = question.question; break; case 7: Question3Label.Text = question.question; break; case 8: Question4Label.Text = question.question; break; case 9: Question5Label.Text = question.question; break; default: MessageUserControl.ShowInfoMessage("New questions have been added to the survey. Please contact your administrator to update this webpage."); break; } } if (surveyAnswers.Count > 0) { foreach (surveyanswer answer in surveyAnswers) { switch (answer.possibleanswer.surveyquestionid) { case 1: Question1aLabel.Text = (answer.historicalquestion == null) ? Question1aLabel.Text : answer.historicalquestion; Answer1.Text = (answer.answer == null) ? "- No response -" : answer.answer; break; case 2: Question1bLabel.Text = (answer.historicalquestion == null) ? Question1bLabel.Text : answer.historicalquestion; Answer2.Text = (answer.answer == null) ? "- No response -" : answer.answer; break; case 3: Question1cLabel.Text = (answer.historicalquestion == null) ? Question1cLabel.Text : answer.historicalquestion; Answer3.Text = (answer.answer == null) ? "- No response -" : answer.answer; break; case 4: Question1dLabel.Text = (answer.historicalquestion == null) ? Question1dLabel.Text : answer.historicalquestion; Answer4.Text = (answer.answer == null) ? "- No response -" : answer.answer; break; case 5: Question1eLabel.Text = (answer.historicalquestion == null) ? Question1eLabel.Text : answer.historicalquestion; Answer5.Text = (answer.answer == null) ? "- No response -" : answer.answer; break; case 6: Question2Label.Text = (answer.historicalquestion == null) ? Question2Label.Text : answer.historicalquestion; Answer6.Text = (answer.answer == null) ? "- No response -" : answer.answer; break; case 7: Question3Label.Text = (answer.historicalquestion == null) ? Question3Label.Text : answer.historicalquestion; Answer7.Text = (answer.answer == null) ? "- No response -" : answer.answer; break; case 8: Question4Label.Text = (answer.historicalquestion == null) ? Question4Label.Text : answer.historicalquestion; Answer8.Text = (answer.answer == null) ? "- No response -" : answer.answer; break; case 9: Question5Label.Text = (answer.historicalquestion == null) ? Question5Label.Text : answer.historicalquestion; Answer9.Text = (answer.answer == null) ? "- No response -" : answer.answer; break; default: MessageUserControl.ShowInfoMessage("New questions have been added to the survey. Please contact your administrator to update this webpage."); break; } } } else { MessageUserControl.ShowInfoMessage("Survey has no answers."); } } else { MessageUserControl.ShowInfoMessage("There are not questions in the database."); } } } }
/* * CREATED: E. Lautner APR 1 2018 * * Page_Load() * Run on page load and is used to display the selected accounts details * * PARAMETERS: * object sender - references the object that raised the Page_Load event * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty) * * RETURNS: * void * * ODEV METHOD CALLS: * MessageUserControl.ShowErrorMessage() * UserManager.FindByName() * UserManager.GetRoles() */ protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { if (AuthorizationLevelRolesRadioList.SelectedValue == AuthorizationLevelRoles.User) { CareSiteDDL.Visible = true; CareSiteLabel.Visible = true; } else { CareSiteDDL.Visible = false; CareSiteLabel.Visible = false; } } else { try { sentUserName = Request.QueryString["id"]; if (sentUserName == "administratoraccount") //can't modify webmaster { Response.Redirect("~/Management/accounts"); } else { if (sentUserName == null) { Response.Redirect("~/Management/accounts"); } else { UsernameLabel.Text = sentUserName; UserManager userManager = new UserManager(); var selectedUser = userManager.FindByName(sentUserName); if (selectedUser == null) { Response.Redirect("~/Management/accounts"); } if (selectedUser.activeyn == true) { PasswordBtn.Visible = true; DeactivateAccountButton.Visible = true; UpdateAccountButton.Visible = true; FirstNameTB.Enabled = true; LastNameTB.Enabled = true; EmailTB.Enabled = true; AuthorizationLevelRolesRadioList.Enabled = true; CareSiteDDL.Enabled = true; if (selectedUser.Id == Context.User.Identity.GetUserId()) { DeactivateAccountButton.Visible = false; AuthorizationLevelRolesRadioList.Enabled = false; } } else { PasswordBtn.Visible = false; DeactivateAccountButton.Visible = false; UpdateAccountButton.Visible = false; FirstNameTB.Enabled = false; LastNameTB.Enabled = false; EmailTB.Enabled = false; AuthorizationLevelRolesRadioList.Enabled = false; CareSiteDDL.Enabled = false; } var userRoles = userManager.GetRoles(selectedUser.Id); string userRole = string.Join("", userRoles.ToArray()); FirstNameTB.Text = selectedUser.firstname; LastNameTB.Text = selectedUser.lastname; EmailTB.Text = selectedUser.Email; CareSiteDDL.SelectedValue = selectedUser.caresiteid.ToString(); if (selectedUser.caresiteid == null) { CareSiteDDL.SelectedValue = "0"; } AuthorizationLevelRolesRadioList.SelectedValue = userRole; if (userRole == AuthorizationLevelRoles.Administrator || userRole == AuthorizationLevelRoles.Super_User) { CareSiteDDL.Visible = false; CareSiteLabel.Visible = false; } } } } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Retrieving account information from the database failed. Please try again. If error persists, please contact your administrator.", ex); } } }
/* * CREATED: E. Lautner APR 1 2018 * MODIFIED: C. Stanhope APR 14 2018 * - changed validation to match the account_add validation * * ModifyUser_Click() * Gathers all given information on the page about the selected account. Sends this information to the userManager so that the account can be updated. * * PARAMETERS: * object sender - references the object that raised the Page_Load event * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty) * * RETURNS: * void * * ODEV METHOD CALLS: * MessageUserControl.ShowSuccessMessage() * MessageUserControl.ShowErrorMessage() * UserManager.ModifyAccount() * UserManager.GetRoles() */ protected void ModifyUser_Click(object sender, EventArgs e) { { sentUserName = Request.QueryString["id"]; if (sentUserName == "" || sentUserName == null) { MessageUserControl.ShowErrorMessage("An account has not been selected. Please navigate back to the Account Search page and select an account. If error persists, please contact your administrator."); } else { //Retrieve the values from the controls string firstNameText = FirstNameTB.Text.Trim(); string lastNameText = LastNameTB.Text.Trim(); string emailText = EmailTB.Text.Trim(); string authLevelText = AuthorizationLevelRolesRadioList.SelectedValue; int careSiteID = int.Parse(CareSiteDDL.Visible == false ? "0" : CareSiteDDL.SelectedValue); List <string> errorList = new List <string>(); bool isValid = true; #region check if any inputs are blank if (string.IsNullOrWhiteSpace(firstNameText)) { errorList.Add("First Name"); isValid = false; } if (string.IsNullOrWhiteSpace(lastNameText)) { errorList.Add("Last Name"); isValid = false; } if (string.IsNullOrWhiteSpace(emailText)) { errorList.Add("Email"); isValid = false; } if (string.IsNullOrWhiteSpace(authLevelText)) { errorList.Add("Authorization Level"); isValid = false; } #endregion if (!isValid) { ErrorMessagesAndValidation errMessAndVal = new ErrorMessagesAndValidation(); string errorMessage = errMessAndVal.ErrorList(errorList); MessageUserControl.ShowInfoMessage(errorMessage); } else { if (!emailText.Contains("@")) { MessageUserControl.ShowInfoMessage("Email must include an '@' symbol."); } else { if (System.Text.RegularExpressions.Regex.IsMatch(FirstNameTB.Text, @"^(?m)[A-Za-z][A-Za-z`. -]*$") && System.Text.RegularExpressions.Regex.IsMatch(LastNameTB.Text, @"^(?m)[A-Za-z][A-Za-z`. -]*$")) { if (int.Parse(CareSiteDDL.SelectedValue) == 0 && AuthorizationLevelRolesRadioList.SelectedValue == AuthorizationLevelRoles.User) { MessageUserControl.ShowInfoMessage("Authorization Level: User, must be associated with a care site"); } else { try { UserManager userManager = new UserManager(); var selectedUser = userManager.FindByName(UsernameLabel.Text); var userRoles = userManager.GetRoles(selectedUser.Id); string userRole = string.Join("", userRoles.ToArray()); string newUserName = userManager.ModifyAccount(UsernameLabel.Text, FirstNameTB.Text.Trim(), LastNameTB.Text.Trim(), EmailTB.Text.Trim(), int.Parse(CareSiteDDL.SelectedValue), userRole, AuthorizationLevelRolesRadioList.SelectedValue); if (newUserName != UsernameLabel.Text) { string resultMessage = string.Format("Update successful, new UserName is {0} ", newUserName); MessageUserControl.ShowSuccessMessage(resultMessage); UsernameLabel.Text = newUserName; } else { string resultMessage = string.Format("Update successful for user: {0}", UsernameLabel.Text); MessageUserControl.ShowSuccessMessage(resultMessage); } } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Update Failed. Please try again. If error persists, please contact your administrator. Error Message: " + ex.Message); } } } else { MessageUserControl.ShowInfoMessage("First Name and Last Name can only contain letters, dashes, apostrophes, grave accents, spaces and periods."); } } } } } }
/* * CREATED: C. Stanhope MAR 23 2018 * MODIFIED: C. Stanhope MAR 24 2018 * - moved error list method to its own class and call it * - changed validation to account for care site name length * MODIFIED: C. Stanhope APR 5 2018 * - trim whitespace on inputs * MODIFIED: C. Stanhope APR 6 2018 * - added try-catch for database access * MODIFIED: C. Stanhope APR 17 2018 * - fixed city regex to limit at 30 characters * - fixed care site regex to limit at 80 characters * * AddCareSiteButton_Click() * Used to add a care site to the database. Validates all input fields. * * PARAMETERS: * object sender - references the object that raised the Page_Load event * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty) * * RETURNS: * void * * ODEV METHOD CALLS: * CareSiteController.AddCareSite() * MessageUserControl.ShowSuccessMessage() * MessageUserControl.ShowInfoMessage() * ErrorMessagesAndValidation.ErrorList() */ protected void AddCareSiteButton_Click(object sender, EventArgs e) { bool isValid = true; List <string> errorList = new List <string>(); #region regexes for validation Regex careSiteRegex = new Regex(@"^[A-z]{1}[A-z 0-9 .-]{4,79}$"); Regex addressRegex = new Regex(@"^[A-z 0-9 .#-]{1,40}$"); Regex cityRegex = new Regex(@"^[A-z]{1}[A-z .-]{0,29}$"); #endregion #region get values from page and validate string careSiteName = CareSiteNameTextBox.Text.Trim(); if (!careSiteRegex.IsMatch(careSiteName)) { errorList.Add("Care site must be a minimum of 5 characters and a maximum of 80 characters long. It must start with a letter and can contain letters, numbers, and the following symbols: . -"); isValid = false; } string address = AddressTextBox.Text.Trim(); if (!addressRegex.IsMatch(address)) { errorList.Add("Address must be a minimum of 1 letter and a maximum of 40 characters long. It can contain letters, numbers, and the following symbols: # . -"); isValid = false; } string city = CityTextBox.Text.Trim(); if (!cityRegex.IsMatch(city)) { errorList.Add("City must be a minimum of 1 letter and a maximum of 30 characters long. It must start with a letter and can contain letters and the following symbols: . -"); isValid = false; } string province = ProvinceDDL.SelectedValue; if (ProvinceDDL.SelectedIndex == 0) { errorList.Add("A province must be selected from the drop-down list"); isValid = false; } #endregion if (isValid) { #region put valid data into DTO, add to database, show success message, clear page CareSiteDTO newCareSite = new CareSiteDTO(); newCareSite.caresitename = careSiteName; newCareSite.address = address; newCareSite.city = city; newCareSite.province = province; CareSiteController careSiteController = new CareSiteController(); try { careSiteController.AddCareSite(newCareSite); // show message, clear page MessageUserControl.ShowSuccessMessage("New care site " + careSiteName + " was successfully added. Please navigate to the Manage Units page to add units to the new care site."); CareSiteNameTextBox.Text = ""; AddressTextBox.Text = ""; CityTextBox.Text = ""; ProvinceDDL.SelectedIndex = 0; } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Adding care site failed. Please try again. If error persists, please contact your administrator.", ex); } #endregion } else { MessageUserControl.ShowInfoList("The following errors caused adding a care site to fail: ", errorList); } }