Exemple #1
0
        public void TrimEmptyPeriod()
        {
            if (Periods == null || Periods.Count == 0)
            {
                return;
            }
            int idx = Periods.Count - 1;
            var p   = Periods[idx];

            if (p.VabUpgrades == 0 && p.SphUpgrades == 0 && p.RndUpgrades == 0)
            {
                Periods.RemoveAt(idx);
            }
        }
Exemple #2
0
        public void Sync(DateTime date)
        {
            try
            {
                this.date = date;
                var    prop       = journalVM.SelectedProperty;
                Single goal       = UserSettings.Current.GetGoal(prop);
                Amount GoalAmount = Amount.FromProperty(goal, prop);
                var    cache      = Cache.GetEntryCache(date);

                SyncHeader(prop);
                SyncHeader(journalVM.NextProperty());

                int pi = 0;
                foreach (Period p in Cache.GetDatePeriods(date))
                {
                    Amount value = Cache.GetPeriodPropertyValue(date, p, prop);
                    int    width = (int)(GoalWidth * (value / GoalAmount));
                    if (GoalAmount.IsZero)
                    {
                        width = 0;
                    }
                    width = width <= 0 ? 0 : width;

                    JournalPeriodVM pvm = null;
                    while (Periods.Count > pi && Periods[pi].Period != p)
                    {
                        Periods.RemoveAt(pi);
                    }

                    if (Periods.Count > pi)
                    {
                        pvm = Periods[pi];
                    }
                    else
                    {
                        pvm = new JournalPeriodVM(p, Strings.FromEnum(p), ValuesTransform);
                        Periods.Add(pvm);
                    }

                    pvm.Value    = value.ValueString();
                    pvm.BarWidth = width;
                    pvm.Note     = Cache.GetPeriodNote(date, p);
                    pvm.Time     = Cache.GetPeriodTime(date, p);

                    int i = 0;
                    JournalLineItemVM line;
                    foreach (var entry in cache[(int)p])
                    {
                        while (pvm.Lines.Count > i && pvm.Lines[i].entry != entry)
                        {
                            pvm.Lines.RemoveAt(i);
                        }
                        if (pvm.Lines.Count > i)
                        {
                            line = pvm.Lines[i];
                        }
                        else
                        {
                            line = new JournalLineItemVM(entry, ValuesTransform);
                            pvm.Lines.Add(line);
                        }
                        line.Text  = entry.EntryText;
                        line.Value = entry.GetPropertyValue(prop).ValueString();
                        i++;
                    }

                    if (pvm.Lines.Count == 0)
                    {
                        pvm.Lines.Add(new JournalLineItemVM(null, ValuesTransform)
                        {
                            Text = AppResources.EmptyEntryList
                        });
                    }

                    pi++;
                }
            }
            catch (Exception ex) { LittleWatson.ReportException(ex); }
        }