示例#1
0
        ///<summary>Makes sure that the pay periods that the user has selected are safe to delete.
        ///A pay period cannot be deleted in bulk if:
        ///a) It is in the past OR
        ///b) There are clockevents tied to it and there are no other pay periods for the date of the clockevent.</summary>
        private bool IsSafeToDelete(List <PayPeriod> listSelectedPayPeriods, out List <PayPeriod> retListToDelete)
        {
            if (listSelectedPayPeriods.Where(x => x.DateStop < DateTimeOD.Today).Count() > 0)
            {
                MsgBox.Show(this, "You may not delete past pay periods from here. Delete them individually by double clicking them instead.");
                retListToDelete = new List <PayPeriod>();
                return(false);
            }
            List <PayPeriod>  listPayPeriodsToDelete = new List <PayPeriod>();
            List <ClockEvent> listClockEventsAll     = ClockEvents.GetAllForPeriod(listSelectedPayPeriods.Min(x => x.DateStart), listSelectedPayPeriods.Max(x => x.DateStop));

            foreach (PayPeriod payPeriod in listSelectedPayPeriods)
            {
                List <ClockEvent> listClockEventsForPeriod = listClockEventsAll.Where(x => x.TimeDisplayed1 >= payPeriod.DateStart && x.TimeDisplayed2 <= payPeriod.DateStop).ToList();
                if (listClockEventsForPeriod.Count == 0)
                {
                    //there are no clock events for this period.
                    listPayPeriodsToDelete.Add(payPeriod);
                    continue;
                }
                //there ARE clock events for this period. now are there other periods that are *not* in the selected list?
                foreach (ClockEvent clockEvent in listClockEventsForPeriod)
                {
                    if (_listPayPeriods.Where(x => x.DateStart <= clockEvent.TimeDisplayed1 && x.DateStop >= clockEvent.TimeDisplayed1 && !listSelectedPayPeriods.Contains(x)).Count() < 1)
                    {
                        //if no, then kick out.
                        MsgBox.Show(this, "You may not delete all pay periods where a clock event exists.");
                        retListToDelete = new List <PayPeriod>();
                        return(false);
                    }
                    //otherwise, the add this pay period to the list to delete and continue
                    listPayPeriodsToDelete.Add(payPeriod);
                }
            }
            retListToDelete = listPayPeriodsToDelete;
            return(true);
        }
