protected void Page_Load(object sender, EventArgs e)
        {
            if (ViewState[szKeyVSAircraftInProgress] != null)
            {
                m_ac = (Aircraft)ViewState[szKeyVSAircraftInProgress];
            }

            if (!IsPostBack)
            {
                cmbCountryCode.DataSource = CountryCodePrefix.CountryCodes();
                cmbCountryCode.DataBind();

                List <AircraftInstance> lst = new List <AircraftInstance>(AircraftInstance.GetInstanceTypes());
                lst.RemoveAll(aic => aic.IsRealAircraft);
                rblTrainingDevices.DataSource = lst;
                rblTrainingDevices.DataBind();
                rblTrainingDevices.SelectedIndex = 0;

                InitFormForAircraft();
            }
            else
            {
                // If it's an existing aircraft and images may have been uploaded, process them
                if (!m_ac.IsNew)
                {
                    ProcessImages();
                }
            }

            SyncTailToCountry();
            SetValidationGroup(mfbMaintainAircraft, "EditAircraft");
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (ViewState[szKeyVSAircraftInProgress] != null)
        {
            m_ac = (Aircraft)ViewState[szKeyVSAircraftInProgress];
        }

        if (!IsPostBack)
        {
            cmbAircraftInstance.DataSource = AircraftInstance.GetInstanceTypes();
            cmbAircraftInstance.DataBind();

            InitFormForAircraft();
        }
        else
        {
            // If it's an existing aircraft and images may have been uploaded, process them
            if (!m_ac.IsNew)
            {
                ProcessImages();
            }
        }

        SyncTailToCountry();
        util.SetValidationGroup(mfbMaintainAircraft, "EditAircraft");
    }
    protected void gvAircraftCandidates_RowCommand(object sender, CommandEventArgs e)
    {
        if (e == null)
        {
            throw new ArgumentException("null gridviewcommandeventargs for new aircraft to import", "e");
        }

        int idRow = Convert.ToInt32(e.CommandArgument, CultureInfo.InvariantCulture);

        if (e.CommandName.CompareOrdinalIgnoreCase("AddNew") == 0)
        {
            UserAircraft           ua = new UserAircraft(Page.User.Identity.Name);
            AircraftImportMatchRow mr = CandidatesForImport.FirstOrDefault <AircraftImportMatchRow>(mr2 => mr2.ID == idRow);
            mr.BestMatchAircraft.Commit(Page.User.Identity.Name);

            ModelMapping[mr.ModelGiven] = MakeModel.GetModel(mr.BestMatchAircraft.ModelID);   // remember the mapping.

            // hack, but the commit above can result in the instance type being cleared out, so restore it.
            if (String.IsNullOrEmpty(mr.BestMatchAircraft.InstanceTypeDescription))
            {
                mr.BestMatchAircraft.InstanceTypeDescription = AircraftInstance.GetInstanceTypes()[mr.BestMatchAircraft.InstanceTypeID - 1].DisplayName;
            }

            mr.State = AircraftImportMatchRow.MatchState.JustAdded;
            UpdateGrid();
        }
    }
    public static string ValidateAircraft(string szTail, int idModel, int instanceType)
    {
        if (!HttpContext.Current.User.Identity.IsAuthenticated || String.IsNullOrEmpty(HttpContext.Current.User.Identity.Name))
        {
            throw new MyFlightbookException("Unauthenticated call to ValidateAircraft");
        }

        if (string.IsNullOrEmpty(szTail))
        {
            throw new ArgumentException("Empty tail in ValidateAircraft");
        }

        // Issue #296: allow sims to come through without a sim prefix; we can fix it at AddNewAircraft time.
        AircraftInstance aic = Array.Find(AircraftInstance.GetInstanceTypes(), it => it.InstanceTypeInt == instanceType);

        if (!aic.IsRealAircraft && !szTail.ToUpper(CultureInfo.CurrentCulture).StartsWith(CountryCodePrefix.SimCountry.Prefix.ToUpper(CultureInfo.CurrentCulture), StringComparison.CurrentCultureIgnoreCase))
        {
            szTail = CountryCodePrefix.SimCountry.Prefix;
        }

        Aircraft ac = new Aircraft()
        {
            TailNumber = szTail, ModelID = idModel, InstanceTypeID = instanceType
        };

        ac.FixTailAndValidate();
        return(ac.ErrorString);
    }
    public static string AddNewAircraft(string szTail, int idModel, int instanceType, string szModelGiven, string szJsonMapping)
    {
        if (!HttpContext.Current.User.Identity.IsAuthenticated || String.IsNullOrEmpty(HttpContext.Current.User.Identity.Name))
        {
            throw new MyFlightbookException("Unauthenticated call to add new aircraft");
        }

        if (string.IsNullOrEmpty(szTail))
        {
            throw new ArgumentException("Missing tail in AddNewAircraft");
        }

        Dictionary <string, MakeModel> dModelMapping = String.IsNullOrEmpty(szJsonMapping) ? new Dictionary <string, MakeModel>() : JsonConvert.DeserializeObject <Dictionary <string, MakeModel> >(szJsonMapping);

        string szCurrentUser = HttpContext.Current.User.Identity.Name;

        Aircraft ac = new Aircraft()
        {
            TailNumber = szTail, ModelID = idModel, InstanceTypeID = instanceType
        };

        // Issue #296: allow sims to come through without a sim prefix; we can fix it at AddNewAircraft time.
        AircraftInstance aic             = Array.Find(AircraftInstance.GetInstanceTypes(), it => it.InstanceTypeInt == instanceType);
        string           szSpecifiedTail = szTail;
        bool             fIsNamedSim     = !aic.IsRealAircraft && !szTail.ToUpper(CultureInfo.CurrentCulture).StartsWith(CountryCodePrefix.SimCountry.Prefix.ToUpper(CultureInfo.CurrentCulture), StringComparison.CurrentCultureIgnoreCase);

        if (fIsNamedSim)
        {
            ac.TailNumber = CountryCodePrefix.SimCountry.Prefix;
        }

        if (ac.FixTailAndValidate())
        {
            ac.CommitForUser(szCurrentUser);

            UserAircraft ua = new UserAircraft(szCurrentUser);
            if (fIsNamedSim)
            {
                ac.PrivateNotes = String.Format(CultureInfo.InvariantCulture, "{0} #ALT{1}#", ac.PrivateNotes ?? string.Empty, szSpecifiedTail);
            }

            ua.FAddAircraftForUser(ac);
            ua.InvalidateCache();

            if (!String.IsNullOrEmpty(szModelGiven))
            {
                dModelMapping[szModelGiven] = MakeModel.GetModel(idModel);
            }
        }
        else
        {
            throw new MyFlightbookValidationException(ac.ErrorString);
        }

        return(JsonConvert.SerializeObject(dModelMapping));
    }
