/// <summary> /// Display the statistics for this aircraft /// </summary> protected IEnumerable <LinkedString> StatsForUser(Aircraft ac) { if (ac == null) { throw new ArgumentNullException(nameof(ac)); } if (ac.IsNew) { return(Array.Empty <LinkedString>()); // nothing to add for a new aircraft } List <LinkedString> lst = new List <LinkedString>(); Stats = new AircraftStats(Page.User.Identity.Name, ac.AircraftID); // Add overall stats lst.Add(new LinkedString(String.Format(CultureInfo.CurrentCulture, Resources.LocalizedText.EditAircraftUserStats, Stats.Users, Stats.Flights))); // And add personal stats lst.Add(Stats.UserStatsDisplay); if (AdminMode && util.GetStringParam(Request, "listUsers").Length > 0) { lst.Add(new LinkedString(String.Format(CultureInfo.CurrentCulture, "Users = {0}", String.Join(", ", Stats.UserNames)))); } return(lst); }
/// <summary> /// Populates stats, if needed. /// </summary> protected void PopulateStats() { if (String.IsNullOrEmpty(hdnStatsFetched.Value)) { hdnStatsFetched.Value = "yes"; RefreshAircraftList(); AircraftStats.PopulateStatsForAircraft(SourceAircraft, Page.User.Identity.Name); } }
protected void Refresh() { if (GroupingMode == AircraftGroup.GroupMode.Recency && String.IsNullOrEmpty(hdnStatsFetched.Value)) { hdnStatsFetched.Value = "yes"; AircraftStats.PopulateStatsForAircraft(SourceAircraft, Page.User.Identity.Name); } rptAircraftGroups.DataSource = AircraftGroup.AssignToGroups(SourceAircraft, IsAdminMode ? AircraftGroup.GroupMode.All : GroupingMode); rptAircraftGroups.DataBind(); }
/// <summary> /// Deletes an aircraft from the user's list. Does NOT remove the underlying aircraft. /// </summary> /// <param name="AircraftID">The ID of the aircraft to delete</param> /// <returns>The updated list of aircraft for the user.</returns> public Aircraft[] FDeleteAircraftforUser(int AircraftID) { if (String.IsNullOrEmpty(User)) { throw new MyFlightbookException("No user specified for Deleteaircraft"); } AircraftStats acs = new AircraftStats(User, AircraftID); // if the user has no flights with this aircraft, simply remove it from their list and be done if (acs.UserFlights != 0) { throw new MyFlightbookException(Resources.Aircraft.errAircraftInUse); } else { new DBHelper().DoNonQuery("DELETE FROM useraircraft WHERE userName=?username AND idAircraft=?aircraftID", (comm) => { comm.Parameters.AddWithValue("username", User); comm.Parameters.AddWithValue("aircraftID", AircraftID); } ); InvalidateCache(); } // Delete any deadlines associated with this aircraft foreach (DeadlineCurrency dc in DeadlineCurrency.DeadlinesForUser(User, AircraftID)) { dc.FDelete(); } // And delete any custom currencies associated with the aircraft foreach (CustomCurrency cc in CustomCurrency.CustomCurrenciesForUser(User)) { List <int> ids = new List <int>(cc.AircraftRestriction); if (ids.Contains(AircraftID)) { ids.Remove(AircraftID); cc.AircraftRestriction = ids; cc.FCommit(); } } // we don't actually delete the aircraft; no need to do so, even if it's not used by anybody because // (a) we can't force caches of aircraft lists to be invalid and, // (b) no harm from keeping it - if somebody re-uses the tailnumber, it will re-use the existing flight. return(GetAircraftForUser()); }