示例#2
0
        private void FillGridMain()
        {
            gridMain.BeginUpdate();
            gridMain.ListGridColumns.Clear();
            gridMain.ListGridColumns.Add(new GridColumn(Lan.g(this, "LName"), 100));
            gridMain.ListGridColumns.Add(new GridColumn(Lan.g(this, "FName"), 100));
            gridMain.ListGridColumns.Add(new GridColumn(_monthT2.ToString("MMMM yyyy"), 100, HorizontalAlignment.Right, GridSortingStrategy.AmountParse));
            gridMain.ListGridColumns.Add(new GridColumn(_monthT1.ToString("MMMM yyyy"), 100, HorizontalAlignment.Right, GridSortingStrategy.AmountParse));
            if (!checkIgnore.Checked)
            {
                gridMain.ListGridColumns.Add(new GridColumn(_monthT0.ToString("MMMM yyyy"), 100, HorizontalAlignment.Right, GridSortingStrategy.AmountParse));
            }
            gridMain.ListGridColumns.Add(new GridColumn(Lan.g(this, "Letter"), 100));
            gridMain.ListGridRows.Clear();
            List <Employee>   listEmpsAll        = Employees.GetDeepCopy(true).OrderBy(x => x.LName).ThenBy(x => x.FName).ToList();
            List <ClockEvent> listClockEventsAll = ClockEvents.GetAllForPeriod(_monthT2, _monthT2.AddMonths(3)); //get all three months of clock events

            listClockEventsAll.RemoveAll(x => x.ClockStatus == TimeClockStatus.Break);                           //remove breaks, they have already been acounted for on the clock events.
            listClockEventsAll.RemoveAll(x => x.TimeDisplayed2 <= x.TimeDisplayed1);                             //Remove all mal-formed entries with stop time before start time. (also if user has not clocked out.)
            listClockEventsAll.RemoveAll(x => x.TimeDisplayed1.Date != x.TimeDisplayed2.Date);                   //No one works over midnight at ODHQ. If they do, they know to split clock events @ midnight
            List <TimeAdjust> listTimeAdjustAll = TimeAdjusts.GetAllForPeriod(_monthT2, _monthT2.AddMonths(3));

            foreach (Employee empCur in listEmpsAll)
            {
                //Construct each row, then filter out if neccesary.
                GridRow row = new GridRow();
                //Name
                row.Cells.Add(empCur.LName);
                row.Cells.Add(empCur.FName);
                //Month T-2 (current month -2 months)
                TimeSpan ts2 = TimeSpan.FromTicks(listClockEventsAll
                                                  .FindAll(x => x.EmployeeNum == empCur.EmployeeNum &&
                                                           x.TimeDisplayed1.Year == _monthT2.Year &&
                                                           x.TimeDisplayed1.Month == _monthT2.Month)
                                                  .Select(x => (x.TimeDisplayed2 - x.TimeDisplayed1) + (x.AdjustIsOverridden ? x.Adjust : x.AdjustAuto))
                                                  .Sum(x => x.Ticks));
                ts2.Add(TimeSpan.FromTicks(listTimeAdjustAll.FindAll(x => x.EmployeeNum == empCur.EmployeeNum &&
                                                                     x.TimeEntry.Year == _monthT2.Year &&
                                                                     x.TimeEntry.Month == _monthT2.Month)
                                           .Sum(x => x.RegHours.Ticks)));
                row.Cells.Add(new GridCell(string.Format("{0:0.00}", Math.Round(ts2.TotalHours, 2, MidpointRounding.AwayFromZero)))
                {
                    ColorBackG = (ts2.TotalHours < 125 ? lightRed : Color.Empty)
                });
                //Month T-1
                TimeSpan ts1 = TimeSpan.FromTicks(listClockEventsAll
                                                  .FindAll(x => x.EmployeeNum == empCur.EmployeeNum &&
                                                           x.TimeDisplayed1.Year == _monthT1.Year &&
                                                           x.TimeDisplayed1.Month == _monthT1.Month)
                                                  .Select(x => (x.TimeDisplayed2 - x.TimeDisplayed1) + (x.AdjustIsOverridden ? x.Adjust : x.AdjustAuto))
                                                  .Sum(x => x.Ticks));
                ts1.Add(TimeSpan.FromTicks(listTimeAdjustAll.FindAll(x => x.EmployeeNum == empCur.EmployeeNum &&
                                                                     x.TimeEntry.Year == _monthT1.Year &&
                                                                     x.TimeEntry.Month == _monthT1.Month)
                                           .Select(x => x.RegHours)
                                           .Sum(x => x.Ticks)));
                row.Cells.Add(new GridCell(string.Format("{0:0.00}", Math.Round(ts1.TotalHours, 2, MidpointRounding.AwayFromZero)))
                {
                    ColorBackG = (ts1.TotalHours < 125 ? lightRed : Color.Empty)
                });
                //Month T-0
                TimeSpan ts0 = TimeSpan.FromTicks(listClockEventsAll
                                                  .FindAll(x => x.EmployeeNum == empCur.EmployeeNum &&
                                                           x.TimeDisplayed1.Year == _monthT0.Year &&
                                                           x.TimeDisplayed1.Month == _monthT0.Month)
                                                  .Select(x => (x.TimeDisplayed2 - x.TimeDisplayed1) + (x.AdjustIsOverridden ? x.Adjust : x.AdjustAuto))
                                                  .Sum(x => x.Ticks));
                ts0.Add(TimeSpan.FromTicks(listTimeAdjustAll.FindAll(x => x.EmployeeNum == empCur.EmployeeNum &&
                                                                     x.TimeEntry.Year == _monthT0.Year &&
                                                                     x.TimeEntry.Month == _monthT0.Month)
                                           .Select(x => x.RegHours)
                                           .Sum(x => x.Ticks)));
                if (!checkIgnore.Checked)
                {
                    row.Cells.Add(new GridCell(string.Format("{0:0.00}", Math.Round(ts0.TotalHours, 2, MidpointRounding.AwayFromZero)))
                    {
                        ColorBackG = (ts0.TotalHours < 125 ? lightRed : Color.Empty)
                    });
                }
                //filter out rows that should not be displaying. Rows should not display only when the most recent month was less than 125 hours, regardless of status of previous months
                if (!checkShowAll.Checked)
                {
                    //Show all is not checked, therefore we must filter out rows with more than 125 hours on the most recent pay period.
                    if (!checkIgnore.Checked && ts0.TotalHours > 125)
                    {
                        //Not ignoring "current month" so check T0 for >125 hours
                        continue;
                    }
                    else if (checkIgnore.Checked && ts1.TotalHours > 125)
                    {
                        //Ignore current month (because it is probably only partially complete), check the previous months for >125 hours.
                        continue;
                    }
                }
                string letterNumber = "";
                if ((checkIgnore.Checked?ts2:ts0).TotalHours < 125 && ts1.TotalHours < 125)
                {
                    //the last two visible month were less than 125 hours. AKA "Send the Second letter"
                    letterNumber = "Second";
                }
                else if ((checkIgnore.Checked?ts1:ts0).TotalHours < 125)
                {
                    //the last visible month was less than 125 hours. AKA "Send the First letter"
                    letterNumber = "First";
                }
                row.Cells.Add(letterNumber);
                gridMain.ListGridRows.Add(row);
            }
            gridMain.EndUpdate();
        }