Computing time and attendance system of working hours

Absolutely original, more judgment conditions, taking into account the lunch break, likes please take away. . .

        ///  <Summary> 
        /// computing an effective working hours today
         ///  </ Summary> 
        public  static a Decimal GetWorkHour (CheckOnModel todayCheckOn)
        {
            // calculate the effective number of hours worked today
             // normal circumstances from work early in the morning and work late 18:00 to 9:00 

            DateTime amTime = Convert.ToDateTime (DateTime.Now.ToString ( " yyyy-MM-dd " ) + " 09 : 01 " );
            DateTime pmTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 18:00");

            DateTime noonBreakStartTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 12:30");
            DateTime noonBreakEndTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 13:30");


            CheckOnModel copyCheckOn = CheckOnModel.DeepCopy(todayCheckOn);

            // deduct one hour lunch break 
            BOOL subtractOneHour = to true ;
             // earlier than 9:05 minutes working time punch work starting from 9:00 
            IF (todayCheckOn.OnDutyTime.Value <= amTime)
            {
                copyCheckOnOnDutyTime = amTimeAddMinutes (- 1 );
            }
            // lunch break from the work at the end of the lunch break start counting 
            IF (todayCheckOn.OnDutyTime.Value> = noonBreakStartTime && todayCheckOn.OnDutyTime.Value <= noonBreakEndTime)
            {
                copyCheckOnOnDutyTime = noonBreakEndTime;
                subtractOneHour = to false ; // no deduction lunchtime 
            }

            // from start to work after the lunch break 
            IF (todayCheckOn.OnDutyTime.Value> = noonBreakEndTime)
            {
                subtractOneHour = to false ; // no deduction lunchtime 
            }

            // punch out starting time from 18:00 
            IF (todayCheckOn.OffDutyTime.Value> = pmTime)
            {
                copyCheckOnOffDutyTime = pmTime;
            }
            // commuting time between lunch break 
            IF (copyCheckOn.OffDutyTime.Value> = noonBreakStartTime && copyCheckOn.OffDutyTime.Value < noonBreakEndTime)
            {
                copyCheckOnOffDutyTime = noonBreakStartTime;
                subtractOneHour = to false ; // no deduction lunch break 
            }
             // commute time is before lunch time 
            IF (copyCheckOn.OffDutyTime.Value < noonBreakStartTime)
            {
                subtractOneHour = to false ; // no deduction lunchtime 
            }

            if (subtractOneHour)
            {
                copyCheckOn.WorkHour = Convert.ToDecimal((copyCheckOn.OffDutyTime.Value - copyCheckOn.OnDutyTime.Value).TotalHours - 1);
            }
            else
            {
                copyCheckOn.WorkHour = Convert.ToDecimal((copyCheckOn.OffDutyTime.Value - copyCheckOn.OnDutyTime.Value).TotalHours);
            }
            // lunch time leave the punch may be negative 
            IF (copyCheckOn.WorkHour < 0 )
            {
                copyCheckOn.WorkHour = 0;
            }

            // retroactive successful as a normal punch but minus the number of hours deducted 
            IF (copyCheckOn.Status == " the Y- " && copyCheckOn.EditMan! = New new Guid ())
            {
                copyCheckOnWorkHour = 8 - copyCheckOnSubtractHour;
            }

            return copyCheckOn.WorkHour;
        }

 

Reproduced in: https: //www.cnblogs.com/ushou/p/3687106.html

Guess you like

Origin blog.csdn.net/weixin_34240520/article/details/93162613