Analysis.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. namespace UAS_Analysis
  3. {
  4. public class Analysis
  5. {
  6. /// <summary>
  7. /// Brand对应品牌,item对应DateCode,LotNo等,Data对应具体解析的数据
  8. /// </summary>
  9. /// <param name="Brand"></param>
  10. /// <param name="item"></param>
  11. /// <param name="Data"></param>
  12. /// <returns></returns>
  13. //Brand对应品牌,item对应DateCode,LotNo等,Data对应具体解析的数据
  14. public static string AnalysisData(string Brand, string item, string Data)
  15. {
  16. string ReturnData = "";
  17. switch (Brand)
  18. {
  19. //采集怡海能达村田的LotNo的解析规则
  20. case "MURATA":
  21. if (item.ToUpper() == "LOTNO" || item.ToUpper() == "DATECODE")
  22. {
  23. string Year = Data.Substring(2, 1);
  24. string Month = Data.Substring(3, 1);
  25. string Day = Data.Substring(4, 2);
  26. //处理年份
  27. //当前年份的前三位
  28. string CurrentYear_3 = DateTime.Now.Year.ToString().Substring(0, 3);
  29. //采集到的年份
  30. int CollectYear = int.Parse(CurrentYear_3 + Year);
  31. //当前的年份
  32. int CurrentYear = int.Parse(DateTime.Now.Year.ToString());
  33. //如果采集到的年份大于当前年份,将十年数-1
  34. if (CollectYear > CurrentYear)
  35. {
  36. Year = int.Parse(CurrentYear_3) - 1 + Year;
  37. }
  38. else
  39. {
  40. Year = CollectYear.ToString();
  41. }
  42. //处理月份
  43. switch (Month)
  44. {
  45. case "O":
  46. Month = "10";
  47. break;
  48. case "N":
  49. Month = "11";
  50. break;
  51. case "D":
  52. Month = "12";
  53. break;
  54. default:
  55. Month = "0" + Month;
  56. break;
  57. }
  58. ReturnData = Year + Month + Day;
  59. }
  60. break;
  61. case "KEC":
  62. if (item.ToUpper() == "LOTNO" || item.ToUpper() == "DATECODE")
  63. {
  64. string Year = Data.Substring(0, 1);
  65. string Week = Data.Substring(1, 2);
  66. DateTime DateBegin = DateTime.Now;
  67. GetDaysOfWeeks(int.Parse("201"+Year), int.Parse(Week), out DateBegin);
  68. ReturnData = DateBegin.ToString("yyyyMMdd");
  69. }
  70. break;
  71. default:
  72. break;
  73. }
  74. return ReturnData;
  75. }
  76. public static bool GetDaysOfWeeks(int year, int index, out DateTime first)
  77. {
  78. first = DateTime.MinValue;
  79. if (year < 1700 || year > 9999)
  80. {
  81. //"年份超限"
  82. return false;
  83. }
  84. if (index < 1 || index > 53)
  85. {
  86. //"周数错误"
  87. return false;
  88. }
  89. DateTime startDay = new DateTime(year, 1, 1); //该年第一天
  90. DateTime endDay = new DateTime(year + 1, 1, 1).AddMilliseconds(-1);
  91. int dayOfWeek = 0;
  92. if (Convert.ToInt32(startDay.DayOfWeek.ToString("d")) > 0)
  93. dayOfWeek = Convert.ToInt32(startDay.DayOfWeek.ToString("d")); //该年第一天为星期几
  94. if (dayOfWeek == 7) { dayOfWeek = 0; }
  95. if (index == 1)
  96. {
  97. first = startDay;
  98. }
  99. else
  100. {
  101. first = startDay.AddDays((7 - dayOfWeek) + (index - 2) * 7); //index周的起始日期
  102. }
  103. if (first > endDay) //startDayOfWeeks不在该年范围内
  104. {
  105. //"输入周数大于本年最大周数";
  106. return false;
  107. }
  108. return true;
  109. }
  110. }
  111. }