private void InitRule()
 {
     _MorningStart   = RequestUtility.ConvertToTime(_MorningStart);
     _MorningEnd     = RequestUtility.ConvertToTime(_MorningEnd);
     _AfternoonStart = RequestUtility.ConvertToTime(_AfternoonStart);
     _AfternoonEnd   = RequestUtility.ConvertToTime(_AfternoonEnd);
 }
Exemplo n.º 2
0
        private decimal CalculatePuTong()
        {
            DateTime fromtemp = RequestUtility.ConvertToTime(_From);
            DateTime totemp   = RequestUtility.ConvertToTime(_To);

            if (_To.Hour == 0 && _To.Minute == 0)
            {
                totemp = totemp.AddDays(1);
            }
            _MorningStart = RequestUtility.ConvertToTime(_MorningStart);
            _AfternoonEnd = RequestUtility.ConvertToTime(_AfternoonEnd);
            if (fromtemp <= _AfternoonEnd && fromtemp >= _MorningStart)
            {
                fromtemp = _AfternoonEnd;
            }
            if (totemp <= _AfternoonEnd && totemp >= _MorningStart)
            {
                totemp = _MorningStart;
            }
            TimeSpan ts  = totemp - fromtemp;
            TimeSpan tsw = _AfternoonEnd - _MorningStart;
            decimal  ans = Convert.ToDecimal(ts.TotalHours);

            if (fromtemp <= _MorningStart && totemp >= _AfternoonEnd)
            {
                ans -= Convert.ToDecimal(tsw.TotalHours);
            }
            return(ans > 0 ? ans : 0);
        }
Exemplo n.º 3
0
        private void InitDateTime(PlanDutyDetail detail)
        {
            DateTime lastenddate =
                detail.PlanDutyClass.FirstStartToTime.AddHours(
                    (detail.PlanDutyClass.SecondStartTime - detail.PlanDutyClass.FirstEndTime).
                    TotalHours + (double)_OneDayMaxHour);

            if (RequestUtility.ConvertToTime(_From) >=
                RequestUtility.ConvertToTime(detail.PlanDutyClass.FirstStartFromTime) &&
                RequestUtility.ConvertToTime(_From) <=
                RequestUtility.ConvertToTime(detail.PlanDutyClass.FirstStartToTime))
            {
                _MorningStart = RequestUtility.ConvertToTime(_From);
            }
            else
            {
                _MorningStart = RequestUtility.ConvertToTime(detail.PlanDutyClass.FirstStartFromTime);
            }
            if (RequestUtility.ConvertToTime(_To) >=
                RequestUtility.ConvertToTime(detail.PlanDutyClass.SecondEndTime) &&
                RequestUtility.ConvertToTime(_To) <=
                RequestUtility.ConvertToTime(lastenddate))
            {
                _AfternoonEnd = RequestUtility.ConvertToTime(_To);
            }
            else
            {
                _AfternoonEnd =
                    RequestUtility.ConvertToTime(lastenddate);
            }
            _MorningEnd     = detail.PlanDutyClass.FirstEndTime;
            _AfternoonStart = detail.PlanDutyClass.SecondStartTime;
        }
Exemplo n.º 4
0
        private static void InitDateTime(DateTime from, DateTime to, PlanDutyDetail detail,
                                         out DateTime dtMorningStart, out DateTime dtAfternoonEnd)
        {
            DateTime lastenddate =
                detail.PlanDutyClass.FirstStartToTime.AddHours(
                    (detail.PlanDutyClass.SecondStartTime - detail.PlanDutyClass.FirstEndTime).
                    TotalHours + (double)_OneDayMaxHour);

            if (RequestUtility.ConvertToTime(from) >=
                RequestUtility.ConvertToTime(detail.PlanDutyClass.FirstStartFromTime) &&
                RequestUtility.ConvertToTime(from) <=
                RequestUtility.ConvertToTime(detail.PlanDutyClass.FirstStartToTime))
            {
                dtMorningStart = RequestUtility.ConvertToTime(from);
            }
            else
            {
                dtMorningStart = RequestUtility.ConvertToTime(detail.PlanDutyClass.FirstStartFromTime);
            }
            if (RequestUtility.ConvertToTime(to) >=
                RequestUtility.ConvertToTime(detail.PlanDutyClass.SecondEndTime) &&
                RequestUtility.ConvertToTime(to) <=
                RequestUtility.ConvertToTime(lastenddate))
            {
                dtAfternoonEnd = RequestUtility.ConvertToTime(to);
            }
            else
            {
                dtAfternoonEnd =
                    RequestUtility.ConvertToTime(lastenddate);
            }
        }
Exemplo n.º 5
0
        private decimal CalculateOneDay(DateTime from, DateTime to)
        {
            InitRule();
            DateTime fromDate = from.Date;

            from = RequestUtility.ConvertToTime(from);
            to   = RequestUtility.ConvertToTime(to);
            DateTime fromtemp = from;
            DateTime totemp   = to;

            if (from <= _MorningStart)
            {
                fromtemp = _MorningStart;
            }
            else if (from >= _MorningEnd &&
                     from <= _AfternoonStart)
            {
                fromtemp = _AfternoonStart;
            }
            if (RequestUtility.ConvertToTime(to) >= _AfternoonEnd)
            {
                totemp = _AfternoonEnd;
            }
            else if (to >= _MorningEnd &&
                     to <= _AfternoonStart)
            {
                totemp = _MorningEnd;
            }
            TimeSpan ts          = totemp - fromtemp;
            decimal  costMinutes = ts.TotalMinutes < 0 ? 0m : Convert.ToDecimal(ts.TotalMinutes);

            if (fromtemp <= _MorningEnd &&
                fromtemp >= _MorningStart &&
                totemp <= _AfternoonEnd &&
                totemp >= _AfternoonStart)
            {
                costMinutes -= Convert.ToDecimal((_AfternoonStart - _MorningEnd).TotalMinutes);
            }
            decimal answer = ConvertToHour(costMinutes / 60);

            ////查询当天其它请假,总和不能超过8
            //var requestsInDaysCostTime = 0m;
            //foreach (var leaveRequest in _LeaveRequests)
            //{
            //   var item= leaveRequest.LeaveRequestItems.Where(x => x.FromDate.Date == fromDate);
            //    if (item.Count() > 0)
            //    {
            //        requestsInDaysCostTime += item.Sum(x => x.CostTime);
            //    }
            //}
            answer = answer > _OneDayMaxHour ? _OneDayMaxHour : answer;
            return(answer);
            //var leftCostHour = _OneDayMaxHour - requestsInDaysCostTime;
            //return answer > leftCostHour ? (leftCostHour < 0 ? 0 : leftCostHour) : answer;
        }
Exemplo n.º 6
0
        private decimal CalculateShuangXiu()
        {
            TimeSpan ts  = _To - _From;
            double   ans = ts.TotalHours;

            if (RequestUtility.ConvertToTime(_To) >= RequestUtility.ConvertToTime(_AfternoonStart) &&
                RequestUtility.ConvertToTime(_From) <= RequestUtility.ConvertToTime(_MorningEnd))
            {
                ans -=
                    (RequestUtility.ConvertToTime(_AfternoonStart) - RequestUtility.ConvertToTime(_MorningEnd)).
                    TotalHours;
            }
            return(Convert.ToDecimal(ans));
        }
        private decimal CalculateOneDay(DateTime from, DateTime to)
        {
            InitRule();
            from = RequestUtility.ConvertToTime(from);
            to   = RequestUtility.ConvertToTime(to);
            DateTime fromtemp = from;
            DateTime totemp   = to;

            if (from <= _MorningStart)
            {
                fromtemp = _MorningStart;
            }
            else if (from >= _MorningEnd &&
                     from <= _AfternoonStart)
            {
                fromtemp = _AfternoonStart;
            }
            if (RequestUtility.ConvertToTime(to) >= _AfternoonEnd)
            {
                totemp = _AfternoonEnd;
            }
            else if (to >= _MorningEnd &&
                     to <= _AfternoonStart)
            {
                totemp = _MorningEnd;
            }
            TimeSpan ts          = totemp - fromtemp;
            decimal  costMinutes = ts.TotalMinutes < 0 ? 0m : Convert.ToDecimal(ts.TotalMinutes);

            if (fromtemp <= _MorningEnd &&
                fromtemp >= _MorningStart &&
                totemp <= _AfternoonEnd &&
                totemp >= _AfternoonStart)
            {
                costMinutes -= Convert.ToDecimal((_AfternoonStart - _MorningEnd).TotalMinutes);
            }
            decimal answer = ConvertToHour(costMinutes / 60);

            return(answer > _OneDayMaxHour ? _OneDayMaxHour : answer);
        }