public static string[] SuggestFullModelsWithTargets(string prefixText, int count, string contextKey)
    {
        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(prefixText))
        {
            return(Array.Empty <string>());
        }

        Dictionary <string, object> dictContextIn = contextKey == null ? new Dictionary <string, object>() : JsonConvert.DeserializeObject <Dictionary <string, object> >(contextKey);

        ModelQuery modelQuery = new ModelQuery()
        {
            FullText = prefixText.Replace("-", "*"), PreferModelNameMatch = true, Skip = 0, Limit = count
        };
        List <string> lst = new List <string>();

        foreach (MakeModel mm in MakeModel.MatchingMakes(modelQuery))
        {
            Dictionary <string, object> d = new Dictionary <string, object>(dictContextIn);
            string modelID      = mm.MakeModelID.ToString(CultureInfo.InvariantCulture);
            string modelDisplay = String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.LocalizedJoinWithDash, mm.ManufacturerDisplay, mm.ModelDisplayName);
            d["modelID"]      = modelID;
            d["modelDisplay"] = modelDisplay;
            lst.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(modelDisplay, JsonConvert.SerializeObject(d)));
        }
        return(lst.ToArray());
    }
Beispiel #2
0
    public static string[] HtmlRowsForMakes(string szRestrict, int skip, int pageSize)
    {
        List <string> lst = new List <string>();

        // We have no Page, so things like Page_Load don't get called.
        // We fix this by faking a page and calling Server.Execute on it.  This sets up the form and - more importantly - causes Page_load to be called on loaded controls.
        using (Page p = new FormlessPage())
        {
            p.Controls.Add(new HtmlForm());
            using (StringWriter sw1 = new StringWriter(CultureInfo.CurrentCulture))
                HttpContext.Current.Server.Execute(p, sw1, false);

            ModelQuery mq = JsonConvert.DeserializeObject <ModelQuery>(szRestrict);
            mq.Skip  = skip;
            mq.Limit = pageSize;

            foreach (MakeModel m in MakeModel.MatchingMakes(mq))
            {
                Controls_mfbMakeListItem mli = (Controls_mfbMakeListItem)p.LoadControl("~/Controls/mfbMakeListItem.ascx");
                HtmlTableRow             tr  = new HtmlTableRow();
                p.Form.Controls.Add(tr);
                HtmlTableCell tc = new HtmlTableCell();
                tr.Cells.Add(tc);
                tc.VAlign = "top";
                tc.Controls.Add(mli);
                // Now, write it out.
                StringBuilder sb = new StringBuilder();
                StringWriter  sw = null;
                try
                {
                    sw = new StringWriter(sb, CultureInfo.CurrentCulture);
                    using (HtmlTextWriter htmlTW = new HtmlTextWriter(sw))
                    {
                        sw = null;
                        try
                        {
                            mli.SortMode = mq.SortMode;
                            mli.Model    = m;
                            mli.ModelLink.NavigateUrl = VirtualPathUtility.ToAbsolute(mli.ModelLink.NavigateUrl);
                            tr.RenderControl(htmlTW);
                            lst.Add(sb.ToString());
                        }
                        catch (ArgumentException ex) when(ex is ArgumentOutOfRangeException)
                        {
                        }                                                                         // don't write bogus or incomplete HTML
                    }
                }
                finally
                {
                    if (sw != null)
                    {
                        sw.Dispose();
                    }
                }
            }
        }

        return(lst.ToArray());
    }
    protected void UpdateFilter()
    {
        ModelQuery mq = ActiveQuery = QueryFromForm(ActiveQuery);

        tblHeaderRow.Visible = true;
        gvMakes.DataSource   = MakeModel.MatchingMakes(mq);
        gvMakes.DataBind();
    }
Beispiel #4
0
    protected void UpdateFilter()
    {
        ModelQuery mq = ActiveQuery;

        mq.Skip             = 0;
        mq.FullText         = mfbSearchbox.SearchText;
        mq.Model            = txtModel.Text;
        mq.ModelName        = txtModelName.Text;
        mq.TypeName         = txtTypeName.Text;
        mq.ManufacturerName = txtManufacturer.Text;
        mq.CatClass         = txtCatClass.Text;
        ActiveQuery         = mq;

        tblHeaderRow.Visible = true;
        gvMakes.DataSource   = MakeModel.MatchingMakes(mq);
        gvMakes.DataBind();
    }
        public static string[] SuggestFullModels(string prefixText, int count)
        {
            if (String.IsNullOrEmpty(prefixText))
            {
                return(Array.Empty <string>());
            }

            ModelQuery modelQuery = new ModelQuery()
            {
                FullText = prefixText.Replace("-", "*"), PreferModelNameMatch = true, Skip = 0, Limit = count
            };
            List <string> lst = new List <string>();

            foreach (MakeModel mm in MakeModel.MatchingMakes(modelQuery))
            {
                lst.Add(AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.LocalizedJoinWithDash, mm.ManufacturerDisplay, mm.ModelDisplayName), mm.MakeModelID.ToString(CultureInfo.InvariantCulture)));
            }

            return(lst.ToArray());
        }
    protected void UpdateModelList(int idManufacturer)
    {
        ListItem liSelect = cmbMakeModel.Items[0];  // hold onto the "please select a model" item.

        cmbMakeModel.Items.Clear();
        cmbMakeModel.Items.Add(liSelect);
        cmbMakeModel.DataSource = (idManufacturer == MakeModel.UnknownModel) ? new System.Collections.ObjectModel.Collection <MakeModel>() : MakeModel.MatchingMakes(idManufacturer);
        cmbMakeModel.DataBind();
    }