public void Delete(IWorkday workday)
 {
     if (workday == null) throw new ArgumentNullException(nameof(workday));
     if (!_allWorkdays.Contains(workday))
         throw new ArgumentOutOfRangeException("this workday is not existent in repository, therefore cant delete it");
     _allWorkdays.Remove(workday);
 }
 public void Add(IWorkday workday)
 {
     if (workday == null) throw new ArgumentNullException(nameof(workday));
     if(_allWorkdays.Any(o => o.Date.Equals(workday.Date)))
         throw new ArgumentException("there is already a workday with this date in repository, therefore cant add it");
     _allWorkdays.Add(workday);
 }
 public void Update(IWorkday workday)
 {
     if (workday == null) throw new ArgumentNullException(nameof(workday));
     if(!_allWorkdays.Any(o => o.Date.Equals(workday.Date)))
         throw new ArgumentOutOfRangeException("there is no workday with specified date in repository, therefore cant update it");
     _allWorkdays.Remove(_allWorkdays.FirstOrDefault(o => o.Date.Equals(workday.Date)));
     _allWorkdays.Add(workday);
 }
 public WorkdayStatistics(IWorkday workday, IMutableTimeSpanFactory timeSpanFactory, IPlannedWorktimeRepository plannedWorktimeRepository)
 {
     if (workday == null) throw new ArgumentNullException(nameof(workday));
     if (timeSpanFactory == null) throw new ArgumentNullException(nameof(timeSpanFactory));
     if (plannedWorktimeRepository == null) throw new ArgumentNullException(nameof(plannedWorktimeRepository));
     _workday = workday;
     _timeSpanFactory = timeSpanFactory;
     _plannedWorktimeRepository = plannedWorktimeRepository;
 }
 public WorkdayInMemoryRepositoryTests()
 {
     _workdays = new List<IWorkday>();
     _someDate = new Date(19, 6, 1991);
     _someWorkday = new Workday(_someDate,
         new EntryExitTime(new MutableDayTime(10, 0), new MutableDayTime(11, 0)), new MutableTimeSpan());
     _workdays.Add(_someWorkday);
     _workdays.Add(new Workday(new Date(6, 6, 1990), new EntryExitTime(new MutableDayTime(6, 0), new MutableDayTime(8, 0)), new MutableTimeSpan()));
     _workdays.Add(new Workday(new Date(5, 7, 1995), new EntryExitTime(new MutableDayTime(1, 0), new MutableDayTime(2, 0)), new MutableTimeSpan()));
     _workdayRepository = new WorkdayInMemoryRepository(_workdays);
 }
Example #6
0
        public static void Load(DataGridView dgv)
        {
            dgv.Rows.Clear();

            Color lgray = Color.FromArgb(255, 240, 240, 240);
            Color lred  = Color.FromArgb(255, 255, 244, 244);

            DateTime chosenMonth;
            {
                var now = DateTime.Now;
                chosenMonth = now.AddDays(0 - now.Day - 1);
            }
            var workdays   = WorkdayHelper.Range(chosenMonth.Year, chosenMonth.Month);
            var workdayKvp = GetData(chosenMonth.Year, chosenMonth.Month);
            var workKvp    = workdayKvp.ToDictionary(wd => wd.Date);

            // Collection already belongs to a DataGridView control. This operation is no longer valid.
            for (int i = 0; i < workdays.Count; i++)
            {
                IWorkday wd = workdays[i];
                if (workKvp.ContainsKey(wd.DateText) && !wd.IsWeekend())
                {
                    dgv.Rows.Add
                    (
                        wd.DateText,
                        wd.DayOfWeekText,
                        workKvp[wd.DateText].ArrivalHours.ToString("0.0"),
                        workKvp[wd.DateText].BreakHours.ToString("0.0"),
                        workKvp[wd.DateText].DepartureHours.ToString("0.0")
                    );

                    if (Enum.TryParse <TimeConfidence>(workKvp[wd.DateText].ArrivalConfidence, out TimeConfidence arrivalConfidence))
                    {
                        if (arrivalConfidence == TimeConfidence.Confident)
                        {
                            dgv.Rows[i].Cells[2].Style.BackColor = lred;
                        }
                    }

                    if (Enum.TryParse <TimeConfidence>(workKvp[wd.DateText].DepartureConfidence, out TimeConfidence departureConfidence))
                    {
                        if (departureConfidence == TimeConfidence.Confident)
                        {
                            dgv.Rows[i].Cells[4].Style.BackColor = lred;
                        }
                    }
                }
                else
                {
                    dgv.Rows.Add
                    (
                        wd.DateText,
                        wd.DayOfWeekText
                    );
                }

                if (wd.IsWeekend())
                {
                    dgv.Rows[i].DefaultCellStyle.BackColor = lgray;
                }

                //dgv.Rows[i].Cells[0].Value = wd.Date;
                //dgv.Rows[i].Cells[1].Value = wd.DayOfWeek;
            }

            // Use pre-defined columns instead `dgv.DataSource = data.Workdays`;
        }