Exemplo n.º 1
0
        private bool IsBoxTypeOk(string str, IProductLogSearchParameter parameter)
        {
            try
            {
                if (str == null) return false;

                if (parameter.IsSearchSmallBox && str.Trim() == "SMALLBOX") return true;
                else if (parameter.IsSearchLargeBox && str.Trim() == "LARGEBOX") return true;
                else return false;
            }
            catch
            {
                return false;
            }
        }
Exemplo n.º 2
0
 public IProductLogData GetProductLog(IProductLogSearchParameter parameter, string path)
 {
     return LoadProductLog(parameter, path);
 }
Exemplo n.º 3
0
        private IProductLogData LoadProductLog(IProductLogSearchParameter parameter, string path)
        {
            int startHour = 0;
            int startMinute = 0;
            int endHour = 23;
            int endMinute = 59;

            DateTime startDate;
            DateTime endDate;

            try
            {
                startDate = DateTime.Parse(parameter.StartDate);
                endDate = DateTime.Parse(parameter.EndDate);
            }
            catch
            {
                return null;
            }

            DateTime now = DateTime.Now;

            startDate = new DateTime(startDate.Year, startDate.Month, startDate.Day, startHour, startMinute, 00);
            endDate = new DateTime(endDate.Year, endDate.Month, endDate.Day, endHour, endMinute, 59);

            List<string> lines = new List<string>();
            for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
            {
                int year = date.Year;

                string filename = path + year.ToString() + @"\" + date.ToString("MM") + @"\" + date.ToString(@"yyyy-MM-dd") + ".log";

                string[] strs = DBUtility.LoadCSV(filename);
                if (strs != null)
                    lines.AddRange(strs);
            }

            dynamic dayResult;
            dynamic swingResult;
            dynamic gyResult1;
            dynamic gyResult2;

            dayResult =
                from row in lines
                let x = row.Split(',')
                where x.Count() > 2 && IsBoxTypeOk(x[2], parameter) && IsInTime(x[0], new TimeSpan(6, 0, 0), new TimeSpan(13, 59, 59))
                select row;

            swingResult =
                from row in lines
                let x = row.Split(',')
                where x.Count() > 2 && IsBoxTypeOk(x[2], parameter) && IsInTime(x[0], new TimeSpan(14, 0, 0), new TimeSpan(21, 59, 59))
                select row;

            gyResult1 =
                from row in lines
                let x = row.Split(',')
                where x.Count() > 2 && IsBoxTypeOk(x[2], parameter) && IsInTime(x[0], new TimeSpan(22, 0, 0), new TimeSpan(23, 59, 59))
                select row;

            gyResult2 =
                from row in lines
                let x = row.Split(',')
                where x.Count() > 2 && IsBoxTypeOk(x[2], parameter) && IsInTime(x[0], new TimeSpan(0, 0, 0), new TimeSpan(05, 59, 59))
                select row;

            if (parameter.IsSearchLargeBox)
            {
                var result =
                    from row in lines
                    let x = row.Split(',')
                    where x.Count() > 9 && IsBoxTypeOk(x[2], parameter) && IsInDateTime(x[0], startDate, endDate)
                    select new ProductLogItem { Date = x[0], OperatorID = x[1], LotNo = x[3], Barcode1 = x[5], Barcode2 = x[6], Barcode3 = x[7], Barcode4 = x[8], Barcode5 = x[9] };

                try
                {
                    ProductLogData returnValue = new ProductLogData();
                    returnValue.Items = result.ToArray<IProductLogItem>();
                    returnValue.CountDay = System.Linq.Enumerable.Count(dayResult);
                    returnValue.CountSwing = System.Linq.Enumerable.Count(swingResult);
                    returnValue.CountGY = System.Linq.Enumerable.Count(gyResult1) + System.Linq.Enumerable.Count(gyResult2);
                    returnValue.CountTotal = System.Linq.Enumerable.Count(result);
                    return returnValue;
                }
                catch
                {
                    return null;
                }
            }
            else
            {
                var result =
                    from row in lines
                    let x = row.Split(',')
                    where x.Count() > 5 && IsBoxTypeOk(x[2], parameter) && IsInDateTime(x[0], startDate, endDate)
                    select new ProductLogItem { Date = x[0], OperatorID = x[1], LotNo = x[3], PartNo = x[4], Barcode1 = x[5], Barcode2 = "", Barcode3 = "", Barcode4 = "", Barcode5 = "" };

                try
                {
                    ProductLogData returnValue = new ProductLogData();
                    returnValue.Items = result.ToArray<IProductLogItem>();
                    returnValue.CountDay = System.Linq.Enumerable.Count(dayResult);
                    returnValue.CountSwing = System.Linq.Enumerable.Count(swingResult);
                    returnValue.CountGY = System.Linq.Enumerable.Count(gyResult1) + System.Linq.Enumerable.Count(gyResult2);
                    returnValue.CountTotal = System.Linq.Enumerable.Count(result);

                    return returnValue;
                }
                catch
                {
                    return null;
                }
            }
        }