其中调休配置在了new_holidayconfig这张表,表里还有国家和日期字段,如果不是D365可以用其他办法去存。
public static int WorkingDayCount(DateTime startTime, DateTime endTime, string countryId, IOrganizationService adminOrganizationService) { int workingDay=0; int totalDays = (int)(endTime-startTime).TotalDays; for(int i =0; i < totalDays; i++) { if(startTime.AddDays(i).DayOfWeek!=DayOfWeek.Saturday && startTime.AddDays(i).DayOfWeek != DayOfWeek.Sunday) { workingDay++; } } if (string.IsNullOrWhiteSpace(countryId)) return workingDay; //如果有国家,去除节日 增补调休日 var qe = new QueryExpression("new_holidayconfig"); qe.NoLock = true; qe.ColumnSet = new ColumnSet("new_holidayconfigid","new_daytypecode"); qe.Criteria.AddCondition("new_country_id", ConditionOperator.Equal, countryId); qe.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0); qe.Criteria.AddCondition("new_date", ConditionOperator.OnOrAfter, startTime); qe.Criteria.AddCondition("new_date", ConditionOperator.OnOrBefore, endTime); var fixDays = adminOrganizationService.RetrieveMultiple(qe); if(fixDays!=null&&fixDays.Entities!=null&& fixDays.Entities.Count>0) { for(int i = 0; i < fixDays.Entities.Count; i++) { if (fixDays.Entities[i].Contains("new_daytypecode")) { var type = fixDays.Entities[i].GetAttributeValue<OptionSetValue>("new_daytypecode").Value; if(type == 1)//节日自增 { workingDay++; } else if (type == 2) { workingDay--; } } } } return workingDay; }
标签:C#,workingDay,D365,int,fixDays,qe,startTime,new,调休 From: https://www.cnblogs.com/RegularMoon/p/18136112/calculateworkingday