Ejemplo n.º 1
0
        async private void ButtonTimeEdit_Click(object sender, EventArgs s)
        {
            TimeSpan oldSpan = TimeSpan.Parse(labelTimeTrackingTrackedTime.Text);

            using (EditTimeForm form = new EditTimeForm(oldSpan))
            {
                if (form.ShowDialog() == DialogResult.OK)
                {
                    TimeSpan newSpan = form.GetTimeSpan();
                    bool     add     = newSpan > oldSpan;
                    TimeSpan diff    = add ? newSpan - oldSpan : oldSpan - newSpan;
                    if (diff != TimeSpan.Zero)
                    {
                        MergeRequestDescriptor mrd = _workflow.State.MergeRequestDescriptor;

                        await _timeTrackingManager.AddSpanAsync(add, diff, mrd);

                        updateTotalTime(_workflow.State.MergeRequestDescriptor);
                        labelWorkflowStatus.Text = "Total spent time updated";

                        Trace.TraceInformation(String.Format("[MainForm] Total time for MR {0} (project {1}) changed to {2}",
                                                             mrd.IId, mrd.ProjectName, diff.ToString()));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private async Task editTrackedTimeAsync(MergeRequestKey mrk, DataCache dataCache)
        {
            IMergeRequestEditor editor     = _shortcuts.GetMergeRequestEditor(mrk);
            TimeSpan?           oldSpanOpt = dataCache?.TotalTimeCache?.GetTotalTime(mrk).Amount;

            if (!oldSpanOpt.HasValue)
            {
                return;
            }

            TimeSpan oldSpan = oldSpanOpt.Value;

            using (EditTimeForm form = new EditTimeForm(oldSpan))
            {
                if (form.ShowDialog() == DialogResult.OK)
                {
                    TimeSpan newSpan  = form.TimeSpan;
                    bool     add      = newSpan > oldSpan;
                    TimeSpan diffTemp = add ? newSpan - oldSpan : oldSpan - newSpan;
                    TimeSpan diff     = new TimeSpan(diffTemp.Hours, diffTemp.Minutes, diffTemp.Seconds);
                    if (diff == TimeSpan.Zero || dataCache?.TotalTimeCache == null)
                    {
                        return;
                    }

                    try
                    {
                        await editor.AddTrackedTime(diff, add);
                    }
                    catch (TimeTrackingException ex)
                    {
                        string message = "Cannot edit total tracked time";
                        ExceptionHandlers.Handle(message, ex);
                        MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    updateTotalTime(mrk, dataCache);
                    addOperationRecord("Total spent time has been updated");

                    Trace.TraceInformation(String.Format("[MainForm] Total time for MR {0} (project {1}) changed to {2}",
                                                         mrk.IId, mrk.ProjectKey.ProjectName, diff.ToString()));
                }
            }
        }