示例#1
0
    /// <summary>
    /// find the longest country prefix that matches for this aircraft
    /// </summary>
    protected void SetUpCountryCode()
    {
        if (m_ac.IsNew)
        {
            string[] rgLocale = Request.UserLanguages;
            if (rgLocale != null && rgLocale.Length > 0 && rgLocale[0].Length > 4)
            {
                cmbCountryCode.SelectedValue = CountryCodePrefix.DefaultCountryCodeForLocale(Request.UserLanguages[0].Substring(3, 2)).HyphenatedPrefix;
            }
            else
            {
                cmbCountryCode.SelectedIndex = 0;
            }
            UpdateMask();
        }
        else
        {
            string szTail = m_ac.TailNumber;

            CountryCodePrefix ccp      = CountryCodePrefix.BestMatchCountryCode(szTail);
            string            szPrefix = ccp.HyphenatedPrefix;

            if (szPrefix.Length > 0) // Should be!
            {
                szTail = szTail.Substring(szPrefix.Length);
                cmbCountryCode.SelectedValue = (ccp.IsSim) ? CountryCodePrefix.DefaultCountryCodeForLocale(Request.UserLanguages[0].Substring(3, 2)).HyphenatedPrefix : szPrefix;
                UpdateMask();
            }
            else
            {
                cmbCountryCode.SelectedValue = String.Empty;
            }
        }
    }
示例#2
0
    protected void ValidateTailNum(object sender, ServerValidateEventArgs args)
    {
        if (args == null)
        {
            throw new ArgumentNullException("args");
        }

        string szNormalTail = Aircraft.NormalizeTail(txtTail.Text);

        // ensure that there is more than just the country code that is specified by the drop-down
        if (txtTail.Text.Length == 0 || String.Compare(szNormalTail, Aircraft.NormalizeTail(cmbCountryCode.SelectedValue), StringComparison.CurrentCultureIgnoreCase) == 0)
        {
            args.IsValid = false;
        }

        CountryCodePrefix cc = CountryCodePrefix.BestMatchCountryCode(txtTail.Text);

        if (cc.Prefix.Length == 0 && !String.IsNullOrEmpty(cmbCountryCode.SelectedValue))
        {
            args.IsValid = false;
        }

        // Ensure that what's there is more than the country code
        if (String.Compare(szNormalTail, cc.NormalizedPrefix, StringComparison.CurrentCultureIgnoreCase) == 0)
        {
            args.IsValid = false;
        }
    }
示例#3
0
 protected void Page_Init(object sender, EventArgs e)
 {
     // For efficiency of viewstate, we repopulate country code on each postback.
     cmbCountryCode.DataSource = CountryCodePrefix.CountryCodes();
     cmbCountryCode.DataBind();
     hdnSimCountry.Value = CountryCodePrefix.szSimPrefix; // hack, but avoids "CA1303:Do not pass literals as localized parameters" warning.
 }
        protected void gvCountryCodes_RowCommand(object sender, CommandEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            if (e.CommandName.CompareCurrentCultureIgnoreCase("fixHyphens") == 0)
            {
                hdnLastCountryEdited.Value = e.CommandArgument.ToString();

                CountryCodePrefix ccp = new List <CountryCodePrefix>(CountryCodePrefix.CountryCodes()).Find(ccp1 => ccp1.Prefix.CompareCurrentCultureIgnoreCase(hdnLastCountryEdited.Value) == 0);
                if (ccp != null)
                {
                    hdnLastCountryResult.Value = String.Format(CultureInfo.CurrentCulture, "{0} aircraft updated", ccp.ADMINNormalizeMatchingAircraft());
                    gvCountryCodes.DataBind();
                }
            }
        }
        protected void ValidateSim(object sender, ServerValidateEventArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }
            CountryCodePrefix     cc  = CountryCodePrefix.BestMatchCountryCode(txtTail.Text);
            AircraftInstanceTypes ait = SelectedInstanceType;

            if (ait == AircraftInstanceTypes.RealAircraft && cc.IsSim)
            {
                args.IsValid = false;
            }

            if (ait != AircraftInstanceTypes.RealAircraft && !cc.IsSim)
            {
                args.IsValid = false;
            }
        }
