Exemple #1
0
        private void AutoUpdateDay(DateTime day)
        {
            try
            {
                var projectStatistics = WorktimeAnalyzer.AnalyzeWorkday(day);

                //in case the user forgot to log out
                try { WorktrackerUpdater.finishDay(day, Handler.currentProjectSince, projectStatistics.totalPausetime); } catch { }

                if (flagConsiderOvertime)
                {
                    var projectStatisticsAdapted = WorktimeAnalyzer.considerOvertimeUndertime(projectStatistics);
                    WorktrackerUpdater.updateFullDay(day, projectStatisticsAdapted, Handler.currentProjectSince); //unfortunately if something fails here, the overtime-db was updated anyways
                    WorktrackerUpdater.updateProjectEntries(day, projectStatisticsAdapted);
                }
                else
                {
                    WorktrackerUpdater.updateProjectEntries(day, projectStatistics);
                    WorktrackerUpdater.updateBreak(day, projectStatistics.totalPausetime);
                }
            }
            catch (Exception)
            {
                //TODO swallow - there is currently no sane way we can propagate this error out for showing e.g
                //a notification bubble as this is certainly not a projectChangeEvent
            }
        }
Exemple #2
0
        private void SetInWT_Click(object sender, EventArgs e)
        {
            WorktimeStatistics projectStatistics;

            try
            {
                projectStatistics = WorktimeAnalyzer.AnalyzeWorkday(Form.dateTimePicker1.Value);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }

            if (isHoliday(Form.dateTimePicker1.Value))
            {
                var dialogResult = MessageBox.Show("You should only do this at the end of the day! When done multiple times, overtimes will be wrong.\nAre you sure you want to log the worktime now?",
                                                   "ProjectTracker",
                                                   MessageBoxButtons.YesNo,
                                                   MessageBoxIcon.Exclamation);
                WorktimeAnalyzer.takeAllProjectimeAsOvertime(projectStatistics);
                if (dialogResult == DialogResult.No)
                {
                    return;
                }

                Form.currentOvertime.Text = WorktimeAnalyzer.sumTimespans(storage.getOvertimes().Values.ToList()).FormatForOvertime();
                MessageBox.Show("As it is a holiday, all project time was considered as overtime",
                                "ProjectTracker",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }

            try //it's a normal workday (and not a weekend/holiday)
            {
                if (!wtUpdater.WorktrackerConnect())
                {
                    throw new Exception("Could not connect to Worktracker");
                }

                if (Form.finishWTday.Checked)
                {
                    wtUpdater.finishDayNow(Form.dateTimePicker1.Value, projectStatistics.totalPausetime);
                }

                if (Form.flagConsiderOvertime.Checked)
                {
                    var projectStatisticsAdapted = WorktimeAnalyzer.considerOvertimeUndertime(projectStatistics);

                    DateTime from, to;
                    ProjectUtilities.getWorkDayByDate(Form.dateTimePicker1.Value, out from, out to);
                    var wtrs    = storage.getAllWorktimeRecords(from, to);
                    var maxDate = wtrs.Max(wtr => wtr.End);
                    var wtrsEnd = wtrs.First(wtr => wtr.End == maxDate).End;

                    wtUpdater.updateFullDay(Form.dateTimePicker1.Value, projectStatisticsAdapted, wtrsEnd); //unfortunately if something fails here, the overtime-db was updated anyways
                    wtUpdater.updateProjectEntries(Form.dateTimePicker1.Value, projectStatisticsAdapted);

                    Form.currentOvertime.Text = WorktimeAnalyzer.sumTimespans(storage.getOvertimes().Values.ToList()).FormatForOvertime();
                    MessageBox.Show("Day with under-/overtime and project entries were successfully set",
                                    "Worktracker",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
                else
                {
                    wtUpdater.updateProjectEntries(Form.dateTimePicker1.Value, projectStatistics);

                    MessageBox.Show("Project entries were successfully set",
                                    "Worktracker",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Worktracker-Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }