Ejemplo n.º 1
0
    /*
     * CREATED:    C. Stanhope     MAR 13 2018
     * MODIFIED:   C. Stanhope     MAR 21 2018
     *  - added ResetSearchFilters() method call
     *  - added validation
     * MODIFIED:   C. Stanhope     APR 5 2018
     *  - new word trims whitespace
     * MODIFIED:   C. Stanhope     APR 6 2018
     *  - added try-catch for database access
     *
     * AddAccessCodeButton_Click()
     * Triggered when "AddAccessCodeButton" is clicked and is used to add an access code to the database.
     *
     * 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.AddAccessCode()
     * MessageUserControl.ShowSuccessMessage()
     * ClearPage()
     * ResetSearchFilters()
     * MessageUserControl.ShowInfoMessage()
     * MessageUserControl.ShowErrorMessage()
     */
    protected void AddAccessCodeButton_Click(object sender, EventArgs e)
    {
        string newWord = AddAccessCodeTB.Text.ToLower().Trim();

        if (newWord.Length > 0)
        {
            if (ValidateAccessCodeWord(newWord))
            {
                AccessCodeDTO newAccessCode = new AccessCodeDTO();
                newAccessCode.accesscodeword = newWord;
                newAccessCode.activeyn       = true; // defaults to active

                try
                {
                    accessCodeController.AddAccessCode(newAccessCode);

                    MessageUserControl.ShowSuccessMessage("New access code '" + newWord + "' added");
                    ClearPage();
                    ResetSearchFilters();
                }
                catch (Exception ex)
                {
                    MessageUserControl.ShowErrorMessage("Adding access code failed. Please try again. If error persists, please contact your administrator.", ex);
                }
            }
            else // invalid code 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).");
            }
        }
        else // no word entered
        {
            MessageUserControl.ShowInfoMessage("No access code word was entered. Please enter a word between 6 and 8 letters (no numbers or symbols are permitted).");
        }
    }
Ejemplo n.º 2
0
 /*
  * CREATED:     A. Valberg		MAR 3 2018
  * MODIFIED:    H. Conant		MAR 5 2018
  * - Updated method signature
  * - Updated method body code
  *
  * DeactivateUnitButton_Click()
  * This method allows the user to deactivate 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.DeactivateUnit()
  * MessageUserControl.ShowSuccessMessage()
  * MessageUserControl.ShowErrorMessage()
  * ClearPage()
  */
 protected void DeactivateUnitButton_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(DeactivateUnitNameLabel.Text))
     {
         MessageUserControl.ShowInfoMessage("Please select a care site and unit.");
     }
     else
     {
         int tempUnitId;
         int.TryParse(UnitDDL.SelectedValue, out tempUnitId);
         if (tempUnitId == 0)
         {
             MessageUserControl.ShowInfoMessage("Please select a care site and unit.");
         }
         else
         {
             UnitDTO tempUnit = new UnitDTO();
             tempUnit.unitid = tempUnitId;
             try
             {
                 unitController.DeactivateUnit(tempUnit);
                 MessageUserControl.ShowSuccessMessage("Unit " + UnitDDL.SelectedItem.Text + " has been deactivated for the " + CareSiteDDL.SelectedItem.Text + " care site.");
                 ClearPage();
             }
             catch (Exception ex)
             {
                 MessageUserControl.ShowErrorMessage("Deactivating unit failed. Please try again. If error persists, please contact your administrator.", ex);
             }
         }
     }
 }
Ejemplo n.º 3
0
    /*
     * 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
     *
     * RetrieveUnit_Select()
     * This method retrieves the unit specified by the user.
     *
     * 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.GetUnit()
     * MessageUserControl.ShowInfoMessage()
     * MessageUserControl.ShowErrorMessage()
     */
    protected void RetrieveUnit_Select(object sender, EventArgs e)
    {
        if (UnitDDL.SelectedValue == "0")
        {
            MessageUserControl.ShowInfoMessage("Please select a unit name if you wish to update or deactivate a unit.");
            UpdateUnitNameTB.Text        = "";
            DeactivateUnitNameLabel.Text = "";
            UpdateDeactivateRow.Visible  = false;
            AddUnitRow.Visible           = true;
        }
        else
        {
            try
            {
                int tempUnitId;
                int.TryParse(UnitDDL.SelectedValue, out tempUnitId);
                UnitDTO tempUnit = unitController.GetUnit(tempUnitId);
                UpdateUnitNameTB.Text        = tempUnit.unitname;
                DeactivateUnitNameLabel.Text = tempUnit.unitname;

                AddUnitRow.Visible          = true;
                UpdateDeactivateRow.Visible = true;
            }
            catch (Exception ex)
            {
                MessageUserControl.ShowErrorMessage("Retrieving units failed. Please try again. If error persists, please contact your administrator.", ex);
            }
        }
    }
