コード例 #1
0
        public AccessCodeDTO GetCareSiteAccessCodeByDate(int careSiteID, DateTime date)
        {
            using (var context = new MSSContext())
            {
                // Note: unfortunately, because of Linq, the only way to compare dates without times is to compare each piece of the date (year, month, day) individually. Linq does not allow the .Date function in its queries and therefore cannot be used.
                var accessCode = from aCareSiteAccess in context.caresiteaccesses
                                 where aCareSiteAccess.caresiteid == careSiteID && aCareSiteAccess.dateused.Year == date.Year && aCareSiteAccess.dateused.Month == date.Month && aCareSiteAccess.dateused.Day == date.Day
                                 select aCareSiteAccess;

                // using .First() here because this search should only return ONE CareSiteAccess item
                AccessCodeDTO selectedCode = new AccessCodeDTO();
                if (accessCode.Count() == 0)
                {
                    selectedCode.accesscodeid = -3;
                }
                else
                {
                    selectedCode.accesscodeid   = accessCode.First().accesscodeid;
                    selectedCode.accesscodeword = accessCode.First().accesscode.accesscodeword;
                    selectedCode.activeyn       = accessCode.First().accesscode.activeyn;
                }

                return(selectedCode);
            }
        }
コード例 #2
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).");
        }
    }
コード例 #3
0
        public List <AccessCodeDTO> GetAccessCodesByExactMatch(string matchString, bool?activeStatus)
        {
            using (var context = new MSSContext())
            {
                IQueryable <accesscode> accessCodes = null;
                if (!activeStatus.HasValue) // return all regardless of status
                {
                    accessCodes = from item in context.accesscodes
                                  where item.accesscodeword.Equals(matchString)
                                  orderby item.accesscodeword ascending
                                  select item;
                }
                else // filter by status
                {
                    accessCodes = from item in context.accesscodes
                                  where item.activeyn == activeStatus && item.accesscodeword.Equals(matchString)
                                  orderby item.accesscodeword ascending
                                  select item;
                }

                List <AccessCodeDTO> accessCodeDTOs = new List <AccessCodeDTO>();
                foreach (accesscode code in accessCodes)
                {
                    AccessCodeDTO temp = new AccessCodeDTO();
                    temp.accesscodeid   = code.accesscodeid;
                    temp.accesscodeword = code.accesscodeword;
                    temp.activeyn       = code.activeyn;
                    accessCodeDTOs.Add(temp);
                }
                return(accessCodeDTOs);
            }
        }
コード例 #4
0
    /*
     * CREATED:    C. Stanhope         MAR 19 2018
     * MODIFIED:   C. Stanhope         MAR 21 2018
     *  - changed error handling
     *  - changed selectedAccessCode to reflect globalization of variable
     * MODIFIED:   C. Stanhope         APR 6 2018
     *  - accounting for non-distinct access codes
     *
     * AccessCodeWordButton_Click()
     * Triggered when a "AccessCodeWordButton" is clicked from the list of code words and is used to determine which code word was clicked on. The Update Access Code Word section is appropriately populated depending on which code was selected.
     *
     * 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()
     */
    protected void AccessCodeWordButton_Click(object sender, EventArgs e)
    {
        #region Getting information from page about selected word
        LinkButton wordButton   = (LinkButton)sender;
        string     selectedWord = wordButton.Text;
        bool       selectedWordStatus;

        if (wordButton.CssClass.Contains("false"))
        {
            selectedWordStatus = false;
        }
        else
        {
            selectedWordStatus = true;
        }
        #endregion

        // make sure accessCodeList isn't empty and isn't null, which should never happen
        if (accessCodeList != null && accessCodeList.Count() != 0)
        {
            // find item in code word array
            var selectedAccessCodeList = from item in accessCodeList
                                         where item.accesscodeword == selectedWord && item.activeyn == selectedWordStatus
                                         select item;

            if (selectedAccessCodeList.Count() > 0) // make sure access code is found (should always find at least one)
            {
                selectedAccessCode = selectedAccessCodeList.First();

                #region populate update textbox and radio buttons to match selected access code
                UpdateAccessCodeTextBox.Text = selectedWord;

                if (selectedAccessCode.activeyn) // if word is active
                {
                    UpdateAccessActiveStatusCodeRadioButtonList.Items.FindByText("inactive").Selected = false;
                    UpdateAccessActiveStatusCodeRadioButtonList.Items.FindByText("active").Selected   = true;
                }
                else
                {
                    UpdateAccessActiveStatusCodeRadioButtonList.Items.FindByText("active").Selected   = false;
                    UpdateAccessActiveStatusCodeRadioButtonList.Items.FindByText("inactive").Selected = true;
                }

                // display update box
                UpdateAccessCodeContainer.Visible = true;
                #endregion
            }
            else // if no access code matches
            {
                MessageUserControl.ShowErrorMessage("The selected access code could not be found in the access code list. Please clear the search and try again. If error persists, please contact your administrator.");
            }
        }
        else // if accessCodeList is empty or null
        {
            MessageUserControl.ShowErrorMessage("An access code was selected but no access codes are being displayed. Please try again. If error persists, please contact your administrator.");
        }
    }
