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); }
public static void AssmPrintWriter(DatasetRAW dsr) { int count = 0; if (File.Exists(Paths.ExportAssemblyData)) { File.Delete(Paths.ExportAssemblyData); } if (File.Exists(Paths.ExportDaily7)) { File.Delete(Paths.ExportDaily7); } string dailyhours = Math.Round((dsr.AnnualAssemblyHours / 250), 2, MidpointRounding.AwayFromZero).ToString(); try { using (StreamWriter sw = new StreamWriter(Paths.ExportRequired)) sw.Write(dailyhours); using (StreamWriter sw = File.CreateText(Paths.ExportAssemblyData)) { Util.SourceOfflineWarning(sw); Util.JobberOfflineWarning(sw); sw.WriteLine($"Assembly Schedule for {DateTime.Now.ToShortDateString()}{Br}{Util.Getj30} Days since June 30th, {Util.GetFiscalYear}{Br}"); sw.WriteLine("* Low Part quantity 0"); foreach (ProductCode code in dsr.ProductCodes) { count += 1; int count2 = 0; if (code.Products != null && code.Products.Count > 0) { sw.WriteLine($"These Items have less than {code.DayLimit} days supply."); sw.WriteLine($" _{code.Productcode}________________________________________________________________________________________"); sw.WriteLine($"|Product|________________________|_Years_|__On__|__Days__|_Do_Not_|__Low___|_For_{code.DayLimit}{(code.DayLimit.ToString().Length > 3 ? string.Empty : "___".Remove(3 - code.DayLimit.ToString().Length))}|_________|"); sw.WriteLine("|__No.__|______Description_______|__Use__|_Hand_|_Supply_|_Exceed_|_Part #_|Day_Sply|__Hours__|"); foreach (ProductModel prod in code.Products) { PP = new PrintProduct(); count2 += 1; PP.Prod = Justify(prod.Number.ToString(), 0, S, 7, JustifyIs.center); if (prod.ExtraData.LowPart != null) { PP.Part = string.Format((prod.ExtraData.LowPart.Part.QuantityOnHand <= 0) ? "*{0}{1}*" : "{0}{1}", prod.ExtraData.LowPart.Part.PartTypePrefix, prod.ExtraData.LowPart.Part.PartNumber); } else { PP.Part = "None"; } PP.Part = Justify(PP.Part, 0, S, 8, JustifyIs.center); PP.Desc = Justify(prod.Description, 0, S, 24, JustifyIs.left); PP.YearsUse = Justify(prod.AnnualUse.ToString("######0"), 0, S, 7, JustifyIs.right); PP.OnHand = Justify(prod.QuantityOnHand.ToString("#####0"), 0, S, 6, JustifyIs.right); PP.DaysSupply = Justify(prod.ExtraData.DaysSupply.ToString("#######0"), 0, S, 8, JustifyIs.right); PP.DoNotExceed = Justify(prod.ExtraData.DoNotExceed.ToString("#######0"), 0, S, 8, JustifyIs.right); PP.Need = Justify(prod.ExtraData.Needed.ToString("#######0"), 0, S, 8, JustifyIs.right); PP.Hour = Justify(prod.ExtraData.NeededAssemblyHours.ToString("####0.##0"), 0, S, 9, JustifyIs.right); sw.WriteLine($"|{PP.Prod}|{PP.Desc}|{PP.YearsUse}|{PP.OnHand}|{PP.DaysSupply}|{PP.DoNotExceed}|{PP.Part}|{PP.Need}|{PP.Hour}|"); } sw.WriteLine($"|_{code.Productcode}___________________________|Hours_Assembled:{Justify(code.HoursAssembled.ToString("####0.0"), 0, L, 7, JustifyIs.right)}|________|_Total:_|{Justify(code.TotalNeeded.ToString(), 0, L, 7, JustifyIs.right)}_|{Justify(code.XdaysSupply.ToString(), 1, L, 9, JustifyIs.right)}|"); sw.WriteLine(); } } sw.WriteLine($"Hours of Assembled Inventory: {dsr.AssembledHours} Hours to Assemble Years Use: {dsr.AnnualAssemblyHours:####0.0}{Br}Hours to produce needed products for a {dsr.ProductCodes[0].DayLimit}-Day supply: {dsr.XdaysSupply}"); sw.WriteLine(Environment.NewLine + Environment.NewLine); sw.WriteLine($"Yesterday's Production Hours: {dsr.YesterdaysProductionHours}"); //TODO: Repiar Get Daily avg function, as used below. //sw.WriteLine("Last Year, This Month, Daily Avg: " + Utilities.GetDailyAvg()); sw.WriteLine($"Required Daily Hours to Produce a 1-year Supply: {dailyhours.Trim()}"); } if (dsr.ProductCodes.Count > 1) { using (StreamWriter sw = new StreamWriter(Paths.ExportDaily7)) { Util.SourceOfflineWarning(sw); Util.JobberOfflineWarning(sw); sw.WriteLine($"THESE PARTS ARE NOT MADE BY US BUT HAVE CYCLE TIMES.{Br}"); foreach (string part in dsr.Daily7Data.PartNumbers) { sw.Write($"{part} "); } sw.WriteLine($"{Br}{Br}{dsr.Daily7Data.HoursForYearsSales.Trim()} HOURS TO PRODUCE ALL PARTS FOR ESTIMATED SALES {Today}"); sw.WriteLine($"THERE MUST BE {dsr.Daily7Data.ProdHoursPerDay.Trim()} PRODUCTION HOURS PER DAY"); sw.WriteLine("THIS DOES NOT INCLUDE THE ASSEMBLY HOURS"); sw.WriteLine($"{dsr.Daily7Data.TotalHours.Trim()} TOTAL HOURS OF PARTS ON HAND {dsr.Daily7Data.AssembledHours.Trim()} ASSEMBLED."); sw.WriteLine(Br + " ________________PARTS__________________ ________________PRODUCTS_______________"); sw.WriteLine("|_DAYS_|__HOURS_NEEDED__|_SURPLUS_HOURS_| |_DAYS_|__HOURS_NEEDED__|_SURPLUS_HOURS_|"); sw.WriteLine($"| -30- | {Justify(dsr.Daily7Data.HoursNeeded30, S, 14, JustifyIs.right)} | {Justify(dsr.Daily7Data.SurplusHours30, S, 13, JustifyIs.right)} | | -30- | {Justify(dsr.ProdHrNeedThirty.ToString(), S, 14, JustifyIs.right)} | {Justify(dsr.ProdSurplusHr30.ToString(), S, 13, JustifyIs.right)} |"); sw.WriteLine($"| -60- | {Justify(dsr.Daily7Data.HoursNeeded60, S, 14, JustifyIs.right)} | {Justify(dsr.Daily7Data.SurplusHours60, S, 13, JustifyIs.right)} | | -60- | {Justify(dsr.ProdHrNeedSixty.ToString(), S, 14, JustifyIs.right)} | {Justify(dsr.ProdSurplusHr60.ToString(), S, 13, JustifyIs.right)} |"); sw.WriteLine($"| -90- | {Justify(dsr.Daily7Data.HoursNeeded90, S, 14, JustifyIs.right)} | {Justify(dsr.Daily7Data.SurplusHours90, S, 13, JustifyIs.right)} | | -90- | | {Justify(dsr.ProdSurplusHr90.ToString(), S, 13, JustifyIs.right)} |"); sw.WriteLine("|______|________________|_______________| |______|________________|_______________|"); sw.WriteLine(" _______________________ _______________________"); sw.WriteLine("| Daily Production | Yesterdays Production |"); sw.WriteLine("| Hours Required to | Hours |"); sw.WriteLine("|Produce a 1-Year Supply| |"); sw.WriteLine($"| {Justify(dailyhours, S, 21, JustifyIs.center)} | {Justify(dsr.YesterdaysProductionHours.ToString("####.##"), S, 21, JustifyIs.center)} | "); sw.WriteLine("|_______________________|_______________________|"); sw.WriteLine(Br + "SEE INVENTORY PRINTOUT FOR ITEMS THAT ARE IN SURPLUS" + Br); sw.WriteLine($"Hours of Assembled Inventory: {dsr.AssembledHours} Hours to Assemble Years Use: {dsr.AnnualAssemblyHours}{Br}Hours to produce needed products for a {dsr.ProductCodes[0].DayLimit}-Day supply: {dsr.XdaysSupply}"); } if (File.Exists(Paths.ExportDaily7)) { Process.Start("notepad.exe", Paths.ExportDaily7); Thread.Sleep(100); } } if (File.Exists(Paths.ExportAssemblyData)) { Process.Start("notepad.exe", Paths.ExportAssemblyData); } } catch (Exception e) { ErrorWriter("At Writer." + Environment.NewLine + e.Message + Br + e.StackTrace); Environment.Exit(0); } }
public static void ParseArgs(string[] args) { Util.UpdateAvgs(false); try { switch (args[0]) { case "-lbl": if (args.Count() == 2 && int.TryParse(args[1], out int LabelCount)) { Write.PrintLabels(Read.GenericRead(Paths.ImportLabelData).ToList(), LabelCount); Process.Start(Paths.ExportLabels); } break; case "-x": Util.UpdateAvgs(true); break; case "-bkosort": Write.BkoWriter(AssemblyOrganizer.Sort(AssemblyOrganizer.Pack(AssemblyOrganizer.ParseIn(Read.GenericRead(Paths.ImportGenericData).ToList())))); Process.Start("notepad.exe", Paths.ExportGenericData); break; case "-f": JobberParser.DumpData(); break; case "-SpecSched": if (args.Length != 2) { Util.ExceptionExit("An invalid number of arguments were supplied by the calling program."); } if (args[1].Length == 8) { var CodeData = Read.GenericRead(Paths.ImportTempImport).ToList(); if (Util.GetDateTimeFromArg(args[1], out DateTime DateLim)) { JobberParser.DumpData(DateLim, CodeData); } } break; case "-mach": if (args.Length != 2) { Util.ExceptionExit("An invalid number of arguments were supplied by the calling program."); } if (args[1].Length == 8) { if (Util.GetDateTimeFromArg(args[1], out DateTime DateLim)) { JobberParser.DumpData(DateLim); } } break; case "-bkod": if (args.Length != 2) { Util.ExceptionExit("An invalid number of arguments were supplied by the calling program."); } if (args[1].Length == 8) { if (Util.GetDateTimeFromArg(args[1], out DateTime DateLim)) { JobberParser.DumpData(DateLim, null); } else { Util.ExceptionExit("Date format was invalid and not parseable.", null, true); } } break; case "-bkop": if (args.Length >= 2 && int.TryParse(args[1], out int ProductNumber)) { JobberParser.DumpData(ProductNumber < 90001 ? ProductNumber : ProductNumber - 90000); } break; case "-bko": string CustomerCode0 = (args.Length >= 2 && args[1] != "_BLANK") ? args[1] : string.Empty; string ReportType = (args.Length >= 3) ? args[2] : string.Empty; JobberParser.DumpData(ReportType, CustomerCode0, args.Length > 1); break; case "-a": if (File.Exists(Paths.ImportGenericData)) { ///GETS DATA FOR NEW ASSEMBLY SCHEDULE AND DAILY_7 PRINTOUT List <string> data0 = Read.ExportReader(Paths.ImportGenericData); ///PARSES GATHERED DATA, IF THERE IS DATA (I.E. THERE WASN'T A PROBLEM IN QB) IT WILL THEN PRINT AND OPEN NEW FILES | IF ALL ELSE FAILS, PRINT AN ERROR if (data0.Any()) { double[] CurrentProductionData = UpdateProductionMetrics(false); DatasetRAW dsr = AssemblyParser.DoWork(data0, CurrentProductionData[1]); Write.AssmPrintWriter(dsr); } else { Write.ErrorWriter("There was an issue with the exported data from basic."); } } else { Write.ErrorWriter("Required Files were not found."); } break; case "-p": UpdateProductionMetrics(true); break; case "-q": Write.QuickSortWriter(AssemblyParser.Quicksort(Read.GenericRead(Paths.ImportGenericData).ToList()), Paths.ExportGenericData); Process.Start("notepad.exe", Paths.ExportGenericData); break; } } catch (Exception e) { Util.ExceptionExit(string.Empty, e); } }