View difference between Paste ID: sC09RaNb and BxYVsfzp
SHOW: | | - or go back to the newest paste.
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Web;
5
using System.Data.SqlClient;
6
using System.Globalization;
7
8
/// <summary>
9
/// Summary description for TestClass
10
/// </summary>
11
public class TestClass
12
{
13
	public TestClass()
14
	{
15
		//
16
		// TODO: Add constructor logic here
17
		//
18
	}
19-
    genericMethods gm = new genericMethods();
19+
20
    {
21
        public DateTime PunchInDate { get; set; }
22
        public DateTime PunchOutDate { get; set; }
23
        public DayOfWeek DayOfWeek { get; set; }
24
        public int WeekNumber { get; set; }
25
        public int MonthNumber { get; set; }
26
        public bool PunchedInLate { get; set; }
27
        public bool PunchedOutLate { get; set; }
28
    }
29
    public class Months
30
    {
31
        public int MonthNumber { get; set; }
32
        public List<Weeks> Weeks { get; set; }
33
    }
34
    public class Weeks
35
    {
36
        public int WeekNumber { get; set; }
37
        public List<Days> Days { get; set; }
38
    }
39
    public class Days
40
    {
41
        public bool PunchedInLate { get; set; }
42
        public bool PunchedOutLate { get; set; }
43
        public DateTime PunchInDate { get; set; }
44
        public DateTime PunchOutDate { get; set; }
45
        public DayOfWeek DayOfWeek { get; set; } 
46
    }
47
    protected int GetAmountOfMonths(List<allItems> list, int numberToFind)
48
    {
49
        List<allItems> results = list.FindAll(
50
            delegate(allItems ai)
51
            {
52
                return ai.MonthNumber == numberToFind;
53
            }
54
            );
55
        return results.Count;
56
    }
57
    protected int GetNumberOfWeeks(List<allItems> list, int numberToFind)
58
    {
59
        List<allItems> results = list.FindAll(
60
            delegate(allItems ai)
61
            {
62
                return ai.WeekNumber == numberToFind;
63
            }
64
            );
65
        return results.Count;
66
    }
67
    public List<Months> getStats(string userId)
68
    {
69
        List<allItems> allStats = getAllStats(userId);
70
        List<Months> stats = new List<Months>();
71
        var asItems =
72
        from item in allStats
73
        group item by new { month = item.MonthNumber } into Month
74
        select new Months()
75
        {
76
            MonthNumber = Month.Key.month,
77
            Weeks = Month.Select(week =>
78
                from item in allStats
79
                group item by new { week = item.WeekNumber } into Week
80
                select new Weeks()
81
                {
82
                    WeekNumber = Week.Key.week,
83
                    Days = Month.Select(days =>
84
                        new Days()
85
                        {
86
                            PunchedInLate = days.PunchedInLate,
87
                            PunchedOutLate = days.PunchedOutLate,
88
                            DayOfWeek = days.DayOfWeek,
89
                            PunchInDate = days.PunchInDate,
90
                            PunchOutDate = days.PunchOutDate
91
                        }).ToList()
92
                })
93
        };
94
        List<Months> stat = asItems.ToList();
95
        return stat;
96
    }
97
    public List<allItems> getAllStats(string userId)
98
    {
99
        List<allItems> stats = new List<allItems>();
100
101
        CultureInfo CultInfo = CultureInfo.CurrentCulture;
102
103
        bool addToList = false;
104
        allItems item = new allItems();
105
        for (int i = 0; i < 10; i++)
106
        {
107
            DateTime dt = DateTime.Now.AddDays(i+3);
108
            string punchInTime = "Kommet for sent";
109
            string punchOutTime = "Gået før flex tid";
110
            item.PunchInDate = dt;
111
            item.PunchOutDate = dt;
112
            item.DayOfWeek = dt.DayOfWeek;
113
            item.MonthNumber = dt.Month;
114
            if (punchInTime == "Kommet for sent")
115
            {
116
                item.PunchedInLate = true;
117
                addToList = true;
118
            }
119
            if (punchOutTime == "Gået før flex-tid")
120
            {
121
                item.PunchedOutLate = true;
122
                addToList = true;
123
            }
124
125
            item.WeekNumber = CultInfo.Calendar.GetWeekOfYear(dt, CultInfo.DateTimeFormat.CalendarWeekRule, CultInfo.DateTimeFormat.FirstDayOfWeek);
126
127
            if (addToList)
128
            {
129
                stats.Add(item);
130
            }
131
        }
132
133
        return stats;
134
    }
135
}