public void AddPictures(Object sender, GridViewRowEventArgs e)
    {
        if (e != null && e.Row.RowType == DataControlRowType.DataRow)
        {
            Aircraft ac = (Aircraft)e.Row.DataItem;

            // Refresh the images
            if (!IsAdminMode)
            {
                ((Controls_mfbHoverImageList)e.Row.FindControl("mfbHoverThumb")).Refresh();
            }

            // Show aircraft capabilities too.
            Controls_popmenu popup = (Controls_popmenu)e.Row.FindControl("popmenu1");
            ((RadioButtonList)popup.FindControl("rblRole")).SelectedValue = ac.RoleForPilot.ToString();
            ((CheckBox)popup.FindControl("ckShowInFavorites")).Checked    = !ac.HideFromSelection;

            ((Label)popup.FindControl("lblOptionHeader")).Text = String.Format(CultureInfo.CurrentCulture, Resources.Aircraft.optionHeader, ac.DisplayTailnumber);

            if (!IsAdminMode)
            {
                List <LinkedString> lst = new List <LinkedString>();

                if (ac.Stats != null)
                {
                    lst.Add(ac.Stats.UserStatsDisplay);
                }
                MakeModel mm = MakeModel.GetModel(ac.ModelID);
                if (mm != null)
                {
                    if (!String.IsNullOrEmpty(mm.FamilyName))
                    {
                        lst.Add(new LinkedString(ModelQuery.ICAOPrefix + mm.FamilyName));
                    }

                    foreach (string sz in mm.AttributeList(ac.AvionicsTechnologyUpgrade, ac.GlassUpgradeDate))
                    {
                        lst.Add(new LinkedString(sz));
                    }
                }

                Repeater rpt = (Repeater)e.Row.FindControl("rptAttributes");
                rpt.DataSource = lst;
                rpt.DataBind();
            }

            if (IsAdminMode)
            {
                HyperLink lnkRegistration = (HyperLink)e.Row.FindControl("lnkRegistration");
                string    szURL           = ac.LinkForTailnumberRegistry();
                lnkRegistration.Visible     = szURL.Length > 0;
                lnkRegistration.NavigateUrl = szURL;
            }
        }
    }
    protected void UpdateAttributesForModel(MakeModel mm)
    {
        List <LinkedString> lst = new List <LinkedString>();

        lst.AddRange(AircraftAttributes);
        if (mm != null)
        {
            if (!String.IsNullOrEmpty(mm.FamilyName))
            {
                lst.Add(new LinkedString(ModelQuery.ICAOPrefix + mm.FamilyName));
            }
            foreach (string sz in mm.AttributeList())
            {
                lst.Add(new LinkedString(sz));
            }
        }
        rptAttributes.DataSource = lst;
        rptAttributes.DataBind();
    }
        private void ShowAircraftForModel(int idMan, int idModel)
        {
            if (!ModelsByManufacturer.ContainsKey(idMan))
            {
                throw new HttpException(404, "Not found");
            }

            MakeModel m = ModelsByManufacturer[idMan].Find(mm => mm.MakeModelID == idModel);

            if (m == null)
            {
                throw new HttpException(404, "Not found");
            }

            rptAttributes.DataSource = m.AttributeList();
            rptAttributes.DataBind();
            lblModel.Text                = HttpUtility.HtmlEncode(m.DisplayName);
            lblAttributesHeader.Text     = String.Format(CultureInfo.CurrentCulture, "Attributes of {0}:", HttpUtility.HtmlEncode(m.DisplayName));
            lblSampleAircraftHeader.Text = String.Format(CultureInfo.CurrentCulture, "Sample aircraft for {0}", HttpUtility.HtmlEncode(m.DisplayName));

            List <Aircraft> lst = new List <Aircraft>();
            // UserAircraft.GetAircraftForUser is pretty heavyweight, especially for models witha  lot of aircraft like C-152.
            // We just don't need that much detail, since we're just binding images by ID and tailnumbers
            DBHelper dbh = new DBHelper(String.Format(CultureInfo.InvariantCulture, "SELECT idaircraft, tailnumber FROM aircraft WHERE idmodel=?modelid AND tailnumber NOT LIKE '{0}%' AND instanceType=1 ORDER BY tailnumber ASC", CountryCodePrefix.szAnonPrefix));

            dbh.ReadRows((comm) => { comm.Parameters.AddWithValue("modelid", idModel); },
                         (dr) =>
            {
                int idaircraft    = Convert.ToInt32(dr["idaircraft"], CultureInfo.InvariantCulture);
                string tailnumber = (string)dr["tailnumber"];
                lst.Add(new Aircraft()
                {
                    AircraftID = idaircraft, TailNumber = tailnumber
                });
            });
            gvAircraft.DataSource = lst;
            gvAircraft.DataBind();
        }
