Esempio n. 1
0
    /*
     * CREATED:     H. Conant		MAR 13 2018
     *
     * RetrieveContactRequests_Click()
     * This method runs any code it contains when the "Retrieve Contact Requests" button is clicked.
     *
     * PARAMETERS:
     * object sender - object on the page that is being targeted
     * EventArgs e - event that has triggered the method
     *
     * RETURNS:
     * void - Nothing is returned
     *
     * METHOD CALLS:
     * List<int>()
     * List<string>()
     * DateTime()
     * List<bool>()
     * .Parse()
     * .FindControl()
     * .Add()
     * List<ContactRequestDTO>()
     * .ViewContactRequests()
     * .DataBind()
     */
    protected void RetrieveContactRequests_Click(object sender, EventArgs e)
    {
        UserMessage.Text = "";
        List <int>    unitIds  = new List <int>();
        List <string> genders  = new List <string>();
        List <string> ages     = new List <string>();
        DateTime      dateOne  = new DateTime();
        DateTime      dateTwo  = new DateTime();
        List <bool>   statuses = new List <bool>();


        dateOne = DateTime.Parse(dateStart.Value);
        dateTwo = DateTime.Parse(dateEnd.Value);

        if (dateOne == null || dateTwo == null || dateOne > dateTwo)
        {
            UserMessage.Text = "Please enter a vaild start and end date";
        }
        else
        {
            foreach (RepeaterItem item in UnitRepeater.Items)
            {
                CheckBox    tempCheckBox    = (CheckBox)item.FindControl("CheckBox");
                HiddenField tempHiddenField = (HiddenField)item.FindControl("HiddenUnitID");

                if (tempCheckBox.Checked == true)
                {
                    int tempUntId;
                    int.TryParse(tempHiddenField.Value, out tempUntId);
                    unitIds.Add(tempUntId);
                }
            }

            if (unitIds.Count < 1)
            {
                UserMessage.Text = "Please select at least one unit";
            }
            else
            {
                if (GenderFemale.Checked == true)
                {
                    genders.Add("F");
                }

                if (GenderMale.Checked == true)
                {
                    genders.Add("M");
                }

                if (GenderOther.Checked == true)
                {
                    genders.Add("O");
                }

                if (GenderPrefNotAns.Checked == true)
                {
                    genders.Add("N");
                }

                if (genders.Count < 1)
                {
                    UserMessage.Text = "Please select at least one gender";
                }
                else
                {
                    if (Age017.Checked == true)
                    {
                        ages.Add("0-17");
                    }

                    if (Age1834.Checked == true)
                    {
                        ages.Add("18-34");
                    }

                    if (Age3554.Checked == true)
                    {
                        ages.Add("35-54");
                    }

                    if (Age5574.Checked == true)
                    {
                        ages.Add("55-74");
                    }

                    if (Age75.Checked == true)
                    {
                        ages.Add("75+");
                    }

                    if (Age0.Checked == true)
                    {
                        ages.Add("0");
                    }

                    if (ages.Count < 1)
                    {
                        UserMessage.Text = "Please select at least one age range";
                    }
                    else
                    {
                        if (ProcessedY.Checked == true)
                        {
                            statuses.Add(true);
                        }

                        if (ProcessedN.Checked == true)
                        {
                            statuses.Add(false);
                        }

                        if (statuses.Count < 1)
                        {
                            UserMessage.Text = "Please select at least 'Processed' or 'Not processed'";
                        }
                        else
                        {
                            try
                            {
                                List <ContactRequestDTO> contactRequests = new List <ContactRequestDTO>();


                                contactRequests = surveyController.ViewContactRequests(unitIds, genders, ages, dateOne, dateTwo, statuses);

                                if (contactRequests.Count < 1)
                                {
                                    UserMessage.Text = "There are no contact requests that match the filers.";
                                }
                                else
                                {
                                    ResultCountLabel.Text = (contactRequests.Count).ToString();

                                    ContactRequestsRepeater.DataSource = contactRequests;
                                    ContactRequestsRepeater.DataBind();
                                }
                            } catch (Exception ex)
                            {
                                ErrorMessage.Text = "Retrieve contact requests failed. Please contact the system administrator.";
                            }
                        }
                    }
                }
            }
        }
    }
Esempio n. 2
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
     *
     * RetrieveContactRequests_Click()
     * This method runs any code it contains when the "Retrieve Contact Requests" 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.ShowInfoList()
     * SurveyController.ViewContactRequests()
     * MessageUserControl.ShowInfoMessage()
     * MessageUserControl.ShowErrorMessage()
     */
    protected void RetrieveContactRequests_Click(object sender, EventArgs e)
    {
        ResultCountLabel.Text = "0";
        List <string> message = new List <string>();

        ContactRequestsRepeater.DataSource = null;
        ContactRequestsRepeater.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();
        List <bool> statuses     = new List <bool>();

        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 tempUntId;
                int.TryParse(tempHiddenField.Value, out tempUntId);
                respodentIds.Add(tempUntId);
            }
        }

        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 (ProcessedY.Checked == true)
        {
            statuses.Add(true);
        }

        if (ProcessedN.Checked == true)
        {
            statuses.Add(false);
        }

        if (statuses.Count < 1)
        {
            message.Add("Please select at least one status 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 <ContactRequestDTO> contactRequests = new List <ContactRequestDTO>();

                if (dateStart.Value == "" && dateEnd.Value == "")
                {
                    contactRequests = surveyController.ViewContactRequests(unitIds, genders, ages, statuses, respodentIds);
                }
                else if (dateStart.Value == "" && dateEnd.Value != "")
                {
                    dateOne = DateTime.MinValue;

                    contactRequests = surveyController.ViewContactRequests(unitIds, genders, ages, dateOne, dateTwo, statuses, respodentIds);
                }
                else if (dateStart.Value != "" && dateEnd.Value == "")
                {
                    dateTwo         = DateTime.Today;
                    dateEnd.Value   = DateTime.Today.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);
                    contactRequests = surveyController.ViewContactRequests(unitIds, genders, ages, dateOne, dateTwo, statuses, respodentIds);
                }
                else
                {
                    contactRequests = surveyController.ViewContactRequests(unitIds, genders, ages, dateOne, dateTwo, statuses, respodentIds);
                }

                if (contactRequests.Count < 1)
                {
                    MessageUserControl.ShowInfoMessage("No contact requests found matching the entered search criteria.");
                }
                else
                {
                    ResultCountLabel.Text = (contactRequests.Count).ToString();

                    ContactRequestsRepeater.DataSource = contactRequests;
                    ContactRequestsRepeater.DataBind();
                }
            }
            catch (Exception ex)
            {
                MessageUserControl.ShowErrorMessage("Retrieving contact requests from the database failed. Please try again. If error persists, please contact your administrator.", ex);
            }
        }
    }