123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using System;
- namespace UAS_Analysis
- {
- public class Analysis
- {
- /// <summary>
- /// Brand对应品牌,item对应DateCode,LotNo等,Data对应具体解析的数据
- /// </summary>
- /// <param name="Brand"></param>
- /// <param name="item"></param>
- /// <param name="Data"></param>
- /// <returns></returns>
- //Brand对应品牌,item对应DateCode,LotNo等,Data对应具体解析的数据
- public static string AnalysisData(string Brand, string item, string Data)
- {
- string ReturnData = "";
- switch (Brand)
- {
- //采集怡海能达村田的LotNo的解析规则
- case "MURATA":
- if (item.ToUpper() == "LOTNO" || item.ToUpper() == "DATECODE")
- {
- string Year = Data.Substring(2, 1);
- string Month = Data.Substring(3, 1);
- string Day = Data.Substring(4, 2);
- //处理年份
- //当前年份的前三位
- string CurrentYear_3 = DateTime.Now.Year.ToString().Substring(0, 3);
- //采集到的年份
- int CollectYear = int.Parse(CurrentYear_3 + Year);
- //当前的年份
- int CurrentYear = int.Parse(DateTime.Now.Year.ToString());
- //如果采集到的年份大于当前年份,将十年数-1
- if (CollectYear > CurrentYear)
- {
- Year = int.Parse(CurrentYear_3) - 1 + Year;
- }
- else
- {
- Year = CollectYear.ToString();
- }
- //处理月份
- switch (Month)
- {
- case "O":
- Month = "10";
- break;
- case "N":
- Month = "11";
- break;
- case "D":
- Month = "12";
- break;
- default:
- Month = "0" + Month;
- break;
- }
- ReturnData = Year + Month + Day;
- }
- break;
- case "KEC":
- if (item.ToUpper() == "LOTNO" || item.ToUpper() == "DATECODE")
- {
- string Year = Data.Substring(0, 1);
- string Week = Data.Substring(1, 2);
- DateTime DateBegin = DateTime.Now;
- GetDaysOfWeeks(int.Parse("201"+Year), int.Parse(Week), out DateBegin);
- ReturnData = DateBegin.ToString("yyyyMMdd");
- }
- break;
- default:
- break;
- }
- return ReturnData;
- }
- public static bool GetDaysOfWeeks(int year, int index, out DateTime first)
- {
- first = DateTime.MinValue;
- if (year < 1700 || year > 9999)
- {
- //"年份超限"
- return false;
- }
- if (index < 1 || index > 53)
- {
- //"周数错误"
- return false;
- }
- DateTime startDay = new DateTime(year, 1, 1); //该年第一天
- DateTime endDay = new DateTime(year + 1, 1, 1).AddMilliseconds(-1);
- int dayOfWeek = 0;
- if (Convert.ToInt32(startDay.DayOfWeek.ToString("d")) > 0)
- dayOfWeek = Convert.ToInt32(startDay.DayOfWeek.ToString("d")); //该年第一天为星期几
- if (dayOfWeek == 7) { dayOfWeek = 0; }
- if (index == 1)
- {
- first = startDay;
- }
- else
- {
- first = startDay.AddDays((7 - dayOfWeek) + (index - 2) * 7); //index周的起始日期
-
- }
- if (first > endDay) //startDayOfWeeks不在该年范围内
- {
- //"输入周数大于本年最大周数";
- return false;
- }
- return true;
- }
- }
- }
|