WeekNumHelper.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Utility;
  6. namespace EMIS.ViewModel
  7. {
  8. public static class WeekNumHelper
  9. {
  10. public static string GetWeekNumString(this List<int?> WeekNumList)
  11. {
  12. int i;
  13. var orderedWeekNumList = WeekNumList.OrderBy(x => x).ToList();
  14. bool isSingle = true;
  15. bool isDouble = true;
  16. int minWeekNum = WeekNumList.Min() ?? 0;
  17. int maxWeekNum = WeekNumList.Max() ?? 0;
  18. for (i = 0; i < orderedWeekNumList.Count; i++)
  19. {
  20. int curWeekNum = orderedWeekNumList[i] ?? 0;
  21. if (curWeekNum == 0)
  22. {
  23. isSingle = false;
  24. isDouble = false;
  25. break;
  26. }
  27. if (curWeekNum != minWeekNum + (i * 2))
  28. {
  29. isSingle = false;
  30. isDouble = false;
  31. break;
  32. }
  33. //判断单周
  34. if (curWeekNum % 2 != 1)
  35. {
  36. isSingle = false;
  37. }
  38. //判断双周
  39. if (curWeekNum % 2 != 0)
  40. {
  41. isDouble = false;
  42. }
  43. }
  44. if (minWeekNum == 0 && maxWeekNum == 0)
  45. {
  46. return "";
  47. }
  48. if (isSingle)
  49. {
  50. return minWeekNum.ToString() + "-" + maxWeekNum.ToString() + "单周";
  51. }
  52. if (isDouble)
  53. {
  54. return minWeekNum.ToString() + "-" + maxWeekNum.ToString() + "双周";
  55. }
  56. return string.Join(",", EnumerableEx.MergeInt(orderedWeekNumList));
  57. }
  58. }
  59. }