Ejemplo n.º 6
0
    private void SetUpImagesForRow(LogbookEntryDisplay le, GridViewRow row)
    {
        // Bind to images.
        Controls_mfbImageList mfbIl = (Controls_mfbImageList)row.FindControl("mfbilFlights");

        if (!SuppressImages)
        {
            // Flight images
            mfbIl.Key = le.FlightID.ToString(CultureInfo.InvariantCulture);
            mfbIl.Refresh();
            if (!le.FlightImages.Any()) // populate images, so that flight coloring can work
            {
                foreach (MyFlightbook.Image.MFBImageInfo mfbii in mfbIl.Images.ImageArray)
                {
                    le.FlightImages.Add(mfbii);
                }
            }

            // wire up images
            if (mfbIl.Images.ImageArray.Count > 0 || le.Videos.Count > 0)
            {
                row.FindControl("pnlImagesHover").Visible = true;
            }
            else
            {
                row.FindControl("pnlFlightImages").Visible = false;
            }

            Aircraft ac = AircraftForUser.Find(a => a.AircraftID == le.AircraftID);
            string   szInstTypeDescription = ac == null ? string.Empty : AircraftInstance.ShortNameForInstanceType(ac.InstanceType);
            ((Label)row.FindControl("lblInstanceTypeDesc")).Text = szInstTypeDescription;

            // And aircraft
            // for efficiency, see if we've already done this tail number; re-use if already done
            if (!m_dictAircraftHoverIDs.ContainsKey(le.AircraftID))
            {
                if (ac != null)
                {
                    mfbilAircraft.DefaultImage = ac.DefaultImage;
                }

                mfbilAircraft.Key = le.AircraftID.ToString(CultureInfo.InvariantCulture);
                mfbilAircraft.Refresh();

                // cache the attributes string - there's a bit of computation involved in it.
                string szAttributes = ((Label)row.FindControl("lblModelAttributes")).Text.EscapeHTML();

                // and the image table.
                m_dictAircraftHoverIDs[le.AircraftID] = szInstTypeDescription + " " + szAttributes + mfbilAircraft.AsHTMLTable();
            }

            row.FindControl("plcTail").Controls.Add(new LiteralControl(m_dictAircraftHoverIDs[le.AircraftID]));
        }
    }
