Example #1
0
        ///<summary>When the date is changed on the calendar control we initialize and start our animation for the daily metrics and calculate the user's clock events for the given week selected.
        ///This method also grabs the user's schedule and populates the calendar grid.</summary>
        private void OnCalendarDateChanged()
        {
            labelArrived.Foreground = Brushes.Gray;
            DailyMetrics.Visibility = Visibility.Visible;
            DateTime selectedDate = (DateTime)dailyCalendar.SelectedDate;
            //starts animation and sets the values of the fields being animated
            DoubleAnimation da = new DoubleAnimation(0, AnimationRow.ActualHeight, TimeSpan.FromMilliseconds(200));

            DailyMetrics.BeginAnimation(Grid.HeightProperty, da);
            DataTable dt        = ClockEvents.GetTimeClockedInOnDate(selectedEng.EmployeeNum, selectedDate);
            string    arrivedAt = "";
            string    leftAt    = "";

            if (dt.Rows.Count != 0)
            {
                arrivedAt = string.Format("{0:hh:mm:ss tt}", dt.Rows[0][0]);
                leftAt    = string.Format("{0:hh:mm:ss tt}", dt.Rows[0][1]);
            }
            //reflect the change in selected date in our date range
            DateTime weekStart = selectedDate.AddDays(-(int)selectedDate.DayOfWeek);
            DateTime weekEnd   = selectedDate.AddDays(7 - ((int)selectedDate.DayOfWeek));
            string   dateRange = weekStart.ToShortDateString() + "-" + weekEnd.ToShortDateString();

            ClockEventsInRange(weekStart, weekEnd);
            FillEngineerCalendar(weekStart, weekEnd);
            DateForSched.Content = dateRange;
            ClearDailyLabels();
            //TODO: Fix the clock in but not clocked out bug
            labelArrived.Content = arrivedAt;
            labelLeftAt.Content  = leftAt;
            if (dt.Rows.Count == 0)
            {
                labelArrived.Content     = "--";
                labelLeftAt.Content      = "--";
                labelHoursWorked.Content = "--";
                return;
            }
            TimeSpan timeWorked = (DateTime)dt.Rows[0][1] - (DateTime)dt.Rows[0][0];

            labelHoursWorked.Content = timeWorked.ToString();
            //check to see if the clock in time is past 10 minutes and mark red to indicate tardiness
            List <Schedule> timeScheduled = Schedules.GetSchedListForDateRange(selectedEng.EmployeeNum, (DateTime)dailyCalendar.SelectedDate, (DateTime)dailyCalendar.SelectedDate);

            if (timeScheduled.Count == 0)           //If the employee is not scheduled they can't be tardy.
            {
                return;
            }
            //Find the difference between clock in and the employee's scheduled start time
            TimeSpan duration = TimeSpan.Parse(((DateTime)dt.Rows[0][0]).ToString("HH:mm")).Subtract(timeScheduled[0].StartTime);

            if (duration.Minutes > 10)
            {
                labelArrived.Foreground = Brushes.Red;
            }
        }
        ///<summary>When the date is changed on the calendar control we initialize and start our animation for the daily metrics and calculate the user's clock events for the given week selected.
        ///This method also grabs the user's schedule and populates the calendar grid.</summary>
        private void OnCalendarDateChanged()
        {
            labelArrived.Foreground = Brushes.Gray;
            DailyMetrics.Visibility = Visibility.Visible;
            DateTime selectedDate = (DateTime)dailyCalendar.SelectedDate;
            //starts animation and sets the values of the fields being animated
            DoubleAnimation da = new DoubleAnimation(0, AnimationRow.ActualHeight, TimeSpan.FromMilliseconds(200));

            DailyMetrics.BeginAnimation(Grid.HeightProperty, da);
            DataTable dt = ClockEvents.GetTimeClockedInOnDate(selectedEng.EmployeeNum, selectedDate);
            //reflect the change in selected date in our date range
            string weekStart = selectedDate.AddDays(-(int)selectedDate.DayOfWeek).ToShortDateString();
            string weekEnd   = selectedDate.AddDays(7 - ((int)selectedDate.DayOfWeek)).ToShortDateString();
            string dateRange = weekStart + "-" + weekEnd;

            ClockEventsInRange(weekStart, weekEnd);
            FillEngineerCalendar(weekStart, weekEnd);
            DateForSched.Content = dateRange;
            ClearDailyLabels();
            if (dt.Rows.Count == 0)
            {
                labelArrived.Content     = "--";
                labelLeftAt.Content      = "--";
                labelHoursWorked.Content = "--";
                return;
            }
            labelArrived.Content     = dt.Rows[0][0].ToString();
            labelLeftAt.Content      = dt.Rows[0][1].ToString();
            labelHoursWorked.Content = dt.Rows[0][2].ToString();
            //check to see if the clock in time is past 10 minutes and mark red to indicate tardiness
            string[] clockedInAt = dt.Rows[0][0].ToString().Split(null);          //This split removes the 'AM' string at the end of the clock in time
            if (clockedInAt[0] == null)
            {
                return;
            }
            List <Schedule> timeScheduled = Schedules.GetSchedListForDateRange(selectedEng.EmployeeNum, dailyCalendar.SelectedDate.ToString(), dailyCalendar.SelectedDate.ToString());

            if (timeScheduled.Count == 0)           //If the employee is not scheduled they can't be tardy.
            {
                return;
            }
            TimeSpan duration = TimeSpan.Parse(clockedInAt[0]).Subtract(TimeSpan.Parse(timeScheduled.First().StartTime.ToString()));

            if (duration.Minutes > 10)
            {
                labelArrived.Foreground = Brushes.Red;
            }
        }