Exemplo n.º 1
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            Design.DisplayWaitCursor(() =>
            {
                for (int i = this.workReports.Count - 1; i >= 0; i--)
                {
                    EditableWorkReport item = this.workReports[i];

                    // Some information is not set
                    if (!item.WrappedInstance.IsValid)
                    {
                        continue;
                    }

                    RemoteStore.WorkReport.SaveWorkReport(item.WrappedInstance);

                    // Remove successfully saved work report from the list
                    this.workReports.RemoveAt(i);
                }

                // Save workreports.
                Core.Xml.History.SaveHistory(this.workReports);

                this.Close();
            });
        }
Exemplo n.º 2
0
        void listView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            EditableWorkReport item = this.GetCurrentItem(e.OriginalSource);

            if (item != null)
            {
                this.EditWorkReport(item);
            }
        }
Exemplo n.º 3
0
        private bool IsUnfinishedWorkReport(out EditableWorkReport item)
        {
            item = this.GetLatestWorkReport();

            // When ToTime is not specified, work report has only started
            if (item != null && item.WrappedInstance.ToTime == DateTime.MinValue)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 4
0
        void EditWorkReport(EditableWorkReport item)
        {
            WorkReportWindow window = new WorkReportWindow();

            window.Owner      = this;
            window.WorkReport = item;

            if (window.ShowDialog().Value)
            {
                // Save workreports.
                Core.Xml.History.SaveHistory(this.workReports);
            }
        }
Exemplo n.º 5
0
        bool StopCounting(bool force = false, bool allowNew = true)
        {
            if (!this.startTime.HasValue)
            {
                return(true);
            }

            this.startTime = null;
            this.trayIcon.StopAnimation();
            this.ToolTipText = "Idle";

            EditableWorkReport item = this.GetLatestWorkReport();

            System.Diagnostics.Debug.Assert(item != null, "Cannot get latest work report");
            System.Diagnostics.Debug.Assert(item.WrappedInstance.ToTime == DateTime.MinValue, "There is some inconsistency in work report");

            bool keepCounting = false;

            if (force || !this.ShowNewWorkReport(item, DateTime.Now, out keepCounting))
            {
                this.workReports.Remove(item);

                allowNew = false;
            }

            // We have to save workreports because there is information about unfinished work report
            this.SaveWorkReports();

            // Continue counting
            if (!keepCounting)
            {
                if (!allowNew)
                {
                    return(true);
                }

                this.StartCounting(StartCountingReasons.AutoContinued);

                return(false);
            }
            else
            {
                this.KeepCounting(item.WrappedInstance.FromTime);

                return(false);
            }
        }
Exemplo n.º 6
0
        bool ShowNewWorkReport(EditableWorkReport item, DateTime endTime, out bool keepCounting)
        {
            keepCounting = false;

            this.saveNewWorkReportWindowDisplayed = true;
            try
            {
                item.WrappedInstance.ToTime  = endTime;
                item.WrappedInstance.Project = new Guid(Core.Settings.GetUserSetting("Project", Core.Settings.TIMECLOCK_REGISTRY_KEY, Guid.Empty.ToString()) as string);
                item.WrappedInstance.Type    = new Guid(Core.Settings.GetUserSetting("WorkReportType", Core.Settings.TIMECLOCK_REGISTRY_KEY, Guid.Empty.ToString()) as string);

                if (this.NewWorkReportShow != null)
                {
                    var workReportEventArgs = new WorkReportEventArgs(item);
                    this.NewWorkReportShow(this, workReportEventArgs);

                    // Item information accepted
                    if (workReportEventArgs.Handled)
                    {
                        keepCounting = workReportEventArgs.KeepCounting;

                        // Reset ToTime
                        if (keepCounting)
                        {
                            item.WrappedInstance.ToTime = default(DateTime);
                        }

                        return(true);
                    }
                }

                return(false);
            }
            finally
            {
                this.saveNewWorkReportWindowDisplayed = false;
            }
        }
Exemplo n.º 7
0
        private void DeleteItem(EditableWorkReport item)
        {
            if (item != null)
            {
                MessageBoxResult result = MessageBox.Show(
                    "Are you sure you want to remove selected item?",
                    Settings.APPLICATION_NAME,
                    MessageBoxButton.YesNo,
                    MessageBoxImage.Question
                    );

                if (result == MessageBoxResult.Yes)
                {
                    this.workReports.Remove(item);

                    // Save workreports.
                    Core.Xml.History.SaveHistory(this.workReports);

                    // Refresh view.
                    ICollectionView view = (ICollectionView)CollectionViewSource.GetDefaultView(this.listView.ItemsSource);
                    view.Refresh();
                }
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 public WorkReportEventArgs(EditableWorkReport workReport)
 {
     this.WorkReport = workReport;
 }