Пример #1
0
        private void DisplayDetails(bool highlightName = false)
        {
            if (TableGrid.SelectedItem == null)
            {
                return;
            }

            if (!detailsView.CloseWithoutSave()) // close previous work
            {
                return;
            }

            detailsView.MainWindow = this;
            TimeEntryView selectedViewEntry = TableGrid.SelectedItem as TimeEntryView;
            TimeEntry     selectedEntry     = entryByIds[selectedViewEntry.GetId()];

            detailsView.Show();
            detailsView.Focus();
            detailsView.SelectedTimeEntry = selectedEntry;
            // set all the text values on the screen
            detailsView.NameField.Text      = selectedEntry.Name;
            detailsView.DetailsField.Text   = selectedEntry.Details;
            detailsView.TimeStatusText.Text = selectedEntry.IsActive ? "Yes" : "No";
            detailsView.CurrentTime.Text    = selectedEntry.ToView(0).Hours;

            detailsView.PendingOffset = 0;

            if (highlightName)
            {
                detailsView.NameField.Focus();
                detailsView.NameField.SelectAll();
            }
        }
Пример #2
0
        private void ToggleEntryTimer()
        {
            if (TableGrid.SelectedItem == null)
            {
                return;
            }

            TimeEntryView selectedViewEntry = TableGrid.SelectedItem as TimeEntryView;
            TimeEntry     selectedEntry     = entryByIds[selectedViewEntry.GetId()];

            if (selectedEntry.IsActive)
            {
                selectedEntry.StopTimer();
            }
            else
            {
                SwitchTimer(selectedEntry);
            }

            SaveImmediately();
        }
Пример #3
0
        private void RefreshViewCollection(bool openNewEntry = true)
        {
            // Merge / update differences between the currentTimeEntries and viewCollection

            // Use reverse for-int loop so we can modify the collection.
            for (int i = viewCollection.Count - 1; i >= 0; i--)
            {
                TimeEntryView view = viewCollection[i];
                int           id   = view.GetId();
                if (!entryByIds.ContainsKey(id))
                {
                    continue;
                }

                // check if we deleted a record from CurrentTimeEntries
                // viewCollection could be out of date here
                if (!CurrentTimeEntries.Contains(entryByIds[id]))
                {
                    viewCollection.RemoveAt(i);
                    continue;
                }

                // update row details every tick
                TimeEntryView newView = entryByIds[id].ToView(id);
                view.Active  = newView.Active;
                view.Hours   = newView.Hours;
                view.Name    = newView.Name;
                view.Details = newView.Details;
            }

            // Insert new
            foreach (TimeEntry entry in CurrentTimeEntries)
            {
                if (entryByIds.ContainsValue(entry))
                {
                    continue;
                }

                int newId = entryByIds.Keys.Count + 1;
                entryByIds[newId] = entry;
                var newRow = entry.ToView(newId);
                viewCollection.Add(newRow);

                if (openNewEntry)
                {
                    // autoselect newest entry
                    TableGrid.SelectedItem = newRow;
                    TableGrid.ScrollIntoView(newRow);
                    DisplayDetails(true); // trigger Edit window
                }
            }

            //viewCollection.Clear();
            //foreach (TimeEntry entry in currentTimeEntries)
            //{
            //    viewCollection.Add(entry.ToView());
            //}

            TotalHours.Text = CurrentTimeEntries.Sum(m => m.DurationHours)
                              .ToString("0.00") + " total hours";
        }