12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- 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<int?> 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));
- }
- }
- }
|