Exemple #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Master.SelectedTab = tabID.actMakes;

        int idModel = util.GetIntParam(Request, "id", -1);
        IEnumerable <Aircraft> rgac = AircraftWithModel(idModel);

        AircraftList1.AircraftSource = rgac;    // do this on every page load for images, etc.  It doesn't keep viewstate

        if (!IsPostBack)
        {
            mfbEditMake1.MakeID = idModel;

            if (mfbEditMake1.MakeID > 0)
            {
                // Default to read-only
                mvMake.SetActiveView(vwView);

                lblEditModel.Text = mfbEditMake1.Model.DisplayName;

                List <LinkedString> lstAttribs = new List <LinkedString>();
                MakeModel           mm         = mfbEditMake1.Model;
                lblMakeModel.Text = mm.DisplayName;
                if (mm != null)
                {
                    if (!String.IsNullOrEmpty(mm.FamilyName))
                    {
                        lstAttribs.Add(new LinkedString(ModelQuery.ICAOPrefix + mm.FamilyName));
                    }
                    foreach (string sz in mm.AttributeList())
                    {
                        lstAttribs.Add(new LinkedString(sz));
                    }
                }

                if (rgac.Count() > 0)
                {
                    lstAttribs.Add(new LinkedString(String.Format(CultureInfo.CurrentCulture, Resources.Makes.MakeStatsAircraftCount, rgac.Count())));

                    lnkViewTotals.Visible = true;
                    FlightQuery fq = new FlightQuery(Page.User.Identity.Name)
                    {
                        MakeList = new MakeModel[] { mfbEditMake1.Model }
                    };
                    MakeModelStats stats        = Stats;
                    string         szStatsLabel = String.Format(CultureInfo.CurrentCulture, Resources.Makes.MakeStatsFlightsCount, stats.NumFlights, stats.EarliestFlight.HasValue && stats.LatestFlight.HasValue ?
                                                                String.Format(CultureInfo.CurrentCulture, Resources.Makes.MakeStatsFlightsDateRange, stats.EarliestFlight.Value, stats.LatestFlight.Value) : string.Empty);
                    lnkViewTotals.Text        = szStatsLabel;
                    lnkViewTotals.NavigateUrl = String.Format(CultureInfo.InvariantCulture, "~/Member/LogbookNew.aspx?ft=Totals&fq={0}", HttpUtility.UrlEncode(Convert.ToBase64String(fq.ToJSONString().Compress())));
                    lstAttribs.Add(new LinkedString(szStatsLabel, lnkViewTotals.NavigateUrl));
                }

                if (Page.User.Identity.IsAuthenticated && MyFlightbook.Profile.GetUser(Page.User.Identity.Name).CanManageData)
                {
                    lnkViewAircraft.Visible     = true;
                    lnkViewAircraft.NavigateUrl = String.Format(CultureInfo.InvariantCulture, "~/Member/Aircraft.aspx?a=1&m={0}", mfbEditMake1.MakeID);
                    lstAttribs.Add(new LinkedString(lnkViewAircraft.Text, lnkViewAircraft.NavigateUrl));
                }

                rptAttributes.DataSource = lstAttribs;
                rptAttributes.DataBind();
            }
            else
            {
                mvMake.SetActiveView(vwEdit);
                mvInstances.Visible = false;
                lblEditModel.Text   = Resources.Makes.newMakeHeader;
            }
        }

        mvInstances.SetActiveView(rgac.Count() == 0 ? vwSampleImages : vwAircraft);

        mfbImageList.Images = new ImageList(SampleImages.ToArray());
        mfbImageList.Refresh(false);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // This page is for search engines by default.
        if (Page.User.Identity.IsAuthenticated && String.IsNullOrEmpty(Request.PathInfo))
        {
            Response.Redirect("~/Member/Makes.aspx", true);
            return;
        }

        if (!IsPostBack)
        {
            Response.Cache.SetExpires(DateTime.Now.AddSeconds(1209600));
            Response.Cache.SetCacheability(System.Web.HttpCacheability.Public);
            Response.Cache.SetValidUntilExpires(true);

            this.Master.Title = String.Format(CultureInfo.CurrentCulture, Resources.Makes.AllMakesTitle, Branding.CurrentBrand.AppName);
            string[] rgIds   = Request.PathInfo.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            int      clevels = rgIds.Length;
            if (clevels >= mvLevelToShow.Views.Count)
            {
                return;
            }
            mvHeader.ActiveViewIndex = mvLevelToShow.ActiveViewIndex = clevels;

            try
            {
                switch (clevels)
                {
                case 0:     // base page - show manufacturers
                {
                    List <Manufacturer> lst = new List <Manufacturer>(Manufacturer.CachedManufacturers());
                    lst.RemoveAll(man => man.AllowedTypes != AllowedAircraftTypes.Any);
                    gvManufacturers.DataSource = lst;
                    gvManufacturers.DataBind();
                }
                break;

                case 1:     // specific manufacturer - show their models
                            // No images, just for performance
                {
                    int idMan = Convert.ToInt32(rgIds[0], CultureInfo.InvariantCulture);
                    if (ModelsByManufacturer.ContainsKey(idMan))
                    {
                        gvMakes.DataSource = ModelsByManufacturer[idMan];
                        gvMakes.DataBind();
                    }
                    else
                    {
                        throw new System.Web.HttpException(404, "Not found");
                    }
                }
                break;

                case 2:     // specific model - show all aircraft
                {
                    int idMan   = Convert.ToInt32(rgIds[0], CultureInfo.InvariantCulture);
                    int idModel = Convert.ToInt32(rgIds[1], CultureInfo.InvariantCulture);

                    if (!ModelsByManufacturer.ContainsKey(idMan))
                    {
                        throw new System.Web.HttpException(404, "Not found");
                    }

                    MakeModel m = ModelsByManufacturer[idMan].Find(mm => mm.MakeModelID == idModel);

                    if (m == null)
                    {
                        throw new System.Web.HttpException(404, "Not found");
                    }

                    rptAttributes.DataSource = m.AttributeList();
                    rptAttributes.DataBind();
                    lblModel.Text = m.DisplayName;

                    List <Aircraft> lst = new List <Aircraft>();
                    // UserAircraft.GetAircraftForUser is pretty heavyweight, especially for models witha  lot of aircraft like C-152.
                    // We just don't need that much detail, since we're just binding images by ID and tailnumbers
                    DBHelper dbh = new DBHelper(String.Format(CultureInfo.InvariantCulture, "SELECT idaircraft, tailnumber FROM aircraft WHERE idmodel=?modelid AND tailnumber NOT LIKE '{0}%' AND instanceType=1 ORDER BY tailnumber ASC", CountryCodePrefix.szAnonPrefix));
                    dbh.ReadRows((comm) => { comm.Parameters.AddWithValue("modelid", idModel); },
                                 (dr) =>
                        {
                            int idaircraft    = Convert.ToInt32(dr["idaircraft"], CultureInfo.InvariantCulture);
                            string tailnumber = (string)dr["tailnumber"];
                            lst.Add(new Aircraft()
                            {
                                AircraftID = idaircraft, TailNumber = tailnumber
                            });
                        });
                    gvAircraft.DataSource = lst;
                    gvAircraft.DataBind();
                }
                break;
                }
            }
            catch (FormatException)
            {
                Response.Clear();
                Response.StatusCode = 404;
                Response.End();
            }
        }
    }