Ejemplo n.º 4
0
    /*
     * CREATED:     C. Stanhope		MAR 23 2018
     *
     * CareSiteDDL_SelectedIndexChanged()
     * Triggered when the care site DDL's selected field is changed. If the DDL is changed to "Select...", a message is displayed and the manage care site form is hidden. If the user selects a care site, the manage care site form is displayed and populated with the proper information.
     *
     * 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()
     */
    protected void CareSiteDDL_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (CareSiteDDL.SelectedIndex == 0)
        {
            MessageUserControl.ShowInfoMessage("Please select a care site to manage.");
            AccountForm.Visible = false;
            selectedCareSite    = null;
        }
        else
        {
            int selectedID;

            if (int.TryParse(CareSiteDDL.SelectedValue, out selectedID))
            {
                selectedCareSite = careSiteController.GetCareSiteByCareSiteID(selectedID);

                // populate form with info from database
                CareSiteNameTextBox.Text  = selectedCareSite.caresitename;
                AddressTextBox.Text       = selectedCareSite.address;
                CityTextBox.Text          = selectedCareSite.city;
                ProvinceDDL.SelectedValue = selectedCareSite.province;
            }
            else
            {
                MessageUserControl.ShowErrorMessage("An error occurred converting the care site drop-down list value. Please try again. If error persists, please contact your administrator.");
            }
        }
    }
Ejemplo n.º 5
0
 /*
  * CREATED:     E. Lautner		MAR 27 2018
  *
  * UsersFetch_Click()
  * This method runs when the search button is clicked. The repeater is forced to databind, which calls the ODS. The ODS uses the string in the search bar for its search.
  *
  * 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.ShowErrorMessage()
  * MessageUserControl.ShowInfoMessage()
  */
 protected void UsersFetch_Click(object sender, EventArgs e)
 {
     try
     {
         AccountRepeater.DataBind();
     }
     catch (Exception ex)
     {
         MessageUserControl.ShowErrorMessage("Account search failed. Please try again. If error persists, please contact your administrator.", ex);
     }
     if (AccountRepeater.Items.Count < 1)
     {
         MessageUserControl.ShowInfoMessage("No accounts found matching the given search text. Try searching by part of the username or by part of the full name.");
     }
 }
Ejemplo n.º 6
0
    /*
     * CREATED:     E. Lautner		Mar 22 2018
     *
     * SetPassword_Click()
     * Checks that the new password is identical in ConfirmPassTextBox and NewPassTextBox.
     * Attempts to change the password by passing the old password and new password.
     * Prompts MessageUserControl when action fails or passes.
     *
     * 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.FindById()
     * UserManager.CheckPassword()
     * MessageUserControl.ShowInfoMessage()
     */
    protected void SetPassword_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            if (ConfirmPassTextBox.Text == NewPassTextBox.Text)
            {
                if (NewPassTextBox.Text.Length < 8)
                {
                    MessageUserControl.ShowInfoMessage("New password must be at least 8 characters long.");
                }
                else
                {
                    try
                    {
                        string      userId        = Context.User.Identity.GetUserId();
                        UserManager userManager   = new UserManager();
                        var         currentUser   = userManager.FindById(userId);
                        bool        checkpassword = userManager.CheckPassword(currentUser, OldPassTextBox.Text);
                        if (checkpassword == true)
                        {
                            IdentityResult result = userManager.ChangePassword(Context.User.Identity.GetUserId(), OldPassTextBox.Text, NewPassTextBox.Text);

                            if (result.Succeeded)
                            {
                                MessageUserControl.ShowSuccessMessage("Password successfully updated.");
                            }
                        }
                        else
                        {
                            MessageUserControl.ShowInfoMessage("Old password was incorrect. Please try again.");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageUserControl.ShowErrorMessage("Password change failed. Please try again. If error persists, please contact your administrator.", ex);
                    }
                }
            }
            else
            {
                MessageUserControl.ShowInfoMessage("New Password and Confirm Password did not match. Please try again.");
            }
        }
    }
