示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="country"></param>
        /// <param name="fromDate"></param>
        /// <param name="toDate"></param>
        /// <param name="fromTime">am/pm</param>
        /// <param name="toTime">am/pm</param>
        /// <returns></returns>
        public double GetTotalHoursWithoutHoliday(string country, string fromDate, string toDate, string fromTime,
                                                  string toTime)
        {
            DateTime from, to;
            bool     isDate_Form = DateTime.TryParse(fromDate, out from);
            bool     isDate_To   = DateTime.TryParse(toDate, out to);

            if (isDate_Form && isDate_To)
            {
                var hoursOfHalfDay             = 4;
                UserHolidayInfo[] holidaysInfo = null;
                if (!String.IsNullOrEmpty(country))
                {
                    holidaysInfo = WFUtilities.GetHolidays(country, from.ToString("yyyyMMdd"), to.ToString("yyyyMMdd"));
                }
                var    interval   = to - from;
                var    totalHours = (interval.TotalDays + 1) * hoursOfHalfDay * 2;
                string f          = from.ToString("yyyyMMdd");
                string t          = to.ToString("yyyyMMdd");
                if (fromTime.EqualsIgnoreCaseAndBlank("pm"))
                {
                    totalHours -= hoursOfHalfDay;
                    f          += "2";
                }
                else
                {
                    f += "1";
                }
                if (toTime.EqualsIgnoreCaseAndBlank("am"))
                {
                    totalHours -= hoursOfHalfDay;
                    t          += "1";
                }
                else
                {
                    t += "2";
                }
                int nf = int.Parse(f);
                int nt = int.Parse(t);
                if (holidaysInfo != null)
                {
                    foreach (var info in holidaysInfo)
                    {
                        if (String.IsNullOrEmpty(info.Time))
                        {
                            continue;
                        }
                        var date = DateTime.ParseExact(info.Date, "yyyyMMdd",
                                                       System.Globalization.CultureInfo.CurrentCulture);
                        List <int> holidayList = new List <int>();
                        if (info.Time.EqualsIgnoreCaseAndBlank("all"))
                        {
                            string h1 = info.Date + "1";
                            string h2 = info.Date + "2";
                            holidayList.Add(int.Parse(h1));
                            holidayList.Add(int.Parse(h2));
                        }
                        else if (info.Time.EqualsIgnoreCaseAndBlank("am"))
                        {
                            string h = info.Date + "1";
                            holidayList.Add(int.Parse(h));
                        }
                        else if (info.Time.EqualsIgnoreCaseAndBlank("pm"))
                        {
                            string h = info.Date + "2";
                            holidayList.Add(int.Parse(h));
                        }
                        foreach (var i in holidayList)
                        {
                            if (i >= nf && i <= nt)
                            {
                                totalHours -= 4;
                            }
                        }
                    }
                }
                return(totalHours);
            }
            else
            {
                return(-1);
            }
        }