Example #1
0
        ///<summary>fromDB is set to false when it is refreshing every second so that there will be no extra network traffic.</summary>
        private void FillMain(bool fromDB)
        {
            if (fromDB)
            {
                ClockEventList = ClockEvents.Refresh(EmployeeCur.EmployeeNum, PIn.PDate(textDateStart.Text),
                                                     PIn.PDate(textDateStop.Text), false, IsBreaks);
                if (IsBreaks)
                {
                    TimeAdjustList = new TimeAdjust[0];
                }
                else
                {
                    TimeAdjustList = TimeAdjusts.Refresh(EmployeeCur.EmployeeNum, PIn.PDate(textDateStart.Text),
                                                         PIn.PDate(textDateStop.Text));
                }
            }
            mergedAL = new ArrayList();
            for (int i = 0; i < ClockEventList.Length; i++)
            {
                mergedAL.Add(ClockEventList[i]);
            }
            for (int i = 0; i < TimeAdjustList.Length; i++)
            {
                mergedAL.Add(TimeAdjustList[i]);
            }
            IComparer myComparer = new ObjectDateComparer();

            mergedAL.Sort(myComparer);
            gridMain.BeginUpdate();
            gridMain.Columns.Clear();
            ODGridColumn col = new ODGridColumn(Lan.g(this, "Date"), 70);

            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g(this, "Weekday"), 70);
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g(this, "Altered"), 50, HorizontalAlignment.Right);
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g(this, "Status"), 50);
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g(this, "In/Out"), 60, HorizontalAlignment.Right);
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g(this, "Time"), 60, HorizontalAlignment.Right);
            gridMain.Columns.Add(col);
            if (IsBreaks)
            {
                col = new ODGridColumn(Lan.g(this, "Minutes"), 50, HorizontalAlignment.Right);
            }
            else
            {
                col = new ODGridColumn(Lan.g(this, "Hours"), 50, HorizontalAlignment.Right);
            }
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g(this, "Overtime"), 55, HorizontalAlignment.Right);
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g(this, "Daily"), 50, HorizontalAlignment.Right);
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g(this, "Weekly"), 50, HorizontalAlignment.Right);
            gridMain.Columns.Add(col);
            col = new ODGridColumn(Lan.g(this, "Note"), 5);
            gridMain.Columns.Add(col);
            gridMain.Rows.Clear();
            ODGridRow row;

            //TimeSpan weeklyTotalPrevious=
            WeeklyTotals = new TimeSpan[mergedAL.Count];
            TimeSpan   alteredSpan = new TimeSpan(0); //used to display altered times
            TimeSpan   pairSpan    = new TimeSpan(0); //used to sum one pair of clockevents
            ClockEvent pairFirst   = null;            //the first of a pair of clockevents
            TimeSpan   daySpan     = new TimeSpan(0); //used for daily totals.
            TimeSpan   weekSpan    = new TimeSpan(0); //used for weekly totals.

            if (mergedAL.Count > 0)
            {
                weekSpan = ClockEvents.GetWeekTotal(EmployeeCur.EmployeeNum, GetDateForRow(0));
            }
            //MessageBox.Show(weekSpan.TotalHours.ToString());
            TimeSpan         periodSpan   = new TimeSpan(0); //used to add up totals for entire page.
            TimeSpan         otspan       = new TimeSpan(0); //overtime for the entire period
            Calendar         cal          = CultureInfo.CurrentCulture.Calendar;
            CalendarWeekRule rule         = CultureInfo.CurrentCulture.DateTimeFormat.CalendarWeekRule;
            DateTime         curDate      = DateTime.MinValue;
            DateTime         previousDate = DateTime.MinValue;
            Type             type;
            ClockEvent       clock;
            TimeAdjust       adjust;

            for (int i = 0; i < mergedAL.Count; i++)
            {
                row          = new ODGridRow();
                type         = mergedAL[i].GetType();
                row.Tag      = mergedAL[i];
                previousDate = curDate;
                //clock event row---------------------------------------------------------------------------------------------
                if (type == typeof(ClockEvent))
                {
                    clock   = (ClockEvent)mergedAL[i];
                    curDate = clock.TimeDisplayed.Date;
                    if (curDate == previousDate)
                    {
                        row.Cells.Add("");
                        row.Cells.Add("");
                    }
                    else
                    {
                        row.Cells.Add(curDate.ToShortDateString());
                        row.Cells.Add(curDate.DayOfWeek.ToString());
                    }
                    //altered--------------------------------------
                    if (clock.TimeEntered != clock.TimeDisplayed)
                    {
                        alteredSpan = clock.TimeDisplayed - clock.TimeEntered;
                        if (IsBreaks)
                        {
                            row.Cells.Add(alteredSpan.TotalMinutes.ToString("n"));
                        }
                        else
                        {
                            row.Cells.Add(alteredSpan.TotalHours.ToString("n"));
                        }
                    }
                    else
                    {
                        row.Cells.Add("");
                    }
                    //status--------------------------------------
                    row.Cells.Add(clock.ClockStatus.ToString());
                    //in/out------------------------------------------
                    if (clock.ClockIn)
                    {
                        row.Cells.Add(Lan.g(this, "In"));
                    }
                    else
                    {
                        row.Cells.Add(Lan.g(this, "Out"));
                    }
                    //time-----------------------------
                    row.Cells.Add(clock.TimeDisplayed.ToShortTimeString());
                    //minutes or hours-------------------------------
                    if (IsBreaks)                     //breaks
                    {
                        if (!clock.ClockIn)           //clocking out
                        {
                            pairFirst = clock.Copy();
                            row.Cells.Add("");
                        }
                        else                         //clocking in
                        {
                            if (pairFirst == null)
                            {
                                row.Cells.Add("");
                            }
                            else
                            {
                                pairSpan = clock.TimeDisplayed - pairFirst.TimeDisplayed;
                                row.Cells.Add(pairSpan.TotalMinutes.ToString("n"));
                                daySpan += pairSpan;
                                //weekSpan+=pairSpan;
                                periodSpan += pairSpan;
                            }
                        }
                    }
                    else                     //regular hours
                    {
                        if (clock.ClockIn)   //clocking in
                        {
                            pairFirst = clock.Copy();
                            row.Cells.Add("");
                        }
                        else                         //clocking out
                        {
                            if (pairFirst == null)
                            {
                                row.Cells.Add("");
                            }
                            else
                            {
                                pairSpan = clock.TimeDisplayed - pairFirst.TimeDisplayed;
                                row.Cells.Add(pairSpan.TotalHours.ToString("n"));
                                daySpan    += pairSpan;
                                weekSpan   += pairSpan;
                                periodSpan += pairSpan;
                            }
                        }
                    }
                    //Overtime------------------------------
                    row.Cells.Add("");
                    //Daily-----------------------------------
                    //if this is the last entry for a given date
                    if (i == mergedAL.Count - 1 ||            //if this is the last row
                        GetDateForRow(i + 1) != curDate)                         //or the next row is a different date
                    {
                        if (IsBreaks)
                        {
                            if (!clock.ClockIn)                            //if they have not clocked back in yet from break
                            //display the timespan of pairSpan using current time as the other number.
                            {
                                pairSpan = DateTime.Now - clock.TimeDisplayed + TimeDelta;
                                row.Cells.Add(pairSpan.TotalMinutes.ToString("n"));
                                daySpan += pairSpan;
                            }
                            else
                            {
                                row.Cells.Add(daySpan.TotalMinutes.ToString("n"));
                            }
                        }
                        else
                        {
                            row.Cells.Add(daySpan.TotalHours.ToString("n"));
                        }
                        daySpan = new TimeSpan(0);
                    }
                    else                     //not the last entry for the day
                    {
                        row.Cells.Add("");
                    }
                    //Weekly-------------------------------------
                    WeeklyTotals[i] = weekSpan;
                    if (IsBreaks)
                    {
                        row.Cells.Add("");
                    }
                    //if this is the last entry for a given week
                    else if (i == mergedAL.Count - 1 ||            //if this is the last row
                             cal.GetWeekOfYear(GetDateForRow(i + 1), rule, DayOfWeek.Sunday)                  //or the next row has a
                             != cal.GetWeekOfYear(clock.TimeDisplayed.Date, rule, DayOfWeek.Sunday))          //different week of year
                    {
                        row.Cells.Add(weekSpan.TotalHours.ToString("n"));
                        weekSpan = new TimeSpan(0);
                    }
                    else
                    {
                        row.Cells.Add("");
                    }
                    //Note-----------------------------------------
                    row.Cells.Add(clock.Note);
                }
                //adjustment row--------------------------------------------------------------------------------------
                else if (type == typeof(TimeAdjust))
                {
                    adjust  = (TimeAdjust)mergedAL[i];
                    curDate = adjust.TimeEntry.Date;
                    if (curDate == previousDate)
                    {
                        row.Cells.Add("");
                        row.Cells.Add("");
                    }
                    else
                    {
                        row.Cells.Add(curDate.ToShortDateString());
                        row.Cells.Add(curDate.DayOfWeek.ToString());
                    }
                    //altered--------------------------------------
                    row.Cells.Add("");                    //2
                    //status--------------------------------------
                    row.Cells.Add(Lan.g(this, "Adjust")); //3
                    row.ColorText = Color.Red;
                    //in/out------------------------------------------
                    row.Cells.Add("");                                   //4
                    //time-----------------------------
                    row.Cells.Add(adjust.TimeEntry.ToShortTimeString()); //5
                    //minutes or hours-------------------------------
                    if (adjust.RegHours.TotalHours == 0)
                    {
                        row.Cells.Add("");                        //6
                    }
                    else
                    {
                        daySpan    += adjust.RegHours;                   //might be negative
                        weekSpan   += adjust.RegHours;
                        periodSpan += adjust.RegHours;
                        row.Cells.Add(adjust.RegHours.TotalHours.ToString("n"));                        //6
                    }
                    //Overtime------------------------------
                    if (adjust.OTimeHours.TotalHours != 0)
                    {
                        otspan += adjust.OTimeHours;
                        row.Cells.Add(adjust.OTimeHours.TotalHours.ToString("n"));                        //7
                    }
                    else
                    {
                        row.Cells.Add("");                        //7
                    }
                    //Daily-----------------------------------
                    //if this is the last entry for a given date
                    if (i == mergedAL.Count - 1 ||            //if this is the last row
                        GetDateForRow(i + 1) != curDate)                         //or the next row is a different date
                    {
                        row.Cells.Add(daySpan.TotalHours.ToString("n"));         //8
                        daySpan = new TimeSpan(0);
                    }
                    else
                    {
                        row.Cells.Add("");
                    }
                    //Weekly-------------------------------------
                    WeeklyTotals[i] = weekSpan;
                    if (IsBreaks)
                    {
                        row.Cells.Add("");
                    }
                    //if this is the last entry for a given week
                    else if (i == mergedAL.Count - 1 ||            //if this is the last row
                             cal.GetWeekOfYear(GetDateForRow(i + 1), rule, DayOfWeek.Sunday)                  //or the next row has a
                             != cal.GetWeekOfYear(adjust.TimeEntry.Date, rule, DayOfWeek.Sunday))             //different week of year
                    {
                        ODGridCell cell = new ODGridCell(weekSpan.TotalHours.ToString("n"));
                        cell.ColorText = Color.Black;
                        row.Cells.Add(cell);
                        weekSpan = new TimeSpan(0);
                    }
                    else
                    {
                        row.Cells.Add("");
                    }
                    //Note-----------------------------------------
                    row.Cells.Add(adjust.Note);
                }
                gridMain.Rows.Add(row);
            }
            gridMain.EndUpdate();
            if (IsBreaks)
            {
                textTotal.Text = "";
            }
            else
            {
                textTotal.Text    = periodSpan.TotalHours.ToString("n");
                textOvertime.Text = otspan.TotalHours.ToString("n");
            }
        }