Exemple #6
0
        public void gvAircraft_OnRowDataBound(Object sender, GridViewRowEventArgs e)
        {
            if (e != null && e.Row.RowType == DataControlRowType.DataRow)
            {
                Aircraft ac = (Aircraft)e.Row.DataItem;

                // Refresh the images
                if (!IsAdminMode)
                {
                    ((Controls_mfbHoverImageList)e.Row.FindControl("mfbHoverThumb")).Refresh();
                }

                // Show aircraft capabilities too.
                Control     popup      = e.Row.FindControl("popmenu1");
                RadioButton rbRoleNone = (RadioButton)popup.FindControl("rbRoleNone");
                RadioButton rbRoleCFI  = (RadioButton)popup.FindControl("rbRoleCFI");
                RadioButton rbRoleSIC  = (RadioButton)popup.FindControl("rbRoleSIC");
                RadioButton rbRolePIC  = (RadioButton)popup.FindControl("rbRolePIC");

                switch (ac.RoleForPilot)
                {
                case Aircraft.PilotRole.None:
                    rbRoleNone.Checked = true;
                    break;

                case Aircraft.PilotRole.CFI:
                    rbRoleCFI.Checked = true;
                    break;

                case Aircraft.PilotRole.SIC:
                    rbRoleSIC.Checked = true;
                    break;

                case Aircraft.PilotRole.PIC:
                    rbRolePIC.Checked = true;
                    break;
                }

                CheckBox ckIsFavorite = (CheckBox)popup.FindControl("ckShowInFavorites");
                ckIsFavorite.Checked = !ac.HideFromSelection;
                ckIsFavorite.Attributes["onclick"] = String.Format(CultureInfo.InvariantCulture, "javascript:toggleFavorite({0},this.checked,'{1}');", ac.AircraftID, ResolveClientUrl("~/Member/Aircraft.aspx/SetActive"));
                CheckBox ckAddName = (CheckBox)popup.FindControl("ckAddNameAsPIC");
                ckAddName.Checked = ac.CopyPICNameWithCrossfill;
                ckAddName.Attributes["onclick"] = String.Format(CultureInfo.InvariantCulture, "javascript:document.getElementById(\"{0}\").click();", rbRolePIC.ClientID);  // clicking the "Add Name" checkbox should effectively click the PIC checkbox.

                rbRoleNone.Attributes["onclick"] = String.Format(CultureInfo.InvariantCulture, "javascript:setRole({0},\"{1}\",false,document.getElementById(\"{2}\"),\"{3}\");", ac.AircraftID, Aircraft.PilotRole.None.ToString(), ckAddName.ClientID, ResolveClientUrl("~/Member/Aircraft.aspx/SetRole"));
                rbRoleCFI.Attributes["onclick"]  = String.Format(CultureInfo.InvariantCulture, "javascript:setRole({0},\"{1}\",false,document.getElementById(\"{2}\"),\"{3}\");", ac.AircraftID, Aircraft.PilotRole.CFI.ToString(), ckAddName.ClientID, ResolveClientUrl("~/Member/Aircraft.aspx/SetRole"));
                rbRoleSIC.Attributes["onclick"]  = String.Format(CultureInfo.InvariantCulture, "javascript:setRole({0},\"{1}\",false,document.getElementById(\"{2}\"),\"{3}\");", ac.AircraftID, Aircraft.PilotRole.SIC.ToString(), ckAddName.ClientID, ResolveClientUrl("~/Member/Aircraft.aspx/SetRole"));
                rbRolePIC.Attributes["onclick"]  = String.Format(CultureInfo.InvariantCulture, "javascript:setRole({0},\"{1}\",document.getElementById(\"{2}\").checked, document.getElementById(\"{3}\"),\"{4}\");", ac.AircraftID, Aircraft.PilotRole.PIC.ToString(), ckAddName.ClientID, ckAddName.ClientID, ResolveClientUrl("~/Member/Aircraft.aspx/SetRole"));

                ((Label)popup.FindControl("lblOptionHeader")).Text = String.Format(CultureInfo.CurrentCulture, Resources.Aircraft.optionHeader, ac.DisplayTailnumber);

                if (!IsAdminMode)
                {
                    List <LinkedString> lst = new List <LinkedString>();

                    if (ac.Stats != null)
                    {
                        lst.Add(ac.Stats.UserStatsDisplay);
                    }
                    MakeModel mm = MakeModel.GetModel(ac.ModelID);
                    if (mm != null)
                    {
                        if (!String.IsNullOrEmpty(mm.FamilyName))
                        {
                            lst.Add(new LinkedString(ModelQuery.ICAOPrefix + mm.FamilyName));
                        }

                        foreach (string sz in mm.AttributeList(ac.AvionicsTechnologyUpgrade, ac.GlassUpgradeDate))
                        {
                            lst.Add(new LinkedString(sz));
                        }
                    }

                    Repeater rpt = (Repeater)e.Row.FindControl("rptAttributes");
                    rpt.DataSource = lst;
                    rpt.DataBind();
                }

                Controls_mfbSelectTemplates selectTemplates = (Controls_mfbSelectTemplates)popup.FindControl("mfbSelectTemplates");
                foreach (int i in ac.DefaultTemplates)
                {
                    selectTemplates.AddTemplate(i);
                }

                selectTemplates.Refresh();

                if (IsAdminMode)
                {
                    HyperLink lnkRegistration = (HyperLink)e.Row.FindControl("lnkRegistration");
                    string    szURL           = ac.LinkForTailnumberRegistry();
                    lnkRegistration.Visible     = szURL.Length > 0;
                    lnkRegistration.NavigateUrl = szURL;
                }
            }
        }