/// <summary>
        /// This method fires when the user clicks the Save button in the
        /// submitOtherSEScreen user control
        /// </summary>
        /// <param name="sender">The submitOtherSEScreen control</param>
        /// <param name="e">The Click event</param>
        protected void submitOtherSEScreen_Click(object sender, EventArgs e)
        {
            if (currentProgramRole.AllowedToEdit.Value)
            {
                //To hold the success message type
                string successMessageType = null;

                //Fill the OtherSEScreen fields from the form
                currentOtherSEScreen.ScreenDate       = deScreenDate.Date;
                currentOtherSEScreen.ScreenTypeCodeFK = Convert.ToInt32(ddScreenType.Value);
                currentOtherSEScreen.ChildFK          = Convert.ToInt32(ddChild.Value);
                currentOtherSEScreen.Score            = Convert.ToInt32(txtScore.Value);
                currentOtherSEScreen.ScoreTypeCodeFK  = Convert.ToInt32(ddScoreType.Value);

                if (currentOtherSEScreenPK > 0)
                {
                    //This is an edit
                    using (PyramidContext context = new PyramidContext())
                    {
                        //Set the success message
                        successMessageType = "OtherSEScreenEdited";

                        //Set the edit-only fields
                        currentOtherSEScreen.Editor   = User.Identity.Name;
                        currentOtherSEScreen.EditDate = DateTime.Now;

                        //Get the existing OtherSEScreen record
                        Models.OtherSEScreen existingASQ = context.OtherSEScreen.Find(currentOtherSEScreen.OtherSEScreenPK);

                        //Overwrite the existing OtherSEScreen record with the values from the form
                        context.Entry(existingASQ).CurrentValues.SetValues(currentOtherSEScreen);
                        context.SaveChanges();
                    }

                    //Redirect the user to the OtherSEScreen dashboard
                    Response.Redirect(string.Format("/Pages/OtherSEScreenDashboard.aspx?messageType={0}", successMessageType));
                }
                else
                {
                    //This is an add
                    using (PyramidContext context = new PyramidContext())
                    {
                        //Set the success message
                        successMessageType = "OtherSEScreenAdded";

                        //Set the create-only fields
                        currentOtherSEScreen.Creator    = User.Identity.Name;
                        currentOtherSEScreen.CreateDate = DateTime.Now;
                        currentOtherSEScreen.ProgramFK  = currentProgramRole.CurrentProgramFK.Value;

                        //Add the OtherSEScreen to the database
                        context.OtherSEScreen.Add(currentOtherSEScreen);
                        context.SaveChanges();
                    }

                    //Redirect the user to the OtherSEScreen dashboard
                    Response.Redirect(string.Format("/Pages/OtherSEScreenDashboard.aspx?messageType={0}", successMessageType));
                }
            }
        }
 /// <summary>
 /// This method populates the page controls from the passed OtherSEScreen object
 /// </summary>
 /// <param name="OtherSEScreenToPopulate">The OtherSEScreen object with values to populate the page controls</param>
 private void PopulatePage(Models.OtherSEScreen OtherSEScreenToPopulate)
 {
     //Set the page controls to the values from the object
     deScreenDate.Value        = OtherSEScreenToPopulate.ScreenDate;
     ddScreenType.SelectedItem = ddScreenType.Items.FindByValue(OtherSEScreenToPopulate.ScreenTypeCodeFK);
     ddChild.SelectedItem      = ddChild.Items.FindByValue(OtherSEScreenToPopulate.ChildFK);
     txtScore.Value            = OtherSEScreenToPopulate.Score;
     ddScoreType.SelectedItem  = ddScoreType.Items.FindByValue(OtherSEScreenToPopulate.ScoreTypeCodeFK);
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Get the user's current program role
            currentProgramRole = Utilities.GetProgramRoleFromSession(Session);

            //Get the OtherSEScreen PK from the query string
            if (!string.IsNullOrWhiteSpace(Request.QueryString["OtherSEScreenPK"]))
            {
                int.TryParse(Request.QueryString["OtherSEScreenPK"], out currentOtherSEScreenPK);
            }

            //Don't allow aggregate viewers into this page
            if (currentProgramRole.RoleFK.Value == (int)Utilities.ProgramRoleFKs.AGGREGATE_DATA_VIEWER)
            {
                Response.Redirect("/Pages/OtherSEScreenDashboard.aspx?messageType=NotAuthorized");
            }

            using (PyramidContext context = new PyramidContext())
            {
                //Get the OtherSEScreen from the database
                currentOtherSEScreen = context.OtherSEScreen.AsNoTracking()
                                       .Include(ose => ose.Program)
                                       .Where(ose => ose.OtherSEScreenPK == currentOtherSEScreenPK).FirstOrDefault();

                //Check to see if the OtherSEScreen from the database exists
                if (currentOtherSEScreen == null)
                {
                    //The OtherSEScreen from the database doesn't exist, set the current OtherSEScreen to a default value
                    currentOtherSEScreen = new Models.OtherSEScreen();

                    //Set the program label to the current user's program
                    lblProgram.Text = currentProgramRole.ProgramName;
                }
                else
                {
                    //Set the program label to the form's program
                    lblProgram.Text = currentOtherSEScreen.Program.ProgramName;
                }
            }

            //Prevent users from viewing OtherSEScreens from other programs
            if (currentOtherSEScreen.OtherSEScreenPK > 0 && !currentProgramRole.ProgramFKs.Contains(currentOtherSEScreen.ProgramFK))
            {
                Response.Redirect(string.Format("/Pages/OtherSEScreenDashboard.aspx?messageType={0}", "NOOtherSEScreen"));
            }

            //Get the proper program fk
            currentProgramFK = (currentOtherSEScreen.OtherSEScreenPK > 0 ? currentOtherSEScreen.ProgramFK : currentProgramRole.CurrentProgramFK.Value);

            //Set the max value for the form date
            deScreenDate.MaxDate = DateTime.Now;

            if (!IsPostBack)
            {
                //Hide the master page title
                ((Dashboard)this.Master).HideTitle();

                //Bind the dropdowns
                BindDropDowns();

                //Check to see if this is an edit
                if (currentOtherSEScreenPK > 0)
                {
                    //This is an edit
                    //Populate the page
                    PopulatePage(currentOtherSEScreen);
                }

                //Get the action from the query string
                string action;
                if (Request.QueryString["action"] != null)
                {
                    action = Request.QueryString["action"];
                }
                else
                {
                    action = "View";
                }

                //Allow adding/editing depending on the user's role and the action
                if (currentOtherSEScreen.OtherSEScreenPK == 0 && currentProgramRole.AllowedToEdit.Value)
                {
                    //Show the submit button
                    submitOtherSEScreen.ShowSubmitButton = true;

                    //Show certain controls
                    hfViewOnly.Value = "False";

                    //Enable page controls
                    EnableControls(true);

                    //Set the page title
                    lblPageTitle.Text = "Add New Other Social Emotional Screening";
                }
                else if (currentOtherSEScreen.OtherSEScreenPK > 0 && action.ToLower() == "edit" && currentProgramRole.AllowedToEdit.Value)
                {
                    //Show the submit button
                    submitOtherSEScreen.ShowSubmitButton = true;

                    //Show certain controls
                    hfViewOnly.Value = "False";

                    //Enable page controls
                    EnableControls(true);

                    //Set the page title
                    lblPageTitle.Text = "Edit Other Social Emotional Screening";
                }
                else
                {
                    //Hide the submit button
                    submitOtherSEScreen.ShowSubmitButton = false;

                    //Hide certain controls
                    hfViewOnly.Value = "True";

                    //Disable page controls
                    EnableControls(false);

                    //Set the page title
                    lblPageTitle.Text = "View Other Social Emotional Screening";
                }

                //Set focus on the screen date field
                deScreenDate.Focus();
            }
        }