Ejemplo n.º 7
0
    public void gvFlightLogs_RowDataBound(Object sender, GridViewRowEventArgs e)
    {
        if (e == null)
        {
            throw new ArgumentNullException("e");
        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            int cCols = e.Row.Cells.Count;

            for (int i = cCols - 1; i >= 1; i--)
            {
                e.Row.Cells.RemoveAt(i);
            }
            e.Row.Cells[0].ColumnSpan = cCols;
        }
        else if (e.Row.RowType == DataControlRowType.Pager)
        {
            ((Label)e.Row.FindControl("lblNumFlights")).Text = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.NumberOfFlights, CachedData.Count());
        }
        else if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LogbookEntryDisplay le = (LogbookEntryDisplay)e.Row.DataItem;

            // Wire up the drop-menu.  We have to do this here because it is an iNamingContainer and can't access the gridviewrow
            Controls_popmenu popup = (Controls_popmenu)e.Row.FindControl("popmenu1");
            ((Controls_mfbMiniFacebook)popup.FindControl("mfbMiniFacebook")).FlightEntry = le;
            ((Controls_mfbTweetThis)popup.FindControl("mfbTweetThis")).FlightToTweet     = le;
            ((LinkButton)popup.FindControl("lnkReverse")).CommandArgument    = ((LinkButton)popup.FindControl("lnkClone")).CommandArgument = le.FlightID.ToString(CultureInfo.InvariantCulture);
            ((LinkButton)popup.FindControl("lnkSendFlight")).CommandArgument = le.FlightID.ToString(CultureInfo.InvariantCulture);
            ((HyperLink)popup.FindControl("lnkEditThisFlight")).NavigateUrl  = EditPath(le.FlightID);
            HyperLink h = (HyperLink)popup.FindControl("lnkRequestSignature");
            h.Visible     = le.CanRequestSig;
            h.NavigateUrl = String.Format(CultureInfo.InvariantCulture, "~/Member/RequestSigs.aspx?id={0}", le.FlightID);

            // fix the ID of the delete button to prevent replay attacks
            string     szDelID  = String.Format(CultureInfo.InvariantCulture, "lnkDel{0}", le.FlightID);
            LinkButton lbDelete = (LinkButton)e.Row.FindControl("lnkDelete");
            lbDelete.ID = szDelID;
            // If the host wants notifications of deletions, register full postback.
            if (ItemDeleted != null)
            {
                ScriptManager.GetCurrent(Page).RegisterPostBackControl(lbDelete);
            }
            ((AjaxControlToolkit.ConfirmButtonExtender)e.Row.FindControl("ConfirmButtonExtender1")).TargetControlID = szDelID;

            // Bind to images.
            Controls_mfbImageList mfbIl = (Controls_mfbImageList)e.Row.FindControl("mfbilFlights");
            if (!SuppressImages)
            {
                // Flight images
                mfbIl.Key = le.FlightID.ToString(CultureInfo.InvariantCulture);
                mfbIl.Refresh();

                // wire up images
                if (mfbIl.Images.ImageArray.Count > 0 || le.Videos.Count > 0)
                {
                    e.Row.FindControl("pnlImagesHover").Visible = true;
                }
                else
                {
                    e.Row.FindControl("pnlFlightImages").Visible = false;
                }

                Aircraft ac = AircraftForUser.Find(a => a.AircraftID == le.AircraftID);
                string   szInstTypeDescription = ac == null ? string.Empty : AircraftInstance.ShortNameForInstanceType(ac.InstanceType);
                ((Label)e.Row.FindControl("lblInstanceTypeDesc")).Text = szInstTypeDescription;

                // And aircraft
                // for efficiency, see if we've already done this tail number; re-use if already done
                if (!m_dictAircraftHoverIDs.ContainsKey(le.AircraftID))
                {
                    if (ac != null)
                    {
                        mfbilAircraft.DefaultImage = ac.DefaultImage;
                    }

                    mfbilAircraft.Key = le.AircraftID.ToString(CultureInfo.InvariantCulture);
                    mfbilAircraft.Refresh();

                    // cache the attributes string - there's a bit of computation involved in it.
                    string szAttributes = ((Label)e.Row.FindControl("lblModelAttributes")).Text.EscapeHTML();

                    // and the image table.
                    m_dictAircraftHoverIDs[le.AircraftID] = szInstTypeDescription + " " + szAttributes + mfbilAircraft.AsHTMLTable();
                }

                e.Row.FindControl("plcTail").Controls.Add(new LiteralControl(m_dictAircraftHoverIDs[le.AircraftID]));
            }

            // Set style for the row
            HtmlGenericControl divDate = (HtmlGenericControl)e.Row.FindControl("divDateAndRoute");
            switch (le.RowType)
            {
            case LogbookEntryDisplay.LogbookRowType.Flight:
                if (le.IsPageBreak)
                {
                    e.Row.CssClass = e.Row.CssClass + " pageBreakRow";
                }
                break;

            case LogbookEntryDisplay.LogbookRowType.RunningTotal:
                e.Row.CssClass  = "runningTotalRow";
                divDate.Visible = false;
                break;

            case LogbookEntryDisplay.LogbookRowType.Subtotal:
                e.Row.CssClass  = (le.IsPageBreak) ? "subtotalRowPageBreak" : "subtotalRow";
                divDate.Visible = false;
                break;
            }
        }
    }