コード例 #5
0
    /*
     * CREATED:     P. Chavez		MAR 29 2018
     * MODIFIED:   C. Stanhope     APR 6 2018
     *  - added try-catch for database access
     * MODIFIED:   C. Stanhope     APR 14 2018
     *  - codes will show themselves independent of each other. You no longer need to have today's code AND tomorrow's code, any that have been generated will be displayed.
     *
     * DisplayAccessCodes()
     * Displays today's and tomorrow's access codes for a care site based on the care site ID passed.
     *
     * PARAMETERS:
     * int careSiteId - the ID of the care site
     *
     * RETURNS:
     * void
     *
     * ODEV METHOD CALLS:
     * MessageUserControl.ShowErrorMessage()
     * CareSiteAccessController.GetCareSiteAccessCodeByDate()
     */
    private void DisplayAccessCodes(int careSiteId)
    {
        try
        {
            // get access codes by today's and tomorrow's dates and the selected caresite
            AccessCodeDTO accessCodeToday    = careSiteAccessController.GetCareSiteAccessCodeByDate(careSiteId, DateTime.Now);
            AccessCodeDTO accessCodeTomorrow = careSiteAccessController.GetCareSiteAccessCodeByDate(careSiteId, DateTime.Now.AddDays(1));

            bool anActiveCodeExists = false;

            #region checking and assigning today's code
            if (accessCodeToday.accesscodeid == -3)
            {
                MessageUserControl.ShowErrorMessage("Today's code is not yet generated. Please return to the dashboard (welcome page) and navigate back to this page. If the error persists, please contact your administrator.");
                TodaysCard.Visible = false;
            }
            else // Today's code exists
            {
                CodeCards.Visible  = true;
                TodaysCard.Visible = true;

                anActiveCodeExists  = true;
                TodayCodeLabel.Text = accessCodeToday.accesscodeword;
                TodayDateLabel.Text = DateTime.Now.ToString("MMM d, yyyy");
            }
            #endregion

            #region checking and assigning tomorrow's code
            if (accessCodeTomorrow.accesscodeid == -3)
            {
                MessageUserControl.ShowErrorMessage("Tomorrow's code is not yet generated. Please return to the dashboard (welcome page) and navigate back to this page. If the error persists, please contact your administrator.");
                TomorrowsCard.Visible = false;
            }
            else // Tomorrow's code exists
            {
                CodeCards.Visible     = true;
                TomorrowsCard.Visible = true;

                anActiveCodeExists     = true;
                TomorrowCodeLabel.Text = accessCodeTomorrow.accesscodeword;
                TomorrowDateLabel.Text = DateTime.Now.AddDays(1).ToString("MMM d, yyyy");
            }
            #endregion

            if (!anActiveCodeExists) // neither code has been generated
            {
                MessageUserControl.ShowErrorMessage("Today's and tomorrow's codes are not yet generated. Please return to the dashboard (welcome page) and navigate back to this page. If the error persists, please contact your administrator.");
                CodeCards.Visible = false;
            }
        }
        catch (Exception ex)
        {
            MessageUserControl.ShowErrorMessage("Retrieving access codes from the database failed. Please try again. If error persists, please contact your administrator.", ex);
        }
    }
