protected bool FCommitMedicalInfo()
        {
            Page.Validate("valPilotInfo");
            if (!Page.IsValid)
            {
                return(false);
            }

            m_pf.LastMedical     = dateMedical.Date;
            m_pf.MonthsToMedical = MonthsToMedical;
            m_pf.UsesICAOMedical = UsesICAOMedical;

            try
            {
                // Type of medical, notes, and date of birth are all set synchronously.
                ProfileCurrency _ = new ProfileCurrency(m_pf)
                {
                    TypeOfMedical = (MedicalType)Enum.Parse(typeof(MedicalType), cmbMedicalType.SelectedValue)
                };
                m_pf.SetPreferenceForKey(MFBConstants.keyMedicalNotes, txtMedicalNotes.Text, String.IsNullOrWhiteSpace(txtMedicalNotes.Text));
                m_pf.DateOfBirth = dateDOB.Date;

                m_pf.FCommit();
                UpdateNextMedical();
            }
            catch (MyFlightbookException ex)
            {
                lblMedicalInfo.Visible  = true;
                lblMedicalInfo.Text     = ex.Message;
                lblMedicalInfo.CssClass = "error";
                return(false);
            }

            return(true);
        }
        protected void UpdateForMedicalType(MedicalType mt)
        {
            bool fNeedsDOB = ProfileCurrency.RequiresBirthdate(mt);

            rowDOB.Visible           = valDOBRequired.Enabled = fNeedsDOB;
            rowOtherMedical.Visible  = mt == MedicalType.Other;
            valMonthsMedical.Enabled = !fNeedsDOB;
        }
 protected void valDOBRequired_ServerValidate(object source, ServerValidateEventArgs args)
 {
     if (args == null)
     {
         throw new ArgumentNullException(nameof(args));
     }
     // all is good if we have no medical (by definition doesn't require DOB), a medical type that doesn't require a birthday, or if we have a DOB.
     args.IsValid = (!dateMedical.Date.HasValue() || !ProfileCurrency.RequiresBirthdate(SelectedMedicalType) || dateDOB.Date.HasValue());;
 }
        private void UpdateNextMedical()
        {
            Page.Validate("valPilotInfo");
            if (!Page.IsValid)
            {
                return;
            }

            IEnumerable <CurrencyStatusItem> rgcs = ProfileCurrency.MedicalStatus(dateMedical.Date, MonthsToMedical, SelectedMedicalType, dateDOB.Date, UsesICAOMedical);

            if (rgcs.Any())
            {
                pnlNextMedical.Visible    = true;
                rptNextMedical.DataSource = rgcs;
                rptNextMedical.DataBind();
            }
            else
            {
                pnlNextMedical.Visible = false;
            }
        }
        public void InitPilotInfo()
        {
            mfbEASATip.BodyContent = Branding.ReBrand(Resources.Preferences.MedicalEASATip);
            dateMedical.Date       = m_pf.LastMedical;
            dateMedical.TextControl.ValidationGroup = "valPilotInfo";
            MonthsToMedical = m_pf.MonthsToMedical;
            MedicalType mt = new ProfileCurrency(m_pf).TypeOfMedical;

            SelectedMedicalType = mt;
            dateDOB.Date        = m_pf.DateOfBirth ?? DateTime.MinValue;
            UpdateForMedicalType(mt);
            UsesICAOMedical = m_pf.UsesICAOMedical;
            UpdateNextMedical();
            txtCertificate.Text             = m_pf.Certificate;
            txtLicense.Text                 = m_pf.License;
            txtLicense.Attributes["dir"]    = txtCertificate.Attributes["dir"] = "auto";
            txtMedicalNotes.Text            = m_pf.GetPreferenceForKey(MFBConstants.keyMedicalNotes) ?? string.Empty;
            mfbTypeInDateCFIExpiration.Date = m_pf.CertificateExpiration;
            mfbDateEnglishCheck.Date        = m_pf.EnglishProficiencyExpiration;
            BasicMedManager.RefreshBasicMedEvents();

            gvIPC.DataSource = ProfileEvent.GetIPCEvents(Page.User.Identity.Name);
            gvIPC.DataBind();

            Achievements.UserRatings ur = new Achievements.UserRatings(m_pf.UserName);
            gvRatings.DataSource = ur.Licenses;
            gvRatings.DataBind();

            ProfileCurrency mc = new ProfileCurrency(m_pf);

            ProfileEvent[] rgpfeBFR = ProfileEvent.GetBFREvents(Page.User.Identity.Name, mc.LastBFREvent);

            gvBFR.DataSource = rgpfeBFR;
            gvBFR.DataBind();

            if (rgpfeBFR.Any()) // we have at least one BFR event, so the first one should be the most recent.
            {
                lblNextBFR.Text    = ProfileCurrency.NextBFR(rgpfeBFR[0].Date).ToShortDateString();
                pnlNextBFR.Visible = true;
            }

            string szPane = Request["pane"];

            if (!String.IsNullOrEmpty(szPane))
            {
                for (int i = 0; i < accordianPilotInfo.Panes.Count; i++)
                {
                    switch (szPane)
                    {
                    case "medical":
                        if (accordianPilotInfo.Panes[i] == acpMedical)
                        {
                            accordianPilotInfo.SelectedIndex = i;
                        }
                        break;

                    case "certificates":
                        if (accordianPilotInfo.Panes[i] == acpCertificates)
                        {
                            accordianPilotInfo.SelectedIndex = i;
                        }
                        break;

                    case "flightreview":
                        if (accordianPilotInfo.Panes[i] == acpFlightReviews)
                        {
                            accordianPilotInfo.SelectedIndex = i;
                        }
                        break;

                    case "ipc":
                        if (accordianPilotInfo.Panes[i] == acpIPCs)
                        {
                            accordianPilotInfo.SelectedIndex = i;
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }