/// <summary> /// 验证日历类型:工作日,休息日,节假日 /// </summary> /// <param name="day">日期,格式yyyyMMdd</param> /// <returns>日历类型</returns> public CalendarType CheckCalendar(string day) { if (string.IsNullOrEmpty(day)) { Log.Error("日期参数不正确。"); throw new InvalidOperationException("日期参数不正确。"); } //节假日 if (Holidays.Any(it => it.Date == day)) { return(CalendarType.Holiday); } try { DateTime date = DateTime.ParseExact(day, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); return(((date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday) && Workdays.Any(it => it.Date == day) == false) ? CalendarType.Weekend : CalendarType.Workday); } catch (Exception ex) { Log.Error(ex); throw ex; } }
public void nwdset_amtimein(string V) { TimeSpan tmp = V != null?TimeSpan.Parse(V) : new TimeSpan(); // for overtime if (tmp.Hours > 11) { Workdays.Last().Value.TimeIn_PM = V != null?TimeSpan.Parse(V) : new TimeSpan(); } // for regular work hours else { Workdays.Last().Value.TimeIn_AM = V != null?TimeSpan.Parse(V) : new TimeSpan(); } if (tmp.Hours > 11) { Workdays.Last().Value.TimeIn_PM = V != null?TimeSpan.Parse(V) : new TimeSpan(); } // for regular work hours else { Workdays.Last().Value.TimeIn_AM = V != null?TimeSpan.Parse(V) : new TimeSpan(); } }
public void AddWorkDay(string WorkDateFromCell) { int IntDay = int.Parse(WorkDateFromCell.Split(' ')[0]); string weekday = WorkDateFromCell.Split(' ')[1]; WorkDay wd = new WorkDay(WorkDateFromCell, IntDay); Workdays.Add(IntDay, wd); }
public void nwdset_pmtimeout(string V) { Workdays.Last().Value.TimeOut_PM = V != null?TimeSpan.Parse(V) : new TimeSpan(); TimeSpan tmp = V != null?TimeSpan.Parse(V) : new TimeSpan(); if (tmp.Hours != 12 && tmp.Hours != 0) { Workdays.Last().Value.TimeOut_PM = new TimeSpan(tmp.Hours - 12, tmp.Minutes, 0); } }
static void Main() { // Date until workdays DateTime date = new DateTime(2015, 03, 15); List <DateTime> holidays = new List <DateTime>() { new DateTime(2015, 02, 14), // Valentine's Day new DateTime(2015, 03, 03), // National praznik new DateTime(2015, 05, 06) // Gergiovden }; Console.WriteLine("Workdays: {0}", Workdays.NumberOfWorkDays(date, holidays)); }
static void Main(string[] args) { Console.Title = "Workdays to given date"; Console.ForegroundColor = ConsoleColor.Green; Console.Write("Enter the month: "); int month = int.Parse(Console.ReadLine()); Console.Write("Enter the day: "); int day = int.Parse(Console.ReadLine()); Workdays workdays = new Workdays(new DateTime(DateTime.Now.Year, month, day)); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("\nYou have {0} workdays to {1}.{2}.{3}", workdays.CountWorkdays(), day, month, DateTime.Now.Year); Console.WriteLine(); Console.ResetColor(); }
static void Main(string[] args) { Console.Title = "Workdays to given date"; Console.ForegroundColor = ConsoleColor.Green; Console.Write("Enter the month: "); int month = int.Parse(Console.ReadLine()); Console.Write("Enter the day: "); int day = int.Parse(Console.ReadLine()); Workdays workdays = new Workdays( new DateTime(DateTime.Now.Year, month, day)); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("\nYou have {0} workdays to {1}.{2}.{3}", workdays.CountWorkdays(), day, month, DateTime.Now.Year); Console.WriteLine(); Console.ResetColor(); }
public void nwdset_amtimeout(string V) { Workdays.Last().Value.TimeOut_AM = V != null?TimeSpan.Parse(V) : new TimeSpan(); }
public static IEnumerable <DateTime> GetWorkdaysInMonth(int month) { return(Enumerable.Range(1, GetDaysInMonth(month)) .Select(day => new DateTime(DateTime.Today.Year, month, day)) .Where(date => Workdays.Contains(date.DayOfWeek))); }
public static int GetWorkWeeksInMonth(int month) { return(GetDaysInMonth(month) / Workdays.Count() + 1); }