示例#6
0
    private void AdjustForRealOrAnonymous(bool fRealAircraft, bool fIsAnonymous, bool fHasModelSpecified, CountryCodePrefix cc)
    {
        if (fRealAircraft)
        {
            if (fIsAnonymous)
            {
                lblAnonTailDisplay.Text = m_ac.TailNumber = txtTail.Text = (fHasModelSpecified) ? Aircraft.AnonymousTailnumberForModel(m_ac.ModelID) : String.Empty;
                pnlAnonTail.Visible     = (fHasModelSpecified);
            }
            else
            {
                if (cc.IsSim || cc.IsAnonymous)   // reset tail if switching from sim or anonymous
                {
                    m_ac.TailNumber = cmbCountryCode.SelectedItem.Value;
                }
                else
                {
                    m_ac.TailNumber = CountryCodePrefix.SetCountryCodeForTail(new CountryCodePrefix(cmbCountryCode.SelectedItem.Text, cmbCountryCode.SelectedValue), txtTail.Text);
                }
                txtTail.Text = HttpUtility.HtmlEncode(m_ac.TailNumber);
            }

            mvRealAircraft.SetActiveView(fIsAnonymous ? vwAnonTail : vwRegularTail);
            valTailNumber.Enabled = fIsAnonymous;
            FixFAALink();
        }
        else
        {
            // Sim
            if (fHasModelSpecified)
            {
                m_ac.TailNumber = Aircraft.SuggestSims(m_ac.ModelID, m_ac.InstanceType)[0].TailNumber;
            }
            vwSimTailDisplay.SetActiveView(fHasModelSpecified ? vwHasModel : vwNoModel);

            lblSimTail.Text = txtTail.Text = m_ac.TailNumber;
        }
    }
        protected void gvCountryCodes_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (sender == null)
            {
                throw new ArgumentNullException(nameof(sender));
            }

            GridView        gv  = (GridView)sender;
            RadioButtonList rbl = (RadioButtonList)gv.Rows[e.RowIndex].FindControl("rblTemplateType");

            sqlDSCountryCode.UpdateParameters["templateType"].DefaultValue = rbl.SelectedValue;
            rbl = (RadioButtonList)gv.Rows[e.RowIndex].FindControl("rblHyphenPref");
            sqlDSCountryCode.UpdateParameters["hyphenpref"].DefaultValue = rbl.SelectedValue;
            sqlDSCountryCode.Update();

            gv.EditIndex = -1;
            CountryCodePrefix.FlushCache();
            gv.DataBind();
        }