コード例 #6
0
 public void UpdateAccessCode(AccessCodeDTO tempCode)
 {
     using (var context = new MSSContext())
     {
         var accessCode = context.accesscodes.Find(tempCode.accesscodeid);
         accessCode.accesscodeword = tempCode.accesscodeword;
         var existingCode = context.Entry(accessCode);
         existingCode.State = EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #7
0
 public void AddAccessCode(AccessCodeDTO tempCode)
 {
     using (var context = new MSSContext())
     {
         accesscode newAccessCode = new accesscode();
         newAccessCode.accesscodeword = tempCode.accesscodeword.ToLower();
         newAccessCode.activeyn       = true;
         context.accesscodes.Add(newAccessCode);
         context.SaveChanges();
     }
 }
コード例 #8
0
    /*
     * CREATED:      C. Stanhope         MAR 13 2018
     *
     * 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
     *
     * METHOD CALLS:
     * AccessCodeController.AddAccessCode()
     * MessageUserControl.ShowSuccessMessage()
     */
    protected void AddAccessCodeButton_Click(object sender, EventArgs e)
    {
        AccessCodeDTO newAccessCode = new AccessCodeDTO();

        newAccessCode.accesscodeword = AddAccessCodeTB.Text;
        newAccessCode.activeyn       = true; // defaults to active

        accessCodeController.AddAccessCode(newAccessCode);

        MessageUserControl.ShowSuccessMessage("New access code added!");
        ClearPage();
    }
コード例 #9
0
 public List <AccessCodeDTO> GetAccessCodes()
 {
     using (var context = new MSSContext())
     {
         var accessCodes = from item in context.accesscodes
                           where item.activeyn == true
                           select item;
         List <AccessCodeDTO> accessCodeDTOs = new List <AccessCodeDTO>();
         foreach (accesscode code in accessCodes)
         {
             AccessCodeDTO temp = new AccessCodeDTO();
             temp.accesscodeid   = code.accesscodeid;
             temp.accesscodeword = code.accesscodeword;
             temp.activeyn       = true;
             accessCodeDTOs.Add(temp);
         }
         return(accessCodeDTOs);
     }
 }
コード例 #10
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
     *
     * METHOD CALLS:
     * MessageUserControl.ShowErrorMessage()
     * int.TryParse()
     * DateTime.Now()
     * DateTime.AddDays()
     * ToString()
     */
    protected void CareSiteDDL_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (CareSiteDDL.SelectedIndex == 0)
        {
            MessageUserControl.ShowErrorMessage("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))
            {
                // get access codes by today's and tomorrow's dates and the selected caresite
                AccessCodeDTO accessCodeToday    = careSiteAccessController.GetCareSiteAccessCodeByDate(selectedCareSiteID, DateTime.Now);
                AccessCodeDTO accessCodeTomorrow = careSiteAccessController.GetCareSiteAccessCodeByDate(selectedCareSiteID, DateTime.Now.AddDays(1));

                if (accessCodeToday.accesscodeid == -3)
                {
                    MessageUserControl.ShowErrorMessage("Today's code not yet generated. Please contact the administrator.");
                    CodeCards.Visible = false;
                }
                else if (accessCodeTomorrow.accesscodeid == -3)
                {
                    MessageUserControl.ShowErrorMessage("Tomorrows's code not generated. Please contact the administrator.");
                    CodeCards.Visible = false;
                }
                else // today's and tomorrow's codes are generated and displayed
                {
                    TodayCodeLabel.Text    = accessCodeToday.accesscodeword;
                    TomorrowCodeLabel.Text = accessCodeTomorrow.accesscodeword;

                    TodayDateLabel.Text    = DateTime.Now.ToString("MMM d, yyyy");
                    TomorrowDateLabel.Text = DateTime.Now.AddDays(1).ToString("MMM d, yyyy");

                    CodeCards.Visible = true;
                }
            }
            else // the tryparse of the care site ID didn't work
            {
                MessageUserControl.ShowErrorMessage("Something failed. Please contact the administrator.");
            }
        }
    }
コード例 #11
0
        public List <AccessCodeDTO> GetAccessCodesByKeyword(string keyword)
        {
            using (var context = new MSSContext())
            {
                IQueryable <accesscode> accessCodes = null;
                if (string.IsNullOrEmpty(keyword)) // empty keyword, return all active
                {
                    accessCodes = from item in context.accesscodes
                                  where item.activeyn == true
                                  orderby item.accesscodeword ascending
                                  select item;
                }
                else if (keyword.Contains("_")) // search for only the first letter
                {
                    string startingLetter = keyword[0].ToString().ToLower();

                    accessCodes = from item in context.accesscodes
                                  where item.activeyn == true && item.accesscodeword.StartsWith(startingLetter)
                                  orderby item.accesscodeword ascending
                                  select item;
                }
                else // search to match keyword if the keyword variable is not empty
                {
                    accessCodes = from item in context.accesscodes
                                  where item.activeyn == true && item.accesscodeword.Contains(keyword.ToLower())
                                  orderby item.accesscodeword ascending
                                  select item;
                }

                List <AccessCodeDTO> accessCodeDTOs = new List <AccessCodeDTO>();
                foreach (accesscode code in accessCodes)
                {
                    AccessCodeDTO temp = new AccessCodeDTO();
                    temp.accesscodeid   = code.accesscodeid;
                    temp.accesscodeword = code.accesscodeword;
                    temp.activeyn       = true;
                    accessCodeDTOs.Add(temp);
                }
                return(accessCodeDTOs);
            }
        }
コード例 #12
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.");
            }
        }
    }