Ejemplo n.º 7
0
 /*
  * CREATED:     C. Stanhope		Mar 11 2018
  *
  * CareSiteDDL_SelectedIndexChanged()
  * Refreshes the page data to reflect the change made in the drop-down list, showing either an error or the access codes for the newly selected care site.
  *
  * 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()
  * MessageUserControl.ShowErrorMessage()
  * DisplayAccessCodes()
  */
 protected void CareSiteDDL_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (CareSiteDDL.SelectedIndex == 0)
     {
         MessageUserControl.ShowInfoMessage("No care site selected. Please select a care site.");
         CodeCards.Visible = false;
     }
     else // care site was selected
     {
         int selectedCareSiteID;
         if (int.TryParse(CareSiteDDL.SelectedValue, out selectedCareSiteID))
         {
             DisplayAccessCodes(selectedCareSiteID);
         }
         else // the tryparse of the care site ID didn't work
         {
             MessageUserControl.ShowErrorMessage("Selected care site not recognised. Please try again. If error persists, please contact your administrator.");
         }
     }
 }
Ejemplo n.º 8
0
    /*
     * CREATED:     E. Lautner		Mar 22 2018
     *
     * LogIn()
     * Attempts to log in the user with the given password and username. If successful it will navigate to the dashboard.
     *
     * 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()
     * UserManager.find()
     */
    protected void LogIn(object sender, EventArgs e)
    {
        if (IsValid)
        {
            // Validate the user password
            var             manager = new UserManager();
            ApplicationUser user    = manager.Find(UsernameTextBox.Text, PasswordTextBox.Text);

            //user must be active
            if (user != null && user.activeyn == true)
            {
                IdentityHelper.SignIn(manager, user, false);
                Response.Redirect("~/Management/dashboard");
            }
            else
            {
                MessageUserControl.ShowInfoMessage("Invalid username or password. If you have forgotten your account login, please contact your administrator.");
            }
        }
    }
Ejemplo n.º 9
0
    /*
     * CREATED:     A. Valberg		MAR 3 2018
     * MODIFIED:    H. Conant		MAR 5 2018
     *  - Updated method signature
     *  - Updated method body code
     *
     * RetrieveUnitList_Select()
     * This method retrieves the units of a care site specified by the user.
     *
     * 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.GetActiveCareSiteUnits()
     * MessageUserControl.ShowInfoMessage()
     * MessageUserControl.ShowErrorMessage()
     */
    protected void RetrieveUnitList_Select(object sender, EventArgs e)
    {
        if (CareSiteDDL.SelectedValue == "0")
        {
            MessageUserControl.ShowInfoMessage("Please select a care site.");
            UnitDDL.Items.Clear();
            UnitDDL.Items.Insert(0, new ListItem("Select...", "0"));
            AddUnitNameTB.Text           = "";
            UpdateUnitNameTB.Text        = "";
            DeactivateUnitNameLabel.Text = "";

            AddUnitRow.Visible          = false;
            ModifyUnitRow.Visible       = false;
            UpdateDeactivateRow.Visible = false;
        }
        else
        {
            try
            {
                int tempCareSiteId;
                int.TryParse(CareSiteDDL.SelectedValue, out tempCareSiteId);
                List <UnitDTO> tempUnitList = unitController.GetActiveCareSiteUnits(tempCareSiteId);
                UnitDDL.DataSource = tempUnitList;
                UnitDDL.DataBind();
                UnitDDL.Items.Insert(0, new ListItem("Select...", "0"));
                UnitDDL.SelectedValue = "0";

                // clear unit selections so user doesn't get confused and edit a unit in another care site
                AddUnitNameTB.Text           = "";
                UpdateUnitNameTB.Text        = "";
                DeactivateUnitNameLabel.Text = "";
                UpdateDeactivateRow.Visible  = false;
                AddUnitRow.Visible           = true;
                ModifyUnitRow.Visible        = true;
            }
            catch (Exception ex)
            {
                MessageUserControl.ShowErrorMessage("Retrieving units failed. Please try again. If error persists, please contact your administrator.", ex);
            }
        }
    }
Ejemplo n.º 10
0
    /*
     * 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);
                }
            }
        }
    }
Ejemplo n.º 11
0
    /*
     * 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);
            }
        }
    }
Ejemplo n.º 12
0
    /*
     * 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);
            }
        }
    }
Ejemplo n.º 13
0
    /*
     * 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).");
            }
        }
    }
Ejemplo n.º 14
0
    /*
     * 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.");
            }
        }
    }
Ejemplo n.º 15
0
    /*
     * 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();
                }
            }
        }
    }
Ejemplo n.º 16
0
    /*
     * 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.");
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 17
0
    /*
     * 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.");
                }
            }
        }
    }
Ejemplo n.º 18
0
    /*
     * 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.");
        }
    }