/// <summary>
        /// This method returns the ChildProgram object filled with information from
        /// the inputs in this control so that the content page can interact with it
        /// </summary>
        /// <returns>The filled ChildProgram object if validation succeeds, null otherwise</returns>
        public Models.ChildProgram GetChildProgram()
        {
            if (ASPxEdit.AreEditorsValid(this, ValidationGroup))
            {
                //Get the ChildProgram pk
                int childProgramPK = Convert.ToInt32(hfChildProgramPK.Value);

                //To hold the ChildProgram object
                Models.ChildProgram childProgram;

                //Determine if the object already exists
                if (childProgramPK > 0)
                {
                    using (PyramidContext context = new PyramidContext())
                    {
                        childProgram = context.ChildProgram.AsNoTracking().Where(cp => cp.ChildProgramPK == childProgramPK).FirstOrDefault();
                    }
                }
                else
                {
                    childProgram = new Models.ChildProgram();
                }

                //Set the values
                childProgram.ProgramFK              = Convert.ToInt32(hfProgramFK.Value);
                childProgram.EnrollmentDate         = Convert.ToDateTime(deEnrollmentDate.Value);
                childProgram.DischargeDate          = (deDischargeDate.Value == null ? (DateTime?)null : Convert.ToDateTime(deDischargeDate.Value));
                childProgram.DischargeCodeFK        = (ddDischargeReason.Value == null ? (int?)null : Convert.ToInt32(ddDischargeReason.Value));
                childProgram.DischargeReasonSpecify = (txtDischargeReasonSpecify.Value == null ? null : txtDischargeReasonSpecify.Value.ToString());
                childProgram.ProgramSpecificID      = txtProgramID.Value.ToString();
                childProgram.HasIEP = Convert.ToBoolean(ddIEP.Value);
                childProgram.IsDLL  = Convert.ToBoolean(ddDLL.Value);

                //Return the object
                return(childProgram);
            }
            else
            {
                if (String.IsNullOrWhiteSpace(ValidationMessageToDisplay))
                {
                    ValidationMessageToDisplay = "Validation failed, see above for details!";
                }
                return(null);
            }
        }
        /// <summary>
        /// This method takes a primary key and it fills the inputs in the
        /// control with the information in the Child table for that primary key
        /// </summary>
        /// <param name="childProgramPK">The primary key of the ChildProgram record</param>
        /// <param name="programFK">The primary key for the program which this child will be in</param>
        /// <param name="readOnly">True if the user is only allowed to view the values</param>
        public void InitializeWithData(int childProgramPK, int programFK, bool readOnly)
        {
            using (PyramidContext context = new PyramidContext())
            {
                //Fill the Gender drop-down
                var genders = context.CodeGender.AsNoTracking().OrderBy(cg => cg.OrderBy).ToList();
                ddGender.DataSource = genders;
                ddGender.DataBind();

                //Fill the Ethnicity drop-down
                var ethnicities = context.CodeEthnicity.AsNoTracking().OrderBy(ce => ce.OrderBy).ToList();
                ddEthnicity.DataSource = ethnicities;
                ddEthnicity.DataBind();

                //Fill the Race drop-down
                var races = context.CodeRace.AsNoTracking().OrderBy(cr => cr.OrderBy).ToList();
                ddRace.DataSource = races;
                ddRace.DataBind();

                //Fill the Discharge Reason drop-down
                var dischargeReasons = context.CodeDischargeReason.AsNoTracking().OrderBy(cdr => cdr.OrderBy).ToList();
                ddDischargeReason.DataSource = dischargeReasons;
                ddDischargeReason.DataBind();

                //Fill the used IDs hidden field
                var usedIDs = context.ChildProgram
                              .AsNoTracking()
                              .Where(cp => cp.ProgramFK == programFK && cp.ChildProgramPK != childProgramPK)
                              .OrderBy(cp => cp.ProgramSpecificID)
                              .Select(cp => cp.ProgramSpecificID)
                              .ToList();
                hfUsedIDs.Value = string.Join(",", usedIDs);

                //Set the program fk hidden field
                hfProgramFK.Value = programFK.ToString();

                if (childProgramPK > 0)
                {
                    //If this is an edit, fill the form with the child's information
                    //Get the objects
                    Models.ChildProgram childProgram = context.ChildProgram.AsNoTracking()
                                                       .Include(cp => cp.Child)
                                                       .Where(cp => cp.ChildProgramPK == childProgramPK)
                                                       .FirstOrDefault();
                    Models.Child child = (childProgram == null ? new Models.Child() : childProgram.Child);

                    //Fill the hidden fields
                    hfChildPK.Value        = child.ChildPK.ToString();
                    hfChildProgramPK.Value = childProgram.ChildProgramPK.ToString();

                    //Fill the input fields
                    txtFirstName.Value              = child.FirstName;
                    txtLastName.Value               = child.LastName;
                    deDOB.Value                     = child.BirthDate.ToString("MM/dd/yyyy");
                    txtProgramID.Value              = childProgram.ProgramSpecificID;
                    deEnrollmentDate.Value          = childProgram.EnrollmentDate.ToString("MM/dd/yyyy");
                    ddGender.SelectedItem           = ddGender.Items.FindByValue(child.GenderCodeFK);
                    ddEthnicity.SelectedItem        = ddEthnicity.Items.FindByValue(child.EthnicityCodeFK);
                    ddRace.SelectedItem             = ddRace.Items.FindByValue(child.RaceCodeFK);
                    ddDLL.SelectedItem              = ddDLL.Items.FindByValue(childProgram.IsDLL);
                    ddIEP.SelectedItem              = ddIEP.Items.FindByValue(childProgram.HasIEP);
                    deDischargeDate.Value           = (childProgram.DischargeDate.HasValue ? childProgram.DischargeDate.Value.ToString("MM/dd/yyyy") : "");
                    ddDischargeReason.SelectedItem  = ddDischargeReason.Items.FindByValue(childProgram.DischargeCodeFK);
                    txtDischargeReasonSpecify.Value = childProgram.DischargeReasonSpecify;
                }

                //Set the controls usability
                txtFirstName.ReadOnly              = readOnly;
                txtLastName.ReadOnly               = readOnly;
                deDOB.ReadOnly                     = readOnly;
                txtProgramID.ReadOnly              = readOnly;
                deEnrollmentDate.ReadOnly          = readOnly;
                ddGender.ReadOnly                  = readOnly;
                ddEthnicity.ReadOnly               = readOnly;
                ddRace.ReadOnly                    = readOnly;
                ddDLL.ReadOnly                     = readOnly;
                ddIEP.ReadOnly                     = readOnly;
                deDischargeDate.ReadOnly           = readOnly;
                ddDischargeReason.ReadOnly         = readOnly;
                txtDischargeReasonSpecify.ReadOnly = readOnly;
            }
        }