Ejemplo n.º 8
0
    public void gvFlightLogs_RowDataBound(Object sender, GridViewRowEventArgs e)
    {
        if (e == null)
        {
            throw new ArgumentNullException("e");
        }
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            int cCols = e.Row.Cells.Count;

            for (int i = cCols - 1; i >= 1; i--)
            {
                e.Row.Cells.RemoveAt(i);
            }
            e.Row.Cells[0].ColumnSpan = cCols;
        }
        else if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LogbookEntryDisplay le = (LogbookEntryDisplay)e.Row.DataItem;

            // Wire up the drop-menu.  We have to do this here because it is an iNamingContainer and can't access the gridviewrow
            Controls_mfbFlightContextMenu cm = (Controls_mfbFlightContextMenu)e.Row.FindControl("popmenu1").FindControl("mfbFlightContextMenu");

            string szEditContext = EditContextParams;

            cm.EditTargetFormatString = (EditPageUrlFormatString == null) ? string.Empty : (EditPageUrlFormatString + (String.IsNullOrEmpty(szEditContext) ? string.Empty : (EditPageUrlFormatString.Contains("?") ? "&" : "?" + szEditContext)));
            cm.Flight = le;

            if (Pilot != null && Pilot.AchievementStatus == MyFlightbook.Achievements.Achievement.ComputeStatus.UpToDate)
            {
                Repeater rptBadges = (Repeater)e.Row.FindControl("rptBadges");
                if (CachedBadgesByFlight.ContainsKey(le.FlightID))
                {
                    IEnumerable <Badge> badges = CachedBadgesByFlight[le.FlightID];
                    if (badges != null)
                    {
                        rptBadges.DataSource = badges;
                        rptBadges.DataBind();
                    }
                }
            }

            // Bind to images.
            Controls_mfbImageList mfbIl = (Controls_mfbImageList)e.Row.FindControl("mfbilFlights");
            if (!SuppressImages)
            {
                // Flight images
                mfbIl.Key = le.FlightID.ToString(CultureInfo.InvariantCulture);
                mfbIl.Refresh();

                // wire up images
                if (mfbIl.Images.ImageArray.Count > 0 || le.Videos.Count() > 0)
                {
                    e.Row.FindControl("pnlImagesHover").Visible = true;
                }
                else
                {
                    e.Row.FindControl("pnlFlightImages").Visible = false;
                }

                Aircraft ac = AircraftForUser.Find(a => a.AircraftID == le.AircraftID);
                string   szInstTypeDescription = ac == null ? string.Empty : AircraftInstance.ShortNameForInstanceType(ac.InstanceType);
                ((Label)e.Row.FindControl("lblInstanceTypeDesc")).Text = szInstTypeDescription;

                // And aircraft
                // for efficiency, see if we've already done this tail number; re-use if already done
                if (!m_dictAircraftHoverIDs.ContainsKey(le.AircraftID))
                {
                    if (ac != null)
                    {
                        mfbilAircraft.DefaultImage = ac.DefaultImage;
                    }

                    mfbilAircraft.Key = le.AircraftID.ToString(CultureInfo.InvariantCulture);
                    mfbilAircraft.Refresh();

                    // cache the attributes string - there's a bit of computation involved in it.
                    string szAttributes = ((Label)e.Row.FindControl("lblModelAttributes")).Text.EscapeHTML();

                    // and the image table.
                    m_dictAircraftHoverIDs[le.AircraftID] = szInstTypeDescription + " " + szAttributes + mfbilAircraft.AsHTMLTable();
                }

                e.Row.FindControl("plcTail").Controls.Add(new LiteralControl(m_dictAircraftHoverIDs[le.AircraftID]));
            }

            // Set style for the row
            HtmlGenericControl divDate = (HtmlGenericControl)e.Row.FindControl("divDateAndRoute");
            switch (le.RowType)
            {
            case LogbookEntryDisplay.LogbookRowType.Flight:
                if (le.IsPageBreak)
                {
                    e.Row.CssClass = e.Row.CssClass + " pageBreakRow";
                }
                break;

            case LogbookEntryDisplay.LogbookRowType.RunningTotal:
                e.Row.CssClass  = "runningTotalRow";
                divDate.Visible = false;
                break;

            case LogbookEntryDisplay.LogbookRowType.Subtotal:
                e.Row.CssClass  = (le.IsPageBreak) ? "subtotalRowPageBreak" : "subtotalRow";
                divDate.Visible = false;
                break;
            }
        }
    }
    protected void gvAircraftCandidates_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e == null)
        {
            throw new ArgumentNullException("e");
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            AircraftImportMatchRow mr  = (AircraftImportMatchRow)e.Row.DataItem;
            GridViewRow            gvr = e.Row;

            // Column 0: Aircraft tail.  Link to registration, if necessary
            HyperLink lnkFAA = (HyperLink)e.Row.FindControl("lnkFAA");
            lnkFAA.NavigateUrl = Aircraft.LinkForTailnumberRegistry(mr.TailNumber);
            ((Label)gvr.FindControl("lblGivenTail")).Visible    = !(lnkFAA.Visible = !String.IsNullOrEmpty(lnkFAA.NavigateUrl));
            ((Label)gvr.FindControl("lblAircraftVersion")).Text = (mr.BestMatchAircraft != null && mr.BestMatchAircraft.Version > 0) ? Resources.Aircraft.ImportAlternateVersion : string.Empty;

            // Column 1 - Best match
            DropDownList cmbInst = (DropDownList)e.Row.FindControl("cmbInstType");

            HiddenField hdnContext = (HiddenField)e.Row.FindControl("hdnContext");
            if (mr.State == AircraftImportMatchRow.MatchState.UnMatched)
            {
                Label lblInstType = (Label)e.Row.FindControl("lblType");
                cmbInst.DataSource = AircraftInstance.GetInstanceTypes();
                cmbInst.DataBind();
                cmbInst.SelectedValue = mr.BestMatchAircraft.InstanceTypeID.ToString(CultureInfo.InvariantCulture);

                cmbInst.Attributes["onchange"] = String.Format(CultureInfo.InvariantCulture, "javascript:updateInstanceDesc('{0}', '{1}', '{2}');", cmbInst.ClientID, lblInstType.ClientID, hdnContext.ClientID);
            }

            // column 2 - "Add this" and status
            Button btnAddThis = (Button)gvr.FindControl("btnAddThis");
            Label  lProblem   = (Label)e.Row.FindControl("lblACErr");
            Label  lblAllGood = (Label)e.Row.FindControl("lblAllGood");
            lblAllGood.Style["display"] = (mr.State == AircraftImportMatchRow.MatchState.JustAdded) ? "block" : "none";
            ((Label)gvr.FindControl("lblAlreadyInProfile")).Visible = mr.State == AircraftImportMatchRow.MatchState.MatchedInProfile;

            Panel pnlStaticMake = (Panel)e.Row.FindControl("pnlStaticMake");
            Panel pnlEditMake   = (Panel)e.Row.FindControl("pnlEditMake");
            Image imgEdit       = (Image)e.Row.FindControl("imgEdit");
            imgEdit.Attributes["onclick"] = String.Format(CultureInfo.InvariantCulture, "javascript:toggleModelEdit('{0}', '{1}');", pnlStaticMake.ClientID, pnlEditMake.ClientID);
            TextBox textBox = (TextBox)e.Row.FindControl("txtSearch");

            HiddenField hdnModel          = (HiddenField)e.Row.FindControl("hdnSelectedModel");
            Label       lblModel          = (Label)e.Row.FindControl("lblSelectedMake");
            Dictionary <string, object> d = new Dictionary <string, object>()
            {
                { "lblID", lblModel.ClientID },                     // ID of the label to display the selected model
                { "lblErr", lProblem.ClientID },                    // ID of the label for displaying an error
                { "lblAllGood", lblAllGood.ClientID },              // ID of the label for displaying success
                { "mdlID", hdnModel.ClientID },                     // ID of the hidden control with the selected model ID
                { "cmbInstance", cmbInst.ClientID },                // ID of the drop-down with the instance type specified
                { "progressID", popupAddingInProgress.BehaviorID }, // ID of the progress behavior ID
                { "btnAdd", btnAddThis.ClientID },                  // ID of the "Add this" button
                { "pnlStaticMake", pnlStaticMake.ClientID },        // ID of the static view of the model/instance type to import
                { "pnlEditMake", pnlEditMake.ClientID },            // ID of the edit view to import
                { "matchRow", mr }                                  // The match row with any additional context
            };
            AjaxControlToolkit.AutoCompleteExtender autoCompleteExtender = (AjaxControlToolkit.AutoCompleteExtender)e.Row.FindControl("autocompleteModel");
            hdnContext.Value = autoCompleteExtender.ContextKey = JsonConvert.SerializeObject(d);

            switch (mr.State)
            {
            case AircraftImportMatchRow.MatchState.JustAdded:
            case AircraftImportMatchRow.MatchState.MatchedInProfile:
                btnAddThis.Visible = false;
                btnAddThis.Attributes["onclick"] = string.Empty;
                break;

            case AircraftImportMatchRow.MatchState.MatchedExisting:
                btnAddThis.Visible = true;
                btnAddThis.Text    = Resources.Aircraft.ImportExistingAircraft;
                btnAddThis.Attributes["onclick"] = String.Format(CultureInfo.InvariantCulture, "addExistingAircraft(JSON.parse(document.getElementById('{0}').value)); return false;", hdnContext.ClientID);
                break;

            case AircraftImportMatchRow.MatchState.UnMatched:
                imgEdit.Visible = true;
                e.Row.FindControl("pnlEditMake").Visible = true;
                btnAddThis.Visible = true;
                btnAddThis.Text    = Resources.Aircraft.ImportAddNewAircraft;
                hdnModel.Value     = mr.BestMatchAircraft.ModelID.ToString(CultureInfo.InvariantCulture);
                if (mr.SuggestedModel == null || !String.IsNullOrEmpty(mr.BestMatchAircraft.ErrorString))
                {
                    textBox.Text = mr.ModelGiven;
                    pnlEditMake.Style["display"]   = "block";
                    pnlStaticMake.Style["display"] = "none";
                    btnAddThis.Style["display"]    = "none";
                }
                else
                {
                    textBox.Text = string.Empty;
                    pnlEditMake.Style["display"]   = "none";
                    pnlStaticMake.Style["display"] = "block";
                    btnAddThis.Style["display"]    = "block";
                }

                btnAddThis.Attributes["onclick"] = String.Format(CultureInfo.InvariantCulture, "addNewAircraft(JSON.parse(document.getElementById('{0}').value)); return false;", hdnContext.ClientID);
                break;
            }

            if (mr.BestMatchAircraft != null && mr.BestMatchAircraft.ErrorString.Length > 0)
            {
                lProblem.Text = mr.BestMatchAircraft.ErrorString;
                btnAddThis.Style["display"] = "none";
            }
            else
            {
                lProblem.Text = string.Empty;

                if (mr.State == AircraftImportMatchRow.MatchState.JustAdded)
                {
                    lblAllGood.Style["display"] = "block";
                    btnAddThis.Style["display"] = "none";
                }
            }
        }
    }
    protected void gvAircraftCandidates_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e == null)
        {
            throw new ArgumentNullException("e");
        }
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            AircraftImportMatchRow mr = (AircraftImportMatchRow)e.Row.DataItem;
            GridView    gv            = (GridView)sender;
            GridViewRow gvr           = e.Row;

            // Column 0: select or not
            LinkButton lnkEdit = (LinkButton)gvr.FindControl("lnkEdit");
            lnkEdit.Visible         = mr.State == AircraftImportMatchRow.MatchState.UnMatched;
            lnkEdit.CommandArgument = gvr.RowIndex.ToString(CultureInfo.InvariantCulture);

            // Column 1: Aircraft tail.  Link to registration, if necessary
            HyperLink lnkFAA = (HyperLink)e.Row.FindControl("lnkFAA");
            lnkFAA.NavigateUrl = Aircraft.LinkForTailnumberRegistry(mr.TailNumber);
            ((Label)gvr.FindControl("lblGivenTail")).Visible    = !(lnkFAA.Visible = !String.IsNullOrEmpty(lnkFAA.NavigateUrl));
            ((Label)gvr.FindControl("lblAircraftVersion")).Text = (mr.BestMatchAircraft != null && mr.BestMatchAircraft.Version > 0) ? Resources.Aircraft.ImportAlternateVersion : string.Empty;

            // Column 2 - Best match
            MultiView mvMatch = (MultiView)e.Row.FindControl("mvMatch");
            mvMatch.ActiveViewIndex = 0;

            DropDownList cmbInst         = (DropDownList)e.Row.FindControl("cmbInstType");
            DropDownList cmbModel        = (DropDownList)e.Row.FindControl("cmbModel");
            DropDownList cmbManufacturer = (DropDownList)e.Row.FindControl("cmbManufacturer");
            if (e.Row.RowIndex == gv.SelectedIndex && mr.State == AircraftImportMatchRow.MatchState.UnMatched)
            {
                cmbInst.DataSource = AircraftInstance.GetInstanceTypes();
                cmbInst.DataBind();
                cmbInst.SelectedValue = mr.BestMatchAircraft.InstanceTypeID.ToString(CultureInfo.InvariantCulture);

                cmbManufacturer.DataSource = AllManufacturers;
                cmbManufacturer.DataBind();
                int idMan   = (mr.SpecifiedModel == null) ? Manufacturer.UnsavedID : mr.SpecifiedModel.ManufacturerID;
                int idModel = (mr.SpecifiedModel == null) ? MakeModel.UnknownModel : mr.SpecifiedModel.MakeModelID;
                cmbManufacturer.SelectedValue = idMan.ToString(CultureInfo.InvariantCulture);

                cmbModel.DataSource = ModelsForManufacturer(idMan);
                cmbModel.DataBind();
                cmbModel.SelectedValue = idModel.ToString(CultureInfo.InvariantCulture);

                mvMatch.ActiveViewIndex = 1;

                e.Row.BackColor   = System.Drawing.Color.FromArgb(0xCC, 0xCC, 0xCC);
                e.Row.BorderColor = System.Drawing.Color.Black;
                e.Row.BorderStyle = BorderStyle.Solid;
                e.Row.BorderWidth = Unit.Pixel(1);
            }
            else
            {
                cmbInst.Items.Clear();
                cmbModel.Items.Clear();
                cmbManufacturer.Items.Clear();
            }

            // column 3 - "Add this" and status
            Button btnAddThis = (Button)gvr.FindControl("btnAddThis");
            Label  lProblem   = (Label)e.Row.FindControl("lblACErr");
            Label  lblAllGood = (Label)e.Row.FindControl("lblAllGood");
            lblAllGood.Style["display"] = (mr.State == AircraftImportMatchRow.MatchState.JustAdded) ? "block" : "none";
            ((Label)gvr.FindControl("lblAlreadyInProfile")).Visible = mr.State == AircraftImportMatchRow.MatchState.MatchedInProfile;

            switch (mr.State)
            {
            case AircraftImportMatchRow.MatchState.JustAdded:
            case AircraftImportMatchRow.MatchState.MatchedInProfile:
                btnAddThis.Visible = false;
                btnAddThis.Attributes["onclick"] = string.Empty;
                break;

            case AircraftImportMatchRow.MatchState.MatchedExisting:
                btnAddThis.Visible = true;
                btnAddThis.Text    = Resources.Aircraft.ImportExistingAircraft;
                btnAddThis.Attributes["onclick"] = String.Format(CultureInfo.InvariantCulture, "addExistingAircraft({0}, '{1}', '{2}', '{3}'); return false;",
                                                                 mr.BestMatchAircraft.AircraftID, btnAddThis.ClientID, lblAllGood.ClientID, popupAddingInProgress.BehaviorID);
                break;

            case AircraftImportMatchRow.MatchState.UnMatched:
                btnAddThis.Visible = true;
                btnAddThis.Text    = Resources.Aircraft.ImportAddNewAircraft;
                if (e.Row.RowIndex != gv.SelectedIndex && mr.State == AircraftImportMatchRow.MatchState.UnMatched && mr.BestMatchAircraft != null)
                {
                    // Bypass a postback if it is an error-free non-selected row.  This should avoid some of the viewstate errors we've been getting for click-click-click down the list of buttons
                    btnAddThis.Attributes["onclick"] = String.Format(CultureInfo.InvariantCulture, "addNewAircraft('{0}', '{1}', {2}, '{3}', {4}, '{5}'); return false;",
                                                                     btnAddThis.ClientID,
                                                                     lblAllGood.ClientID,
                                                                     mr.BestMatchAircraft.ModelID,
                                                                     mr.BestMatchAircraft.TailNumber,
                                                                     mr.BestMatchAircraft.InstanceTypeID,
                                                                     popupAddingInProgress.BehaviorID);
                }
                break;
            }

            if (mr.BestMatchAircraft != null && mr.BestMatchAircraft.ErrorString.Length > 0)
            {
                lProblem.Text      = mr.BestMatchAircraft.ErrorString;
                btnAddThis.Visible = false;
            }
            else
            {
                lProblem.Text = string.Empty;

                if (mr.State == AircraftImportMatchRow.MatchState.JustAdded)
                {
                    lblAllGood.Style["display"] = "block";
                    btnAddThis.Visible          = false;
                    lnkEdit.Visible             = false; // disable the Edit button
                }
            }
        }
    }