/// <summary>
        /// Computes the progress against this milestone
        /// </summary>
        /// <returns>A list of MilestoneItem objects</returns>
        virtual public Collection <MilestoneItem> Refresh()
        {
            if (String.IsNullOrEmpty(Username))
            {
                throw new MyFlightbookException("Cannot compute milestones on an empty user!");
            }

            List <ExaminerFlightRow> lstRows  = new List <ExaminerFlightRow>();
            StringBuilder            sbRoutes = new StringBuilder();

            DBHelper dbh = new DBHelper(CurrencyExaminer.CurrencyQuery(CurrencyExaminer.CurrencyQueryDirection.Descending));

            dbh.ReadRows(
                (comm) =>
            {
                comm.Parameters.AddWithValue("UserName", Username);
                comm.Parameters.AddWithValue("langID", System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName);
            },
                (dr) =>
            {
                ExaminerFlightRow cfr = new ExaminerFlightRow(dr);
                sbRoutes.AppendFormat(CultureInfo.InvariantCulture, "{0} ", cfr.Route);
                lstRows.Add(cfr);       // we'll examine it below, after we've populated the routes
            });

            // Set up the airport list once for DB efficiency
            AirportListOfRoutes = new AirportList(sbRoutes.ToString());

            lstRows.ForEach(cfr => { ExamineFlight(cfr); });

            return(Milestones);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Computes the progress against this milestone
        /// </summary>
        /// <returns>A list of MilestoneItem objects</returns>
        public Collection <MilestoneItem> Refresh()
        {
            if (String.IsNullOrEmpty(Username))
            {
                throw new MyFlightbookException("Cannot compute milestones on an empty user!");
            }

            // get all custom flight properties that could contribute to currency of one sort or another
            // and stick them into a dictionary for retrieval down below by flightID.
            Dictionary <int, List <CustomFlightProperty> > dctFlightEvents = new Dictionary <int, List <CustomFlightProperty> >();     // flight events (IPC, Instrument checkrides, etc.), keyed by flight ID
            IEnumerable <CustomFlightProperty>             rgPfe           = CustomFlightProperty.GetFlaggedEvents(Username);

            foreach (CustomFlightProperty pfe in rgPfe)
            {
                List <CustomFlightProperty> lstpf = (dctFlightEvents.ContainsKey(pfe.FlightID) ? dctFlightEvents[pfe.FlightID] : null);
                if (lstpf == null)
                {
                    dctFlightEvents.Add(pfe.FlightID, lstpf = new List <CustomFlightProperty>());
                }
                lstpf.Add(pfe);
            }

            List <ExaminerFlightRow> lstRows  = new List <ExaminerFlightRow>();
            StringBuilder            sbRoutes = new StringBuilder();

            DBHelper dbh = new DBHelper(CurrencyExaminer.CurrencyQuery(CurrencyExaminer.CurrencyQueryDirection.Descending));

            dbh.ReadRows(
                (comm) =>
            {
                comm.Parameters.AddWithValue("UserName", Username);
                comm.Parameters.AddWithValue("langID", System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName);
            },
                (dr) =>
            {
                ExaminerFlightRow cfr = new ExaminerFlightRow(dr);
                if (dctFlightEvents.ContainsKey(cfr.flightID))
                {
                    cfr.AddEvents(dctFlightEvents[cfr.flightID]);
                }
                sbRoutes.AppendFormat("{0} ", cfr.Route);
                lstRows.Add(cfr);       // we'll examine it below, after we've populated the routes
            });

            // Set up the airport list once for DB efficiency
            AirportListOfRoutes = new AirportList(sbRoutes.ToString());

            lstRows.ForEach(cfr => { ExamineFlight(cfr); });

            return(Milestones);
        }
Exemplo n.º 3
0
 private static CurrencyStatusItem StatusForDate(DateTime dt, string szLabel, CurrencyStatusItem.CurrencyGroups rt)
 {
     if (dt.CompareTo(DateTime.MinValue) != 0)
     {
         TimeSpan      ts   = dt.Subtract(DateTime.Now);
         int           days = (int)Math.Ceiling(ts.TotalDays);
         CurrencyState cs   = (days < 0) ? CurrencyState.NotCurrent : ((ts.Days < 30) ? CurrencyState.GettingClose : CurrencyState.OK);
         return(new CurrencyStatusItem(szLabel, CurrencyExaminer.StatusDisplayForDate(dt), cs, (cs == CurrencyState.GettingClose) ? String.Format(CultureInfo.CurrentCulture, Resources.Profile.ProfileCurrencyStatusClose, days) :
                                       (cs == CurrencyState.NotCurrent) ? String.Format(CultureInfo.CurrentCulture, Resources.Profile.ProfileCurrencyStatusNotCurrent, -days) : string.Empty)
         {
             CurrencyGroup = rt
         });
     }
     else
     {
         return(null);
     }
 }