Guest User

Untitled

a guest
Mar 11th, 2013
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.25 KB | None | 0 0
  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();
  20.     public class allItems
  21.     {
  22.         public DateTime PunchInDate { get; set; }
  23.         public DateTime PunchOutDate { get; set; }
  24.         public DayOfWeek DayOfWeek { get; set; }
  25.         public int WeekNumber { get; set; }
  26.         public int MonthNumber { get; set; }
  27.         public bool PunchedInLate { get; set; }
  28.         public bool PunchedOutLate { get; set; }
  29.     }
  30.     public class Months
  31.     {
  32.         public int MonthNumber { get; set; }
  33.         public List<Weeks> Weeks { get; set; }
  34.     }
  35.     public class Weeks
  36.     {
  37.         public int WeekNumber { get; set; }
  38.         public List<Days> Days { get; set; }
  39.     }
  40.     public class Days
  41.     {
  42.         public bool PunchedInLate { get; set; }
  43.         public bool PunchedOutLate { get; set; }
  44.         public DateTime PunchInDate { get; set; }
  45.         public DateTime PunchOutDate { get; set; }
  46.         public DayOfWeek DayOfWeek { get; set; }
  47.     }
  48.     protected int GetAmountOfMonths(List<allItems> list, int numberToFind)
  49.     {
  50.         List<allItems> results = list.FindAll(
  51.             delegate(allItems ai)
  52.             {
  53.                 return ai.MonthNumber == numberToFind;
  54.             }
  55.             );
  56.         return results.Count;
  57.     }
  58.     protected int GetNumberOfWeeks(List<allItems> list, int numberToFind)
  59.     {
  60.         List<allItems> results = list.FindAll(
  61.             delegate(allItems ai)
  62.             {
  63.                 return ai.WeekNumber == numberToFind;
  64.             }
  65.             );
  66.         return results.Count;
  67.     }
  68.     public List<Months> getStats(string userId)
  69.     {
  70.         List<allItems> allStats = getAllStats(userId);
  71.         List<Months> stats = new List<Months>();
  72.         var asItems =
  73.         from item in allStats
  74.         group item by new { month = item.MonthNumber } into Month
  75.         select new Months()
  76.         {
  77.             MonthNumber = Month.Key.month,
  78.             Weeks = Month.Select(week =>
  79.                 from item in allStats
  80.                 group item by new { week = item.WeekNumber } into Week
  81.                 select new Weeks()
  82.                 {
  83.                     WeekNumber = Week.Key.week,
  84.                     Days = Month.Select(days =>
  85.                         new Days()
  86.                         {
  87.                             PunchedInLate = days.PunchedInLate,
  88.                             PunchedOutLate = days.PunchedOutLate,
  89.                             DayOfWeek = days.DayOfWeek,
  90.                             PunchInDate = days.PunchInDate,
  91.                             PunchOutDate = days.PunchOutDate
  92.                         }).ToList()
  93.                 })
  94.         };
  95.         List<Months> stat = asItems.ToList();
  96.         return stat;
  97.     }
  98.     public List<allItems> getAllStats(string userId)
  99.     {
  100.         List<allItems> stats = new List<allItems>();
  101.  
  102.         CultureInfo CultInfo = CultureInfo.CurrentCulture;
  103.  
  104.         bool addToList = false;
  105.         allItems item = new allItems();
  106.         for (int i = 0; i < 10; i++)
  107.         {
  108.             DateTime dt = DateTime.Now.AddDays(i+3);
  109.             string punchInTime = "Kommet for sent";
  110.             string punchOutTime = "Gået før flex tid";
  111.             item.PunchInDate = dt;
  112.             item.PunchOutDate = dt;
  113.             item.DayOfWeek = dt.DayOfWeek;
  114.             item.MonthNumber = dt.Month;
  115.             if (punchInTime == "Kommet for sent")
  116.             {
  117.                 item.PunchedInLate = true;
  118.                 addToList = true;
  119.             }
  120.             if (punchOutTime == "Gået før flex-tid")
  121.             {
  122.                 item.PunchedOutLate = true;
  123.                 addToList = true;
  124.             }
  125.  
  126.             item.WeekNumber = CultInfo.Calendar.GetWeekOfYear(dt, CultInfo.DateTimeFormat.CalendarWeekRule, CultInfo.DateTimeFormat.FirstDayOfWeek);
  127.  
  128.             if (addToList)
  129.             {
  130.                 stats.Add(item);
  131.             }
  132.         }
  133.  
  134.         return stats;
  135.     }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment