Beispiel #1
0
 /// <summary>
 /// Return the summed actual hours from the phase code entry stored in the external data cache.
 /// PhaseCode parameter must be formatted to be compatible with SPECTRUM.
 /// </summary>
 /// <param name="spectrumFormattedPhaseCode"></param>
 /// <returns></returns>
 public double GetActualHoursByPhaseCode(string spectrumFormattedPhaseCode)
 {
     try
     {
         HoursEntry entry = actualHours.Where(h => h.PhaseCode == spectrumFormattedPhaseCode).FirstOrDefault();
         if (entry != null)
         {
             return(entry.SummedHours);
         }
         else
         {
             return(0);
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.Message);
         return(0);
     }
 }
    public void ShowMonth(int year, int month)
    {
        foreach (Day d in daysShown)
        {
            Destroy(d.gameObject);
        }
        daysShown.Clear();

        currentYear  = year;
        currentMonth = month;
        int      lastMonthsYear  = month > 1 ? year : year - 1;
        int      lastMonth       = month > 1 ? month - 1 : 12;
        int      nextMonthsYear  = month < 12 ? year : year + 1;
        int      nextMonth       = month < 12 ? month + 1 : 1;
        DateTime firstDay        = new DateTime(year, month, 1);
        int      daysInMonth     = DateTime.DaysInMonth(year, month);
        DateTime lastDay         = new DateTime(year, month, daysInMonth);
        int      daysInLastMonth = DateTime.DaysInMonth(lastMonthsYear, lastMonth);
        int      daysInNextMonth = DateTime.DaysInMonth(nextMonthsYear, nextMonth);

        DayOfWeek dayOfWeek = firstDay.DayOfWeek;

        // instantiate the days before 1st
        for (int date = daysInLastMonth - ((int)dayOfWeek - 1); date < daysInLastMonth + 1; ++date)
        {
            Day day = Instantiate(dayPrefab, transform).GetComponent <Day>();
            day.dateText.text = date.ToString();

            HoursEntry he = hours.FirstOrDefault(
                h => h.date.Year == (lastMonthsYear) &&
                h.date.Month == (lastMonth) &&
                h.date.Day == date);
            if (he != null)
            {
                day.hours          = he;
                day.hoursText.text = (he.time_out - he.time_in).TotalHours.ToString("0.## hrs");
            }
            else
            {
                day.date           = new DateTime(lastMonthsYear, lastMonth, date);
                day.hoursText.text = "";
            }

            day.gameObject.SetActive(true);
            if (datesWithLeaves.ContainsKey(day.date))
            {
                day.SetLeaveStatus(datesWithLeaves[day.date]);
            }
            else
            {
                day.MakeTransparent(true);
            }
            daysShown.Add(day);
        }

        // instantiate the month itself
        for (int date = 1; date < daysInMonth + 1; ++date)
        {
            Day day = Instantiate(dayPrefab, transform).GetComponent <Day>();
            day.dateText.text = date.ToString();

            HoursEntry he = hours.FirstOrDefault(
                h => h.date.Year == year &&
                h.date.Month == month &&
                h.date.Day == date);
            if (he != null)
            {
                day.hours          = he;
                day.hoursText.text = (he.time_out - he.time_in).TotalHours.ToString("0.## hrs");
            }
            else
            {
                day.date           = new DateTime(year, month, date);
                day.hoursText.text = "";
            }

            day.gameObject.SetActive(true);
            if (datesWithLeaves.ContainsKey(day.date))
            {
                day.SetLeaveStatus(datesWithLeaves[day.date]);
            }
            else
            {
                day.MakeTransparent(false);
            }
            daysShown.Add(day);
        }

        // instantiate a few days of next month to fill up calendar
        if (lastDay.DayOfWeek != DayOfWeek.Saturday)         // last day of month is not saturday
        {
            for (int date = 1; date < 7 - (int)lastDay.DayOfWeek; ++date)
            {
                Day day = Instantiate(dayPrefab, transform).GetComponent <Day>();
                day.dateText.text = date.ToString();

                HoursEntry he = hours.FirstOrDefault(
                    h => h.date.Year == (nextMonthsYear) &&
                    h.date.Month == (nextMonth) &&
                    h.date.Day == date);
                if (he != null)
                {
                    day.hours          = he;
                    day.hoursText.text = (he.time_out - he.time_in).TotalHours.ToString("0.## hrs");
                }
                else
                {
                    day.date           = new DateTime(nextMonthsYear, nextMonth, date);
                    day.hoursText.text = "";
                }

                day.gameObject.SetActive(true);
                if (datesWithLeaves.ContainsKey(day.date))
                {
                    day.SetLeaveStatus(datesWithLeaves[day.date]);
                }
                else
                {
                    day.MakeTransparent(true);
                }
                daysShown.Add(day);
            }
        }
    }