Skip to content
This repository was archived by the owner on May 18, 2022. It is now read-only.

Commit 5a6b821

Browse files
committed
Fixed Class Hierarchy and add day class. Need to fix issue with Observable Collection property in week class.
1 parent ae1164e commit 5a6b821

6 files changed

Lines changed: 71 additions & 86 deletions

File tree

TimeSheet/Windows/TimeSheet/Models/Calendar/Day.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ namespace TimeSheet.Windows.TimeSheet.Models.Calendar
1010
{
1111
public class Day
1212
{
13-
public ObservableCollection<TimeLog> TimeLogs { get; set; }
14-
public DayOfWeek DateDayOfWeek { get; set; }
13+
public ObservableCollection<TimeLog> TimeLogs { get; set; } = new ObservableCollection<TimeLog>();
14+
public DateTime DayDate { get; set; }
15+
16+
public Day() {}
1517

1618
public Day(DateTime date)
1719
{
18-
DateDayOfWeek = date.DayOfWeek;
20+
DayDate = date;
21+
}
22+
23+
public void AddTimeLog(TimeLog timeLog)
24+
{
25+
TimeLogs.Add(timeLog);
26+
DayDate = timeLog.TimeStamp;
1927
}
2028
}
2129
}

TimeSheet/Windows/TimeSheet/Models/Calendar/Week.cs

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ namespace TimeSheet.Windows.TimeSheet.Models.Calendar
77
{
88
public class Week
99
{
10-
public ObservableCollection<TimeLog> Sunday { get; } = new ObservableCollection<TimeLog>();
11-
public ObservableCollection<TimeLog> Monday { get; } = new ObservableCollection<TimeLog>();
12-
public ObservableCollection<TimeLog> Tuesday { get; } = new ObservableCollection<TimeLog>();
13-
public ObservableCollection<TimeLog> Wednesday { get; } = new ObservableCollection<TimeLog>();
14-
public ObservableCollection<TimeLog> Thursday { get; } = new ObservableCollection<TimeLog>();
15-
public ObservableCollection<TimeLog> Friday { get; } = new ObservableCollection<TimeLog>();
16-
public ObservableCollection<TimeLog> Saturday { get; } = new ObservableCollection<TimeLog>();
10+
/// <summary>
11+
/// 0 -> Sunday
12+
/// 1 -> Monday
13+
/// 2 -> Tuesday
14+
/// 3 -> Wednesday
15+
/// 4 -> Thursday
16+
/// 5 -> Friday
17+
/// 6 -> Saturday
18+
/// </summary>
19+
public ObservableCollection<Day> WeekDays { get; set; } = new ObservableCollection<Day>();
1720

1821
/// <summary>
1922
/// Returns the week number that the time stamp falls into
@@ -24,40 +27,5 @@ public static int GetWeekOfYear(DateTime timeStamp)
2427
System.Globalization.Calendar cal = new CultureInfo("en-US").Calendar;
2528
return cal.GetWeekOfYear(timeStamp, CalendarWeekRule.FirstDay, DayOfWeek.Sunday);
2629
}
27-
28-
/// <summary>
29-
/// Sets the observable collection property that correspond to the day of the time log
30-
/// </summary>
31-
/// <param name="week">week oject</param>
32-
/// <param name="timeLog">time log object containing day information</param>
33-
public void AddTimeLogByDay(Week week, TimeLog timeLog)
34-
{
35-
switch (timeLog.TimeStamp.DayOfWeek)
36-
{
37-
case DayOfWeek.Sunday:
38-
week.Sunday.Add(timeLog);
39-
break;
40-
case DayOfWeek.Monday:
41-
week.Monday.Add(timeLog);
42-
break;
43-
case DayOfWeek.Tuesday:
44-
week.Tuesday.Add(timeLog);
45-
break;
46-
case DayOfWeek.Wednesday:
47-
week.Wednesday.Add(timeLog);
48-
break;
49-
case DayOfWeek.Thursday:
50-
week.Thursday.Add(timeLog);
51-
break;
52-
case DayOfWeek.Friday:
53-
week.Friday.Add(timeLog);
54-
break;
55-
case DayOfWeek.Saturday:
56-
week.Saturday.Add(timeLog);
57-
break;
58-
default:
59-
throw new ArgumentOutOfRangeException();
60-
}
61-
}
6230
}
6331
}

TimeSheet/Windows/TimeSheet/Models/DataQuery/DataQuery.cs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
4+
using System.IO;
45
using System.Linq;
6+
using System.Runtime.Remoting.Metadata.W3cXsd2001;
7+
using System.Windows.Controls;
8+
using MahApps.Metro.Controls;
59
using TimeSheet.Windows.TimeSheet.Models.Calendar;
610

711
namespace TimeSheet.Windows.TimeSheet.Models.DataQuery
@@ -16,43 +20,47 @@ public class DataQuery
1620
/// </summary>
1721
/// <param name="data"></param>
1822
/// <returns></returns>
19-
public IEnumerable<IGrouping<int, TimeLog>> GroupDataByWeek(IEnumerable<TimeLog> data)
20-
{
21-
22-
IEnumerable<IGrouping<int, TimeLog>> groupByWeek =
23-
from timelog in data
24-
group timelog by Week.GetWeekOfYear(timelog.TimeStamp)
25-
into groupedByWeek
26-
orderby groupedByWeek.Key
27-
select groupedByWeek;
28-
23+
public IEnumerable<IGrouping<int, IGrouping<DayOfWeek, TimeLog>>> GroupDataByWeekAndDay(IEnumerable<TimeLog> data)
24+
{
25+
IEnumerable<IGrouping<int, IGrouping<DayOfWeek, TimeLog>>> groupByWeek =
26+
from timelog in data
27+
group timelog by Week.GetWeekOfYear(timelog.TimeStamp)
28+
into groupedByWeek
29+
from groupedByDay in (
30+
from timelogs in groupedByWeek
31+
group timelogs by timelogs.TimeStamp.DayOfWeek)
32+
group groupedByDay by groupedByWeek.Key;
33+
2934
//pull info from data base
3035
return groupByWeek;
31-
3236
}
3337

3438
/// <summary>
3539
/// Returns a Week object with the time stamp information of the week and year specified
3640
/// </summary>
37-
/// <param name="group">Data grouped by week number</param>
38-
/// <param name="numWeek">week to pull records from</param>
39-
/// <param name="numYear">year to pull records from</param>
41+
/// <param name="groupedData">Data grouped by week number</param>
42+
/// <param name="numWeek">Week of the year</param>
43+
/// <param name="year">year</param>
4044
/// <returns></returns>
41-
public Week GetWeekTimeLogs(IEnumerable<IGrouping<int, TimeLog>> group, int numWeek, int numYear)
45+
public Week GetWeekTimeLogs(IEnumerable<IGrouping<int, IGrouping<DayOfWeek, TimeLog>>> groupedData, int numWeek, int numYear)
4246
{
4347
Week week = new Week();
4448

45-
foreach (var weekGroups in group)
49+
foreach (var weekGroups in groupedData)
4650
{
47-
if (weekGroups.Key != numWeek)
51+
if(weekGroups.Key != numWeek)
4852
continue;
4953

50-
foreach (var timeLog in weekGroups)
54+
foreach (IGrouping<DayOfWeek, TimeLog> dayGroups in weekGroups)
5155
{
52-
if (timeLog.TimeStamp.Year != numYear)
53-
continue;
54-
55-
week.AddTimeLogByDay(week, timeLog);
56+
Day day = new Day();
57+
foreach (TimeLog timeLog in dayGroups)
58+
{
59+
if(timeLog.TimeStamp.Year != numYear)
60+
continue;
61+
day.AddTimeLog(timeLog);
62+
}
63+
week.WeekDays.Add(day);
5664
}
5765
}
5866
return week;

TimeSheet/Windows/TimeSheet/TimeSheetWindow.xaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@
9393
<DataGrid.Columns>
9494
<DataGridTemplateColumn Width="SizeToCells" MinWidth="120" SortMemberPath="Sunday">
9595
<DataGridTemplateColumn.HeaderTemplate>
96-
<DataTemplate>
96+
<DataTemplate DataType="calendar:Week">
9797
<StackPanel Margin="0, 0, 0, 2">
9898
<TextBlock Text="Sunday" FontFamily="Calibri" FontSize="18" FontWeight="Heavy" TextAlignment="Center"></TextBlock>
99-
<!-- <TextBlock Text="{Binding }" FontFamily="Calibri" FontSize="14" TextAlignment="Center"></TextBlock> -->
99+
<!-- <TextBlock Text="{Binding WeekDays[0].DayDate}" FontFamily="Calibri" FontSize="14" TextAlignment="Center"></TextBlock> -->
100100
</StackPanel>
101101
</DataTemplate>
102102
</DataGridTemplateColumn.HeaderTemplate>
103103
<DataGridTemplateColumn.CellTemplate>
104104
<DataTemplate DataType="calendar:Week">
105105
<Grid>
106-
<DataGrid IsHitTestVisible="True" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" FontFamily="Calibri" FontSize="14" HeadersVisibility="None" ColumnWidth="SizeToCells" MinColumnWidth="120" ItemsSource="{Binding Sunday}" GridLinesVisibility="Horizontal"></DataGrid>
106+
<DataGrid IsHitTestVisible="True" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" FontFamily="Calibri" FontSize="14" HeadersVisibility="None" ColumnWidth="SizeToCells" MinColumnWidth="120" ItemsSource="{Binding WeekDays[0].TimeLogs}" GridLinesVisibility="Horizontal"></DataGrid>
107107
</Grid>
108108
</DataTemplate>
109109
</DataGridTemplateColumn.CellTemplate>
@@ -121,7 +121,7 @@
121121
<DataGridTemplateColumn.CellTemplate>
122122
<DataTemplate DataType="calendar:Week">
123123
<Grid>
124-
<DataGrid IsHitTestVisible="False" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" FontFamily="Calibri" FontSize="14" HeadersVisibility="None" ColumnWidth="SizeToCells" MinColumnWidth="120" ItemsSource="{Binding Monday}" GridLinesVisibility="Horizontal"></DataGrid>
124+
<DataGrid IsHitTestVisible="False" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" FontFamily="Calibri" FontSize="14" HeadersVisibility="None" ColumnWidth="SizeToCells" MinColumnWidth="120" ItemsSource="{Binding WeekDays[1].TimeLogs}" GridLinesVisibility="Horizontal"></DataGrid>
125125
</Grid>
126126
</DataTemplate>
127127
</DataGridTemplateColumn.CellTemplate>
@@ -138,7 +138,7 @@
138138
</DataGridTemplateColumn.HeaderTemplate>
139139
<DataGridTemplateColumn.CellTemplate>
140140
<DataTemplate DataType="calendar:Week">
141-
<DataGrid IsHitTestVisible="False" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" FontFamily="Calibri" FontSize="14" HeadersVisibility="None" ColumnWidth="SizeToCells" MinColumnWidth="120" ItemsSource="{Binding Tuesday}" GridLinesVisibility="Horizontal"></DataGrid>
141+
<DataGrid IsHitTestVisible="False" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" FontFamily="Calibri" FontSize="14" HeadersVisibility="None" ColumnWidth="SizeToCells" MinColumnWidth="120" ItemsSource="{Binding WeekDays[2].TimeLogs}" GridLinesVisibility="Horizontal"></DataGrid>
142142
</DataTemplate>
143143
</DataGridTemplateColumn.CellTemplate>
144144
</DataGridTemplateColumn>
@@ -154,7 +154,7 @@
154154
</DataGridTemplateColumn.HeaderTemplate>
155155
<DataGridTemplateColumn.CellTemplate>
156156
<DataTemplate DataType="calendar:Week">
157-
<DataGrid IsHitTestVisible="False" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" FontFamily="Calibri" FontSize="14" HeadersVisibility="None" ColumnWidth="SizeToCells" MinColumnWidth="120" ItemsSource="{Binding Wednesday}" GridLinesVisibility="Horizontal"></DataGrid>
157+
<DataGrid IsHitTestVisible="False" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" FontFamily="Calibri" FontSize="14" HeadersVisibility="None" ColumnWidth="SizeToCells" MinColumnWidth="120" ItemsSource="{Binding WeekDays[3].TimeLogs}" GridLinesVisibility="Horizontal"></DataGrid>
158158
</DataTemplate>
159159
</DataGridTemplateColumn.CellTemplate>
160160
</DataGridTemplateColumn>
@@ -170,7 +170,7 @@
170170
</DataGridTemplateColumn.HeaderTemplate>
171171
<DataGridTemplateColumn.CellTemplate>
172172
<DataTemplate DataType="calendar:Week">
173-
<DataGrid IsHitTestVisible="False" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" FontFamily="Calibri" FontSize="14" HeadersVisibility="None" ColumnWidth="SizeToCells" MinColumnWidth="120" ItemsSource="{Binding Thursday}" GridLinesVisibility="Horizontal"></DataGrid>
173+
<DataGrid IsHitTestVisible="False" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" FontFamily="Calibri" FontSize="14" HeadersVisibility="None" ColumnWidth="SizeToCells" MinColumnWidth="120" ItemsSource="{Binding WeekDays[4].TimeLogs}" GridLinesVisibility="Horizontal"></DataGrid>
174174
</DataTemplate>
175175
</DataGridTemplateColumn.CellTemplate>
176176
</DataGridTemplateColumn>
@@ -186,7 +186,7 @@
186186
</DataGridTemplateColumn.HeaderTemplate>
187187
<DataGridTemplateColumn.CellTemplate>
188188
<DataTemplate DataType="calendar:Week">
189-
<DataGrid IsHitTestVisible="False" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" FontFamily="Calibri" FontSize="14" HeadersVisibility="None" ColumnWidth="SizeToCells" MinColumnWidth="120" ItemsSource="{Binding Friday}" GridLinesVisibility="Horizontal"></DataGrid>
189+
<DataGrid IsHitTestVisible="False" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" FontFamily="Calibri" FontSize="14" HeadersVisibility="None" ColumnWidth="SizeToCells" MinColumnWidth="120" ItemsSource="{Binding WeekDays[5].TimeLogs}" GridLinesVisibility="Horizontal"></DataGrid>
190190
</DataTemplate>
191191
</DataGridTemplateColumn.CellTemplate>
192192
</DataGridTemplateColumn>
@@ -202,7 +202,7 @@
202202
</DataGridTemplateColumn.HeaderTemplate>
203203
<DataGridTemplateColumn.CellTemplate>
204204
<DataTemplate DataType="calendar:Week">
205-
<DataGrid IsHitTestVisible="False" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" FontFamily="Calibri" FontSize="14" HeadersVisibility="None" ColumnWidth="SizeToCells" MinColumnWidth="120" ItemsSource="{Binding Saturday}" GridLinesVisibility="Horizontal"></DataGrid>
205+
<DataGrid IsHitTestVisible="False" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" FontFamily="Calibri" FontSize="14" HeadersVisibility="None" ColumnWidth="SizeToCells" MinColumnWidth="120" ItemsSource="{Binding WeekDays[6].TimeLogs}" GridLinesVisibility="Horizontal"></DataGrid>
206206
</DataTemplate>
207207
</DataGridTemplateColumn.CellTemplate>
208208
</DataGridTemplateColumn>

TimeSheet/Windows/TimeSheet/View Models/TimeSheetViewModel.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ private void OnLoadCommand()
8181

8282
currentWeekData.LoadSampleData();
8383

84-
var timeLogsGroupedByWeek = currentWeekData.GroupDataByWeek(DataQuery.Data);
84+
var timeLogsGroupedByWeek = currentWeekData.GroupDataByWeekAndDay(DataQuery.Data);
8585

8686
var currentWeekTimeStamps = currentWeekData.GetWeekTimeLogs(timeLogsGroupedByWeek, DataQuery.CurrentWeek, DateTime.Now.Year);
87-
87+
8888
WeekTimeStamps.Add(currentWeekTimeStamps);
8989
}
9090

@@ -99,7 +99,7 @@ private void OnSearchCommand()
9999

100100
DataQuery dataFromSearchedWeek = new DataQuery();
101101

102-
var timeLogsGroupedByWeek = dataFromSearchedWeek.GroupDataByWeek(DataQuery.Data);
102+
var timeLogsGroupedByWeek = dataFromSearchedWeek.GroupDataByWeekAndDay(DataQuery.Data);
103103

104104
var searchedWeekTimeStamps = dataFromSearchedWeek.GetWeekTimeLogs(timeLogsGroupedByWeek, int.Parse(NumWeek), int.Parse(NumYear));
105105

@@ -114,8 +114,8 @@ private void OnPreviousWeekCommand()
114114
WeekTimeStamps.Clear();
115115
DataQuery previousWeekData = new DataQuery();
116116
DataQuery.CurrentWeek -= 1;
117-
var timeLogsGroupedByWeek = previousWeekData.GroupDataByWeek(DataQuery.Data);
118-
117+
var timeLogsGroupedByWeek = previousWeekData.GroupDataByWeekAndDay(DataQuery.Data);
118+
119119
var previousWeekTimeStamps = previousWeekData.GetWeekTimeLogs(timeLogsGroupedByWeek, DataQuery.CurrentWeek, DateTime.Now.Year);
120120

121121
WeekTimeStamps.Add(previousWeekTimeStamps);
@@ -131,9 +131,9 @@ private void OnNextWeekCommand()
131131
DataQuery nextWeekData = new DataQuery();
132132
DataQuery.CurrentWeek += 1;
133133

134-
var timeLogsGroupedByWeek = nextWeekData.GroupDataByWeek(DataQuery.Data);
135-
136-
var nextWeekTimeStamps = nextWeekData.GetWeekTimeLogs(timeLogsGroupedByWeek, DataQuery.CurrentWeek , DateTime.Now.Year);
134+
var timeLogsGroupedByWeek = nextWeekData.GroupDataByWeekAndDay(DataQuery.Data);
135+
136+
var nextWeekTimeStamps = nextWeekData.GetWeekTimeLogs(timeLogsGroupedByWeek, DataQuery.CurrentWeek, DateTime.Now.Year);
137137

138138
WeekTimeStamps.Add(nextWeekTimeStamps);
139139
FirstDateOfCurrentWeek = FirstDateOfCurrentWeek.AddDays(7);
@@ -146,7 +146,7 @@ private void OnClockInCommand()
146146
{
147147
var todayTimeStamp = new TimeLog(TimeLog.TimeEntry.ClockIn, DateTime.Now);
148148
Week week = new Week();
149-
week.AddTimeLogByDay(week, todayTimeStamp);
149+
// week.AddTimeLogByDay(week, todayTimeStamp);
150150
WeekTimeStamps.Add(week);
151151
LastActivity = "Clocked in at " + todayTimeStamp.TimeStamp;
152152
}
@@ -157,7 +157,7 @@ private void OnClockOutCommand()
157157
{
158158
var todayTimeStamp = new TimeLog(TimeLog.TimeEntry.ClockOut, DateTime.Now);
159159
Week week = new Week();
160-
week.AddTimeLogByDay(week, todayTimeStamp);
160+
// week.AddTimeLogByDay(week, todayTimeStamp);
161161
WeekTimeStamps.Add(week);
162162
LastActivity = "Clocked out at " + todayTimeStamp.TimeStamp;
163163
}

0 commit comments

Comments
 (0)