Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Data.SqlClient;
- using System.Globalization;
- /// <summary>
- /// Summary description for TestClass
- /// </summary>
- public class TestClass
- {
- public TestClass()
- {
- //
- // TODO: Add constructor logic here
- //
- }
- public class allItems
- {
- public DateTime PunchInDate { get; set; }
- public DateTime PunchOutDate { get; set; }
- public DayOfWeek DayOfWeek { get; set; }
- public int WeekNumber { get; set; }
- public int MonthNumber { get; set; }
- public bool PunchedInLate { get; set; }
- public bool PunchedOutLate { get; set; }
- }
- public class Months
- {
- public int MonthNumber { get; set; }
- public List<Weeks> Weeks { get; set; }
- }
- public class Weeks
- {
- public int WeekNumber { get; set; }
- public List<Days> Days { get; set; }
- }
- public class Days
- {
- public bool PunchedInLate { get; set; }
- public bool PunchedOutLate { get; set; }
- public DateTime PunchInDate { get; set; }
- public DateTime PunchOutDate { get; set; }
- public DayOfWeek DayOfWeek { get; set; }
- }
- protected int GetAmountOfMonths(List<allItems> list, int numberToFind)
- {
- List<allItems> results = list.FindAll(
- delegate(allItems ai)
- {
- return ai.MonthNumber == numberToFind;
- }
- );
- return results.Count;
- }
- protected int GetNumberOfWeeks(List<allItems> list, int numberToFind)
- {
- List<allItems> results = list.FindAll(
- delegate(allItems ai)
- {
- return ai.WeekNumber == numberToFind;
- }
- );
- return results.Count;
- }
- public List<Months> getStats(string userId)
- {
- List<allItems> allStats = getAllStats(userId);
- List<Months> stats = new List<Months>();
- var asItems =
- from item in allStats
- group item by new { month = item.MonthNumber } into Month
- select new Months()
- {
- MonthNumber = Month.Key.month,
- Weeks = Month.Select(week =>
- from item in allStats
- group item by new { week = item.WeekNumber } into Week
- select new Weeks()
- {
- WeekNumber = Week.Key.week,
- Days = Month.Select(days =>
- new Days()
- {
- PunchedInLate = days.PunchedInLate,
- PunchedOutLate = days.PunchedOutLate,
- DayOfWeek = days.DayOfWeek,
- PunchInDate = days.PunchInDate,
- PunchOutDate = days.PunchOutDate
- }).ToList()
- })
- };
- List<Months> stat = asItems.ToList();
- return stat;
- }
- public List<allItems> getAllStats(string userId)
- {
- List<allItems> stats = new List<allItems>();
- CultureInfo CultInfo = CultureInfo.CurrentCulture;
- bool addToList = false;
- allItems item = new allItems();
- for (int i = 0; i < 10; i++)
- {
- DateTime dt = DateTime.Now.AddDays(i+3);
- string punchInTime = "Kommet for sent";
- string punchOutTime = "Gået før flex tid";
- item.PunchInDate = dt;
- item.PunchOutDate = dt;
- item.DayOfWeek = dt.DayOfWeek;
- item.MonthNumber = dt.Month;
- if (punchInTime == "Kommet for sent")
- {
- item.PunchedInLate = true;
- addToList = true;
- }
- if (punchOutTime == "Gået før flex-tid")
- {
- item.PunchedOutLate = true;
- addToList = true;
- }
- item.WeekNumber = CultInfo.Calendar.GetWeekOfYear(dt, CultInfo.DateTimeFormat.CalendarWeekRule, CultInfo.DateTimeFormat.FirstDayOfWeek);
- if (addToList)
- {
- stats.Add(item);
- }
- }
- return stats;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement