using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Utility; namespace EMIS.ViewModel { public static class WeekNumHelper { public static string GetWeekNumString(this List WeekNumList) { int i; var orderedWeekNumList = WeekNumList.OrderBy(x => x).ToList(); bool isSingle = true; bool isDouble = true; int minWeekNum = WeekNumList.Min() ?? 0; int maxWeekNum = WeekNumList.Max() ?? 0; for (i = 0; i < orderedWeekNumList.Count; i++) { int curWeekNum = orderedWeekNumList[i] ?? 0; if (curWeekNum == 0) { isSingle = false; isDouble = false; break; } if (curWeekNum != minWeekNum + (i * 2)) { isSingle = false; isDouble = false; break; } //判断单周 if (curWeekNum % 2 != 1) { isSingle = false; } //判断双周 if (curWeekNum % 2 != 0) { isDouble = false; } } if (minWeekNum == 0 && maxWeekNum == 0) { return ""; } if (isSingle) { return minWeekNum.ToString() + "-" + maxWeekNum.ToString() + "单周"; } if (isDouble) { return minWeekNum.ToString() + "-" + maxWeekNum.ToString() + "双周"; } return string.Join(",", EnumerableEx.MergeInt(orderedWeekNumList)); } } }