Ejemplo n.º 1
0
        public static DatasetRAW DoWork(List <string> dataset, double YesterdaysHours)
        {
            DatasetRAW      pcodes                = new DatasetRAW();
            Daily7Data      daily7Data            = new Daily7Data();
            NeededAndAnnual naa                   = Util.GetAnnualUseHours();
            string          lline                 = "";
            var             ProductCodeDictionary = Util.Products.GroupBy(x => x.ProductCode).ToDictionary(x => x.Key, x => x.ToList());

            try
            {
                foreach (string line in dataset)
                {
                    switch (line[0])
                    {
                    case '╝':
                        //a code line
                        var code = new ProductCode(line);
                        if (ProductCodeDictionary.ContainsKey(code.Productcode))
                        {
                            pcodes.ProductCodes.Add(code.InitCode(ProductCodeDictionary[code.Productcode]));
                        }
                        continue;

                    case '└':
                        //beginning of daily_7 data, parts list
                        pcodes.Daily7Data = Daily7Parser(line);
                        pcodes.YesterdaysProductionHours = YesterdaysHours;
                        continue;

                    default:
                        continue;
                    }
                }
            }
            catch (Exception e)
            {
                Write.ErrorWriter(lline + _ + "Stopped at parser switch." + _ + e.InnerException + _ + " " + e.Message + _ + e.StackTrace); Environment.Exit(0);
            }

            try
            {
                pcodes.AnnualAssemblyHours = naa.AnnualHours;
                pcodes.AssembledHours      = Math.Round(pcodes.ProductCodes.Sum(x => x.HoursAssembled), 2, MidpointRounding.AwayFromZero);
                pcodes.XdaysSupply         = Math.Round(pcodes.ProductCodes.Sum(x => x.XdaysSupply), 1, MidpointRounding.AwayFromZero);
                if (pcodes.ProductCodes.Any())
                {
                    pcodes.ProdSurplusHr30  = Math.Round((pcodes.AssembledHours - ((pcodes.AnnualAssemblyHours / 250) * 30)), 2, MidpointRounding.AwayFromZero);
                    pcodes.ProdSurplusHr60  = Math.Round((pcodes.AssembledHours - ((pcodes.AnnualAssemblyHours / 250) * 60)), 2, MidpointRounding.AwayFromZero);
                    pcodes.ProdSurplusHr90  = Math.Round((pcodes.AssembledHours - ((pcodes.AnnualAssemblyHours / 250) * 90)), 2, MidpointRounding.AwayFromZero);
                    pcodes.ProdHrNeedThirty = naa.Needed30;
                    pcodes.ProdHrNeedSixty  = naa.Needed60;
                }
                else
                {
                    pcodes.ProdSurplusHr30  = 0;
                    pcodes.ProdSurplusHr60  = 0;
                    pcodes.ProdSurplusHr90  = 0;
                    pcodes.ProdHrNeedThirty = 0;
                    pcodes.ProdHrNeedSixty  = 0;
                    pcodes.ProdHrNeedNinety = 0;
                }
            }
            catch (Exception e)
            {
                Write.ErrorWriter("Stopped after parser switch." + _ + e.InnerException + _ + " " + e.Message + _ + e.StackTrace); Environment.Exit(0);
            }
            //pcodes.pcodes = pcodes.pcodes.OrderBy(x => x._pcode).ToList();
            return(pcodes);
        }