Пример #1
0
 private void UpdateStatus()
 {
     if (currentStartTime.HasValue)
     {
         var ts = DateTime.Now - currentStartTime.Value;
         textBlockStatus.Text = String.Format(Properties.Resources.TEXT_RECORD_START_0_1_2, currentStartTime.Value.ToShortDateString(), currentStartTime.Value.ToShortTimeString(), DurationValueConverter.Convert(ts));
     }
 }
Пример #2
0
        private void UpdateTotalHours()
        {
            double dur = WorkTime.CalculateTotalHours(workTimes);

            textBlockTotal.Text = string.Format(Properties.Resources.TEXT_TOTAL_0_1, datePicker.SelectedDate.Value.ToLongDateString(), DurationValueConverter.Convert(dur));
        }
        private void Calculate()
        {
            var oldcursor = Cursor;

            Cursor = Cursors.Wait;
            try
            {
                textBlockResult.Text = "";
                textBlockInfo.Text   = "";
                weekOvertimes.Clear();
                if (!datePickerStartDay.SelectedDate.HasValue ||
                    !double.TryParse(textBoxHoursPerWeek.Text, out double hoursPerWeek) ||
                    !double.TryParse(textBoxStartOverTimeHours.Text, out double overTimeBefore))
                {
                    return;
                }
                var from = datePickerStartDay.SelectedDate.Value.GetDayDateTime();
                var to   = DateTime.Today;
                textBlockInfo.Text = string.Format(Properties.Resources.TEXT_OVERTIME_0_1, from.ToLongDateString(), to.ToLongDateString());
                var freeDays = new HashSet <DateTime>();
                var halfDays = new HashSet <DateTime>();
                foreach (var nwd in database.SelectAllNonWorkingDays())
                {
                    for (var day = nwd.StartDay; day <= nwd.EndDay; day = day.AddDays(1.0))
                    {
                        freeDays.Add(day);
                        if (nwd.Hours == 4)
                        {
                            halfDays.Add(day);
                        }
                    }
                }
                var    weekInfo    = new Dictionary <Tuple <int, int>, Tuple <double, double> >();
                double overTime    = overTimeBefore;
                double hoursPerDay = hoursPerWeek / 5.0;
                var    dfi         = DateTimeFormatInfo.CurrentInfo;
                var    cal         = dfi.Calendar;
                var    dt          = from;
                while (dt < to)
                {
                    var hours      = WorkTime.CalculateTotalHours(database.SelectWorkTimes(dt));
                    var weekofyear = cal.GetWeekOfYear(dt, dfi.CalendarWeekRule, dfi.FirstDayOfWeek);
                    var key        = Tuple.Create(dt.Year, weekofyear);
                    if (!weekInfo.TryGetValue(key, out Tuple <double, double> t))
                    {
                        t             = Tuple.Create(0.0, 0.0);
                        weekInfo[key] = t;
                    }
                    if (!dt.IsWorkDay() || freeDays.Contains(dt))
                    {
                        if (dt.IsWorkDay() && halfDays.Contains(dt))
                        {
                            overTime     += hours - hoursPerDay / 2;
                            weekInfo[key] = Tuple.Create(t.Item1 + hours, t.Item2 + hoursPerDay / 2);
                        }
                        else
                        {
                            overTime     += hours;
                            weekInfo[key] = Tuple.Create(t.Item1 + hours, t.Item2);
                        }
                    }
                    else
                    {
                        overTime     += hours - hoursPerDay;
                        weekInfo[key] = Tuple.Create(t.Item1 + hours, t.Item2 + hoursPerDay);
                    }
                    dt = dt.AddDays(1.0);
                }
                textBlockResult.Text = string.Format(Properties.Resources.TEXT_TOTAL_OVERTIME_0, DurationValueConverter.Convert(overTime));
                var items = new List <WeekOvertime>();
                foreach (var elem in weekInfo)
                {
                    var weekovertime = new WeekOvertime(
                        elem.Key.Item1,
                        elem.Key.Item2,
                        elem.Value.Item1,
                        elem.Value.Item2);
                    items.Add(weekovertime);
                }
                items.Reverse();
                foreach (var item in items)
                {
                    weekOvertimes.Add(item);
                }
            }
            catch (Exception ex)
            {
                Cursor = oldcursor;
                HandleError(ex);
            }
            finally
            {
                Cursor = oldcursor;
            }
        }