Beispiel #1
0
        /// <summary>
        /// Returns a set of models for the specified aircraft, drawing from the cache if possible else doing a SINGLE database query
        /// </summary>
        /// <param name="rgac">An enumerable set of aircraft</param>
        /// <returns>A sorted (by model) enumerable list of matching models</returns>
        public static IEnumerable <MakeModel> ModelsForAircraft(IEnumerable <Aircraft> rgac)
        {
            if (rgac == null)
            {
                throw new ArgumentNullException("rgac");
            }
            Dictionary <int, MakeModel> dModels = new Dictionary <int, MakeModel>();
            List <int> lstIdsToGet = new List <int>();

            foreach (Aircraft ac in rgac)
            {
                if (!dModels.ContainsKey(ac.ModelID))
                {
                    MakeModel m = CachedModel(ac.ModelID);
                    dModels[ac.ModelID] = m ?? new MakeModel(); // if null, put in a placeholder so that we know we've seen it; we'll fill it in below.
                    if (m == null)
                    {
                        lstIdsToGet.Add(ac.ModelID);
                    }
                }
            }

            // Now get each of the models that didn't hit the cache
            if (lstIdsToGet.Count > 0)
            {
                DBHelper dbh = new DBHelper(String.Format(CultureInfo.InvariantCulture, szSQLSelectTemplate, String.Format(CultureInfo.InvariantCulture, "models.idmodel IN ({0})", String.Join(",", lstIdsToGet))));
                dbh.ReadRows((comm) => { }, (dr) =>
                {
                    MakeModel mm            = new MakeModel(dr);
                    dModels[mm.MakeModelID] = mm;   // overwrite the placeholder from above
                });
                if (dbh.LastError.Length > 0)
                {
                    throw new MyFlightbookException(String.Format(CultureInfo.InvariantCulture, "Error loading makes: {0}", dbh.LastError));
                }
            }

            List <MakeModel> lst = new List <MakeModel>();

            foreach (int mkey in dModels.Keys)
            {
                lst.Add(dModels[mkey]);
            }
            lst.Sort((mm1, mm2) => { return(mm1.Model.CompareCurrentCulture(mm2.Model)); });
            return(lst);
        }
Beispiel #2
0
        public void gvFlightLogs_RowDataBound(Object sender, GridViewRowEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (!(e.Row.DataItem is LogbookEntryBase le))
                {
                    throw new InvalidCastException("DataItem is not a logbook entry!");
                }

                // Property summary
                string szProperties = CustomFlightProperty.PropListDisplay(le.CustomProperties, false, "; ");
                if (szProperties.Length > 0)
                {
                    PlaceHolder plcProperties = (PlaceHolder)e.Row.FindControl("plcProperties");
                    TableCell   tc            = (TableCell)plcProperties.Parent;
                    tc.Text = szProperties;
                }

                // Splice in the custom property types.
                foreach (CustomFlightProperty cfp in le.CustomProperties)
                {
                    e.Row.Cells[PropertyColumnMap[cfp.PropTypeID]].Text = HttpUtility.HtmlEncode(cfp.ValueString);
                }

                // Add model attributes
                MakeModel m  = MakeModel.GetModel(AircraftForUser[le.AircraftID].ModelID);
                Aircraft  ac = AircraftForUser.ContainsKey(le.AircraftID) ? AircraftForUser[le.AircraftID] : null;
                ((Label)e.Row.FindControl("lblComplex")).Text   = m.IsComplex.FormatBooleanInt();
                ((Label)e.Row.FindControl("lblCSP")).Text       = m.IsConstantProp.FormatBooleanInt();
                ((Label)e.Row.FindControl("lblFlaps")).Text     = m.HasFlaps.FormatBooleanInt();
                ((Label)e.Row.FindControl("lblRetract")).Text   = m.IsRetract.FormatBooleanInt();
                ((Label)e.Row.FindControl("lblTailwheel")).Text = m.IsTailWheel.FormatBooleanInt();
                ((Label)e.Row.FindControl("lblHP")).Text        = m.IsHighPerf.FormatBooleanInt();
                ((Label)e.Row.FindControl("lblTurbine")).Text   = m.EngineType == MakeModel.TurbineLevel.Piston ? string.Empty : 1.FormatBooleanInt();
                ((Label)e.Row.FindControl("lblTAA")).Text       = (m.AvionicsTechnology == MakeModel.AvionicsTechnologyType.TAA ||
                                                                   (ac != null && (ac.AvionicsTechnologyUpgrade == MakeModel.AvionicsTechnologyType.TAA && (!ac.GlassUpgradeDate.HasValue || le.Date.CompareTo(ac.GlassUpgradeDate.Value) >= 0)))).FormatBooleanInt();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Checks to see if this possibly matches another make/model
        /// </summary>
        /// <param name="mm">The make/model to which it should be compared</param>
        /// <returns>True if it is a potential match</returns>
        public Boolean IsPossibleMatch(MakeModel mm)
        {
            if (mm == null)
            {
                throw new ArgumentNullException("mm");
            }
            string szCompare = rNormalize.Replace(mm.DisplayName, "").ToUpper(CultureInfo.CurrentCulture);

            // for now, let's see how this works if you just see if the manufacturer name is present AND the (modelname OR model) is present
            string szManufacturerNormal = rNormalize.Replace(ManufacturerDisplay, "").ToUpper(CultureInfo.CurrentCulture);
            string szModelNameNormal    = rNormalize.Replace(ModelName, "").ToUpper(CultureInfo.CurrentCulture);
            string szModelNormal        = rNormalize.Replace(Model, "").ToUpper(CultureInfo.CurrentCulture);

            Boolean fMatchManufacturer = szCompare.Contains(szManufacturerNormal);
            Boolean fMatchModel        = (szModelNormal.Length > 0 && szCompare.Contains(szModelNormal));
            Boolean fMatchModelName    = (szModelNameNormal.Length > 0 && szCompare.Contains(szModelNameNormal));
            Boolean fIsPossibleMatch   = fMatchManufacturer && (fMatchModel || fMatchModelName);

            return(fIsPossibleMatch);
        }