示例#8
0
    protected void SyncTailToCountry()
    {
        bool fChangedTail    = hdnLastTail.Value.CompareCurrentCultureIgnoreCase(txtTail.Text) != 0;
        bool fChangedCountry = hdnLastCountry.Value.CompareCurrentCultureIgnoreCase(cmbCountryCode.SelectedValue) != 0;

        if (!fChangedTail && !fChangedCountry)
        {
            return;
        }

        if (fChangedCountry)
        {
            UpdateMask();
            FixFAALink();
        }
        else if (fChangedTail)
        {
            // sync the countrycode to the tail.  Note that we set hdnLastCountry.Value here as well to prevent a potential loop.
            cmbCountryCode.SelectedValue = hdnLastCountry.Value = CountryCodePrefix.BestMatchCountryCode(txtTail.Text).HyphenatedPrefix;
        }
        hdnLastCountry.Value = cmbCountryCode.SelectedValue;
        hdnLastTail.Value    = txtTail.Text;
    }
 protected void UpdateMask()
 {
     txtTail.Text = HttpUtility.HtmlEncode(CountryCodePrefix.SetCountryCodeForTail(new CountryCodePrefix(cmbCountryCode.SelectedItem.Text, cmbCountryCode.SelectedValue), txtTail.Text));
 }
        protected void SaveChanges()
        {
            lblError.Text = string.Empty;
            string szTailNew      = txtTail.Text.ToUpper(CultureInfo.CurrentCulture);
            int    AircraftIDOrig = AircraftID;

            Aircraft ac = AircraftToEdit;

            // Rules for how we want to handle a tailnumber edit
            // a) New aircraft - no issue (Commit will match to an existing aircraft as needed)
            // b) Existing aircraft with no other users: go ahead and change the aircraft.
            // c) Existing aircraft with other users: Treat as a new aircraft with the specified model; after commit, do any replacement as necessary
            // In other words, migrate the user to another aircraft if we are editing an existing aircraft, changing the tail, and there are other users.
            bool fChangedTail  = (String.Compare(Aircraft.NormalizeTail(ac.TailNumber), Aircraft.NormalizeTail(szTailNew), StringComparison.CurrentCultureIgnoreCase) != 0);
            bool fIsNew        = ac.IsNew;
            bool fChangedModel = ac.ModelID != SelectedModelID;

            UserAircraft ua = new UserAircraft(Page.User.Identity.Name);

            // check if this isn't already in our aircraft list
            int addToUserCount = (!fIsNew && fChangedModel && !AdminMode && ua[m_ac.AircraftID] == null) ? 1 : 0;

            bool fOtherUsers  = !fIsNew && (fChangedTail || fChangedModel) && (new AircraftStats(Page.User.Identity.Name, m_ac.AircraftID)).Users + addToUserCount > 1;  // no need to compute user stats if new, or if tail and model are both unchanged
            bool fMigrateUser = (!fIsNew && fChangedTail && fOtherUsers);

            // Check for model change without tail number change on an existing aircraft
            if (!AdminMode && !fIsNew && !fChangedTail && fChangedModel && fOtherUsers && ac.HandlePotentialClone(SelectedModelID, Page.User.Identity.Name))
            {
                Response.Redirect("~/Member/Aircraft.aspx");
                return;
            }

            // set the tailnumber regardless, using appropriate hyphenation (if hyphenation is specified)
            CountryCodePrefix cc = CountryCodePrefix.BestMatchCountryCode(szTailNew);

            ac.TailNumber = (cc.HyphenPref == CountryCodePrefix.HyphenPreference.None) ? szTailNew.ToUpperInvariant() : Aircraft.NormalizeTail(szTailNew, CountryCodePrefix.BestMatchCountryCode(szTailNew));
            if (fMigrateUser)
            {
                ac.AircraftID = Aircraft.idAircraftUnknown; // treat this as if we are adding a new aircraft.
            }
            else
            {
                ac.UpdateMaintenanceForUser(mfbMaintainAircraft.MaintenanceForAircraft(), Page.User.Identity.Name);
            }

            ac.ModelID                   = SelectedModelID;
            ac.InstanceTypeID            = (int)this.SelectedInstanceType;
            ac.AvionicsTechnologyUpgrade = AvionicsUpgrade;
            ac.GlassUpgradeDate          = (ac.AvionicsTechnologyUpgrade != MakeModel.AvionicsTechnologyType.None && mfbDateOfGlassUpgrade.Date.HasValue()) ? mfbDateOfGlassUpgrade.Date : (DateTime?)null;
            ac.IsLocked                  = ckLocked.Checked;
            ac.PrivateNotes              = txtPrivateNotes.Text;
            ac.PublicNotes               = txtPublicNotes.Text;
            ac.DefaultImage              = mfbIl.DefaultImage;

            // Preserve any flags
            if (!ac.IsNew)
            {
                Aircraft acExisting = ua[AircraftID];
                if (acExisting != null)
                {
                    ac.CopyFlags(acExisting);
                }
            }

            try
            {
                if (AdminMode)
                {
                    ac.Commit();
                }
                else
                {
                    ac.Commit(Page.User.Identity.Name);
                }

                m_ac       = ac;
                AircraftID = ac.AircraftID;

                ProcessImages();

                // If we migrated, then move the user's existing flights.
                if (fMigrateUser)
                {
                    ua.ReplaceAircraftForUser(ac, new Aircraft(AircraftIDOrig), true);
                }
            }
            catch (Exception ex) when(!(ex is OutOfMemoryException))
            {
                lblError.Text = ex.Message;
            }
        }
        /// <summary>
        /// Shows/hides functionality based on instance type, new/existing, sim, or anonymous.  Does NOT bind any data
        /// </summary>
        protected void AdjustForAircraftType()
        {
            MakeModel mm = MakeModel.GetModel(m_ac.ModelID);

            bool fRealAircraft   = IsRealAircraft;
            CountryCodePrefix cc = CountryCodePrefix.BestMatchCountryCode(m_ac.TailNumber);

            bool fIsNew             = m_ac.IsNew;
            bool fHasModelSpecified = (m_ac.ModelID > 0);

            bool fIsAnonymous = rbRealAnonymous.Checked;

            rbRealRegistered.Enabled = rbRealAnonymous.Enabled = true;
            switch (mm.AllowedTypes)
            {
            case AllowedAircraftTypes.Any:
                break;

            case AllowedAircraftTypes.SimOrAnonymous:
                if (fRealAircraft)
                {
                    fIsAnonymous         = true;
                    m_ac.TailNumber      = CountryCodePrefix.AnonymousCountry.Prefix;  // so that the selected instance will do anonymous correctly
                    SelectedInstanceType = AircraftInstanceTypes.RealAircraft;
                }
                rbRealRegistered.Enabled = false;
                break;

            case AllowedAircraftTypes.SimulatorOnly:
                cc = CountryCodePrefix.SimCountry;
                if (fRealAircraft)
                {
                    // migrate to an ATD.
                    m_ac.InstanceType = SelectedInstanceType = AircraftInstanceTypes.CertifiedATD;
                    fRealAircraft     = false;
                }
                rbRealRegistered.Enabled = rbRealAnonymous.Enabled = false;
                break;
            }

            mvTailnumber.SetActiveView(fRealAircraft ? vwRealAircraft : vwSimTail);

            // Show glass option if this is not, by model, a glass cockpit AND if it's not anonymous
            bool fRealRegistered = fRealAircraft && !fIsAnonymous;

            // All avionics upgrade options are limited to real, registered aircraft.  Beyond that:
            // - Can upgrade to glass if the model is not already glass or TAA (i.e., = steam)
            // - Can upgrade to TAA if the model is not already TAA-only AND this is an airplane (TAA is airplane only).
            // - So we will hide the overall avionics upgrade panel if no upgrade is possible.
            bool fAvionicsGlassvisible = fRealRegistered && mm.AvionicsTechnology == MakeModel.AvionicsTechnologyType.None;
            bool fTAAVisible           = fRealRegistered && mm.AvionicsTechnology != MakeModel.AvionicsTechnologyType.TAA;

            rbAvionicsGlass.Visible = fAvionicsGlassvisible;
            pnlTAA.Visible          = fTAAVisible;
            pnlGlassCockpit.Visible = fAvionicsGlassvisible || fTAAVisible;

            // Sanity check
            if ((rbAvionicsGlass.Checked && !rbAvionicsGlass.Visible) || (rbAvionicsTAA.Checked && !rbAvionicsTAA.Visible))
            {
                AvionicsUpgrade = MakeModel.AvionicsTechnologyType.None;
            }

            rowCountry.Visible     = fRealAircraft && !fIsAnonymous;
            rowMaintenance.Visible = rowCountry.Visible && !fIsNew;

            pnlTrainingDeviceTypes.Visible = fIsNew && !fRealAircraft;

            AdjustForRealOrAnonymous(fRealAircraft, fIsAnonymous, fHasModelSpecified, cc);
        }
    protected void UpdateMask()
    {
        string szCountry = IsRealAircraft ? cmbCountryCode.SelectedValue : hdnSimCountry.Value;

        txtTail.Text = CountryCodePrefix.SetCountryCodeForTail(new CountryCodePrefix(cmbCountryCode.SelectedItem.Text, cmbCountryCode.SelectedValue), txtTail.Text);
    }
    /// <summary>
    /// Shows/hides functionality based on instance type, new/existing, sim, or anonymous.  Does NOT bind any data
    /// </summary>
    protected void AdjustForAircraftType()
    {
        MakeModel mm = MakeModel.GetModel(m_ac.ModelID);

        Boolean           fRealAircraft = IsRealAircraft;
        CountryCodePrefix cc            = CountryCodePrefix.BestMatchCountryCode(m_ac.TailNumber);

        Boolean fIsNew             = m_ac.IsNew;
        Boolean fHasModelSpecified = (m_ac.ModelID > 0);

        Boolean fIsAnonymous = rbRealAnonymous.Checked;

        rbRealRegistered.Enabled = rbRealAnonymous.Enabled = true;
        switch (mm.AllowedTypes)
        {
        case AllowedAircraftTypes.Any:
            break;

        case AllowedAircraftTypes.SimOrAnonymous:
            if (fRealAircraft)
            {
                fIsAnonymous         = true;
                m_ac.TailNumber      = CountryCodePrefix.AnonymousCountry.Prefix;  // so that the selected instance will do anonymous correctly
                SelectedInstanceType = AircraftInstanceTypes.RealAircraft;
            }
            rbRealRegistered.Enabled = false;
            break;

        case AllowedAircraftTypes.SimulatorOnly:
            cc = CountryCodePrefix.SimCountry;
            if (fRealAircraft)
            {
                // migrate to an ATD.
                m_ac.InstanceType = SelectedInstanceType = AircraftInstanceTypes.CertifiedATD;
                fRealAircraft     = false;
            }
            rbRealRegistered.Enabled = rbRealAnonymous.Enabled = false;
            break;
        }

        mvTailnumber.SetActiveView(fRealAircraft ? vwRealAircraft : vwSimTail);

        // Show glass option if this is not, by model, a glass cockpit AND if it's not anonymous
        bool fRealRegistered = fRealAircraft && !fIsAnonymous;

        // All avionics upgrade options are limited to real, registered aircraft.  Beyond that:
        // - Can upgrade to glass if the model is not already glass or TAA (i.e., = steam)
        // - Can upgrade to TAA if the model is not already TAA-only AND this is an airplane (TAA is airplane only).
        // - So we will hide the overall avionics upgrade panel if no upgrade is possible.
        bool fAvionicsGlassvisible = fRealRegistered && mm.AvionicsTechnology == MakeModel.AvionicsTechnologyType.None;
        bool fTAAVisible           = fRealRegistered && mm.AvionicsTechnology != MakeModel.AvionicsTechnologyType.TAA;

        rbAvionicsGlass.Visible = fAvionicsGlassvisible;
        pnlTAA.Visible          = fTAAVisible;
        pnlGlassCockpit.Visible = fAvionicsGlassvisible || fTAAVisible;

        // Sanity check
        if ((rbAvionicsGlass.Checked && !rbAvionicsGlass.Visible) || (rbAvionicsTAA.Checked && !rbAvionicsTAA.Visible))
        {
            AvionicsUpgrade = MakeModel.AvionicsTechnologyType.None;
        }

        rowCountry.Visible     = fRealAircraft && !fIsAnonymous;
        rowMaintenance.Visible = rowCountry.Visible && !fIsNew;

        pnlTrainingDeviceTypes.Visible = fIsNew && !fRealAircraft;

        if (fRealAircraft)
        {
            if (fIsAnonymous)
            {
                lblAnonTailDisplay.Text = m_ac.TailNumber = txtTail.Text = (fHasModelSpecified) ? Aircraft.AnonymousTailnumberForModel(m_ac.ModelID) : String.Empty;
                pnlAnonTail.Visible     = (fHasModelSpecified);
            }
            else
            {
                if (cc.IsSim || cc.IsAnonymous)   // reset tail if switching from sim or anonymous
                {
                    m_ac.TailNumber = txtTail.Text = cmbCountryCode.SelectedItem.Value;
                }
                else
                {
                    m_ac.TailNumber = txtTail.Text = CountryCodePrefix.SetCountryCodeForTail(new CountryCodePrefix(cmbCountryCode.SelectedItem.Text, cmbCountryCode.SelectedValue), txtTail.Text);
                }
            }

            mvRealAircraft.SetActiveView(fIsAnonymous ? vwAnonTail : vwRegularTail);
            valTailNumber.Enabled = fIsAnonymous;
            FixFAALink();
        }
        else
        {
            // Sim
            if (fHasModelSpecified)
            {
                m_ac.TailNumber = Aircraft.SuggestSims(m_ac.ModelID, m_ac.InstanceType)[0].TailNumber;
            }
            vwSimTailDisplay.SetActiveView(fHasModelSpecified ? vwHasModel : vwNoModel);

            lblSimTail.Text = txtTail.Text = m_ac.TailNumber;
        }
    }